@chainingintention/pi-web-cn 1.202606.14 → 1.202606.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,9 @@ let qn=[],Lo=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,
4
4
  `,this;e--}else if(n instanceof J){let h=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,h.length>Math.max(0,e))return this.value=e==0?h:t>0?h.slice(e):h.slice(0,h.length-e),this;e-=h.length}else{let h=n.children[o+(t<0?-1:0)];e>h.length?(e-=h.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(t>0?1:(h instanceof J?h.text.length:h.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Wo{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new _t(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 Ho{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.afterBreak?(this.value="",this.afterBreak=!1):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}}typeof Symbol<"u"&&(E.prototype[Symbol.iterator]=function(){return this.iter()},_t.prototype[Symbol.iterator]=Wo.prototype[Symbol.iterator]=Ho.prototype[Symbol.iterator]=function(){return this});class Zh{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}function Pt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function ie(s,e,t=!0,i=!0){return _h(s,e,t,i)}function ea(s){return s>=56320&&s<57344}function ta(s){return s>=55296&&s<56320}function ia(s,e){let t=s.charCodeAt(e);if(!ta(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return ea(i)?(t-55296<<10)+(i-56320)+65536:t}function na(s){return s<65536?1:2}const jn=/\r\n?|\n/;var le=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(le||(le={}));class He{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 this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(e,t=!1){Un(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 He(e)}composeDesc(e){return this.empty?e:e.empty?this:Vo(this,e)}mapDesc(e,t=!1){return e.empty?this:Gn(this,e,t)}mapPos(e,t=-1,i=le.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],a=n+l;if(h<0){if(a>e)return r+(e-n);r+=l}else{if(i!=le.Simple&&a>=e&&(i==le.TrackDel&&n<e&&a>e||i==le.TrackBefore&&n<e||i==le.TrackAfter&&a>e))return null;if(a>e||a==e&&t<0&&!l)return e==n||t<0?r:r+h;r+=h}n=a}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return r}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}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(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new He(e)}static create(e){return new He(e)}}class X extends He{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 Un(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return Gn(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let h=n>>1;for(;i.length<h;)i.push(E.empty);i.push(o?e.slice(r,r+o):E.empty)}r+=o}return new X(t,i)}compose(e){return this.empty?e:e.empty?this:Vo(this,e,!0)}map(e,t=!1){return e.empty?this:Gn(this,e,t,!0)}iterChanges(e,t=!1){Un(this,e,t)}get desc(){return He.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new ii(this);e:for(let o=0,l=0;;){let h=o==e.length?1e9:e[o++];for(;l<h||l==h&&r.len==0;){if(r.done)break e;let f=Math.min(r.len,h-l);te(n,f,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;te(t,f,c),c>0&&et(i,t,r.text),r.forward(f),l+=f}let a=e[o++];for(;l<a;){if(r.done)break e;let f=Math.min(r.len,a-l);te(t,f,-1),te(n,f,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(f),l+=f}}return{changes:new X(t,i),filtered:He.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):n==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function h(f=!1){if(!f&&!n.length)return;o<t&&te(n,t-o,-1);let c=new X(n,r);l=l?l.compose(c.map(l)):c,n=[],r=[],o=0}function a(f){if(Array.isArray(f))for(let c of f)a(c);else if(f instanceof X){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);h(),l=l?l.compose(f.map(l)):f}else{let{from:c,to:u=c,insert:d}=f;if(c>u||c<0||u>t)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?E.of(d.split(i||jn)):d:E.empty,g=p.length;if(c==u&&g==0)return;c<o&&h(),c>o&&te(n,c-o,-1),te(n,u-c,g),et(r,n,p),o=u}}return a(e),h(!l),l}static empty(e){return new X(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<n;)i.push(E.empty);i[n]=E.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new X(t,i)}static createSet(e,t){return new X(e,t)}}function te(s,e,t,i=!1){if(e==0&&t<=0)return;let n=s.length-2;n>=0&&t<=0&&t==s[n+1]?s[n]+=e:n>=0&&e==0&&s[n]==0?s[n+1]+=t:i?(s[n]+=e,s[n+1]+=t):s.push(e,t)}function et(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(t);else{for(;s.length<i;)s.push(E.empty);s.push(t)}}function Un(s,e,t){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],h=s.sections[o++];if(h<0)n+=l,r+=l;else{let a=n,f=r,c=E.empty;for(;a+=l,f+=h,h&&i&&(c=c.append(i[o-2>>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],h=s.sections[o++];e(n,a,r,f,c),n=a,r=f}}}function Gn(s,e,t,i=!1){let n=[],r=i?[]:null,o=new ii(s),l=new ii(e);for(let h=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let a=Math.min(o.len,l.len);te(n,a,-1),o.forward(a),l.forward(a)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let a=l.len;for(te(n,l.ins,-1);a;){let f=Math.min(o.len,a);o.ins>=0&&h<o.i&&o.len<=f&&(te(n,0,o.ins),r&&et(r,n,o.text),h=o.i),o.forward(f),a-=f}l.next()}else if(o.ins>=0){let a=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);a+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.len<f)f-=l.len,l.next();else break;te(n,a,h<o.i?o.ins:0),r&&h<o.i&&et(r,n,o.text),h=o.i,o.forward(o.len-f)}else{if(o.done&&l.done)return r?X.createSet(n,r):He.create(n);throw new Error("Mismatched change set lengths")}}}function Vo(s,e,t=!1){let i=[],n=t?[]:null,r=new ii(s),o=new ii(e);for(let l=!1;;){if(r.done&&o.done)return n?X.createSet(i,n):He.create(i);if(r.ins==0)te(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)te(i,0,o.ins,l),n&&et(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(r.len2,o.len),a=i.length;if(r.ins==-1){let f=o.ins==-1?-1:o.off?0:o.ins;te(i,h,f,l),n&&f&&et(n,i,o.text)}else o.ins==-1?(te(i,r.off?0:r.len,h,l),n&&et(n,i,r.textBit(h))):(te(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&et(n,i,o.text));l=(r.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>a),r.forward2(h),o.forward(h)}}}}class ii{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?E.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?E.empty:t[i].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 ut{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}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 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 ut(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(e.anchor,e.head)}static create(e,t,i){return new ut(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.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)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(e.ranges.map(t=>ut.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.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 i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,n){return ut.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(e,t,i,n,r){let o=(i??16777215)<<6|(n==null?7:Math.min(6,n));return!r&&e!=t&&(r=t<e?1:-1),t<e?ut.create(t,e,48|o):ut.create(e,t,(r?r<0?8:16:0)|o)}static normalized(e,t=0){let i=e[t];e.sort((n,r)=>n.from-r.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let r=e[n],o=e[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,h=Math.max(r.to,o.to);n<=t&&t--,e.splice(--n,2,r.anchor>r.head?b.range(h,l):b.range(l,h))}}return new b(e,t)}}function zo(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Es=0;class A{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=Es++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new A(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Ls),!!e.static,e.enables)}of(e){return new Hi([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Hi(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Hi(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Ls(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class Hi{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=Es++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,h=!1,a=!1,f=[];for(let c of this.dependencies)c=="doc"?h=!0:c=="selection"?a=!0:(((t=e[c.id])!==null&&t!==void 0?t:1)&1)==0&&f.push(e[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(h&&u.docChanged||a&&(u.docChanged||u.selection)||Jn(c,f)){let d=i(c);if(l?!dr(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[r];if(p!=null){let g=ji(u,p);if(this.dependencies.every(m=>m instanceof A?u.facet(m)===c.facet(m):m instanceof Je?u.field(m,!1)==c.field(m,!1):!0)||(l?dr(d=i(c),g,n):n(d=i(c),g)))return c.values[o]=g,0}else d=i(c);return c.values[o]=d,1}}}}function dr(s,e,t){if(s.length!=e.length)return!1;for(let i=0;i<s.length;i++)if(!t(s[i],e[i]))return!1;return!0}function Jn(s,e){let t=!1;for(let i of e)Xt(s,i)&1&&(t=!0);return t}function sa(s,e,t){let i=t.map(h=>s[h.id]),n=t.map(h=>h.type),r=i.filter(h=>!(h&1)),o=s[e.id]>>1;function l(h){let a=[];for(let f=0;f<i.length;f++){let c=ji(h,i[f]);if(n[f]==2)for(let u of c)a.push(u);else a.push(c)}return e.combine(a)}return{create(h){for(let a of i)Xt(h,a);return h.values[o]=l(h),1},update(h,a){if(!Jn(h,r))return 0;let f=l(h);return e.compare(f,h.values[o])?0:(h.values[o]=f,1)},reconfigure(h,a){let f=Jn(h,i),c=a.config.facets[e.id],u=a.facet(e);if(c&&!f&&Ls(t,c))return h.values[o]=u,0;let d=l(h);return e.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const Si=A.define({static:!0});class Je{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new Je(Es++,e.create,e.update,e.compare||((i,n)=>i===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Si).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>{let r=i.facet(Si),o=n.facet(Si),l;return(l=r.find(h=>h.field==this))&&l!=o.find(h=>h.field==this)?(i.values[t]=l.create(i),1):n.config.address[this.id]!=null?(i.values[t]=n.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,Si.of({field:this,create:e})]}get extension(){return this}}const ct={lowest:4,low:3,default:2,high:1,highest:0};function Kt(s){return e=>new Ko(e,s)}const on={highest:Kt(ct.highest),high:Kt(ct.high),default:Kt(ct.default),low:Kt(ct.low),lowest:Kt(ct.lowest)};class Ko{constructor(e,t){this.inner=e,this.prec=t}}class ln{of(e){return new Yn(this,e)}reconfigure(e){return ln.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Yn{constructor(e,t){this.compartment=e,this.inner=t}}class qi{constructor(e,t,i,n,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.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,i){let n=[],r=Object.create(null),o=new Map;for(let u of ra(e,t,o))u instanceof Je?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],a=[];for(let u of n)l[u.id]=a.length<<1,a.push(d=>u.slot(d));let f=i?.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=f&&f[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,Ls(g,d))h.push(i.facet(p));else{let m=p.combine(d.map(y=>y.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=a.length<<1,a.push(y=>m.dynamicSlot(y)));l[p.id]=a.length<<1,a.push(m=>sa(m,p,d))}}let c=a.map(u=>u(l));return new qi(e,o,c,l,h,r)}}function ra(s,e,t){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let h=n.get(o);if(h!=null){if(h<=l)return;let a=i[h].indexOf(o);a>-1&&i[h].splice(a,1),o instanceof Yn&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let a of o)r(a,l);else if(o instanceof Yn){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let a=e.get(o.compartment)||o.inner;t.set(o.compartment,a),r(a,l)}else if(o instanceof Ko)r(o.inner,o.prec);else if(o instanceof Je)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Hi)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,ct.default);else{let a=o.extension;if(!a)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(a,l)}}return r(s,ct.default),i.reduce((o,l)=>o.concat(l))}function Xt(s,e){if(e&1)return 2;let t=e>>1,i=s.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[t]=4;let n=s.computeSlot(s,s.config.dynamicSlots[t]);return s.status[t]=2|n}function ji(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const $o=A.define(),_n=A.define({combine:s=>s.some(e=>e),static:!0}),qo=A.define({combine:s=>s.length?s[0]:void 0,static:!0}),jo=A.define(),Uo=A.define(),Go=A.define(),Jo=A.define({combine:s=>s.length?s[0]:!1});class Ye{constructor(e,t){this.type=e,this.value=t}static define(){return new oa}}class oa{of(e){return new Ye(this,e)}}class la{constructor(e){this.map=e}of(e){return new q(this,e)}}class q{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 q(this.type,t)}is(e){return this.type==e}static define(e={}){return new la(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let r=n.map(t);r&&i.push(r)}return i}}q.reconfigure=q.define();q.appendConfig=q.define();class _{constructor(e,t,i,n,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&zo(i,t.newLength),r.some(l=>l.type==_.time)||(this.annotations=r.concat(_.time.of(Date.now())))}static create(e,t,i,n,r,o){return new _(e,t,i,n,r,o)}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(_.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}_.time=Ye.define();_.userEvent=Ye.define();_.addToHistory=Ye.define();_.remote=Ye.define();function ha(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==e.length||e[n]>=s[i]))r=s[i++],o=s[i++];else if(n<e.length)r=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Yo(s,e,t){var i;let n,r,o;return t?(n=e.changes,r=X.empty(e.changes.length),o=s.changes.compose(e.changes)):(n=e.changes.map(s.changes),r=s.changes.mapDesc(e.changes,!0),o=s.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:q.mapEffects(s.effects,n).concat(q.mapEffects(e.effects,r)),annotations:s.annotations.length?s.annotations.concat(e.annotations):e.annotations,scrollIntoView:s.scrollIntoView||e.scrollIntoView}}function Xn(s,e,t){let i=e.selection,n=Ct(e.annotations);return e.userEvent&&(n=n.concat(_.userEvent.of(e.userEvent))),{changes:e.changes instanceof X?e.changes:X.of(e.changes||[],t,s.facet(qo)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Ct(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function _o(s,e,t){let i=Xn(s,e.length?e[0]:{},s.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Yo(i,Xn(s,e[r],o?i.changes.newLength:s.doc.length),o)}let n=_.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return fa(t?aa(n):n)}function aa(s){let e=s.startState,t=!0;for(let n of e.facet(jo)){let r=n(s);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:ha(t,r))}if(t!==!0){let n,r;if(t===!1)r=s.changes.invertedDesc,n=X.empty(e.doc.length);else{let o=s.changes.filter(t);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=_.create(e,n,s.selection&&s.selection.map(r),q.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=e.facet(Uo);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof _?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof _?s=r[0]:s=_o(e,Ct(r),!1)}return s}function fa(s){let e=s.startState,t=e.facet(Go),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=Yo(i,Xn(e,r,s.changes.newLength),!0))}return i==s?s:_.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const ca=[];function Ct(s){return s==null?ca:Array.isArray(s)?s:[s]}var $e=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})($e||($e={}));const ua=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Qn;try{Qn=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function da(s){if(Qn)return Qn.test(s);for(let e=0;e<s.length;e++){let t=s[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||ua.test(t)))return!0}return!1}function pa(s){return e=>{if(!/\S/.test(e))return $e.Space;if(da(e))return $e.Word;for(let t=0;t<s.length;t++)if(e.indexOf(s[t])>-1)return $e.Word;return $e.Other}}class N{constructor(e,t,i,n,r,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Xt(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return Xt(this,i),ji(this,i)}update(...e){return _o(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:n}=t;for(let l of e.effects)l.is(ln.reconfigure)?(t&&(n=new Map,t.compartments.forEach((h,a)=>n.set(a,h)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(q.reconfigure)?(t=null,i=l.value):l.is(q.appendConfig)&&(t=null,i=Ct(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=qi.resolve(i,n,this),r=new N(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(h,a)=>a.reconfigure(h,this),null).values);let o=e.startState.facet(_n)?e.newSelection:e.newSelection.asSingle();new N(t,e.newDoc,o,r,(l,h)=>h.update(l,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:b.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Ct(i.effects);for(let l=1;l<t.ranges.length;l++){let h=e(t.ranges[l]),a=this.changes(h.changes),f=a.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(f);let c=n.mapDesc(a,!0);r.push(h.range.map(c)),n=n.compose(f),o=q.mapEffects(o,f).concat(q.mapEffects(Ct(h.effects),c))}return{changes:n,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof X?e:X.of(e,this.doc.length,this.facet(N.lineSeparator))}toText(e){return E.of(e.split(this.facet(N.lineSeparator)||jn))}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:(Xt(this,t),ji(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 Je&&this.config.address[n.id]!=null&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];n.push(o.init(h=>o.spec.fromJSON(l,h)))}}return N.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=qi.resolve(e.extensions||[],new Map),i=e.doc instanceof E?e.doc:E.of((e.doc||"").split(t.staticFacet(N.lineSeparator)||jn)),n=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return zo(n,i.length),t.staticFacet(_n)||(n=n.asSingle()),new N(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(N.tabSize)}get lineBreak(){return this.facet(N.lineSeparator)||`
5
5
  `}get readOnly(){return this.facet(Jo)}phrase(e,...t){for(let i of this.facet(N.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet($o))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return pa(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let h=ie(t,o,!1);if(r(t.slice(h,o))!=$e.Word)break;o=h}for(;l<n;){let h=ie(t,l);if(r(t.slice(l,h))!=$e.Word)break;l=h}return o==l?null:b.range(o+i,l+i)}}N.allowMultipleSelections=_n;N.tabSize=A.define({combine:s=>s.length?s[0]:4});N.lineSeparator=qo;N.readOnly=Jo;N.phrases=A.define({compare(s,e){let t=Object.keys(s),i=Object.keys(e);return t.length==i.length&&t.every(n=>s[n]==e[n])}});N.languageData=$o;N.changeFilter=jo;N.transactionFilter=Uo;N.transactionExtender=Go;ln.reconfigure=q.define();function Xo(s,e,t={}){let i={};for(let n of s)for(let r of Object.keys(n)){let o=n[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let n in e)i[n]===void 0&&(i[n]=e[n]);return i}class tt{eq(e){return this==e}range(e,t=e){return Zn.create(e,t,this)}}tt.prototype.startSide=tt.prototype.endSide=0;tt.prototype.point=!1;tt.prototype.mapMode=le.TrackDel;function Rs(s,e){return s==e||s.constructor==e.constructor&&s.eq(e)}let Zn=class Qo{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Qo(e,t,i)}};function es(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class Ns{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 r=i?this.to:this.from;for(let o=n,l=r.length;;){if(o==l)return o;let h=o+l>>1,a=r[h]-e||(i?this.value[h].endSide:this.value[h].startSide)-t;if(h==o)return a>=0?o:l;a>=0?l=h:o=h+1}}between(e,t,i,n){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(n(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],n=[],r=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let a=this.value[h],f=this.from[h]+e,c=this.to[h]+e,u,d;if(f==c){let p=t.mapPos(f,a.startSide,a.mapMode);if(p==null||(u=d=p,a.startSide!=a.endSide&&(d=t.mapPos(f,a.endSide),d<u)))continue}else if(u=t.mapPos(f,a.startSide),d=t.mapPos(c,a.endSide),u>d||u==d&&a.startSide>0&&a.endSide<=0)continue;(d-u||a.endSide-a.startSide)<0||(o<0&&(o=u),a.point&&(l=Math.max(l,d-u)),i.push(a),n.push(u-o),r.push(d-o))}return{mapped:i.length?new Ns(n,r,i,l):null,pos:o}}}class L{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 L(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:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(es)),this.isEmpty)return t.length?L.of(t):this;let l=new Zo(this,null,-1).goto(0),h=0,a=[],f=new ni;for(;l.value||h<t.length;)if(h<t.length&&(l.from-t[h].from||l.startSide-t[h].value.startSide)>=0){let c=t[h++];f.addInner(c.from,c.to,c.value)||a.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==t.length||this.chunkEnd(l.chunkIndex)<t[h].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&f.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||n>l.to||r<l.from||o(l.from,l.to,l.value))&&(f.addInner(l.from,l.to,l.value)||a.push(Zn.create(l.from,l.to,l.value))),l.next());return f.finishInner(this.nextLayer.isEmpty&&!a.length?L.empty:this.nextLayer.update({add:a,filter:o,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],a=e.touchesRange(l,l+h.length);if(a===!1)n=Math.max(n,h.maxPoint),t.push(h),i.push(e.mapPos(l));else if(a===!0){let{mapped:f,pos:c}=h.map(l,e);f&&(n=Math.max(n,f.maxPoint),t.push(f),i.push(c))}}let r=this.nextLayer.map(e);return t.length==0?r:new L(i,t,r||L.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return si.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return si.from(e).goto(t)}static compare(e,t,i,n,r=-1){let o=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),h=pr(o,l,i),a=new $t(o,h,r),f=new $t(l,h,r);i.iterGaps((c,u,d)=>gr(a,c,f,u,d,n)),i.empty&&i.length==0&&gr(a,0,f,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),o=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=pr(r,o),h=new $t(r,l,0).goto(i),a=new $t(o,l,0).goto(i);for(;;){if(h.to!=a.to||!ts(h.active,a.active)||h.point&&(!a.point||!Rs(h.point,a.point)))return!1;if(h.to>n)return!0;h.next(),a.next()}}static spans(e,t,i,n,r=-1){let o=new $t(e,null,r).goto(t),l=t,h=o.openStart;for(;;){let a=Math.min(o.to,i);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFrom<t?f.length+1:o.point.startSide<0?f.length:Math.min(f.length,h);n.point(l,a,o.point,f,c,o.pointRank),h=Math.min(o.openEnd(a),f.length)}else a>l&&(n.span(l,a,o.active,h),h=o.openEnd(a));if(o.to>i)return h+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new ni;for(let n of e instanceof Zn?[e]:t?ga(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return L.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=L.empty;n=n.nextLayer)t=new L(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}L.empty=new L([],[],null,-1);function ga(s){if(s.length>1)for(let e=s[0],t=1;t<s.length;t++){let i=s[t];if(es(e,i)>0)return s.slice().sort(es);e=i}return s}L.empty.nextLayer=L.empty;class ni{finishChunk(e){this.chunks.push(new Ns(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 ni)).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?!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=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(L.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=L.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function pr(s,e,t){let i=new Map;for(let r of s)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let n=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!t?.touchesRange(l,l+r.chunk[o].length)&&n.add(r.chunk[o])}return n}class Zo{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 n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<e||n.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}else{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 si{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Zo(o,t,i,r));return n.length==1?n[0]:new si(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 i=this.heap.length>>1;i>=0;i--)vn(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)vn(this.heap,i);(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(),vn(this.heap,0)}}}function vn(s,e){for(let t=s[e];;){let i=(e<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1<s.length&&n.compare(s[i+1])>=0&&(n=s[i+1],i++),t.compare(n)<0)break;s[i]=t,s[e]=n,e=i}}class $t{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=si.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){vi(this.active,e),vi(this.activeTo,e),vi(this.activeRank,e),this.minActive=mr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;Ai(this.active,t,i),Ai(this.activeTo,t,n),Ai(this.activeRank,t,r),e&&Ai(e,t,this.cursor.from),this.minActive=mr(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&&vi(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<e;n--)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 gr(s,e,t,i,n,r){s.goto(e),t.goto(i);let o=i+n,l=i,h=i-e,a=!!r.boundChange;for(let f=!1;;){let c=s.to+h-t.to,u=c||s.endSide-t.endSide,d=u<0?s.to+h:t.to,p=Math.min(d,o);if(s.point||t.point?(s.point&&t.point&&Rs(s.point,t.point)&&ts(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,p,s.point,t.point),f=!1):(f&&r.boundChange(l),p>l&&!ts(s.active,t.active)&&r.compareRange(l,p,s.active,t.active),a&&p<o&&(c||s.openEnd(d)!=t.openEnd(d))&&(f=!0)),d>o)break;l=d,u<=0&&s.next(),u>=0&&t.next()}}function ts(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(s[t]!=e[t]&&!Rs(s[t],e[t]))return!1;return!0}function vi(s,e){for(let t=e,i=s.length-1;t<i;t++)s[t]=s[t+1];s.pop()}function Ai(s,e,t){for(let i=s.length-1;i>=e;i--)s[i+1]=s[i];s[e]=t}function mr(s,e){let t=-1,i=1e9;for(let n=0;n<e.length;n++)(e[n]-i||s[n].endSide-s[t].endSide)<0&&(t=n,i=e[n]);return t}function hn(s,e,t=s.length){let i=0;for(let n=0;n<t&&n<s.length;)s.charCodeAt(n)==9?(i+=e-i%e,n++):(i++,n=ie(s,n));return i}function ma(s,e,t,i){for(let n=0,r=0;;){if(r>=e)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?t-r%t:1,n=ie(s,n)}return s.length}const is="ͼ",yr=typeof Symbol>"u"?"__"+is:Symbol.for(is),ns=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),br=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class it{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,a){let f=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,f,u)}else p!=null&&f.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(f.length||u)&&h.push((i&&!c&&!a?o.map(i):o).join(", ")+" {"+f.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(`
6
6
  `)}static newName(){let e=br[yr]||1;return br[yr]=e+1,is+e.toString(36)}static mount(e,t,i){let n=e[ns],r=i&&i.nonce;n?r&&n.setNonce(r):n=new ya(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let kr=new Map;class ya{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let r=kr.get(i);if(r)return e[ns]=r;this.sheet=new n.CSSStyleSheet,kr.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[ns]=this}mount(e,t){let i=this.sheet,n=0,r=0;for(let o=0;o<e.length;o++){let l=e[o],h=this.modules.indexOf(l);if(h<r&&h>-1&&(this.modules.splice(h,1),r--,h=-1),h==-1){if(this.modules.splice(r++,0,l),i)for(let a=0;a<l.rules.length;a++)i.insertRule(l.rules[a],n++)}else{for(;r<h;)n+=this.modules[r++].rules.length;n+=l.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let h=0;h<this.modules.length;h++)o+=this.modules[h].getRules()+`
