import{r as En,j as ye,u as zh,b as $h}from"./vendor-BKmmeuxg.js";import{I as Fh}from"./input-error-LaPr_4wd.js";import{L as Vh}from"./loading-button-BnTVAMJ7.js";import{C as Wh,a as Hh,c as Xh,d as qh,b as jh}from"./card-D9_SJYq6.js";import{S as Yh}from"./separator-_3LZ_wAA.js";import"./utils-DxSsnXxD.js";import"./button-BpNwv2aE.js";import"./index-WW_1X1qx.js";let os=[],hl=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e>1;if(s=hl[i])e=i+1;else return!0;if(e==t)return!1}}function Cr(s){return s>=127462&&s<=127487}const Ar=8205;function Uh(s,e,t=!0,i=!0){return(t?fl:Kh)(s,e,i)}function fl(s,e,t){if(e==s.length)return e;e&&cl(s.charCodeAt(e))&&ul(s.charCodeAt(e-1))&&e--;let i=Ln(s,e);for(e+=Pr(i);e=0&&Cr(Ln(s,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Kh(s,e,t){for(;e>0;){let i=fl(s,e-2,t);if(i=56320&&s<57344}function ul(s){return s>=55296&&s<56320}function Pr(s){return s<65536?1:2}class E{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=zt(this,e,t);let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),Ve.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=zt(this,e,t);let i=[];return this.decompose(e,t,i,0),Ve.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new ti(this),r=new ti(e);for(let o=t,l=t;;){if(n.next(o),r.next(o),o=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(e=1){return new ti(this,e)}iterRange(e,t=this.length){return new dl(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new pl(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?E.empty:e.length<=32?new j(e):Ve.from(j.split(e,[]))}}class j extends E{constructor(e,t=_h(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((t?i:l)>=e)return new Zh(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new j(Qr(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=qi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new j(l,o.length+r.length));else{let a=l.length>>1;i.push(new j(l.slice(0,a)),new j(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof j))return super.replace(e,t,i);[e,t]=zt(this,e,t);let n=qi(this.text,qi(i.text,Qr(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new j(n,r):Ve.from(j.split(n,[]),r)}sliceString(e,t=this.length,i=` `){[e,t]=zt(this,e,t);let n="";for(let r=0,o=0;r<=t&&oe&&o&&(n+=i),er&&(n+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,i.length==32&&(t.push(new j(i,n)),i=[],n=-1);return n>-1&&t.push(new j(i,n)),t}}class Ve extends E{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,n);n=l+1,i=a+1}}decompose(e,t,i,n){for(let r=0,o=0;o<=t&&r=o){let f=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!f?i.push(l):l.decompose(e-o,t-o,i,f)}o=a+1}}replace(e,t,i){if([e,t]=zt(this,e,t),i.lines=r&&t<=l){let a=o.replace(e-r,t-r,i),f=this.lines-o.lines+a.lines;if(a.lines>4&&a.lines>f>>6){let h=this.children.slice();return h[n]=a,new Ve(h,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=` `){[e,t]=zt(this,e,t);let n="";for(let r=0,o=0;re&&r&&(n+=i),eo&&(n+=l.sliceString(e-o,t-o,i)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Ve))return 0;let i=0,[n,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,r+=t){if(n==o||r==l)return i;let a=this.children[n],f=e.children[r];if(a!=f)return i+a.scanIdentical(f,t);i+=a.length+1}}static from(e,t=e.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new j(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,f=-1,h=[];function c(d){let p;if(d.lines>r&&d instanceof Ve)for(let g of d.children)c(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof j&&a&&(p=h[h.length-1])instanceof j&&d.lines+p.lines<=32?(a+=d.lines,f+=d.length+1,h[h.length-1]=new j(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,f+=d.length+1,h.push(d))}function u(){a!=0&&(l.push(h.length==1?h[0]:Ve.from(h,f)),f=-1,a=h.length=0)}for(let d of e)c(d);return u(),l.length==1?l[0]:new Ve(l,t)}}E.empty=new j([""],0);function _h(s){let e=-1;for(let t of s)e+=t.length+1;return e}function qi(s,e,t=0,i=1e9){for(let n=0,r=0,o=!0;r=t&&(a>i&&(l=l.slice(0,i-n)),n0?1:(e instanceof j?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],o=r>>1,l=n instanceof j?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=` `,this;e--}else if(n instanceof j){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof j?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class dl{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ti(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 pl{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()},ti.prototype[Symbol.iterator]=dl.prototype[Symbol.iterator]=pl.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 zt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function ae(s,e,t=!0,i=!0){return Uh(s,e,t,i)}function Jh(s){return s>=56320&&s<57344}function ef(s){return s>=55296&&s<56320}function be(s,e){let t=s.charCodeAt(e);if(!ef(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return Jh(i)?(t-55296<<10)+(i-56320)+65536:t}function Us(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function We(s){return s<65536?1:2}const ls=/\r\n?|\n/;var ce=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(ce||(ce={}));class Ye{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return r+(e-n);r+=l}else{if(i!=ce.Simple&&f>=e&&(i==ce.TrackDel&&ne||i==ce.TrackBefore&&ne))return null;if(f>e||f==e&&t<0&&!l)return e==n||t<0?r:r+a;r+=a}n=f}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=0&&n<=t&&l>=e)return nt?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t=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 Ye(e)}static create(e){return new Ye(e)}}class K extends Ye{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 as(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return hs(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length0&&ot(i,t,r.text),r.forward(h),l+=h}let f=e[o++];for(;l>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(h=!1){if(!h&&!n.length)return;ou||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||ls)):d:E.empty,g=p.length;if(c==u&&g==0)return;co&&ne(n,c-o,-1),ne(n,u-c,g),ot(r,n,p),o=u}}return f(e),a(!l),l}static empty(e){return new K(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;nl&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length=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 ot(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];e(n,f,r,h,c),n=f,r=h}}}function hs(s,e,t,i=!1){let n=[],r=i?[]:null,o=new oi(s),l=new oi(e);for(let a=-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 f=Math.min(o.len,l.len);ne(n,f,-1),o.forward(f),l.forward(f)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len=0&&a=0){let f=0,h=o.len;for(;h;)if(l.ins==-1){let c=Math.min(h,l.len);f+=c,h-=c,l.forward(c)}else if(l.ins==0&&l.lena||o.ins>=0&&o.len>a)&&(l||i.length>f),r.forward2(a),o.forward(a)}}}}class oi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>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 xt{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 xt(i,n,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return O.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return O.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return O.range(e.anchor,e.head)}static create(e,t,i){return new xt(e,t,i)}}class O{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:O.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;ie.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 O(e.ranges.map(t=>xt.fromJSON(t)),e.main)}static single(e,t=e){return new O([O.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;ne?8:0)|r)}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;nr.head?O.range(a,l):O.range(l,a))}}return new O(e,t)}}function ml(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Ks=0;class Q{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=Ks++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new Q(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:_s),!!e.static,e.enables)}of(e){return new ji([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ji(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ji(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function _s(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class ji{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=Ks++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,f=!1,h=[];for(let c of this.dependencies)c=="doc"?a=!0:c=="selection"?f=!0:(((t=e[c.id])!==null&&t!==void 0?t:1)&1)==0&&h.push(e[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(a&&u.docChanged||f&&(u.docChanged||u.selection)||fs(c,h)){let d=i(c);if(l?!Mr(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=nn(u,p);if(this.dependencies.every(m=>m instanceof Q?u.facet(m)===c.facet(m):m instanceof Re?u.field(m,!1)==c.field(m,!1):!0)||(l?Mr(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 Mr(s,e,t){if(s.length!=e.length)return!1;for(let i=0;is[a.id]),n=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=s[e.id]>>1;function l(a){let f=[];for(let h=0;hi===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ai).find(i=>i.field==this);return((t==null?void 0: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(Ai),o=n.facet(Ai),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.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,Ai.of({field:this,create:e})]}get extension(){return this}}const bt={lowest:4,low:3,default:2,high:1,highest:0};function jt(s){return e=>new yl(e,s)}const Oi={highest:jt(bt.highest),high:jt(bt.high),default:jt(bt.default),low:jt(bt.low),lowest:jt(bt.lowest)};class yl{constructor(e,t){this.inner=e,this.prec=t}}class kn{of(e){return new cs(this,e)}reconfigure(e){return kn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class cs{constructor(e,t){this.compartment=e,this.inner=t}}class tn{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>1]}static resolve(e,t,i){let n=[],r=Object.create(null),o=new Map;for(let u of nf(e,t,o))u instanceof Re?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],f=[];for(let u of n)l[u.id]=f.length<<1,f.push(d=>u.slot(d));let h=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=h&&h[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=a.length<<1|1,_s(g,d))a.push(i.facet(p));else{let m=p.combine(d.map(y=>y.value));a.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=a.length<<1|1,a.push(m.value)):(l[m.id]=f.length<<1,f.push(y=>m.dynamicSlot(y)));l[p.id]=f.length<<1,f.push(m=>tf(m,p,d))}}let c=f.map(u=>u(l));return new tn(e,o,c,l,a,r)}}function nf(s,e,t){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let f=i[a].indexOf(o);f>-1&&i[a].splice(f,1),o instanceof cs&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let f of o)r(f,l);else if(o instanceof cs){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let f=e.get(o.compartment)||o.inner;t.set(o.compartment,f),r(f,l)}else if(o instanceof yl)r(o.inner,o.prec);else if(o instanceof Re)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof ji)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,bt.default);else{let f=o.extension;if(!f)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(f,l)}}return r(s,bt.default),i.reduce((o,l)=>o.concat(l))}function ii(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 nn(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const Ol=Q.define(),us=Q.define({combine:s=>s.some(e=>e),static:!0}),bl=Q.define({combine:s=>s.length?s[0]:void 0,static:!0}),xl=Q.define(),kl=Q.define(),wl=Q.define(),Sl=Q.define({combine:s=>s.length?s[0]:!1});class tt{constructor(e,t){this.type=e,this.value=t}static define(){return new sf}}class sf{of(e){return new tt(this,e)}}class rf{constructor(e){this.map=e}of(e){return new V(this,e)}}class V{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 V(this.type,t)}is(e){return this.type==e}static define(e={}){return new rf(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}}V.reconfigure=V.define();V.appendConfig=V.define();class Z{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&&ml(i,t.newLength),r.some(l=>l.type==Z.time)||(this.annotations=r.concat(Z.time.of(Date.now())))}static create(e,t,i,n,r,o){return new Z(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(Z.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Z.time=tt.define();Z.userEvent=tt.define();Z.addToHistory=tt.define();Z.remote=tt.define();function of(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i=s[i]))r=s[i++],o=s[i++];else if(n=0;n--){let r=i[n](s);r instanceof Z?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Z?s=r[0]:s=Cl(e,Rt(r),!1)}return s}function af(s){let e=s.startState,t=e.facet(wl),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=vl(i,ds(e,r,s.changes.newLength),!0))}return i==s?s:Z.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const hf=[];function Rt(s){return s==null?hf:Array.isArray(s)?s:[s]}var re=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(re||(re={}));const ff=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let ps;try{ps=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function cf(s){if(ps)return ps.test(s);for(let e=0;e"€"&&(t.toUpperCase()!=t.toLowerCase()||ff.test(t)))return!0}return!1}function uf(s){return e=>{if(!/\S/.test(e))return re.Space;if(cf(e))return re.Word;for(let t=0;t-1)return re.Word;return re.Other}}class I{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;ln.set(f,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(V.reconfigure)?(t=null,i=l.value):l.is(V.appendConfig)&&(t=null,i=Rt(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=tn.resolve(i,n,this),r=new I(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,f)=>f.reconfigure(a,this),null).values);let o=e.startState.facet(us)?e.newSelection:e.newSelection.asSingle();new I(t,e.newDoc,o,r,(l,a)=>a.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:O.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=Rt(i.effects);for(let l=1;lo.spec.fromJSON(l,a)))}}return I.create({doc:e.doc,selection:O.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=tn.resolve(e.extensions||[],new Map),i=e.doc instanceof E?e.doc:E.of((e.doc||"").split(t.staticFacet(I.lineSeparator)||ls)),n=e.selection?e.selection instanceof O?e.selection:O.single(e.selection.anchor,e.selection.head):O.single(0);return ml(n,i.length),t.staticFacet(us)||(n=n.asSingle()),new I(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(I.tabSize)}get lineBreak(){return this.facet(I.lineSeparator)||` `}get readOnly(){return this.facet(Sl)}phrase(e,...t){for(let i of this.facet(I.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(Ol))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){return uf(this.languageDataAt("wordChars",e).join(""))}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 a=ae(t,o,!1);if(r(t.slice(a,o))!=re.Word)break;o=a}for(;ls.length?s[0]:4});I.lineSeparator=bl;I.readOnly=Sl;I.phrases=Q.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])}});I.languageData=Ol;I.changeFilter=xl;I.transactionFilter=kl;I.transactionExtender=wl;kn.reconfigure=V.define();function bi(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 vt{eq(e){return this==e}range(e,t=e){return gs.create(e,t,this)}}vt.prototype.startSide=vt.prototype.endSide=0;vt.prototype.point=!1;vt.prototype.mapMode=ce.TrackDel;let gs=class Al{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Al(e,t,i)}};function ms(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class Zs{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 a=o+l>>1,f=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return f>=0?o:l;f>=0?l=a:o=a+1}}between(e,t,i,n){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);rd||u==d&&f.startSide>0&&f.endSide<=0)continue;(d-u||f.endSide-f.startSide)<0||(o<0&&(o=u),f.point&&(l=Math.max(l,d-u)),i.push(f),n.push(u-o),r.push(d-o))}return{mapped:i.length?new Zs(n,r,i,l):null,pos:o}}}class N{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 N(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(ms)),this.isEmpty)return t.length?N.of(t):this;let l=new Pl(this,null,-1).goto(0),a=0,f=[],h=new li;for(;l.value||a=0){let c=t[a++];h.addInner(c.from,c.to,c.value)||f.push(c)}else l.rangeIndex==1&&l.chunkIndexthis.chunkEnd(l.chunkIndex)||rl.to||r=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 ai.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return ai.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),a=Tr(o,l,i),f=new Yt(o,a,r),h=new Yt(l,a,r);i.iterGaps((c,u,d)=>Dr(f,c,h,u,d,n)),i.empty&&i.length==0&&Dr(f,0,h,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Tr(r,o),a=new Yt(r,l,0).goto(i),f=new Yt(o,l,0).goto(i);for(;;){if(a.to!=f.to||!ys(a.active,f.active)||a.point&&(!f.point||!a.point.eq(f.point)))return!1;if(a.to>n)return!0;a.next(),f.next()}}static spans(e,t,i,n,r=-1){let o=new Yt(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let f=Math.min(o.to,i);if(o.point){let h=o.activeForPoint(o.to),c=o.pointFroml&&(n.span(l,f,o.active,a),a=o.openEnd(f));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new li;for(let n of e instanceof gs?[e]:t?df(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return N.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=N.empty;n=n.nextLayer)t=new N(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}N.empty=new N([],[],null,-1);function df(s){if(s.length>1)for(let e=s[0],t=1;t0)return s.slice().sort(ms);e=i}return s}N.empty.nextLayer=N.empty;class li{finishChunk(e){this.chunks.push(new Zs(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 li)).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(N.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=N.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Tr(s,e,t){let i=new Map;for(let r of s)for(let o=0;o=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new Pl(o,t,i,r));return n.length==1?n[0]:new ai(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--)Nn(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--)Nn(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(),Nn(this.heap,0)}}}function Nn(s,e){for(let t=s[e];;){let i=(e<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1=0&&(n=s[i+1],i++),t.compare(n)<0)break;s[i]=t,s[e]=n,e=i}}class Yt{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=ai.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){Pi(this.active,e),Pi(this.activeTo,e),Pi(this.activeRank,e),this.minActive=Br(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t0;)t++;Qi(this.active,t,i),Qi(this.activeTo,t,n),Qi(this.activeRank,t,r),e&&Qi(e,t,this.cursor.from),this.minActive=Br(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&&Pi(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=0&&i[n]=0&&!(this.activeRank[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 Dr(s,e,t,i,n,r){s.goto(e),t.goto(i);let o=i+n,l=i,a=i-e;for(;;){let f=s.to+a-t.to,h=f||s.endSide-t.endSide,c=h<0?s.to+a:t.to,u=Math.min(c,o);if(s.point||t.point?s.point&&t.point&&(s.point==t.point||s.point.eq(t.point))&&ys(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,u,s.point,t.point):u>l&&!ys(s.active,t.active)&&r.compareRange(l,u,s.active,t.active),c>o)break;(f||s.openEnd!=t.openEnd)&&r.boundChange&&r.boundChange(c),l=c,h<=0&&s.next(),h>=0&&t.next()}}function ys(s,e){if(s.length!=e.length)return!1;for(let t=0;t=e;i--)s[i+1]=s[i];s[e]=t}function Br(s,e){let t=-1,i=1e9;for(let n=0;n=e)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?t-r%t:1,n=ae(s,n)}return s.length}const Os="ͼ",Rr=typeof Symbol>"u"?"__"+Os:Symbol.for(Os),bs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Er=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class ht{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,f){let h=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return a.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,a);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,h,u)}else p!=null&&h.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(h.length||u)&&a.push((i&&!c&&!f?o.map(i):o).join(", ")+" {"+h.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(` `)}static newName(){let e=Er[Rr]||1;return Er[Rr]=e+1,Os+e.toString(36)}static mount(e,t,i){let n=e[bs],r=i&&i.nonce;n?r&&n.setNonce(r):n=new gf(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let Lr=new Map;class gf{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let r=Lr.get(i);if(r)return e[bs]=r;this.sheet=new n.CSSStyleSheet,Lr.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[bs]=this}mount(e,t){let i=this.sheet,n=0,r=0;for(let o=0;o-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let f=0;f",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},mf=typeof navigator<"u"&&/Mac/.test(navigator.platform),yf=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ie=0;ie<10;ie++)ft[48+ie]=ft[96+ie]=String(ie);for(var ie=1;ie<=24;ie++)ft[ie+111]="F"+ie;for(var ie=65;ie<=90;ie++)ft[ie]=String.fromCharCode(ie+32),hi[ie]=String.fromCharCode(ie);for(var In in ft)hi.hasOwnProperty(In)||(hi[In]=ft[In]);function Of(s){var e=mf&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||yf&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?hi:ft)[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 le=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},xs=typeof document<"u"?document:{documentElement:{style:{}}};const ks=/Edge\/(\d+)/.exec(le.userAgent),Ql=/MSIE \d/.test(le.userAgent),ws=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(le.userAgent),Sn=!!(Ql||ws||ks),Nr=!Sn&&/gecko\/(\d+)/i.test(le.userAgent),zn=!Sn&&/Chrome\/(\d+)/.exec(le.userAgent),bf="webkitFontSmoothing"in xs.documentElement.style,Ss=!Sn&&/Apple Computer/.test(le.vendor),Ir=Ss&&(/Mobile\/\w+/.test(le.userAgent)||le.maxTouchPoints>2);var C={mac:Ir||/Mac/.test(le.platform),windows:/Win/.test(le.platform),linux:/Linux|X11/.test(le.platform),ie:Sn,ie_version:Ql?xs.documentMode||6:ws?+ws[1]:ks?+ks[1]:0,gecko:Nr,gecko_version:Nr?+(/Firefox\/(\d+)/.exec(le.userAgent)||[0,0])[1]:0,chrome:!!zn,chrome_version:zn?+zn[1]:0,ios:Ir,android:/Android\b/.test(le.userAgent),webkit_version:bf?+(/\bAppleWebKit\/(\d+)/.exec(le.userAgent)||[0,0])[1]:0,safari:Ss,safari_version:Ss?+(/\bVersion\/(\d+(\.\d+)?)/.exec(le.userAgent)||[0,0])[1]:0,tabSize:xs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function fi(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function vs(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function Yi(s,e){if(!e.anchorNode)return!1;try{return vs(s,e.anchorNode)}catch{return!1}}function ci(s){return s.nodeType==3?At(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ni(s,e,t,i){return t?zr(s,e,t,i,-1)||zr(s,e,t,i,1):!1}function Ct(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function sn(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function zr(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:Ge(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=Ct(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?Ge(s):0}else return!1}}function Ge(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function vn(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function xf(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 Ml(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 kf(s,e,t,i,n,r,o,l){let a=s.ownerDocument,f=a.defaultView||window;for(let h=s,c=!1;h&&!c;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=xf(f);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(c=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let b=h.getBoundingClientRect();({scaleX:p,scaleY:g}=Ml(h,b)),u={left:b.left,right:b.left+h.clientWidth*p,top:b.top,bottom:b.top+h.clientHeight*g}}let m=0,y=0;if(n=="nearest")e.top0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom&&(y=e.bottom-u.bottom+o,t<0&&e.top-y0&&e.right>u.right+m&&(m=e.right-u.right+r)):e.right>u.right&&(m=e.right-u.right+r,t<0&&e.leftu.bottom||e.leftu.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)}),h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function wf(s){let e=s.ownerDocument,t,i;for(let n=s.parentNode;n&&!(n==e.body||t&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!t&&n.scrollWidth>n.clientWidth&&(t=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:t,y:i}}class Sf{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?Ge(t):0),i,Math.min(e.focusOffset,i?Ge(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let Ot=null;C.safari&&C.safari_version>=26&&(Ot=!1);function Tl(s){if(s.setActive)return s.setActive();if(Ot)return s.focus(Ot);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(Ot==null?{get preventScroll(){return Ot={preventScroll:!0},!0}}:void 0),!Ot){Ot=!1;for(let t=0;tMath.max(1,s.scrollHeight-s.clientHeight-4)}function Rl(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=Ge(t)}else if(t.parentNode&&!sn(t))i=Ct(t),t=t.parentNode;else return null}}function El(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&it)return c.domBoundsAround(e,t,f);if(u>=e&&n==-1&&(n=a,r=f),f>t&&c.dom.parentNode==this.dom){o=a,l=h;break}h=u,f=u+c.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=Js){this.markDirty();for(let n=e;nthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Nl(s,e,t,i,n,r,o,l,a){let{children:f}=s,h=f.length?f[e]:null,c=r.length?r[r.length-1]:null,u=c?c.breakAfter:o;if(!(e==i&&h&&!o&&!u&&r.length<2&&h.merge(t,n,r.length?c:null,t==0,l,a))){if(i0&&(!o&&r.length&&h.merge(t,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(tAf||i.flags&8)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new De(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new se(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return Pf(this.dom,e,t)}}class et extends z{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let n of t)n.setParent(this)}setAttrs(e){if(Dl(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,i,n,r,o){return i&&(!(i instanceof et&&i.mark.eq(this.mark))||e&&r<=0||te&&t.push(i=e&&(n=r),i=a,r++}let o=this.length-e;return this.length=e,n>-1&&(this.children.length=n,this.markDirty()),new et(this.mark,t,o)}domAtPos(e){return zl(this,e)}coordsAt(e,t){return Fl(this,e,t)}}function Pf(s,e,t){let i=s.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?C.chrome||C.gecko||(e?(n--,o=1):r=0)?0:l.length-1];return C.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,f=>f.width)||a),o?vn(a,o<0):a||null}class lt extends z{static create(e,t,i){return new lt(e,t,i)}constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}split(e){let t=lt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,i,n,r,o){return i&&(!(i instanceof lt)||!this.widget.compare(i.widget)||e>0&&r<=0||t0)?se.before(this.dom):se.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?n.length-1:0;r=n[l],!(e>0?l==0:l==n.length-1||r.top0?se.before(this.dom):se.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return E.empty}get isHidden(){return!0}}De.prototype.children=lt.prototype.children=$t.prototype.children=Js;function zl(s,e){let t=s.dom,{children:i}=s,n=0;for(let r=0;nr&&e0;r--){let o=i[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=n;r0&&e instanceof et&&n.length&&(i=n[n.length-1])instanceof et&&i.mark.eq(e.mark)?$l(i,e.children[0],t-1):(n.push(e),e.setParent(s)),s.length+=e.length}function Fl(s,e,t){let i=null,n=-1,r=null,o=-1;function l(f,h){for(let c=0,u=0;c=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&(t>0||Mf(r,d)))&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u-1?1:0)!=n.length-(t&&n.indexOf(t)>-1?1:0))return!1;for(let r of i)if(r!=t&&(n.indexOf(r)==-1||s[r]!==e[r]))return!1;return!0}function As(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 Tf(s){let e=Object.create(null);for(let t=0;t0?3e8:-4e8:t>0?1e8:-1e8,new ct(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}=Vl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new ct(e,i,n,t,e.widget||null,!0)}static line(e){return new ki(e)}static set(e,t=!1){return N.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}R.none=N.empty;class xi extends R{constructor(e){let{start:t,end:i}=Vl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,i;return this==e||e instanceof xi&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((i=e.attrs)===null||i===void 0?void 0:i.class))&&rn(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}xi.prototype.point=!1;class ki extends R{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof ki&&this.spec.class==e.spec.class&&rn(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)}}ki.prototype.mapMode=ce.TrackBefore;ki.prototype.point=!0;class ct extends R{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?ce.TrackBefore:ce.TrackAfter:ce.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 ct&&Df(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)}}ct.prototype.point=!0;function Vl(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 Df(s,e){return s==e||!!(s&&e&&s.compare(e))}function Gi(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 G extends z{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,n,r,o){if(i){if(!(i instanceof G))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Il(this,e,t,i?i.children.slice():[],r,o),!0}split(e){let t=new G;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:n}=this.childPos(e);n&&(t.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let r=i;r0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){rn(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){$l(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=Cs(t,this.attrs||{})),i&&(this.attrs=Cs({class:i},this.attrs||{}))}domAtPos(e){return zl(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var i;this.dom?this.flags&4&&(Dl(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(As(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let n=this.dom.lastChild;for(;n&&z.get(n)instanceof et;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=z.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!C.ios||!this.children.some(r=>r instanceof De))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let i of this.children){if(!(i instanceof De)||/[^ -~]/.test(i.text))return null;let n=ci(i.dom);if(n.length!=1)return null;e+=n[0].width,t=n[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let i=Fl(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:n}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-n.lineHeight)<2&&n.textHeight=t){if(r instanceof G)return r;if(o>t)break}n=o+r.breakAfter}return null}}class Je extends z{constructor(e,t,i){super(),this.widget=e,this.length=t,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,n,r,o){return i&&(!(i instanceof Je)||!this.widget.compare(i.widget)||e>0&&r<=0||t0}}class Ps extends er{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}}class si{constructor(e,t,i,n){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof Je&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new G),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Mi(new $t(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof Je)&&this.getLine()}buildText(e,t,i){for(;e>0;){if(this.textOff==this.text.length){let{value:o,lineBreak:l,done:a}=this.cursor.next(this.skip);if(this.skip=0,a)throw new Error("Ran out of text content when drawing inline views");if(l){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=o,this.textOff=0}let n=Math.min(this.text.length-this.textOff,e),r=Math.min(n,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(Mi(new De(this.text.slice(this.textOff,this.textOff+r)),t),i),this.atCursorPos=!0,this.textOff+=r,e-=r,i=n<=r?0:t.length}}span(e,t,i,n){this.buildText(t-e,i,n),this.pos=t,this.openStart<0&&(this.openStart=n)}point(e,t,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ct){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof ct)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Je(i.widget||Ft.block,l,i));else{let a=lt.create(i.widget||Ft.inline,l,l?0:i.startSide),f=this.atCursorPos&&!a.isEditable&&r<=n.length&&(e0),h=!a.isEditable&&(en.length||i.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!f&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),f&&(c.append(Mi(new $t(1),n),r),r=n.length+Math.max(0,r-n.length)),c.append(Mi(a,n),r),this.atCursorPos=h,this.pendingBuffer=h?en.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,i,n,r){let o=new si(e,t,i,r);return o.openEnd=N.spans(n,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Mi(s,e){for(let t of e)s=new et(t,[s],s.length);return s}class Ft extends er{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}}Ft.inline=new Ft("span");Ft.block=new Ft("div");var Y=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(Y||(Y={}));const Pt=Y.LTR,tr=Y.RTL;function Wl(s){let e=[];for(let t=0;t=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.fromt:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Xl(s,e){if(s.length!=e.length)return!1;for(let t=0;t=0;g-=3)if(Ie[g+1]==-d){let m=Ie[g+2],y=m&2?n:m&4?m&1?r:n:0;y&&($[c]=$[Ie[g]]=y),l=g;break}}else{if(Ie.length==189)break;Ie[l++]=c,Ie[l++]=u,Ie[l++]=a}else if((p=$[c])==2||p==1){let g=p==n;a=g?0:1;for(let m=l-3;m>=0;m-=3){let y=Ie[m+2];if(y&2)break;if(g)Ie[m+2]|=2;else{if(y&4)break;Ie[m+2]|=4}}}}}function If(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=na;)p==m&&(p=t[--g].from,m=g?t[g-1].to:s),$[--p]=d;a=h}else r=f,a++}}}function Ms(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=e,f=0;aa&&o.push(new at(a,g.from,d));let m=g.direction==Pt!=!(d%2);Ts(s,m?i+1:i,n,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==t||(h?$[p]!=l:$[p]==l))break;p++}u?Ms(s,a,p,i+1,n,u,o):ae;){let h=!0,c=!1;if(!f||a>r[f-1].to){let g=$[a-1];g!=l&&(h=!1,c=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(f&&p==r[f-1].to){if(c)break e;let g=r[--f];if(!h)for(let m=g.from,y=f;;){if(m==e)break e;if(y&&r[y-1].to==m)m=r[--y].from;else{if($[m-1]==l)break e;break}}if(u)u.push(g);else{g.to$.length;)$[$.length]=256;let i=[],n=e==Pt?0:1;return Ts(s,n,n,t,0,s.length,i),i}function ql(s){return[new at(0,s,0)]}let jl="";function $f(s,e,t,i,n){var r;let o=i.head-s.from,l=at.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],f=a.side(n,t);if(o==f){let u=l+=n?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!n,t),f=a.side(n,t)}let h=ae(s.text,o,a.forward(n,t));(ha.to)&&(h=f),jl=s.text.slice(Math.min(o,h),Math.max(o,h));let c=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return c&&h==f&&c.level+(n?0:1)s.some(e=>e)}),Vf=Q.define({combine:s=>s.some(e=>e)}),ea=Q.define();class Lt{constructor(e,t="nearest",i="nearest",n=5,r=5,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 Lt(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 Lt(O.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ti=V.define({map:(s,e)=>s.map(e)}),ta=V.define();function xe(s,e,t){let i=s.facet(Kl);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 Ze=Q.define({combine:s=>s.length?s[0]:!0});let Wf=0;const Mt=Q.define({combine(s){return s.filter((e,t)=>{for(let i=0;i{let a=[];return o&&a.push(ui.of(f=>{let h=f.plugin(l);return h?o(h):R.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return Pe.define((i,n)=>new e(i,n),t)}}class $n{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(xe(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){xe(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){xe(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const ia=Q.define(),sr=Q.define(),ui=Q.define(),na=Q.define(),wi=Q.define(),sa=Q.define();function Wr(s,e){let t=s.state.facet(sa);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return N.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let f=r-e.from,h=o-e.from,c=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Ff(e.text,f,h)),a>0&&c.length&&(p=c[c.length-1]).to==f&&p.direction==d)p.to=h,c=p.inner;else{let g={from:f,to:h,direction:d,inner:[]};c.push(g),c=g.inner}}}}),n}const ra=Q.define();function rr(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(ra)){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 _t=Q.define();class Ae{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Ae(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.toAh)break;r+=2}if(!a)return i;new Ae(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class on{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=K.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,a)=>n.push(new Ae(r,o,l,a))),this.changedRanges=n}static create(e,t,i){return new on(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}}class Hr extends z{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=R.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.setDOM(e.contentDOM),this.children=[new G],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ae(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:h})=>hthis.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:!Uf(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Xf(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:f,to:h}=this.hasComposition;i=new Ae(f,h,e.changes.mapPos(f,-1),e.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(C.ie||C.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=Yf(o,l,e.changes);return i=Ae.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=C.chrome||C.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to=0?n[o]:null;if(!l)break;let{fromA:a,toA:f,fromB:h,toB:c}=l,u,d,p,g;if(i&&i.range.fromBh){let v=si.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),S=si.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);d=v.breakAtStart,p=v.openStart,g=S.openEnd;let P=this.compositionView(i);S.breakAtStart?P.breakAfter=1:S.content.length&&P.merge(P.length,P.length,S.content[0],!1,S.openStart,0)&&(P.breakAfter=S.content[0].breakAfter,S.content.shift()),v.content.length&&P.merge(0,0,v.content[v.content.length-1],!0,0,v.openEnd)&&v.content.pop(),u=v.content.concat(P).concat(S.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=si.build(this.view.state.doc,h,c,this.decorations,this.dynamicDecorationMap));let{i:m,off:y}=r.findPos(f,1),{i:b,off:w}=r.findPos(a,-1);Nl(this,b,w,m,y,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(ta)&&(this.editContextFormatting=i.value)}compositionView(e){let t=new De(e.text.nodeValue);t.flags|=8;for(let{deco:n}of e.marks)t=new et(n,[t],t.length);let i=new G;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=z.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(e.range.fromB,1),n=this.children[i.i];t(e.line,n);for(let r=e.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],t(r>=0?e.marks[r].node:e.text,n)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&!(this.view.state.facet(Ze)||this.dom.tabIndex>-1)&&Yi(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),f=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(C.gecko&&l.empty&&!this.hasComposition&&Hf(a)){let c=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(c,a.node.childNodes[a.offset]||null)),a=f=new se(c,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!ni(a.node,a.offset,h.anchorNode,h.anchorOffset)||!ni(f.node,f.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{C.android&&C.chrome&&this.dom.contains(h.focusNode)&&Gf(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=fi(this.view.root);if(c)if(l.empty){if(C.gecko){let u=qf(a.node,a.offset);if(u&&u!=3){let d=(u==1?Rl:El)(a.node,a.offset);d&&(a=new se(d.node,d.offset))}}c.collapse(a.node,a.offset),l.bidiLevel!=null&&c.caretBidiLevel!==void 0&&(c.caretBidiLevel=l.bidiLevel)}else if(c.extend){c.collapse(a.node,a.offset);try{c.extend(f.node,f.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,f]=[f,a]),u.setEnd(f.node,f.offset),u.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new se(h.anchorNode,h.anchorOffset),this.impreciseHead=f.precise?null:new se(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ni(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=fi(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=G.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),f=this.coordsAt(t.head,1);if(!a||!f||a.bottom>f.top)return;let h=this.domAtPos(t.head+t.assoc);i.collapse(h.node,h.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)}moveToLine(e){let t=this.dom,i;if(e.node!=t)return e;for(let n=e.offset;!i&&n=0;n--){let r=z.get(t.childNodes[n]);r instanceof G&&(i=r.domAtPos(r.length))}return i?new se(i.node,i.offset,!0):e}nearest(e){for(let t=e;t;){let i=z.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t=0;o--){let l=this.children[o],a=r-l.breakAfter,f=a-l.length;if(ae||l.covers(1))&&(!i||l instanceof G&&!(i instanceof G&&t>=0)))i=l,n=f;else if(i&&f==e&&a==e&&l instanceof Je&&Math.abs(t)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=f}return i?i.coordsAt(e-n,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),n=this.children[t];if(!(n instanceof G))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=a}if(!(n instanceof De))return null;let r=ae(n.text,i);if(r==i)return null;let o=At(n.dom,i,r).getClientRects();for(let l=0;lMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Y.LTR;for(let f=0,h=0;hn)break;if(f>=i){let d=c.dom.getBoundingClientRect();if(t.push(d.height),o){let p=c.dom.lastChild,g=p?ci(p):[];if(g.length){let m=g[g.length-1],y=a?m.right-d.left:d.right-m.left;y>l&&(l=y,this.minWidth=r,this.minWidthFrom=f,this.minWidthTo=u)}}}f=u+c.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?Y.RTL:Y.LTR}measureTextSize(){for(let r of this.children)if(r instanceof G){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,n;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=ci(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:n}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ll(this.children,e,t)}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.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(R.replace({widget:new Ps(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return R.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ui).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(na).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(N.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];et.anchor?-1:1),n;if(!i)return;!t.empty&&(n=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=rr(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;kf(this.view.scrollDOM,o,t.headn instanceof lt||n.children.some(i);return i(this.children[t])}}function Hf(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 oa(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=Rl(t.focusNode,t.focusOffset),n=El(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=z.get(n.node);if(!l||l instanceof De&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=z.get(i.node);!a||a instanceof De&&a.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 Xf(s,e,t){let i=oa(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 a=e.invertedDesc,f=new Ae(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let c=n.parentNode;;c=c.parentNode){let u=z.get(c);if(u instanceof et)h.push({node:c,deco:u.mark});else{if(u instanceof G||c.nodeName=="DIV"&&c.parentNode==s.contentDOM)return{range:f,text:n,marks:h,line:c};if(c!=s.contentDOM)h.push({node:c,deco:new xi({inclusive:!0,attributes:Tf(c),tagName:c.tagName.toLowerCase()})});else return null}}}function qf(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e{ie.from&&(t=!0)}),t}function Kf(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return O.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=ae(n.text,r,!1):l=ae(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let f=ae(n.text,o,!1);if(i(n.text.slice(f,o))!=a)break;o=f}for(;ls?e.left-s:Math.max(0,s-e.right)}function Zf(s,e){return e.top>s?e.top-s:Math.max(0,s-e.bottom)}function Fn(s,e){return s.tope.top+1}function Xr(s,e){return es.bottom?{top:s.top,left:s.left,right:s.right,bottom:e}:s}function Bs(s,e,t){let i,n,r,o,l=!1,a,f,h,c;for(let p=s.firstChild;p;p=p.nextSibling){let g=ci(p);for(let m=0;mw||o==w&&r>b)&&(i=p,n=y,r=b,o=w,l=b?e0:my.bottom&&(!h||h.bottomy.top)&&(f=p,c=y):h&&Fn(h,y)?h=qr(h,y.bottom):c&&Fn(c,y)&&(c=Xr(c,y.top))}}if(h&&h.bottom>=t?(i=a,n=h):c&&c.top<=t&&(i=f,n=c),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,e));if(i.nodeType==3)return jr(i,u,t);if(l&&i.contentEditable!="false")return Bs(i,u,t);let d=Array.prototype.indexOf.call(s.childNodes,i)+(e>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function jr(s,e,t){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;lt?h.top-t:t-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&c=(h.left+h.right)/2,d=u;if(C.chrome||C.gecko){let p=At(s,l).getBoundingClientRect();Math.abs(p.left-h.right)<.1&&(d=!u)}if(c<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=c}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function la(s,e,t,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,a,{docHeight:f}=s.viewState,{x:h,y:c}=e,u=c-l;if(u<0)return 0;if(u>f)return s.state.doc.length;for(let v=s.viewState.heightOracle.textHeight/2,S=!1;a=s.elementAtHeight(u),a.type!=Ce.Text;)for(;u=i>0?a.bottom+v:a.top-v,!(u>=0&&u<=f);){if(S)return t?null:0;S=!0,i=-i}c=l+u;let d=a.from;if(ds.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:t?null:Yr(s,o,a,h,c);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,m=g.elementFromPoint(h,c);m&&!s.contentDOM.contains(m)&&(m=null),m||(h=Math.max(o.left+1,Math.min(o.right-1,h)),m=g.elementFromPoint(h,c),m&&!s.contentDOM.contains(m)&&(m=null));let y,b=-1;if(m&&((n=s.docView.nearest(m))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let v=p.caretPositionFromPoint(h,c);v&&({offsetNode:y,offset:b}=v)}else if(p.caretRangeFromPoint){let v=p.caretRangeFromPoint(h,c);v&&({startContainer:y,startOffset:b}=v)}y&&(!s.contentDOM.contains(y)||C.safari&&Jf(y,b,h)||C.chrome&&ec(y,b,h))&&(y=void 0),y&&(b=Math.min(Ge(y),b))}if(!y||!s.docView.dom.contains(y)){let v=G.find(s.docView,d);if(!v)return u>a.top+a.height/2?a.to:a.from;({node:y,offset:b}=Bs(v.dom,h,c))}let w=s.docView.nearest(y);if(!w)return null;if(w.isWidget&&((r=w.dom)===null||r===void 0?void 0:r.nodeType)==1){let v=w.dom.getBoundingClientRect();return e.ys.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-t.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(t.from,t.to);return t.from+pf(o,r,s.state.tabSize)}function aa(s,e,t){let i,n=s;if(s.nodeType!=3||e!=(i=s.nodeValue.length))return!1;for(;;){let r=n.nextSibling;if(r){if(r.nodeName=="BR")break;return!1}else{let o=n.parentNode;if(!o||o.nodeName=="DIV")break;n=o}}return At(s,i-1,i).getBoundingClientRect().right>t}function Jf(s,e,t){return aa(s,e,t)}function ec(s,e,t){if(e!=0)return aa(s,e,t);for(let n=s;;){let r=n.parentNode;if(!r||r.nodeType!=1||r.firstChild!=n)return!1;if(r.classList.contains("cm-line"))break;n=r}let i=s.nodeType==1?s.getBoundingClientRect():At(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function tc(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.toe)return r;(!n||r.type==Ce.Text&&(n.type!=r.type||(t<0?r.frome)))&&(n=r)}}return n||i}return i}function ic(s,e,t,i){let n=tc(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),a=s.posAtCoords({x:t==(l==Y.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return O.cursor(a,t?-1:1)}return O.cursor(t?n.to:n.from,t?-1:1)}function Gr(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,a=null;;){let f=$f(n,r,o,l,t),h=jl;if(!f){if(n.number==(t?s.state.doc.lines:1))return l;h=` `,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),f=s.visualLineSide(n,!t)}if(a){if(!a(h))return l}else{if(!i)return f;a=i(h)}l=f}}function nc(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==re.Space&&(n=o),n==o}}function sc(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return O.cursor(n,e.assoc);let o=e.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),f=s.coordsAtPos(n,e.assoc||-1),h=s.documentTop;if(f)o==null&&(o=f.left-a.left),l=r<0?f.top:f.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+h}let c=a.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=la(s,{x:c,y:p},!1,r);if(pa.bottom||(r<0?gn)){let m=s.docView.coordsForChar(g),y=!m||p{if(e>r&&en(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:O.cursor(i,ir)&&!lc(o,t)&&this.lineBreak(),n=o}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 a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=z.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+(oc(e,i.node,i.offset)?t:0))}}function oc(s,e,t){for(;;){if(!e||t-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:fc(e),a=new rc(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=cc(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!vs(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),f=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!vs(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=e.viewport;if((C.ios||C.chrome)&&e.state.selection.main.empty&&a!=f&&(h.from>0||h.to-1&&e.state.selection.ranges.length>1?this.newSel=e.state.selection.replaceRange(O.range(f,a)):this.newSel=O.single(f,a)}}}function fa(s,e){let t,{newSel:i}=e,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=n.from,f=null;(r===8||C.android&&e.text.length=n.from&&t.to<=n.to&&(t.from!=n.from||t.to!=n.to)&&n.to-n.from-(t.to-t.from)<=4?t={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,t.from).append(t.insert).append(s.state.doc.slice(t.to,n.to))}:s.state.doc.lineAt(n.from).toDate.now()-50?t={from:n.from,to:n.to,insert:s.state.toText(s.inputState.insertingText)}:C.chrome&&t&&t.from==t.to&&t.from==n.head&&t.insert.toString()==` `&&s.lineWrapping&&(i&&(i=O.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:E.of([" "])}),t)return or(s,t,i,r);if(i&&!i.main.eq(n)){let o=!1,l="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(o=!0),l=s.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=ha(s.state.facet(wi).map(a=>a(s)),i))),s.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function or(s,e,t,i=-1){if(C.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(C.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&&Et(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.lengthn.head)&&Et(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&Et(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=hc(s,e,t));return s.state.facet(_l).some(a=>a(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function hc(s,e,t){let i,n=s.state,r=n.selection.main,o=-1;if(e.from==e.to&&e.fromr.to){let a=e.fromc(s)),f,a);e.from==h&&(o=h)}if(o>-1)i={changes:e,selection:O.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 a=r.frome.to?n.sliceDoc(e.to,r.to):"";i=n.replaceSelection(s.state.toText(a+e.insert.sliceString(0,void 0,s.state.lineBreak)+f))}else{let a=n.changes(e),f=t&&t.main.to<=a.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 h=s.state.sliceDoc(e.from,e.to),c,u=t&&oa(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:a,range:f||p.map(a)};let g=p.to-d,m=g-h.length;if(s.state.sliceDoc(m,g)!=h||g>=c.from&&m<=c.to)return{range:p};let y=n.changes({from:m,to:g,insert:e.insert}),b=p.to-r.to;return{changes:y,range:f?O.range(Math.max(0,f.anchor+b),Math.max(0,f.head+b)):p.map(y)}})}else i={changes:a,selection:f&&n.selection.replaceRange(f)}}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 ca(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function fc(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 Ur(t,i)),(n!=t||r!=i)&&e.push(new Ur(n,r))),e}function cc(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?O.single(t+e,i+e):null}class uc{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=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,C.safari&&e.contentDOM.addEventListener("input",()=>null),C.gecko&&Qc(e.contentDOM.ownerDocument)}handleEvent(e){!xc(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=dc(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&&da.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),C.android&&C.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return C.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=ua.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||pc.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(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.from0?!0:C.safari&&!C.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 Kr(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){xe(t.state,n)}}}function dc(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 a=r[l];a&&t(l).handlers.push(Kr(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(Kr(i.value,a))}}for(let i in Be)t(i).handlers.push(Be[i]);for(let i in Qe)t(i).observers.push(Qe[i]);return e}const ua=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],pc="dthko",da=[16,17,18,20,91,92,224,225],Di=6;function Bi(s){return Math.max(0,s)*.7+8}function gc(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class mc{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=wf(e.contentDOM),this.atoms=e.state.facet(wi).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(I.allowMultipleSelections)&&yc(e,t),this.dragging=bc(e,t)&&ma(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&&gc(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 a=rr(this.view);e.clientX-a.left<=n+Di?t=-Bi(n-e.clientX):e.clientX+a.right>=o-Di&&(t=Bi(e.clientX-o)),e.clientY-a.top<=r+Di?i=-Bi(r-e.clientY):e.clientY+a.bottom>=l-Di&&(i=Bi(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=ha(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 yc(s,e){let t=s.state.facet(Yl);return t.length?t[0](e):C.mac?e.metaKey:e.ctrlKey}function Oc(s,e){let t=s.state.facet(Gl);return t.length?t[0](e):C.mac?!e.altKey:!e.ctrlKey}function bc(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=fi(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function xc(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=z.get(t))&&i.ignoreEvent(e))return!1;return!0}const Be=Object.create(null),Qe=Object.create(null),pa=C.ie&&C.ie_version<15||C.ios&&C.webkit_version<604;function kc(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(),ga(s,t.value)},50)}function Cn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function ga(s,e){e=Cn(s.state,ir,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Rs!=null&&t.selection.ranges.every(a=>a.empty)&&Rs==r.toString()){let a=-1;i=t.changeByRange(f=>{let h=t.doc.lineAt(f.from);if(h.from==a)return{range:f};a=h.from;let c=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:c},range:O.cursor(f.from+c.length)}})}else o?i=t.changeByRange(a=>{let f=r.line(n++);return{changes:{from:a.from,to:a.to,insert:f.text},range:O.cursor(a.from+f.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Qe.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};Be.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Qe.touchstart=(s,e)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Qe.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Be.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(Ul))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=vc(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new mc(s,e,t,i)),i&&s.observer.ignore(()=>{Tl(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 _r(s,e,t,i){if(i==1)return O.cursor(e,t);if(i==2)return Kf(s.state,e,t);{let n=G.find(s.docView,e),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return le>=t.top&&e<=t.bottom&&s>=t.left&&s<=t.right;function wc(s,e,t,i){let n=G.find(s.docView,e);if(!n)return 1;let r=e-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&Zr(t,i,o))return-1;let l=n.coordsAt(r,1);return l&&Zr(t,i,l)?1:o&&o.bottom>=i?-1:1}function Jr(s,e){let t=s.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:wc(s,t,e.clientX,e.clientY)}}const Sc=C.ie&&C.ie_version<=11;let eo=null,to=0,io=0;function ma(s){if(!Sc)return s.detail;let e=eo,t=io;return eo=s,io=Date.now(),to=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(to+1)%3:1}function vc(s,e){let t=Jr(s,e),i=ma(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 a=Jr(s,r),f,h=_r(s,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let c=_r(s,t.pos,t.bias,i),u=Math.min(c.from,h.from),d=Math.max(c.to,h.to);h=u1&&(f=Cc(n,a.pos))?f:l?n.addRange(h):O.create([h])}}}function Cc(s,e){for(let t=0;t=e)return O.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}Be.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.nearest(e.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=O.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Cn(s.state,nr,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Be.dragend=s=>(s.inputState.draggedContent=null,!1);function no(s,e,t,i){if(t=Cn(s.state,ir,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Oc(s,e)?{from:r.from,to:r.to}:null,l={from:n,insert:t},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Be.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&&no(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o{/[\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 no(s,e,i,!0),!0}return!1};Be.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=pa?null:e.clipboardData;return t?(ga(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(kc(s),!1)};function Ac(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 Pc(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:Cn(s,nr,e.join(s.lineBreak)),ranges:t,linewise:i}}let Rs=null;Be.copy=Be.cut=(s,e)=>{let{text:t,ranges:i,linewise:n}=Pc(s.state);if(!t&&!n)return!1;Rs=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=pa?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Ac(s,t),!1)};const ya=tt.define();function Oa(s,e){let t=[];for(let i of s.facet(Zl)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:ya.of(!0)}):null}function ba(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Oa(s.state,e);t?s.dispatch(t):s.update([])}},10)}Qe.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),ba(s)};Qe.blur=s=>{s.observer.clearSelectionRange(),ba(s)};Qe.compositionstart=Qe.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Qe.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,C.chrome&&C.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Qe.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Be.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],a=s.posAtDOM(l.startContainer,l.startOffset),f=s.posAtDOM(l.endContainer,l.endOffset);return or(s,{from:a,to:f,insert:s.state.toText(r)},null),!0}}let n;if(C.chrome&&C.android&&(n=ua.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 C.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),C.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Qe.compositionend(s,e),20),!1};const so=new Set;function Qc(s){so.has(s)||(so.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const ro=["pre-wrap","normal","pre-line","break-spaces"];let Vt=!1;function oo(){Vt=!1}class Mc{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 ro.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let f=0;f0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Ui&&(Vt=!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:a,toA:f,fromB:h,toB:c}=n[l],u=r.lineAt(a,W.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=f?u:r.lineAt(f,W.ByPosNoHeight,i,0,0);for(c+=d.to-f,f=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,h=n[l-1].fromB,l--,ar*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&&o(this.blockAt(0,i,n,r))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Oe extends xa{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,n){return new He(n,this.length,i,this.height,this.breaks)}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof Oe||n instanceof te&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof te?n=new Oe(n.length,this.height):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.setHeight(n.heights[n.index++]):(i||this.outdated)&&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 te 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 a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(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:a}=this.heightMetrics(t,n);if(t.lineWrapping){let f=n+(e0){let r=i[i.length-1];r instanceof te?i[i.length-1]=new te(r.length+n):i.push(null,new te(n-1))}if(e>0){let r=i[0];r instanceof te?i[0]=new te(e+r.length):i.unshift(new te(e-1),null)}return he.of(i)}decomposeLeft(e,t){t.push(new te(e-1),null)}decomposeRight(e,t){t.push(null,new te(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),a=-1;for(n.from>t&&o.push(new te(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++];a==-1?a=c:Math.abs(c-a)>=Ui&&(a=-2);let u=new Oe(h,c);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new te(r-l).updateHeight(e,l));let f=he.of(o);return(a<0||Math.abs(f.height-this.height)>=Ui||Math.abs(a-this.heightMetrics(e,t).perLine)>=Ui)&&(Vt=!0),ln(this,f)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Dc 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 el))return f;let h=t==W.ByPosNoHeight?W.ByPosNoHeight:W.ByPos;return a?f.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,n,r).join(f)}forEachLine(e,t,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,l,a,o);else{let f=this.lineAt(a,W.ByPos,i,n,r);e=e&&f.from<=t&&o(f),t>f.to&&this.right.forEachLine(f.to+1,t,i,l,a,o)}}replace(e,t,i){let n=this.left.length+this.break;if(tthis.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&&lo(r,o-1),t=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);e2*t.size||t.size>2*e.size?he.of(this.break?[e,null,t]:[e,t]):(this.left=ln(this.left,e),this.right=ln(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,a=null;return n&&n.from<=t+r.length&&n.more?a=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),a?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 lo(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof te&&(i=s[e+1])instanceof te&&s.splice(e-1,3,new te(t.length+1+i.length))}const Bc=5;class lr{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 Oe?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Oe(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=Bc)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new Oe(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new te(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 Oe)return e;let t=new Oe(0,-1);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 Oe)&&!this.isCovered?this.nodes.push(new Oe(0,-1)):(this.writtenToh.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(f==s.parentNode?n.innerHeight:a,u.bottom)}f=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(f.nodeType==11)f=f.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Nc(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left0&&e.top0}function Ic(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Wn{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;itypeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Mc(t),this.stateDeco=e.facet(ui).filter(i=>typeof i!="function"),this.heightMap=he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle.setDoc(e.doc),[new Ae(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=R.set(this.lineGaps.map(i=>i.draw(this,!1))),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 Ri(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?ho:new ar(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=this.state.facet(ui).filter(h=>typeof h!="function");let n=e.changedRanges,r=Ae.extendWithRanges(n,Rc(i,this.stateDeco,e?e.changes:K.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);oo(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Vt)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let f=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(f||!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.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Vf)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let 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),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let f=0,h=0;if(l.width&&l.height){let{scaleX:v,scaleY:S}=Ml(t,l);(v>.005&&Math.abs(this.scaleX-v)>.005||S>.005&&Math.abs(this.scaleY-S)>.005)&&(this.scaleX=v,this.scaleY=S,f|=16,o=a=!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,f|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,f|=16);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Bl(e.scrollDOM);let p=(this.printing?Ic:Lc)(t,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!Nc(e.dom))return 0;let b=l.width;if((this.contentDOMWidth!=b||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,f|=16),a){let v=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(v)&&(o=!0),o||n.lineWrapping&&Math.abs(b-this.contentDOMWidth)>n.charWidth){let{lineHeight:S,charWidth:P,textHeight:A}=e.docView.measureTextSize();o=S>0&&n.refresh(r,S,P,A,Math.max(5,b/P),v),o&&(e.docView.minWidth=0,f|=16)}g>0&&m>0?h=Math.max(g,m):g<0&&m<0&&(h=Math.min(g,m)),oo();for(let S of this.viewports){let P=S.from==this.viewport.from?v:e.docView.measureVisibleLineHeights(S);this.heightMap=(o?he.empty().applyChanges(this.stateDeco,E.empty,this.heightOracle,[new Ae(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Tc(S.from,P))}Vt&&(f|=2)}let w=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return w&&(f&2&&(f|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),f|=this.updateForViewport()),(f&2||w)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),f|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),f}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,a=new Ri(n.lineAt(o-i*1e3,W.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,W.ByHeight,r,0,0).to);if(t){let{head:f}=t.range;if(fa.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(f,W.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&f=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r>1,o=n<<1;if(this.defaultTextDirection!=Y.LTR&&!i)return[];let l=[],a=(h,c,u,d)=>{if(c-hh&&yy.from>=u.from&&y.to<=u.to&&Math.abs(y.from-h)y.fromb));if(!m){if(cw.from<=c&&w.to>=c)){let w=t.moveToLineBoundary(O.cursor(c),!1,!0).head;w>h&&(c=w)}let y=this.gapSize(u,h,c,d),b=i||y<2e6?y:2e6;m=new Wn(h,c,y,b)}l.push(m)},f=h=>{if(h.length2e6)for(let P of e)P.from>=h.from&&P.fromh.from&&a(h.from,d,h,c),pt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];N.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=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Jt(this.heightMap.lineAt(e,W.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),W.ByHeight,this.heightOracle,0,0),this.scaler)}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 Ri{constructor(e,t){this.from=e,this.to=t}}function $c(s,e,t){let i=[],n=s,r=0;return N.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n=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 Li(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 Fc(s,e){for(let t of s)if(e(t))return t}const ho={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};class ar{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let f=t.lineAt(l,W.ByPos,e,0,0).top,h=t.lineAt(a,W.ByPos,e,0,0).bottom;return n+=h-f,{from:l,to:a,top:f,bottom:h,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=tt.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 He(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>Jt(n,e)):s._content)}const Ni=Q.define({combine:s=>s.join(" ")}),Es=Q.define({combine:s=>s.indexOf(!0)>-1}),Ls=ht.newName(),ka=ht.newName(),wa=ht.newName(),Sa={"&light":"."+ka,"&dark":"."+wa};function Ns(s,e,t){return new ht(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 Vc=Ns("."+Ls,{"&":{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-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,')`,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"}},Sa),Wc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Hn=C.ie&&C.ie_version<=11;class Hc{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Sf,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);(C.ie&&C.ie_version<=11||C.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&&C.android&&e.constructor.EDIT_CONTEXT!==!1&&!(C.chrome&&C.chrome_version<126)&&(this.editContext=new qc(e),e.state.facet(Ze)&&(e.contentDOM.editContext=this.editContext.editContext)),Hn&&(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){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(Ze)?i.root.activeElement!=this.dom:!Yi(this.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(C.ie&&C.ie_version<=11||C.android&&C.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ni(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=fi(e.root);if(!t)return!1;let i=C.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Xc(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=Yi(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Et(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{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&&Yi(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 ac(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=fa(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let i=fo(t,e.previousSibling||e.target.previousSibling,-1),n=fo(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(Ze)!=e.state.facet(Ze)&&(e.view.contentDOM.editContext=e.state.facet(Ze)?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 fo(s,e,t){for(;e;){let i=z.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 co(s,e){let t=e.startContainer,i=e.startOffset,n=e.endContainer,r=e.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return ni(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function Xc(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return co(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?co(s,t):null}class qc{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),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let f=a-l>i.text.length;l==this.from&&rthis.to&&(a=r);let h=ca(e.state.sliceDoc(l,a),i.text,(f?n.from:n.to)-l,f?"end":null);if(!h){let u=O.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));u.main.eq(n)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:h.from+l,to:h.toA+l,insert:E.of(i.text.slice(h.from,h.toB).split(` `))};if((C.mac||C.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:a,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);or(e,c,O.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),c.from=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{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 a=this.toEditorPos(r.rangeStart),f=this.toEditorPos(r.rangeEnd);if(a{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=fi(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,a,f)=>{if(i)return;let h=f.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(f)){n=this.pendingContextChange=null,t+=h,this.to+=h;return}else n=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=h,this.to+=h;else if(rthis.to||this.to-this.from+f.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),f.toString()),this.to+=h}t+=h}),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.to1e4*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 M{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||vf(e.parent)||document,this.viewState=new ao(e.state||I.create(e)),e.scrollTo&&e.scrollTo.is(Ti)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Mt).map(n=>new $n(n));for(let n of this.plugins)n.update(this);this.observer=new Hc(this),this.inputState=new uc(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Hr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...e){let t=e.length==1&&e[0]instanceof Z?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,a=null;e.some(u=>u.annotation(ya))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Oa(r,o),a||(l=1));let f=this.observer.delayedAndroidKey,h=null;if(f?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet(I.phrases)!=this.state.facet(I.phrases))return this.setState(r);n=on.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;c=new Lt(d.empty?d:O.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Ti)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=an.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(_t)!=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(Ni)!=n.state.facet(Ni)&&(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(Ds))try{u(n)}catch(d){xe(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!fa(this,h)&&f.force&&Et(this.contentDOM,f.key,f.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 ao(e),this.plugins=e.facet(Mt).map(i=>new $n(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Hr(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(Mt),i=e.state.facet(Mt);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new $n(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-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.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Bl(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!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 f=[];a&4||([this.measureRequests,f]=[f,this.measureRequests]);let h=f.map(d=>{try{return d.read(this)}catch(p){return xe(this.state,p),uo}}),c=on.create(this,this.state,[]),u=!1;c.flags|=a,t?t.flags|=a: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;d1||p<-1){n=n+p,i.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Ds))l(t)}get themeClasses(){return Ls+" "+(this.state.facet(Es)?wa:ka)+" "+this.state.facet(Ni)}updateAttrs(){let e=po(this,ia,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Ze)?"true":"false",class:"cm-content",style:`${C.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),po(this,sr,t);let i=this.observer.ignore(()=>{let n=As(this.contentDOM,this.contentAttrs,t),r=As(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(M.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(_t);let e=this.state.facet(M.cspNonce);ht.mount(this.root,this.styleModules.concat(Vc).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;ti.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 Vn(this,e,Gr(this,e,t,i))}moveByGroup(e,t){return Vn(this,e,Gr(this,e,t,i=>nc(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 O.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return ic(this,e,t,i)}moveVertically(e,t,i){return Vn(this,e,sc(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),la(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[at.find(r,e-n.from,-1,t)];return vn(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(Jl)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>jc)return ql(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||Xl(r.isolates,i=Wr(this,e))))return r.order;i||(i=Wr(this,e));let n=zf(e.text,t,i);return this.bidiCache.push(new an(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||C.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Tl(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={}){return Ti.of(new Lt(typeof e=="number"?O.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Ti.of(new Lt(O.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 Pe.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Pe.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ht.newName(),n=[Ni.of(i),_t.of(Ns(`.${i}`,e))];return t&&t.dark&&n.push(Es.of(!0)),n}static baseTheme(e){return Oi.lowest(_t.of(Ns("."+Ls,e,Sa)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&z.get(i)||z.get(e);return((t=n==null?void 0:n.rootView)===null||t===void 0?void 0:t.view)||null}}M.styleModule=_t;M.inputHandler=_l;M.clipboardInputFilter=ir;M.clipboardOutputFilter=nr;M.scrollHandler=ea;M.focusChangeEffect=Zl;M.perLineTextDirection=Jl;M.exceptionSink=Kl;M.updateListener=Ds;M.editable=Ze;M.mouseSelectionStyle=Ul;M.dragMovesSelection=Gl;M.clickAddsSelectionRange=Yl;M.decorations=ui;M.outerDecorations=na;M.atomicRanges=wi;M.bidiIsolatedRanges=sa;M.scrollMargins=ra;M.darkTheme=Es;M.cspNonce=Q.define({combine:s=>s.length?s[0]:""});M.contentAttributes=sr;M.editorAttributes=ia;M.lineWrapping=M.contentAttributes.of({class:"cm-lineWrapping"});M.announce=V.define();const jc=4096,uo={};class an{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=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Cs(o,t)}return t}const Yc=C.mac?"mac":C.windows?"win":C.linux?"linux":"key";function Gc(s,e){const t=s.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;ai.concat(n),[]))),t}let rt=null;const _c=4e3;function Zc(s,e=Yc){let t=Object.create(null),i=Object.create(null),n=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,f,h)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>Gc(y,e));for(let y=1;y{let v=rt={view:w,prefix:b,scope:o};return setTimeout(()=>{rt==v&&(rt=null)},_c),!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())||[]});a&&m.run.push(a),f&&(m.preventDefault=!0),h&&(m.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let f of l){let h=t[f]||(t[f]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in h)h[u].run.push(d=>c(d,Is))}let a=o[e]||o.key;if(a)for(let f of l)r(f,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(f,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Is=null;function Jc(s,e,t,i){Is=e;let n=Of(e),r=be(n,0),o=We(r)==n.length&&n!=" ",l="",a=!1,f=!1,h=!1;rt&&rt.view==t&&rt.scope==i&&(l=rt.prefix+" ",da.indexOf(e.keyCode)<0&&(f=!0,rt=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&&(h=!0),!0;m.preventDefault&&(m.stopPropagation&&(h=!0),f=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+Ii(n,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(C.windows&&e.ctrlKey&&e.altKey)&&!(C.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ft[e.keyCode])&&p!=n?(u(d[l+Ii(p,e,!0)])||e.shiftKey&&(g=hi[e.keyCode])!=n&&g!=p&&u(d[l+Ii(g,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Ii(n,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),f&&(a=!0),a&&h&&e.stopPropagation(),Is=null,a}function eu(){return iu}const tu=R.line({class:"cm-activeLine"}),iu=Pe.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.docChanged||s.selectionSet)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let e=-1,t=[];for(let i of s.state.selection.ranges){let n=s.lineBlockAt(i.head);n.from>e&&(t.push(tu.range(n.from)),e=n.from)}return R.set(t)}},{decorations:s=>s.decorations}),zi="-10000px";class nu{constructor(e,t,i,n){this.facet=t,this.createTooltipView=i,this.removeTooltipView=n,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let n=e.state.facet(this.facet),r=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;at[f]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function su(s){let e=s.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Xn=Q.define({combine:s=>{var e,t,i;return{position:C.ios?"absolute":((e=s.find(n=>n.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=s.find(n=>n.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||su}}}),mo=new WeakMap,va=Pe.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=s.state.facet(Xn);this.position=e.position,this.parent=e.parent,this.classes=s.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new nu(s,Ca,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),s.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let s of this.manager.tooltipViews)this.intersectionObserver.observe(s.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(s){s.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(s,this.above);e&&this.observeIntersection();let t=e||s.geometryChanged,i=s.state.facet(Xn);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(s,e){let t=s.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),s.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",t.dom.appendChild(n)}return t.dom.style.position=this.position,t.dom.style.top=zi,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var s,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(s=i.destroy)===null||s===void 0||s.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(C.safari){let o=r.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!r.offsetParent&&r.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let r=this.parent.getBoundingClientRect();r.width&&r.height&&(s=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:s,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),n=rr(this.view);return{visible:{left:i.left+n.left,top:i.top+n.top,right:i.right-n.right,bottom:i.bottom-n.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((r,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(r.pos):this.view.coordsAtPos(r.pos)}),size:this.manager.tooltipViews.map(({dom:r})=>r.getBoundingClientRect()),space:this.view.state.facet(Xn).tooltipSpace(this.view),scaleX:s,scaleY:e,makeAbsolute:t}}writeMeasure(s){var e;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l=Math.min(t.bottom,i.bottom)||c.rightMath.min(t.right,i.right)+.1)){h.style.top=zi;continue}let d=a.arrow?f.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,m=(e=mo.get(f))!==null&&e!==void 0?e:u.bottom-u.top,y=f.offset||ou,b=this.view.textDirection==Y.LTR,w=u.width>i.right-i.left?b?i.left:i.right-u.width:b?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-g)):Math.min(Math.max(i.left,c.left-g+(d?14:0)-y.x),i.right-g),v=this.above[l];!a.strictSide&&(v?c.top-m-p-y.yi.bottom)&&v==i.bottom-c.bottom>c.top-i.top&&(v=this.above[l]=!v);let S=(v?c.top-i.top:i.bottom-c.bottom)-p;if(Sw&&L.topP&&(P=v?L.top-m-2-p:L.bottom+p+2);if(this.position=="absolute"?(h.style.top=(P-s.parent.top)/r+"px",yo(h,(w-s.parent.left)/n)):(h.style.top=P/r+"px",yo(h,w/n)),d){let L=c.left+(b?y.x:-y.x)-(w+14-7);d.style.left=L/n+"px"}f.overlap!==!0&&o.push({left:w,top:P,right:A,bottom:P+m}),h.classList.toggle("cm-tooltip-above",v),h.classList.toggle("cm-tooltip-below",!v),f.positioned&&f.positioned(s.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let s of this.manager.tooltipViews)s.dom.style.top=zi}},{eventObservers:{scroll(){this.maybeMeasure()}}});function yo(s,e){let t=parseInt(s.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(s.style.left=e+"px")}const ru=M.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),ou={x:0,y:0},Ca=Q.define({enables:[va,ru]});function Aa(s,e){let t=s.plugin(va);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}class ut extends vt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}ut.prototype.elementClass="";ut.prototype.toDOM=void 0;ut.prototype.mapMode=ce.TrackBefore;ut.prototype.startSide=ut.prototype.endSide=-1;ut.prototype.point=!0;const Ki=Q.define(),lu=Q.define(),_i=Q.define(),Oo=Q.define({combine:s=>s.some(e=>e)});function au(s){return[hu]}const hu=Pe.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(_i).map(e=>new xo(s,e)),this.fixed=!s.state.facet(Oo);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(Oo)!=!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=N.iter(this.view.state.facet(Ki),this.view.viewport.from),i=[],n=this.gutters.map(r=>new fu(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){zs(t,i,l.from);for(let a of n)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of n)a.widget(this.view,l)}else if(r.type==Ce.Text){zs(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(_i),t=s.state.facet(_i),i=s.docChanged||s.heightChanged||s.viewportChanged||!N.eq(s.startState.facet(Ki),s.state.facet(Ki),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 xo(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=>M.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 bo(s){return Array.isArray(s)?s:[s]}function zs(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class fu{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=N.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 Pa(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=[];zs(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(lu)){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 xo{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 a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=n.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,n)&&n.preventDefault()});this.markers=bo(t.markers(e)),t.initialSpacer&&(this.spacer=new Pa(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=bo(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!N.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 Pa{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":""),cu(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,a=rr(l,a,f)||o(l,a,f):o}return i}})}});class qn extends ut{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function jn(s,e){return s.state.facet(Tt).formatNumber(e,s.state)}const pu=_i.compute([Tt],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(uu)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new qn(jn(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(du)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Tt)!=e.state.facet(Tt),initialSpacer(e){return new qn(jn(e,ko(e.state.doc.lines)))},updateSpacer(e,t){let i=jn(t.view,ko(t.view.state.doc.lines));return i==e.number?e:new qn(i)},domEventHandlers:s.facet(Tt).domEventHandlers,side:"before"}));function gu(s={}){return[Tt.of(s),au(),pu]}function ko(s){let e=9;for(;e{let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.head).from;n>t&&(t=n,e.push(mu.range(n)))}return N.of(e)});function Ou(){return yu}const Qa=1024;let bu=0;class Yn{constructor(e,t){this.from=e,this.to=t}}class D{constructor(e={}){this.id=bu++,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=pe.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}D.closedBy=new D({deserialize:s=>s.split(" ")});D.openedBy=new D({deserialize:s=>s.split(" ")});D.group=new D({deserialize:s=>s.split(" ")});D.isolate=new D({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});D.contextHash=new D({perNode:!0});D.lookAhead=new D({perNode:!0});D.mounted=new D({perNode:!0});class hn{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}static get(e){return e&&e.props&&e.props[D.mounted.id]}}const xu=Object.create(null);class pe{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):xu,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new pe(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(D.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(D.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}pe.none=new pe("",Object.create(null),0,8);class fr{constructor(e){this.types=e;for(let t=0;t0;for(let a=this.cursor(o|_.IncludeAnonymous);;){let f=!1;if(a.from<=r&&a.to>=n&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;f=!0}for(;f&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;f=!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:dr(pe.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new U(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new U(pe.none,t,i,n)))}static build(e){return vu(e)}}U.empty=new U(pe.none,[],[],0);class cr{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 cr(this.buffer,this.index)}}class dt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return pe.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return l}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l=e&&te;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function di(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.to0?l.length:-1;e!=f;e+=t){let h=l[e],c=a[e]+o.from;if(Ma(n,i,c,c+h.length)){if(h instanceof dt){if(r&_.ExcludeBuffers)continue;let u=h.findChild(0,h.buffer.length,t,i-c,n);if(u>-1)return new Xe(new ku(o,h,e,c),null,u)}else if(r&_.IncludeAnonymous||!h.type.isAnonymous||ur(h)){let u;if(!(r&_.IgnoreMounts)&&(u=hn.get(h))&&!u.overlay)return new de(u.tree,c,e,o);let d=new de(h,c,e,o);return r&_.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?h.children.length-1:0,t,i,n)}}}if(r&_.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&_.IgnoreOverlays)&&(n=hn.get(this._tree))&&n.overlay){let r=e-this.from;for(let{from:o,to:l}of n.overlay)if((t>0?o<=r:o=r:l>r))return new de(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 So(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 $s(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 ku{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class Xe extends Ta{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 Xe(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&_.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 Xe(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 Xe(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 Xe(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 U(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Da(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;rt.from||o.to=e){let l=new de(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(di(l,e,t,!1))}}return n?Da(n):i}class Fs{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof de)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 de?(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&_.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&_.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&_.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-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&_.IncludeAnonymous||l instanceof dt||!l.type.isAnonymous||ur(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=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=0;r--){if(r<0)return $s(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 ur(s){return s.children.some(e=>e instanceof dt||!e.type.isAnonymous||ur(e))}function vu(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Qa,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new cr(t,t.length):t,a=i.types,f=0,h=0;function c(S,P,A,L,F,q){let{id:B,start:T,end:H,size:X}=l,ee=h,it=f;if(X<0)if(l.next(),X==-1){let Ue=r[B];A.push(Ue),L.push(T-S);return}else if(X==-3){f=B;return}else if(X==-4){h=B;return}else throw new RangeError(`Unrecognized record size: ${X}`);let qt=a[B],vi,gt,Sr=T-S;if(H-T<=n&&(gt=m(l.pos-P,F))){let Ue=new Uint16Array(gt.size-gt.skip),ke=l.pos-gt.size,Ne=Ue.length;for(;l.pos>ke;)Ne=y(gt.start,Ue,Ne);vi=new dt(Ue,H-gt.start,i),Sr=gt.start-S}else{let Ue=l.pos-X;l.next();let ke=[],Ne=[],mt=B>=o?B:-1,Qt=0,Ci=H;for(;l.pos>Ue;)mt>=0&&l.id==mt&&l.size>=0?(l.end<=Ci-n&&(p(ke,Ne,T,Qt,l.end,Ci,mt,ee,it),Qt=ke.length,Ci=l.end),l.next()):q>2500?u(T,Ue,ke,Ne):c(T,Ue,ke,Ne,mt,q+1);if(mt>=0&&Qt>0&&Qt-1&&Qt>0){let vr=d(qt,it);vi=dr(qt,ke,Ne,0,ke.length,0,H-T,vr,vr)}else vi=g(qt,ke,Ne,H-T,ee-H,it)}A.push(vi),L.push(Sr)}function u(S,P,A,L){let F=[],q=0,B=-1;for(;l.pos>P;){let{id:T,start:H,end:X,size:ee}=l;if(ee>4)l.next();else{if(B>-1&&H=0;X-=3)T[ee++]=F[X],T[ee++]=F[X+1]-H,T[ee++]=F[X+2]-H,T[ee++]=ee;A.push(new dt(T,F[2]-H,i)),L.push(H-S)}}function d(S,P){return(A,L,F)=>{let q=0,B=A.length-1,T,H;if(B>=0&&(T=A[B])instanceof U){if(!B&&T.type==S&&T.length==F)return T;(H=T.prop(D.lookAhead))&&(q=L[B]+T.length+H)}return g(S,A,L,F,q,P)}}function p(S,P,A,L,F,q,B,T,H){let X=[],ee=[];for(;S.length>L;)X.push(S.pop()),ee.push(P.pop()+A-F);S.push(g(i.types[B],X,ee,q-F,T-q,H)),P.push(F-A)}function g(S,P,A,L,F,q,B){if(q){let T=[D.contextHash,q];B=B?[T].concat(B):[T]}if(F>25){let T=[D.lookAhead,F];B=B?[T].concat(B):[T]}return new U(S,P,A,L,B)}function m(S,P){let A=l.fork(),L=0,F=0,q=0,B=A.end-n,T={size:0,start:0,skip:0};e:for(let H=A.pos-S;A.pos>H;){let X=A.size;if(A.id==P&&X>=0){T.size=L,T.start=F,T.skip=q,q+=4,L+=4,A.next();continue}let ee=A.pos-X;if(X<0||ee=o?4:0,qt=A.start;for(A.next();A.pos>ee;){if(A.size<0)if(A.size==-3||A.size==-4)it+=4;else break e;else A.id>=o&&(it+=4);A.next()}F=qt,L+=X,q+=it}return(P<0||L==S)&&(T.size=L,T.start=F,T.skip=q),T.size>4?T:void 0}function y(S,P,A){let{id:L,start:F,end:q,size:B}=l;if(l.next(),B>=0&&L4){let H=l.pos-(B-4);for(;l.pos>H;)A=y(S,P,A)}P[--A]=T,P[--A]=q-S,P[--A]=F-S,P[--A]=L}else B==-3?f=L:B==-4&&(h=L);return A}let b=[],w=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,b,w,-1,0);let v=(e=s.length)!==null&&e!==void 0?e:b.length?w[0]+b[0].length:0;return new U(a[s.topID],b.reverse(),w.reverse(),v)}const vo=new WeakMap;function Zi(s,e){if(!s.isAnonymous||e instanceof dt||e.type!=s)return 1;let t=vo.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof U)){t=1;break}t+=Zi(s,i)}vo.set(e,t)}return t}function dr(s,e,t,i,n,r,o,l,a){let f=0;for(let p=i;p=h)break;P+=A}if(w==v+1){if(P>h){let A=p[v];d(A.children,A.positions,0,A.children.length,g[v]+b);continue}c.push(p[v])}else{let A=g[w-1]+p[w-1].length-S;c.push(dr(s,p,g,v,w,S,A,null,a))}u.push(S+b-r)}}return d(e,t,i,n,0),(l||a)(c,u,o)}class Cu{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 Xe?this.setBuffer(e.context.buffer,e.index,t):e instanceof de&&this.map.set(e.tree,t)}get(e){return e instanceof Xe?this.getBuffer(e.context.buffer,e.index):e instanceof de?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 wt{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 wt(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,a=0,f=0;;l++){let h=l=i)for(;o&&o.from=u.from||c<=u.to||f){let d=Math.max(u.from,a)-f,p=Math.min(u.to,c)-f;u=d>=p?null:new wt(d,p,u.tree,u.offset+f,l>0,!!h)}if(u&&n.push(u),o.to>c)break;o=rnew Yn(n.from,n.to)):[new Yn(0,0)]:[new Yn(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 Au{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)}}new D({perNode:!0});let Pu=0;class we{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=Pu++}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 we&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let n=new we(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 fn(e);return i=>i.modified.indexOf(t)>-1?i:fn.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}}let Qu=0;class fn{constructor(e){this.name=e,this.instances=[],this.id=Qu++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Mu(t,l.modified));if(i)return i;let n=[],r=new we(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=Tu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(fn.get(l,a));return r}}function Mu(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function Tu(s){let e=[[]];for(let t=0;ti.length-t.length)}function Ra(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 a=r.length-1,f=r[a];if(!f)throw new RangeError("Invalid path: "+n);let h=new pi(i,o,a>0?r.slice(0,a):null);e[f]=h.sort(e[f])}}return Ea.add(e)}const Ea=new D({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 pi(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class pi{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{let o=n;for(let l of r)for(let a of l.set){let f=t[a.id];if(f){o=o?o+" "+f:f;break}}return o},scope:i}}function Du(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function Bu(s,e,t,i=0,n=s.length){let r=new Ru(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class Ru{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:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let f=n,h=Eu(e)||pi.empty,c=Du(r,h.tags);if(c&&(f&&(f+=" "),f+=c,h.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(t,l),f),h.opaque)return;let u=e.tree&&e.tree.prop(D.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 b=m=w||!e.nextSibling())););if(!b||w>i)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),f))}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),f)}while(e.nextSibling());e.parent()}}}function Eu(s){let e=s.type.prop(Ea);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const k=we.define,Fi=k(),nt=k(),Co=k(nt),Ao=k(nt),st=k(),Vi=k(st),Gn=k(st),Fe=k(),yt=k(Fe),ze=k(),$e=k(),Vs=k(),Gt=k(Vs),Wi=k(),x={comment:Fi,lineComment:k(Fi),blockComment:k(Fi),docComment:k(Fi),name:nt,variableName:k(nt),typeName:Co,tagName:k(Co),propertyName:Ao,attributeName:k(Ao),className:k(nt),labelName:k(nt),namespace:k(nt),macroName:k(nt),literal:st,string:Vi,docString:k(Vi),character:k(Vi),attributeValue:k(Vi),number:Gn,integer:k(Gn),float:k(Gn),bool:k(st),regexp:k(st),escape:k(st),color:k(st),url:k(st),keyword:ze,self:k(ze),null:k(ze),atom:k(ze),unit:k(ze),modifier:k(ze),operatorKeyword:k(ze),controlKeyword:k(ze),definitionKeyword:k(ze),moduleKeyword:k(ze),operator:$e,derefOperator:k($e),arithmeticOperator:k($e),logicOperator:k($e),bitwiseOperator:k($e),compareOperator:k($e),updateOperator:k($e),definitionOperator:k($e),typeOperator:k($e),controlOperator:k($e),punctuation:Vs,separator:k(Vs),bracket:Gt,angleBracket:k(Gt),squareBracket:k(Gt),paren:k(Gt),brace:k(Gt),content:Fe,heading:yt,heading1:k(yt),heading2:k(yt),heading3:k(yt),heading4:k(yt),heading5:k(yt),heading6:k(yt),contentSeparator:k(Fe),list:k(Fe),quote:k(Fe),emphasis:k(Fe),strong:k(Fe),link:k(Fe),monospace:k(Fe),strikethrough:k(Fe),inserted:k(),deleted:k(),changed:k(),invalid:k(),meta:Wi,documentMeta:k(Wi),annotation:k(Wi),processingInstruction:k(Wi),definition:we.defineModifier("definition"),constant:we.defineModifier("constant"),function:we.defineModifier("function"),standard:we.defineModifier("standard"),local:we.defineModifier("local"),special:we.defineModifier("special")};for(let s in x){let e=x[s];e instanceof we&&(e.name=s)}La([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);var Un;const Dt=new D;function Lu(s){return Q.define({combine:s?e=>e.concat(s):void 0})}const Nu=new D;class Te{constructor(e,t,i=[],n=""){this.data=e,this.name=n,I.prototype.hasOwnProperty("tree")||Object.defineProperty(I.prototype,"tree",{get(){return ge(this)}}),this.parser=t,this.extension=[Ht.of(this),I.languageData.of((r,o,l)=>{let a=Po(r,o,l),f=a.type.prop(Dt);if(!f)return[];let h=r.facet(f),c=a.type.prop(Nu);if(c){let u=a.resolve(o-a.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(h)}}return h})].concat(i)}isActiveAt(e,t,i=-1){return Po(e,t,i).type.prop(Dt)==this.data}findRegions(e){let t=e.facet(Ht);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(Dt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(D.mounted);if(l){if(l.tree.prop(Dt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;ai.isTop?t:void 0)]}),e.name)}configure(e,t){return new cn(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ge(s){let e=s.field(Te.state,!1);return e?e.tree:U.empty}class Iu{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=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let Ut=null;class un{constructor(e,t,i=[],n,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new un(e,t,[],U.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Iu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=U.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.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(wt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Ut;Ut=this;try{return e()}finally{Ut=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Qo(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 a=[];if(e.iterChangedRanges((f,h,c,u)=>a.push({fromA:f,toA:h,fromB:c,toB:u})),i=wt.applyChanges(i,a),n=U.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let f of this.skipped){let h=e.mapPos(f.from,1),c=e.mapPos(f.to,-1);he.from&&(this.fragments=Qo(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 Ba{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=Ut;if(a){for(let f of n)a.tempSkipped.push(f);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new U(pe.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 Ut}}function Qo(s,e,t){return wt.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class Wt{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 Wt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=un.create(e.facet(Ht).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Wt(i)}}Te.state=Re.define({create:Wt.init,update(s,e){for(let t of e.effects)if(t.is(Te.setState))return t.value;return e.startState.facet(Ht)!=e.state.facet(Ht)?Wt.init(e.state):s.apply(e)}});let Na=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Na=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Kn=typeof navigator<"u"&&(!((Un=navigator.scheduling)===null||Un===void 0)&&Un.isInputPending)?()=>navigator.scheduling.isInputPending():null,zu=Pe.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(Te.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(Te.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Na(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndn+1e3,a=r.context.work(()=>Kn&&Kn()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Te.setState.of(new Wt(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>xe(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()}}}),Ht=Q.define({combine(s){return s.length?s[0]:null},enables:s=>[Te.state,zu,M.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class $u{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Fu=Q.define(),pr=Q.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 dn(s){let e=s.facet(pr);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function pn(s,e){let t="",i=s.tabSize,n=s.facet(pr)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r=e?Vu(s,t,e):null}class An{constructor(e,t={}){this.state=e,this.options=t,this.unit=dn(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-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return wn(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 za=new D;function Vu(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.fromi.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 $a(i,s,t)}function $a(s,e,t){for(let i=s;i;i=i.next){let n=Hu(i.node);if(n)return n(gr.create(e,t,i))}return 0}function Wu(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function Hu(s){let e=s.type.prop(za);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(D.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>Yu(o,!0,1,void 0,r&&!Wu(o)?n.from:void 0)}return s.parent==null?Xu:null}function Xu(){return 0}class gr extends An{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 gr(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(qu(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return $a(this.context.next,this.base,this.pos)}}function qu(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function ju(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 a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let f=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+f}}l=a.to}}function Yu(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,a=ju(s);return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}function Gu({except:s,units:e=1}={}){return t=>{let i=s&&s.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const Uu=new D;function Ku(s){let e=s.firstChild,t=s.lastChild;return e&&e.tol.prop(Dt)==o.data:o?l=>l==o:void 0,this.style=La(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ht(i):null,this.themeType=t.themeType}static define(e,t){return new Pn(e,t||{})}}const Ws=Q.define(),_u=Q.define({combine(s){return s.length?[s[0]]:null}});function _n(s){let e=s.facet(Ws);return e.length?e:s.facet(_u)}function Zu(s,e){let t=[ed],i;return s instanceof Pn&&(s.module&&t.push(M.styleModule.of(s.module)),i=s.themeType),i?t.push(Ws.computeN([M.darkTheme],n=>n.facet(M.darkTheme)==(i=="dark")?[s]:[])):t.push(Ws.of(s)),t}class Ju{constructor(e){this.markCache=Object.create(null),this.tree=ge(e.state),this.decorations=this.buildDeco(e,_n(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=ge(e.state),i=_n(e.state),n=i!=_n(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length=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 R.none;let i=new li;for(let{from:n,to:r}of e.visibleRanges)Bu(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=R.mark({class:a})))},n,r);return i.finish()}}const ed=Oi.high(Pe.fromClass(Ju,{decorations:s=>s.decorations})),td=M.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Fa=1e4,Va="()[]{}",Wa=Q.define({combine(s){return bi(s,{afterCursor:!0,brackets:Va,maxScanDistance:Fa,renderMatch:sd})}}),id=R.mark({class:"cm-matchingBracket"}),nd=R.mark({class:"cm-nonmatchingBracket"});function sd(s){let e=[],t=s.matched?id:nd;return e.push(t.range(s.start.from,s.start.to)),s.end&&e.push(t.range(s.end.from,s.end.to)),e}const rd=Re.define({create(){return R.none},update(s,e){if(!e.docChanged&&!e.selection)return s;let t=[],i=e.state.facet(Wa);for(let n of e.state.selection.ranges){if(!n.empty)continue;let r=qe(e.state,n.head,-1,i)||n.head>0&&qe(e.state,n.head-1,1,i)||i.afterCursor&&(qe(e.state,n.head,1,i)||n.headM.decorations.from(s)}),od=[rd,td];function ld(s={}){return[Wa.of(s),od]}const ad=new D;function Hs(s,e,t){let i=s.prop(e<0?D.openedBy:D.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 Xs(s){let e=s.type.prop(ad);return e?e(s.node):s}function qe(s,e,t,i={}){let n=i.maxScanDistance||Fa,r=i.brackets||Va,o=ge(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let f=Hs(a.type,t,r);if(f&&a.from0?e>=h.from&&eh.from&&e<=h.to))return hd(s,e,t,a,h,f,r)}}return fd(s,e,t,o,l.type,n,r)}function hd(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},f=0,h=l==null?void 0:l.cursor();if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(f==0&&r.indexOf(h.type.name)>-1&&h.from0)return null;let f={from:t<0?e-1:e,to:t>0?e+1:e},h=s.doc.iterRange(e,t>0?s.doc.length:0),c=0;for(let u=0;!h.next().done&&u<=r;){let d=h.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:f,end:{from:p+g,to:p+g+1},matched:y>>1==a>>1};c--}}t>0&&(u+=d.length)}return h.done?{start:f,matched:!1}:null}const cd=Object.create(null),Mo=[pe.none],To=[],Do=Object.create(null),ud=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"]])ud[s]=dd(cd,e);function Zn(s,e){To.indexOf(s)>-1||(To.push(s),console.warn(e))}function dd(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let f of l.split(".")){let h=s[f]||x[f];h?typeof h=="function"?a.length?a=a.map(h):Zn(f,`Modifier ${f} used at start of tag`):a.length?Zn(f,`Tag ${f} used as modifier`):a=Array.isArray(h)?h:[h]:Zn(f,`Unknown highlighting tag ${f}`)}for(let f of a)t.push(f)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=Do[n];if(r)return r.id;let o=Do[n]=pe.define({id:Mo.length,name:i,props:[Ra({[i]:t})]});return Mo.push(o),o.id}Y.RTL,Y.LTR;class Ha{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=ge(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(Xa(e,!1));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 Bo(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 pd(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;rtypeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:pd(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}class Ro{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function St(s){return s.selection.main.from}function Xa(s,e){var t;let{source:i}=s,n=e&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(t=s.flags)!==null&&t!==void 0?t:s.ignoreCase?"i":"")}const qa=tt.define();function md(s,e,t,i){let{main:n}=s.selection,r=t-n.from,o=i-n.from;return{...s.changeByRange(l=>{if(l!=n&&t!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(t,i))return{range:l};let a=s.toText(e);return{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:a},range:O.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Eo=new WeakMap;function yd(s){if(!Array.isArray(s))return s;let e=Eo.get(s);return e||Eo.set(s,e=gd(s)),e}const gn=V.define(),gi=V.define();class Od{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t=48&&S<=57||S>=97&&S<=122?2:S>=65&&S<=90?1:0:(P=Us(S))!=P.toLowerCase()?1:P!=P.toUpperCase()?2:0;(!b||A==1&&m||v==0&&A!=0)&&(t[c]==S||i[c]==S&&(u=!0)?o[c++]=b:o.length&&(y=!1)),v=A,b+=We(S)}return c==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(g==e.length?0:-100),[0,g]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,g]):c==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,e)}result(e,t,i){let n=[],r=0;for(let o of t){let l=o+(this.astral?We(be(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(e-i.length,n)}}class bd{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:xd,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Lo(e(i),t(i)),optionClass:(e,t)=>i=>Lo(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Lo(s,e){return s?e?s+" "+e:s:e}function xd(s,e,t,i,n,r){let o=s.textDirection==Y.RTL,l=o,a=!1,f="top",h,c,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u=g||b>e.top?h=t.bottom-e.top:(f="bottom",h=e.bottom-t.top)}let m=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${f}: ${h/m}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function kd(s){let e=s.addToOptions.slice();return s.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let f=0;fa&&o.appendChild(document.createTextNode(l.slice(a,h)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(h,c))),u.className="cm-completionMatchedText",a=c}return at.position-i.position).map(t=>t.render)}function Jn(s,e,t){if(s<=t)return{from:0,to:s};if(e<0&&(e=0),e<=s>>1){let n=Math.floor(e/t);return{from:n*t,to:(n+1)*t}}let i=Math.floor((s-e)/t);return{from:s-(i+1)*t,to:s-i*t}}class wd{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let n=e.state.field(t),{options:r,selected:o}=n.open,l=e.state.facet(J);this.optionContent=kd(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Jn(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:f}=e.state.field(t).open;for(let h=a.target,c;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(c=/-(\d+)$/.exec(h.id))&&+c[1]{let f=e.state.field(this.stateField,!1);f&&f.tooltip&&e.state.facet(J).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:gi.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=Jn(r.length,o,e.state.facet(J).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=n.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected=this.range.to)&&(this.range=Jn(t.options.length,t.selected,this.view.state.facet(J).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:n}=t.options[t.selected],{info:r}=n;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(n);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,n)}).catch(l=>xe(this.view.state,l,"completion info")):(this.addInfoPane(o,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:n,destroy:r}=e;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&vd(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return n.top>Math.min(r.bottom,t.bottom)-10||n.bottom{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;oi.from||i.from==0))if(r=u,typeof f!="string"&&f.header)n.appendChild(f.header(f));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const h=n.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let c=this.optionClass(l);c&&(h.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew wd(t,s,e)}function vd(s,e){let t=s.getBoundingClientRect(),i=e.getBoundingClientRect(),n=t.height/s.offsetHeight;i.topt.bottom&&(s.scrollTop+=(i.bottom-t.bottom)/n)}function No(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function Cd(s,e){let t=[],i=null,n=null,r=h=>{t.push(h);let{section:c}=h.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=e.facet(J);for(let h of s)if(h.hasResult()){let c=h.result.getMatch;if(h.result.filter===!1)for(let u of h.result.options)r(new Ro(u,h.source,c?c(u):[],1e9-t.length));else{let u=e.sliceDoc(h.from,h.to),d,p=o.filterStrict?new bd(u):new Od(u);for(let g of h.result.options)if(d=p.match(g.label)){let m=g.displayLabel?c?c(g,d.matched):[]:d.matched,y=d.score+(g.boost||0);if(r(new Ro(g,h.source,m,y)),typeof g.section=="object"&&g.section.rank==="dynamic"){let{name:b}=g.section;n||(n=Object.create(null)),n[b]=Math.max(y,n[b]||-1e9)}}}}if(i){let h=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?n[p.name]-n[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.nameu.score-c.score||f(c.completion,u.completion))){let c=h.completion;!a||a.label!=c.label||a.detail!=c.detail||a.type!=null&&c.type!=null&&a.type!=c.type||a.apply!=c.apply||a.boost!=c.boost?l.push(h):No(h.completion)>No(a)&&(l[l.length-1]=h),a=h.completion}return l}class Bt{constructor(e,t,i,n,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Bt(this.options,Io(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r,o){if(n&&!o&&e.some(f=>f.isPending))return n.setDisabled();let l=Cd(e,t);if(!l.length)return n&&e.some(f=>f.isPending)?n.setDisabled():null;let a=t.facet(J).selectOnOpen?0:-1;if(n&&n.selected!=a&&n.selected!=-1){let f=n.options[n.selected].completion;for(let h=0;hh.hasResult()?Math.min(f,h.from):f,1e8),create:Dd,above:r.aboveCursor},n?n.timestamp:Date.now(),a,!1)}map(e){return new Bt(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Bt(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class mn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new mn(Md,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(J),r=(i.override||t.languageDataAt("autocomplete",St(t)).map(yd)).map(a=>(this.active.find(h=>h.source==a)||new Se(a,this.active.some(h=>h.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((a,f)=>a==this.active[f])&&(r=this.active);let o=this.open,l=e.effects.some(a=>a.is(mr));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!Ad(r,this.active)||l?o=Bt.build(r,t,this.id,o,i,l):o&&o.disabled&&!r.some(a=>a.isPending)&&(o=null),!o&&r.every(a=>!a.isPending)&&r.some(a=>a.hasResult())&&(r=r.map(a=>a.hasResult()?new Se(a.source,0):a));for(let a of e.effects)a.is(Ya)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new mn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Pd:Qd}}function Ad(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t-1&&(t["aria-activedescendant"]=s+"-"+e),t}const Md=[];function ja(s,e){if(s.isUserEvent("input.complete")){let i=s.annotation(qa);if(i&&e.activateOnCompletion(i))return 12}let t=s.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:s.isUserEvent("delete.backward")?2:s.selection?8:s.docChanged?16:0}class Se{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=ja(e,t),n=this;(i&8||i&16&&this.touches(e))&&(n=new Se(n.source,0)),i&4&&n.state==0&&(n=new Se(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(gn))n=new Se(n.source,1,r.value);else if(r.is(gi))n=new Se(n.source,0);else if(r.is(mr))for(let o of r.value)o.source==n.source&&(n=o);return n}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(St(e.state))}}class Nt extends Se{constructor(e,t,i,n,r,o){super(e,3,t),this.limit=i,this.result=n,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let n=this.result;n.map&&!e.changes.empty&&(n=n.map(n,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=St(e.state);if(l>o||!n||t&2&&(St(e.startState)==this.from||lt.map(e))}}),Ya=V.define(),fe=Re.define({create(){return mn.start()},update(s,e){return s.update(e)},provide:s=>[Ca.from(s,e=>e.tooltip),M.contentAttributes.from(s,e=>e.attrs)]});function yr(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(fe).active.find(n=>n.source==e.source);return i instanceof Nt?(typeof t=="string"?s.dispatch({...md(s.state,t,i.from,i.to),annotations:qa.of(e.completion)}):t(s,e.completion,i.from,i.to),!0):!1}const Dd=Sd(fe,yr);function Hi(s,e="option"){return t=>{let i=t.state.field(fe,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp-1?i.open.selected+n*(s?1:-1):s?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Ya.of(l)}),!0}}const Bd=s=>{let e=s.state.field(fe,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamps.state.field(fe,!1)?(s.dispatch({effects:gn.of(!0)}),!0):!1,Rd=s=>{let e=s.state.field(fe,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:gi.of(null)}),!0)};class Ed{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Ld=50,Nd=1e3,Id=Pe.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of s.state.field(fe).active)e.isPending&&this.startQuery(e)}update(s){let e=s.state.field(fe),t=s.state.facet(J);if(!s.selectionSet&&!s.docChanged&&s.startState.field(fe)==e)return;let i=s.transactions.some(r=>{let o=ja(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;rLd&&Date.now()-o.time>Nd){for(let l of o.context.abortListeners)try{l()}catch(a){xe(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(r=>r.effects.some(o=>o.is(gn)))&&(this.pendingStart=!0);let n=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),n):-1,this.composing!=0)for(let r of s.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,e=s.field(fe);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(J).updateSyncTime))}startQuery(s){let{state:e}=this.view,t=St(e),i=new Ha(e,t,s.explicit,this.view),n=new Ed(s,i);this.running.push(n),Promise.resolve(s.source(i)).then(r=>{n.context.aborted||(n.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:gi.of(null)}),xe(this.view.state,r)})}scheduleAccept(){this.running.every(s=>s.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(J).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(J),i=this.view.state.field(fe);for(let n=0;nl.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Se(r.active.source,0);for(let a of r.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:mr.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(fe,!1);if(e&&e.tooltip&&this.view.state.facet(J).closeOnBlur){let t=e.open&&Aa(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:gi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:gn.of(!1)}),20),this.composing=0}}}),zd=typeof navigator=="object"&&/Win/.test(navigator.platform),$d=Oi.highest(M.domEventHandlers({keydown(s,e){let t=e.state.field(fe,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||s.key.length>1||s.ctrlKey&&!(zd&&s.altKey)||s.metaKey)return!1;let i=t.open.options[t.open.selected],n=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||n.result.commitCharacters;return r&&r.indexOf(s.key)>-1&&yr(e,i),!1}})),Fd=M.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"},".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"}}}),mi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},kt=V.define({map(s,e){let t=e.mapPos(s,-1,ce.TrackAfter);return t??void 0}}),Or=new class extends vt{};Or.startSide=1;Or.endSide=-1;const Ga=Re.define({create(){return N.empty},update(s,e){if(s=s.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);s=s.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(kt)&&(s=s.update({add:[Or.range(t.value,t.value+1)]}));return s}});function Vd(){return[Hd,Ga]}const ts="()[]{}<>«»»«[]{}";function Ua(s){for(let e=0;e{if((Wd?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&We(be(i,0))==1||e!=n.from||t!=n.to)return!1;let r=jd(s.state,i);return r?(s.dispatch(r),!0):!1}),Xd=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let i=Ka(s,s.selection.main.head).brackets||mi.brackets,n=null,r=s.changeByRange(o=>{if(o.empty){let l=Yd(s.doc,o.head);for(let a of i)if(a==l&&Qn(s.doc,o.head)==Ua(be(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:O.cursor(o.head-a.length)}}return{range:n=o}});return n||e(s.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!n},qd=[{key:"Backspace",run:Xd}];function jd(s,e){let t=Ka(s,s.selection.main.head),i=t.brackets||mi.brackets;for(let n of i){let r=Ua(be(n,0));if(e==n)return r==n?Kd(s,n,i.indexOf(n+n+n)>-1,t):Gd(s,n,r,t.before||mi.before);if(e==r&&_a(s,s.selection.main.from))return Ud(s,n,r)}return null}function _a(s,e){let t=!1;return s.field(Ga).between(0,s.doc.length,i=>{i==e&&(t=!0)}),t}function Qn(s,e){let t=s.sliceString(e,e+2);return t.slice(0,We(be(t,0)))}function Yd(s,e){let t=s.sliceString(e-2,e);return We(be(t,0))==t.length?t:t.slice(1)}function Gd(s,e,t,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:kt.of(o.to+e.length),range:O.range(o.anchor+e.length,o.head+e.length)};let l=Qn(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:kt.of(o.head+e.length),range:O.cursor(o.head+e.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Ud(s,e,t){let i=null,n=s.changeByRange(r=>r.empty&&Qn(s.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:O.cursor(r.head+t.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function Kd(s,e,t,i){let n=i.stringPrefixes||mi.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:kt.of(l.to+e.length),range:O.range(l.anchor+e.length,l.head+e.length)};let a=l.head,f=Qn(s.doc,a),h;if(f==e){if(zo(s,a))return{changes:{insert:e+e,from:a},effects:kt.of(a+e.length),range:O.cursor(a+e.length)};if(_a(s,a)){let u=t&&s.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:O.cursor(a+u.length)}}}else{if(t&&s.sliceDoc(a-2*e.length,a)==e+e&&(h=$o(s,a-2*e.length,n))>-1&&zo(s,h))return{changes:{insert:e+e+e+e,from:a},effects:kt.of(a+e.length),range:O.cursor(a+e.length)};if(s.charCategorizer(a)(f)!=re.Word&&$o(s,a,n)>-1&&!_d(s,a,e,n))return{changes:{insert:e+e,from:a},effects:kt.of(a+e.length),range:O.cursor(a+e.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function zo(s,e){let t=ge(s).resolveInner(e+1);return t.parent&&t.from==e}function _d(s,e,t,i){let n=ge(s).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=s.sliceDoc(n.from,Math.min(n.to,n.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=n.firstChild;for(;h&&h.from==n.from&&h.to-h.from>t.length+a;){if(s.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let f=n.to==e&&n.parent;if(!f)break;n=f}return!1}function $o(s,e,t){let i=s.charCategorizer(e);if(i(s.sliceDoc(e-1,e))!=re.Word)return e;for(let n of t){let r=e-n.length;if(s.sliceDoc(r,e)==n&&i(s.sliceDoc(r-1,r))!=re.Word)return r}return-1}function Zd(s={}){return[$d,fe,J.of(s),Id,Jd,Fd]}const Za=[{key:"Ctrl-Space",run:es},{mac:"Alt-`",run:es},{mac:"Alt-i",run:es},{key:"Escape",run:Rd},{key:"ArrowDown",run:Hi(!0)},{key:"ArrowUp",run:Hi(!1)},{key:"PageDown",run:Hi(!0,"page")},{key:"PageUp",run:Hi(!1,"page")},{key:"Enter",run:Bd}],Jd=Oi.highest(hr.computeN([J],s=>s.facet(J).defaultKeymap?[Za]:[])),ep=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=xr(s.state,t.from);return i.line?tp(s):i.block?np(s):!1};function br(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 tp=br(op,0),ip=br(Ja,0),np=br((s,e)=>Ja(s,e,rp(e)),0);function xr(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Kt=50;function sp(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-Kt,i),o=s.sliceDoc(n,n+Kt),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,f=r.length-l;if(r.slice(f-e.length,f)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let h,c;n-i<=2*Kt?h=c=s.sliceDoc(i,n):(h=s.sliceDoc(i,i+Kt),c=s.sliceDoc(n-Kt,n));let u=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return h.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(h.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function rp(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 Ja(s,e,t=e.selection.ranges){let i=t.map(r=>xr(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>sp(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;on&&(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+f.length)==f?u:-1;ur.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:f,empty:h,single:c}of i)(c||!h)&&r.push({from:l.from+f,insert:a+" "});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:a}of i)if(l>=0){let f=o.from+l,h=f+a.length;o.text[h-o.from]==" "&&h++,r.push({from:f,to:h})}return{changes:r}}return null}const qs=tt.define(),lp=tt.define(),ap=Q.define(),eh=Q.define({combine(s){return bi(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)})}}),th=Re.define({create(){return je.empty},update(s,e){let t=e.state.facet(eh),i=e.annotation(qs);if(i){let a=ue.fromTransaction(e,i.selection),f=i.side,h=f==0?s.undone:s.done;return a?h=yn(h,h.length,t.minDepth,a):h=sh(h,e.startState.selection),new je(f==0?i.rest:h,f==0?h:i.rest)}let n=e.annotation(lp);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(Z.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=ue.fromTransaction(e),o=e.annotation(Z.time),l=e.annotation(Z.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 je(s.done.map(ue.fromJSON),s.undone.map(ue.fromJSON))}});function hp(s={}){return[th,eh.of(s),M.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?ih:e.inputType=="historyRedo"?js:null;return i?(e.preventDefault(),i(t)):!1}})]}function Mn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(th,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const ih=Mn(0,!1),js=Mn(1,!1),fp=Mn(0,!0),cp=Mn(1,!0);class ue{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 ue(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 ue(e.changes&&K.fromJSON(e.changes),[],e.mapped&&Ye.fromJSON(e.mapped),e.startSelection&&O.fromJSON(e.startSelection),e.selectionsAfter.map(O.fromJSON))}static fromTransaction(e,t){let i=ve;for(let n of e.startState.facet(ap)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new ue(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,ve)}static selection(e){return new ue(void 0,ve,void 0,void 0,e)}}function yn(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 up(s,e){let t=[],i=!1;return s.iterChangedRanges((n,r)=>t.push(n,r)),e.iterChangedRanges((n,r,o,l)=>{for(let a=0;a=f&&o<=h&&(i=!0)}}),i}function dp(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function nh(s,e){return s.length?e.length?s.concat(e):s:e}const ve=[],pp=200;function sh(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-pp));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),yn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[ue.selection([e])]}function gp(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 is(s,e){if(!s.length)return s;let t=s.length,i=ve;for(;t;){let n=mp(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?[ue.selection(i)]:ve}function mp(s,e,t){let i=nh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):ve,t);if(!s.changes)return ue.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new ue(n,V.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const yp=/^(input\.type|delete)($|\.)/;class je{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 je(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||yp.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?s.moveByChar(t,e):Tn(t,e))}function oe(s){return s.textDirectionAt(s.state.selection.main.head)==Y.LTR}const oh=s=>rh(s,!oe(s)),lh=s=>rh(s,oe(s));function ah(s,e){return Le(s,t=>t.empty?s.moveByGroup(t,e):Tn(t,e))}const bp=s=>ah(s,!oe(s)),xp=s=>ah(s,oe(s));function kp(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 Dn(s,e,t){let i=ge(s).resolveInner(e.head),n=t?D.closedBy:D.openedBy;for(let a=e.head;;){let f=t?i.childAfter(a):i.childBefore(a);if(!f)break;kp(s,f,n)?i=f:a=t?f.to:f.from}let r=i.type.prop(n),o,l;return r&&(o=t?qe(s,i.from,1):qe(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,O.cursor(l,t?-1:1)}const wp=s=>Le(s,e=>Dn(s.state,e,!oe(s))),Sp=s=>Le(s,e=>Dn(s.state,e,oe(s)));function hh(s,e){return Le(s,t=>{if(!t.empty)return Tn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const fh=s=>hh(s,!1),ch=s=>hh(s,!0);function uh(s){let e=s.scrollDOM.clientHeighto.empty?s.moveVertically(o,e,t.height):Tn(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(),a=l.top+t.marginTop,f=l.bottom-t.marginBottom;o&&o.top>a&&o.bottomdh(s,!1),Ys=s=>dh(s,!0);function pt(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=O.cursor(i.from+r))}return n}const vp=s=>Le(s,e=>pt(s,e,!0)),Cp=s=>Le(s,e=>pt(s,e,!1)),Ap=s=>Le(s,e=>pt(s,e,!oe(s))),Pp=s=>Le(s,e=>pt(s,e,oe(s))),Qp=s=>Le(s,e=>O.cursor(s.lineBlockAt(e.head).from,1)),Mp=s=>Le(s,e=>O.cursor(s.lineBlockAt(e.head).to,-1));function Tp(s,e,t){let i=!1,n=Xt(s.selection,r=>{let o=qe(s,r.head,-1)||qe(s,r.head,1)||r.head>0&&qe(s,r.head-1,1)||r.headTp(s,e);function Me(s,e){let t=Xt(s.state.selection,i=>{let n=e(i);return O.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)});return t.eq(s.state.selection)?!1:(s.dispatch(Ee(s.state,t)),!0)}function ph(s,e){return Me(s,t=>s.moveByChar(t,e))}const gh=s=>ph(s,!oe(s)),mh=s=>ph(s,oe(s));function yh(s,e){return Me(s,t=>s.moveByGroup(t,e))}const Bp=s=>yh(s,!oe(s)),Rp=s=>yh(s,oe(s)),Ep=s=>Me(s,e=>Dn(s.state,e,!oe(s))),Lp=s=>Me(s,e=>Dn(s.state,e,oe(s)));function Oh(s,e){return Me(s,t=>s.moveVertically(t,e))}const bh=s=>Oh(s,!1),xh=s=>Oh(s,!0);function kh(s,e){return Me(s,t=>s.moveVertically(t,e,uh(s).height))}const Vo=s=>kh(s,!1),Wo=s=>kh(s,!0),Np=s=>Me(s,e=>pt(s,e,!0)),Ip=s=>Me(s,e=>pt(s,e,!1)),zp=s=>Me(s,e=>pt(s,e,!oe(s))),$p=s=>Me(s,e=>pt(s,e,oe(s))),Fp=s=>Me(s,e=>O.cursor(s.lineBlockAt(e.head).from)),Vp=s=>Me(s,e=>O.cursor(s.lineBlockAt(e.head).to)),Ho=({state:s,dispatch:e})=>(e(Ee(s,{anchor:0})),!0),Xo=({state:s,dispatch:e})=>(e(Ee(s,{anchor:s.doc.length})),!0),qo=({state:s,dispatch:e})=>(e(Ee(s,{anchor:s.selection.main.anchor,head:0})),!0),jo=({state:s,dispatch:e})=>(e(Ee(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),Wp=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),Hp=({state:s,dispatch:e})=>{let t=Bn(s).map(({from:i,to:n})=>O.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:O.create(t),userEvent:"select"})),!0},Xp=({state:s,dispatch:e})=>{let t=Xt(s.selection,i=>{let n=ge(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.to||l.to>i.to&&l.from<=i.from)&&o.next)return O.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Ee(s,t)),!0)};function wh(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.to0)for(let l=r;;){let a=s.moveVertically(l,e);if(a.heado.to){n.some(f=>f.head==a.head)||n.push(a);break}else{if(a.head==l.head)break;l=a}}}return n.length==i.ranges.length?!1:(s.dispatch(Ee(t,O.create(n,n.length-1))),!0)}const qp=s=>wh(s,!1),jp=s=>wh(s,!0),Yp=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=O.create([t.main]):t.main.empty||(i=O.create([O.cursor(t.main.head)])),i?(e(Ee(s,i)),!0):!1};function Si(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 a=e(r);ao&&(t="delete.forward",a=Xi(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Xi(s,o,!1),l=Xi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:O.cursor(o,on(s)))i.between(e,e,(n,r)=>{ne&&(e=t?r:n)});return e}const Sh=(s,e,t)=>Si(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(t&&!e&&n>o.from&&nSh(s,!1,!0),vh=s=>Sh(s,!0,!1),Ch=(s,e)=>Si(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 a=ae(r.text,i-r.from,e)+r.from,f=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),h=o(f);if(l!=null&&h!=l)break;(f!=" "||i!=t.head)&&(l=h),i=a}return i}),Ah=s=>Ch(s,!1),Gp=s=>Ch(s,!0),Up=s=>Si(s,e=>{let t=s.lineBlockAt(e.head).to;return e.headSi(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),_p=s=>Si(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:E.of(["",""])},range:O.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Jp=({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:ae(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ae(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:O.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Bn(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 Ph(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of Bn(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 a of r.ranges)n.push(O.range(Math.min(s.doc.length,a.anchor+l),Math.min(s.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let a of r.ranges)n.push(O.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:O.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const eg=({state:s,dispatch:e})=>Ph(s,e,!1),tg=({state:s,dispatch:e})=>Ph(s,e,!0);function Qh(s,e,t){if(s.readOnly)return!1;let i=[];for(let n of Bn(s))t?i.push({from:n.from,insert:s.doc.slice(n.from,n.to)+s.lineBreak}):i.push({from:n.to,insert:s.lineBreak+s.doc.slice(n.from,n.to)});return e(s.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const ig=({state:s,dispatch:e})=>Qh(s,e,!1),ng=({state:s,dispatch:e})=>Qh(s,e,!0),sg=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(Bn(e).map(({from:n,to:r})=>(n>0?n--:r{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 rg(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ge(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(D.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 Yo=Mh(!1),og=Mh(!0);function Mh(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),a=!s&&r==o&&rg(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let f=new An(e,{simulateBreak:r,simulateDoubleBreak:!!a}),h=Ia(f,r);for(h==null&&(h=wn(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));ol.from&&r{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:O.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const lg=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new An(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=kr(s,(r,o,l)=>{let a=Ia(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let f=/^\s*/.exec(r.text)[0],h=pn(s,a);(f!=h||l.froms.readOnly?!1:(e(s.update(kr(s,(t,i)=>{i.push({from:t.from,insert:s.facet(pr)})}),{userEvent:"input.indent"})),!0),hg=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(kr(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=wn(n,s.tabSize),o=0,l=pn(s,Math.max(0,r-dn(s)));for(;o(s.setTabFocusMode(),!0),cg=[{key:"Ctrl-b",run:oh,shift:gh,preventDefault:!0},{key:"Ctrl-f",run:lh,shift:mh},{key:"Ctrl-p",run:fh,shift:bh},{key:"Ctrl-n",run:ch,shift:xh},{key:"Ctrl-a",run:Qp,shift:Fp},{key:"Ctrl-e",run:Mp,shift:Vp},{key:"Ctrl-d",run:vh},{key:"Ctrl-h",run:Gs},{key:"Ctrl-k",run:Up},{key:"Ctrl-Alt-h",run:Ah},{key:"Ctrl-o",run:Zp},{key:"Ctrl-t",run:Jp},{key:"Ctrl-v",run:Ys}],ug=[{key:"ArrowLeft",run:oh,shift:gh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:bp,shift:Bp,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Ap,shift:zp,preventDefault:!0},{key:"ArrowRight",run:lh,shift:mh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:xp,shift:Rp,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Pp,shift:$p,preventDefault:!0},{key:"ArrowUp",run:fh,shift:bh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ho,shift:qo},{mac:"Ctrl-ArrowUp",run:Fo,shift:Vo},{key:"ArrowDown",run:ch,shift:xh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Xo,shift:jo},{mac:"Ctrl-ArrowDown",run:Ys,shift:Wo},{key:"PageUp",run:Fo,shift:Vo},{key:"PageDown",run:Ys,shift:Wo},{key:"Home",run:Cp,shift:Ip,preventDefault:!0},{key:"Mod-Home",run:Ho,shift:qo},{key:"End",run:vp,shift:Np,preventDefault:!0},{key:"Mod-End",run:Xo,shift:jo},{key:"Enter",run:Yo,shift:Yo},{key:"Mod-a",run:Wp},{key:"Backspace",run:Gs,shift:Gs,preventDefault:!0},{key:"Delete",run:vh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Ah,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Gp,preventDefault:!0},{mac:"Mod-Backspace",run:Kp,preventDefault:!0},{mac:"Mod-Delete",run:_p,preventDefault:!0}].concat(cg.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),dg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:wp,shift:Ep},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Sp,shift:Lp},{key:"Alt-ArrowUp",run:eg},{key:"Shift-Alt-ArrowUp",run:ig},{key:"Alt-ArrowDown",run:tg},{key:"Shift-Alt-ArrowDown",run:ng},{key:"Mod-Alt-ArrowUp",run:qp},{key:"Mod-Alt-ArrowDown",run:jp},{key:"Escape",run:Yp},{key:"Mod-Enter",run:og},{key:"Alt-l",mac:"Ctrl-l",run:Hp},{key:"Mod-i",run:Xp,preventDefault:!0},{key:"Mod-[",run:hg},{key:"Mod-]",run:ag},{key:"Mod-Alt-\\",run:lg},{key:"Shift-Mod-k",run:sg},{key:"Shift-Mod-\\",run:Dp},{key:"Mod-/",run:ep},{key:"Alt-A",run:ip},{key:"Ctrl-m",mac:"Shift-Alt-m",run:fg}].concat(ug);var Go={};class On{constructor(e,t,i,n,r,o,l,a,f,h=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=a,this.curContext=f,this.lookAhead=h,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 On(e,[],t,i,i,0,[],0,n?new Uo(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=2e3&&!(!((t=this.p.parser.nodeSet.types[n])===null||t===void 0)&&t.isAnonymous)&&(f==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=h):this.p.lastBigReductionSizea;)this.stack.pop();this.reduceContext(n,f)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(t==i)return;if(o.buffer[l-2]>=t){o.buffer[l-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 a=o;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-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;(n>this.pos||t<=o.maxNode)&&(this.pos=n,o.stateFlag(r,1)||(this.reducePos=n)),this.pushState(r,i),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>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 On(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 pg(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;ra&1&&l==o)||n.push(t[r],o)}t=n}let i=[];for(let n=0;n>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 a=o&65535,f=this.stack.length-l*3;if(f>=0&&e.getGoto(this.stack[f],a,!1)>=0)return l<<19|65536|a}}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;t0&&this.emitLookAhead()}}class Uo{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class pg{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 bn{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 bn(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 bn(this.stack,this.pos,this.index)}}function ei(s,e=Uint16Array){if(typeof s!="string")return s;let t=null;for(let i=0,n=0;i=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[n++]=r:t=new e(r)}return t}class Ji{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const Ko=new Ji;class gg{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Ko,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(;ri.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&&ee)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,n;if(t>=0&&t=this.chunk2Pos&&il.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.chunk2Pos&&this.posthis.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=Ko,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&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 It{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;Dh(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}It.prototype.contextual=It.prototype.fallback=It.prototype.extend=!1;class Th{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data=typeof e=="string"?ei(e):e}token(e,t){let i=e.pos,n=0;for(;;){let r=e.next<0,o=e.resolveOffset(1,1);if(Dh(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))}}Th.prototype.contextual=It.prototype.fallback=It.prototype.extend=!1;class Rn{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function Dh(s,e,t,i,n,r){let o=0,l=1<0){let p=s[d];if(a.allows(p)&&(e.token.value==-1||e.token.value==p||mg(p,e.token.value,n,r))){e.acceptToken(p);break}}let h=e.next,c=0,u=s[o+2];if(e.next<0&&u>c&&s[f+u*3-3]==65535){o=s[f+u*3-1];continue e}for(;c>1,p=f+d+(d<<1),g=s[p],m=s[p+1]||65536;if(h=m)c=d+1;else{o=s[p+2],e.advance();continue e}}break}}function _o(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function mg(s,e,t,i){let n=_o(t,i,e);return n<0||_o(t,i,s)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 yg{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?Zo(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Zo(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(ee)return this.nextStart=o,null;if(r instanceof U){if(o==e){if(o=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 Og{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new Ji)}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,a=0;for(let f=0;fc.end+25&&(a=Math.max(c.lookAhead,a)),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),!h.extend&&(i=c,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new Ji,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 Ji,{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=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;re.bufferLength*4?new yg(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;ot)i.push(l);else{if(this.advanceStack(l,i,e))continue;{n||(n=[],r=[]),n.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!i.length){let o=n&&kg(n);if(o)return me&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw me&&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 me&&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,a)=>a.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;o500&&f.buffer.length>500)if((l.score-f.score||l.buffer.length-f.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&i.splice(12,i.length-12)}this.minStackPos=i[0].pos;for(let o=1;o ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let f=e.curContext&&e.curContext.tracker.strict,h=f?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&&(!f||(c.prop(D.contextHash)||0)==h))return e.useNode(c,u),me&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof U)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof U&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),me&&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 a=this.tokens.getActions(e);for(let f=0;fn?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 Jo(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let o=0;o ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),me&&console.log(h+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=h;for(let d=0;d<10&&c.forceReduce()&&(me&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)me&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(a))me&&console.log(h+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(f==l.pos&&(f++,a=0),l.recoverByDelete(a,f),me&&console.log(h+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),Jo(l,i)):(!n||n.scoree.topRules[l][1]),n=[];for(let l=0;l=0)r(h,a,l[f++]);else{let c=l[f+-h];for(let u=-h;u>0;u--)r(l[f++],a,c);f++}}}this.nodeSet=new fr(t.map((l,a)=>pe.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:n[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Qa;let o=ei(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;ltypeof l=="number"?new It(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 bg(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,a=n[r++];if(l&&i)return a;for(let f=r+(o>>1);r0}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=_e(this.data,r+2);else break;n=t(_e(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=_e(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(xn.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]=el(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;ri)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.scores.external(t,i)<<1|e}return s.get}const wg=122,tl=1,Sg=123,vg=124,Bh=2,Cg=125,Ag=3,Pg=4,Rh=[9,10,11,12,13,32,133,160,5760,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8232,8233,8239,8287,12288],Qg=58,Mg=40,Eh=95,Tg=91,en=45,Dg=46,Bg=35,Rg=37,Eg=38,Lg=92,Ng=10,Ig=42;function yi(s){return s>=65&&s<=90||s>=97&&s<=122||s>=161}function wr(s){return s>=48&&s<=57}function il(s){return wr(s)||s>=97&&s<=102||s>=65&&s<=70}const Lh=(s,e,t)=>(i,n)=>{for(let r=!1,o=0,l=0;;l++){let{next:a}=i;if(yi(a)||a==en||a==Eh||r&&wr(a))!r&&(a!=en||l>0)&&(r=!0),o===l&&a==en&&o++,i.advance();else if(a==Lg&&i.peek(1)!=Ng){if(i.advance(),il(i.next)){do i.advance();while(il(i.next));i.next==32&&i.advance()}else i.next>-1&&i.advance();r=!0}else{r&&i.acceptToken(o==2&&n.canShift(Bh)?e:a==Mg?t:s);break}}},zg=new Rn(Lh(Sg,Bh,vg)),$g=new Rn(Lh(Cg,Ag,Pg)),Fg=new Rn(s=>{if(Rh.includes(s.peek(-1))){let{next:e}=s;(yi(e)||e==Eh||e==Bg||e==Dg||e==Ig||e==Tg||e==Qg&&yi(s.peek(1))||e==en||e==Eg)&&s.acceptToken(wg)}}),Vg=new Rn(s=>{if(!Rh.includes(s.peek(-1))){let{next:e}=s;if(e==Rg&&(s.advance(),s.acceptToken(tl)),yi(e)){do s.advance();while(yi(s.next)||wr(s.next));s.acceptToken(tl)}}}),Wg=Ra({"AtKeyword import charset namespace keyframes media supports":x.definitionKeyword,"from to selector":x.keyword,NamespaceName:x.namespace,KeyframeName:x.labelName,KeyframeRangeName:x.operatorKeyword,TagName:x.tagName,ClassName:x.className,PseudoClassName:x.constant(x.className),IdName:x.labelName,"FeatureName PropertyName":x.propertyName,AttributeName:x.attributeName,NumberLiteral:x.number,KeywordQuery:x.keyword,UnaryQueryOp:x.operatorKeyword,"CallTag ValueName":x.atom,VariableName:x.variableName,Callee:x.operatorKeyword,Unit:x.unit,"UniversalSelector NestingSelector":x.definitionOperator,"MatchOp CompareOp":x.compareOperator,"ChildOp SiblingOp, LogicOp":x.logicOperator,BinOp:x.arithmeticOperator,Important:x.modifier,Comment:x.blockComment,ColorLiteral:x.color,"ParenthesizedContent StringLiteral":x.string,":":x.punctuation,"PseudoOp #":x.derefOperator,"; ,":x.separator,"( )":x.paren,"[ ]":x.squareBracket,"{ }":x.brace}),Hg={__proto__:null,lang:38,"nth-child":38,"nth-last-child":38,"nth-of-type":38,"nth-last-of-type":38,dir:38,"host-context":38,if:84,url:124,"url-prefix":124,domain:124,regexp:124},Xg={__proto__:null,or:98,and:98,not:106,only:106,layer:170},qg={__proto__:null,selector:112,layer:166},jg={__proto__:null,"@import":162,"@media":174,"@charset":178,"@namespace":182,"@keyframes":188,"@supports":200,"@scope":204},Yg={__proto__:null,to:207},Gg=xn.deserialize({version:14,states:"EbQYQdOOO#qQdOOP#xO`OOOOQP'#Cf'#CfOOQP'#Ce'#CeO#}QdO'#ChO$nQaO'#CcO$xQdO'#CkO%TQdO'#DpO%YQdO'#DrO%_QdO'#DuO%_QdO'#DxOOQP'#FV'#FVO&eQhO'#EhOOQS'#FU'#FUOOQS'#Ek'#EkQYQdOOO&lQdO'#EOO&PQhO'#EUO&lQdO'#EWO'aQdO'#EYO'lQdO'#E]O'tQhO'#EcO(VQdO'#EeO(bQaO'#CfO)VQ`O'#D{O)[Q`O'#F`O)gQdO'#F`QOQ`OOP)qO&jO'#CaPOOO)C@t)C@tOOQP'#Cj'#CjOOQP,59S,59SO#}QdO,59SO)|QdO,59VO%TQdO,5:[O%YQdO,5:^O%_QdO,5:aO%_QdO,5:cO%_QdO,5:dO%_QdO'#ErO*XQ`O,58}O*aQdO'#DzOOQS,58},58}OOQP'#Cn'#CnOOQO'#Dn'#DnOOQP,59V,59VO*hQ`O,59VO*mQ`O,59VOOQP'#Dq'#DqOOQP,5:[,5:[OOQO'#Ds'#DsO*rQpO,5:^O+]QaO,5:aO+sQaO,5:dOOQW'#DZ'#DZO,ZQhO'#DdO,xQhO'#FaO'tQhO'#DbO-WQ`O'#DhOOQW'#F['#F[O-]Q`O,5;SO-eQ`O'#DeOOQS-E8i-E8iOOQ['#Cs'#CsO-jQdO'#CtO.QQdO'#CzO.hQdO'#C}O/OQ!pO'#DPO1RQ!jO,5:jOOQO'#DU'#DUO*mQ`O'#DTO1cQ!nO'#FXO3`Q`O'#DVO3eQ`O'#DkOOQ['#FX'#FXO-`Q`O,5:pO3jQ!bO,5:rOOQS'#E['#E[O3rQ`O,5:tO3wQdO,5:tOOQO'#E_'#E_O4PQ`O,5:wO4UQhO,5:}O%_QdO'#DgOOQS,5;P,5;PO-eQ`O,5;PO4^QdO,5;PO4fQdO,5:gO4vQdO'#EtO5TQ`O,5;zO5TQ`O,5;zPOOO'#Ej'#EjP5`O&jO,58{POOO,58{,58{OOQP1G.n1G.nOOQP1G.q1G.qO*hQ`O1G.qO*mQ`O1G.qOOQP1G/v1G/vO5kQpO1G/xO5sQaO1G/{O6ZQaO1G/}O6qQaO1G0OO7XQaO,5;^OOQO-E8p-E8pOOQS1G.i1G.iO7cQ`O,5:fO7hQdO'#DoO7oQdO'#CrOOQP1G/x1G/xO&lQdO1G/xO7vQ!jO'#DZO8UQ!bO,59vO8^QhO,5:OOOQO'#F]'#F]O8XQ!bO,59zO'tQhO,59xO8fQhO'#EvO8sQ`O,5;{O9OQhO,59|O9uQhO'#DiOOQW,5:S,5:SOOQS1G0n1G0nOOQW,5:P,5:PO9|Q!fO'#FYOOQS'#FY'#FYOOQS'#Em'#EmO;^QdO,59`OOQ[,59`,59`O;tQdO,59fOOQ[,59f,59fO<[QdO,59iOOQ[,59i,59iOOQ[,59k,59kO&lQdO,59mOPQ!fO1G0ROOQO1G0R1G0ROOQO,5;`,5;`O>gQdO,5;`OOQO-E8r-E8rO>tQ`O1G1fPOOO-E8h-E8hPOOO1G.g1G.gOOQP7+$]7+$]OOQP7+%d7+%dO&lQdO7+%dOOQS1G0Q1G0QO?PQaO'#F_O?ZQ`O,5:ZO?`Q!fO'#ElO@^QdO'#FWO@hQ`O,59^O@mQ!bO7+%dO&lQdO1G/bO@uQhO1G/fOOQW1G/j1G/jOOQW1G/d1G/dOAWQhO,5;bOOQO-E8t-E8tOAfQhO'#DZOAtQhO'#F^OBPQ`O'#F^OBUQ`O,5:TOOQS-E8k-E8kOOQ[1G.z1G.zOOQ[1G/Q1G/QOOQ[1G/T1G/TOOQ[1G/X1G/XOBZQdO,5:lOOQS7+%p7+%pOB`Q`O7+%pOBeQhO'#DYOBmQ`O,59sO'tQhO,59sOOQ[1G/q1G/qOBuQ`O1G/qOOQS7+%z7+%zOBzQbO'#DPOOQO'#Eb'#EbOCYQ`O'#EaOOQO'#Ea'#EaOCeQ`O'#EwOCmQdO,5:zOOQS,5:z,5:zOOQ[1G/m1G/mOOQS7+&V7+&VO-`Q`O7+&VOCxQ!fO'#EsO&lQdO'#EsOEPQdO7+%mOOQO7+%m7+%mOOQO1G0z1G0zOEdQ!bO<jAN>jOIUQaO,5;]OOQO-E8o-E8oOI`QdO,5;[OOQO-E8n-E8nOOQW<WO&lQdO1G0uOK]Q`O7+'OOOQO,5;a,5;aOOQO-E8s-E8sOOQW<t}!O?V!O!P?t!P!Q@]!Q![AU![!]BP!]!^B{!^!_C^!_!`DY!`!aDm!a!b$q!b!cEn!c!}$q!}#OG{#O#P$q#P#QH^#Q#R6W#R#o$q#o#pHo#p#q6W#q#rIQ#r#sIc#s#y$q#y#z%i#z$f$q$f$g%i$g#BY$q#BY#BZ%i#BZ$IS$q$IS$I_%i$I_$I|$q$I|$JO%i$JO$JT$q$JT$JU%i$JU$KV$q$KV$KW%i$KW&FU$q&FU&FV%i&FV;'S$q;'S;=`Iz<%lO$q`$tSOy%Qz;'S%Q;'S;=`%c<%lO%Q`%VS!a`Oy%Qz;'S%Q;'S;=`%c<%lO%Q`%fP;=`<%l%Q~%nh#s~OX%QX^'Y^p%Qpq'Yqy%Qz#y%Q#y#z'Y#z$f%Q$f$g'Y$g#BY%Q#BY#BZ'Y#BZ$IS%Q$IS$I_'Y$I_$I|%Q$I|$JO'Y$JO$JT%Q$JT$JU'Y$JU$KV%Q$KV$KW'Y$KW&FU%Q&FU&FV'Y&FV;'S%Q;'S;=`%c<%lO%Q~'ah#s~!a`OX%QX^'Y^p%Qpq'Yqy%Qz#y%Q#y#z'Y#z$f%Q$f$g'Y$g#BY%Q#BY#BZ'Y#BZ$IS%Q$IS$I_'Y$I_$I|%Q$I|$JO'Y$JO$JT%Q$JT$JU'Y$JU$KV%Q$KV$KW'Y$KW&FU%Q&FU&FV'Y&FV;'S%Q;'S;=`%c<%lO%Qj)OUOy%Qz#]%Q#]#^)b#^;'S%Q;'S;=`%c<%lO%Qj)gU!a`Oy%Qz#a%Q#a#b)y#b;'S%Q;'S;=`%c<%lO%Qj*OU!a`Oy%Qz#d%Q#d#e*b#e;'S%Q;'S;=`%c<%lO%Qj*gU!a`Oy%Qz#c%Q#c#d*y#d;'S%Q;'S;=`%c<%lO%Qj+OU!a`Oy%Qz#f%Q#f#g+b#g;'S%Q;'S;=`%c<%lO%Qj+gU!a`Oy%Qz#h%Q#h#i+y#i;'S%Q;'S;=`%c<%lO%Qj,OU!a`Oy%Qz#T%Q#T#U,b#U;'S%Q;'S;=`%c<%lO%Qj,gU!a`Oy%Qz#b%Q#b#c,y#c;'S%Q;'S;=`%c<%lO%Qj-OU!a`Oy%Qz#h%Q#h#i-b#i;'S%Q;'S;=`%c<%lO%Qj-iS!qY!a`Oy%Qz;'S%Q;'S;=`%c<%lO%Q~-xWOY-uZr-urs.bs#O-u#O#P.g#P;'S-u;'S;=`/c<%lO-u~.gOt~~.jRO;'S-u;'S;=`.s;=`O-u~.vXOY-uZr-urs.bs#O-u#O#P.g#P;'S-u;'S;=`/c;=`<%l-u<%lO-u~/fP;=`<%l-uj/nYjYOy%Qz!Q%Q!Q![0^![!c%Q!c!i0^!i#T%Q#T#Z0^#Z;'S%Q;'S;=`%c<%lO%Qj0cY!a`Oy%Qz!Q%Q!Q![1R![!c%Q!c!i1R!i#T%Q#T#Z1R#Z;'S%Q;'S;=`%c<%lO%Qj1WY!a`Oy%Qz!Q%Q!Q![1v![!c%Q!c!i1v!i#T%Q#T#Z1v#Z;'S%Q;'S;=`%c<%lO%Qj1}YrY!a`Oy%Qz!Q%Q!Q![2m![!c%Q!c!i2m!i#T%Q#T#Z2m#Z;'S%Q;'S;=`%c<%lO%Qj2tYrY!a`Oy%Qz!Q%Q!Q![3d![!c%Q!c!i3d!i#T%Q#T#Z3d#Z;'S%Q;'S;=`%c<%lO%Qj3iY!a`Oy%Qz!Q%Q!Q![4X![!c%Q!c!i4X!i#T%Q#T#Z4X#Z;'S%Q;'S;=`%c<%lO%Qj4`YrY!a`Oy%Qz!Q%Q!Q![5O![!c%Q!c!i5O!i#T%Q#T#Z5O#Z;'S%Q;'S;=`%c<%lO%Qj5TY!a`Oy%Qz!Q%Q!Q![5s![!c%Q!c!i5s!i#T%Q#T#Z5s#Z;'S%Q;'S;=`%c<%lO%Qj5zSrY!a`Oy%Qz;'S%Q;'S;=`%c<%lO%Qd6ZUOy%Qz!_%Q!_!`6m!`;'S%Q;'S;=`%c<%lO%Qd6tS!hS!a`Oy%Qz;'S%Q;'S;=`%c<%lO%Qb7VSZQOy%Qz;'S%Q;'S;=`%c<%lO%Q~7fWOY7cZw7cwx.bx#O7c#O#P8O#P;'S7c;'S;=`8z<%lO7c~8RRO;'S7c;'S;=`8[;=`O7c~8_XOY7cZw7cwx.bx#O7c#O#P8O#P;'S7c;'S;=`8z;=`<%l7c<%lO7c~8}P;=`<%l7cj9VSeYOy%Qz;'S%Q;'S;=`%c<%lO%Q~9hOd~n9oUWQvWOy%Qz!_%Q!_!`6m!`;'S%Q;'S;=`%c<%lO%Qj:YWvW!mQOy%Qz!O%Q!O!P:r!P!Q%Q!Q![=w![;'S%Q;'S;=`%c<%lO%Qj:wU!a`Oy%Qz!Q%Q!Q![;Z![;'S%Q;'S;=`%c<%lO%Qj;bY!a`#}YOy%Qz!Q%Q!Q![;Z![!g%Q!g!hO[!a`#}YOy%Qz!O%Q!O!P;Z!P!Q%Q!Q![=w![!g%Q!g!hyS!^YOy%Qz;'S%Q;'S;=`%c<%lO%Qj?[WvWOy%Qz!O%Q!O!P:r!P!Q%Q!Q![=w![;'S%Q;'S;=`%c<%lO%Qj?yU]YOy%Qz!Q%Q!Q![;Z![;'S%Q;'S;=`%c<%lO%Q~@bTvWOy%Qz{@q{;'S%Q;'S;=`%c<%lO%Q~@xS!a`#t~Oy%Qz;'S%Q;'S;=`%c<%lO%QjAZ[#}YOy%Qz!O%Q!O!P;Z!P!Q%Q!Q![=w![!g%Q!g!hHg[s]||-1},{term:125,get:s=>Xg[s]||-1},{term:4,get:s=>qg[s]||-1},{term:25,get:s=>jg[s]||-1},{term:123,get:s=>Yg[s]||-1}],tokenPrec:1963});let ss=null;function rs(){if(!ss&&typeof document=="object"&&document.body){let{style:s}=document.body,e=[],t=new Set;for(let i in s)i!="cssText"&&i!="cssFloat"&&typeof s[i]=="string"&&(/[A-Z]/.test(i)&&(i=i.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())),t.has(i)||(e.push(i),t.add(i)));ss=e.sort().map(i=>({type:"property",label:i,apply:i+": "}))}return ss||[]}const nl=["active","after","any-link","autofill","backdrop","before","checked","cue","default","defined","disabled","empty","enabled","file-selector-button","first","first-child","first-letter","first-line","first-of-type","focus","focus-visible","focus-within","fullscreen","has","host","host-context","hover","in-range","indeterminate","invalid","is","lang","last-child","last-of-type","left","link","marker","modal","not","nth-child","nth-last-child","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","part","placeholder","placeholder-shown","read-only","read-write","required","right","root","scope","selection","slotted","target","target-text","valid","visited","where"].map(s=>({type:"class",label:s})),sl=["above","absolute","activeborder","additive","activecaption","after-white-space","ahead","alias","all","all-scroll","alphabetic","alternate","always","antialiased","appworkspace","asterisks","attr","auto","auto-flow","avoid","avoid-column","avoid-page","avoid-region","axis-pan","background","backwards","baseline","below","bidi-override","blink","block","block-axis","bold","bolder","border","border-box","both","bottom","break","break-all","break-word","bullets","button","button-bevel","buttonface","buttonhighlight","buttonshadow","buttontext","calc","capitalize","caps-lock-indicator","caption","captiontext","caret","cell","center","checkbox","circle","cjk-decimal","clear","clip","close-quote","col-resize","collapse","color","color-burn","color-dodge","column","column-reverse","compact","condensed","contain","content","contents","content-box","context-menu","continuous","copy","counter","counters","cover","crop","cross","crosshair","currentcolor","cursive","cyclic","darken","dashed","decimal","decimal-leading-zero","default","default-button","dense","destination-atop","destination-in","destination-out","destination-over","difference","disc","discard","disclosure-closed","disclosure-open","document","dot-dash","dot-dot-dash","dotted","double","down","e-resize","ease","ease-in","ease-in-out","ease-out","element","ellipse","ellipsis","embed","end","ethiopic-abegede-gez","ethiopic-halehame-aa-er","ethiopic-halehame-gez","ew-resize","exclusion","expanded","extends","extra-condensed","extra-expanded","fantasy","fast","fill","fill-box","fixed","flat","flex","flex-end","flex-start","footnotes","forwards","from","geometricPrecision","graytext","grid","groove","hand","hard-light","help","hidden","hide","higher","highlight","highlighttext","horizontal","hsl","hsla","hue","icon","ignore","inactiveborder","inactivecaption","inactivecaptiontext","infinite","infobackground","infotext","inherit","initial","inline","inline-axis","inline-block","inline-flex","inline-grid","inline-table","inset","inside","intrinsic","invert","italic","justify","keep-all","landscape","large","larger","left","level","lighter","lighten","line-through","linear","linear-gradient","lines","list-item","listbox","listitem","local","logical","loud","lower","lower-hexadecimal","lower-latin","lower-norwegian","lowercase","ltr","luminosity","manipulation","match","matrix","matrix3d","medium","menu","menutext","message-box","middle","min-intrinsic","mix","monospace","move","multiple","multiple_mask_images","multiply","n-resize","narrower","ne-resize","nesw-resize","no-close-quote","no-drop","no-open-quote","no-repeat","none","normal","not-allowed","nowrap","ns-resize","numbers","numeric","nw-resize","nwse-resize","oblique","opacity","open-quote","optimizeLegibility","optimizeSpeed","outset","outside","outside-shape","overlay","overline","padding","padding-box","painted","page","paused","perspective","pinch-zoom","plus-darker","plus-lighter","pointer","polygon","portrait","pre","pre-line","pre-wrap","preserve-3d","progress","push-button","radial-gradient","radio","read-only","read-write","read-write-plaintext-only","rectangle","region","relative","repeat","repeating-linear-gradient","repeating-radial-gradient","repeat-x","repeat-y","reset","reverse","rgb","rgba","ridge","right","rotate","rotate3d","rotateX","rotateY","rotateZ","round","row","row-resize","row-reverse","rtl","run-in","running","s-resize","sans-serif","saturation","scale","scale3d","scaleX","scaleY","scaleZ","screen","scroll","scrollbar","scroll-position","se-resize","self-start","self-end","semi-condensed","semi-expanded","separate","serif","show","single","skew","skewX","skewY","skip-white-space","slide","slider-horizontal","slider-vertical","sliderthumb-horizontal","sliderthumb-vertical","slow","small","small-caps","small-caption","smaller","soft-light","solid","source-atop","source-in","source-out","source-over","space","space-around","space-between","space-evenly","spell-out","square","start","static","status-bar","stretch","stroke","stroke-box","sub","subpixel-antialiased","svg_masks","super","sw-resize","symbolic","symbols","system-ui","table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row","table-row-group","text","text-bottom","text-top","textarea","textfield","thick","thin","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","to","top","transform","translate","translate3d","translateX","translateY","translateZ","transparent","ultra-condensed","ultra-expanded","underline","unidirectional-pan","unset","up","upper-latin","uppercase","url","var","vertical","vertical-text","view-box","visible","visibleFill","visiblePainted","visibleStroke","visual","w-resize","wait","wave","wider","window","windowframe","windowtext","words","wrap","wrap-reverse","x-large","x-small","xor","xx-large","xx-small"].map(s=>({type:"keyword",label:s})).concat(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"].map(s=>({type:"constant",label:s}))),Ug=["a","abbr","address","article","aside","b","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","dd","del","details","dfn","dialog","div","dl","dt","em","figcaption","figure","footer","form","header","hgroup","h1","h2","h3","h4","h5","h6","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","main","meter","nav","ol","output","p","pre","ruby","section","select","small","source","span","strong","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","tr","u","ul"].map(s=>({type:"type",label:s})),Kg=["@charset","@color-profile","@container","@counter-style","@font-face","@font-feature-values","@font-palette-values","@import","@keyframes","@layer","@media","@namespace","@page","@position-try","@property","@scope","@starting-style","@supports","@view-transition"].map(s=>({type:"keyword",label:s})),Ke=/^(\w[\w-]*|-\w[\w-]*|)$/,_g=/^-(-[\w-]*)?$/;function Zg(s,e){var t;if((s.name=="("||s.type.isError)&&(s=s.parent||s),s.name!="ArgList")return!1;let i=(t=s.parent)===null||t===void 0?void 0:t.firstChild;return(i==null?void 0:i.name)!="Callee"?!1:e.sliceString(i.from,i.to)=="var"}const rl=new Cu,Jg=["Declaration"];function em(s){for(let e=s;;){if(e.type.isTop)return e;if(!(e=e.parent))return s}}function Nh(s,e,t){if(e.to-e.from>4096){let i=rl.get(e);if(i)return i;let n=[],r=new Set,o=e.cursor(_.IncludeAnonymous);if(o.firstChild())do for(let l of Nh(s,o.node,t))r.has(l.label)||(r.add(l.label),n.push(l));while(o.nextSibling());return rl.set(e,n),n}else{let i=[],n=new Set;return e.cursor().iterate(r=>{var o;if(t(r)&&r.matchContext(Jg)&&((o=r.node.nextSibling)===null||o===void 0?void 0:o.name)==":"){let l=s.sliceString(r.from,r.to);n.has(l)||(n.add(l),i.push({label:l,type:"variable"}))}}),i}}const tm=s=>e=>{let{state:t,pos:i}=e,n=ge(t).resolveInner(i,-1),r=n.type.isError&&n.from==n.to-1&&t.doc.sliceString(n.from,n.to)=="-";if(n.name=="PropertyName"||(r||n.name=="TagName")&&/^(Block|Styles)$/.test(n.resolve(n.to).name))return{from:n.from,options:rs(),validFor:Ke};if(n.name=="ValueName")return{from:n.from,options:sl,validFor:Ke};if(n.name=="PseudoClassName")return{from:n.from,options:nl,validFor:Ke};if(s(n)||(e.explicit||r)&&Zg(n,t.doc))return{from:s(n)||r?n.from:i,options:Nh(t.doc,em(n),s),validFor:_g};if(n.name=="TagName"){for(let{parent:a}=n;a;a=a.parent)if(a.name=="Block")return{from:n.from,options:rs(),validFor:Ke};return{from:n.from,options:Ug,validFor:Ke}}if(n.name=="AtKeyword")return{from:n.from,options:Kg,validFor:Ke};if(!e.explicit)return null;let o=n.resolve(i),l=o.childBefore(i);return l&&l.name==":"&&o.name=="PseudoClassSelector"?{from:i,options:nl,validFor:Ke}:l&&l.name==":"&&o.name=="Declaration"||o.name=="ArgList"?{from:i,options:sl,validFor:Ke}:o.name=="Block"||o.name=="Styles"?{from:i,options:rs(),validFor:Ke}:null},im=tm(s=>s.name=="VariableName"),ol=cn.define({name:"css",parser:Gg.configure({props:[za.add({Declaration:Gu()}),Uu.add({"Block KeyframeList":Ku})]}),languageData:{commentTokens:{block:{open:"/*",close:"*/"}},indentOnInput:/^\s*\}$/,wordChars:"-"}});function nm(){return new $u(ol,ol.data.of({autocomplete:im}))}const ll=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class Ih{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(ll(l)):ll,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return be(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Us(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=We(e);let n=this.normalize(t);if(n.length)for(let r=0,o=i;;r++){let l=n.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}o==i&&re||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function om(s){return[cm,fm]}const lm=R.mark({class:"cm-selectionMatch"}),am=R.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function al(s,e,t,i){return(t==0||s(e.sliceDoc(t-1,t))!=re.Word)&&(i==e.doc.length||s(e.sliceDoc(i,i+1))!=re.Word)}function hm(s,e,t,i){return s(e.sliceDoc(t,t+1))==re.Word&&s(e.sliceDoc(i-1,i))==re.Word}const fm=Pe.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.selectionSet||s.docChanged||s.viewportChanged)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let e=s.state.facet(rm),{state:t}=s,i=t.selection;if(i.ranges.length>1)return R.none;let n=i.main,r,o=null;if(n.empty){if(!e.highlightWordAroundCursor)return R.none;let a=t.wordAt(n.head);if(!a)return R.none;o=t.charCategorizer(n.head),r=t.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a200)return R.none;if(e.wholeWords){if(r=t.sliceDoc(n.from,n.to),o=t.charCategorizer(n.head),!(al(o,t,n.from,n.to)&&hm(o,t,n.from,n.to)))return R.none}else if(r=t.sliceDoc(n.from,n.to),!r)return R.none}let l=[];for(let a of s.visibleRanges){let f=new Ih(t.doc,r,a.from,a.to);for(;!f.next().done;){let{from:h,to:c}=f.value;if((!o||al(o,t,h,c))&&(n.empty&&h<=n.from&&c>=n.to?l.push(am.range(h,c)):(h>=n.to||c<=n.from)&&l.push(lm.range(h,c)),l.length>e.maxMatches))return R.none}}return R.set(l)}},{decorations:s=>s.decorations}),cm=M.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),um=M.theme({"&":{color:"inherit",fontSize:"90%",backgroundColor:"inherit",outline:"none !important",display:"block !important",width:"100%",minHeight:"inherit",cursor:"text",height:"100%"},".cm-content":{lineHeight:1.75,fontFamily:"var(--font-mono)",caretColor:"hsl(var(--foreground, 0 0% 100%))",padding:"10px 0"},".cm-scroller":{minHeight:"inherit",height:"100%"},".cm-cursor":{borderLeftColor:"inherit"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"rgba(59, 130, 246, 0.25)"},".cm-gutters":{color:"inherit",backgroundColor:"inherit",borderRight:"unset"},".cm-lineNumbers .cm-gutterElement":{paddingRight:"24px",opacity:"75%"},".cm-lineWrapping ":{wordBreak:"break-all !important"},".cm-tooltip":{backgroundColor:"hsl(var(--popover, 0 0% 10%))",color:"hsl(var(--popover-foreground, 0 0% 98%))",border:"1px solid hsl(var(--border, 0 0% 25%))",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",zIndex:60},".cm-tooltip-autocomplete":{"& > ul":{maxHeight:"240px",overflow:"auto"}},".cm-tooltip-autocomplete ul li":{padding:"6px 8px"},".cm-tooltip-autocomplete ul li[aria-selected]":{backgroundColor:"hsl(var(--accent, 0 0% 20%))",color:"hsl(var(--accent-foreground, 0 0% 98%))"},".cm-completionMatchedText":{color:"#60a5fa",fontWeight:600,textDecoration:"none"}}),dm=Pn.define([{tag:[x.comment],color:"#64748b"},{tag:[x.keyword,x.typeName,x.typeOperator],color:"#7c3aed",fontWeight:"500"},{tag:[x.string,x.meta,x.regexp],color:"#16a34a"},{tag:[x.number,x.bool],color:"#ea580c"},{tag:[x.operator,x.name],color:"#0ea5e9"},{tag:[x.variableName,x.attributeName,x.propertyName],color:"#0ea5e9"},{tag:[x.className],color:"#22d3ee"},{tag:[x.tagName],color:"#e11d48"},{tag:[x.heading,x.strong],color:"#111827",fontWeight:"bold"},{tag:[x.emphasis],color:"#111827",fontStyle:"italic"},{tag:[x.link],textDecoration:"underline"},{tag:[x.strikethrough],textDecoration:"line-through"},{tag:[x.invalid],color:"#ef4444"}]),pm=[um,Zu(dm)],gm=({value:s,setValue:e})=>{const t=En.useRef(null),i=En.useRef(null);return En.useEffect(()=>{if(!t.current)return;const n=s||"",r=I.create({doc:n,extensions:[gu(),eu(),Ou(),nm(),pm,hp(),ld(),Vd(),Zd(),om(),hr.of([...dg,...Op,...Za,...qd]),M.updateListener.of(l=>{if(l.docChanged){const a=l.state.doc.toString();e(a)}}),M.lineWrapping]}),o=new M({state:r,parent:t.current});return i.current=o,()=>o.destroy()},[t]),ye.jsx("div",{ref:t,className:"h-[420px] w-full rounded-md border",onMouseDown:n=>{var o;n.target.closest(".cm-editor")||(n.preventDefault(),(o=i.current)==null||o.focus())}})},Am=()=>{const{props:s}=zh(),{translate:e}=s,{settings:t,button:i}=e,n=s.system.fields,{data:r,setData:o,post:l,errors:a,processing:f}=$h({...s.system.fields,global_style:n.global_style}),h=c=>{c.preventDefault(),l(route("settings.system.update",{id:s.system.id}),{showProgress:!1,preserveScroll:!0})};return ye.jsxs(Wh,{children:[ye.jsxs(Hh,{className:"p-4 sm:p-6",children:[ye.jsx(Xh,{className:"flex items-center gap-2",children:t.custom_global_style}),ye.jsx(qh,{className:"hidden sm:block",children:t.css_description})]}),ye.jsx(Yh,{}),ye.jsx(jh,{className:"p-4 sm:p-6",children:ye.jsxs("form",{onSubmit:h,className:"space-y-6",children:[ye.jsxs("div",{children:[ye.jsx(gm,{value:r.global_style,setValue:c=>o("global_style",c)}),ye.jsx(Fh,{message:a.global_style})]}),ye.jsx("div",{className:"flex justify-end",children:ye.jsx(Vh,{loading:f,type:"submit",children:i.save_changes})})]})})]})};export{Am as default};