7
- `;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var nt={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:"'"},ri={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ba=typeof navigator<"u"&&/Mac/.test(navigator.platform),ka=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ee=0;ee<10;ee++)nt[48+ee]=nt[96+ee]=String(ee);for(var ee=1;ee<=24;ee++)nt[ee+111]="F"+ee;for(var ee=65;ee<=90;ee++)nt[ee]=String.fromCharCode(ee+32),ri[ee]=String.fromCharCode(ee);for(var An in nt)ri.hasOwnProperty(An)||(ri[An]=nt[An]);function xa(s){var e=ba&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||ka&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?ri:nt)[s.keyCode]||s.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}let oe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},ss=typeof document<"u"?document:{documentElement:{style:{}}};const rs=/Edge\/(\d+)/.exec(oe.userAgent),el=/MSIE \d/.test(oe.userAgent),os=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oe.userAgent),an=!!(el||os||rs),xr=!an&&/gecko\/(\d+)/i.test(oe.userAgent),Cn=!an&&/Chrome\/(\d+)/.exec(oe.userAgent),wa="webkitFontSmoothing"in ss.documentElement.style,ls=!an&&/Apple Computer/.test(oe.vendor),wr=ls&&(/Mobile\/\w+/.test(oe.userAgent)||oe.maxTouchPoints>2);var S={mac:wr||/Mac/.test(oe.platform),windows:/Win/.test(oe.platform),linux:/Linux|X11/.test(oe.platform),ie:an,ie_version:el?ss.documentMode||6:os?+os[1]:rs?+rs[1]:0,gecko:xr,gecko_version:xr?+(/Firefox\/(\d+)/.exec(oe.userAgent)||[0,0])[1]:0,chrome:!!Cn,chrome_version:Cn?+Cn[1]:0,ios:wr,android:/Android\b/.test(oe.userAgent),webkit_version:wa?+(/\bAppleWebKit\/(\d+)/.exec(oe.userAgent)||[0,0])[1]:0,safari:ls,safari_version:ls?+(/\bVersion\/(\d+(\.\d+)?)/.exec(oe.userAgent)||[0,0])[1]:0,tabSize:ss.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Fs(s,e){for(let t in s)t=="class"&&e.class?e.class+=" "+s.class:t=="style"&&e.style?e.style+=";"+s.style:e[t]=s[t];return e}const Ui=Object.create(null);function Ws(s,e,t){if(s==e)return!0;s||(s=Ui),e||(e=Ui);let i=Object.keys(s),n=Object.keys(e);if(i.length-0!=n.length-0)return!1;for(let r of i)if(r!=t&&(n.indexOf(r)==-1||s[r]!==e[r]))return!1;return!0}function Sa(s,e){for(let t=s.attributes.length-1;t>=0;t--){let i=s.attributes[t].name;e[i]==null&&s.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?s.style.cssText=i:s.getAttribute(t)!=i&&s.setAttribute(t,i)}}function Sr(s,e,t){let i=!1;if(e)for(let n in e)t&&n in t||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(t)for(let n in t)e&&e[n]==t[n]||(i=!0,n=="style"?s.style.cssText=t[n]:s.setAttribute(n,t[n]));return i}function va(s){let e=Object.create(null);for(let t=0;t<s.attributes.length;t++){let i=s.attributes[t];e[i.name]=i.value}return e}class Wt{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ce=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(ce||(ce={}));class z extends tt{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new gi(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new gt(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,n;if(e.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=tl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new gt(e,i,n,t,e.widget||null,!0)}static line(e){return new mi(e)}static set(e,t=!1){return L.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}z.none=L.empty;class gi extends z{constructor(e){let{start:t,end:i}=tl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Fs(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Ui}eq(e){return this==e||e instanceof gi&&this.tagName==e.tagName&&Ws(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}gi.prototype.point=!1;class mi extends z{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof mi&&this.spec.class==e.spec.class&&Ws(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}mi.prototype.mapMode=le.TrackBefore;mi.prototype.point=!0;class gt extends z{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?le.TrackBefore:le.TrackAfter:le.TrackDel}get type(){return this.startSide!=this.endSide?ce.WidgetRange:this.startSide<=0?ce.WidgetBefore:ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof gt&&Aa(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}gt.prototype.point=!0;function tl(s,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=s;return t==null&&(t=s.inclusive),i==null&&(i=s.inclusive),{start:t??e,end:i??e}}function Aa(s,e){return s==e||!!(s&&e&&s.compare(e))}function Mt(s,e,t,i=0){let n=t.length-1;n>=0&&t[n]+i>=s?t[n]=Math.max(t[n],e):t.push(s,e)}class oi extends tt{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof oi&&this.tagName==e.tagName&&Ws(this.attributes,e.attributes)}static create(e){return new oi(e.tagName,e.attributes||Ui)}static set(e,t=!1){return L.of(e,t)}}oi.prototype.startSide=oi.prototype.endSide=-1;function li(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function hs(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function Qt(s,e){if(!e.anchorNode)return!1;try{return hs(s,e.anchorNode)}catch{return!1}}function Zt(s){return s.nodeType==3?ai(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ei(s,e,t,i){return t?vr(s,e,t,i,-1)||vr(s,e,t,i,1):!1}function st(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function Gi(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function vr(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:Ue(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=st(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[e+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;e=n<0?Ue(s):0}else return!1}}function Ue(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function hi(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function Ca(s){let e=s.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function il(s,e){let t=e.width/s.offsetWidth,i=e.height/s.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-s.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-s.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Ma(s,e,t,i,n,r,o,l){let h=s.ownerDocument,a=h.defaultView||window;for(let f=s,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==h.body,p=1,g=1;if(d)u=Ca(a);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let k=f.getBoundingClientRect();({scaleX:p,scaleY:g}=il(f,k)),u={left:k.left,right:k.left+f.clientWidth*p,top:k.top,bottom:k.top+f.clientHeight*g}}let m=0,y=0;if(n=="nearest")e.top<u.top+o?(y=e.top-(u.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=e.top-(u.top+o)));else{let k=e.bottom-e.top,v=u.bottom-u.top;y=(n=="center"&&k<=v?e.top+k/2-v/2:n=="start"||n=="center"&&t<0?e.top-o:e.bottom-v+o)-u.top}if(i=="nearest"?e.left<u.left+r?(m=e.left-(u.left+r),t>0&&e.right>u.right+m&&(m=e.right-u.right+r)):e.right>u.right-r&&(m=e.right-u.right+r,t<0&&e.left<u.left+m&&(m=e.left-(u.left+r))):m=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,m||y)if(d)a.scrollBy(m,y);else{let k=0,v=0;if(y){let P=f.scrollTop;f.scrollTop+=y/g,v=(f.scrollTop-P)*g}if(m){let P=f.scrollLeft;f.scrollLeft+=m/p,k=(f.scrollLeft-P)*p}e={left:e.left-k,top:e.top-v,right:e.right-k,bottom:e.bottom-v},k&&Math.abs(k-m)<1&&(i="nearest"),v&&Math.abs(v-y)<1&&(n="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function nl(s,e=!0){let t=s.ownerDocument,i=null,n=null;for(let r=s.parentNode;r&&!(r==t.body||(!e||i)&&n);)if(r.nodeType==1)!n&&r.scrollHeight>r.clientHeight&&(n=r),e&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:n}}class Ta{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Ue(t):0),i,Math.min(e.focusOffset,i?Ue(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let ft=null;S.safari&&S.safari_version>=26&&(ft=!1);function sl(s){if(s.setActive)return s.setActive();if(ft)return s.focus(ft);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(ft==null?{get preventScroll(){return ft={preventScroll:!0},!0}}:void 0),!ft){ft=!1;for(let t=0;t<e.length;){let i=e[t++],n=e[t++],r=e[t++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Ar;function ai(s,e,t=e){let i=Ar||(Ar=document.createRange());return i.setEnd(s,t),i.setStart(s,e),i}function Tt(s,e,t,i){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Da(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Oa(s,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Ue(t));;)if(i){if(t.nodeType!=1)return!1;let n=t.childNodes[i-1];n.contentEditable=="false"?i--:(t=n,i=Ue(t))}else{if(t==s)return!0;i=st(t),t=t.parentNode}}function rl(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function ol(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=Ue(t)}else if(t.parentNode&&!Gi(t))i=st(t),t=t.parentNode;else return null}}function ll(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Gi(t))i=st(t)+1,t=t.parentNode;else return null}}class Ae{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Ae(e.parentNode,st(e),t)}static after(e,t){return new Ae(e.parentNode,st(e)+1,t)}}var Y=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(Y||(Y={}));const mt=Y.LTR,Hs=Y.RTL;function hl(s){let e=[];for(let t=0;t<s.length;t++)e.push(1<<+s[t]);return e}const Ba=hl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Pa=hl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),as=Object.create(null),Oe=[];for(let s of["()","[]","{}"]){let e=s.charCodeAt(0),t=s.charCodeAt(1);as[e]=t,as[t]=-e}function al(s){return s<=247?Ba[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?Pa[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const Ia=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Re{get dir(){return this.level%2?Hs:mt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function fl(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++){let i=s[t],n=e[t];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!fl(i.inner,n.inner))return!1}return!0}const W=[];function Ea(s,e,t,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,h=r?256:n;for(let a=o,f=h,c=h;a<l;a++){let u=al(s.charCodeAt(a));u==512?u=f:u==8&&c==4&&(u=16),W[a]=u==4?2:u,u&7&&(c=u),f=u}for(let a=o,f=h,c=h;a<l;a++){let u=W[a];if(u==128)a<l-1&&f==W[a+1]&&f&24?u=W[a]=f:W[a]=256;else if(u==64){let d=a+1;for(;d<l&&W[d]==64;)d++;let p=a&&f==8||d<t&&W[d]==8?c==1?1:8:256;for(let g=a;g<d;g++)W[g]=p;a=d-1}else u==8&&c==1&&(W[a]=1);f=u,u&7&&(c=u)}}}function La(s,e,t,i,n){let r=n==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let a=o?i[o-1].to:e,f=o<i.length?i[o].from:t;for(let c=a,u,d,p;c<f;c++)if(d=as[u=s.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(Oe[g+1]==-d){let m=Oe[g+2],y=m&2?n:m&4?m&1?r:n:0;y&&(W[c]=W[Oe[g]]=y),l=g;break}}else{if(Oe.length==189)break;Oe[l++]=c,Oe[l++]=u,Oe[l++]=h}else if((p=W[c])==2||p==1){let g=p==n;h=g?0:1;for(let m=l-3;m>=0;m-=3){let y=Oe[m+2];if(y&2)break;if(g)Oe[m+2]|=2;else{if(y&4)break;Oe[m+2]|=4}}}}}function Ra(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=n<t.length?t[n].from:e;for(let h=o;h<l;){let a=W[h];if(a==256){let f=h+1;for(;;)if(f==l){if(n==t.length)break;f=t[n++].to,l=n<t.length?t[n].from:e}else if(W[f]==256)f++;else break;let c=r==1,u=(f<e?W[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,g=n,m=g?t[g-1].to:s;p>h;)p==m&&(p=t[--g].from,m=g?t[g-1].to:s),W[--p]=d;h=f}else r=a,h++}}}function fs(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let h=e,a=0;h<t;){let f=!0,c=!1;if(a==r.length||h<r[a].from){let g=W[h];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;e:for(;;)if(a<r.length&&p==r[a].from){if(c)break e;let g=r[a];if(!f)for(let m=g.to,y=a+1;;){if(m==t)break e;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(W[m]==l)break e;break}}if(a++,u)u.push(g);else{g.from>h&&o.push(new Re(h,g.from,d));let m=g.direction==mt!=!(d%2);cs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==t||(f?W[p]!=l:W[p]==l))break;p++}u?fs(s,h,p,i+1,n,u,o):h<p&&o.push(new Re(h,p,d)),h=p}else for(let h=t,a=r.length;h>e;){let f=!0,c=!1;if(!a||h>r[a-1].to){let g=W[h-1];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;e:for(;;)if(a&&p==r[a-1].to){if(c)break e;let g=r[--a];if(!f)for(let m=g.from,y=a;;){if(m==e)break e;if(y&&r[y-1].to==m)m=r[--y].from;else{if(W[m-1]==l)break e;break}}if(u)u.push(g);else{g.to<h&&o.push(new Re(g.to,h,d));let m=g.direction==mt!=!(d%2);cs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==e||(f?W[p-1]!=l:W[p-1]==l))break;p--}u?fs(s,p,h,i+1,n,u,o):p<h&&o.push(new Re(p,h,d)),h=p}}function cs(s,e,t,i,n,r,o){let l=e%2?2:1;Ea(s,n,r,i,l),La(s,n,r,i,l),Ra(n,r,i,l),fs(s,n,r,e,t,i,o)}function Na(s,e,t){if(!s)return[new Re(0,0,e==Hs?1:0)];if(e==mt&&!t.length&&!Ia.test(s))return cl(s.length);if(t.length)for(;s.length>W.length;)W[W.length]=256;let i=[],n=e==mt?0:1;return cs(s,n,n,t,0,s.length,i),i}function cl(s){return[new Re(0,s,0)]}let ul="";function Fa(s,e,t,i,n){var r;let o=i.head-s.from,l=Re.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),h=e[l],a=h.side(n,t);if(o==a){let u=l+=n?1:-1;if(u<0||u>=e.length)return null;h=e[l=u],o=h.side(!n,t),a=h.side(n,t)}let f=ie(s.text,o,h.forward(n,t));(f<h.from||f>h.to)&&(f=a),ul=s.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return c&&f==a&&c.level+(n?0:1)<h.level?b.cursor(c.side(!n,t)+s.from,c.forward(n,t)?1:-1,c.level):b.cursor(f+s.from,h.forward(n,t)?-1:1,h.level)}function Wa(s,e,t){for(let i=e;i<t;i++){let n=al(s.charCodeAt(i));if(n==1)return mt;if(n==2||n==4)return Hs}return mt}const dl=A.define(),pl=A.define(),gl=A.define(),ml=A.define(),us=A.define(),yl=A.define(),bl=A.define(),Vs=A.define(),zs=A.define(),kl=A.define({combine:s=>s.some(e=>e)}),Ha=A.define({combine:s=>s.some(e=>e)}),xl=A.define();class Dt{constructor(e,t,i,n,r,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Dt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Dt(b.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ci=q.define({map:(s,e)=>s.map(e)}),wl=q.define();function Ne(s,e,t){let i=s.facet(ml);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const Ke=A.define({combine:s=>s.length?s[0]:!0});let Va=0;const St=A.define({combine(s){return s.filter((e,t)=>{for(let i=0;i<t;i++)if(s[i].plugin==e.plugin)return!1;return!0})}});class Ge{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(St.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(St.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=t||{};return new Ge(Va++,e,i,n,l=>{let h=[];return o&&h.push(fn.of(a=>{let f=a.plugin(l);return f?o(f):z.none})),r&&h.push(r(l)),h})}static fromClass(e,t){return Ge.define((i,n)=>new e(i,n),t)}}class Mn{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(Ne(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Ne(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){Ne(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Sl=A.define(),Ks=A.define(),fn=A.define(),vl=A.define(),$s=A.define(),yi=A.define(),Al=A.define();function Cr(s,e){let t=s.state.facet(Al);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return L.spans(i,e.from,e.to,{point(){},span(r,o,l,h){let a=r-e.from,f=o-e.from,c=n;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Wa(e.text,a,f)),h>0&&c.length&&(p=c[c.length-1]).to==a&&p.direction==d)p.to=f,c=p.inner;else{let g={from:a,to:f,direction:d,inner:[]};c.push(g),c=g.inner}}}}),n}const Cl=A.define();function Ml(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(Cl)){let o=r(s);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:e,right:t,top:i,bottom:n}}const Gt=A.define();class ye{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new ye(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let n=0,r=0,o=0;;){let l=n<e.length?e[n].fromB:1e9,h=r<t.length?t[r]:1e9,a=Math.min(l,h);if(a==1e9)break;let f=a+o,c=a,u=f;for(;;)if(r<t.length&&t[r]<=c){let d=t[r+1];r+=2,c=Math.max(c,d);for(let p=n;p<e.length&&e[p].fromB<=c;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(n<e.length&&e[n].fromB<=c){let d=e[n++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new ye(f,u,a,c))}return i}}class Ji{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=X.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,h)=>n.push(new ye(r,o,l,h))),this.changedRanges=n}static create(e,t,i){return new Ji(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const za=[];class G{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return za}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&Sa(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let n of this.children){if(n==e)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=st(this.dom),n=this.length?e>0:t>0;return new Ae(this.parent.dom,i+(n?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof un)return e;return null}static get(e){return e.cmTile}}class cn extends G{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,n,r=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,n=i?i.nextSibling:t.firstChild,r&&n!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;n&&n!=l.dom;)n=Mr(n);else t.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:t.firstChild,r&&n&&(r.written=!0);n;)n=Mr(n);this.length=o}}function Mr(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class un extends cn{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=G.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let o=i.children[n++];if(o instanceof qe)t.push(n),i=o,n=0;else{let l=r+o.length,h=e(o,r);if(h!==void 0)return h;r=l+o.breakAfter}}}resolveBlock(e,t){let i,n=-1,r,o=-1;if(this.blockTiles((l,h)=>{let a=h+l.length;if(e>=h&&e<=a){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(h<e||e==a&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,n=e-h),(a>e||e==h&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-h)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:n}:{tile:r,offset:o}}}class qe extends cn{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new qe(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class It extends cn{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new It(t||document.createElement("div"),e);return(!t||!i)&&(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(e,t,i){let n=null,r=-1,o=null,l=-1;function h(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],g=d+p.length;g>=c&&(p.isComposite()?h(p,c-d):(!o||o.isHidden&&(t>0||i&&$a(o,p)))&&(g>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(n=p,r=c-d)),d=g}}h(this,e);let a=(t<0?n:o)||n||o;return a?{tile:a,offset:a==n?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):Ka(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:n,offset:r}=i;if(this.dom.contains(n.dom))return n.isText()?new Ae(n.dom,Math.min(n.dom.nodeValue.length,r)):n.domPosFor(r,n.flags&16?1:n.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let h of o.children){if(l)return new Ae(h.dom,0);h==i.tile&&(l=!0)}}return new Ae(this.dom,0)}}function Ka(s){let e=s.dom.lastChild;if(!e)return s.dom.getBoundingClientRect();let t=Zt(e);return t[t.length-1]||null}function $a(s,e){let t=s.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class ae extends cn{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new ae(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class dt extends G{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?S.chrome||S.gecko||(e?(n--,o=1):r<i&&(r++,o=-1)):t<0?n--:r<i&&r++;let l=ai(this.dom,n,r).getClientRects();if(!l.length)return null;let h=l[(o?o<0:t>=0)?0:l.length-1];return S.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?hi(h,o<0):h||null}static of(e,t){let i=new dt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class yt extends G{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return hi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let h=l?r.length-1:0;o=r[h],!(e>0?h==0:h==r.length-1||o.top<o.bottom);h+=l?-1:1);return hi(o,!l)}}get overrideDOMText(){if(!this.length)return E.empty;let{root:e}=this;if(!e)return E.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new yt(r,i,e,n)}}class Yi extends G{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return E.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class qa{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(n.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==n.children.length){if(!e&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let h=n.children[r],a=h.breakAfter;(t>0?h.length<=e:h.length<e)&&(!i||i.skip(h,0,h.length)!==!1||!h.isComposite)?(o=!!a,r++,e-=h.length):(l.push({tile:n,index:r}),n=h,r=0,i&&h.isComposite()&&i.enter(h))}else if(r==n.length)o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++;else if(e){let h=Math.min(e,n.length-r);i&&i.skip(n,r,r+h),e-=h,r+=h}else break;return this.tile=n,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class ja{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class Ua{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let h=o.children[o.children.length-1]=new dt(l.dom,l.text+e);h.parent=o}else o.append(n||dt.of(e,(r=this.cache.find(dt))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Tn(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let l=t.marks.length-1;l>=0;l--){let h=t.marks[l],a=n.lastChild;if(a instanceof ae&&a.mark.eq(h.mark))a.dom!=h.dom&&a.setDOM(Tn(h.dom)),n=a;else{if(this.cache.reused.get(h)){let c=G.get(h.dom);c&&c.setDOM(Tn(h.dom))}let f=ae.of(h.mark,h.dom);n.append(f),n=f}this.cache.reused.set(h,2)}let r=G.get(e.text);r&&this.cache.reused.set(r,2);let o=new dt(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,n.append(o)}addInlineWidget(e,t,i){let n=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);n||this.flushBuffer();let r=this.ensureMarks(t,i);!n&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=Tl);let n=It.start(e,t||((i=this.cache.find(It))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let n=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=n.lastChild)&&l instanceof ae&&l.mark.eq(o))n=l,t--;else{let h=ae.of(o,(i=this.cache.find(ae,a=>a.mark.eq(o)))===null||i===void 0?void 0:i.dom);n.append(h),n=h,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Tr(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(S.ios&&Tr(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Dn,0,32)||new yt(Dn.toDOM(),0,Dn,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new ja(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof qe&&n.wrapper.eq(i.wrapper))t=n;else{let r=qe.of(i.wrapper,(e=this.cache.find(qe,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(Yi,void 0,1);return i&&(i.flags=t),i||new Yi(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Ga{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:n,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=n;let l=this.textOff=Math.min(e,n.length);return r?null:n.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const _i=[yt,It,dt,ae,Yi,qe,un];for(let s=0;s<_i.length;s++)_i[s].bucket=s;class Ja{constructor(e){this.view=e,this.buckets=_i.map(()=>[]),this.index=_i.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let n=e.bucket,r=this.buckets[n],o=this.index[n];for(let l=r.length-1;l>=0;l--){let h=(l+o)%r.length,a=r[h];if((!t||t(a))&&!this.reused.has(a))return r.splice(h,1),h<o&&this.index[n]--,this.reused.set(a,i),a}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,o=0;;r++){if(r==n.length){if(o)return null;o=1,r=0}let l=n[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new yt(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class Ya{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new Ja(e),this.text=new Ga(e.state.doc),this.builder=new Ua(this.cache,new un(e,e.contentDOM),L.iter(i)),this.cache.reused.set(t,2),this.old=new qa(t),this.reuseWalker={skip:(o,l,h)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let n=0,r=0,o=0;;){let l=o<e.length?e[o++]:null,h=l?l.fromA:this.old.root.length;if(h>n){let a=h-n;this.preserve(a,!o,!l),n=h,r+=a}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,n=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=Qa(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,h)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(h-l);else{let a=h>0||l<o.length?yt.of(o.widget,this.view,h-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,n,r),r=n.length)}else if(o.isText())this.builder.ensureLine(null),!l&&h==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,n,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,h),n,r)),r=n.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Yi)this.cache.add(o);else if(o instanceof ae)this.builder.ensureLine(null),this.builder.addMark(o,n,r),this.cache.reused.set(o,1),r=n.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof ae&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof ae&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,n=this.builder,r=0,o=L.spans(this.decorations,e,t,{point:(l,h,a,f,c,u)=>{if(a instanceof gt){if(this.disallowBlockEffectsFor[u]){if(a.block)throw new RangeError("Block decorations may not be specified via plugins");if(h>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=f.length,c>f.length)n.continueWidget(h-l);else{let d=a.widget||(a.block?Et.block:Et.inline),p=_a(a),g=this.cache.findWidget(d,h-l,p)||yt.of(d,this.view,h-l,p);a.block?(a.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(g)):(n.ensureLine(i),n.addInlineWidget(g,f,c))}i=null}else i=Xa(i,a);h>l&&this.text.skip(h-l)},span:(l,h,a,f)=>{for(let c=l;c<h;){let u=this.text.next(Math.min(512,h-c));u==null?(n.addLineStartIfNotCovered(i),n.addBreak(),c++):(n.ensureLine(i),n.addText(u,a,c==l?f:a.length),c+=u.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let r=G.get(n);if(n==this.view.contentDOM)break;r instanceof ae?t.push(r):r?.isLine()?i=r:r instanceof qe||(n.nodeName=="DIV"&&!i&&n!=this.view.contentDOM?i=new It(n,Tl):i||t.push(ae.of(new gi({tagName:n.nodeName.toLowerCase(),attributes:va(n)}),n)))}return{line:i,marks:t}}}function Tr(s,e){let t=i=>{for(let n of i.children)if((e?n.isText():n.length)||t(n))return!0;return!1};return t(s)}function _a(s){let e=s.isReplace?(s.startSide<0?64:0)|(s.endSide>0?128:0):s.startSide>0?32:16;return s.block&&(e|=256),e}const Tl={class:"cm-line"};function Xa(s,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(s||(s={class:"cm-line"}),t&&Fs(t,s),i&&(s.class+=" "+i)),s}function Qa(s){let e=[];for(let t=s.parents.length;t>1;t--){let i=t==s.parents.length?s.tile:s.parents[t].tile;i instanceof ae&&e.push(i.mark)}return e}function Tn(s){let e=G.get(s);return e&&e.setDOM(s.cloneNode()),s}class Et extends Wt{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Et.inline=new Et("span");Et.block=new Et("div");const Dn=new class extends Wt{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Dr{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=z.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new un(e,e.contentDOM),this.updateInner([new ye(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?n=this.domChanged.newSel.head:!hf(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?ef(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new ye(f,c,e.changes.mapPos(f,-1),e.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(S.ie||S.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let h=sf(o,this.decorations,e.changes);h.length&&(i=ye.extendWithRanges(i,h));let a=of(l,this.blockWrappers,e.changes);return a.length&&(i=ye.extendWithRanges(i,a)),r&&!i.some(f=>f.fromA<=r.range.fromA&&f.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new Ya(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&G.get(t.text)&&l.cache.reused.set(G.get(t.text),2),this.tile=l.run(e,t),ds(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=S.chrome||S.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof On&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(wl)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,o=!r&&!(this.view.state.facet(Ke)||i.tabIndex>-1)&&Qt(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,a,f;if(h.empty?f=a=this.inlineDOMNearPos(h.anchor,h.assoc||1):(f=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),a=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),S.gecko&&h.empty&&!this.hasComposition&&Za(a)){let u=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(u,a.node.childNodes[a.offset]||null)),a=f=new Ae(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!ei(a.node,a.offset,c.anchorNode,c.anchorOffset)||!ei(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,h))&&(this.view.observer.ignore(()=>{S.android&&S.chrome&&i.contains(c.focusNode)&&lf(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=li(this.view.root);if(u)if(h.empty){if(S.gecko){let d=tf(a.node,a.offset);if(d&&d!=3){let p=(d==1?ol:ll)(a.node,a.offset);p&&(a=new Ae(p.node,p.offset))}}u.collapse(a.node,a.offset),h.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=h.bidiLevel)}else if(u.extend){u.collapse(a.node,a.offset);try{u.extend(f.node,f.offset)}catch{}}else{let d=document.createRange();h.anchor>h.head&&([a,f]=[f,a]),d.setEnd(f.node,f.offset),d.setStart(a.node,a.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new Ae(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new Ae(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ei(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=li(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let h=this.coordsAt(t.head,-1),a=this.coordsAt(t.head,1);if(!h||!a||h.bottom>a.top)return;let f=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(f.node,f.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let n=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=Ue(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!G.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let h=i.children[o];if(h.dom==r)return l;l+=h.length+h.breakAfter}}else return i.isText()?e==i.dom?n+t:n+(t?i.length:0):n}domAtPos(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(n,t)}inlineDOMNearPos(e,t){let i,n=-1,r=!1,o,l=-1,h=!1;return this.tile.blockTiles((a,f)=>{if(a.isWidget()){if(a.flags&32&&f>=e)return!0;a.flags&16&&(r=!0)}else{let c=f+a.length;if(f<=e&&(i=a,n=e-f,r=c<e),c>=e&&!o&&(o=a,l=e-f,h=f>e),f>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:h&&i&&(o=null),i&&t<0||!o?i.domIn(n,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof On?null:i.coordsInWidget(n,t,!0):i.coordsIn(n,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function n(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let h=n(l,o);if(h)return h}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=ie(r.text,o);if(l==o)return null;let h=ai(r.dom,o,l).getClientRects();for(let a=0;a<h.length;a++){let f=h[a];if(a==h.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return n(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==Y.LTR,a=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>n);p++){let g=c.children[p],m=u+g.length,y=g.dom.getBoundingClientRect(),{height:k}=y;if(d&&!p&&(a+=y.top-d.top),g instanceof qe)m>i&&f(g,u,y);else if(u>=i&&(a>0&&t.push(-a),t.push(k+a),a=0,o)){let v=g.dom.lastChild,P=v?Zt(v):[];if(P.length){let M=P[P.length-1],T=h?M.right-y.left:y.right-M.left;T>l&&(l=T,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=m)}}d&&p==c.children.length-1&&(a+=d.bottom-y.bottom),u=m+g.breakAfter}};return f(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Y.RTL:Y.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,h;for(let a of o.children){if(!a.isText()||/[^ -~]/.test(a.text))return;let f=Zt(a.dom);if(f.length!=1)return;l+=f[0].width,h=f[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:h}}});if(e)return e;let t=document.createElement("div"),i,n,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Zt(t.firstChild)[0];i=t.getBoundingClientRect().height,n=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:n,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(z.replace({widget:new On(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return z.set(e)}updateDeco(){let e=1,t=this.view.state.facet(fn).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet($s).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[e++]=i,t.push(L.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(vl).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(xl))try{if(f(this.view,e.range,e))return!0}catch(c){Ne(this.view.state,c,"scroll handler")}let{range:i}=e,n=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!n)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let o=Ml(this.view),l={left:n.left-o.left,top:n.top-o.top,right:n.right+o.right,bottom:n.bottom+o.bottom},{offsetWidth:h,offsetHeight:a}=this.view.scrollDOM;if(Ma(this.view.scrollDOM,l,i.head<i.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,h),-h),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==Y.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(i.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){ds(this.tile)}}function ds(s,e){let t=e?.get(s);if(t!=1){t==null&&s.destroy();for(let i of s.children)ds(i,e)}}function Za(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}function Dl(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=ol(t.focusNode,t.focusOffset),n=ll(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=G.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let h=G.get(i.node);!h||h.isText()&&h.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function ef(s,e,t){let i=Dl(s,t);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let h=e.invertedDesc;return{range:new ye(h.mapPos(r),h.mapPos(o),r,o),text:n}}function tf(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e<s.childNodes.length&&s.childNodes[e].contentEditable=="false"?2:0)}let nf=class{constructor(){this.changes=[]}compareRange(e,t){Mt(e,t,this.changes)}comparePoint(e,t){Mt(e,t,this.changes)}boundChange(e){Mt(e,e,this.changes)}};function sf(s,e,t){let i=new nf;return L.compare(s,e,t,i),i.changes}class rf{constructor(){this.changes=[]}compareRange(e,t){Mt(e,t,this.changes)}comparePoint(){}boundChange(e){Mt(e,e,this.changes)}}function of(s,e,t){let i=new rf;return L.compare(s,e,t,i),i.changes}function lf(s,e){for(let t=s;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function hf(s,e){let t=!1;return e&&s.iterChangedRanges((i,n)=>{i<e.to&&n>e.from&&(t=!0)}),t}class On extends Wt{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function af(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return b.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=ie(n.text,r,!1):l=ie(n.text,r);let h=i(n.text.slice(o,l));for(;o>0;){let a=ie(n.text,o,!1);if(i(n.text.slice(a,o))!=h)break;o=a}for(;l<n.length;){let a=ie(n.text,l);if(i(n.text.slice(l,a))!=h)break;l=a}return b.range(o+n.from,l+n.from)}function ff(s,e,t,i,n){let r=Math.round((i-e.left)*s.defaultCharacterWidth);if(s.lineWrapping&&t.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,h=Math.floor((n-t.top-(s.defaultLineHeight-l)*.5)/l);r+=h*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(t.from,t.to);return t.from+ma(o,r,s.state.tabSize)}function cf(s,e,t){let i=s.lineBlockAt(e);if(Array.isArray(i.type)){let n;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!n||r.type==ce.Text&&(n.type!=r.type||(t<0?r.from<e:r.to>e)))&&(n=r)}}return n||i}return i}function uf(s,e,t,i){let n=cf(s,e.head,e.assoc||-1),r=!i||n.type!=ce.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),h=s.posAtCoords({x:t==(l==Y.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(h!=null)return b.cursor(h,t?-1:1)}return b.cursor(t?n.to:n.from,t?-1:1)}function Or(s,e,t,i){let n=s.state.doc.lineAt(e.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=e,h=null;;){let a=Fa(n,r,o,l,t),f=ul;if(!a){if(n.number==(t?s.state.doc.lines:1))return l;f=`
8
- `,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),a=s.visualLineSide(n,!t)}if(h){if(!h(f))return l}else{if(!i)return a;h=i(f)}l=a}}function df(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==$e.Space&&(n=o),n==o}}function pf(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return b.cursor(n,e.assoc);let o=e.goalColumn,l,h=s.contentDOM.getBoundingClientRect(),a=s.coordsAtPos(n,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),f=s.documentTop;if(a)o==null&&(o=a.left-h.left),l=r<0?a.top:a.bottom;else{let p=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(h.right-h.left,s.defaultCharacterWidth*(n-p.from))),l=(r<0?p.top:p.bottom)+f}let c=h.left+o,u=s.viewState.heightOracle.textHeight>>1,d=i??u;for(let p=0;;p+=u){let g=l+(d+p)*r,m=ps(s,{x:c,y:g},!1,r);if(t?g>h.bottom:g<h.top)return b.cursor(m.pos,m.assoc);let y=s.coordsAtPos(m.pos,m.assoc),k=y?(y.top+y.bottom)/2:0;if(!y||(t?k>l:k<l))return b.cursor(m.pos,m.assoc,void 0,o)}}function ti(s,e,t){for(;;){let i=0;for(let n of s)n.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let h=i||t||(e-r<o-e?-1:1);e=h<0?r:o,i=h}});if(!i)return e}}function Ol(s,e){let t=null;for(let i=0;i<e.ranges.length;i++){let n=e.ranges[i],r=null;if(n.empty){let o=ti(s,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=ti(s,n.from,-1),l=ti(s,n.to,1);(o!=n.from||l!=n.to)&&(r=b.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}function Bn(s,e,t){let i=ti(s.state.facet(yi).map(n=>n(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class Le{constructor(e,t){this.pos=e,this.assoc=t}}function ps(s,e,t,i){let n=s.contentDOM.getBoundingClientRect(),r=n.top+s.viewState.paddingTop,{x:o,y:l}=e,h=l-r,a;for(;;){if(h<0)return new Le(0,1);if(h>s.viewState.docHeight)return new Le(s.state.doc.length,-1);if(a=s.elementAtHeight(h),i==null)break;if(a.type==ce.Text){if(i<0?a.to<s.viewport.from:a.from>s.viewport.to)break;let u=s.docView.coordsAt(i<0?a.from:a.to,i>0?-1:1);if(u&&(i<0?u.top<=h+r:u.bottom>=h+r))break}let c=s.viewState.heightOracle.textHeight/2;h=i>0?a.bottom+c:a.top-c}if(s.viewport.from>=a.to||s.viewport.to<=a.from){if(t)return null;if(a.type==ce.Text){let c=ff(s,n,a,o,l);return new Le(c,c==a.from?1:-1)}}if(a.type!=ce.Text)return h<(a.top+a.bottom)/2?new Le(a.from,1):new Le(a.to,-1);let f=s.docView.lineAt(a.from,2);return(!f||f.length!=a.length)&&(f=s.docView.lineAt(a.from,-2)),new gf(s,o,l,s.textDirectionAt(a.from)).scanTile(f,a.from)}class gf{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Re.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Re.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t,i=!1){let n=0,r=e.length-1,o=new Set,l=this.bidiIn(e[0],e[r]),h,a,f=-1,c=1e9,u;e:for(;n<r;){let p=r-n,g=n+r>>1;t:if(o.has(g)){let y=n+Math.floor(Math.random()*p);for(let k=0;k<p;k++){if(!o.has(y)){g=y;break t}y++,y==r&&(y=n)}break e}o.add(g);let m=t(g);if(m)for(let y=0;y<m.length;y++){let k=m[y],v=0;if(!(k.width==0&&m.length>1)){if(k.bottom<this.y)(!h||h.bottom<k.bottom)&&(h=k),v=1;else if(k.top>this.y)(!a||a.top>k.top)&&(a=k),v=-1;else{let P=k.left>this.x?this.x-k.left:k.right<this.x?this.x-k.right:0,M=Math.abs(P);M<c&&(f=g,c=M,u=k),P&&(v=P<0==(this.baseDir==Y.LTR)?-1:1)}v==-1&&(!l||this.baseDirAt(e[g],1))?r=g:v==1&&(!l||this.baseDirAt(e[g+1],-1))&&(n=g+1)}}}if(!u){let p=h&&(!a||this.y-h.bottom<a.top-this.y)?h:a;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(c&&!i){let{top:p,bottom:g}=u;if(h&&h.bottom>(p+p+g)/3)return this.y=h.bottom-1,this.scan(e,t,!0);if(a&&a.top<(p+g+g)/3)return this.y=a.top+1,this.scan(e,t,!0)}let d=(l?this.dirAt(e[f],1):this.baseDir)==Y.LTR;return{i:f,after:this.x>(u.left+u.right)/2==d}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=ie(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return ai(e.dom,o,l).getClientRects()});return n.after?new Le(i[n.i+1],-1):new Le(i[n.i],1)}scanTile(e,t){if(!e.length)return new Le(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,h=t;l<e.children.length;l++)i.push(h+=e.children[l].length);let n=this.scan(i,l=>{let h=e.children[l];return h.flags&48?null:(h.dom.nodeType==1?h.dom:ai(h.dom,0,h.length)).getClientRects()}),r=e.children[n.i],o=i[n.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):n.after?new Le(i[n.i+1],-1):new Le(o,1)}}const wt="￿";class mf{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(N.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=wt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=G.get(n),l=n.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let h=G.get(l);(o&&h?o.breakAfter:(o?o.breakAfter:Gi(n))||Gi(l)&&(n.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!bf(l,t)&&this.lineBreak(),n=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==e&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(e){let t=G.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(yf(e,i.node,i.offset)?t:0))}}function yf(s,e,t){for(;;){if(!e||t<Ue(e))return!1;if(e==s)return!0;t=st(e)+1,e=e.parentNode}}function bf(s,e){let t;for(;!(s==e||!s);s=s.nextSibling){let i=G.get(s);if(!i?.isWidget())return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let n=i.overrideDOMText;if(n?.length)return!1}return!0}class Br{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class kf{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Bl(e.docView.tile,t,i,0))){let h=r||o?[]:wf(e),a=new mf(h,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Sf(h,this.bounds.from)}else{let h=e.observer.selectionRange,a=r&&r.node==h.focusNode&&r.offset==h.focusOffset||!hs(e.contentDOM,h.focusNode)?l.main.head:e.docView.posFromDOM(h.focusNode,h.focusOffset),f=o&&o.node==h.anchorNode&&o.offset==h.anchorOffset||!hs(e.contentDOM,h.anchorNode)?l.main.anchor:e.docView.posFromDOM(h.anchorNode,h.anchorOffset),c=e.viewport;if((S.ios||S.chrome)&&l.main.empty&&a!=f&&(c.from>0||c.to<e.state.doc.length)){let u=Math.min(a,f),d=Math.max(a,f),p=c.from-u,g=c.to-d;(p==0||p==1||u==0)&&(g==0||g==-1||d==e.state.doc.length)&&(a=0,f=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(b.range(f,a));else if(e.lineWrapping&&f==a&&!(l.main.empty&&l.main.head==a)&&e.inputState.lastTouchTime>Date.now()-100){let u=e.coordsAtPos(a,-1),d=0;u&&(d=e.inputState.lastTouchY<=u.bottom?-1:1),this.newSel=b.create([b.cursor(a,d)])}else this.newSel=b.single(f,a)}}}function Bl(s,e,t,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let h=0,a=i,f=i;h<s.children.length;h++){let c=s.children[h],u=a+c.length;if(a<e&&u>t)return Bl(c,e,t,a);if(u>=e&&n==-1&&(n=h,r=a),a>t&&c.dom.parentNode==s.dom){o=h,l=f;break}f=u,a=u+c.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o<s.children.length&&o>=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function Pl(s,e){let t,{newSel:i}=e,{state:n}=s,r=n.selection.main,o=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:h}=e.bounds,a=r.from,f=null;(o===8||S.android&&e.text.length<h-l)&&(a=r.to,f="end");let c=n.doc.sliceString(l,h,wt),u,d;!r.empty&&r.from>=l&&r.to<=h&&(e.typeOver||c!=e.text)&&c.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&c.slice(r.to-l)==e.text.slice(u=e.text.length-(c.length-(r.to-l)))?t={from:r.from,to:r.to,insert:E.of(e.text.slice(r.from-l,u).split(wt))}:(d=Il(c,e.text,a-l,f))&&(S.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==wt+wt&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:E.of(e.text.slice(d.from,d.toB).split(wt))})}else i&&(!s.hasFocus&&n.facet(Ke)||Xi(i,r))&&(i=null);if(!t&&!i)return!1;if((S.mac||S.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:E.of([t.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).to<r.to&&s.docView.lineHasWidget(r.to)&&s.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:S.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
9
- `&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:E.of([" "])}),t)return qs(s,t,i,o);if(i&&!Xi(i,r)){let l=!1,h="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(l=!0),h=s.inputState.lastSelectionOrigin,h=="select.pointer"&&(i=Ol(n.facet(yi).map(a=>a(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:h}),!0}else return!1}function qs(s,e,t,i=-1){if(S.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(S.android&&(e.to==n.to&&(e.from==n.from||e.from==n.from-1&&s.state.sliceDoc(e.from,n.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Tt(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>n.head)&&Tt(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&Tt(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=xf(s,e,t));return s.state.facet(yl).some(h=>h(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function xf(s,e,t){let i,n=s.state,r=n.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let h=e.from<r.from?-1:1,a=h<0?r.from:r.to,f=ti(n.facet(yi).map(c=>c(s)),a,h);e.from==f&&(o=f)}if(o>-1)i={changes:e,selection:b.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&s.inputState.composing<0){let h=r.from<e.from?n.sliceDoc(r.from,e.from):"",a=r.to>e.to?n.sliceDoc(e.to,r.to):"";i=n.replaceSelection(s.state.toText(h+e.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let h=n.changes(e),a=t&&t.main.to<=h.newLength?t.main:void 0;if(n.selection.ranges.length>1&&(s.inputState.composing>=0||s.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let f=s.state.sliceDoc(e.from,e.to),c,u=t&&Dl(s,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);c={from:u.from,to:u.to-p}}else c=s.state.doc.lineAt(r.head);let d=r.to-e.to;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:h,range:a||p.map(h)};let g=p.to-d,m=g-f.length;if(s.state.sliceDoc(m,g)!=f||g>=c.from&&m<=c.to)return{range:p};let y=n.changes({from:m,to:g,insert:e.insert}),k=p.to-r.to;return{changes:y,range:a?b.range(Math.max(0,a.anchor+k),Math.max(0,a.head+k)):p.map(y)}})}else i={changes:h,selection:a&&n.selection.replaceRange(a)}}let l="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,l+=".compose",s.inputState.compositionFirstChange&&(l+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:l,scrollIntoView:!0})}function Il(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r<n&&s.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==n&&s.length==e.length)return null;let o=s.length,l=e.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));t-=o+h-r}if(o<r&&s.length<e.length){let h=t<=r&&t>=o?r-t:0;r-=h,l=r+(l-o),o=r}else if(l<r){let h=t<=r&&t>=l?r-t:0;r-=h,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function wf(s){let e=[];if(s.root.activeElement!=s.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return t&&(e.push(new Br(t,i)),(n!=t||r!=i)&&e.push(new Br(n,r))),e}function Sf(s,e){if(s.length==0)return null;let t=s[0].pos,i=s.length==2?s[1].pos:t;return t>-1&&i>-1?b.single(t+e,i+e):null}function Xi(s,e){return e.head==s.main.head&&e.anchor==s.main.anchor}class vf{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,S.safari&&e.contentDOM.addEventListener("input",()=>null),S.gecko&&Wf(e.contentDOM.ownerDocument)}handleEvent(e){!Pf(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let n of i.observers)n(this.view,t);for(let n of i.handlers){if(t.defaultPrevented)break;if(n(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Af(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Ll.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),S.android&&S.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return S.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=El.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Cf.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Tt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:S.safari&&!S.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Pr(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){Ne(t.state,n)}}}function Af(s){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec,r=n&&n.plugin.domEventHandlers,o=n&&n.plugin.domEventObservers;if(r)for(let l in r){let h=r[l];h&&t(l).handlers.push(Pr(i.value,h))}if(o)for(let l in o){let h=o[l];h&&t(l).observers.push(Pr(i.value,h))}}for(let i in Ce)t(i).handlers.push(Ce[i]);for(let i in ue)t(i).observers.push(ue[i]);return e}const El=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Cf="dthko",Ll=[16,17,18,20,91,92,224,225],Mi=6;function Ti(s){return Math.max(0,s)*.7+8}function Mf(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class Tf{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=nl(e.contentDOM),this.atoms=e.state.facet(yi).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(N.allowMultipleSelections)&&Df(e,t),this.dragging=Bf(e,t)&&Fl(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Mf(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=Ml(this.view);e.clientX-h.left<=n+Mi?t=-Ti(n-e.clientX):e.clientX+h.right>=o-Mi&&(t=Ti(e.clientX-o)),e.clientY-h.top<=r+Mi?i=-Ti(r-e.clientY):e.clientY+h.bottom>=l-Mi&&(i=Ti(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=Ol(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Df(s,e){let t=s.state.facet(dl);return t.length?t[0](e):S.mac?e.metaKey:e.ctrlKey}function Of(s,e){let t=s.state.facet(pl);return t.length?t[0](e):S.mac?!e.altKey:!e.ctrlKey}function Bf(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=li(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Pf(s,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=s.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Ce=Object.create(null),ue=Object.create(null),Rl=S.ie&&S.ie_version<15||S.ios&&S.webkit_version<604;function If(s){let e=s.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{s.focus(),t.remove(),Nl(s,t.value)},50)}function dn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function Nl(s,e){e=dn(s.state,Vs,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(gs!=null&&t.selection.ranges.every(h=>h.empty)&&gs==r.toString()){let h=-1;i=t.changeByRange(a=>{let f=t.doc.lineAt(a.from);if(f.from==h)return{range:a};h=f.from;let c=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:b.cursor(a.from+c.length)}})}else o?i=t.changeByRange(h=>{let a=r.line(n++);return{changes:{from:h.from,to:h.to,insert:a.text},range:b.cursor(h.from+a.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}ue.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ue.wheel=ue.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};Ce.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);ue.touchstart=(s,e)=>{let t=s.inputState,i=e.targetTouches[0];t.lastTouchTime=Date.now(),i&&(t.lastTouchX=i.clientX,t.lastTouchY=i.clientY),t.setSelectionOrigin("select.pointer")};ue.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Ce.mousedown=(s,e)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of s.state.facet(gl))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Lf(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new Tf(s,e,t,i)),i&&s.observer.ignore(()=>{sl(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(e),n.dragging===!1}else s.inputState.setSelectionOrigin("select.pointer");return!1};function Ir(s,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return af(s.state,e,t);{let n=s.docView.lineAt(e,t),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,b.range(o,l)}}const Ef=S.ie&&S.ie_version<=11;let Er=null,Lr=0,Rr=0;function Fl(s){if(!Ef)return s.detail;let e=Er,t=Rr;return Er=s,Rr=Date.now(),Lr=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(Lr+1)%3:1}function Lf(s,e){let t=s.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Fl(e),n=s.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),n=n.map(r.changes))},get(r,o,l){let h=s.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),a,f=Ir(s,h.pos,h.assoc,i);if(t.pos!=h.pos&&!o){let c=Ir(s,t.pos,t.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?b.range(u,d,f.assoc):b.range(d,u,f.assoc)}return o?n.replaceRange(n.main.extend(f.from,f.to,f.assoc)):l&&i==1&&n.ranges.length>1&&(a=Rf(n,h.pos))?a:l?n.addRange(f):b.create([f])}}}function Rf(s,e){for(let t=0;t<s.ranges.length;t++){let{from:i,to:n}=s.ranges[t];if(i<=e&&n>=e)return b.create(s.ranges.slice(0,t).concat(s.ranges.slice(t+1)),s.mainIndex==t?0:s.mainIndex-(s.mainIndex>t?1:0))}return null}Ce.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.tile.nearest(e.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",dn(s.state,zs,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Ce.dragend=s=>(s.inputState.draggedContent=null,!1);function Nr(s,e,t,i){if(t=dn(s.state,Vs,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Of(s,e)?{from:r.from,to:r.to}:null,l={from:n,insert:t},h=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:h,selection:{anchor:h.mapPos(n,-1),head:h.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Ce.drop=(s,e)=>{if(!e.dataTransfer)return!1;if(s.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),n=0,r=()=>{++n==t.length&&Nr(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return Nr(s,e,i,!0),!0}return!1};Ce.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=Rl?null:e.clipboardData;return t?(Nl(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(If(s),!1)};function Nf(s,e){let t=s.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function Ff(s){let e=[],t=[],i=!1;for(let n of s.selection.ranges)n.empty||(e.push(s.sliceDoc(n.from,n.to)),t.push(n));if(!e.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(e.push(o.text),t.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:dn(s,zs,e.join(s.lineBreak)),ranges:t,linewise:i}}let gs=null;Ce.copy=Ce.cut=(s,e)=>{if(!Qt(s.contentDOM,s.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:n}=Ff(s.state);if(!t&&!n)return!1;gs=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Rl?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Nf(s,t),!1)};const Wl=Ye.define();function Hl(s,e){let t=[];for(let i of s.facet(bl)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:Wl.of(!0)}):null}function Vl(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Hl(s.state,e);t?s.dispatch(t):s.update([])}},10)}ue.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),Vl(s)};ue.blur=s=>{s.observer.clearSelectionRange(),Vl(s)};ue.compositionstart=ue.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};ue.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,S.chrome&&S.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};ue.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Ce.beforeinput=(s,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(s.inputState.insertingText=e.data,s.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&s.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],h=s.posAtDOM(l.startContainer,l.startOffset),a=s.posAtDOM(l.endContainer,l.endOffset);return qs(s,{from:h,to:a,insert:s.state.toText(r)},null),!0}}let n;if(S.chrome&&S.android&&(n=El.find(r=>r.inputType==e.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return S.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),S.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>ue.compositionend(s,e),20),!1};const Fr=new Set;function Wf(s){Fr.has(s)||(Fr.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const Wr=["pre-wrap","normal","pre-line","break-spaces"];let Lt=!1;function Hr(){Lt=!1}class Hf{constructor(e){this.lineWrapping=e,this.doc=E.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Wr.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(t=!0,this.heightSamples[Math.floor(n*10)]=!0)}return t}refresh(e,t,i,n,r,o){let l=Wr.indexOf(e)>-1,h=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,h){this.heightSamples={};for(let a=0;a<o.length;a++){let f=o[a];f<0?a++:this.heightSamples[Math.floor(f*10)]=!0}}return h}}class Vf{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class ve{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?ce.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof gt?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new ve(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var V=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})(V||(V={}));const Vi=.001;class he{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Vi&&(Lt=!0),this.height=e)}replace(e,t,i){return he.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:h,toA:a,fromB:f,toB:c}=n[l],u=r.lineAt(h,V.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=a?u:r.lineAt(a,V.ByPosNoHeight,i,0,0);for(c+=d.to-a,a=d.to;l>0&&u.from<=n[l-1].toA;)h=n[l-1].fromA,f=n[l-1].fromB,l--,h<u.from&&(u=r.lineAt(h,V.ByPosNoHeight,i,0,0));f+=u.from-h,h=u.from;let p=js.build(i.setDoc(o),e,f,c);r=Qi(r,r.replace(h,a,p))}return r.updateHeight(i,0)}static empty(){return new pe(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=e[t++];l&&(n+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Kf(he.of(e.slice(0,t)),o,he.of(e.slice(i)))}}function Qi(s,e){return s==e?s:(s.constructor!=e.constructor&&(Lt=!0),e)}he.prototype.size=1;const zf=z.replace({});class zl extends he{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new ve(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new ve(n,0,i,this.spaceAbove,zf):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let o=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(o):o}forEachLine(e,t,i,n,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,V.ByPos,i,n,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class pe extends zl{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new ve(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof pe||n instanceof Z&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Z?n=new pe(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):he.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Z extends he{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,n=e.doc.lineAt(t+this.length).number,r=n-i+1,o,l=0;if(e.lineWrapping){let h=Math.min(this.height,e.lineHeight*r);o=h/r,this.length>r+1&&(l=(this.height-h)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(e,t,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(t,n);if(t.lineWrapping){let a=n+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),f=t.doc.lineAt(a),c=l+f.length*h,u=Math.max(i,e-c/2);return new ve(f.from,f.length,u,c,0)}else{let a=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:f,length:c}=t.doc.line(r+a);return new ve(f,c,i+l*a,l,0)}}lineAt(e,t,i,n,r){if(t==V.ByHeight)return this.blockAt(e,i,n,r);if(t==V.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new ve(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,r),a=i.doc.lineAt(e),f=l+a.length*h,c=a.number-o,u=n+l*c+h*(a.from-r-c);return new ve(a.from,a.length,Math.max(n,Math.min(u,n+this.height-f)),f,0)}forEachLine(e,t,i,n,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:h,perChar:a}=this.heightMetrics(i,r);for(let f=e,c=n;f<=t;){let u=i.doc.lineAt(f);if(f==e){let p=u.number-l;c+=h*p+a*(e-r-p)}let d=h+a*u.length;o(new ve(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let r=i[i.length-1];r instanceof Z?i[i.length-1]=new Z(r.length+n):i.push(null,new Z(n-1))}if(e>0){let r=i[0];r instanceof Z?i[0]=new Z(e+r.length):i.unshift(new Z(e-1),null)}return he.of(i)}decomposeLeft(e,t){t.push(new Z(e-1),null)}decomposeRight(e,t){t.push(null,new Z(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let o=[],l=Math.max(t,n.from),h=-1;for(n.from>t&&o.push(new Z(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++],u=0;c<0&&(u=-c,c=n.heights[n.index++]),h==-1?h=c:Math.abs(c-h)>=Vi&&(h=-2);let d=new pe(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new Z(r-l).updateHeight(e,l));let a=he.of(o);return(h<0||Math.abs(a.height-this.height)>=Vi||Math.abs(h-this.heightMetrics(e,t).perLine)>=Vi)&&(Lt=!0),Qi(this,a)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Kf extends he{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,h=t==V.ByHeight?e<o:e<l,a=h?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let f=t==V.ByPosNoHeight?V.ByPosNoHeight:V.ByPos;return h?a.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,n,r).join(a)}forEachLine(e,t,i,n,r,o){let l=n+this.left.height,h=r+this.left.length+this.break;if(this.break)e<h&&this.left.forEachLine(e,t,i,n,r,o),t>=h&&this.right.forEachLine(e,t,i,l,h,o);else{let a=this.lineAt(h,V.ByPos,i,n,r);e<a.from&&this.left.forEachLine(e,a.from-1,i,n,r,o),a.to>=e&&a.from<=t&&o(a),t>a.to&&this.right.forEachLine(a.to+1,t,i,l,h,o)}}replace(e,t,i){let n=this.left.length+this.break;if(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Vr(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Vr(r,l)}return he.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?he.of(this.break?[e,null,t]:[e,t]):(this.left=Qi(this.left,e),this.right=Qi(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:o}=this,l=t+r.length+this.break,h=null;return n&&n.from<=t+r.length&&n.more?h=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?h=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vr(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof Z&&(i=s[e+1])instanceof Z&&s.splice(e-1,3,new Z(t.length+1+i.length))}const $f=5;class js{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof pe?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new pe(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new zl(o,n,i)):(o||r||n>=$f)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new pe(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new Z(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof pe)return e;let t=new pe(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof pe)&&!this.isCovered?this.nodes.push(new pe(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let n of this.nodes)n instanceof pe&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new js(i,e);return L.spans(t,i,n,r,0),r.finish(i)}}function qf(s,e,t){let i=new jf;return L.compare(s,e,t,i,0),i.changes}class jf{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&Mt(e,t,this.changes,5)}}function Uf(s,e){let t=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(n.innerWidth,t.right),l=Math.max(0,t.top),h=Math.min(n.innerHeight,t.bottom);for(let a=s.parentNode;a&&a!=i.body;)if(a.nodeType==1){let f=a,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(a==s.parentNode?n.innerHeight:h,u.bottom)}a=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(a.nodeType==11)a=a.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,h)-(t.top+e)}}function Gf(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function Jf(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Pn{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return z.replace({widget:new Yf(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class Yf extends Wt{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class zr{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Kr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Y.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet(Ks).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Hf(i),this.stateDeco=$r(t),this.heightMap=he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle.setDoc(t.doc),[new ye(0,0,0,t.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=z.set(this.lineGaps.map(n=>n.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);e.push(new Di(r,o))}}return this.viewports=e.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Kr:new Us(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Jt(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=$r(this.state);let n=e.changedRanges,r=ye.extendWithRanges(n,qf(i,this.stateDeco,e?e.changes:X.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Hr(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Lt)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let h=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<h.from||t.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,t));let a=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,e.flags|=this.updateForViewport(),(a||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ha)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Y.RTL:Y.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let a=0,f=0;if(l.width&&l.height){let{scaleX:M,scaleY:T}=il(t,l);(M>.005&&Math.abs(this.scaleX-M)>.005||T>.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=M,this.scaleY=T,a|=16,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(h=!0),this.editorWidth=e.scrollDOM.clientWidth,a|=16);let d=nl(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=rl(this.scrollParent||e.win);let g=(this.printing?Jf:Uf)(t,this.paddingTop),m=g.top-this.pixelViewport.top,y=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let k=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(k!=this.inView&&(this.inView=k,k&&(h=!0)),!this.inView&&!this.scrollTarget&&!Gf(e.dom))return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,a|=16),h){let M=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(M)&&(o=!0),o||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:T,charWidth:C,textHeight:K}=e.docView.measureTextSize();o=T>0&&n.refresh(r,T,C,K,Math.max(5,v/C),M),o&&(e.docView.minWidth=0,a|=16)}m>0&&y>0?f=Math.max(m,y):m<0&&y<0&&(f=Math.min(m,y)),Hr();for(let T of this.viewports){let C=T.from==this.viewport.from?M:e.docView.measureVisibleLineHeights(T);this.heightMap=(o?he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle,[new ye(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Vf(T.from,C))}Lt&&(a|=2)}let P=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return P&&(a&2&&(a|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),a|=this.updateForViewport()),(a&2||P)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new Di(n.lineAt(o-i*1e3,V.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,V.ByHeight,r,0,0).to);if(t){let{head:a}=t.range;if(a<h.from||a>h.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(a,V.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&a<h.from?u=c.top:u=c.bottom-f,h=new Di(n.lineAt(u-1e3/2,V.ByHeight,r,0,0).from,n.lineAt(u+f+1e3/2,V.ByHeight,r,0,0).to)}}return h}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new Di(this.heightMap.lineAt(i,V.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,V.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,V.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||n<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new Pn(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=Y.LTR&&!i)return[];let l=[],h=(f,c,u,d)=>{if(c-f<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let y of g)if(y>f&&y<c){h(f,y-10,u,d),h(y+10,c,u,d);return}let m=Xf(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-f)<r&&Math.abs(y.to-c)<r&&!g.some(k=>y.from<k&&y.to>k));if(!m){if(c<u.to&&t&&i&&t.visibleRanges.some(v=>v.from<=c&&v.to>=c)){let v=t.moveToLineBoundary(b.cursor(c),!1,!0).head;v>f&&(c=v)}let y=this.gapSize(u,f,c,d),k=i||y<2e6?y:2e6;m=new Pn(f,c,y,k)}l.push(m)},a=f=>{if(f.length<o||f.type!=ce.Text)return;let c=_f(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,y;if(u!=null){let k=Bi(c,u),v=((this.visibleBottom-this.visibleTop)/2+g)/f.height;m=k-v,y=k+v}else m=(this.visibleTop-f.top-g)/f.height,y=(this.visibleBottom-f.top+g)/f.height;d=Oi(c,m),p=Oi(c,y)}else{let g=c.total*this.heightOracle.charWidth,m=n*this.heightOracle.charWidth,y=0;if(g>2e6)for(let T of e)T.from>=f.from&&T.from<f.to&&T.size!=T.displaySize&&T.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=T.size-T.displaySize);let k=this.pixelViewport.left+y,v=this.pixelViewport.right+y,P,M;if(u!=null){let T=Bi(c,u),C=((v-k)/2+m)/g;P=T-C,M=T+C}else P=(k-m)/g,M=(v+m)/g;d=Oi(c,P),p=Oi(c,M)}d>f.from&&h(f.from,d,f,c),p<f.to&&h(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(a):a(f);return l}gapSize(e,t,i,n){let r=Bi(n,i)-Bi(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){Pn.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=z.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];L.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(n&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(n|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Jt(this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Jt(this.heightMap.lineAt(this.scaler.fromDOM(e),V.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Jt(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Di{constructor(e,t){this.from=e,this.to=t}}function _f(s,e,t){let i=[],n=s,r=0;return L.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<e&&(i.push({from:n,to:e}),r+=e-n),{total:r,ranges:i}}function Oi({total:s,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(s*t);for(let n=0;;n++){let{from:r,to:o}=e[n],l=o-r;if(i<=l)return r+i;i-=l}}function Bi(s,e){let t=0;for(let{from:i,to:n}of s.ranges){if(e<=n){t+=e-i;break}t+=n-i}return t/s.total}function Xf(s,e){for(let t of s)if(e(t))return t}const Kr={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function $r(s){let e=s.facet(fn).filter(i=>typeof i!="function"),t=s.facet($s).filter(i=>typeof i!="function");return t.length&&e.push(L.join(t)),e}class Us{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=t.lineAt(l,V.ByPos,e,0,0).top,f=t.lineAt(h,V.ByPos,e,0,0).bottom;return n+=f-a,{from:l,to:h,top:a,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof Us?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function Jt(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new ve(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>Jt(n,e)):s._content)}const Pi=A.define({combine:s=>s.join(" ")}),ms=A.define({combine:s=>s.indexOf(!0)>-1}),ys=it.newName(),Kl=it.newName(),$l=it.newName(),ql={"&light":"."+Kl,"&dark":"."+$l};function bs(s,e,t){return new it(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!t||!t[n])throw new RangeError(`Unsupported selector: ${n}`);return t[n]}):s+" "+i}})}const Qf=bs("."+ys,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},ql),Zf={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},In=S.ie&&S.ie_version<=11;class ec{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Ta,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(S.ie&&S.ie_version<=11||S.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&S.android&&e.constructor.EDIT_CONTEXT!==!1&&!(S.chrome&&S.chrome_version<126)&&(this.editContext=new ic(e),e.state.facet(Ke)&&(e.contentDOM.editContext=this.editContext.editContext)),In&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Ke)?i.root.activeElement!=this.dom:!Qt(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(S.ie&&S.ie_version<=11||S.android&&S.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ei(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=li(e.root);if(!t)return!1;let i=S.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&tc(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=Qt(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Oa(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Zf),In&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),In&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Tt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Qt(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new kf(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Pl(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!Xi(this.view.state.selection,t.newSel.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=qr(t,e.previousSibling||e.target.previousSibling,-1),n=qr(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Ke)!=e.state.facet(Ke)&&(e.view.contentDOM.editContext=e.state.facet(Ke)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function qr(s,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==s)return i;let n=e.parentNode;e=n!=s.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function jr(s,e){let t=e.startContainer,i=e.startOffset,n=e.endContainer,r=e.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor,1);return ei(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function tc(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return jr(s,n)}let t=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),t=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),t?jr(s,t):null}class ic{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let n=e.state.selection.main,{anchor:r,head:o}=n,l=this.toEditorPos(i.updateRangeStart),h=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let a=h-l>i.text.length;l==this.from&&r<this.from?l=r:h==this.to&&r>this.to&&(h=r);let f=Il(e.state.sliceDoc(l,h),i.text,(a?n.from:n.to)-l,a?"end":null);if(!f){let u=b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Xi(u,n)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:E.of(i.text.slice(f.from,f.toB).split(`
7
+ `;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var nt={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:"'"},ri={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ba=typeof navigator<"u"&&/Mac/.test(navigator.platform),ka=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ee=0;ee<10;ee++)nt[48+ee]=nt[96+ee]=String(ee);for(var ee=1;ee<=24;ee++)nt[ee+111]="F"+ee;for(var ee=65;ee<=90;ee++)nt[ee]=String.fromCharCode(ee+32),ri[ee]=String.fromCharCode(ee);for(var An in nt)ri.hasOwnProperty(An)||(ri[An]=nt[An]);function xa(s){var e=ba&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||ka&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?ri:nt)[s.keyCode]||s.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}let oe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},ss=typeof document<"u"?document:{documentElement:{style:{}}};const rs=/Edge\/(\d+)/.exec(oe.userAgent),el=/MSIE \d/.test(oe.userAgent),os=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oe.userAgent),an=!!(el||os||rs),xr=!an&&/gecko\/(\d+)/i.test(oe.userAgent),Cn=!an&&/Chrome\/(\d+)/.exec(oe.userAgent),wa="webkitFontSmoothing"in ss.documentElement.style,ls=!an&&/Apple Computer/.test(oe.vendor),wr=ls&&(/Mobile\/\w+/.test(oe.userAgent)||oe.maxTouchPoints>2);var S={mac:wr||/Mac/.test(oe.platform),windows:/Win/.test(oe.platform),linux:/Linux|X11/.test(oe.platform),ie:an,ie_version:el?ss.documentMode||6:os?+os[1]:rs?+rs[1]:0,gecko:xr,gecko_version:xr?+(/Firefox\/(\d+)/.exec(oe.userAgent)||[0,0])[1]:0,chrome:!!Cn,chrome_version:Cn?+Cn[1]:0,ios:wr,android:/Android\b/.test(oe.userAgent),webkit_version:wa?+(/\bAppleWebKit\/(\d+)/.exec(oe.userAgent)||[0,0])[1]:0,safari:ls,safari_version:ls?+(/\bVersion\/(\d+(\.\d+)?)/.exec(oe.userAgent)||[0,0])[1]:0,tabSize:ss.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Fs(s,e){for(let t in s)t=="class"&&e.class?e.class+=" "+s.class:t=="style"&&e.style?e.style+=";"+s.style:e[t]=s[t];return e}const Ui=Object.create(null);function Ws(s,e,t){if(s==e)return!0;s||(s=Ui),e||(e=Ui);let i=Object.keys(s),n=Object.keys(e);if(i.length-0!=n.length-0)return!1;for(let r of i)if(r!=t&&(n.indexOf(r)==-1||s[r]!==e[r]))return!1;return!0}function Sa(s,e){for(let t=s.attributes.length-1;t>=0;t--){let i=s.attributes[t].name;e[i]==null&&s.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?s.style.cssText=i:s.getAttribute(t)!=i&&s.setAttribute(t,i)}}function Sr(s,e,t){let i=!1;if(e)for(let n in e)t&&n in t||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(t)for(let n in t)e&&e[n]==t[n]||(i=!0,n=="style"?s.style.cssText=t[n]:s.setAttribute(n,t[n]));return i}function va(s){let e=Object.create(null);for(let t=0;t<s.attributes.length;t++){let i=s.attributes[t];e[i.name]=i.value}return e}class Wt{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ce=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(ce||(ce={}));class z extends tt{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new gi(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new gt(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,n;if(e.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=tl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new gt(e,i,n,t,e.widget||null,!0)}static line(e){return new mi(e)}static set(e,t=!1){return L.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}z.none=L.empty;class gi extends z{constructor(e){let{start:t,end:i}=tl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Fs(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Ui}eq(e){return this==e||e instanceof gi&&this.tagName==e.tagName&&Ws(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}gi.prototype.point=!1;class mi extends z{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof mi&&this.spec.class==e.spec.class&&Ws(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}mi.prototype.mapMode=le.TrackBefore;mi.prototype.point=!0;class gt extends z{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?le.TrackBefore:le.TrackAfter:le.TrackDel}get type(){return this.startSide!=this.endSide?ce.WidgetRange:this.startSide<=0?ce.WidgetBefore:ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof gt&&Aa(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}gt.prototype.point=!0;function tl(s,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=s;return t==null&&(t=s.inclusive),i==null&&(i=s.inclusive),{start:t??e,end:i??e}}function Aa(s,e){return s==e||!!(s&&e&&s.compare(e))}function Mt(s,e,t,i=0){let n=t.length-1;n>=0&&t[n]+i>=s?t[n]=Math.max(t[n],e):t.push(s,e)}class oi extends tt{constructor(e,t,i){super(),this.tagName=e,this.attributes=t,this.rank=i}eq(e){return e==this||e instanceof oi&&this.tagName==e.tagName&&Ws(this.attributes,e.attributes)}static create(e){return new oi(e.tagName,e.attributes||Ui,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return L.of(e,t)}}oi.prototype.startSide=oi.prototype.endSide=-1;function li(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function hs(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function Qt(s,e){if(!e.anchorNode)return!1;try{return hs(s,e.anchorNode)}catch{return!1}}function Zt(s){return s.nodeType==3?ai(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ei(s,e,t,i){return t?vr(s,e,t,i,-1)||vr(s,e,t,i,1):!1}function st(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function Gi(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function vr(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:Ue(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=st(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[e+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;e=n<0?Ue(s):0}else return!1}}function Ue(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function hi(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function Ca(s){let e=s.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function il(s,e){let t=e.width/s.offsetWidth,i=e.height/s.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-s.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-s.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Ma(s,e,t,i,n,r,o,l){let h=s.ownerDocument,a=h.defaultView||window;for(let f=s,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==h.body,p=1,g=1;if(d)u=Ca(a);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let k=f.getBoundingClientRect();({scaleX:p,scaleY:g}=il(f,k)),u={left:k.left,right:k.left+f.clientWidth*p,top:k.top,bottom:k.top+f.clientHeight*g}}let m=0,y=0;if(n=="nearest")e.top<u.top+o?(y=e.top-(u.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=e.top-(u.top+o)));else{let k=e.bottom-e.top,v=u.bottom-u.top;y=(n=="center"&&k<=v?e.top+k/2-v/2:n=="start"||n=="center"&&t<0?e.top-o:e.bottom-v+o)-u.top}if(i=="nearest"?e.left<u.left+r?(m=e.left-(u.left+r),t>0&&e.right>u.right+m&&(m=e.right-u.right+r)):e.right>u.right-r&&(m=e.right-u.right+r,t<0&&e.left<u.left+m&&(m=e.left-(u.left+r))):m=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,m||y)if(d)a.scrollBy(m,y);else{let k=0,v=0;if(y){let P=f.scrollTop;f.scrollTop+=y/g,v=(f.scrollTop-P)*g}if(m){let P=f.scrollLeft;f.scrollLeft+=m/p,k=(f.scrollLeft-P)*p}e={left:e.left-k,top:e.top-v,right:e.right-k,bottom:e.bottom-v},k&&Math.abs(k-m)<1&&(i="nearest"),v&&Math.abs(v-y)<1&&(n="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function nl(s,e=!0){let t=s.ownerDocument,i=null,n=null;for(let r=s.parentNode;r&&!(r==t.body||(!e||i)&&n);)if(r.nodeType==1)!n&&r.scrollHeight>r.clientHeight&&(n=r),e&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:n}}class Ta{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Ue(t):0),i,Math.min(e.focusOffset,i?Ue(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let ft=null;S.safari&&S.safari_version>=26&&(ft=!1);function sl(s){if(s.setActive)return s.setActive();if(ft)return s.focus(ft);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(ft==null?{get preventScroll(){return ft={preventScroll:!0},!0}}:void 0),!ft){ft=!1;for(let t=0;t<e.length;){let i=e[t++],n=e[t++],r=e[t++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Ar;function ai(s,e,t=e){let i=Ar||(Ar=document.createRange());return i.setEnd(s,t),i.setStart(s,e),i}function Tt(s,e,t,i){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Da(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Oa(s,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Ue(t));;)if(i){if(t.nodeType!=1)return!1;let n=t.childNodes[i-1];n.contentEditable=="false"?i--:(t=n,i=Ue(t))}else{if(t==s)return!0;i=st(t),t=t.parentNode}}function rl(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function ol(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=Ue(t)}else if(t.parentNode&&!Gi(t))i=st(t),t=t.parentNode;else return null}}function ll(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Gi(t))i=st(t)+1,t=t.parentNode;else return null}}class Ae{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Ae(e.parentNode,st(e),t)}static after(e,t){return new Ae(e.parentNode,st(e)+1,t)}}var Y=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(Y||(Y={}));const mt=Y.LTR,Hs=Y.RTL;function hl(s){let e=[];for(let t=0;t<s.length;t++)e.push(1<<+s[t]);return e}const Ba=hl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Pa=hl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),as=Object.create(null),Oe=[];for(let s of["()","[]","{}"]){let e=s.charCodeAt(0),t=s.charCodeAt(1);as[e]=t,as[t]=-e}function al(s){return s<=247?Ba[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?Pa[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const Ia=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Re{get dir(){return this.level%2?Hs:mt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function fl(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++){let i=s[t],n=e[t];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!fl(i.inner,n.inner))return!1}return!0}const W=[];function Ea(s,e,t,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,h=r?256:n;for(let a=o,f=h,c=h;a<l;a++){let u=al(s.charCodeAt(a));u==512?u=f:u==8&&c==4&&(u=16),W[a]=u==4?2:u,u&7&&(c=u),f=u}for(let a=o,f=h,c=h;a<l;a++){let u=W[a];if(u==128)a<l-1&&f==W[a+1]&&f&24?u=W[a]=f:W[a]=256;else if(u==64){let d=a+1;for(;d<l&&W[d]==64;)d++;let p=a&&f==8||d<t&&W[d]==8?c==1?1:8:256;for(let g=a;g<d;g++)W[g]=p;a=d-1}else u==8&&c==1&&(W[a]=1);f=u,u&7&&(c=u)}}}function La(s,e,t,i,n){let r=n==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let a=o?i[o-1].to:e,f=o<i.length?i[o].from:t;for(let c=a,u,d,p;c<f;c++)if(d=as[u=s.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(Oe[g+1]==-d){let m=Oe[g+2],y=m&2?n:m&4?m&1?r:n:0;y&&(W[c]=W[Oe[g]]=y),l=g;break}}else{if(Oe.length==189)break;Oe[l++]=c,Oe[l++]=u,Oe[l++]=h}else if((p=W[c])==2||p==1){let g=p==n;h=g?0:1;for(let m=l-3;m>=0;m-=3){let y=Oe[m+2];if(y&2)break;if(g)Oe[m+2]|=2;else{if(y&4)break;Oe[m+2]|=4}}}}}function Ra(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=n<t.length?t[n].from:e;for(let h=o;h<l;){let a=W[h];if(a==256){let f=h+1;for(;;)if(f==l){if(n==t.length)break;f=t[n++].to,l=n<t.length?t[n].from:e}else if(W[f]==256)f++;else break;let c=r==1,u=(f<e?W[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,g=n,m=g?t[g-1].to:s;p>h;)p==m&&(p=t[--g].from,m=g?t[g-1].to:s),W[--p]=d;h=f}else r=a,h++}}}function fs(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let h=e,a=0;h<t;){let f=!0,c=!1;if(a==r.length||h<r[a].from){let g=W[h];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;e:for(;;)if(a<r.length&&p==r[a].from){if(c)break e;let g=r[a];if(!f)for(let m=g.to,y=a+1;;){if(m==t)break e;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(W[m]==l)break e;break}}if(a++,u)u.push(g);else{g.from>h&&o.push(new Re(h,g.from,d));let m=g.direction==mt!=!(d%2);cs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==t||(f?W[p]!=l:W[p]==l))break;p++}u?fs(s,h,p,i+1,n,u,o):h<p&&o.push(new Re(h,p,d)),h=p}else for(let h=t,a=r.length;h>e;){let f=!0,c=!1;if(!a||h>r[a-1].to){let g=W[h-1];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;e:for(;;)if(a&&p==r[a-1].to){if(c)break e;let g=r[--a];if(!f)for(let m=g.from,y=a;;){if(m==e)break e;if(y&&r[y-1].to==m)m=r[--y].from;else{if(W[m-1]==l)break e;break}}if(u)u.push(g);else{g.to<h&&o.push(new Re(g.to,h,d));let m=g.direction==mt!=!(d%2);cs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==e||(f?W[p-1]!=l:W[p-1]==l))break;p--}u?fs(s,p,h,i+1,n,u,o):p<h&&o.push(new Re(p,h,d)),h=p}}function cs(s,e,t,i,n,r,o){let l=e%2?2:1;Ea(s,n,r,i,l),La(s,n,r,i,l),Ra(n,r,i,l),fs(s,n,r,e,t,i,o)}function Na(s,e,t){if(!s)return[new Re(0,0,e==Hs?1:0)];if(e==mt&&!t.length&&!Ia.test(s))return cl(s.length);if(t.length)for(;s.length>W.length;)W[W.length]=256;let i=[],n=e==mt?0:1;return cs(s,n,n,t,0,s.length,i),i}function cl(s){return[new Re(0,s,0)]}let ul="";function Fa(s,e,t,i,n){var r;let o=i.head-s.from,l=Re.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),h=e[l],a=h.side(n,t);if(o==a){let u=l+=n?1:-1;if(u<0||u>=e.length)return null;h=e[l=u],o=h.side(!n,t),a=h.side(n,t)}let f=ie(s.text,o,h.forward(n,t));(f<h.from||f>h.to)&&(f=a),ul=s.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return c&&f==a&&c.level+(n?0:1)<h.level?b.cursor(c.side(!n,t)+s.from,c.forward(n,t)?1:-1,c.level):b.cursor(f+s.from,h.forward(n,t)?-1:1,h.level)}function Wa(s,e,t){for(let i=e;i<t;i++){let n=al(s.charCodeAt(i));if(n==1)return mt;if(n==2||n==4)return Hs}return mt}const dl=A.define(),pl=A.define(),gl=A.define(),ml=A.define(),us=A.define(),yl=A.define(),bl=A.define(),Vs=A.define(),zs=A.define(),kl=A.define({combine:s=>s.some(e=>e)}),Ha=A.define({combine:s=>s.some(e=>e)}),xl=A.define();class Dt{constructor(e,t,i,n,r,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Dt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Dt(b.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ci=q.define({map:(s,e)=>s.map(e)}),wl=q.define();function Ne(s,e,t){let i=s.facet(ml);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const Ke=A.define({combine:s=>s.length?s[0]:!0});let Va=0;const St=A.define({combine(s){return s.filter((e,t)=>{for(let i=0;i<t;i++)if(s[i].plugin==e.plugin)return!1;return!0})}});class Ge{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(St.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(St.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=t||{};return new Ge(Va++,e,i,n,l=>{let h=[];return o&&h.push(fn.of(a=>{let f=a.plugin(l);return f?o(f):z.none})),r&&h.push(r(l)),h})}static fromClass(e,t){return Ge.define((i,n)=>new e(i,n),t)}}class Mn{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(Ne(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Ne(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){Ne(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Sl=A.define(),Ks=A.define(),fn=A.define(),vl=A.define(),$s=A.define(),yi=A.define(),Al=A.define();function Cr(s,e){let t=s.state.facet(Al);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return L.spans(i,e.from,e.to,{point(){},span(r,o,l,h){let a=r-e.from,f=o-e.from,c=n;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Wa(e.text,a,f)),h>0&&c.length&&(p=c[c.length-1]).to==a&&p.direction==d)p.to=f,c=p.inner;else{let g={from:a,to:f,direction:d,inner:[]};c.push(g),c=g.inner}}}}),n}const Cl=A.define();function Ml(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(Cl)){let o=r(s);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:e,right:t,top:i,bottom:n}}const Gt=A.define();class ye{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new ye(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let n=0,r=0,o=0;;){let l=n<e.length?e[n].fromB:1e9,h=r<t.length?t[r]:1e9,a=Math.min(l,h);if(a==1e9)break;let f=a+o,c=a,u=f;for(;;)if(r<t.length&&t[r]<=c){let d=t[r+1];r+=2,c=Math.max(c,d);for(let p=n;p<e.length&&e[p].fromB<=c;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(n<e.length&&e[n].fromB<=c){let d=e[n++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new ye(f,u,a,c))}return i}}class Ji{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=X.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,h)=>n.push(new ye(r,o,l,h))),this.changedRanges=n}static create(e,t,i){return new Ji(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const za=[];class G{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return za}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&Sa(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let n of this.children){if(n==e)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=st(this.dom),n=this.length?e>0:t>0;return new Ae(this.parent.dom,i+(n?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof un)return e;return null}static get(e){return e.cmTile}}class cn extends G{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,n,r=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,n=i?i.nextSibling:t.firstChild,r&&n!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;n&&n!=l.dom;)n=Mr(n);else t.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:t.firstChild,r&&n&&(r.written=!0);n;)n=Mr(n);this.length=o}}function Mr(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class un extends cn{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=G.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let o=i.children[n++];if(o instanceof qe)t.push(n),i=o,n=0;else{let l=r+o.length,h=e(o,r);if(h!==void 0)return h;r=l+o.breakAfter}}}resolveBlock(e,t){let i,n=-1,r,o=-1;if(this.blockTiles((l,h)=>{let a=h+l.length;if(e>=h&&e<=a){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(h<e||e==a&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,n=e-h),(a>e||e==h&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-h)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:n}:{tile:r,offset:o}}}class qe extends cn{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new qe(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class It extends cn{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new It(t||document.createElement("div"),e);return(!t||!i)&&(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(e,t,i){let n=null,r=-1,o=null,l=-1;function h(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],g=d+p.length;g>=c&&(p.isComposite()?h(p,c-d):(!o||o.isHidden&&(t>0||i&&$a(o,p)))&&(g>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(n=p,r=c-d)),d=g}}h(this,e);let a=(t<0?n:o)||n||o;return a?{tile:a,offset:a==n?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):Ka(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:n,offset:r}=i;if(this.dom.contains(n.dom))return n.isText()?new Ae(n.dom,Math.min(n.dom.nodeValue.length,r)):n.domPosFor(r,n.flags&16?1:n.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let h of o.children){if(l)return new Ae(h.dom,0);h==i.tile&&(l=!0)}}return new Ae(this.dom,0)}}function Ka(s){let e=s.dom.lastChild;if(!e)return s.dom.getBoundingClientRect();let t=Zt(e);return t[t.length-1]||null}function $a(s,e){let t=s.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class ae extends cn{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new ae(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class dt extends G{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?S.chrome||S.gecko||(e?(n--,o=1):r<i&&(r++,o=-1)):t<0?n--:r<i&&r++;let l=ai(this.dom,n,r).getClientRects();if(!l.length)return null;let h=l[(o?o<0:t>=0)?0:l.length-1];return S.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?hi(h,o<0):h||null}static of(e,t){let i=new dt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class yt extends G{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return hi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let h=l?r.length-1:0;o=r[h],!(e>0?h==0:h==r.length-1||o.top<o.bottom);h+=l?-1:1);return hi(o,!l)}}get overrideDOMText(){if(!this.length)return E.empty;let{root:e}=this;if(!e)return E.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new yt(r,i,e,n)}}class Yi extends G{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return E.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class qa{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(n.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==n.children.length){if(!e&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let h=n.children[r],a=h.breakAfter;(t>0?h.length<=e:h.length<e)&&(!i||i.skip(h,0,h.length)!==!1||!h.isComposite)?(o=!!a,r++,e-=h.length):(l.push({tile:n,index:r}),n=h,r=0,i&&h.isComposite()&&i.enter(h))}else if(r==n.length)o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++;else if(e){let h=Math.min(e,n.length-r);i&&i.skip(n,r,r+h),e-=h,r+=h}else break;return this.tile=n,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class ja{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class Ua{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let h=o.children[o.children.length-1]=new dt(l.dom,l.text+e);h.parent=o}else o.append(n||dt.of(e,(r=this.cache.find(dt))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Tn(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let l=t.marks.length-1;l>=0;l--){let h=t.marks[l],a=n.lastChild;if(a instanceof ae&&a.mark.eq(h.mark))a.dom!=h.dom&&a.setDOM(Tn(h.dom)),n=a;else{if(this.cache.reused.get(h)){let c=G.get(h.dom);c&&c.setDOM(Tn(h.dom))}let f=ae.of(h.mark,h.dom);n.append(f),n=f}this.cache.reused.set(h,2)}let r=G.get(e.text);r&&this.cache.reused.set(r,2);let o=new dt(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,n.append(o)}addInlineWidget(e,t,i){let n=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);n||this.flushBuffer();let r=this.ensureMarks(t,i);!n&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=Tl);let n=It.start(e,t||((i=this.cache.find(It))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let n=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=n.lastChild)&&l instanceof ae&&l.mark.eq(o))n=l,t--;else{let h=ae.of(o,(i=this.cache.find(ae,a=>a.mark.eq(o)))===null||i===void 0?void 0:i.dom);n.append(h),n=h,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Tr(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(S.ios&&Tr(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Dn,0,32)||new yt(Dn.toDOM(),0,Dn,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,i=new ja(e.from,e.to,e.value,t),n=this.wrappers.length;for(;n>0&&(this.wrappers[n-1].rank-i.rank||this.wrappers[n-1].to-i.to)<0;)n--;this.wrappers.splice(n,0,i)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof qe&&n.wrapper.eq(i.wrapper))t=n;else{let r=qe.of(i.wrapper,(e=this.cache.find(qe,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(Yi,void 0,1);return i&&(i.flags=t),i||new Yi(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Ga{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:n,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=n;let l=this.textOff=Math.min(e,n.length);return r?null:n.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const _i=[yt,It,dt,ae,Yi,qe,un];for(let s=0;s<_i.length;s++)_i[s].bucket=s;class Ja{constructor(e){this.view=e,this.buckets=_i.map(()=>[]),this.index=_i.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let n=e.bucket,r=this.buckets[n],o=this.index[n];for(let l=r.length-1;l>=0;l--){let h=(l+o)%r.length,a=r[h];if((!t||t(a))&&!this.reused.has(a))return r.splice(h,1),h<o&&this.index[n]--,this.reused.set(a,i),a}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,o=0;;r++){if(r==n.length){if(o)return null;o=1,r=0}let l=n[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new yt(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class Ya{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new Ja(e),this.text=new Ga(e.state.doc),this.builder=new Ua(this.cache,new un(e,e.contentDOM),L.iter(i)),this.cache.reused.set(t,2),this.old=new qa(t),this.reuseWalker={skip:(o,l,h)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let n=0,r=0,o=0;;){let l=o<e.length?e[o++]:null,h=l?l.fromA:this.old.root.length;if(h>n){let a=h-n;this.preserve(a,!o,!l),n=h,r+=a}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,n=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=Qa(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,h)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(h-l);else{let a=h>0||l<o.length?yt.of(o.widget,this.view,h-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,n,r),r=n.length)}else if(o.isText())this.builder.ensureLine(null),!l&&h==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,n,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,h),n,r)),r=n.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Yi)this.cache.add(o);else if(o instanceof ae)this.builder.ensureLine(null),this.builder.addMark(o,n,r),this.cache.reused.set(o,1),r=n.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof ae&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof ae&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,n=this.builder,r=0,o=L.spans(this.decorations,e,t,{point:(l,h,a,f,c,u)=>{if(a instanceof gt){if(this.disallowBlockEffectsFor[u]){if(a.block)throw new RangeError("Block decorations may not be specified via plugins");if(h>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=f.length,c>f.length)n.continueWidget(h-l);else{let d=a.widget||(a.block?Et.block:Et.inline),p=_a(a),g=this.cache.findWidget(d,h-l,p)||yt.of(d,this.view,h-l,p);a.block?(a.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(g)):(n.ensureLine(i),n.addInlineWidget(g,f,c))}i=null}else i=Xa(i,a);h>l&&this.text.skip(h-l)},span:(l,h,a,f)=>{for(let c=l;c<h;){let u=this.text.next(Math.min(512,h-c));u==null?(n.addLineStartIfNotCovered(i),n.addBreak(),c++):(n.ensureLine(i),n.addText(u,a,c==l?f:a.length),c+=u.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let r=G.get(n);if(n==this.view.contentDOM)break;r instanceof ae?t.push(r):r?.isLine()?i=r:r instanceof qe||(n.nodeName=="DIV"&&!i&&n!=this.view.contentDOM?i=new It(n,Tl):i||t.push(ae.of(new gi({tagName:n.nodeName.toLowerCase(),attributes:va(n)}),n)))}return{line:i,marks:t}}}function Tr(s,e){let t=i=>{for(let n of i.children)if((e?n.isText():n.length)||t(n))return!0;return!1};return t(s)}function _a(s){let e=s.isReplace?(s.startSide<0?64:0)|(s.endSide>0?128:0):s.startSide>0?32:16;return s.block&&(e|=256),e}const Tl={class:"cm-line"};function Xa(s,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(s||(s={class:"cm-line"}),t&&Fs(t,s),i&&(s.class+=" "+i)),s}function Qa(s){let e=[];for(let t=s.parents.length;t>1;t--){let i=t==s.parents.length?s.tile:s.parents[t].tile;i instanceof ae&&e.push(i.mark)}return e}function Tn(s){let e=G.get(s);return e&&e.setDOM(s.cloneNode()),s}class Et extends Wt{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Et.inline=new Et("span");Et.block=new Et("div");const Dn=new class extends Wt{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Dr{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=z.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new un(e,e.contentDOM),this.updateInner([new ye(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?n=this.domChanged.newSel.head:!hf(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?ef(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new ye(f,c,e.changes.mapPos(f,-1),e.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(S.ie||S.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let h=sf(o,this.decorations,e.changes);h.length&&(i=ye.extendWithRanges(i,h));let a=of(l,this.blockWrappers,e.changes);return a.length&&(i=ye.extendWithRanges(i,a)),r&&!i.some(f=>f.fromA<=r.range.fromA&&f.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new Ya(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&G.get(t.text)&&l.cache.reused.set(G.get(t.text),2),this.tile=l.run(e,t),ds(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=S.chrome||S.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof On&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(wl)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,o=!r&&!(this.view.state.facet(Ke)||i.tabIndex>-1)&&Qt(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,a,f;if(h.empty?f=a=this.inlineDOMNearPos(h.anchor,h.assoc||1):(f=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),a=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),S.gecko&&h.empty&&!this.hasComposition&&Za(a)){let u=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(u,a.node.childNodes[a.offset]||null)),a=f=new Ae(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!ei(a.node,a.offset,c.anchorNode,c.anchorOffset)||!ei(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,h))&&(this.view.observer.ignore(()=>{S.android&&S.chrome&&i.contains(c.focusNode)&&lf(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=li(this.view.root);if(u)if(h.empty){if(S.gecko){let d=tf(a.node,a.offset);if(d&&d!=3){let p=(d==1?ol:ll)(a.node,a.offset);p&&(a=new Ae(p.node,p.offset))}}u.collapse(a.node,a.offset),h.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=h.bidiLevel)}else if(u.extend){u.collapse(a.node,a.offset);try{u.extend(f.node,f.offset)}catch{}}else{let d=document.createRange();h.anchor>h.head&&([a,f]=[f,a]),d.setEnd(f.node,f.offset),d.setStart(a.node,a.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new Ae(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new Ae(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ei(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=li(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let h=this.coordsAt(t.head,-1),a=this.coordsAt(t.head,1);if(!h||!a||h.bottom>a.top)return;let f=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(f.node,f.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let n=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=Ue(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!G.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let h=i.children[o];if(h.dom==r)return l;l+=h.length+h.breakAfter}}else return i.isText()?e==i.dom?n+t:n+(t?i.length:0):n}domAtPos(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(n,t)}inlineDOMNearPos(e,t){let i,n=-1,r=!1,o,l=-1,h=!1;return this.tile.blockTiles((a,f)=>{if(a.isWidget()){if(a.flags&32&&f>=e)return!0;a.flags&16&&(r=!0)}else{let c=f+a.length;if(f<=e&&(i=a,n=e-f,r=c<e),c>=e&&!o&&(o=a,l=e-f,h=f>e),f>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:h&&i&&(o=null),i&&t<0||!o?i.domIn(n,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof On?null:i.coordsInWidget(n,t,!0):i.coordsIn(n,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function n(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let h=n(l,o);if(h)return h}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=ie(r.text,o);if(l==o)return null;let h=ai(r.dom,o,l).getClientRects();for(let a=0;a<h.length;a++){let f=h[a];if(a==h.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return n(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==Y.LTR,a=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>n);p++){let g=c.children[p],m=u+g.length,y=g.dom.getBoundingClientRect(),{height:k}=y;if(d&&!p&&(a+=y.top-d.top),g instanceof qe)m>i&&f(g,u,y);else if(u>=i&&(a>0&&t.push(-a),t.push(k+a),a=0,o)){let v=g.dom.lastChild,P=v?Zt(v):[];if(P.length){let M=P[P.length-1],T=h?M.right-y.left:y.right-M.left;T>l&&(l=T,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=m)}}d&&p==c.children.length-1&&(a+=d.bottom-y.bottom),u=m+g.breakAfter}};return f(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Y.RTL:Y.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,h;for(let a of o.children){if(!a.isText()||/[^ -~]/.test(a.text))return;let f=Zt(a.dom);if(f.length!=1)return;l+=f[0].width,h=f[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:h}}});if(e)return e;let t=document.createElement("div"),i,n,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Zt(t.firstChild)[0];i=t.getBoundingClientRect().height,n=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:n,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(z.replace({widget:new On(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return z.set(e)}updateDeco(){let e=1,t=this.view.state.facet(fn).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet($s).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[e++]=i,t.push(L.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(vl).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(xl))try{if(f(this.view,e.range,e))return!0}catch(c){Ne(this.view.state,c,"scroll handler")}let{range:i}=e,n=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!n)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let o=Ml(this.view),l={left:n.left-o.left,top:n.top-o.top,right:n.right+o.right,bottom:n.bottom+o.bottom},{offsetWidth:h,offsetHeight:a}=this.view.scrollDOM;if(Ma(this.view.scrollDOM,l,i.head<i.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,h),-h),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==Y.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(i.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){ds(this.tile)}}function ds(s,e){let t=e?.get(s);if(t!=1){t==null&&s.destroy();for(let i of s.children)ds(i,e)}}function Za(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}function Dl(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=ol(t.focusNode,t.focusOffset),n=ll(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=G.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let h=G.get(i.node);!h||h.isText()&&h.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function ef(s,e,t){let i=Dl(s,t);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let h=e.invertedDesc;return{range:new ye(h.mapPos(r),h.mapPos(o),r,o),text:n}}function tf(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e<s.childNodes.length&&s.childNodes[e].contentEditable=="false"?2:0)}let nf=class{constructor(){this.changes=[]}compareRange(e,t){Mt(e,t,this.changes)}comparePoint(e,t){Mt(e,t,this.changes)}boundChange(e){Mt(e,e,this.changes)}};function sf(s,e,t){let i=new nf;return L.compare(s,e,t,i),i.changes}class rf{constructor(){this.changes=[]}compareRange(e,t){Mt(e,t,this.changes)}comparePoint(){}boundChange(e){Mt(e,e,this.changes)}}function of(s,e,t){let i=new rf;return L.compare(s,e,t,i),i.changes}function lf(s,e){for(let t=s;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function hf(s,e){let t=!1;return e&&s.iterChangedRanges((i,n)=>{i<e.to&&n>e.from&&(t=!0)}),t}class On extends Wt{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function af(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return b.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=ie(n.text,r,!1):l=ie(n.text,r);let h=i(n.text.slice(o,l));for(;o>0;){let a=ie(n.text,o,!1);if(i(n.text.slice(a,o))!=h)break;o=a}for(;l<n.length;){let a=ie(n.text,l);if(i(n.text.slice(l,a))!=h)break;l=a}return b.range(o+n.from,l+n.from)}function ff(s,e,t,i,n){let r=Math.round((i-e.left)*s.defaultCharacterWidth);if(s.lineWrapping&&t.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,h=Math.floor((n-t.top-(s.defaultLineHeight-l)*.5)/l);r+=h*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(t.from,t.to);return t.from+ma(o,r,s.state.tabSize)}function cf(s,e,t){let i=s.lineBlockAt(e);if(Array.isArray(i.type)){let n;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!n||r.type==ce.Text&&(n.type!=r.type||(t<0?r.from<e:r.to>e)))&&(n=r)}}return n||i}return i}function uf(s,e,t,i){let n=cf(s,e.head,e.assoc||-1),r=!i||n.type!=ce.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),h=s.posAtCoords({x:t==(l==Y.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(h!=null)return b.cursor(h,t?-1:1)}return b.cursor(t?n.to:n.from,t?-1:1)}function Or(s,e,t,i){let n=s.state.doc.lineAt(e.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=e,h=null;;){let a=Fa(n,r,o,l,t),f=ul;if(!a){if(n.number==(t?s.state.doc.lines:1))return l;f=`
8
+ `,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),a=s.visualLineSide(n,!t)}if(h){if(!h(f))return l}else{if(!i)return a;h=i(f)}l=a}}function df(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==$e.Space&&(n=o),n==o}}function pf(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return b.cursor(n,e.assoc);let o=e.goalColumn,l,h=s.contentDOM.getBoundingClientRect(),a=s.coordsAtPos(n,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),f=s.documentTop;if(a)o==null&&(o=a.left-h.left),l=r<0?a.top:a.bottom;else{let p=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(h.right-h.left,s.defaultCharacterWidth*(n-p.from))),l=(r<0?p.top:p.bottom)+f}let c=h.left+o,u=s.viewState.heightOracle.textHeight>>1,d=i??u;for(let p=0;;p+=u){let g=l+(d+p)*r,m=ps(s,{x:c,y:g},!1,r);if(t?g>h.bottom:g<h.top)return b.cursor(m.pos,m.assoc);let y=s.coordsAtPos(m.pos,m.assoc),k=y?(y.top+y.bottom)/2:0;if(!y||(t?k>l:k<l))return b.cursor(m.pos,m.assoc,void 0,o)}}function ti(s,e,t){for(;;){let i=0;for(let n of s)n.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let h=i||t||(e-r<o-e?-1:1);e=h<0?r:o,i=h}});if(!i)return e}}function Ol(s,e){let t=null;for(let i=0;i<e.ranges.length;i++){let n=e.ranges[i],r=null;if(n.empty){let o=ti(s,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=ti(s,n.from,-1),l=ti(s,n.to,1);(o!=n.from||l!=n.to)&&(r=b.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}function Bn(s,e,t){let i=ti(s.state.facet(yi).map(n=>n(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class Le{constructor(e,t){this.pos=e,this.assoc=t}}function ps(s,e,t,i){let n=s.contentDOM.getBoundingClientRect(),r=n.top+s.viewState.paddingTop,{x:o,y:l}=e,h=l-r,a;for(;;){if(h<0)return new Le(0,1);if(h>s.viewState.docHeight)return new Le(s.state.doc.length,-1);if(a=s.elementAtHeight(h),i==null)break;if(a.type==ce.Text){if(i<0?a.to<s.viewport.from:a.from>s.viewport.to)break;let u=s.docView.coordsAt(i<0?a.from:a.to,i>0?-1:1);if(u&&(i<0?u.top<=h+r:u.bottom>=h+r))break}let c=s.viewState.heightOracle.textHeight/2;h=i>0?a.bottom+c:a.top-c}if(s.viewport.from>=a.to||s.viewport.to<=a.from){if(t)return null;if(a.type==ce.Text){let c=ff(s,n,a,o,l);return new Le(c,c==a.from?1:-1)}}if(a.type!=ce.Text)return h<(a.top+a.bottom)/2?new Le(a.from,1):new Le(a.to,-1);let f=s.docView.lineAt(a.from,2);return(!f||f.length!=a.length)&&(f=s.docView.lineAt(a.from,-2)),new gf(s,o,l,s.textDirectionAt(a.from)).scanTile(f,a.from)}class gf{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Re.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Re.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t,i=!1){let n=0,r=e.length-1,o=new Set,l=this.bidiIn(e[0],e[r]),h,a,f=-1,c=1e9,u;e:for(;n<r;){let p=r-n,g=n+r>>1;t:if(o.has(g)){let y=n+Math.floor(Math.random()*p);for(let k=0;k<p;k++){if(!o.has(y)){g=y;break t}y++,y==r&&(y=n)}break e}o.add(g);let m=t(g);if(m)for(let y=0;y<m.length;y++){let k=m[y],v=0;if(!(k.width==0&&m.length>1)){if(k.bottom<this.y)(!h||h.bottom<k.bottom)&&(h=k),v=1;else if(k.top>this.y)(!a||a.top>k.top)&&(a=k),v=-1;else{let P=k.left>this.x?this.x-k.left:k.right<this.x?this.x-k.right:0,M=Math.abs(P);M<c&&(f=g,c=M,u=k),P&&(v=P<0==(this.baseDir==Y.LTR)?-1:1)}v==-1&&(!l||this.baseDirAt(e[g],1))?r=g:v==1&&(!l||this.baseDirAt(e[g+1],-1))&&(n=g+1)}}}if(!u){if(!a&&!h)return{i:e[0],after:!1};let p=h&&(!a||this.y-h.bottom<a.top-this.y)?h:a;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(c&&!i){let{top:p,bottom:g}=u;if(h&&h.bottom>(p+p+g)/3)return this.y=h.bottom-1,this.scan(e,t,!0);if(a&&a.top<(p+g+g)/3)return this.y=a.top+1,this.scan(e,t,!0)}let d=(l?this.dirAt(e[f],1):this.baseDir)==Y.LTR;return{i:f,after:this.x>(u.left+u.right)/2==d}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=ie(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return ai(e.dom,o,l).getClientRects()});return n.after?new Le(i[n.i+1],-1):new Le(i[n.i],1)}scanTile(e,t){if(!e.length)return new Le(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,h=t;l<e.children.length;l++)i.push(h+=e.children[l].length);let n=this.scan(i,l=>{let h=e.children[l];return h.flags&48?null:(h.dom.nodeType==1?h.dom:ai(h.dom,0,h.length)).getClientRects()}),r=e.children[n.i],o=i[n.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):n.after?new Le(i[n.i+1],-1):new Le(o,1)}}const wt="￿";class mf{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(N.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=wt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=G.get(n),l=n.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let h=G.get(l);(o&&h?o.breakAfter:(o?o.breakAfter:Gi(n))||Gi(l)&&(n.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!bf(l,t)&&this.lineBreak(),n=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==e&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(e){let t=G.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(yf(e,i.node,i.offset)?t:0))}}function yf(s,e,t){for(;;){if(!e||t<Ue(e))return!1;if(e==s)return!0;t=st(e)+1,e=e.parentNode}}function bf(s,e){let t;for(;!(s==e||!s);s=s.nextSibling){let i=G.get(s);if(!i?.isWidget())return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let n=i.overrideDOMText;if(n?.length)return!1}return!0}class Br{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class kf{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Bl(e.docView.tile,t,i,0))){let h=r||o?[]:wf(e),a=new mf(h,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Sf(h,this.bounds.from)}else{let h=e.observer.selectionRange,a=r&&r.node==h.focusNode&&r.offset==h.focusOffset||!hs(e.contentDOM,h.focusNode)?l.main.head:e.docView.posFromDOM(h.focusNode,h.focusOffset),f=o&&o.node==h.anchorNode&&o.offset==h.anchorOffset||!hs(e.contentDOM,h.anchorNode)?l.main.anchor:e.docView.posFromDOM(h.anchorNode,h.anchorOffset),c=e.viewport;if((S.ios||S.chrome)&&l.main.empty&&a!=f&&(c.from>0||c.to<e.state.doc.length)){let u=Math.min(a,f),d=Math.max(a,f),p=c.from-u,g=c.to-d;(p==0||p==1||u==0)&&(g==0||g==-1||d==e.state.doc.length)&&(a=0,f=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(b.range(f,a));else if(e.lineWrapping&&f==a&&!(l.main.empty&&l.main.head==a)&&e.inputState.lastTouchTime>Date.now()-100){let u=e.coordsAtPos(a,-1),d=0;u&&(d=e.inputState.lastTouchY<=u.bottom?-1:1),this.newSel=b.create([b.cursor(a,d)])}else this.newSel=b.single(f,a)}}}function Bl(s,e,t,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let h=0,a=i,f=i;h<s.children.length;h++){let c=s.children[h],u=a+c.length;if(a<e&&u>t)return Bl(c,e,t,a);if(u>=e&&n==-1&&(n=h,r=a),a>t&&c.dom.parentNode==s.dom){o=h,l=f;break}f=u,a=u+c.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o<s.children.length&&o>=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function Pl(s,e){let t,{newSel:i}=e,{state:n}=s,r=n.selection.main,o=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:h}=e.bounds,a=r.from,f=null;(o===8||S.android&&e.text.length<h-l)&&(a=r.to,f="end");let c=n.doc.sliceString(l,h,wt),u,d;!r.empty&&r.from>=l&&r.to<=h&&(e.typeOver||c!=e.text)&&c.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&c.slice(r.to-l)==e.text.slice(u=e.text.length-(c.length-(r.to-l)))?t={from:r.from,to:r.to,insert:E.of(e.text.slice(r.from-l,u).split(wt))}:(d=Il(c,e.text,a-l,f))&&(S.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==wt+wt&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:E.of(e.text.slice(d.from,d.toB).split(wt))})}else i&&(!s.hasFocus&&n.facet(Ke)||Xi(i,r))&&(i=null);if(!t&&!i)return!1;if((S.mac||S.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:E.of([t.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).to<r.to&&s.docView.lineHasWidget(r.to)&&s.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:S.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
9
+ `&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:E.of([" "])}),t)return qs(s,t,i,o);if(i&&!Xi(i,r)){let l=!1,h="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(l=!0),h=s.inputState.lastSelectionOrigin,h=="select.pointer"&&(i=Ol(n.facet(yi).map(a=>a(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:h}),!0}else return!1}function qs(s,e,t,i=-1){if(S.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(S.android&&(e.to==n.to&&(e.from==n.from||e.from==n.from-1&&s.state.sliceDoc(e.from,n.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Tt(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>n.head)&&Tt(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&Tt(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=xf(s,e,t));return s.state.facet(yl).some(h=>h(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function xf(s,e,t){let i,n=s.state,r=n.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let h=e.from<r.from?-1:1,a=h<0?r.from:r.to,f=ti(n.facet(yi).map(c=>c(s)),a,h);e.from==f&&(o=f)}if(o>-1)i={changes:e,selection:b.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&s.inputState.composing<0){let h=r.from<e.from?n.sliceDoc(r.from,e.from):"",a=r.to>e.to?n.sliceDoc(e.to,r.to):"";i=n.replaceSelection(s.state.toText(h+e.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let h=n.changes(e),a=t&&t.main.to<=h.newLength?t.main:void 0;if(n.selection.ranges.length>1&&(s.inputState.composing>=0||s.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let f=s.state.sliceDoc(e.from,e.to),c,u=t&&Dl(s,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);c={from:u.from,to:u.to-p}}else c=s.state.doc.lineAt(r.head);let d=r.to-e.to;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:h,range:a||p.map(h)};let g=p.to-d,m=g-f.length;if(s.state.sliceDoc(m,g)!=f||g>=c.from&&m<=c.to)return{range:p};let y=n.changes({from:m,to:g,insert:e.insert}),k=p.to-r.to;return{changes:y,range:a?b.range(Math.max(0,a.anchor+k),Math.max(0,a.head+k)):p.map(y)}})}else i={changes:h,selection:a&&n.selection.replaceRange(a)}}let l="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,l+=".compose",s.inputState.compositionFirstChange&&(l+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:l,scrollIntoView:!0})}function Il(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r<n&&s.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==n&&s.length==e.length)return null;let o=s.length,l=e.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));t-=o+h-r}if(o<r&&s.length<e.length){let h=t<=r&&t>=o?r-t:0;r-=h,l=r+(l-o),o=r}else if(l<r){let h=t<=r&&t>=l?r-t:0;r-=h,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function wf(s){let e=[];if(s.root.activeElement!=s.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return t&&(e.push(new Br(t,i)),(n!=t||r!=i)&&e.push(new Br(n,r))),e}function Sf(s,e){if(s.length==0)return null;let t=s[0].pos,i=s.length==2?s[1].pos:t;return t>-1&&i>-1?b.single(t+e,i+e):null}function Xi(s,e){return e.head==s.main.head&&e.anchor==s.main.anchor}class vf{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,S.safari&&e.contentDOM.addEventListener("input",()=>null),S.gecko&&Wf(e.contentDOM.ownerDocument)}handleEvent(e){!Pf(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let n of i.observers)n(this.view,t);for(let n of i.handlers){if(t.defaultPrevented)break;if(n(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Af(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Ll.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),S.android&&S.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return S.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=El.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Cf.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Tt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:S.safari&&!S.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Pr(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){Ne(t.state,n)}}}function Af(s){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec,r=n&&n.plugin.domEventHandlers,o=n&&n.plugin.domEventObservers;if(r)for(let l in r){let h=r[l];h&&t(l).handlers.push(Pr(i.value,h))}if(o)for(let l in o){let h=o[l];h&&t(l).observers.push(Pr(i.value,h))}}for(let i in Ce)t(i).handlers.push(Ce[i]);for(let i in ue)t(i).observers.push(ue[i]);return e}const El=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Cf="dthko",Ll=[16,17,18,20,91,92,224,225],Mi=6;function Ti(s){return Math.max(0,s)*.7+8}function Mf(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class Tf{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=nl(e.contentDOM),this.atoms=e.state.facet(yi).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(N.allowMultipleSelections)&&Df(e,t),this.dragging=Bf(e,t)&&Fl(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Mf(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=Ml(this.view);e.clientX-h.left<=n+Mi?t=-Ti(n-e.clientX):e.clientX+h.right>=o-Mi&&(t=Ti(e.clientX-o)),e.clientY-h.top<=r+Mi?i=-Ti(r-e.clientY):e.clientY+h.bottom>=l-Mi&&(i=Ti(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=Ol(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Df(s,e){let t=s.state.facet(dl);return t.length?t[0](e):S.mac?e.metaKey:e.ctrlKey}function Of(s,e){let t=s.state.facet(pl);return t.length?t[0](e):S.mac?!e.altKey:!e.ctrlKey}function Bf(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=li(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Pf(s,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=s.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Ce=Object.create(null),ue=Object.create(null),Rl=S.ie&&S.ie_version<15||S.ios&&S.webkit_version<604;function If(s){let e=s.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{s.focus(),t.remove(),Nl(s,t.value)},50)}function dn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function Nl(s,e){e=dn(s.state,Vs,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(gs!=null&&t.selection.ranges.every(h=>h.empty)&&gs==r.toString()){let h=-1;i=t.changeByRange(a=>{let f=t.doc.lineAt(a.from);if(f.from==h)return{range:a};h=f.from;let c=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:b.cursor(a.from+c.length)}})}else o?i=t.changeByRange(h=>{let a=r.line(n++);return{changes:{from:h.from,to:h.to,insert:a.text},range:b.cursor(h.from+a.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}ue.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ue.wheel=ue.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};Ce.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);ue.touchstart=(s,e)=>{let t=s.inputState,i=e.targetTouches[0];t.lastTouchTime=Date.now(),i&&(t.lastTouchX=i.clientX,t.lastTouchY=i.clientY),t.setSelectionOrigin("select.pointer")};ue.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Ce.mousedown=(s,e)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of s.state.facet(gl))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Lf(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new Tf(s,e,t,i)),i&&s.observer.ignore(()=>{sl(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(e),n.dragging===!1}else s.inputState.setSelectionOrigin("select.pointer");return!1};function Ir(s,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return af(s.state,e,t);{let n=s.docView.lineAt(e,t),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,b.range(o,l)}}const Ef=S.ie&&S.ie_version<=11;let Er=null,Lr=0,Rr=0;function Fl(s){if(!Ef)return s.detail;let e=Er,t=Rr;return Er=s,Rr=Date.now(),Lr=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(Lr+1)%3:1}function Lf(s,e){let t=s.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Fl(e),n=s.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),n=n.map(r.changes))},get(r,o,l){let h=s.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),a,f=Ir(s,h.pos,h.assoc,i);if(t.pos!=h.pos&&!o){let c=Ir(s,t.pos,t.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?b.range(u,d,f.assoc):b.range(d,u,f.assoc)}return o?n.replaceRange(n.main.extend(f.from,f.to,f.assoc)):l&&i==1&&n.ranges.length>1&&(a=Rf(n,h.pos))?a:l?n.addRange(f):b.create([f])}}}function Rf(s,e){for(let t=0;t<s.ranges.length;t++){let{from:i,to:n}=s.ranges[t];if(i<=e&&n>=e)return b.create(s.ranges.slice(0,t).concat(s.ranges.slice(t+1)),s.mainIndex==t?0:s.mainIndex-(s.mainIndex>t?1:0))}return null}Ce.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.tile.nearest(e.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",dn(s.state,zs,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Ce.dragend=s=>(s.inputState.draggedContent=null,!1);function Nr(s,e,t,i){if(t=dn(s.state,Vs,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Of(s,e)?{from:r.from,to:r.to}:null,l={from:n,insert:t},h=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:h,selection:{anchor:h.mapPos(n,-1),head:h.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Ce.drop=(s,e)=>{if(!e.dataTransfer)return!1;if(s.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),n=0,r=()=>{++n==t.length&&Nr(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return Nr(s,e,i,!0),!0}return!1};Ce.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=Rl?null:e.clipboardData;return t?(Nl(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(If(s),!1)};function Nf(s,e){let t=s.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function Ff(s){let e=[],t=[],i=!1;for(let n of s.selection.ranges)n.empty||(e.push(s.sliceDoc(n.from,n.to)),t.push(n));if(!e.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(e.push(o.text),t.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:dn(s,zs,e.join(s.lineBreak)),ranges:t,linewise:i}}let gs=null;Ce.copy=Ce.cut=(s,e)=>{if(!Qt(s.contentDOM,s.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:n}=Ff(s.state);if(!t&&!n)return!1;gs=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Rl?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Nf(s,t),!1)};const Wl=Ye.define();function Hl(s,e){let t=[];for(let i of s.facet(bl)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:Wl.of(!0)}):null}function Vl(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Hl(s.state,e);t?s.dispatch(t):s.update([])}},10)}ue.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),Vl(s)};ue.blur=s=>{s.observer.clearSelectionRange(),Vl(s)};ue.compositionstart=ue.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};ue.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,S.chrome&&S.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};ue.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Ce.beforeinput=(s,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(s.inputState.insertingText=e.data,s.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&s.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],h=s.posAtDOM(l.startContainer,l.startOffset),a=s.posAtDOM(l.endContainer,l.endOffset);return qs(s,{from:h,to:a,insert:s.state.toText(r)},null),!0}}let n;if(S.chrome&&S.android&&(n=El.find(r=>r.inputType==e.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return S.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),S.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>ue.compositionend(s,e),20),!1};const Fr=new Set;function Wf(s){Fr.has(s)||(Fr.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const Wr=["pre-wrap","normal","pre-line","break-spaces"];let Lt=!1;function Hr(){Lt=!1}class Hf{constructor(e){this.lineWrapping=e,this.doc=E.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Wr.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(t=!0,this.heightSamples[Math.floor(n*10)]=!0)}return t}refresh(e,t,i,n,r,o){let l=Wr.indexOf(e)>-1,h=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,h){this.heightSamples={};for(let a=0;a<o.length;a++){let f=o[a];f<0?a++:this.heightSamples[Math.floor(f*10)]=!0}}return h}}class Vf{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class ve{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?ce.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof gt?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new ve(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var V=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})(V||(V={}));const Vi=.001;class he{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Vi&&(Lt=!0),this.height=e)}replace(e,t,i){return he.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:h,toA:a,fromB:f,toB:c}=n[l],u=r.lineAt(h,V.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=a?u:r.lineAt(a,V.ByPosNoHeight,i,0,0);for(c+=d.to-a,a=d.to;l>0&&u.from<=n[l-1].toA;)h=n[l-1].fromA,f=n[l-1].fromB,l--,h<u.from&&(u=r.lineAt(h,V.ByPosNoHeight,i,0,0));f+=u.from-h,h=u.from;let p=js.build(i.setDoc(o),e,f,c);r=Qi(r,r.replace(h,a,p))}return r.updateHeight(i,0)}static empty(){return new pe(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=e[t++];l&&(n+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Kf(he.of(e.slice(0,t)),o,he.of(e.slice(i)))}}function Qi(s,e){return s==e?s:(s.constructor!=e.constructor&&(Lt=!0),e)}he.prototype.size=1;const zf=z.replace({});class zl extends he{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new ve(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new ve(n,0,i,this.spaceAbove,zf):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let o=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(o):o}forEachLine(e,t,i,n,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,V.ByPos,i,n,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class pe extends zl{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new ve(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof pe||n instanceof Z&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Z?n=new pe(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):he.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Z extends he{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,n=e.doc.lineAt(t+this.length).number,r=n-i+1,o,l=0;if(e.lineWrapping){let h=Math.min(this.height,e.lineHeight*r);o=h/r,this.length>r+1&&(l=(this.height-h)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(e,t,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(t,n);if(t.lineWrapping){let a=n+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),f=t.doc.lineAt(a),c=l+f.length*h,u=Math.max(i,e-c/2);return new ve(f.from,f.length,u,c,0)}else{let a=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:f,length:c}=t.doc.line(r+a);return new ve(f,c,i+l*a,l,0)}}lineAt(e,t,i,n,r){if(t==V.ByHeight)return this.blockAt(e,i,n,r);if(t==V.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new ve(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,r),a=i.doc.lineAt(e),f=l+a.length*h,c=a.number-o,u=n+l*c+h*(a.from-r-c);return new ve(a.from,a.length,Math.max(n,Math.min(u,n+this.height-f)),f,0)}forEachLine(e,t,i,n,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:h,perChar:a}=this.heightMetrics(i,r);for(let f=e,c=n;f<=t;){let u=i.doc.lineAt(f);if(f==e){let p=u.number-l;c+=h*p+a*(e-r-p)}let d=h+a*u.length;o(new ve(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let r=i[i.length-1];r instanceof Z?i[i.length-1]=new Z(r.length+n):i.push(null,new Z(n-1))}if(e>0){let r=i[0];r instanceof Z?i[0]=new Z(e+r.length):i.unshift(new Z(e-1),null)}return he.of(i)}decomposeLeft(e,t){t.push(new Z(e-1),null)}decomposeRight(e,t){t.push(null,new Z(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let o=[],l=Math.max(t,n.from),h=-1;for(n.from>t&&o.push(new Z(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++],u=0;c<0&&(u=-c,c=n.heights[n.index++]),h==-1?h=c:Math.abs(c-h)>=Vi&&(h=-2);let d=new pe(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new Z(r-l).updateHeight(e,l));let a=he.of(o);return(h<0||Math.abs(a.height-this.height)>=Vi||Math.abs(h-this.heightMetrics(e,t).perLine)>=Vi)&&(Lt=!0),Qi(this,a)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Kf extends he{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,h=t==V.ByHeight?e<o:e<l,a=h?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let f=t==V.ByPosNoHeight?V.ByPosNoHeight:V.ByPos;return h?a.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,n,r).join(a)}forEachLine(e,t,i,n,r,o){let l=n+this.left.height,h=r+this.left.length+this.break;if(this.break)e<h&&this.left.forEachLine(e,t,i,n,r,o),t>=h&&this.right.forEachLine(e,t,i,l,h,o);else{let a=this.lineAt(h,V.ByPos,i,n,r);e<a.from&&this.left.forEachLine(e,a.from-1,i,n,r,o),a.to>=e&&a.from<=t&&o(a),t>a.to&&this.right.forEachLine(a.to+1,t,i,l,h,o)}}replace(e,t,i){let n=this.left.length+this.break;if(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Vr(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Vr(r,l)}return he.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?he.of(this.break?[e,null,t]:[e,t]):(this.left=Qi(this.left,e),this.right=Qi(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:o}=this,l=t+r.length+this.break,h=null;return n&&n.from<=t+r.length&&n.more?h=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?h=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vr(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof Z&&(i=s[e+1])instanceof Z&&s.splice(e-1,3,new Z(t.length+1+i.length))}const $f=5;class js{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof pe?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new pe(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new zl(o,n,i)):(o||r||n>=$f)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new pe(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new Z(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof pe)return e;let t=new pe(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof pe)&&!this.isCovered?this.nodes.push(new pe(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let n of this.nodes)n instanceof pe&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new js(i,e);return L.spans(t,i,n,r,0),r.finish(i)}}function qf(s,e,t){let i=new jf;return L.compare(s,e,t,i,0),i.changes}class jf{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&Mt(e,t,this.changes,5)}}function Uf(s,e){let t=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(n.innerWidth,t.right),l=Math.max(0,t.top),h=Math.min(n.innerHeight,t.bottom);for(let a=s.parentNode;a&&a!=i.body;)if(a.nodeType==1){let f=a,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(a==s.parentNode?n.innerHeight:h,u.bottom)}a=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(a.nodeType==11)a=a.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,h)-(t.top+e)}}function Gf(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function Jf(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Pn{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return z.replace({widget:new Yf(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class Yf extends Wt{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class zr{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Kr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Y.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet(Ks).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Hf(i),this.stateDeco=$r(t),this.heightMap=he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle.setDoc(t.doc),[new ye(0,0,0,t.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=z.set(this.lineGaps.map(n=>n.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);e.push(new Di(r,o))}}return this.viewports=e.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Kr:new Us(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Jt(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=$r(this.state);let n=e.changedRanges,r=ye.extendWithRanges(n,qf(i,this.stateDeco,e?e.changes:X.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Hr(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Lt)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let h=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<h.from||t.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,t));let a=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,e.flags|=this.updateForViewport(),(a||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ha)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Y.RTL:Y.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let a=0,f=0;if(l.width&&l.height){let{scaleX:M,scaleY:T}=il(t,l);(M>.005&&Math.abs(this.scaleX-M)>.005||T>.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=M,this.scaleY=T,a|=16,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(h=!0),this.editorWidth=e.scrollDOM.clientWidth,a|=16);let d=nl(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=rl(this.scrollParent||e.win);let g=(this.printing?Jf:Uf)(t,this.paddingTop),m=g.top-this.pixelViewport.top,y=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let k=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(k!=this.inView&&(this.inView=k,k&&(h=!0)),!this.inView&&!this.scrollTarget&&!Gf(e.dom))return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,a|=16),h){let M=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(M)&&(o=!0),o||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:T,charWidth:C,textHeight:K}=e.docView.measureTextSize();o=T>0&&n.refresh(r,T,C,K,Math.max(5,v/C),M),o&&(e.docView.minWidth=0,a|=16)}m>0&&y>0?f=Math.max(m,y):m<0&&y<0&&(f=Math.min(m,y)),Hr();for(let T of this.viewports){let C=T.from==this.viewport.from?M:e.docView.measureVisibleLineHeights(T);this.heightMap=(o?he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle,[new ye(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Vf(T.from,C))}Lt&&(a|=2)}let P=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return P&&(a&2&&(a|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),a|=this.updateForViewport()),(a&2||P)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new Di(n.lineAt(o-i*1e3,V.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,V.ByHeight,r,0,0).to);if(t){let{head:a}=t.range;if(a<h.from||a>h.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(a,V.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&a<h.from?u=c.top:u=c.bottom-f,h=new Di(n.lineAt(u-1e3/2,V.ByHeight,r,0,0).from,n.lineAt(u+f+1e3/2,V.ByHeight,r,0,0).to)}}return h}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new Di(this.heightMap.lineAt(i,V.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,V.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,V.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||n<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new Pn(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=Y.LTR&&!i)return[];let l=[],h=(f,c,u,d)=>{if(c-f<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let y of g)if(y>f&&y<c){h(f,y-10,u,d),h(y+10,c,u,d);return}let m=Xf(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-f)<r&&Math.abs(y.to-c)<r&&!g.some(k=>y.from<k&&y.to>k));if(!m){if(c<u.to&&t&&i&&t.visibleRanges.some(v=>v.from<=c&&v.to>=c)){let v=t.moveToLineBoundary(b.cursor(c),!1,!0).head;v>f&&(c=v)}let y=this.gapSize(u,f,c,d),k=i||y<2e6?y:2e6;m=new Pn(f,c,y,k)}l.push(m)},a=f=>{if(f.length<o||f.type!=ce.Text)return;let c=_f(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,y;if(u!=null){let k=Bi(c,u),v=((this.visibleBottom-this.visibleTop)/2+g)/f.height;m=k-v,y=k+v}else m=(this.visibleTop-f.top-g)/f.height,y=(this.visibleBottom-f.top+g)/f.height;d=Oi(c,m),p=Oi(c,y)}else{let g=c.total*this.heightOracle.charWidth,m=n*this.heightOracle.charWidth,y=0;if(g>2e6)for(let T of e)T.from>=f.from&&T.from<f.to&&T.size!=T.displaySize&&T.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=T.size-T.displaySize);let k=this.pixelViewport.left+y,v=this.pixelViewport.right+y,P,M;if(u!=null){let T=Bi(c,u),C=((v-k)/2+m)/g;P=T-C,M=T+C}else P=(k-m)/g,M=(v+m)/g;d=Oi(c,P),p=Oi(c,M)}d>f.from&&h(f.from,d,f,c),p<f.to&&h(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(a):a(f);return l}gapSize(e,t,i,n){let r=Bi(n,i)-Bi(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){Pn.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=z.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];L.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(n&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(n|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Jt(this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Jt(this.heightMap.lineAt(this.scaler.fromDOM(e),V.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Jt(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Di{constructor(e,t){this.from=e,this.to=t}}function _f(s,e,t){let i=[],n=s,r=0;return L.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<e&&(i.push({from:n,to:e}),r+=e-n),{total:r,ranges:i}}function Oi({total:s,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(s*t);for(let n=0;;n++){let{from:r,to:o}=e[n],l=o-r;if(i<=l)return r+i;i-=l}}function Bi(s,e){let t=0;for(let{from:i,to:n}of s.ranges){if(e<=n){t+=e-i;break}t+=n-i}return t/s.total}function Xf(s,e){for(let t of s)if(e(t))return t}const Kr={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function $r(s){let e=s.facet(fn).filter(i=>typeof i!="function"),t=s.facet($s).filter(i=>typeof i!="function");return t.length&&e.push(L.join(t)),e}class Us{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=t.lineAt(l,V.ByPos,e,0,0).top,f=t.lineAt(h,V.ByPos,e,0,0).bottom;return n+=f-a,{from:l,to:h,top:a,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof Us?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function Jt(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new ve(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>Jt(n,e)):s._content)}const Pi=A.define({combine:s=>s.join(" ")}),ms=A.define({combine:s=>s.indexOf(!0)>-1}),ys=it.newName(),Kl=it.newName(),$l=it.newName(),ql={"&light":"."+Kl,"&dark":"."+$l};function bs(s,e,t){return new it(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!t||!t[n])throw new RangeError(`Unsupported selector: ${n}`);return t[n]}):s+" "+i}})}const Qf=bs("."+ys,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},ql),Zf={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},In=S.ie&&S.ie_version<=11;class ec{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Ta,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(S.ie&&S.ie_version<=11||S.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&S.android&&e.constructor.EDIT_CONTEXT!==!1&&!(S.chrome&&S.chrome_version<126)&&(this.editContext=new ic(e),e.state.facet(Ke)&&(e.contentDOM.editContext=this.editContext.editContext)),In&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Ke)?i.root.activeElement!=this.dom:!Qt(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(S.ie&&S.ie_version<=11||S.android&&S.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ei(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=li(e.root);if(!t)return!1;let i=S.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&tc(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=Qt(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Oa(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Zf),In&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),In&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Tt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Qt(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new kf(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Pl(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!Xi(this.view.state.selection,t.newSel.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=qr(t,e.previousSibling||e.target.previousSibling,-1),n=qr(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Ke)!=e.state.facet(Ke)&&(e.view.contentDOM.editContext=e.state.facet(Ke)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function qr(s,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==s)return i;let n=e.parentNode;e=n!=s.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function jr(s,e){let t=e.startContainer,i=e.startOffset,n=e.endContainer,r=e.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor,1);return ei(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function tc(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return jr(s,n)}let t=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),t=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),t?jr(s,t):null}class ic{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let n=e.state.selection.main,{anchor:r,head:o}=n,l=this.toEditorPos(i.updateRangeStart),h=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let a=h-l>i.text.length;l==this.from&&r<this.from?l=r:h==this.to&&r>this.to&&(h=r);let f=Il(e.state.sliceDoc(l,h),i.text,(a?n.from:n.to)-l,a?"end":null);if(!f){let u=b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Xi(u,n)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:E.of(i.text.slice(f.from,f.toB).split(`
10
10
  `))};if((S.mac||S.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:h,insert:E.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!e.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);qs(e,c,b.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),c.from<c.to&&!c.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let h=e.coordsForChar(o);r=h&&new DOMRect(h.left,h.top,h.right-h.left,h.bottom-h.top)||r||new DOMRect,n.push(r)}t.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let h=this.toEditorPos(r.rangeStart),a=this.toEditorPos(r.rangeEnd);if(h<a){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;n.push(z.mark({attributes:{style:f}}).range(h,a))}}}e.dispatch({effects:wl.of(z.set(n))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=li(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,n=this.pendingContextChange;return e.changes.iterChanges((r,o,l,h,a)=>{if(i)return;let f=a.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(a)){n=this.pendingContextChange=null,t+=f,this.to+=f;return}else n=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=f,this.to+=f;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+a.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),a.toString()),this.to+=f}t+=f}),n&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(n=>!n.isUserEvent("input.type")&&n.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),n=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class D{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(n=>n.forEach(r=>i(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Da(e.parent)||document,this.viewState=new zr(this,e.state||N.create(e)),e.scrollTo&&e.scrollTo.is(Ci)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(St).map(n=>new Mn(n));for(let n of this.plugins)n.update(this);this.observer=new ec(this),this.inputState=new vf(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Dr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof _?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,n,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,h=null;e.some(u=>u.annotation(Wl))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=Hl(r,o),h||(l=1));let a=this.observer.delayedAndroidKey,f=null;if(a?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(f=null)):this.observer.clear(),r.facet(N.phrases)!=this.state.facet(N.phrases))return this.setState(r);n=Ji.create(this,r,e),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:g}=this.state.facet(D.cursorScrollMargin);c=new Dt(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",g,p)}for(let d of u.effects)d.is(Ci)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=Zi.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(Gt)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Pi)!=n.state.facet(Pi)&&(this.viewState.mustMeasureContent=!0),(t||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(us))try{u(n)}catch(d){Ne(this.state,d,"update listener")}(h||f)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),f&&!Pl(this,f)&&a.force&&Tt(this.contentDOM,a.key,a.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new zr(this,e),this.plugins=e.facet(St).map(i=>new Mn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Dr(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(St),i=e.state.facet(St);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new Mn(r));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){Ne(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(rl(i||this.win))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);r=d.from,o=d.top}this.updateState=1;let h=this.viewState.measure();if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let a=[];h&4||([this.measureRequests,a]=[a,this.measureRequests]);let f=a.map(d=>{try{return d.read(this)}catch(p){return Ne(this.state,p),Ur}}),c=Ji.create(this,this.state,[]),u=!1;c.flags|=h,t?t.flags|=h:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<a.length;d++)if(f[d]!=Ur)try{let p=a[d];p.write&&p.write(f[d],this)}catch(p){Ne(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o)/this.scaleY;if((p>1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n=n+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(us))l(t)}get themeClasses(){return ys+" "+(this.state.facet(ms)?$l:Kl)+" "+this.state.facet(Pi)}updateAttrs(){let e=Gr(this,Sl,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Ke)?"true":"false",class:"cm-content",style:`${S.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Gr(this,Ks,t);let i=this.observer.ignore(()=>{let n=Sr(this.contentDOM,this.contentAttrs,t),r=Sr(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let n of i.effects)if(n.is(D.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(Gt);let e=this.state.facet(D.cspNonce);it.mount(this.root,this.styleModules.concat(Qf).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Bn(this,e,Or(this,e,t,i))}moveByGroup(e,t){return Bn(this,e,Or(this,e,t,i=>df(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return b.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return uf(this,e,t,i)}moveVertically(e,t,i){return Bn(this,e,pf(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=ps(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),ps(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),o=r[Re.find(r,e-n.from,-1,t)];return hi(i,o.dir==Y.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(kl)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>nc)return cl(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||fl(r.isolates,i=Cr(this,e))))return r.order;i||(i=Cr(this,e));let n=Na(e.text,t,i);return this.bidiCache.push(new Zi(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||S.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{sl(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,n,r,o;return Ci.of(new Dt(typeof e=="number"?b.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(n=t.x)!==null&&n!==void 0?n:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Ci.of(new Dt(b.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Ge.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Ge.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=it.newName(),n=[Pi.of(i),Gt.of(bs(`.${i}`,e))];return t&&t.dark&&n.push(ms.of(!0)),n}static baseTheme(e){return on.lowest(Gt.of(bs("."+ys,e,ql)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&G.get(i)||G.get(e);return((t=n?.root)===null||t===void 0?void 0:t.view)||null}}D.styleModule=Gt;D.inputHandler=yl;D.clipboardInputFilter=Vs;D.clipboardOutputFilter=zs;D.scrollHandler=xl;D.focusChangeEffect=bl;D.perLineTextDirection=kl;D.exceptionSink=ml;D.updateListener=us;D.editable=Ke;D.mouseSelectionStyle=gl;D.dragMovesSelection=pl;D.clickAddsSelectionRange=dl;D.decorations=fn;D.blockWrappers=vl;D.outerDecorations=$s;D.atomicRanges=yi;D.bidiIsolatedRanges=Al;D.cursorScrollMargin=A.define({combine:s=>{let e=5,t=5;for(let i of s)typeof i=="number"?e=t=i:{x:e,y:t}=i;return{x:e,y:t}}});D.scrollMargins=Cl;D.darkTheme=ms;D.cspNonce=A.define({combine:s=>s.length?s[0]:""});D.contentAttributes=Ks;D.editorAttributes=Sl;D.lineWrapping=D.contentAttributes.of({class:"cm-lineWrapping"});D.announce=q.define();const nc=4096,Ur={};class Zi{constructor(e,t,i,n,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],n=e.length?e[e.length-1].dir:Y.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==n&&!t.touchesRange(o.from,o.to)&&i.push(new Zi(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Gr(s,e,t){for(let i=s.state.facet(e),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Fs(o,t)}return t}const sc=S.mac?"mac":S.windows?"win":S.linux?"linux":"key";function rc(s,e){const t=s.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let h=0;h<t.length-1;++h){const a=t[h];if(/^(cmd|meta|m)$/i.test(a))l=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))o=!0;else if(/^mod$/i.test(a))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ii(s,e,t){return e.altKey&&(s="Alt-"+s),e.ctrlKey&&(s="Ctrl-"+s),e.metaKey&&(s="Meta-"+s),t!==!1&&e.shiftKey&&(s="Shift-"+s),s}const oc=on.default(D.domEventHandlers({keydown(s,e){return fc(lc(e.state),s,e,"editor")}})),jl=A.define({enables:oc}),Jr=new WeakMap;function lc(s){let e=s.facet(jl),t=Jr.get(e);return t||Jr.set(e,t=ac(e.reduce((i,n)=>i.concat(n),[]))),t}let Ze=null;const hc=4e3;function ac(s,e=sc){let t=Object.create(null),i=Object.create(null),n=(o,l)=>{let h=i[o];if(h==null)i[o]=l;else if(h!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,h,a,f)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>rc(y,e));for(let y=1;y<p.length;y++){let k=p.slice(0,y).join(" ");n(k,!0),d[k]||(d[k]={preventDefault:!0,stopPropagation:!1,run:[v=>{let P=Ze={view:v,prefix:k,scope:o};return setTimeout(()=>{Ze==P&&(Ze=null)},hc),!0}]})}let g=p.join(" ");n(g,!1);let m=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});h&&m.run.push(h),a&&(m.preventDefault=!0),f&&(m.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let a of l){let f=t[a]||(t[a]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in f)f[u].run.push(d=>c(d,ks))}let h=o[e]||o.key;if(h)for(let a of l)r(a,h,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(a,"Shift-"+h,o.shift,o.preventDefault,o.stopPropagation)}return t}let ks=null;function fc(s,e,t,i){ks=e;let n=xa(e),r=ia(n,0),o=na(r)==n.length&&n!=" ",l="",h=!1,a=!1,f=!1;Ze&&Ze.view==t&&Ze.scope==i&&(l=Ze.prefix+" ",Ll.indexOf(e.keyCode)<0&&(a=!0,Ze=null));let c=new Set,u=m=>{if(m){for(let y of m.run)if(!c.has(y)&&(c.add(y),y(t)))return m.stopPropagation&&(f=!0),!0;m.preventDefault&&(m.stopPropagation&&(f=!0),a=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+Ii(n,e,!o)])?h=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(S.windows&&e.ctrlKey&&e.altKey)&&!(S.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=nt[e.keyCode])&&p!=n?(u(d[l+Ii(p,e,!0)])||e.shiftKey&&(g=ri[e.keyCode])!=n&&g!=p&&u(d[l+Ii(g,e,!1)]))&&(h=!0):o&&e.shiftKey&&u(d[l+Ii(n,e,!0)])&&(h=!0),!h&&u(d._any)&&(h=!0)),a&&(h=!0),h&&f&&e.stopPropagation(),ks=null,h}class cc extends Wt{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?Zt(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),n=hi(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return n.bottom-n.top>r*1.5?{left:n.left,right:n.right,top:n.top,bottom:n.top+r}:n}ignoreEvent(){return!1}}function Gd(s){return[Ge.fromClass(class{constructor(t){this.view=t,this.placeholder=z.set([z.widget({widget:new cc(s),side:1}).range(0)])}get decorations(){return this.view.state.doc.length?z.none:this.placeholder}},{decorations:t=>t.decorations}),D.contentAttributes.of({"aria-placeholder":s})]}class bt extends tt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}bt.prototype.elementClass="";bt.prototype.toDOM=void 0;bt.prototype.mapMode=le.TrackBefore;bt.prototype.startSide=bt.prototype.endSide=-1;bt.prototype.point=!0;const En=A.define(),uc=A.define(),zi=A.define(),Yr=A.define({combine:s=>s.some(e=>e)});function dc(s){return[pc]}const pc=Ge.fromClass(class{constructor(s){this.view=s,this.domAfter=null,this.prevViewport=s.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=s.state.facet(zi).map(e=>new Xr(s,e)),this.fixed=!s.state.facet(Yr);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),s.scrollDOM.insertBefore(this.dom,s.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(s){if(this.updateGutters(s)){let e=this.prevViewport,t=s.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(s.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Yr)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=s.view.viewport}syncGutters(s){let e=this.dom.nextSibling;s&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=L.iter(this.view.state.facet(En),this.view.viewport.from),i=[],n=this.gutters.map(r=>new gc(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==ce.Text&&o){xs(t,i,l.from);for(let h of n)h.line(this.view,l,i);o=!1}else if(l.widget)for(let h of n)h.widget(this.view,l)}else if(r.type==ce.Text){xs(t,i,r.from);for(let o of n)o.line(this.view,r,i)}else if(r.widget)for(let o of n)o.widget(this.view,r);for(let r of n)r.finish();s&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(s){let e=s.startState.facet(zi),t=s.state.facet(zi),i=s.docChanged||s.heightChanged||s.viewportChanged||!L.eq(s.startState.facet(En),s.state.facet(En),s.view.viewport.from,s.view.viewport.to);if(e==t)for(let n of this.gutters)n.update(s)&&(i=!0);else{i=!0;let n=[];for(let r of t){let o=e.indexOf(r);o<0?n.push(new Xr(this.view,r)):(this.gutters[o].update(s),n.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),n.indexOf(r)<0&&r.destroy();for(let r of n)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=n}return i}destroy(){for(let s of this.gutters)s.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:s=>D.scrollMargins.of(e=>{let t=e.plugin(s);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,n=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Y.LTR?{left:i,right:n}:{right:i,left:n}})});function _r(s){return Array.isArray(s)?s:[s]}function xs(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class gc{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=L.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:n}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==n.elements.length){let l=new Ul(e,o,r,i);n.elements.push(l),n.dom.appendChild(l.dom)}else n.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let n=[];xs(this.cursor,n,t.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(e,t,n);r&&n.unshift(r);let o=this.gutter;n.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,n)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),n=i?[i]:null;for(let r of e.state.facet(uc)){let o=r(e,t.widget,t);o&&(n||(n=[])).push(o)}n&&this.addElement(e,t,n)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Xr{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,n=>{let r=n.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let h=r.getBoundingClientRect();o=(h.top+h.bottom)/2}else o=n.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,n)&&n.preventDefault()});this.markers=_r(t.markers(e)),t.initialSpacer&&(this.spacer=new Ul(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=_r(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let n=this.config.updateSpacer(this.spacer.markers[0],e);n!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[n])}let i=e.view.viewport;return!L.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Ul{constructor(e,t,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,n)}update(e,t,i,n){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),mc(this.markers,n)||this.setMarkers(e,n)}setMarkers(e,t){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,o=0;;){let l=o,h=r<t.length?t[r++]:null,a=!1;if(h){let f=h.elementClass;f&&(i+=" "+f);for(let c=o;c<this.markers.length;c++)if(this.markers[c].compare(h)){l=c,a=!0;break}}else l=this.markers.length;for(;o<l;){let f=this.markers[o++];if(f.toDOM){f.destroy(n);let c=n.nextSibling;n.remove(),n=c}}if(!h)break;h.toDOM&&(a?n=n.nextSibling:this.dom.insertBefore(h.toDOM(e),n)),a&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function mc(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(!s[t].compare(e[t]))return!1;return!0}const yc=A.define(),bc=A.define(),vt=A.define({combine(s){return Xo(s,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let r=i[n],o=t[n];i[n]=r?(l,h,a)=>r(l,h,a)||o(l,h,a):o}return i}})}});class Ln extends bt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Rn(s,e){return s.state.facet(vt).formatNumber(e,s.state)}const kc=zi.compute([vt],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(yc)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new Ln(Rn(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(bc)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(vt)!=e.state.facet(vt),initialSpacer(e){return new Ln(Rn(e,Qr(e.state.doc.lines)))},updateSpacer(e,t){let i=Rn(t.view,Qr(t.view.state.doc.lines));return i==e.number?e:new Ln(i)},domEventHandlers:s.facet(vt).domEventHandlers,side:"before"}));function Jd(s={}){return[vt.of(s),dc(),kc]}function Qr(s){let e=9;for(;e<s;)e=e*10+9;return e}const Gl=1024;let xc=0;class be{constructor(e,t){this.from=e,this.to=t}}class B{constructor(e={}){this.id=xc++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=se.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}B.closedBy=new B({deserialize:s=>s.split(" ")});B.openedBy=new B({deserialize:s=>s.split(" ")});B.group=new B({deserialize:s=>s.split(" ")});B.isolate=new B({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});B.contextHash=new B({perNode:!0});B.lookAhead=new B({perNode:!0});B.mounted=new B({perNode:!0});class Ot{constructor(e,t,i,n=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=n}static get(e){return e&&e.props&&e.props[B.mounted.id]}}const wc=Object.create(null);class se{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):wc,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new se(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(B.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return i=>{for(let n=i.prop(B.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}se.none=new se("",Object.create(null),0,8);class pn{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let r of e){let o=r(i);if(o){n||(n=Object.assign({},i.props));let l=o[1],h=o[0];h.combine&&h.id in n&&(l=h.combine(n[h.id],l)),n[h.id]=l}}t.push(n?new se(i.name,n,i.id,i.flags):i)}return new pn(t)}}const Ei=new WeakMap,Zr=new WeakMap;var F;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(F||(F={}));class R{constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Ot.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new en(this.topNode,e)}cursorAt(e,t=0,i=0){let n=Ei.get(this)||this.topNode,r=new en(n);return r.moveTo(e,t),Ei.set(this,r._tree),r}get topNode(){return new ne(this,0,0,null)}resolve(e,t=0){let i=fi(Ei.get(this)||this.topNode,e,t,!1);return Ei.set(this,i),i}resolveInner(e,t=0){let i=fi(Zr.get(this)||this.topNode,e,t,!0);return Zr.set(this,i),i}resolveStack(e,t=0){return Ac(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,o=e.mode||0,l=(o&F.IncludeAnonymous)>0;for(let h=this.cursor(o|F.IncludeAnonymous);;){let a=!1;if(h.from<=r&&h.to>=n&&(!l&&h.type.isAnonymous||t(h)!==!1)){if(h.firstChild())continue;a=!0}for(;a&&i&&(l||!h.type.isAnonymous)&&i(h),!h.nextSibling();){if(!h.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Ys(se.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new R(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new R(se.none,t,i,n)))}static build(e){return Cc(e)}}R.empty=new R(se.none,[],[],0);class Gs{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Gs(this.buffer,this.index)}}class rt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return se.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,n,r){let{buffer:o}=this,l=-1;for(let h=e;h!=t&&!(Jl(r,n,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,h=0;l<t;){r[h++]=n[l++],r[h++]=n[l++]-i;let a=r[h++]=n[l++]-i;r[h++]=n[l++]-e,o=Math.max(o,a)}return new rt(r,o,this.set)}}function Jl(s,e,t,i){switch(s){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function fi(s,e,t,i){for(var n;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let o=!i&&s instanceof ne&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:F.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof ne&&o.index<0&&((n=l.enter(e,t,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(e,t,r);if(!o)return s;s=o}}class Yl{cursor(e=0){return new en(this,e)}getChild(e,t=null,i=null){let n=eo(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return eo(this,e,t,i)}resolve(e,t=0){return fi(this,e,t,!1)}resolveInner(e,t=0){return fi(this,e,t,!0)}matchContext(e){return ws(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}get node(){return this}get next(){return this.parent}}class ne extends Yl{constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,a=t>0?l.length:-1;e!=a;e+=t){let f=l[e],c=h[e]+o.from,u;if(!(!(r&F.EnterBracketed&&f instanceof R&&(u=Ot.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!Jl(n,i,c,c+f.length))){if(f instanceof rt){if(r&F.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,t,i-c,n);if(d>-1)return new Fe(new Sc(o,f,e,c),null,d)}else if(r&F.IncludeAnonymous||!f.type.isAnonymous||Js(f)){let d;if(!(r&F.IgnoreMounts)&&(d=Ot.get(f))&&!d.overlay)return new ne(d.tree,c,e,o);let p=new ne(f,c,e,o);return r&F.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?f.children.length-1:0,t,i,n,r)}}}if(r&F.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let n;if(!(i&F.IgnoreOverlays)&&(n=Ot.get(this._tree))&&n.overlay){let r=e-this.from,o=i&F.EnterBracketed&&n.bracketed;for(let{from:l,to:h}of n.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?h>=r:h>r))return new ne(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function eo(s,e,t,i){let n=s.cursor(),r=[];if(!n.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=n.type.is(t),!n.nextSibling())return r}for(;;){if(i!=null&&n.type.is(i))return r;if(n.type.is(e)&&r.push(n.node),!n.nextSibling())return i==null?r:[]}}function ws(s,e,t=e.length-1){for(let i=s;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class Sc{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class Fe extends Yl{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new Fe(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&F.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new Fe(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Fe(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new Fe(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let o=i.buffer[this.index+1];e.push(i.slice(n,r,o)),t.push(0)}return new R(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function _l(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof ne&&t.index<0?null:t.parent,n=s.slice();return i?n[e]=i:n.splice(e,1),new vc(n,t)}class vc{constructor(e,t){this.heads=e,this.node=t}get next(){return _l(this.heads)}}function Ac(s,e,t){let i=s.resolveInner(e,t),n=null;for(let r=i instanceof ne?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(e,t)),r=o}else{let o=Ot.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new ne(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(fi(l,e,t,!1))}}return n?_l(n):i}class en{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~F.EnterBracketed,e instanceof ne)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return e?e instanceof ne?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&F.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&F.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&F.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(n.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&F.IncludeAnonymous||l instanceof rt||!l.type.isAnonymous||Js(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new Fe(this.buffer,t,this.stack[n]);return this.bufferNode=new Fe(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return ws(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return ws(this._tree,e,n);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[n]&&e[n]!=o.name)return!1;n--}}return!0}}function Js(s){return s.children.some(e=>e instanceof rt||!e.type.isAnonymous||Js(e))}function Cc(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Gl,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new Gs(t,t.length):t,h=i.types,a=0,f=0;function c(M,T,C,K,H,U){let{id:I,start:O,end:$,size:j}=l,Q=f,_e=a;if(j<0)if(l.next(),j==-1){let Ve=r[I];C.push(Ve),K.push(O-M);return}else if(j==-3){a=I;return}else if(j==-4){f=I;return}else throw new RangeError(`Unrecognized record size: ${j}`);let zt=h[I],xi,lt,lr=O-M;if($-O<=n&&(lt=m(l.pos-T,H))){let Ve=new Uint16Array(lt.size-lt.skip),ge=l.pos-lt.size,De=Ve.length;for(;l.pos>ge;)De=y(lt.start,Ve,De);xi=new rt(Ve,$-lt.start,i),lr=lt.start-M}else{let Ve=l.pos-j;l.next();let ge=[],De=[],ht=I>=o?I:-1,xt=0,wi=$;for(;l.pos>Ve;)ht>=0&&l.id==ht&&l.size>=0?(l.end<=wi-n&&(p(ge,De,O,xt,l.end,wi,ht,Q,_e),xt=ge.length,wi=l.end),l.next()):U>2500?u(O,Ve,ge,De):c(O,Ve,ge,De,ht,U+1);if(ht>=0&&xt>0&&xt<ge.length&&p(ge,De,O,xt,O,wi,ht,Q,_e),ge.reverse(),De.reverse(),ht>-1&&xt>0){let hr=d(zt,_e);xi=Ys(zt,ge,De,0,ge.length,0,$-O,hr,hr)}else xi=g(zt,ge,De,$-O,Q-$,_e)}C.push(xi),K.push(lr)}function u(M,T,C,K){let H=[],U=0,I=-1;for(;l.pos>T;){let{id:O,start:$,end:j,size:Q}=l;if(Q>4)l.next();else{if(I>-1&&$<I)break;I<0&&(I=j-n),H.push(O,$,j),U++,l.next()}}if(U){let O=new Uint16Array(U*4),$=H[H.length-2];for(let j=H.length-3,Q=0;j>=0;j-=3)O[Q++]=H[j],O[Q++]=H[j+1]-$,O[Q++]=H[j+2]-$,O[Q++]=Q;C.push(new rt(O,H[2]-$,i)),K.push($-M)}}function d(M,T){return(C,K,H)=>{let U=0,I=C.length-1,O,$;if(I>=0&&(O=C[I])instanceof R){if(!I&&O.type==M&&O.length==H)return O;($=O.prop(B.lookAhead))&&(U=K[I]+O.length+$)}return g(M,C,K,H,U,T)}}function p(M,T,C,K,H,U,I,O,$){let j=[],Q=[];for(;M.length>K;)j.push(M.pop()),Q.push(T.pop()+C-H);M.push(g(i.types[I],j,Q,U-H,O-U,$)),T.push(H-C)}function g(M,T,C,K,H,U,I){if(U){let O=[B.contextHash,U];I=I?[O].concat(I):[O]}if(H>25){let O=[B.lookAhead,H];I=I?[O].concat(I):[O]}return new R(M,T,C,K,I)}function m(M,T){let C=l.fork(),K=0,H=0,U=0,I=C.end-n,O={size:0,start:0,skip:0};e:for(let $=C.pos-M;C.pos>$;){let j=C.size;if(C.id==T&&j>=0){O.size=K,O.start=H,O.skip=U,U+=4,K+=4,C.next();continue}let Q=C.pos-j;if(j<0||Q<$||C.start<I)break;let _e=C.id>=o?4:0,zt=C.start;for(C.next();C.pos>Q;){if(C.size<0)if(C.size==-3||C.size==-4)_e+=4;else break e;else C.id>=o&&(_e+=4);C.next()}H=zt,K+=j,U+=_e}return(T<0||K==M)&&(O.size=K,O.start=H,O.skip=U),O.size>4?O:void 0}function y(M,T,C){let{id:K,start:H,end:U,size:I}=l;if(l.next(),I>=0&&K<o){let O=C;if(I>4){let $=l.pos-(I-4);for(;l.pos>$;)C=y(M,T,C)}T[--C]=O,T[--C]=U-M,T[--C]=H-M,T[--C]=K}else I==-3?a=K:I==-4&&(f=K);return C}let k=[],v=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,k,v,-1,0);let P=(e=s.length)!==null&&e!==void 0?e:k.length?v[0]+k[0].length:0;return new R(h[s.topID],k.reverse(),v.reverse(),P)}const to=new WeakMap;function Ki(s,e){if(!s.isAnonymous||e instanceof rt||e.type!=s)return 1;let t=to.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof R)){t=1;break}t+=Ki(s,i)}to.set(e,t)}return t}function Ys(s,e,t,i,n,r,o,l,h){let a=0;for(let p=i;p<n;p++)a+=Ki(s,e[p]);let f=Math.ceil(a*1.5/8),c=[],u=[];function d(p,g,m,y,k){for(let v=m;v<y;){let P=v,M=g[v],T=Ki(s,p[v]);for(v++;v<y;v++){let C=Ki(s,p[v]);if(T+C>=f)break;T+=C}if(v==P+1){if(T>f){let C=p[P];d(C.children,C.positions,0,C.children.length,g[P]+k);continue}c.push(p[P])}else{let C=g[v-1]+p[v-1].length-M;c.push(Ys(s,p,g,P,v,M,C,null,h))}u.push(M+k-r)}}return d(e,t,i,n,0),(l||h)(c,u,o)}class Yd{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof Fe?this.setBuffer(e.context.buffer,e.index,t):e instanceof ne&&this.map.set(e.tree,t)}get(e){return e instanceof Fe?this.getBuffer(e.context.buffer,e.index):e instanceof ne?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class je{constructor(e,t,i,n,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let n=[new je(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],r=1,o=e.length?e[0]:null;for(let l=0,h=0,a=0;;l++){let f=l<t.length?t[l]:null,c=f?f.fromA:1e9;if(c-h>=i)for(;o&&o.from<c;){let u=o;if(h>=u.from||c<=u.to||a){let d=Math.max(u.from,h)-a,p=Math.min(u.to,c)-a;u=d>=p?null:new je(d,p,u.tree,u.offset+a,l>0,!!f)}if(u&&n.push(u),o.to>c)break;o=r<e.length?e[r++]:null}if(!f)break;h=f.toA,a=f.toA-f.toB}return n}}class _s{startParse(e,t,i){return typeof e=="string"&&(e=new Mc(e)),i=i?i.length?i.map(n=>new be(n.from,n.to)):[new be(0,0)]:[new be(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let r=n.advance();if(r)return r}}}class Mc{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function _d(s){return(e,t,i,n)=>new Dc(e,s,t,i,n)}class io{constructor(e,t,i,n,r,o){this.parser=e,this.parse=t,this.overlay=i,this.bracketed=n,this.target=r,this.from=o}}function no(s){if(!s.length||s.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}class Tc{constructor(e,t,i,n,r,o,l,h){this.parser=e,this.predicate=t,this.mounts=i,this.index=n,this.start=r,this.bracketed=o,this.target=l,this.prev=h,this.depth=0,this.ranges=[]}}const Ss=new B({perNode:!0});class Dc{constructor(e,t,i,n,r){this.nest=t,this.input=i,this.fragments=n,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let n of this.inner)n.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new R(i.type,i.children,i.positions,i.length,i.propValues.concat([[Ss,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[B.mounted.id]=new Ot(t,e.overlay,e.parser,e.bracketed),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Pc(this.fragments),t=null,i=null,n=new en(new ne(this.baseTree,this.ranges[0].from,0,null),F.IncludeAnonymous|F.IgnoreMounts);e:for(let r,o;;){let l=!0,h;if(this.stoppedAt!=null&&n.from>=this.stoppedAt)l=!1;else if(e.hasNode(n)){if(t){let a=t.mounts.find(f=>f.frag.from<=n.from&&f.frag.to>=n.to&&f.mount.overlay);if(a)for(let f of a.mount.overlay){let c=f.from+a.pos,u=f.to+a.pos;c>=n.from&&u<=n.to&&!t.ranges.some(d=>d.from<u&&d.to>c)&&t.ranges.push({from:c,to:u})}}l=!1}else if(i&&(o=Oc(i.ranges,n.from,n.to)))l=o!=2;else if(!n.type.isAnonymous&&(r=this.nest(n,this.input))&&(n.from<n.to||!r.overlay)){n.tree||(Bc(n),t&&t.depth++,i&&i.depth++);let a=e.findMounts(n.from,r.parser);if(typeof r.overlay=="function")t=new Tc(r.parser,r.overlay,a,this.inner.length,n.from,!!r.bracketed,n.tree,t);else{let f=oo(this.ranges,r.overlay||(n.from<n.to?[new be(n.from,n.to)]:[]));f.length&&no(f),(f.length||!r.overlay)&&this.inner.push(new io(r.parser,f.length?r.parser.startParse(this.input,lo(a,f),f):r.parser.startParse(""),r.overlay?r.overlay.map(c=>new be(c.from-n.from,c.to-n.from)):null,!!r.bracketed,n.tree,f.length?f[0].from:n.from)),r.overlay?f.length&&(i={ranges:f,depth:0,prev:i}):l=!1}}else if(t&&(h=t.predicate(n))&&(h===!0&&(h=new be(n.from,n.to)),h.from<h.to)){let a=t.ranges.length-1;a>=0&&t.ranges[a].to==h.from?t.ranges[a]={from:t.ranges[a].from,to:h.to}:t.ranges.push(h)}if(l&&n.firstChild())t&&t.depth++,i&&i.depth++;else for(;!n.nextSibling();){if(!n.parent())break e;if(t&&!--t.depth){let a=oo(this.ranges,t.ranges);a.length&&(no(a),this.inner.splice(t.index,0,new io(t.parser,t.parser.startParse(this.input,lo(t.mounts,a),a),t.ranges.map(f=>new be(f.from-t.start,f.to-t.start)),t.bracketed,t.target,a[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function Oc(s,e,t){for(let i of s){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function so(s,e,t,i,n,r){if(e<t){let o=s.buffer[e+1];i.push(s.slice(e,t,o)),n.push(o-r)}}function Bc(s){let{node:e}=s,t=[],i=e.context.buffer;do t.push(s.index),s.parent();while(!s.tree);let n=s.tree,r=n.children.indexOf(i),o=n.children[r],l=o.buffer,h=[r];function a(f,c,u,d,p,g){let m=t[g],y=[],k=[];so(o,f,m,y,k,d);let v=l[m+1],P=l[m+2];h.push(y.length);let M=g?a(m+4,l[m+3],o.set.types[l[m]],v,P-v,g-1):e.toTree();return y.push(M),k.push(v-d),so(o,l[m+3],c,y,k,d),new R(u,y,k,p)}n.children[r]=a(0,l.length,se.none,0,o.length,t.length-1);for(let f of h){let c=s.tree.children[f],u=s.tree.positions[f];s.yield(new ne(c,u+s.from,f,s._tree))}}class ro{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(F.IncludeAnonymous|F.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)if(!(t.to>=e&&t.enter(i,1,F.IgnoreOverlays|F.ExcludeBuffers)))if(t.to<=e)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof R)t=t.children[0];else break}return!1}}let Pc=class{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(Ss))!==null&&t!==void 0?t:i.to,this.inner=new ro(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Ss))!==null&&e!==void 0?e:t.to,this.inner=new ro(t.tree,-t.offset)}}findMounts(e,t){var i;let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(i=r.tree)===null||i===void 0?void 0:i.prop(B.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let h=this.fragments[l];if(h.from>=r.to)break;h.tree==this.curFrag.tree&&n.push({frag:h,pos:r.from-h.offset,mount:o})}}}return n}};function oo(s,e){let t=null,i=e;for(let n=1,r=0;n<s.length;n++){let o=s[n-1].to,l=s[n].from;for(;r<i.length;r++){let h=i[r];if(h.from>=l)break;h.to<=o||(t||(i=t=e.slice()),h.from<o?(t[r]=new be(h.from,o),h.to>l&&t.splice(r+1,0,new be(l,h.to))):h.to>l?t[r--]=new be(l,h.to):t.splice(r--,1))}}return i}function Ic(s,e,t,i){let n=0,r=0,o=!1,l=!1,h=-1e9,a=[];for(;;){let f=n==s.length?1e9:o?s[n].to:s[n].from,c=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let u=Math.max(h,t),d=Math.min(f,c,i);u<d&&a.push(new be(u,d))}if(h=Math.min(f,c),h==1e9)break;f==h&&(o?(o=!1,n++):o=!0),c==h&&(l?(l=!1,r++):l=!0)}return a}function lo(s,e){let t=[];for(let{pos:i,mount:n,frag:r}of s){let o=i+(n.overlay?n.overlay[0].from:0),l=o+n.tree.length,h=Math.max(r.from,o),a=Math.min(r.to,l);if(n.overlay){let f=n.overlay.map(u=>new be(u.from+i,u.to+i)),c=Ic(e,f,h,a);for(let u=0,d=h;;u++){let p=u==c.length,g=p?a:c[u].from;if(g>d&&t.push(new je(d,g,n.tree,-o,r.from>=d||r.openStart,r.to<=g||r.openEnd)),p)break;d=c[u].to}}else t.push(new je(h,a,n.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let Ec=0;class me{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=Ec++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof me&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let n=new me(i,[],null,[]);if(n.set.push(n),t)for(let r of t.set)n.set.push(r);return n}static defineModifier(e){let t=new tn(e);return i=>i.modified.indexOf(t)>-1?i:tn.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}}let Lc=0;class tn{constructor(e){this.name=e,this.instances=[],this.id=Lc++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Rc(t,l.modified));if(i)return i;let n=[],r=new me(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=Nc(t);for(let l of e.set)if(!l.modified.length)for(let h of o)n.push(tn.get(l,h));return r}}function Rc(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function Nc(s){let e=[[]];for(let t=0;t<s.length;t++)for(let i=0,n=e.length;i<n;i++)e.push(e[i].concat(s[t]));return e.sort((t,i)=>i.length-t.length)}function Fc(s){let e=Object.create(null);for(let t in s){let i=s[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let r=[],o=2,l=n;for(let c=0;;){if(l=="..."&&c>0&&c+3==n.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+n);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(c)}let h=r.length-1,a=r[h];if(!a)throw new RangeError("Invalid path: "+n);let f=new ci(i,o,h>0?r.slice(0,h):null);e[a]=f.sort(e[a])}}return Xl.add(e)}const Xl=new B({combine(s,e){let t,i,n;for(;s||e;){if(!s||e&&s.depth>=e.depth?(n=e,e=e.next):(n=s,s=s.next),t&&t.mode==n.mode&&!n.context&&!t.context)continue;let r=new ci(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class ci{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}ci.empty=new ci([],2,null);function Ql(s,e){let t=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:n=null}=e||{};return{style:r=>{let o=n;for(let l of r)for(let h of l.set){let a=t[h.id];if(a){o=o?o+" "+a:a;break}}return o},scope:i}}function Wc(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function Hc(s,e,t,i=0,n=s.length){let r=new Vc(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class Vc{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,n,r){let{type:o,from:l,to:h}=e;if(l>=i||h<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let a=n,f=zc(e)||ci.empty,c=Wc(r,f.tags);if(c&&(a&&(a+=" "),a+=c,f.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(t,l),a),f.opaque)return;let u=e.tree&&e.tree.prop(B.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=e.firstChild();for(let m=0,y=l;;m++){let k=m<u.overlay.length?u.overlay[m]:null,v=k?k.from+l:h,P=Math.max(t,y),M=Math.min(i,v);if(P<M&&g)for(;e.from<M&&(this.highlightRange(e,P,M,n,r),this.startSpan(Math.min(M,e.to),a),!(e.to>=v||!e.nextSibling())););if(!k||v>i)break;y=k.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,k.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),a))}g&&e.parent()}else if(e.firstChild()){u&&(n="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,n,r),this.startSpan(Math.min(i,e.to),a)}while(e.nextSibling());e.parent()}}}function zc(s){let e=s.type.prop(Xl);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const x=me.define,Li=x(),Xe=x(),ho=x(Xe),ao=x(Xe),Qe=x(),Ri=x(Qe),Nn=x(Qe),Ie=x(),at=x(Ie),Be=x(),Pe=x(),vs=x(),qt=x(vs),Ni=x(),w={comment:Li,lineComment:x(Li),blockComment:x(Li),docComment:x(Li),name:Xe,variableName:x(Xe),typeName:ho,tagName:x(ho),propertyName:ao,attributeName:x(ao),className:x(Xe),labelName:x(Xe),namespace:x(Xe),macroName:x(Xe),literal:Qe,string:Ri,docString:x(Ri),character:x(Ri),attributeValue:x(Ri),number:Nn,integer:x(Nn),float:x(Nn),bool:x(Qe),regexp:x(Qe),escape:x(Qe),color:x(Qe),url:x(Qe),keyword:Be,self:x(Be),null:x(Be),atom:x(Be),unit:x(Be),modifier:x(Be),operatorKeyword:x(Be),controlKeyword:x(Be),definitionKeyword:x(Be),moduleKeyword:x(Be),operator:Pe,derefOperator:x(Pe),arithmeticOperator:x(Pe),logicOperator:x(Pe),bitwiseOperator:x(Pe),compareOperator:x(Pe),updateOperator:x(Pe),definitionOperator:x(Pe),typeOperator:x(Pe),controlOperator:x(Pe),punctuation:vs,separator:x(vs),bracket:qt,angleBracket:x(qt),squareBracket:x(qt),paren:x(qt),brace:x(qt),content:Ie,heading:at,heading1:x(at),heading2:x(at),heading3:x(at),heading4:x(at),heading5:x(at),heading6:x(at),contentSeparator:x(Ie),list:x(Ie),quote:x(Ie),emphasis:x(Ie),strong:x(Ie),link:x(Ie),monospace:x(Ie),strikethrough:x(Ie),inserted:x(),deleted:x(),changed:x(),invalid:x(),meta:Ni,documentMeta:x(Ni),annotation:x(Ni),processingInstruction:x(Ni),definition:me.defineModifier("definition"),constant:me.defineModifier("constant"),function:me.defineModifier("function"),standard:me.defineModifier("standard"),local:me.defineModifier("local"),special:me.defineModifier("special")};for(let s in w){let e=w[s];e instanceof me&&(e.name=s)}Ql([{tag:w.link,class:"tok-link"},{tag:w.heading,class:"tok-heading"},{tag:w.emphasis,class:"tok-emphasis"},{tag:w.strong,class:"tok-strong"},{tag:w.keyword,class:"tok-keyword"},{tag:w.atom,class:"tok-atom"},{tag:w.bool,class:"tok-bool"},{tag:w.url,class:"tok-url"},{tag:w.labelName,class:"tok-labelName"},{tag:w.inserted,class:"tok-inserted"},{tag:w.deleted,class:"tok-deleted"},{tag:w.literal,class:"tok-literal"},{tag:w.string,class:"tok-string"},{tag:w.number,class:"tok-number"},{tag:[w.regexp,w.escape,w.special(w.string)],class:"tok-string2"},{tag:w.variableName,class:"tok-variableName"},{tag:w.local(w.variableName),class:"tok-variableName tok-local"},{tag:w.definition(w.variableName),class:"tok-variableName tok-definition"},{tag:w.special(w.variableName),class:"tok-variableName2"},{tag:w.definition(w.propertyName),class:"tok-propertyName tok-definition"},{tag:w.typeName,class:"tok-typeName"},{tag:w.namespace,class:"tok-namespace"},{tag:w.className,class:"tok-className"},{tag:w.macroName,class:"tok-macroName"},{tag:w.propertyName,class:"tok-propertyName"},{tag:w.operator,class:"tok-operator"},{tag:w.comment,class:"tok-comment"},{tag:w.meta,class:"tok-meta"},{tag:w.invalid,class:"tok-invalid"},{tag:w.punctuation,class:"tok-punctuation"}]);var Fn;const pt=new B;function Zl(s){return A.define({combine:s?e=>e.concat(s):void 0})}const Kc=new B;class ke{constructor(e,t,i=[],n=""){this.data=e,this.name=n,N.prototype.hasOwnProperty("tree")||Object.defineProperty(N.prototype,"tree",{get(){return we(this)}}),this.parser=t,this.extension=[Ft.of(this),N.languageData.of((r,o,l)=>{let h=fo(r,o,l),a=h.type.prop(pt);if(!a)return[];let f=r.facet(a),c=h.type.prop(Kc);if(c){let u=h.resolve(o-h.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(e,t,i=-1){return fo(e,t,i).type.prop(pt)==this.data}findRegions(e){let t=e.facet(Ft);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(pt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(B.mounted);if(l){if(l.tree.prop(pt)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let h=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<r.children.length;h++){let a=r.children[h];a instanceof R&&n(a,r.positions[h]+o)}};return n(we(e),0),i}get allowsNesting(){return!0}}ke.setState=q.define();function fo(s,e,t){let i=s.facet(Ft),n=we(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(e,t,F.ExcludeBuffers|F.EnterBracketed))r.type.isTop&&(n=r);return n}class As extends ke{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Zl(e.languageData);return new As(t,e.parser.configure({props:[pt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new As(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function we(s){let e=s.field(ke.state,!1);return e?e.tree:R.empty}class $c{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let jt=null;class Rt{constructor(e,t,i=[],n,r,o,l,h){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Rt(e,t,[],R.empty,0,i,[],null)}startParse(){return this.parser.startParse(new $c(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=R.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(je.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(je.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=jt;jt=this;try{return e()}finally{jt=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=co(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let h=[];if(e.iterChangedRanges((a,f,c,u)=>h.push({fromA:a,toA:f,fromB:c,toB:u})),i=je.applyChanges(i,h),n=R.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let a of this.skipped){let f=e.mapPos(a.from,1),c=e.mapPos(a.to,-1);f<c&&l.push({from:f,to:c})}}}return new Rt(this.parser,t,i,n,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<e.to&&r>e.from&&(this.fragments=co(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends _s{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let h=jt;if(h){for(let a of n)h.tempSkipped.push(a);e&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,e]):e)}return this.parsedPos=o,new R(se.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return jt}}function co(s,e,t){return je.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class Nt{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new Nt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Rt.create(e.facet(Ft).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Nt(i)}}ke.state=Je.define({create:Nt.init,update(s,e){for(let t of e.effects)if(t.is(ke.setState))return t.value;return e.startState.facet(Ft)!=e.state.facet(Ft)?Nt.init(e.state):s.apply(e)}});let eh=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(eh=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Wn=typeof navigator<"u"&&(!((Fn=navigator.scheduling)===null||Fn===void 0)&&Fn.isInputPending)?()=>navigator.scheduling.isInputPending():null,qc=Ge.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(ke.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(ke.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=eh(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(ke.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Wn?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,h=r.context.work(()=>Wn&&Wn()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(h||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:ke.setState.of(new Nt(r.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ne(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ft=A.define({combine(s){return s.length?s[0]:null},enables:s=>[ke.state,qc,D.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class Zd{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class th{constructor(e,t,i,n,r,o=void 0){this.name=e,this.alias=t,this.extensions=i,this.filename=n,this.loadFunc=r,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new th(e.name,(e.alias||[]).concat(e.name).map(n=>n.toLowerCase()),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let i=/\.([^.]+)$/.exec(t);if(i){for(let n of e)if(n.extensions.indexOf(i[1])>-1)return n}return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(r=>r==t))return n;if(i)for(let n of e)for(let r of n.alias){let o=t.indexOf(r);if(o>-1&&(r.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+r.length])))return n}return null}}const jc=A.define(),gn=A.define({combine:s=>{if(!s.length)return" ";let e=s[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return e}});function kt(s){let e=s.facet(gn);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function ui(s,e){let t="",i=s.tabSize,n=s.facet(gn)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r<e;r++)t+=n;return t}function Xs(s,e){s instanceof N&&(s=new mn(s));for(let i of s.state.facet(jc)){let n=i(s,e);if(n!==void 0)return n}let t=we(s.state);return t.length>=e?Uc(s,t,e):null}class mn{constructor(e,t={}){this.state=e,this.options=t,this.unit=kt(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return hn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(n);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const ih=new B;function Uc(s,e,t){let i=e.resolveStack(t),n=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return nh(i,s,t)}function nh(s,e,t){for(let i=s;i;i=i.next){let n=Jc(i.node);if(n)return n(Qs.create(e,t,i))}return 0}function Gc(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function Jc(s){let e=s.type.prop(ih);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(B.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>sh(o,!0,1,void 0,r&&!Gc(o)?n.from:void 0)}return s.parent==null?Yc:null}function Yc(){return 0}class Qs extends mn{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Qs(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(_c(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return nh(this.context.next,this.base,this.pos)}}function _c(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function Xc(s){let e=s.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(t.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=t.to;;){let h=e.childAfter(l);if(!h||h==i)return null;if(!h.type.isSkipped){if(h.from>=o)return null;let a=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+a}}l=h.to}}function ep({closing:s,align:e=!0,units:t=1}){return i=>sh(i,e,t,s)}function sh(s,e,t,i,n){let r=s.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||n==s.pos+o,h=e?Xc(s):null;return h?l?s.column(h.from):s.column(h.to):s.baseIndent+(l?0:s.unit*t)}const tp=s=>s.baseIndent;function ip({except:s,units:e=1}={}){return t=>{let i=s&&s.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const Qc=200;function np(){return N.transactionFilter.of(s=>{if(!s.docChanged||!s.isUserEvent("input.type")&&!s.isUserEvent("input.complete"))return s;let e=s.startState.languageDataAt("indentOnInput",s.startState.selection.main.head);if(!e.length)return s;let t=s.newDoc,{head:i}=s.newSelection.main,n=t.lineAt(i);if(i>n.from+Qc)return s;let r=t.sliceString(n.from,i);if(!e.some(a=>a.test(r)))return s;let{state:o}=s,l=-1,h=[];for(let{head:a}of o.selection.ranges){let f=o.doc.lineAt(a);if(f.from==l)continue;l=f.from;let c=Xs(o,f.from);if(c==null)continue;let u=/^\s*/.exec(f.text)[0],d=ui(o,c);u!=d&&h.push({from:f.from,to:f.from+u.length,insert:d})}return h.length?[s,{changes:h,sequential:!0}]:s})}const sp=A.define(),rp=new B;function op(s){let e=s.firstChild,t=s.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?s.to:t.from}:null}class yn{constructor(e,t){this.specs=e;let i;function n(l){let h=it.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const r=typeof t.all=="string"?t.all:t.all?n(t.all):void 0,o=t.scope;this.scope=o instanceof ke?l=>l.prop(pt)==o.data:o?l=>l==o:void 0,this.style=Ql(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new it(i):null,this.themeType=t.themeType}static define(e,t){return new yn(e,t||{})}}const Cs=A.define(),rh=A.define({combine(s){return s.length?[s[0]]:null}});function Hn(s){let e=s.facet(Cs);return e.length?e:s.facet(rh)}function lp(s,e){let t=[eu],i;return s instanceof yn&&(s.module&&t.push(D.styleModule.of(s.module)),i=s.themeType),e?.fallback?t.push(rh.of(s)):i?t.push(Cs.computeN([D.darkTheme],n=>n.facet(D.darkTheme)==(i=="dark")?[s]:[])):t.push(Cs.of(s)),t}class Zc{constructor(e){this.markCache=Object.create(null),this.tree=we(e.state),this.decorations=this.buildDeco(e,Hn(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=we(e.state),i=Hn(e.state),n=i!=Hn(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return z.none;let i=new ni;for(let{from:n,to:r}of e.visibleRanges)Hc(this.tree,t,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=z.mark({class:h})))},n,r);return i.finish()}}const eu=on.high(Ge.fromClass(Zc,{decorations:s=>s.decorations})),hp=yn.define([{tag:w.meta,color:"#404740"},{tag:w.link,textDecoration:"underline"},{tag:w.heading,textDecoration:"underline",fontWeight:"bold"},{tag:w.emphasis,fontStyle:"italic"},{tag:w.strong,fontWeight:"bold"},{tag:w.strikethrough,textDecoration:"line-through"},{tag:w.keyword,color:"#708"},{tag:[w.atom,w.bool,w.url,w.contentSeparator,w.labelName],color:"#219"},{tag:[w.literal,w.inserted],color:"#164"},{tag:[w.string,w.deleted],color:"#a11"},{tag:[w.regexp,w.escape,w.special(w.string)],color:"#e40"},{tag:w.definition(w.variableName),color:"#00f"},{tag:w.local(w.variableName),color:"#30a"},{tag:[w.typeName,w.namespace],color:"#085"},{tag:w.className,color:"#167"},{tag:[w.special(w.variableName),w.macroName],color:"#256"},{tag:w.definition(w.propertyName),color:"#00c"},{tag:w.comment,color:"#940"},{tag:w.invalid,color:"#f00"}]),tu=1e4,iu="()[]{}",nu=new B;function Ms(s,e,t){let i=s.prop(e<0?B.openedBy:B.closedBy);if(i)return i;if(s.name.length==1){let n=t.indexOf(s.name);if(n>-1&&n%2==(e<0?1:0))return[t[n+e]]}return null}function Ts(s){let e=s.type.prop(nu);return e?e(s.node):s}function At(s,e,t,i={}){let n=i.maxScanDistance||tu,r=i.brackets||iu,o=we(s),l=o.resolveInner(e,t);for(let h=l;h;h=h.parent){let a=Ms(h.type,t,r);if(a&&h.from<h.to){let f=Ts(h);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return su(s,e,t,h,f,a,r)}}return ru(s,e,t,o,l.type,n,r)}function su(s,e,t,i,n,r,o){let l=i.parent,h={from:n.from,to:n.to},a=0,f=l?.cursor();if(f&&(t<0?f.childBefore(i.from):f.childAfter(i.to)))do if(t<0?f.to<=i.from:f.from>=i.to){if(a==0&&r.indexOf(f.type.name)>-1&&f.from<f.to){let c=Ts(f);return{start:h,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(Ms(f.type,t,o))a++;else if(Ms(f.type,-t,o)){if(a==0){let c=Ts(f);return{start:h,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}a--}}while(t<0?f.prevSibling():f.nextSibling());return{start:h,matched:!1}}function ru(s,e,t,i,n,r,o){if(t<0?!e:e==s.doc.length)return null;let l=t<0?s.sliceDoc(e-1,e):s.sliceDoc(e,e+1),h=o.indexOf(l);if(h<0||h%2==0!=t>0)return null;let a={from:t<0?e-1:e,to:t>0?e+1:e},f=s.doc.iterRange(e,t>0?s.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=r;){let d=f.value;t<0&&(u+=d.length);let p=e+u*t;for(let g=t>0?0:d.length-1,m=t>0?d.length:-1;g!=m;g+=t){let y=o.indexOf(d[g]);if(!(y<0||i.resolveInner(p+g,1).type!=n))if(y%2==0==t>0)c++;else{if(c==1)return{start:a,end:{from:p+g,to:p+g+1},matched:y>>1==h>>1};c--}}t>0&&(u+=d.length)}return f.done?{start:a,matched:!1}:null}function uo(s,e,t,i=0,n=0){e==null&&(e=s.search(/[^\s\u00a0]/),e==-1&&(e=s.length));let r=n;for(let o=i;o<e;o++)s.charCodeAt(o)==9?r+=t-r%t:r++;return r}class oh{constructor(e,t,i,n){this.string=e,this.tabSize=t,this.indentUnit=i,this.overrideIndent=n,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),i;if(typeof e=="string"?i=t==e:i=t&&(e instanceof RegExp?e.test(t):e(t)),i)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=uo(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:uo(this.string,null,this.tabSize)}match(e,t,i){if(typeof e=="string"){let n=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return n(r)==n(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}}function ou(s){return{name:s.name||"",token:s.token,blankLine:s.blankLine||(()=>{}),startState:s.startState||(()=>!0),copyState:s.copyState||lu,indent:s.indent||(()=>null),languageData:s.languageData||{},tokenTable:s.tokenTable||er,mergeTokens:s.mergeTokens!==!1}}function lu(s){if(typeof s!="object")return s;let e={};for(let t in s){let i=s[t];e[t]=i instanceof Array?i.slice():i}return e}const po=new WeakMap;class lh extends ke{constructor(e){let t=Zl(e.languageData),i=ou(e),n,r=new class extends _s{createParse(o,l,h){return new au(n,o,l,h)}};super(t,r,[],e.name),this.topNode=uu(t,this),n=this,this.streamParser=i,this.stateAfter=new B({perNode:!0}),this.tokenTable=e.tokenTable?new ch(i.tokenTable):cu}static define(e){return new lh(e)}getIndent(e){let t,{overrideIndentation:i}=e.options;i&&(t=po.get(e.state),t!=null&&t<e.pos-1e4&&(t=void 0));let n=Zs(this,e.node.tree,e.node.from,e.node.from,t??e.pos),r,o;if(n?(o=n.state,r=n.pos+1):(o=this.streamParser.startState(e.unit),r=e.node.from),e.pos-r>1e4)return null;for(;r<e.pos;){let h=e.state.doc.lineAt(r),a=Math.min(e.pos,h.to);if(h.length){let f=i?i(h.from):-1,c=new oh(h.text,e.state.tabSize,e.unit,f<0?void 0:f);for(;c.pos<a-h.from;)ah(this.streamParser.token,c,o)}else this.streamParser.blankLine(o,e.unit);if(a==e.pos)break;r=h.to+1}let l=e.lineAt(e.pos);return i&&t==null&&po.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function Zs(s,e,t,i,n){let r=t>=i&&t+e.length<=n&&e.prop(s.stateAfter);if(r)return{state:s.streamParser.copyState(r),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],h=t+e.positions[o],a=l instanceof R&&h<n&&Zs(s,l,h,i,n);if(a)return a}return null}function hh(s,e,t,i,n){if(n&&t<=0&&i>=e.length)return e;!n&&t==0&&e.type==s.topNode&&(n=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],h;if(o<i&&l instanceof R){if(!(h=hh(s,l,t-o,i-o,n)))break;return n?new R(e.type,e.children.slice(0,r).concat(h),e.positions.slice(0,r+1),o+h.length):h}}return null}function hu(s,e,t,i,n){for(let r of e){let o=r.from+(r.openStart?25:0),l=r.to-(r.openEnd?25:0),h=o<=t&&l>t&&Zs(s,r.tree,0-r.offset,t,l),a;if(h&&h.pos<=i&&(a=hh(s,r.tree,t+r.offset,h.pos+r.offset,!1)))return{state:h.state,tree:a}}return{state:s.streamParser.startState(n?kt(n):4),tree:R.empty}}let au=class{constructor(e,t,i,n){this.lang=e,this.input=t,this.fragments=i,this.ranges=n,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=n[n.length-1].to;let r=Rt.get(),o=n[0].from,{state:l,tree:h}=hu(e,i,o,this.to,r?.state);this.state=l,this.parsedPos=this.chunkStart=o+h.length;for(let a=0;a<h.children.length;a++)this.chunks.push(h.children[a]),this.chunkPos.push(h.positions[a]);r&&this.parsedPos<r.viewport.from-1e5&&n.some(a=>a.from<=r.viewport.from&&a.to>=r.viewport.from)&&(this.state=this.lang.streamParser.startState(kt(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Rt.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(t,this.chunkStart+512);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
11
11
  `&&(t="");else{let i=t.indexOf(`
12
- `);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let n=this.rangeIndex;;){let r=this.ranges[n].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),n++,n==this.ranges.length))break;let o=this.ranges[n].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let n=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?n>r:n>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-n}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,i,n){let r=4;if(this.ranges.length>1){n=this.skipGapsTo(t,n,1),t+=n;let l=this.chunk.length;n=this.skipGapsTo(i,n,-1),i+=n,r+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&r==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=i:this.chunk.push(e,t,i,r),n}parseLine(e){let{line:t,end:i}=this.nextLine(),n=0,{streamParser:r}=this.lang,o=new oh(t,e?e.state.tabSize:4,e?kt(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=ah(r.token,o,this.state);if(l&&(n=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,n)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=R.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:fu,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new R(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new R(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}};function ah(s,e,t){e.start=e.pos;for(let i=0;i<10;i++){let n=s(e,t);if(e.pos>e.start)return n}throw new Error("Stream parser failed to advance stream.")}const er=Object.create(null),di=[se.none],fu=new pn(di),go=[],mo=Object.create(null),fh=Object.create(null);for(let[s,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])fh[s]=uh(er,e);class ch{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),fh)}resolve(e){return e?this.table[e]||(this.table[e]=uh(this.extra,e)):0}}const cu=new ch(er);function Vn(s,e){go.indexOf(s)>-1||(go.push(s),console.warn(e))}function uh(s,e){let t=[];for(let l of e.split(" ")){let h=[];for(let a of l.split(".")){let f=s[a]||w[a];f?typeof f=="function"?h.length?h=h.map(f):Vn(a,`Modifier ${a} used at start of tag`):h.length?Vn(a,`Tag ${a} used as modifier`):h=Array.isArray(f)?f:[f]:Vn(a,`Unknown highlighting tag ${a}`)}for(let a of h)t.push(a)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=mo[n];if(r)return r.id;let o=mo[n]=se.define({id:di.length,name:i,props:[Fc({[i]:t})]});return di.push(o),o.id}function uu(s,e){let t=se.define({id:di.length,name:"Document",props:[pt.add(()=>s),ih.add(()=>i=>e.getIndent(i))],top:!0});return di.push(t),t}Y.RTL,Y.LTR;const du=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=ir(s.state,t.from);return i.line?pu(s):i.block?mu(s):!1};function tr(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const pu=tr(ku,0),gu=tr(dh,0),mu=tr((s,e)=>dh(s,e,bu(e)),0);function ir(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Ut=50;function yu(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-Ut,i),o=s.sliceDoc(n,n+Ut),l=/\s*$/.exec(r)[0].length,h=/^\s*/.exec(o)[0].length,a=r.length-l;if(r.slice(a-e.length,a)==e&&o.slice(h,h+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+h,margin:h&&1}};let f,c;n-i<=2*Ut?f=c=s.sliceDoc(i,n):(f=s.sliceDoc(i,i+Ut),c=s.sliceDoc(n-Ut,n));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function bu(s){let e=[];for(let t of s.selection.ranges){let i=s.doc.lineAt(t.from),n=t.to<=i.to?i:s.doc.lineAt(t.to);n.from>i.from&&n.from==t.to&&(n=t.to==i.to+1?i:s.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=n.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return e}function dh(s,e,t=e.selection.ranges){let i=t.map(r=>ir(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>yu(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let h=i[o],{open:a,close:f}=l;r.push({from:a.pos-h.open.length,to:a.pos+a.margin},{from:f.pos-f.margin,to:f.pos+h.close.length})}return{changes:r}}return null}function ku(s,e,t=e.selection.ranges){let i=[],n=-1;e:for(let{from:r,to:o}of t){let l=i.length,h=1e9,a;for(let f=r;f<=o;){let c=e.doc.lineAt(f);if(a==null&&(a=ir(e,c.from).line,!a))continue e;if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+a.length)==a?u:-1;u<c.text.length&&u<h&&(h=u),i.push({line:c,comment:p,token:a,indent:u,empty:d,single:!1})}f=c.to+1}if(h<1e9)for(let f=l;f<i.length;f++)i[f].indent<i[f].line.text.length&&(i[f].indent=h);i.length==l+1&&(i[l].single=!0)}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:h,indent:a,empty:f,single:c}of i)(c||!f)&&r.push({from:l.from+a,insert:h+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:h}of i)if(l>=0){let a=o.from+l,f=a+h.length;o.text[f-o.from]==" "&&f++,r.push({from:a,to:f})}return{changes:r}}return null}const Ds=Ye.define(),xu=Ye.define(),wu=A.define(),ph=A.define({combine(s){return Xo(s,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}}),gh=Je.define({create(){return We.empty},update(s,e){let t=e.state.facet(ph),i=e.annotation(Ds);if(i){let h=fe.fromTransaction(e,i.selection),a=i.side,f=a==0?s.undone:s.done;return h?f=nn(f,f.length,t.minDepth,h):f=bh(f,e.startState.selection),new We(a==0?i.rest:f,a==0?f:i.rest)}let n=e.annotation(xu);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(_.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=fe.fromTransaction(e),o=e.annotation(_.time),l=e.annotation(_.userEvent);return r?s=s.addChanges(r,o,l,t,e):e.selection&&(s=s.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(e=>e.toJSON()),undone:s.undone.map(e=>e.toJSON())}},fromJSON(s){return new We(s.done.map(fe.fromJSON),s.undone.map(fe.fromJSON))}});function fp(s={}){return[gh,ph.of(s),D.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?mh:e.inputType=="historyRedo"?Os:null;return i?(e.preventDefault(),i(t)):!1}})]}function bn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(gh,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const mh=bn(0,!1),Os=bn(1,!1),Su=bn(0,!0),vu=bn(1,!0);class fe{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new fe(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(e){return new fe(e.changes&&X.fromJSON(e.changes),[],e.mapped&&He.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=xe;for(let n of e.startState.facet(wu)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new fe(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,xe)}static selection(e){return new fe(void 0,xe,void 0,void 0,e)}}function nn(s,e,t,i){let n=e+1>t+20?e-t-1:0,r=s.slice(n,e);return r.push(i),r}function Au(s,e){let t=[],i=!1;return s.iterChangedRanges((n,r)=>t.push(n,r)),e.iterChangedRanges((n,r,o,l)=>{for(let h=0;h<t.length;){let a=t[h++],f=t[h++];l>=a&&o<=f&&(i=!0)}}),i}function Cu(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function yh(s,e){return s.length?e.length?s.concat(e):s:e}const xe=[],Mu=200;function bh(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Mu));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),nn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[fe.selection([e])]}function Tu(s){let e=s[s.length-1],t=s.slice();return t[s.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function zn(s,e){if(!s.length)return s;let t=s.length,i=xe;for(;t;){let n=Du(s[t-1],e,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,t);return r[t-1]=n,r}else e=n.mapped,t--,i=n.selectionsAfter}return i.length?[fe.selection(i)]:xe}function Du(s,e,t){let i=yh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):xe,t);if(!s.changes)return fe.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new fe(n,q.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const Ou=/^(input\.type|delete)($|\.)/;class We{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new We(this.done,this.undone):this}addChanges(e,t,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Ou.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Au(l.changes,e.changes))||i=="input.type.compose")?o=nn(o,o.length-1,n.minDepth,new fe(e.changes.compose(l.changes),yh(q.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,xe)):o=nn(o,o.length,n.minDepth,e),new We(o,xe,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:xe;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Cu(r[r.length-1],e)?this:new We(bh(this.done,e),this.undone,t,i)}addMapping(e){return new We(zn(this.done,e),zn(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Ds.of({side:e,rest:Tu(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?xe:n.slice(0,n.length-1);return r.mapped&&(l=zn(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Ds.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}We.empty=new We(xe,xe);const cp=[{key:"Mod-z",run:mh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Os,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Os,preventDefault:!0},{key:"Mod-u",run:Su,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:vu,preventDefault:!0}];function Ht(s,e){return b.create(s.ranges.map(e),s.mainIndex)}function Me(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Te({state:s,dispatch:e},t){let i=Ht(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Me(s,i)),!0)}function kn(s,e){return b.cursor(e?s.to:s.from)}function kh(s,e){return Te(s,t=>t.empty?s.moveByChar(t,e):kn(t,e))}function re(s){return s.textDirectionAt(s.state.selection.main.head)==Y.LTR}const xh=s=>kh(s,!re(s)),wh=s=>kh(s,re(s));function Sh(s,e){return Te(s,t=>t.empty?s.moveByGroup(t,e):kn(t,e))}const Bu=s=>Sh(s,!re(s)),Pu=s=>Sh(s,re(s));function Iu(s,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(e.from,e.to)))||e.firstChild}function xn(s,e,t){let i=we(s).resolveInner(e.head),n=t?B.closedBy:B.openedBy;for(let h=e.head;;){let a=t?i.childAfter(h):i.childBefore(h);if(!a)break;Iu(s,a,n)?i=a:h=t?a.to:a.from}let r=i.type.prop(n),o,l;return r&&(o=t?At(s,i.from,1):At(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const Eu=s=>Te(s,e=>xn(s.state,e,!re(s))),Lu=s=>Te(s,e=>xn(s.state,e,re(s)));function vh(s,e){return Te(s,t=>{if(!t.empty)return kn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const Ah=s=>vh(s,!1),Ch=s=>vh(s,!0);function Mh(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(D.scrollMargins)){let o=r(s);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function Th(s,e){let t=Mh(s),{state:i}=s,n=Ht(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):kn(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),h=l.top+t.marginTop,a=l.bottom-t.marginBottom;o&&o.top>h&&o.bottom<a&&(r=D.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-h}))}return s.dispatch(Me(i,n),{effects:r}),!0}const yo=s=>Th(s,!1),Bs=s=>Th(s,!0);function ot(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const Ru=s=>Te(s,e=>ot(s,e,!0)),Nu=s=>Te(s,e=>ot(s,e,!1)),Fu=s=>Te(s,e=>ot(s,e,!re(s))),Wu=s=>Te(s,e=>ot(s,e,re(s))),Hu=s=>Te(s,e=>b.cursor(s.lineBlockAt(e.head).from,1)),Vu=s=>Te(s,e=>b.cursor(s.lineBlockAt(e.head).to,-1));function zu(s,e,t){let i=!1,n=Ht(s.selection,r=>{let o=At(s,r.head,-1)||At(s,r.head,1)||r.head>0&&At(s,r.head-1,1)||r.head<s.doc.length&&At(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return b.cursor(l)});return i?(e(Me(s,n)),!0):!1}const Ku=({state:s,dispatch:e})=>zu(s,e);function Se(s,e){let t=Ht(s.state.selection,i=>{let n=e(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return t.eq(s.state.selection)?!1:(s.dispatch(Me(s.state,t)),!0)}function Dh(s,e){return Se(s,t=>s.moveByChar(t,e))}const Oh=s=>Dh(s,!re(s)),Bh=s=>Dh(s,re(s));function Ph(s,e){return Se(s,t=>s.moveByGroup(t,e))}const $u=s=>Ph(s,!re(s)),qu=s=>Ph(s,re(s)),ju=s=>Se(s,e=>xn(s.state,e,!re(s))),Uu=s=>Se(s,e=>xn(s.state,e,re(s)));function Ih(s,e){return Se(s,t=>s.moveVertically(t,e))}const Eh=s=>Ih(s,!1),Lh=s=>Ih(s,!0);function Rh(s,e){return Se(s,t=>s.moveVertically(t,e,Mh(s).height))}const bo=s=>Rh(s,!1),ko=s=>Rh(s,!0),Gu=s=>Se(s,e=>ot(s,e,!0)),Ju=s=>Se(s,e=>ot(s,e,!1)),Yu=s=>Se(s,e=>ot(s,e,!re(s))),_u=s=>Se(s,e=>ot(s,e,re(s))),Xu=s=>Se(s,e=>b.cursor(s.lineBlockAt(e.head).from)),Qu=s=>Se(s,e=>b.cursor(s.lineBlockAt(e.head).to)),xo=({state:s,dispatch:e})=>(e(Me(s,{anchor:0})),!0),wo=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.doc.length})),!0),So=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.selection.main.anchor,head:0})),!0),vo=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),Zu=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),ed=({state:s,dispatch:e})=>{let t=wn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:b.create(t),userEvent:"select"})),!0},td=({state:s,dispatch:e})=>{let t=Ht(s.selection,i=>{let n=we(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return b.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Me(s,t)),!0)};function Nh(s,e){let{state:t}=s,i=t.selection,n=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let h=s.moveVertically(l,e);if(h.head<o.from||h.head>o.to){n.some(a=>a.head==h.head)||n.push(h);break}else{if(h.head==l.head)break;l=h}}}return n.length==i.ranges.length?!1:(s.dispatch(Me(t,b.create(n,n.length-1))),!0)}const id=s=>Nh(s,!1),nd=s=>Nh(s,!0),sd=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Me(s,i)),!0):!1};function bi(s,e){if(s.state.readOnly)return!1;let t="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let h=e(r);h<o?(t="delete.backward",h=Fi(s,h,!1)):h>o&&(t="delete.forward",h=Fi(s,h,!0)),o=Math.min(o,h),l=Math.max(l,h)}else o=Fi(s,o,!1),l=Fi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?D.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Fi(s,e,t){if(s instanceof D)for(let i of s.state.facet(D.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const Fh=(s,e,t)=>bi(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,h;if(t&&!e&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let a=hn(l,r.tabSize),f=a%kt(r)||kt(r);for(let c=0;c<f&&l[l.length-1-c]==" ";c++)n--;h=n}else h=ie(o.text,n-o.from,e,e)+o.from,h==n&&o.number!=(e?r.doc.lines:1)?h+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(h-o.from,n-o.from))&&(h=ie(o.text,h-o.from,!1,!1)+o.from);return h}),Ps=s=>Fh(s,!1,!0),Wh=s=>Fh(s,!0,!1),Hh=(s,e)=>bi(s,t=>{let i=t.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?n.doc.lines:1)&&(i+=e?1:-1);break}let h=ie(r.text,i-r.from,e)+r.from,a=r.text.slice(Math.min(i,h)-r.from,Math.max(i,h)-r.from),f=o(a);if(l!=null&&f!=l)break;(a!=" "||i!=t.head)&&(l=f),i=h}return i}),Vh=s=>Hh(s,!1),rd=s=>Hh(s,!0),od=s=>bi(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),ld=s=>bi(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),hd=s=>bi(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),ad=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:E.of(["",""])},range:b.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},fd=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let n=i.from,r=s.doc.lineAt(n),o=n==r.from?n-1:ie(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ie(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:b.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function wn(s){let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.from),r=s.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=s.doc.lineAt(i.to-1)),t>=n.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:n.from,to:r.to,ranges:[i]});t=r.number+1}return e}function zh(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of wn(s)){if(t?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let h of r.ranges)n.push(b.range(Math.min(s.doc.length,h.anchor+l),Math.min(s.doc.length,h.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let h of r.ranges)n.push(b.range(h.anchor-l,h.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const cd=({state:s,dispatch:e})=>zh(s,e,!1),ud=({state:s,dispatch:e})=>zh(s,e,!0);function Kh(s,e,t){if(s.readOnly)return!1;let i=[];for(let r of wn(s))t?i.push({from:r.from,insert:s.doc.slice(r.from,r.to)+s.lineBreak}):i.push({from:r.to,insert:s.lineBreak+s.doc.slice(r.from,r.to)});let n=s.changes(i);return e(s.update({changes:n,selection:s.selection.map(n,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const dd=({state:s,dispatch:e})=>Kh(s,e,!1),pd=({state:s,dispatch:e})=>Kh(s,e,!0),gd=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(wn(e).map(({from:n,to:r})=>(n>0?n--:r<e.doc.length&&r++,{from:n,to:r}))),i=Ht(e.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function md(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=we(s).resolveInner(e),i=t.childBefore(e),n=t.childAfter(e),r;return i&&n&&i.to<=e&&n.from>=e&&(r=i.type.prop(B.closedBy))&&r.indexOf(n.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(n.from).from&&!/\S/.test(s.sliceDoc(i.to,n.from))?{from:i.to,to:n.from}:null}const Ao=$h(!1),yd=$h(!0);function $h(s){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(n=>{let{from:r,to:o}=n,l=e.doc.lineAt(r),h=!s&&r==o&&md(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let a=new mn(e,{simulateBreak:r,simulateDoubleBreak:!!h}),f=Xs(a,r);for(f==null&&(f=hn(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;h?{from:r,to:o}=h:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",ui(e,f)];return h&&c.push(ui(e,a.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:E.of(c)},range:b.cursor(r+1+c[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function nr(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const bd=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new mn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=nr(s,(r,o,l)=>{let h=Xs(i,r.from);if(h==null)return;/\S/.test(r.text)||(h=0);let a=/^\s*/.exec(r.text)[0],f=ui(s,h);(a!=f||l.from<r.from+a.length)&&(t[r.from]=h,o.push({from:r.from,to:r.from+a.length,insert:f}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},qh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(nr(s,(t,i)=>{i.push({from:t.from,insert:s.facet(gn)})}),{userEvent:"input.indent"})),!0),jh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(nr(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=hn(n,s.tabSize),o=0,l=ui(s,Math.max(0,r-kt(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),kd=s=>(s.setTabFocusMode(),!0),xd=[{key:"Ctrl-b",run:xh,shift:Oh,preventDefault:!0},{key:"Ctrl-f",run:wh,shift:Bh},{key:"Ctrl-p",run:Ah,shift:Eh},{key:"Ctrl-n",run:Ch,shift:Lh},{key:"Ctrl-a",run:Hu,shift:Xu},{key:"Ctrl-e",run:Vu,shift:Qu},{key:"Ctrl-d",run:Wh},{key:"Ctrl-h",run:Ps},{key:"Ctrl-k",run:od},{key:"Ctrl-Alt-h",run:Vh},{key:"Ctrl-o",run:ad},{key:"Ctrl-t",run:fd},{key:"Ctrl-v",run:Bs}],wd=[{key:"ArrowLeft",run:xh,shift:Oh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Bu,shift:$u,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Fu,shift:Yu,preventDefault:!0},{key:"ArrowRight",run:wh,shift:Bh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Pu,shift:qu,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Wu,shift:_u,preventDefault:!0},{key:"ArrowUp",run:Ah,shift:Eh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xo,shift:So},{mac:"Ctrl-ArrowUp",run:yo,shift:bo},{key:"ArrowDown",run:Ch,shift:Lh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:wo,shift:vo},{mac:"Ctrl-ArrowDown",run:Bs,shift:ko},{key:"PageUp",run:yo,shift:bo},{key:"PageDown",run:Bs,shift:ko},{key:"Home",run:Nu,shift:Ju,preventDefault:!0},{key:"Mod-Home",run:xo,shift:So},{key:"End",run:Ru,shift:Gu,preventDefault:!0},{key:"Mod-End",run:wo,shift:vo},{key:"Enter",run:Ao,shift:Ao},{key:"Mod-a",run:Zu},{key:"Backspace",run:Ps,shift:Ps,preventDefault:!0},{key:"Delete",run:Wh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Vh,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:rd,preventDefault:!0},{mac:"Mod-Backspace",run:ld,preventDefault:!0},{mac:"Mod-Delete",run:hd,preventDefault:!0}].concat(xd.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),up=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Eu,shift:ju},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Lu,shift:Uu},{key:"Alt-ArrowUp",run:cd},{key:"Shift-Alt-ArrowUp",run:dd},{key:"Alt-ArrowDown",run:ud},{key:"Shift-Alt-ArrowDown",run:pd},{key:"Mod-Alt-ArrowUp",run:id},{key:"Mod-Alt-ArrowDown",run:nd},{key:"Escape",run:sd},{key:"Mod-Enter",run:yd},{key:"Alt-l",mac:"Ctrl-l",run:ed},{key:"Mod-i",run:td,preventDefault:!0},{key:"Mod-[",run:jh},{key:"Mod-]",run:qh},{key:"Mod-Alt-\\",run:bd},{key:"Shift-Mod-k",run:gd},{key:"Shift-Mod-\\",run:Ku},{key:"Mod-/",run:du},{key:"Alt-A",run:gu},{key:"Ctrl-m",mac:"Shift-Alt-m",run:kd}].concat(wd),dp={key:"Tab",run:qh,shift:jh};class pp{constructor(e,t,i,n){this.state=e,this.pos=t,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=we(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(vd(e));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Co(s){let e=Object.keys(s).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Sd(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=Co(e)+Co(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function gp(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:Sd(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}function mp(s,e){return t=>{for(let i=we(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}function vd(s,e){var t;let{source:i}=s,n=i[i.length-1]!="$";return n?new RegExp(`(?:${i})${n?"$":""}`,(t=s.flags)!==null&&t!==void 0?t:s.ignoreCase?"i":""):s}const Ad=Ye.define(),Cd=D.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Md{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class sr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,le.TrackDel),i=e.mapPos(this.to,1,le.TrackDel);return t==null||i==null?null:new sr(this.field,t,i)}}class rr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let h of this.lines){if(i.length){let a=o,f=/^\t*/.exec(h)[0].length;for(let c=0;c<f;c++)a+=e.facet(gn);n.push(t+a.length-f),h=a+h.slice(f)}i.push(h),t+=h.length+1}let l=this.fieldPositions.map(h=>new sr(h.field,n[h.line]+h.from,n[h.line]+h.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,h=r[2]||r[3]||"",a=-1,f=h.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:f&&t[c].name==f)&&(a=c);if(a<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:f}),a=c;for(let u of n)u.field>=a&&u.field++}for(let c of n)if(c.line==i.length&&c.from>r.index){let u=r[2]?3+(r[1]||"").length:2;c.from-=u,c.to-=u}n.push(new Md(a,i.length,r.index,r.index+f.length)),o=o.slice(0,r.index)+h+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,h,a)=>{for(let f of n)f.line==i.length&&f.from>a&&(f.from--,f.to--);return h}),i.push(o)}return new rr(i,n)}}let Td=z.widget({widget:new class extends Wt{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Dd=z.mark({class:"cm-snippetField"});class Vt{constructor(e,t){this.ranges=e,this.active=t,this.deco=z.set(e.map(i=>(i.from==i.to?Td:Dd).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new Vt(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const ki=q.define({map(s,e){return s&&s.map(e)}}),Od=q.define(),pi=Je.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(ki))return t.value;if(t.is(Od)&&s)return new Vt(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>D.decorations.from(s,e=>e?e.deco:z.none)});function or(s,e){return b.create(s.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Bd(s){let e=rr.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),{main:h}=t.state.selection,a={changes:{from:n,to:r==h.from?h.to:r,insert:E.of(o)},scrollIntoView:!0,annotations:i?[Ad.of(i),_.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=or(l,0)),l.some(f=>f.field>0)){let f=new Vt(l,0),c=a.effects=[ki.of(f)];t.state.field(pi,!1)===void 0&&c.push(q.appendConfig.of([pi,Rd,Nd,Cd]))}t.dispatch(t.state.update(a))}}function Uh(s){return({state:e,dispatch:t})=>{let i=e.field(pi,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:or(i.ranges,n),effects:ki.of(r?null:new Vt(i.ranges,n)),scrollIntoView:!0})),!0}}const Pd=({state:s,dispatch:e})=>s.field(pi,!1)?(e(s.update({effects:ki.of(null)})),!0):!1,Id=Uh(1),Ed=Uh(-1),Ld=[{key:"Tab",run:Id,shift:Ed},{key:"Escape",run:Pd}],Mo=A.define({combine(s){return s.length?s[0]:Ld}}),Rd=on.highest(jl.compute([Mo],s=>s.facet(Mo)));function yp(s,e){return{...e,apply:Bd(s)}}const Nd=D.domEventHandlers({mousedown(s,e){let t=e.state.field(pi,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:or(t.ranges,n.field),effects:ki.of(t.ranges.some(r=>r.field>n.field)?new Vt(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),Gh=new class extends tt{};Gh.startSide=1;Gh.endSide=-1;var To={};class sn{constructor(e,t,i,n,r,o,l,h,a,f=0,c){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new sn(e,[],t,i,i,0,[],0,n?new Do(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let h=this.stack.length-(i-1)*3-(e&262144?6:0),a=h?this.stack[h-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let f=this.reducePos-a;f>=2e3&&!(!((t=this.p.parser.nodeSet.types[n])===null||t===void 0)&&t.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=f):this.p.lastBigReductionSize<f&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=f));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,a,d,u+4,!0)}if(e&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(n,a)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(t==i)return;if(this.buffer[o-2]>=t){this.buffer[o-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(e,t,i,n){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=n;let l=o.stateFlag(r,1);!l&&(n>i||t<=o.maxNode)&&(this.reducePos=n),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,n,4)}else this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4)}apply(e,t,i,n){e&65536?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(t&&e.buffer[t-4]==0&&(t-=4);t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new sn(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Fd(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&n.push(t[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<t.length;r+=2){let o=t[r+1];n.some((l,h)=>h&1&&l==o)||n.push(t[r],o)}t=n}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let r=t[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let h=o&65535,a=this.stack.length-l*3;if(a>=0&&e.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new Do(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class Do{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class Fd{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class rn{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new rn(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new rn(this.stack,this.pos,this.index)}}function Yt(s,e=Uint16Array){if(typeof s!="string")return s;let t=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),r+=h,l)break;r*=46}t?t[n++]=r:t=new e(r)}return t}class $i{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const Oo=new $i;class Wd{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Oo,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,n;if(t>=0&&t<this.chunk.length)i=this.pos+e,n=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=Oo,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class Bt{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;Jh(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}Bt.prototype.contextual=Bt.prototype.fallback=Bt.prototype.extend=!1;class Hd{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data=typeof e=="string"?Yt(e):e}token(e,t){let i=e.pos,n=0;for(;;){let r=e.next<0,o=e.resolveOffset(1,1);if(Jh(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(this.elseToken==null)return;if(r||n++,o==null)break;e.reset(o,e.token)}n&&(e.reset(i,e.token),e.acceptToken(this.elseToken,n))}}Hd.prototype.contextual=Bt.prototype.fallback=Bt.prototype.extend=!1;class bp{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function Jh(s,e,t,i,n,r){let o=0,l=1<<i,{dialect:h}=t.p.parser;e:for(;(l&s[o])!=0;){let a=s[o+1];for(let d=o+3;d<a;d+=2)if((s[d+1]&l)>0){let p=s[d];if(h.allows(p)&&(e.token.value==-1||e.token.value==p||Vd(p,e.token.value,n,r))){e.acceptToken(p);break}}let f=e.next,c=0,u=s[o+2];if(e.next<0&&u>c&&s[a+u*3-3]==65535){o=s[a+u*3-1];continue e}for(;c<u;){let d=c+u>>1,p=a+d+(d<<1),g=s[p],m=s[p+1]||65536;if(f<g)u=d;else if(f>=m)c=d+1;else{o=s[p+2],e.advance();continue e}}break}}function Bo(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function Vd(s,e,t,i){let n=Bo(t,i,e);return n<0||Bo(t,i,s)<n}const de=typeof process<"u"&&To&&/\bparse\b/.test(To.LOG);let Kn=null;function Po(s,e,t){let i=s.cursor(F.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(s.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:s.length}}class zd{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Po(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Po(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[t]+i.positions[n];if(o>e)return this.nextStart=o,null;if(r instanceof R){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let h=r.prop(B.lookAhead);if(!h||l+h<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class Kd{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new $i)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,o=n.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,h=0;for(let a=0;a<r.length;a++){if((1<<a&o)==0)continue;let f=r[a],c=this.tokens[a];if(!(i&&!f.fallback)&&((f.contextual||c.start!=e.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,f,e),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=t;if(c.extended>-1&&(t=this.addActions(e,c.extended,c.end,t)),t=this.addActions(e,c.value,c.end,t),!f.extend&&(i=c,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return h&&e.setLookAhead(h),!i&&e.pos==this.stream.end&&(i=new $i,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new $i,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let h=0;h<2;h++)for(let a=o.stateSlot(r,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=ze(l,a+2);else{n==0&&l[a+1]==2&&(n=this.putAction(ze(l,a+2),t,i,n));break}l[a]==t&&(n=this.putAction(ze(l,a+1),t,i,n))}return n}}class $d{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Wd(t,n),this.tokens=new Kd(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[sn.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new zd(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{n||(n=[],r=[]),n.push(l);let h=this.tokens.getMainToken(l);r.push(h.value,h.end)}}break}}if(!i.length){let o=n&&jd(n);if(o)return de&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw de&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return de&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let a=i[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this,o=de?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let a=e.curContext&&e.curContext.tracker.strict,f=a?e.curContext.hash:0;for(let c=this.fragments.nodeAt(n);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?r.getGoto(e.state,c.type.id):-1;if(u>-1&&c.length&&(!a||(c.prop(B.contextHash)||0)==f))return e.useNode(c,u),de&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof R)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof R&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),de&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let h=this.tokens.getActions(e);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],u=h[a++],d=a==h.length||!i,p=d?e:e.split(),g=this.tokens.mainToken;if(p.apply(f,c,g?g.start:p.pos,u),de&&console.log(o+this.stackID(p)+` (via ${(f&65536)==0?"shift":`reduce of ${r.getName(f&65535)}`} for ${r.getName(c)} @ ${n}${p==e?"":", split"})`),d)return!0;p.pos>n?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return Io(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],h=t[o<<1],a=t[(o<<1)+1],f=de?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),de&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=f;for(let d=0;d<10&&c.forceReduce()&&(de&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)de&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))de&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),de&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Io(l,i)):(!n||n.score<c.score)&&(n=c)}return n}stackToTree(e){return e.close(),R.build({buffer:rn.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Kn||(Kn=new WeakMap)).get(e);return t||Kn.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function Io(s,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==s.pos&&i.sameState(s)){e[t].score<s.score&&(e[t]=s);return}}e.push(s)}class qd{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}const $n=s=>s;class kp{constructor(e){this.start=e.start,this.shift=e.shift||$n,this.reduce=e.reduce||$n,this.reuse=e.reuse||$n,this.hash=e.hash||(()=>0),this.strict=e.strict!==!1}}class Is extends _s{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),n=[];for(let l=0;l<t.length;l++)n.push([]);function r(l,h,a){n[l].push([h,h.deserialize(String(a))])}if(e.nodeProps)for(let l of e.nodeProps){let h=l[0];typeof h=="string"&&(h=B[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)r(f,h,l[a++]);else{let c=l[a+-f];for(let u=-f;u>0;u--)r(l[a++],h,c);a++}}}this.nodeSet=new pn(t.map((l,h)=>se.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:n[h],top:i.indexOf(h)>-1,error:h==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(h)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Gl;let o=Yt(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Eo),this.states=Yt(e.states,Uint32Array),this.data=Yt(e.stateData),this.goto=Yt(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new Bt(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new $d(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let o=n[r++],l=o&1,h=n[r++];if(l&&i)return h;for(let a=r+(o>>1);r<a;r++)if(n[r]==e)return h;if(l)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(e,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=ze(i,r+2)];else{if(i[r+1]==2)return ze(i,r+2);break}if(o==t||o==0)return ze(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=ze(this.data,r+2);else break;n=t(ze(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=ze(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];t.some((r,o)=>o&1&&r==n)||t.push(this.data[i],n)}}return t}configure(e){let t=Object.assign(Object.create(Is.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let n=e.tokenizers.find(r=>r.from==i);return n?n.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=Eo(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new qd(e,i,n)}static deserialize(e){return new Is(e)}}function ze(s,e){return s[e]|s[e+1]<<16}function jd(s){let e=null;for(let t of s){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Eo(s){if(s.external){let e=s.extend?1:0;return(t,i)=>s.external(t,i)<<1|e}return s.get}export{Jd as $,jl as A,hn as B,kp as C,sp as D,bp as E,ke as F,gn as G,pp as H,F as I,N as J,pt as K,Is as L,th as M,se as N,Rt as O,_s as P,ln as Q,fp as R,np as S,me as T,lp as U,Gd as V,cp as W,up as X,Ao as Y,dp as Z,hp as _,B as a,lh as a0,pn as b,R as c,Hd as d,As as e,ip as f,rp as g,op as h,ih as i,Zd as j,we as k,Yd as l,Kc as m,tp as n,ep as o,_d as p,mp as q,gp as r,Fc as s,w as t,Zl as u,yp as v,D as w,b as x,nu as y,on as z};
12
+ `);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let n=this.rangeIndex;;){let r=this.ranges[n].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),n++,n==this.ranges.length))break;let o=this.ranges[n].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let n=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?n>r:n>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-n}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,i,n){let r=4;if(this.ranges.length>1){n=this.skipGapsTo(t,n,1),t+=n;let l=this.chunk.length;n=this.skipGapsTo(i,n,-1),i+=n,r+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&r==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=i:this.chunk.push(e,t,i,r),n}parseLine(e){let{line:t,end:i}=this.nextLine(),n=0,{streamParser:r}=this.lang,o=new oh(t,e?e.state.tabSize:4,e?kt(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=ah(r.token,o,this.state);if(l&&(n=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,n)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=R.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:fu,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new R(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new R(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}};function ah(s,e,t){e.start=e.pos;for(let i=0;i<10;i++){let n=s(e,t);if(e.pos>e.start)return n}throw new Error("Stream parser failed to advance stream.")}const er=Object.create(null),di=[se.none],fu=new pn(di),go=[],mo=Object.create(null),fh=Object.create(null);for(let[s,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])fh[s]=uh(er,e);class ch{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),fh)}resolve(e){return e?this.table[e]||(this.table[e]=uh(this.extra,e)):0}}const cu=new ch(er);function Vn(s,e){go.indexOf(s)>-1||(go.push(s),console.warn(e))}function uh(s,e){let t=[];for(let l of e.split(" ")){let h=[];for(let a of l.split(".")){let f=s[a]||w[a];f?typeof f=="function"?h.length?h=h.map(f):Vn(a,`Modifier ${a} used at start of tag`):h.length?Vn(a,`Tag ${a} used as modifier`):h=Array.isArray(f)?f:[f]:Vn(a,`Unknown highlighting tag ${a}`)}for(let a of h)t.push(a)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=mo[n];if(r)return r.id;let o=mo[n]=se.define({id:di.length,name:i,props:[Fc({[i]:t})]});return di.push(o),o.id}function uu(s,e){let t=se.define({id:di.length,name:"Document",props:[pt.add(()=>s),ih.add(()=>i=>e.getIndent(i))],top:!0});return di.push(t),t}Y.RTL,Y.LTR;const du=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=ir(s.state,t.from);return i.line?pu(s):i.block?mu(s):!1};function tr(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const pu=tr(ku,0),gu=tr(dh,0),mu=tr((s,e)=>dh(s,e,bu(e)),0);function ir(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Ut=50;function yu(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-Ut,i),o=s.sliceDoc(n,n+Ut),l=/\s*$/.exec(r)[0].length,h=/^\s*/.exec(o)[0].length,a=r.length-l;if(r.slice(a-e.length,a)==e&&o.slice(h,h+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+h,margin:h&&1}};let f,c;n-i<=2*Ut?f=c=s.sliceDoc(i,n):(f=s.sliceDoc(i,i+Ut),c=s.sliceDoc(n-Ut,n));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function bu(s){let e=[];for(let t of s.selection.ranges){let i=s.doc.lineAt(t.from),n=t.to<=i.to?i:s.doc.lineAt(t.to);n.from>i.from&&n.from==t.to&&(n=t.to==i.to+1?i:s.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=n.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return e}function dh(s,e,t=e.selection.ranges){let i=t.map(r=>ir(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>yu(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let h=i[o],{open:a,close:f}=l;r.push({from:a.pos-h.open.length,to:a.pos+a.margin},{from:f.pos-f.margin,to:f.pos+h.close.length})}return{changes:r}}return null}function ku(s,e,t=e.selection.ranges){let i=[],n=-1;e:for(let{from:r,to:o}of t){let l=i.length,h=1e9,a;for(let f=r;f<=o;){let c=e.doc.lineAt(f);if(a==null&&(a=ir(e,c.from).line,!a))continue e;if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+a.length)==a?u:-1;u<c.text.length&&u<h&&(h=u),i.push({line:c,comment:p,token:a,indent:u,empty:d,single:!1})}f=c.to+1}if(h<1e9)for(let f=l;f<i.length;f++)i[f].indent<i[f].line.text.length&&(i[f].indent=h);i.length==l+1&&(i[l].single=!0)}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:h,indent:a,empty:f,single:c}of i)(c||!f)&&r.push({from:l.from+a,insert:h+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:h}of i)if(l>=0){let a=o.from+l,f=a+h.length;o.text[f-o.from]==" "&&f++,r.push({from:a,to:f})}return{changes:r}}return null}const Ds=Ye.define(),xu=Ye.define(),wu=A.define(),ph=A.define({combine(s){return Xo(s,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}}),gh=Je.define({create(){return We.empty},update(s,e){let t=e.state.facet(ph),i=e.annotation(Ds);if(i){let h=fe.fromTransaction(e,i.selection),a=i.side,f=a==0?s.undone:s.done;return h?f=nn(f,f.length,t.minDepth,h):f=bh(f,e.startState.selection),new We(a==0?i.rest:f,a==0?f:i.rest)}let n=e.annotation(xu);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(_.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=fe.fromTransaction(e),o=e.annotation(_.time),l=e.annotation(_.userEvent);return r?s=s.addChanges(r,o,l,t,e):e.selection&&(s=s.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(e=>e.toJSON()),undone:s.undone.map(e=>e.toJSON())}},fromJSON(s){return new We(s.done.map(fe.fromJSON),s.undone.map(fe.fromJSON))}});function fp(s={}){return[gh,ph.of(s),D.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?mh:e.inputType=="historyRedo"?Os:null;return i?(e.preventDefault(),i(t)):!1}})]}function bn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(gh,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const mh=bn(0,!1),Os=bn(1,!1),Su=bn(0,!0),vu=bn(1,!0);class fe{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new fe(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(e){return new fe(e.changes&&X.fromJSON(e.changes),[],e.mapped&&He.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=xe;for(let n of e.startState.facet(wu)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new fe(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,xe)}static selection(e){return new fe(void 0,xe,void 0,void 0,e)}}function nn(s,e,t,i){let n=e+1>t+20?e-t-1:0,r=s.slice(n,e);return r.push(i),r}function Au(s,e){let t=[],i=!1;return s.iterChangedRanges((n,r)=>t.push(n,r)),e.iterChangedRanges((n,r,o,l)=>{for(let h=0;h<t.length;){let a=t[h++],f=t[h++];l>=a&&o<=f&&(i=!0)}}),i}function Cu(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function yh(s,e){return s.length?e.length?s.concat(e):s:e}const xe=[],Mu=200;function bh(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Mu));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),nn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[fe.selection([e])]}function Tu(s){let e=s[s.length-1],t=s.slice();return t[s.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function zn(s,e){if(!s.length)return s;let t=s.length,i=xe;for(;t;){let n=Du(s[t-1],e,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,t);return r[t-1]=n,r}else e=n.mapped,t--,i=n.selectionsAfter}return i.length?[fe.selection(i)]:xe}function Du(s,e,t){let i=yh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):xe,t);if(!s.changes)return fe.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new fe(n,q.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const Ou=/^(input\.type|delete)($|\.)/;class We{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new We(this.done,this.undone):this}addChanges(e,t,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Ou.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Au(l.changes,e.changes))||i=="input.type.compose")?o=nn(o,o.length-1,n.minDepth,new fe(e.changes.compose(l.changes),yh(q.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,xe)):o=nn(o,o.length,n.minDepth,e),new We(o,xe,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:xe;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Cu(r[r.length-1],e)?this:new We(bh(this.done,e),this.undone,t,i)}addMapping(e){return new We(zn(this.done,e),zn(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Ds.of({side:e,rest:Tu(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?xe:n.slice(0,n.length-1);return r.mapped&&(l=zn(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Ds.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}We.empty=new We(xe,xe);const cp=[{key:"Mod-z",run:mh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Os,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Os,preventDefault:!0},{key:"Mod-u",run:Su,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:vu,preventDefault:!0}];function Ht(s,e){return b.create(s.ranges.map(e),s.mainIndex)}function Me(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Te({state:s,dispatch:e},t){let i=Ht(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Me(s,i)),!0)}function kn(s,e){return b.cursor(e?s.to:s.from)}function kh(s,e){return Te(s,t=>t.empty?s.moveByChar(t,e):kn(t,e))}function re(s){return s.textDirectionAt(s.state.selection.main.head)==Y.LTR}const xh=s=>kh(s,!re(s)),wh=s=>kh(s,re(s));function Sh(s,e){return Te(s,t=>t.empty?s.moveByGroup(t,e):kn(t,e))}const Bu=s=>Sh(s,!re(s)),Pu=s=>Sh(s,re(s));function Iu(s,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(e.from,e.to)))||e.firstChild}function xn(s,e,t){let i=we(s).resolveInner(e.head),n=t?B.closedBy:B.openedBy;for(let h=e.head;;){let a=t?i.childAfter(h):i.childBefore(h);if(!a)break;Iu(s,a,n)?i=a:h=t?a.to:a.from}let r=i.type.prop(n),o,l;return r&&(o=t?At(s,i.from,1):At(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const Eu=s=>Te(s,e=>xn(s.state,e,!re(s))),Lu=s=>Te(s,e=>xn(s.state,e,re(s)));function vh(s,e){return Te(s,t=>{if(!t.empty)return kn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const Ah=s=>vh(s,!1),Ch=s=>vh(s,!0);function Mh(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(D.scrollMargins)){let o=r(s);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function Th(s,e){let t=Mh(s),{state:i}=s,n=Ht(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):kn(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),h=l.top+t.marginTop,a=l.bottom-t.marginBottom;o&&o.top>h&&o.bottom<a&&(r=D.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-h}))}return s.dispatch(Me(i,n),{effects:r}),!0}const yo=s=>Th(s,!1),Bs=s=>Th(s,!0);function ot(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const Ru=s=>Te(s,e=>ot(s,e,!0)),Nu=s=>Te(s,e=>ot(s,e,!1)),Fu=s=>Te(s,e=>ot(s,e,!re(s))),Wu=s=>Te(s,e=>ot(s,e,re(s))),Hu=s=>Te(s,e=>b.cursor(s.lineBlockAt(e.head).from,1)),Vu=s=>Te(s,e=>b.cursor(s.lineBlockAt(e.head).to,-1));function zu(s,e,t){let i=!1,n=Ht(s.selection,r=>{let o=At(s,r.head,-1)||At(s,r.head,1)||r.head>0&&At(s,r.head-1,1)||r.head<s.doc.length&&At(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return b.cursor(l)});return i?(e(Me(s,n)),!0):!1}const Ku=({state:s,dispatch:e})=>zu(s,e);function Se(s,e){let t=Ht(s.state.selection,i=>{let n=e(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return t.eq(s.state.selection)?!1:(s.dispatch(Me(s.state,t)),!0)}function Dh(s,e){return Se(s,t=>s.moveByChar(t,e))}const Oh=s=>Dh(s,!re(s)),Bh=s=>Dh(s,re(s));function Ph(s,e){return Se(s,t=>s.moveByGroup(t,e))}const $u=s=>Ph(s,!re(s)),qu=s=>Ph(s,re(s)),ju=s=>Se(s,e=>xn(s.state,e,!re(s))),Uu=s=>Se(s,e=>xn(s.state,e,re(s)));function Ih(s,e){return Se(s,t=>s.moveVertically(t,e))}const Eh=s=>Ih(s,!1),Lh=s=>Ih(s,!0);function Rh(s,e){return Se(s,t=>s.moveVertically(t,e,Mh(s).height))}const bo=s=>Rh(s,!1),ko=s=>Rh(s,!0),Gu=s=>Se(s,e=>ot(s,e,!0)),Ju=s=>Se(s,e=>ot(s,e,!1)),Yu=s=>Se(s,e=>ot(s,e,!re(s))),_u=s=>Se(s,e=>ot(s,e,re(s))),Xu=s=>Se(s,e=>b.cursor(s.lineBlockAt(e.head).from)),Qu=s=>Se(s,e=>b.cursor(s.lineBlockAt(e.head).to)),xo=({state:s,dispatch:e})=>(e(Me(s,{anchor:0})),!0),wo=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.doc.length})),!0),So=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.selection.main.anchor,head:0})),!0),vo=({state:s,dispatch:e})=>(e(Me(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),Zu=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),ed=({state:s,dispatch:e})=>{let t=wn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:b.create(t),userEvent:"select"})),!0},td=({state:s,dispatch:e})=>{let t=Ht(s.selection,i=>{let n=we(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return b.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Me(s,t)),!0)};function Nh(s,e){let{state:t}=s,i=t.selection,n=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let h=s.moveVertically(l,e);if(h.head<o.from||h.head>o.to){n.some(a=>a.head==h.head)||n.push(h);break}else{if(h.head==l.head)break;l=h}}}return n.length==i.ranges.length?!1:(s.dispatch(Me(t,b.create(n,n.length-1))),!0)}const id=s=>Nh(s,!1),nd=s=>Nh(s,!0),sd=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Me(s,i)),!0):!1};function bi(s,e){if(s.state.readOnly)return!1;let t="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let h=e(r);h<o?(t="delete.backward",h=Fi(s,h,!1)):h>o&&(t="delete.forward",h=Fi(s,h,!0)),o=Math.min(o,h),l=Math.max(l,h)}else o=Fi(s,o,!1),l=Fi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?D.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Fi(s,e,t){if(s instanceof D)for(let i of s.state.facet(D.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const Fh=(s,e,t)=>bi(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,h;if(t&&!e&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let a=hn(l,r.tabSize),f=a%kt(r)||kt(r);for(let c=0;c<f&&l[l.length-1-c]==" ";c++)n--;h=n}else h=ie(o.text,n-o.from,e,e)+o.from,h==n&&o.number!=(e?r.doc.lines:1)?h+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(h-o.from,n-o.from))&&(h=ie(o.text,h-o.from,!1,!1)+o.from);return h}),Ps=s=>Fh(s,!1,!0),Wh=s=>Fh(s,!0,!1),Hh=(s,e)=>bi(s,t=>{let i=t.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?n.doc.lines:1)&&(i+=e?1:-1);break}let h=ie(r.text,i-r.from,e)+r.from,a=r.text.slice(Math.min(i,h)-r.from,Math.max(i,h)-r.from),f=o(a);if(l!=null&&f!=l)break;(a!=" "||i!=t.head)&&(l=f),i=h}return i}),Vh=s=>Hh(s,!1),rd=s=>Hh(s,!0),od=s=>bi(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),ld=s=>bi(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),hd=s=>bi(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),ad=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:E.of(["",""])},range:b.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},fd=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let n=i.from,r=s.doc.lineAt(n),o=n==r.from?n-1:ie(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ie(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:b.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function wn(s){let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.from),r=s.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=s.doc.lineAt(i.to-1)),t>=n.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:n.from,to:r.to,ranges:[i]});t=r.number+1}return e}function zh(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of wn(s)){if(t?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let h of r.ranges)n.push(b.range(Math.min(s.doc.length,h.anchor+l),Math.min(s.doc.length,h.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let h of r.ranges)n.push(b.range(h.anchor-l,h.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const cd=({state:s,dispatch:e})=>zh(s,e,!1),ud=({state:s,dispatch:e})=>zh(s,e,!0);function Kh(s,e,t){if(s.readOnly)return!1;let i=[];for(let r of wn(s))t?i.push({from:r.from,insert:s.doc.slice(r.from,r.to)+s.lineBreak}):i.push({from:r.to,insert:s.lineBreak+s.doc.slice(r.from,r.to)});let n=s.changes(i);return e(s.update({changes:n,selection:s.selection.map(n,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const dd=({state:s,dispatch:e})=>Kh(s,e,!1),pd=({state:s,dispatch:e})=>Kh(s,e,!0),gd=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(wn(e).map(({from:n,to:r})=>(n>0?n--:r<e.doc.length&&r++,{from:n,to:r}))),i=Ht(e.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function md(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=we(s).resolveInner(e),i=t.childBefore(e),n=t.childAfter(e),r;return i&&n&&i.to<=e&&n.from>=e&&(r=i.type.prop(B.closedBy))&&r.indexOf(n.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(n.from).from&&!/\S/.test(s.sliceDoc(i.to,n.from))?{from:i.to,to:n.from}:null}const Ao=$h(!1),yd=$h(!0);function $h(s){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(n=>{let{from:r,to:o}=n,l=e.doc.lineAt(r),h=!s&&r==o&&md(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let a=new mn(e,{simulateBreak:r,simulateDoubleBreak:!!h}),f=Xs(a,r);for(f==null&&(f=hn(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;h?{from:r,to:o}=h:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",ui(e,f)];return h&&c.push(ui(e,a.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:E.of(c)},range:b.cursor(r+1+c[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function nr(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const bd=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new mn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=nr(s,(r,o,l)=>{let h=Xs(i,r.from);if(h==null)return;/\S/.test(r.text)||(h=0);let a=/^\s*/.exec(r.text)[0],f=ui(s,h);(a!=f||l.from<r.from+a.length)&&(t[r.from]=h,o.push({from:r.from,to:r.from+a.length,insert:f}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},qh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(nr(s,(t,i)=>{i.push({from:t.from,insert:s.facet(gn)})}),{userEvent:"input.indent"})),!0),jh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(nr(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=hn(n,s.tabSize),o=0,l=ui(s,Math.max(0,r-kt(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),kd=s=>(s.setTabFocusMode(),!0),xd=[{key:"Ctrl-b",run:xh,shift:Oh,preventDefault:!0},{key:"Ctrl-f",run:wh,shift:Bh},{key:"Ctrl-p",run:Ah,shift:Eh},{key:"Ctrl-n",run:Ch,shift:Lh},{key:"Ctrl-a",run:Hu,shift:Xu},{key:"Ctrl-e",run:Vu,shift:Qu},{key:"Ctrl-d",run:Wh},{key:"Ctrl-h",run:Ps},{key:"Ctrl-k",run:od},{key:"Ctrl-Alt-h",run:Vh},{key:"Ctrl-o",run:ad},{key:"Ctrl-t",run:fd},{key:"Ctrl-v",run:Bs}],wd=[{key:"ArrowLeft",run:xh,shift:Oh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Bu,shift:$u,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Fu,shift:Yu,preventDefault:!0},{key:"ArrowRight",run:wh,shift:Bh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Pu,shift:qu,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Wu,shift:_u,preventDefault:!0},{key:"ArrowUp",run:Ah,shift:Eh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xo,shift:So},{mac:"Ctrl-ArrowUp",run:yo,shift:bo},{key:"ArrowDown",run:Ch,shift:Lh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:wo,shift:vo},{mac:"Ctrl-ArrowDown",run:Bs,shift:ko},{key:"PageUp",run:yo,shift:bo},{key:"PageDown",run:Bs,shift:ko},{key:"Home",run:Nu,shift:Ju,preventDefault:!0},{key:"Mod-Home",run:xo,shift:So},{key:"End",run:Ru,shift:Gu,preventDefault:!0},{key:"Mod-End",run:wo,shift:vo},{key:"Enter",run:Ao,shift:Ao},{key:"Mod-a",run:Zu},{key:"Backspace",run:Ps,shift:Ps,preventDefault:!0},{key:"Delete",run:Wh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Vh,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:rd,preventDefault:!0},{mac:"Mod-Backspace",run:ld,preventDefault:!0},{mac:"Mod-Delete",run:hd,preventDefault:!0}].concat(xd.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),up=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Eu,shift:ju},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Lu,shift:Uu},{key:"Alt-ArrowUp",run:cd},{key:"Shift-Alt-ArrowUp",run:dd},{key:"Alt-ArrowDown",run:ud},{key:"Shift-Alt-ArrowDown",run:pd},{key:"Mod-Alt-ArrowUp",run:id},{key:"Mod-Alt-ArrowDown",run:nd},{key:"Escape",run:sd},{key:"Mod-Enter",run:yd},{key:"Alt-l",mac:"Ctrl-l",run:ed},{key:"Mod-i",run:td,preventDefault:!0},{key:"Mod-[",run:jh},{key:"Mod-]",run:qh},{key:"Mod-Alt-\\",run:bd},{key:"Shift-Mod-k",run:gd},{key:"Shift-Mod-\\",run:Ku},{key:"Mod-/",run:du},{key:"Alt-A",run:gu},{key:"Ctrl-m",mac:"Shift-Alt-m",run:kd}].concat(wd),dp={key:"Tab",run:qh,shift:jh};class pp{constructor(e,t,i,n){this.state=e,this.pos=t,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=we(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(vd(e));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Co(s){let e=Object.keys(s).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Sd(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=Co(e)+Co(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function gp(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:Sd(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}function mp(s,e){return t=>{for(let i=we(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}function vd(s,e){var t;let{source:i}=s,n=i[i.length-1]!="$";return n?new RegExp(`(?:${i})${n?"$":""}`,(t=s.flags)!==null&&t!==void 0?t:s.ignoreCase?"i":""):s}const Ad=Ye.define(),Cd=D.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Md{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class sr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,le.TrackDel),i=e.mapPos(this.to,1,le.TrackDel);return t==null||i==null?null:new sr(this.field,t,i)}}class rr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let h of this.lines){if(i.length){let a=o,f=/^\t*/.exec(h)[0].length;for(let c=0;c<f;c++)a+=e.facet(gn);n.push(t+a.length-f),h=a+h.slice(f)}i.push(h),t+=h.length+1}let l=this.fieldPositions.map(h=>new sr(h.field,n[h.line]+h.from,n[h.line]+h.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,h=r[2]||r[3]||"",a=-1;l===0&&(l=1e9);let f=h.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:f&&t[c].name==f)&&(a=c);if(a<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:f}),a=c;for(let u of n)u.field>=a&&u.field++}for(let c of n)if(c.line==i.length&&c.from>r.index){let u=r[2]?3+(r[1]||"").length:2;c.from-=u,c.to-=u}n.push(new Md(a,i.length,r.index,r.index+f.length)),o=o.slice(0,r.index)+h+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,h,a)=>{for(let f of n)f.line==i.length&&f.from>a&&(f.from--,f.to--);return h}),i.push(o)}return new rr(i,n)}}let Td=z.widget({widget:new class extends Wt{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Dd=z.mark({class:"cm-snippetField"});class Vt{constructor(e,t){this.ranges=e,this.active=t,this.deco=z.set(e.map(i=>(i.from==i.to?Td:Dd).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new Vt(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const ki=q.define({map(s,e){return s&&s.map(e)}}),Od=q.define(),pi=Je.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(ki))return t.value;if(t.is(Od)&&s)return new Vt(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>D.decorations.from(s,e=>e?e.deco:z.none)});function or(s,e){return b.create(s.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Bd(s){let e=rr.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),{main:h}=t.state.selection,a={changes:{from:n,to:r==h.from?h.to:r,insert:E.of(o)},scrollIntoView:!0,annotations:i?[Ad.of(i),_.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=or(l,0)),l.some(f=>f.field>0)){let f=new Vt(l,0),c=a.effects=[ki.of(f)];t.state.field(pi,!1)===void 0&&c.push(q.appendConfig.of([pi,Rd,Nd,Cd]))}t.dispatch(t.state.update(a))}}function Uh(s){return({state:e,dispatch:t})=>{let i=e.field(pi,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:or(i.ranges,n),effects:ki.of(r?null:new Vt(i.ranges,n)),scrollIntoView:!0})),!0}}const Pd=({state:s,dispatch:e})=>s.field(pi,!1)?(e(s.update({effects:ki.of(null)})),!0):!1,Id=Uh(1),Ed=Uh(-1),Ld=[{key:"Tab",run:Id,shift:Ed},{key:"Escape",run:Pd}],Mo=A.define({combine(s){return s.length?s[0]:Ld}}),Rd=on.highest(jl.compute([Mo],s=>s.facet(Mo)));function yp(s,e){return{...e,apply:Bd(s)}}const Nd=D.domEventHandlers({mousedown(s,e){let t=e.state.field(pi,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:or(t.ranges,n.field),effects:ki.of(t.ranges.some(r=>r.field>n.field)?new Vt(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),Gh=new class extends tt{};Gh.startSide=1;Gh.endSide=-1;var To={};class sn{constructor(e,t,i,n,r,o,l,h,a,f=0,c){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new sn(e,[],t,i,i,0,[],0,n?new Do(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let h=this.stack.length-(i-1)*3-(e&262144?6:0),a=h?this.stack[h-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let f=this.reducePos-a;f>=2e3&&!(!((t=this.p.parser.nodeSet.types[n])===null||t===void 0)&&t.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=f):this.p.lastBigReductionSize<f&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=f));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,a,d,u+4,!0)}if(e&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(n,a)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(t==i)return;if(this.buffer[o-2]>=t){this.buffer[o-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(e,t,i,n){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=n;let l=o.stateFlag(r,1);!l&&(n>i||t<=o.maxNode)&&(this.reducePos=n),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,n,4)}else this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4)}apply(e,t,i,n){e&65536?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(t&&e.buffer[t-4]==0&&(t-=4);t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new sn(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Fd(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&n.push(t[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<t.length;r+=2){let o=t[r+1];n.some((l,h)=>h&1&&l==o)||n.push(t[r],o)}t=n}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let r=t[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let h=o&65535,a=this.stack.length-l*3;if(a>=0&&e.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new Do(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class Do{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class Fd{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class rn{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new rn(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new rn(this.stack,this.pos,this.index)}}function Yt(s,e=Uint16Array){if(typeof s!="string")return s;let t=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),r+=h,l)break;r*=46}t?t[n++]=r:t=new e(r)}return t}class $i{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const Oo=new $i;class Wd{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Oo,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,n;if(t>=0&&t<this.chunk.length)i=this.pos+e,n=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=Oo,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class Bt{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;Jh(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}Bt.prototype.contextual=Bt.prototype.fallback=Bt.prototype.extend=!1;class Hd{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data=typeof e=="string"?Yt(e):e}token(e,t){let i=e.pos,n=0;for(;;){let r=e.next<0,o=e.resolveOffset(1,1);if(Jh(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(this.elseToken==null)return;if(r||n++,o==null)break;e.reset(o,e.token)}n&&(e.reset(i,e.token),e.acceptToken(this.elseToken,n))}}Hd.prototype.contextual=Bt.prototype.fallback=Bt.prototype.extend=!1;class bp{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function Jh(s,e,t,i,n,r){let o=0,l=1<<i,{dialect:h}=t.p.parser;e:for(;(l&s[o])!=0;){let a=s[o+1];for(let d=o+3;d<a;d+=2)if((s[d+1]&l)>0){let p=s[d];if(h.allows(p)&&(e.token.value==-1||e.token.value==p||Vd(p,e.token.value,n,r))){e.acceptToken(p);break}}let f=e.next,c=0,u=s[o+2];if(e.next<0&&u>c&&s[a+u*3-3]==65535){o=s[a+u*3-1];continue e}for(;c<u;){let d=c+u>>1,p=a+d+(d<<1),g=s[p],m=s[p+1]||65536;if(f<g)u=d;else if(f>=m)c=d+1;else{o=s[p+2],e.advance();continue e}}break}}function Bo(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function Vd(s,e,t,i){let n=Bo(t,i,e);return n<0||Bo(t,i,s)<n}const de=typeof process<"u"&&To&&/\bparse\b/.test(To.LOG);let Kn=null;function Po(s,e,t){let i=s.cursor(F.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(s.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:s.length}}class zd{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Po(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Po(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[t]+i.positions[n];if(o>e)return this.nextStart=o,null;if(r instanceof R){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let h=r.prop(B.lookAhead);if(!h||l+h<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class Kd{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new $i)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,o=n.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,h=0;for(let a=0;a<r.length;a++){if((1<<a&o)==0)continue;let f=r[a],c=this.tokens[a];if(!(i&&!f.fallback)&&((f.contextual||c.start!=e.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,f,e),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=t;if(c.extended>-1&&(t=this.addActions(e,c.extended,c.end,t)),t=this.addActions(e,c.value,c.end,t),!f.extend&&(i=c,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return h&&e.setLookAhead(h),!i&&e.pos==this.stream.end&&(i=new $i,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new $i,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let h=0;h<2;h++)for(let a=o.stateSlot(r,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=ze(l,a+2);else{n==0&&l[a+1]==2&&(n=this.putAction(ze(l,a+2),t,i,n));break}l[a]==t&&(n=this.putAction(ze(l,a+1),t,i,n))}return n}}class $d{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Wd(t,n),this.tokens=new Kd(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[sn.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new zd(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{n||(n=[],r=[]),n.push(l);let h=this.tokens.getMainToken(l);r.push(h.value,h.end)}}break}}if(!i.length){let o=n&&jd(n);if(o)return de&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw de&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return de&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let a=i[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this,o=de?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let a=e.curContext&&e.curContext.tracker.strict,f=a?e.curContext.hash:0;for(let c=this.fragments.nodeAt(n);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?r.getGoto(e.state,c.type.id):-1;if(u>-1&&c.length&&(!a||(c.prop(B.contextHash)||0)==f))return e.useNode(c,u),de&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof R)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof R&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),de&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let h=this.tokens.getActions(e);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],u=h[a++],d=a==h.length||!i,p=d?e:e.split(),g=this.tokens.mainToken;if(p.apply(f,c,g?g.start:p.pos,u),de&&console.log(o+this.stackID(p)+` (via ${(f&65536)==0?"shift":`reduce of ${r.getName(f&65535)}`} for ${r.getName(c)} @ ${n}${p==e?"":", split"})`),d)return!0;p.pos>n?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return Io(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],h=t[o<<1],a=t[(o<<1)+1],f=de?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),de&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=f;for(let d=0;d<10&&c.forceReduce()&&(de&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)de&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))de&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),de&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Io(l,i)):(!n||n.score<c.score)&&(n=c)}return n}stackToTree(e){return e.close(),R.build({buffer:rn.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Kn||(Kn=new WeakMap)).get(e);return t||Kn.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function Io(s,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==s.pos&&i.sameState(s)){e[t].score<s.score&&(e[t]=s);return}}e.push(s)}class qd{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}const $n=s=>s;class kp{constructor(e){this.start=e.start,this.shift=e.shift||$n,this.reduce=e.reduce||$n,this.reuse=e.reuse||$n,this.hash=e.hash||(()=>0),this.strict=e.strict!==!1}}class Is extends _s{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),n=[];for(let l=0;l<t.length;l++)n.push([]);function r(l,h,a){n[l].push([h,h.deserialize(String(a))])}if(e.nodeProps)for(let l of e.nodeProps){let h=l[0];typeof h=="string"&&(h=B[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)r(f,h,l[a++]);else{let c=l[a+-f];for(let u=-f;u>0;u--)r(l[a++],h,c);a++}}}this.nodeSet=new pn(t.map((l,h)=>se.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:n[h],top:i.indexOf(h)>-1,error:h==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(h)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Gl;let o=Yt(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Eo),this.states=Yt(e.states,Uint32Array),this.data=Yt(e.stateData),this.goto=Yt(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new Bt(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new $d(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let o=n[r++],l=o&1,h=n[r++];if(l&&i)return h;for(let a=r+(o>>1);r<a;r++)if(n[r]==e)return h;if(l)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(e,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=ze(i,r+2)];else{if(i[r+1]==2)return ze(i,r+2);break}if(o==t||o==0)return ze(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=ze(this.data,r+2);else break;n=t(ze(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=ze(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];t.some((r,o)=>o&1&&r==n)||t.push(this.data[i],n)}}return t}configure(e){let t=Object.assign(Object.create(Is.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let n=e.tokenizers.find(r=>r.from==i);return n?n.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=Eo(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new qd(e,i,n)}static deserialize(e){return new Is(e)}}function ze(s,e){return s[e]|s[e+1]<<16}function jd(s){let e=null;for(let t of s){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Eo(s){if(s.external){let e=s.extend?1:0;return(t,i)=>s.external(t,i)<<1|e}return s.get}export{Jd as $,jl as A,hn as B,kp as C,sp as D,bp as E,ke as F,gn as G,pp as H,F as I,N as J,pt as K,Is as L,th as M,se as N,Rt as O,_s as P,ln as Q,fp as R,np as S,me as T,lp as U,Gd as V,cp as W,up as X,Ao as Y,dp as Z,hp as _,B as a,lh as a0,pn as b,R as c,Hd as d,As as e,ip as f,rp as g,op as h,ih as i,Zd as j,we as k,Yd as l,Kc as m,tp as n,ep as o,_d as p,mp as q,gp as r,Fc as s,w as t,Zl as u,yp as v,D as w,b as x,nu as y,on as z};