import{r as H,j as y,B as le,K as gl,L as St,X as Zs,D as Iu,a as Wu,$ as xl,c as Fu,d as Vu,E as Hu,o as zu}from"./index-CwVkcMR-.js";import{u as Ah}from"./use-toast-C8N6561m.js";import{k as wt}from"./index-DK2BjZ0M.js";import{C as bl}from"./copy-CKzeWvtb.js";import{S as xs}from"./sparkles-BA2sXk5-.js";import{S as yl}from"./save-CdpyeGoy.js";import{S as kl,a as wl,b as vl,c as Sl,d as Ol}from"./select-CGtvCG8I.js";import{x as Qu,a as $u}from"./xterm-DSqgeKvr.js";import{B as ju}from"./box-D54sw_gB.js";import{R as qu}from"./rotate-cw-BWMnGC9F.js";import{M as Xu,a as Uu}from"./minimize-2-Dk2LAAKi.js";import{B as Yu}from"./badge-DgJ0w7jf.js";import{H as _u}from"./hard-drive-CGq_SnM5.js";import{A as Ku}from"./arrow-left-B1MijWEO.js";import{U as Gu}from"./upload-CSuL4aK-.js";import{R as Ju}from"./refresh-cw-DM6JPbZg.js";import{F as Zu,a as ed}from"./folder-Jx79bRH4.js";import{D as td}from"./download-BgEJ-n5L.js";function Tr(){return Tr=Object.assign?Object.assign.bind():function(s){for(var e=1;e|]/.test(P)}function A(N){for(i++;iP.startsWith(D)):!1}for(;i=2&&D<=4&&P.startsWith("pod-template-hash")&&P.includes(":")){i++;continue}if(D===2&&M&&n.has(M)){S(N)?i++:A(2);continue}if(D===2&&M&&r.has(M)){A(2);continue}if(f&&D>2&&M&&a.has(M)){if(S(N))i++;else{const R=P.split(":").slice(1).join(":").trim();/^[>|]/.test(R)?A(D):i++}continue}}if(u){if(D===2&&M==="template"){t.push(N),i++;continue}if(D===2&&M&&o[M]){const F=P.split(":").slice(1).join(":").trim();if(o[M].includes(F)){i++;continue}}if(D===2&&M==="nodeName"){i++;continue}if(D===2&&M==="spec"){d=!0,k=D,t.push(N),i++;continue}}if(d&&D>k){if(M==="containers"){p=!0,m=!1,t.push(N),i++;continue}if(M==="initContainers"){m=!0,p=!1,t.push(N),i++;continue}if(M==="volumes"){x=!0,t.push(N),i++;continue}if(M&&o[M]){const F=P.split(":").slice(1).join(":").trim();if(o[M].includes(F)){i++;continue}}if(M==="nodeName"){i++;continue}if(M==="serviceAccount"&&P.endsWith(":")){S(N)?i++:A(D);continue}}if((p||m)&&D>=6){if(M&&l[M]){const F=P.split(":").slice(1).join(":").trim();if(l[M].includes(F)){i++;continue}}if(M==="volumeMounts"&&(g=!0),g&&P.startsWith("- name:")){let F=[N],R=i+1,C=!1;for(;R=4&&P.startsWith("- name:")&&O(P)){const F=D;for(i++;i0&&t[t.length-1].trim()===""){i++;continue}t.push(N),i++}return t.join(` `).replace(/\n{3,}/g,` `).trimEnd()+` `}function sd(s){return s.includes("mountPath:")&&(s.includes("/var/run/secrets/kubernetes.io")||s.includes("/var/run/secrets/sa"))}const ys={green:"#10b981",orange:"#f59e0b",red:"#ef4444",blue:"#326CE5"};function Ey(s){if(!s)return"#64748b";const e=s.toLowerCase();return["running","available","ready","active","completed","succeeded"].includes(e)?ys.green:["pending","updating","progressing","containercreating"].includes(e)?ys.orange:["failed","error","crashloopbackoff","imagepullbackoff","errimageneverpull"].includes(e)?ys.red:ys.blue}function Ly(s){if(!s)return"-";const e=new Date(s);if(isNaN(e.getTime()))return s;const t=i=>String(i).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}function Ny(s,e){if(!s||!e)return null;const t=new Date(s).getTime(),i=new Date(e).getTime();return isNaN(t)||isNaN(i)||i{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=Mh[i])e=i+1;else return!0;if(e==t)return!1}}function Cl(s){return s>=127462&&s<=127487}const Al=8205;function rd(s,e,t=!0,i=!0){return(t?Ph:od)(s,e,i)}function Ph(s,e,t){if(e==s.length)return e;e&&Th(s.charCodeAt(e))&&Dh(s.charCodeAt(e-1))&&e--;let i=_n(s,e);for(e+=Ml(i);e=0&&Cl(_n(s,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function od(s,e,t){for(;e>0;){let i=Ph(s,e-2,t);if(i=56320&&s<57344}function Dh(s){return s>=55296&&s<56320}function Ml(s){return s<65536?1:2}class Y{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]=xi(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),tt.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]=xi(this,e,t);let i=[];return this.decompose(e,t,i,0),tt.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 Wi(this),r=new Wi(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 Wi(this,e)}iterRange(e,t=this.length){return new Rh(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 Bh(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]?Y.empty:e.length<=32?new ne(e):tt.from(ne.split(e,[]))}}class ne extends Y{constructor(e,t=ld(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 ad(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new ne(Pl(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=js(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new ne(l,o.length+r.length));else{let a=l.length>>1;i.push(new ne(l.slice(0,a)),new ne(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof ne))return super.replace(e,t,i);[e,t]=xi(this,e,t);let n=js(this.text,js(i.text,Pl(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new ne(n,r):tt.from(ne.split(n,[]),r)}sliceString(e,t=this.length,i=` `){[e,t]=xi(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 ne(i,n)),i=[],n=-1);return n>-1&&t.push(new ne(i,n)),t}}class tt extends Y{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 h=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=xi(this,e,t),i.lines=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines>4&&a.lines>h>>6){let c=this.children.slice();return c[n]=a,new tt(c,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]=xi(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 tt))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],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,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 ne(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof tt)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof ne&&a&&(p=c[c.length-1])instanceof ne&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new ne(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:tt.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new tt(l,t)}}Y.empty=new ne([""],0);function ld(s){let e=-1;for(let t of s)e+=t.length+1;return e}function js(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 ne?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 ne?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 ne){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 ne?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 Rh{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new Wi(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 Bh{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"&&(Y.prototype[Symbol.iterator]=function(){return this.iter()},Wi.prototype[Symbol.iterator]=Rh.prototype[Symbol.iterator]=Bh.prototype[Symbol.iterator]=function(){return this});class ad{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 xi(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function fe(s,e,t=!0,i=!0){return rd(s,e,t,i)}function hd(s){return s>=56320&&s<57344}function cd(s){return s>=55296&&s<56320}function Ce(s,e){let t=s.charCodeAt(e);if(!cd(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return hd(i)?(t-55296<<10)+(i-56320)+65536:t}function Ro(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function it(s){return s<65536?1:2}const Rr=/\r\n?|\n/;var Se=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(Se||(Se={}));class lt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return r+(e-n);r+=l}else{if(i!=Se.Simple&&h>=e&&(i==Se.TrackDel&&ne||i==Se.TrackBefore&&ne))return null;if(h>e||h==e&&t<0&&!l)return e==n||t<0?r:r+a;r+=a}n=h}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 lt(e)}static create(e){return new lt(e)}}class ae extends lt{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 Br(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return Er(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(c),l+=c}let h=e[o++];for(;l>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!n.length)return;ou||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?Y.of(d.split(i||Rr)):d:Y.empty,m=p.length;if(f==u&&m==0)return;fo&&xe(n,f-o,-1),xe(n,u-f,m),Ot(r,n,p),o=u}}return h(e),a(!l),l}static empty(e){return new ae(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,h,r,c,f),n=h,r=c}}}function Er(s,e,t,i=!1){let n=[],r=i?[]:null,o=new Xi(s),l=new Xi(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 h=Math.min(o.len,l.len);xe(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len=0&&a=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.lena||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class Xi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>1;return t>=e.length?Y.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?Y.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 $t{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 $t(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return v.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return v.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return v.range(e.anchor,e.head)}static create(e,t,i){return new $t(e,t,i)}}class v{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:v.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 v(e.ranges.map(t=>$t.fromJSON(t)),e.main)}static single(e,t=e){return new v([v.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;nn.from-r.from),t=e.indexOf(i);for(let n=1;nr.head?v.range(a,l):v.range(l,a))}}return new v(e,t)}}function Lh(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Bo=0;class I{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=Bo++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new I(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Eo),!!e.static,e.enables)}of(e){return new qs([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new qs(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new qs(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Eo(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class qs{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=Bo++}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,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||Lr(f,c)){let d=i(f);if(l?!Tl(d,f.values[o],n):!n(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let m=tn(u,p);if(this.dependencies.every(g=>g instanceof I?u.facet(g)===f.facet(g):g instanceof ye?u.field(g,!1)==f.field(g,!1):!0)||(l?Tl(d=i(f),m,n):n(d=i(f),m)))return f.values[o]=m,0}else d=i(f);return f.values[o]=d,1}}}}function Tl(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 h=[];for(let c=0;ci===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(ks).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>{let r=i.facet(ks),o=n.facet(ks),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,ks.of({field:this,create:e})]}get extension(){return this}}const Ht={lowest:4,low:3,default:2,high:1,highest:0};function Ti(s){return e=>new Nh(e,s)}const ei={highest:Ti(Ht.highest),high:Ti(Ht.high),default:Ti(Ht.default),low:Ti(Ht.low),lowest:Ti(Ht.lowest)};class Nh{constructor(e,t){this.inner=e,this.prec=t}}class Dn{of(e){return new Nr(this,e)}reconfigure(e){return Dn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Nr{constructor(e,t){this.compartment=e,this.inner=t}}class en{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 ud(e,t,o))u instanceof ye?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of n)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=i?.config.facets;for(let u in r){let d=r[u],p=d[0].facet,m=c&&c[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,Eo(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(x=>x.value));a.push(i&&p.compare(g,i.facet(p))?i.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(x=>g.dynamicSlot(x)));l[p.id]=h.length<<1,h.push(g=>fd(g,p,d))}}let f=h.map(u=>u(l));return new en(e,o,f,l,a,r)}}function ud(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 h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof Nr&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof Nr){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof Nh)r(o.inner,o.prec);else if(o instanceof ye)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof qs)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,Ht.default);else{let h=o.extension;if(!h)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(h,l)}}return r(s,Ht.default),i.reduce((o,l)=>o.concat(l))}function Fi(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 tn(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const Ih=I.define(),Ir=I.define({combine:s=>s.some(e=>e),static:!0}),Wh=I.define({combine:s=>s.length?s[0]:void 0,static:!0}),Fh=I.define(),Vh=I.define(),Hh=I.define(),zh=I.define({combine:s=>s.length?s[0]:!1});class at{constructor(e,t){this.type=e,this.value=t}static define(){return new dd}}class dd{of(e){return new at(this,e)}}class pd{constructor(e){this.map=e}of(e){return new $(this,e)}}class ${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 $(this.type,t)}is(e){return this.type==e}static define(e={}){return new pd(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}}$.reconfigure=$.define();$.appendConfig=$.define();class he{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&&Lh(i,t.newLength),r.some(l=>l.type==he.time)||(this.annotations=r.concat(he.time.of(Date.now())))}static create(e,t,i,n,r,o){return new he(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(he.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}he.time=at.define();he.userEvent=at.define();he.addToHistory=at.define();he.remote=at.define();function md(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 he?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof he?s=r[0]:s=$h(e,ci(r),!1)}return s}function xd(s){let e=s.startState,t=e.facet(Hh),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=Qh(i,Wr(e,r,s.changes.newLength),!0))}return i==s?s:he.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const bd=[];function ci(s){return s==null?bd:Array.isArray(s)?s:[s]}var ee=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(ee||(ee={}));const yd=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Fr;try{Fr=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function kd(s){if(Fr)return Fr.test(s);for(let e=0;e"€"&&(t.toUpperCase()!=t.toLowerCase()||yd.test(t)))return!0}return!1}function wd(s){return e=>{if(!/\S/.test(e))return ee.Space;if(kd(e))return ee.Word;for(let t=0;t-1)return ee.Word;return ee.Other}}class U{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(h,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is($.reconfigure)?(t=null,i=l.value):l.is($.appendConfig)&&(t=null,i=ci(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=en.resolve(i,n,this),r=new U(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Ir)?e.newSelection:e.newSelection.asSingle();new U(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:v.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=ci(i.effects);for(let l=1;lo.spec.fromJSON(l,a)))}}return U.create({doc:e.doc,selection:v.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=en.resolve(e.extensions||[],new Map),i=e.doc instanceof Y?e.doc:Y.of((e.doc||"").split(t.staticFacet(U.lineSeparator)||Rr)),n=e.selection?e.selection instanceof v?e.selection:v.single(e.selection.anchor,e.selection.head):v.single(0);return Lh(n,i.length),t.staticFacet(Ir)||(n=n.asSingle()),new U(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(U.tabSize)}get lineBreak(){return this.facet(U.lineSeparator)||` `}get readOnly(){return this.facet(zh)}phrase(e,...t){for(let i of this.facet(U.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(Ih))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return wd(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=fe(t,o,!1);if(r(t.slice(a,o))!=ee.Word)break;o=a}for(;ls.length?s[0]:4});U.lineSeparator=Wh;U.readOnly=zh;U.phrases=I.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])}});U.languageData=Ih;U.changeFilter=Fh;U.transactionFilter=Vh;U.transactionExtender=Hh;Dn.reconfigure=$.define();function ht(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 Mt{eq(e){return this==e}range(e,t=e){return Vr.create(e,t,this)}}Mt.prototype.startSide=Mt.prototype.endSide=0;Mt.prototype.point=!1;Mt.prototype.mapMode=Se.TrackDel;function Lo(s,e){return s==e||s.constructor==e.constructor&&s.eq(e)}let Vr=class jh{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new jh(e,t,i)}};function Hr(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class No{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,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=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&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),i.push(h),n.push(u-o),r.push(d-o))}return{mapped:i.length?new No(n,r,i,l):null,pos:o}}}class X{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 X(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(Hr)),this.isEmpty)return t.length?X.of(t):this;let l=new qh(this,null,-1).goto(0),a=0,h=[],c=new mt;for(;l.value||a=0){let f=t[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}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 Ui.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ui.from(e).goto(t)}static compare(e,t,i,n,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=Dl(o,l,i),h=new Di(o,a,r),c=new Di(l,a,r);i.iterGaps((f,u,d)=>Rl(h,f,c,u,d,n)),i.empty&&i.length==0&&Rl(h,0,c,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Dl(r,o),a=new Di(r,l,0).goto(i),h=new Di(o,l,0).goto(i);for(;;){if(a.to!=h.to||!zr(a.active,h.active)||a.point&&(!h.point||!Lo(a.point,h.point)))return!1;if(a.to>n)return!0;a.next(),h.next()}}static spans(e,t,i,n,r=-1){let o=new Di(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFroml&&(n.span(l,h,o.active,a),a=o.openEnd(h));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 mt;for(let n of e instanceof Vr?[e]:t?vd(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return X.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=X.empty;n=n.nextLayer)t=new X(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}X.empty=new X([],[],null,-1);function vd(s){if(s.length>1)for(let e=s[0],t=1;t0)return s.slice().sort(Hr);e=i}return s}X.empty.nextLayer=X.empty;class mt{finishChunk(e){this.chunks.push(new No(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 mt)).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(X.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=X.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Dl(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 qh(o,t,i,r));return n.length==1?n[0]:new Ui(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--)Kn(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--)Kn(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(),Kn(this.heap,0)}}}function Kn(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 Di{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=Ui.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){ws(this.active,e),ws(this.activeTo,e),ws(this.activeRank,e),this.minActive=Bl(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t0;)t++;vs(this.active,t,i),vs(this.activeTo,t,n),vs(this.activeRank,t,r),e&&vs(e,t,this.cursor.from),this.minActive=Bl(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&&ws(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 Rl(s,e,t,i,n,r){s.goto(e),t.goto(i);let o=i+n,l=i,a=i-e,h=!!r.boundChange;for(let c=!1;;){let f=s.to+a-t.to,u=f||s.endSide-t.endSide,d=u<0?s.to+a:t.to,p=Math.min(d,o);if(s.point||t.point?(s.point&&t.point&&Lo(s.point,t.point)&&zr(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,p,s.point,t.point),c=!1):(c&&r.boundChange(l),p>l&&!zr(s.active,t.active)&&r.compareRange(l,p,s.active,t.active),h&&po)break;l=d,u<=0&&s.next(),u>=0&&t.next()}}function zr(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 Bl(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=fe(s,n)}return i===!0?-1:s.length}const $r="ͼ",El=typeof Symbol>"u"?"__"+$r:Symbol.for($r),jr=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Ll=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Pt{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((i&&!f&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(` `)}static newName(){let e=Ll[El]||1;return Ll[El]=e+1,$r+e.toString(36)}static mount(e,t,i){let n=e[jr],r=i&&i.nonce;n?r&&n.setNonce(r):n=new Sd(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let Nl=new Map;class Sd{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let r=Nl.get(i);if(r)return e[jr]=r;this.sheet=new n.CSSStyleSheet,Nl.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[jr]=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 h=0;h",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Od=typeof navigator<"u"&&/Mac/.test(navigator.platform),Cd=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var me=0;me<10;me++)Tt[48+me]=Tt[96+me]=String(me);for(var me=1;me<=24;me++)Tt[me+111]="F"+me;for(var me=65;me<=90;me++)Tt[me]=String.fromCharCode(me+32),Yi[me]=String.fromCharCode(me);for(var Gn in Tt)Yi.hasOwnProperty(Gn)||(Yi[Gn]=Tt[Gn]);function Ad(s){var e=Od&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||Cd&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?Yi:Tt)[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}function _(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var n=t[i];typeof n=="string"?s.setAttribute(i,n):n!=null&&(s[i]=n)}e++}for(;e2);var W={mac:Fl||/Mac/.test(ve.platform),windows:/Win/.test(ve.platform),linux:/Linux|X11/.test(ve.platform),ie:Rn,ie_version:Uh?qr.documentMode||6:Ur?+Ur[1]:Xr?+Xr[1]:0,gecko:Il,gecko_version:Il?+(/Firefox\/(\d+)/.exec(ve.userAgent)||[0,0])[1]:0,chrome:!!Jn,chrome_version:Jn?+Jn[1]:0,ios:Fl,android:/Android\b/.test(ve.userAgent),webkit:Wl,webkit_version:Wl?+(/\bAppleWebKit\/(\d+)/.exec(ve.userAgent)||[0,0])[1]:0,safari:Yr,safari_version:Yr?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ve.userAgent)||[0,0])[1]:0,tabSize:qr.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Io(s,e){for(let t in s)t=="class"&&e.class?e.class+=" "+s.class:t=="style"&&e.style?e.style+=";"+s.style:e[t]=s[t];return e}const sn=Object.create(null);function Wo(s,e,t){if(s==e)return!0;s||(s=sn),e||(e=sn);let i=Object.keys(s),n=Object.keys(e);if(i.length-0!=n.length-0)return!1;for(let r of i)if(r!=t&&(n.indexOf(r)==-1||s[r]!==e[r]))return!1;return!0}function Md(s,e){for(let t=s.attributes.length-1;t>=0;t--){let i=s.attributes[t].name;e[i]==null&&s.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?s.style.cssText=i:s.getAttribute(t)!=i&&s.setAttribute(t,i)}}function Vl(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 Pd(s){let e=Object.create(null);for(let t=0;t0?3e8:-4e8:t>0?1e8:-1e8,new Kt(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}=Yh(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new Kt(e,i,n,t,e.widget||null,!0)}static line(e){return new cs(e)}static set(e,t=!1){return X.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}z.none=X.empty;class hs extends z{constructor(e){let{start:t,end:i}=Yh(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Io(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||sn}eq(e){return this==e||e instanceof hs&&this.tagName==e.tagName&&Wo(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}hs.prototype.point=!1;class cs extends z{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof cs&&this.spec.class==e.spec.class&&Wo(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)}}cs.prototype.mapMode=Se.TrackBefore;cs.prototype.point=!0;class Kt extends z{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?Se.TrackBefore:Se.TrackAfter:Se.TrackDel}get type(){return this.startSide!=this.endSide?ge.WidgetRange:this.startSide<=0?ge.WidgetBefore:ge.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof Kt&&Td(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)}}Kt.prototype.point=!0;function Yh(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 Td(s,e){return s==e||!!(s&&e&&s.compare(e))}function fi(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 _i extends Mt{constructor(e,t,i){super(),this.tagName=e,this.attributes=t,this.rank=i}eq(e){return e==this||e instanceof _i&&this.tagName==e.tagName&&Wo(this.attributes,e.attributes)}static create(e){return new _i(e.tagName,e.attributes||sn,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return X.of(e,t)}}_i.prototype.startSide=_i.prototype.endSide=-1;function Ki(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function _r(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function Vi(s,e){if(!e.anchorNode)return!1;try{return _r(s,e.anchorNode)}catch{return!1}}function Hi(s){return s.nodeType==3?Ji(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function zi(s,e,t,i){return t?Hl(s,e,t,i,-1)||Hl(s,e,t,i,1):!1}function Dt(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function nn(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Hl(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:gt(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=Dt(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?gt(s):0}else return!1}}function gt(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function Gi(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function Dd(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 _h(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 Rd(s,e,t,i,n,r,o,l){let a=s.ownerDocument,h=a.defaultView||window;for(let c=s,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==a.body,p=1,m=1;if(d)u=Dd(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let k=c.getBoundingClientRect();({scaleX:p,scaleY:m}=_h(c,k)),u={left:k.left,right:k.left+c.clientWidth*p,top:k.top,bottom:k.top+c.clientHeight*m}}let g=0,x=0;if(n=="nearest")e.top0&&e.bottom>u.bottom+x&&(x=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(x=e.bottom-u.bottom+o,t<0&&e.top-x0&&e.right>u.right+g&&(g=e.right-u.right+r)):e.right>u.right-r&&(g=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)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Kh(s,e=!0){let t=s.ownerDocument,i=null,n=null;for(let r=s.parentNode;r&&!(r==t.body||(!e||i)&&n);)if(r.nodeType==1)!n&&r.scrollHeight>r.clientHeight&&(n=r),e&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:n}}class Bd{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?gt(t):0),i,Math.min(e.focusOffset,i?gt(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let Vt=null;W.safari&&W.safari_version>=26&&(Vt=!1);function Gh(s){if(s.setActive)return s.setActive();if(Vt)return s.focus(Vt);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(Vt==null?{get preventScroll(){return Vt={preventScroll:!0},!0}}:void 0),!Vt){Vt=!1;for(let t=0;tMath.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Zh(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=gt(t)}else if(t.parentNode&&!nn(t))i=Dt(t),t=t.parentNode;else return null}}function ec(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i=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 sc(s,e){if(s.length!=e.length)return!1;for(let t=0;t=0;m-=3)if(Ge[m+1]==-d){let g=Ge[m+2],x=g&2?n:g&4?g&1?r:n:0;x&&(G[f]=G[Ge[m]]=x),l=m;break}}else{if(Ge.length==189)break;Ge[l++]=f,Ge[l++]=u,Ge[l++]=a}else if((p=G[f])==2||p==1){let m=p==n;a=m?0:1;for(let g=l-3;g>=0;g-=3){let x=Ge[g+2];if(x&2)break;if(m)Ge[g+2]|=2;else{if(x&4)break;Ge[g+2]|=4}}}}}function Hd(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==g&&(p=t[--m].from,g=m?t[m-1].to:s),G[--p]=d;a=c}else r=h,a++}}}function Gr(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=e,h=0;aa&&o.push(new nt(a,m.from,d));let g=m.direction==Gt!=!(d%2);Jr(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?G[p]!=l:G[p]==l))break;p++}u?Gr(s,a,p,i+1,n,u,o):ae;){let c=!0,f=!1;if(!h||a>r[h-1].to){let m=G[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(f)break e;let m=r[--h];if(!c)for(let g=m.from,x=h;;){if(g==e)break e;if(x&&r[x-1].to==g)g=r[--x].from;else{if(G[g-1]==l)break e;break}}if(u)u.push(m);else{m.toG.length;)G[G.length]=256;let i=[],n=e==Gt?0:1;return Jr(s,n,n,t,0,s.length,i),i}function nc(s){return[new nt(0,s,0)]}let rc="";function Qd(s,e,t,i,n){var r;let o=i.head-s.from,l=nt.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],h=a.side(n,t);if(o==h){let u=l+=n?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!n,t),h=a.side(n,t)}let c=fe(s.text,o,a.forward(n,t));(ca.to)&&(c=h),rc=s.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return f&&c==h&&f.level+(n?0:1)s.some(e=>e)}),dc=I.define({combine:s=>s.some(e=>e)}),pc=I.define();class di{constructor(e,t,i,n,r,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new di(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 di(v.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ss=$.define({map:(s,e)=>s.map(e)}),mc=$.define();function Pe(s,e,t){let i=s.facet(hc);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 dt=I.define({combine:s=>s.length?s[0]:!0});let jd=0;const oi=I.define({combine(s){return s.filter((e,t)=>{for(let i=0;i{let a=[];return o&&a.push(Bn.of(h=>{let c=h.plugin(l);return c?o(c):z.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return se.define((i,n)=>new e(i,n),t)}}class Zn{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(Pe(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){Pe(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){Pe(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const gc=I.define(),zo=I.define(),Bn=I.define(),xc=I.define(),Qo=I.define(),fs=I.define(),bc=I.define();function Ql(s,e){let t=s.state.facet(bc);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return X.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,c=o-e.from,f=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=$d(e.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),n}const yc=I.define();function $o(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(yc)){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 Li=I.define();class We{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new We(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.toAn.push(new We(r,o,l,a))),this.changedRanges=n}static create(e,t,i){return new rn(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const qd=[];class ie{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return qd}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&Md(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let n of this.children){if(n==e)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=Dt(this.dom),n=this.length?e>0:t>0;return new je(this.parent.dom,i+(n?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Ln)return e;return null}static get(e){return e.cmTile}}class En extends ie{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,n,r=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,n=i?i.nextSibling:t.firstChild,r&&n!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;n&&n!=l.dom;)n=$l(n);else t.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:t.firstChild,r&&n&&(r.written=!0);n;)n=$l(n);this.length=o}}function $l(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class Ln extends En{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=ie.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let o=i.children[n++];if(o instanceof pt)t.push(n),i=o,n=0;else{let l=r+o.length,a=e(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(e,t){let i,n=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(ae||e==a&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-a)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:n}:{tile:r,offset:o}}}class pt extends En{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new pt(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class bi extends En{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new bi(t||document.createElement("div"),e);return(!t||!i)&&(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(e,t,i){let n=null,r=-1,o=null,l=-1;function a(c,f){for(let u=0,d=0;u=f&&(p.isComposite()?a(p,f-d):(!o||o.isHidden&&(t>0||i&&Ud(o,p)))&&(m>f||p.flags&32)?(o=p,l=f-d):(di&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?W.chrome||W.gecko||(e?(n--,o=1):r=0)?0:l.length-1];return W.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Gi(a,o<0):a||null}static of(e,t){let i=new jt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class Jt extends ie{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return Gi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?r.length-1:0;o=r[a],!(e>0?a==0:a==r.length-1||o.top0;)if(n.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==n.children.length){if(!e&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let a=n.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length=0;l--){let a=t.marks[l],h=n.lastChild;if(h instanceof Me&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(er(a.dom)),n=h;else{if(this.cache.reused.get(a)){let f=ie.get(a.dom);f&&f.setDOM(er(a.dom))}let c=Me.of(a.mark,a.dom);n.append(c),n=c}this.cache.reused.set(a,2)}let r=ie.get(e.text);r&&this.cache.reused.set(r,2);let o=new jt(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,n.append(o)}addInlineWidget(e,t,i){let n=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);n||this.flushBuffer();let r=this.ensureMarks(t,i);!n&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=kc);let n=bi.start(e,t||((i=this.cache.find(bi))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let n=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=n.lastChild)&&l instanceof Me&&l.mark.eq(o))n=l,t--;else{let a=Me.of(o,(i=this.cache.find(Me,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);n.append(a),n=a,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!jl(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(W.ios&&jl(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(tr,0,32)||new Jt(tr.toDOM(),0,tr,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to=this.pos){let t=e.rank*102+e.value.rank,i=new _d(e.from,e.to,e.value,t),n=this.wrappers.length;for(;n>0&&(this.wrappers[n-1].rank-i.rank||this.wrappers[n-1].to-i.to)<0;)n--;this.wrappers.splice(n,0,i)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.fromo.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(on,void 0,1);return i&&(i.flags=t),i||new on(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Gd{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:n,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=n;let l=this.textOff=Math.min(e,n.length);return r?null:n.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const ln=[Jt,bi,jt,Me,on,pt,Ln];for(let s=0;s[]),this.index=ln.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let n=e.bucket,r=this.buckets[n],o=this.index[n];for(let l=r.length-1;l>=0;l--){let a=(l+o)%r.length,h=r[a];if((!t||t(h))&&!this.reused.has(h))return r.splice(a,1),a{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let n=0,r=0,o=0;;){let l=on){let h=a-n;this.preserve(h,!o,!l),n=a,r+=h}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof Me&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof Me&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,n=this.builder,r=0,o=X.spans(this.decorations,e,t,{point:(l,a,h,c,f,u)=>{if(h instanceof Kt){if(this.disallowBlockEffectsFor[u]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,f>c.length)n.continueWidget(a-l);else{let d=h.widget||(h.block?yi.block:yi.inline),p=ep(h),m=this.cache.findWidget(d,a-l,p)||Jt.of(d,this.view,a-l,p);h.block?(h.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(m)):(n.ensureLine(i),n.addInlineWidget(m,c,f))}i=null}else i=tp(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;fr,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let r=ie.get(n);if(n==this.view.contentDOM)break;r instanceof Me?t.push(r):r?.isLine()?i=r:r instanceof pt||(n.nodeName=="DIV"&&!i&&n!=this.view.contentDOM?i=new bi(n,kc):i||t.push(Me.of(new hs({tagName:n.nodeName.toLowerCase(),attributes:Pd(n)}),n)))}return{line:i,marks:t}}}function jl(s,e){let t=i=>{for(let n of i.children)if((e?n.isText():n.length)||t(n))return!0;return!1};return t(s)}function ep(s){let e=s.isReplace?(s.startSide<0?64:0)|(s.endSide>0?128:0):s.startSide>0?32:16;return s.block&&(e|=256),e}const kc={class:"cm-line"};function tp(s,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(s||(s={class:"cm-line"}),t&&Io(t,s),i&&(s.class+=" "+i)),s}function ip(s){let e=[];for(let t=s.parents.length;t>1;t--){let i=t==s.parents.length?s.tile:s.parents[t].tile;i instanceof Me&&e.push(i.mark)}return e}function er(s){let e=ie.get(s);return e&&e.setDOM(s.cloneNode()),s}class yi extends ct{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}}yi.inline=new yi("span");yi.block=new yi("div");const tr=new class extends ct{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class ql{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=z.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Ln(e,e.contentDOM),this.updateInner([new We(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>fthis.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:!fp(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?np(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new We(c,f,e.changes.mapPos(c,-1),e.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(W.ie||W.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=lp(o,this.decorations,e.changes);a.length&&(i=We.extendWithRanges(i,a));let h=hp(l,this.blockWrappers,e.changes);return h.length&&(i=We.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new Zd(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&ie.get(t.text)&&l.cache.reused.set(ie.get(t.text),2),this.tile=l.run(e,t),eo(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=W.chrome||W.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to-1)&&Vi(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),W.gecko&&a.empty&&!this.hasComposition&&sp(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=c=new je(u,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!zi(h.node,h.offset,f.anchorNode,f.anchorOffset)||!zi(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{W.android&&W.chrome&&i.contains(f.focusNode)&&cp(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=Ki(this.view.root);if(u)if(a.empty){if(W.gecko){let d=rp(h.node,h.offset);if(d&&d!=3){let p=(d==1?Zh:ec)(h.node,h.offset);p&&(h=new je(p.node,p.offset))}}u.collapse(h.node,h.offset),a.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=a.bidiLevel)}else if(u.extend){u.collapse(h.node,h.offset);try{u.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new je(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new je(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&zi(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=Ki(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let n=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=gt(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!ie.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?e==i.dom?n+t:n+(t?i.length:0):n}domAtPos(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(n,t)}inlineDOMNearPos(e,t){let i,n=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(r=!0)}else{let f=c+h.length;if(c<=e&&(i=h,n=e-c,r=f=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:a&&i&&(o=null),i&&t<0||!o?i.domIn(n,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof ir?null:i.coordsInWidget(n,t,!0):i.coordsIn(n,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function n(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=n(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&oMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==J.LTR,h=0,c=(f,u,d)=>{for(let p=0;pn);p++){let m=f.children[p],g=u+m.length,x=m.dom.getBoundingClientRect(),{height:k}=x;if(d&&!p&&(h+=x.top-d.top),m instanceof pt)g>i&&c(m,u,x);else if(u>=i&&(h>0&&t.push(-h),t.push(k+h),h=0,o)){let w=m.dom.lastChild,T=w?Hi(w):[];if(T.length){let S=T[T.length-1],A=a?S.right-x.left:x.right-S.left;A>l&&(l=A,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=g)}}d&&p==f.children.length-1&&(h+=d.bottom-x.bottom),u=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?J.RTL:J.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Hi(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),i,n,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Hi(t.firstChild)[0];i=t.getBoundingClientRect().height,n=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:n,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(z.replace({widget:new ir(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return z.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Bn).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(Qo).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(X.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];etypeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let c=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=c.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let c of this.view.state.facet(pc))try{if(c(this.view,e.range,e))return!0}catch(f){Pe(this.view.state,f,"scroll handler")}let{range:i}=e,n=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!n)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let o=$o(this.view),l={left:n.left-o.left,top:n.top-o.top,right:n.right+o.right,bottom:n.bottom+o.bottom},{offsetWidth:a,offsetHeight:h}=this.view.scrollDOM;if(Rd(this.view.scrollDOM,l,i.head1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottomi.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){eo(this.tile)}}function eo(s,e){let t=e?.get(s);if(t!=1){t==null&&s.destroy();for(let i of s.children)eo(i,e)}}function sp(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 wc(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=Zh(t.focusNode,t.focusOffset),n=ec(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=ie.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=ie.get(i.node);!a||a.isText()&&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 np(s,e,t){let i=wc(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;return{range:new We(a.mapPos(r),a.mapPos(o),r,o),text:n}}function rp(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e{ie.from&&(t=!0)}),t}class ir extends ct{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function up(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return v.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=fe(n.text,r,!1):l=fe(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let h=fe(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;ls.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+Qr(o,r,s.state.tabSize)}function to(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==ge.Text&&(n.type!=r.type||(t<0?r.frome)))&&(n=r)}}return n||i}return i}function pp(s,e,t,i){let n=to(s,e.head,e.assoc||-1),r=!i||n.type!=ge.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==J.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return v.cursor(a,t?-1:1)}return v.cursor(t?n.to:n.from,t?-1:1)}function Xl(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 h=Qd(n,r,o,l,t),c=rc;if(!h){if(n.number==(t?s.state.doc.lines:1))return l;c=` `,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),h=s.visualLineSide(n,!t)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function mp(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==ee.Space&&(n=o),n==o}}function gp(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return v.cursor(n,e.assoc);let o=e.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(n,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=s.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let p=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-p.from))),l=(r<0?p.top:p.bottom)+c}let f=a.left+o,u=s.viewState.heightOracle.textHeight>>1,d=i??u;for(let p=0;;p+=u){let m=l+(d+p)*r,g=io(s,{x:f,y:m},!1,r);if(t?m>a.bottom:ml:k{if(e>r&&en(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:v.cursor(i,is.viewState.docHeight)return new st(s.state.doc.length,-1);if(h=s.elementAtHeight(a),i==null)break;if(h.type==ge.Text){if(i<0?h.tos.viewport.to)break;let u=s.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(u&&(i<0?u.top<=a+r:u.bottom>=a+r))break}let f=s.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(s.viewport.from>=h.to||s.viewport.to<=h.from){if(t)return null;if(h.type==ge.Text){let f=dp(s,n,h,o,l);return new st(f,f==h.from?1:-1)}}if(h.type!=ge.Text)return a<(h.top+h.bottom)/2?new st(h.from,1):new st(h.to,-1);let c=s.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=s.docView.lineAt(h.from,-2)),new xp(s,o,l,s.textDirectionAt(h.from)).scanTile(c,h.from)}class xp{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from>1;t:if(o.has(m)){let x=n+Math.floor(Math.random()*p);for(let k=0;k1)){if(k.bottomthis.y)(!h||h.top>k.top)&&(h=k),w=-1;else{let T=k.left>this.x?this.x-k.left:k.right(p+p+m)/3)return this.y=a.bottom-1,this.scan(e,t,!0);if(h&&h.top<(p+m+m)/3)return this.y=h.top+1,this.scan(e,t,!0)}let d=(l?this.dirAt(e[c],1):this.baseDir)==J.LTR;return{i:c,after:this.x>(u.left+u.right)/2==d}}scanText(e,t){let i=[];for(let r=0;r{let o=i[r]-t,l=i[r+1]-t;return Ji(e.dom,o,l).getClientRects()});return n.after?new st(i[n.i+1],-1):new st(i[n.i],1)}scanTile(e,t){if(!e.length)return new st(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,a=t;l{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:Ji(a.dom,0,a.length)).getClientRects()}),r=e.children[n.i],o=i[n.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):n.after?new st(i[n.i+1],-1):new st(o,1)}}const ii="￿";class bp{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(U.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ii}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=ie.get(n),l=n.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=ie.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:nn(n))||nn(l)&&(n.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!kp(l,t)&&this.lineBreak(),n=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){let t=ie.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+(yp(e,i.node,i.offset)?t:0))}}function yp(s,e,t){for(;;){if(!e||t-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Sc(e.docView.tile,t,i,0))){let a=r||o?[]:Sp(e),h=new bp(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=Op(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!_r(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!_r(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),f=e.viewport;if((W.ios||W.chrome)&&l.main.empty&&h!=c&&(f.from>0||f.to-1&&l.ranges.length>1)this.newSel=l.replaceRange(v.range(c,h));else if(e.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&e.inputState.lastTouchTime>Date.now()-100){let u=e.coordsAtPos(h,-1),d=0;u&&(d=e.inputState.lastTouchY<=u.bottom?-1:1),this.newSel=v.create([v.cursor(h,d)])}else this.newSel=v.single(c,h)}}}function Sc(s,e,t,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;at)return Sc(f,e,t,h);if(u>=e&&n==-1&&(n=a,r=h),h>t&&f.dom.parentNode==s.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function Oc(s,e){let t,{newSel:i}=e,{state:n}=s,r=n.selection.main,o=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:a}=e.bounds,h=r.from,c=null;(o===8||W.android&&e.text.length=l&&r.to<=a&&(e.typeOver||f!=e.text)&&f.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&f.slice(r.to-l)==e.text.slice(u=e.text.length-(f.length-(r.to-l)))?t={from:r.from,to:r.to,insert:Y.of(e.text.slice(r.from-l,u).split(ii))}:(d=Cc(f,e.text,h-l,c))&&(W.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==ii+ii&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:Y.of(e.text.slice(d.from,d.toB).split(ii))})}else i&&(!s.hasFocus&&n.facet(dt)||an(i,r))&&(i=null);if(!t&&!i)return!1;if((W.mac||W.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=v.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:Y.of([t.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).toDate.now()-50?t={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:W.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==` `&&s.lineWrapping&&(i&&(i=v.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:Y.of([" "])}),t)return jo(s,t,i,o);if(i&&!an(i,r)){let l=!1,a="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(l=!0),a=s.inputState.lastSelectionOrigin,a=="select.pointer"&&(i=vc(n.facet(fs).map(h=>h(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function jo(s,e,t,i=-1){if(W.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(W.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&&ui(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.lengthn.head)&&ui(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&ui(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=vp(s,e,t));return s.state.facet(cc).some(a=>a(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function vp(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.fromf(s)),h,a);e.from==c&&(o=c)}if(o>-1)i={changes:e,selection:v.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)+h))}else{let a=n.changes(e),h=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 c=s.state.sliceDoc(e.from,e.to),f,u=t&&wc(s,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);f={from:u.from,to:u.to-p}}else f=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:h||p.map(a)};let m=p.to-d,g=m-c.length;if(s.state.sliceDoc(g,m)!=c||m>=f.from&&g<=f.to)return{range:p};let x=n.changes({from:g,to:m,insert:e.insert}),k=p.to-r.to;return{changes:x,range:h?v.range(Math.max(0,h.anchor+k),Math.max(0,h.head+k)):p.map(x)}})}else i={changes:a,selection:h&&n.selection.replaceRange(h)}}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 Cc(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 Sp(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 Ul(t,i)),(n!=t||r!=i)&&e.push(new Ul(n,r))),e}function Op(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?v.single(t+e,i+e):null}function an(s,e){return e.head==s.main.head&&e.anchor==s.main.anchor}class Cp{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,W.safari&&e.contentDOM.addEventListener("input",()=>null),W.gecko&&Hp(e.contentDOM.ownerDocument)}handleEvent(e){!Ep(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=Ap(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&&Mc.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),W.android&&W.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return W.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=Ac.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Mp.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from0?!0:W.safari&&!W.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 Yl(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){Pe(t.state,n)}}}function Ap(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(Yl(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(Yl(i.value,a))}}for(let i in Xe)t(i).handlers.push(Xe[i]);for(let i in De)t(i).observers.push(De[i]);return e}const Ac=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Mp="dthko",Mc=[16,17,18,20,91,92,224,225],Os=6;function Cs(s){return Math.max(0,s)*.7+8}function Pp(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class Tp{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=Kh(e.contentDOM),this.atoms=e.state.facet(fs).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(U.allowMultipleSelections)&&Dp(e,t),this.dragging=Bp(e,t)&&Dc(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&&Pp(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=$o(this.view);e.clientX-a.left<=n+Os?t=-Cs(n-e.clientX):e.clientX+a.right>=o-Os&&(t=Cs(e.clientX-o)),e.clientY-a.top<=r+Os?i=-Cs(r-e.clientY):e.clientY+a.bottom>=l-Os&&(i=Cs(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=vc(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 Dp(s,e){let t=s.state.facet(oc);return t.length?t[0](e):W.mac?e.metaKey:e.ctrlKey}function Rp(s,e){let t=s.state.facet(lc);return t.length?t[0](e):W.mac?!e.altKey:!e.ctrlKey}function Bp(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=Ki(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 Ep(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=ie.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Xe=Object.create(null),De=Object.create(null),Pc=W.ie&&W.ie_version<15||W.ios&&W.webkit_version<604;function Lp(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(),Tc(s,t.value)},50)}function Nn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function Tc(s,e){e=Nn(s.state,Vo,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(so!=null&&t.selection.ranges.every(a=>a.empty)&&so==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:v.cursor(h.from+f.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:v.cursor(a.from+h.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}De.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};De.wheel=De.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};Xe.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);De.touchstart=(s,e)=>{let t=s.inputState,i=e.targetTouches[0];t.lastTouchTime=Date.now(),i&&(t.lastTouchX=i.clientX,t.lastTouchY=i.clientY),t.setSelectionOrigin("select.pointer")};De.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Xe.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(ac))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Ip(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new Tp(s,e,t,i)),i&&s.observer.ignore(()=>{Gh(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 _l(s,e,t,i){if(i==1)return v.cursor(e,t);if(i==2)return up(s.state,e,t);{let n=s.docView.lineAt(e,t),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return lDate.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(Gl+1)%3:1}function Ip(s,e){let t=s.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Dc(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=s.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=_l(s,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let f=_l(s,t.pos,t.assoc,i),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u1&&(h=Wp(n,a.pos))?h:l?n.addRange(c):v.create([c])}}}function Wp(s,e){for(let t=0;t=e)return v.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}Xe.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.tile.nearest(e.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=v.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Nn(s.state,Ho,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Xe.dragend=s=>(s.inputState.draggedContent=null,!1);function Zl(s,e,t,i){if(t=Nn(s.state,Vo,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Rp(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}Xe.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&&Zl(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 Zl(s,e,i,!0),!0}return!1};Xe.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=Pc?null:e.clipboardData;return t?(Tc(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Lp(s),!1)};function Fp(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 Vp(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:Nn(s,Ho,e.join(s.lineBreak)),ranges:t,linewise:i}}let so=null;Xe.copy=Xe.cut=(s,e)=>{if(!Vi(s.contentDOM,s.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:n}=Vp(s.state);if(!t&&!n)return!1;so=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Pc?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Fp(s,t),!1)};const Rc=at.define();function Bc(s,e){let t=[];for(let i of s.facet(fc)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:Rc.of(!0)}):null}function Ec(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Bc(s.state,e);t?s.dispatch(t):s.update([])}},10)}De.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),Ec(s)};De.blur=s=>{s.observer.clearSelectionRange(),Ec(s)};De.compositionstart=De.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};De.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,W.chrome&&W.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};De.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Xe.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),h=s.posAtDOM(l.endContainer,l.endOffset);return jo(s,{from:a,to:h,insert:s.state.toText(r)},null),!0}}let n;if(W.chrome&&W.android&&(n=Ac.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 W.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),W.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>De.compositionend(s,e),20),!1};const ea=new Set;function Hp(s){ea.has(s)||(ea.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const ta=["pre-wrap","normal","pre-line","break-spaces"];let ki=!1;function ia(){ki=!1}class zp{constructor(e){this.lineWrapping=e,this.doc=Y.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 ta.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let h=0;h0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Xs&&(ki=!0),this.height=e)}replace(e,t,i){return Oe.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:h,fromB:c,toB:f}=n[l],u=r.lineAt(a,Z.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,Z.ByPosNoHeight,i,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,c=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.lineAt(0,Z.ByPos,i,n,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ne extends Lc{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new $e(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof Ne||n instanceof pe&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof pe?n=new Ne(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):Oe.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class pe extends Oe{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 h=n+(e0){let r=i[i.length-1];r instanceof pe?i[i.length-1]=new pe(r.length+n):i.push(null,new pe(n-1))}if(e>0){let r=i[0];r instanceof pe?i[0]=new pe(e+r.length):i.unshift(new pe(e-1),null)}return Oe.of(i)}decomposeLeft(e,t){t.push(new pe(e-1),null)}decomposeRight(e,t){t.push(null,new pe(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 pe(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++],u=0;f<0&&(u=-f,f=n.heights[n.index++]),a==-1?a=f:Math.abs(f-a)>=Xs&&(a=-2);let d=new Ne(c,f,u);d.outdated=!1,o.push(d),l+=c+1}l<=r&&o.push(null,new pe(r-l).updateHeight(e,l));let h=Oe.of(o);return(a<0||Math.abs(h.height-this.height)>=Xs||Math.abs(a-this.heightMetrics(e,t).perLine)>=Xs)&&(ki=!0),hn(this,h)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class jp extends Oe{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 h;let c=t==Z.ByPosNoHeight?Z.ByPosNoHeight:Z.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,n,r).join(h)}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 h=this.lineAt(a,Z.ByPos,i,n,r);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.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&&sa(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?Oe.of(this.break?[e,null,t]:[e,t]):(this.left=hn(this.left,e),this.right=hn(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 sa(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof pe&&(i=s[e+1])instanceof pe&&s.splice(e-1,3,new pe(t.length+1+i.length))}const qp=5;class qo{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 Ne?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ne(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=qp)&&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 Ne(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new pe(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 Ne)return e;let t=new Ne(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ne)&&!this.isCovered?this.nodes.push(new Ne(0,-1,0)):(this.writtenToc.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let u=c.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==s.parentNode?n.innerHeight:a,u.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.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 _p(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left0&&e.top0}function Kp(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class nr{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 n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new zp(i),this.stateDeco=oa(t),this.heightMap=Oe.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle.setDoc(t.doc),[new We(0,0,0,t.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=z.set(this.lineGaps.map(n=>n.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);e.push(new As(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?ra:new Xo(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(Ni(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=oa(this.state);let n=e.changedRanges,r=We.extendWithRanges(n,Xp(i,this.stateDeco,e?e.changes:ae.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);ia(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||ki)&&(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 h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(dc)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?J.RTL:J.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:S,scaleY:A}=_h(t,l);(S>.005&&Math.abs(this.scaleX-S)>.005||A>.005&&Math.abs(this.scaleY-A)>.005)&&(this.scaleX=S,this.scaleY=A,h|=16,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=Kh(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Jh(this.scrollParent||e.win);let m=(this.printing?Kp:Yp)(t,this.paddingTop),g=m.top-this.pixelViewport.top,x=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let k=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(k!=this.inView&&(this.inView=k,k&&(a=!0)),!this.inView&&!this.scrollTarget&&!_p(e.dom))return 0;let w=l.width;if((this.contentDOMWidth!=w||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let S=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(S)&&(o=!0),o||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:A,charWidth:O,textHeight:V}=e.docView.measureTextSize();o=A>0&&n.refresh(r,A,O,V,Math.max(5,w/O),S),o&&(e.docView.minWidth=0,h|=16)}g>0&&x>0?c=Math.max(g,x):g<0&&x<0&&(c=Math.min(g,x)),ia();for(let A of this.viewports){let O=A.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(A);this.heightMap=(o?Oe.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle,[new We(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Qp(A.from,O))}ki&&(h|=2)}let T=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return T&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||T)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}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 As(n.lineAt(o-i*1e3,Z.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,Z.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(h,Z.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r>1,o=n<<1;if(this.defaultTextDirection!=J.LTR&&!i)return[];let l=[],a=(c,f,u,d)=>{if(f-cc&&xx.from>=u.from&&x.to<=u.to&&Math.abs(x.from-c)x.fromk));if(!g){if(fw.from<=f&&w.to>=f)){let w=t.moveToLineBoundary(v.cursor(f),!1,!0).head;w>c&&(f=w)}let x=this.gapSize(u,c,f,d),k=i||x<2e6?x:2e6;g=new nr(c,f,x,k)}l.push(g)},h=c=>{if(c.length2e6)for(let A of e)A.from>=c.from&&A.fromc.from&&a(c.from,d,c,f),pt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];X.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)||Ni(this.heightMap.lineAt(e,Z.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)||Ni(this.heightMap.lineAt(this.scaler.fromDOM(e),Z.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Ni(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 As{constructor(e,t){this.from=e,this.to=t}}function Jp(s,e,t){let i=[],n=s,r=0;return X.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 Ps(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 Zp(s,e){for(let t of s)if(e(t))return t}const ra={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function oa(s){let e=s.facet(Bn).filter(i=>typeof i!="function"),t=s.facet(Qo).filter(i=>typeof i!="function");return t.length&&e.push(X.join(t)),e}class Xo{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,Z.ByPos,e,0,0).top,c=t.lineAt(a,Z.ByPos,e,0,0).bottom;return n+=c-h,{from:l,to:a,top:h,bottom:c,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 Ni(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new $e(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>Ni(n,e)):s._content)}const Ts=I.define({combine:s=>s.join(" ")}),no=I.define({combine:s=>s.indexOf(!0)>-1}),ro=Pt.newName(),Nc=Pt.newName(),Ic=Pt.newName(),Wc={"&light":"."+Nc,"&dark":"."+Ic};function oo(s,e,t){return new Pt(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 em=oo("."+ro,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,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"}},Wc),tm={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},rr=W.ie&&W.ie_version<=11;class im{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Bd,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);(W.ie&&W.ie_version<=11||W.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&&W.android&&e.constructor.EDIT_CONTEXT!==!1&&!(W.chrome&&W.chrome_version<126)&&(this.editContext=new nm(e),e.state.facet(dt)&&(e.contentDOM.editContext=this.editContext.editContext)),rr&&(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(dt)?i.root.activeElement!=this.dom:!Vi(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(W.ie&&W.ie_version<=11||W.android&&W.chrome)&&!i.state.selection.main.empty&&n.focusNode&&zi(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Ki(e.root);if(!t)return!1;let i=W.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&sm(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=Vi(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&&ui(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&&Vi(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 wp(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=Oc(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!an(this.view.state.selection,t.newSel.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=la(t,e.previousSibling||e.target.previousSibling,-1),n=la(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(dt)!=e.state.facet(dt)&&(e.view.contentDOM.editContext=e.state.facet(dt)?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 la(s,e,t){for(;e;){let i=ie.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 aa(s,e){let t=e.startContainer,i=e.startOffset,n=e.endContainer,r=e.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor,1);return zi(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function sm(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return aa(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?aa(s,t):null}class nm{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 h=a-l>i.text.length;l==this.from&&rthis.to&&(a=r);let c=Cc(e.state.sliceDoc(l,a),i.text,(h?n.from:n.to)-l,h?"end":null);if(!c){let u=v.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));an(u,n)||e.dispatch({selection:u,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:Y.of(i.text.slice(c.from,c.toB).split(` `))};if((W.mac||W.android)&&f.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:Y.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let u=this.to-this.from+(f.to-f.from+f.insert.length);jo(e,f,v.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),f.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),h=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=Ki(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,h)=>{if(i)return;let c=h.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(h)){n=this.pendingContextChange=null,t+=c,this.to+=c;return}else n=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(rthis.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),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 L{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||Ed(e.parent)||document,this.viewState=new na(this,e.state||U.create(e)),e.scrollTo&&e.scrollTo.is(Ss)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(oi).map(n=>new Zn(n));for(let n of this.plugins)n.update(this);this.observer=new im(this),this.inputState=new Cp(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ql(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof he?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(Rc))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Bc(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(U.phrases)!=this.state.facet(U.phrases))return this.setState(r);n=rn.create(this,r,e),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(L.cursorScrollMargin);f=new di(d.empty?d:v.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(Ss)&&(f=d.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=cn.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(Li)!=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(Ts)!=n.state.facet(Ts)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Zr))try{u(n)}catch(d){Pe(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Oc(this,c)&&h.force&&ui(this.contentDOM,h.key,h.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 na(this,e),this.plugins=e.facet(oi).map(i=>new Zn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new ql(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(oi),i=e.state.facet(oi);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new Zn(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.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Jh(i||this.win))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure();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 h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(p){return Pe(this.state,p),ha}}),f=rn.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n=n+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Zr))l(t)}get themeClasses(){return ro+" "+(this.state.facet(no)?Ic:Nc)+" "+this.state.facet(Ts)}updateAttrs(){let e=ca(this,gc,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(dt)?"true":"false",class:"cm-content",style:`${W.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),ca(this,zo,t);let i=this.observer.ignore(()=>{let n=Vl(this.contentDOM,this.contentAttrs,t),r=Vl(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(L.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(Li);let e=this.state.facet(L.cspNonce);Pt.mount(this.root,this.styleModules.concat(em).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 sr(this,e,Xl(this,e,t,i))}moveByGroup(e,t){return sr(this,e,Xl(this,e,t,i=>mp(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 v.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return pp(this,e,t,i)}moveVertically(e,t,i){return sr(this,e,gp(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=io(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),io(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[nt.find(r,e-n.from,-1,t)];return Gi(i,o.dir==J.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(uc)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>rm)return nc(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||sc(r.isolates,i=Ql(this,e))))return r.order;i||(i=Ql(this,e));let n=zd(e.text,t,i);return this.bidiCache.push(new cn(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||W.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Gh(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,n,r,o;return Ss.of(new di(typeof e=="number"?v.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(n=t.x)!==null&&n!==void 0?n:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Ss.of(new di(v.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 se.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return se.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=Pt.newName(),n=[Ts.of(i),Li.of(oo(`.${i}`,e))];return t&&t.dark&&n.push(no.of(!0)),n}static baseTheme(e){return ei.lowest(Li.of(oo("."+ro,e,Wc)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&ie.get(i)||ie.get(e);return((t=n?.root)===null||t===void 0?void 0:t.view)||null}}L.styleModule=Li;L.inputHandler=cc;L.clipboardInputFilter=Vo;L.clipboardOutputFilter=Ho;L.scrollHandler=pc;L.focusChangeEffect=fc;L.perLineTextDirection=uc;L.exceptionSink=hc;L.updateListener=Zr;L.editable=dt;L.mouseSelectionStyle=ac;L.dragMovesSelection=lc;L.clickAddsSelectionRange=oc;L.decorations=Bn;L.blockWrappers=xc;L.outerDecorations=Qo;L.atomicRanges=fs;L.bidiIsolatedRanges=bc;L.cursorScrollMargin=I.define({combine:s=>{let e=5,t=5;for(let i of s)typeof i=="number"?e=t=i:{x:e,y:t}=i;return{x:e,y:t}}});L.scrollMargins=yc;L.darkTheme=no;L.cspNonce=I.define({combine:s=>s.length?s[0]:""});L.contentAttributes=zo;L.editorAttributes=gc;L.lineWrapping=L.contentAttributes.of({class:"cm-lineWrapping"});L.announce=$.define();const rm=4096,ha={};class cn{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:J.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&&Io(o,t)}return t}const om=W.mac?"mac":W.windows?"win":W.linux?"linux":"key";function lm(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}function hm(s,e,t){return Vc(Fc(s.state),e,s,t)}let vt=null;const cm=4e3;function fm(s,e=om){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,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(x=>lm(x,e));for(let x=1;x{let T=vt={view:w,prefix:k,scope:o};return setTimeout(()=>{vt==T&&(vt=null)},cm),!0}]})}let m=p.join(" ");n(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,lo))}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let lo=null;function Vc(s,e,t,i){lo=e;let n=Ad(e),r=Ce(n,0),o=it(r)==n.length&&n!=" ",l="",a=!1,h=!1,c=!1;vt&&vt.view==t&&vt.scope==i&&(l=vt.prefix+" ",Mc.indexOf(e.keyCode)<0&&(h=!0,vt=null));let f=new Set,u=g=>{if(g){for(let x of g.run)if(!f.has(x)&&(f.add(x),x(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),h=!0)}return!1},d=s[i],p,m;return d&&(u(d[l+Ds(n,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(W.windows&&e.ctrlKey&&e.altKey)&&!(W.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=Tt[e.keyCode])&&p!=n?(u(d[l+Ds(p,e,!0)])||e.shiftKey&&(m=Yi[e.keyCode])!=n&&m!=p&&u(d[l+Ds(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Ds(n,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),lo=null,a}class Ut{constructor(e,t,i,n,r){this.className=e,this.left=t,this.top=i,this.width=n,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let n=e.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=Hc(e);return[new Ut(t,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}else return um(e,t,i)}}function Hc(s){let e=s.scrollDOM.getBoundingClientRect();return{left:(s.textDirection==J.LTR?e.left:e.right-s.scrollDOM.clientWidth*s.scaleX)-s.scrollDOM.scrollLeft*s.scaleX,top:e.top-s.scrollDOM.scrollTop*s.scaleY}}function ua(s,e,t,i){let n=s.coordsAtPos(e,t*2);if(!n)return i;let r=s.dom.getBoundingClientRect(),o=(n.top+n.bottom)/2,l=s.posAtCoords({x:r.left+1,y:o}),a=s.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function um(s,e,t){if(t.to<=s.viewport.from||t.from>=s.viewport.to)return[];let i=Math.max(t.from,s.viewport.from),n=Math.min(t.to,s.viewport.to),r=s.textDirection==J.LTR,o=s.contentDOM,l=o.getBoundingClientRect(),a=Hc(s),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=to(s,i,1),p=to(s,n,-1),m=d.type==ge.Text?d:null,g=p.type==ge.Text?p:null;if(m&&(s.lineWrapping||d.widgetLineBreaks)&&(m=ua(s,i,1,m)),g&&(s.lineWrapping||p.widgetLineBreaks)&&(g=ua(s,n,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return k(w(t.from,t.to,m));{let S=m?w(t.from,null,m):T(d,!1),A=g?w(null,t.to,g):T(p,!0),O=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&S.bottom+s.defaultLineHeight/2M&&R.from=B)break;ue>C&&D(Math.max(Q,C),S==null&&Q<=M,Math.min(ue,B),A==null&&ue>=F,oe.dir)}if(C=j.to+1,C>=B)break}return P.length==0&&D(M,S==null,F,A==null,s.textDirection),{top:V,bottom:N,horizontal:P}}function T(S,A){let O=l.top+(A?S.top:S.bottom);return{top:O,bottom:O,horizontal:[]}}}function dm(s,e){return s.constructor==e.constructor&&s.eq(e)}class pm{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Us)!=e.state.facet(Us)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(Us);for(;t!dm(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let n of e)n.update&&t&&n.constructor&&this.drawn[i].constructor&&n.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(n.draw(),t);for(;t;){let n=t.nextSibling;t.remove(),t=n}this.drawn=e,W.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Us=I.define();function zc(s){return[se.define(e=>new pm(e,s)),Us.of(s)]}const wi=I.define({combine(s){return ht(s,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function mm(s={}){return[wi.of(s),gm,xm,bm,dc.of(!0)]}function Qc(s){return s.startState.facet(wi)!=s.state.facet(wi)}const gm=zc({above:!0,markers(s){let{state:e}=s,t=e.facet(wi),i=[];for(let n of e.selection.ranges){let r=n==e.selection.main;if(n.empty||t.drawRangeCursor&&!(r&&W.ios&&t.iosSelectionHandles)){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=n.empty?n:v.cursor(n.head,n.assoc);for(let a of Ut.forRange(s,o,l))i.push(a)}}return i},update(s,e){s.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Qc(s);return t&&da(s.state,e),s.docChanged||s.selectionSet||t},mount(s,e){da(e.state,s)},class:"cm-cursorLayer"});function da(s,e){e.style.animationDuration=s.facet(wi).cursorBlinkRate+"ms"}const xm=zc({above:!1,markers(s){let e=[],{main:t,ranges:i}=s.state.selection;for(let n of i)if(!n.empty)for(let r of Ut.forRange(s,"cm-selectionBackground",n))e.push(r);if(W.ios&&!t.empty&&s.state.facet(wi).iosSelectionHandles){for(let n of Ut.forRange(s,"cm-selectionHandle cm-selectionHandle-start",v.cursor(t.from,1)))e.push(n);for(let n of Ut.forRange(s,"cm-selectionHandle cm-selectionHandle-end",v.cursor(t.to,1)))e.push(n)}return e},update(s,e){return s.docChanged||s.selectionSet||s.viewportChanged||Qc(s)},class:"cm-selectionLayer"}),bm=ei.highest(L.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),$c=$.define({map(s,e){return s==null?null:e.mapPos(s)}}),Ii=ye.define({create(){return null},update(s,e){return s!=null&&(s=e.changes.mapPos(s)),e.effects.reduce((t,i)=>i.is($c)?i.value:t,s)}}),ym=se.fromClass(class{constructor(s){this.view=s,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(s){var e;let t=s.state.field(Ii);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(s.startState.field(Ii)!=t||s.docChanged||s.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:s}=this,e=s.state.field(Ii),t=e!=null&&s.coordsAtPos(e);if(!t)return null;let i=s.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+s.scrollDOM.scrollLeft*s.scaleX,top:t.top-i.top+s.scrollDOM.scrollTop*s.scaleY,height:t.bottom-t.top}}drawCursor(s){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;s?(this.cursor.style.left=s.left/e+"px",this.cursor.style.top=s.top/t+"px",this.cursor.style.height=s.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(s){this.view.state.field(Ii)!=s&&this.view.dispatch({effects:$c.of(s)})}},{eventObservers:{dragover(s){this.setDropPos(this.view.posAtCoords({x:s.clientX,y:s.clientY}))},dragleave(s){(s.target==this.view.contentDOM||!this.view.contentDOM.contains(s.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function km(){return[Ii,ym]}function pa(s,e,t,i,n){e.lastIndex=0;for(let r=s.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)n(o+l.index,l)}function wm(s,e){let t=s.visibleRanges;if(t.length==1&&t[0].from==s.viewport.from&&t[0].to==s.viewport.to)return t;let i=[];for(let{from:n,to:r}of t)n=Math.max(s.state.doc.lineAt(n).from,n-e),r=Math.min(s.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=n?i[i.length-1].to=r:i.push({from:n,to:r});return i}class vm{constructor(e){const{regexp:t,decoration:i,decorate:n,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,n)this.addMatch=(l,a,h,c)=>n(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new mt,i=t.add.bind(t);for(let{from:n,to:r}of wm(e,this.maxLength))pa(e.state.doc,this.regexp,n,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,n=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>=e.view.viewport.from&&l<=e.view.viewport.to&&(i=Math.min(l,i),n=Math.max(a,n))}),e.viewportMoved||n-i>1e3?this.createDeco(e.view):n>-1?this.updateRange(e.view,t.map(e.changes),i,n):t}updateRange(e,t,i,n){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,n);if(l>=o){let a=e.state.doc.lineAt(o),h=a.toa.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;lu.push(x.range(m,g));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.indexthis.addMatch(g,e,m,p));t=t.update({filterFrom:c,filterTo:f,filter:(m,g)=>mf,add:u})}}return t}}const ao=/x/.unicode!=null?"gu":"g",Sm=new RegExp(`[\0-\b --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,ao),Om={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let or=null;function Cm(){var s;if(or==null&&typeof document<"u"&&document.body){let e=document.body.style;or=((s=e.tabSize)!==null&&s!==void 0?s:e.MozTabSize)!=null}return or||!1}const Ys=I.define({combine(s){let e=ht(s,{render:null,specialChars:Sm,addSpecialChars:null});return(e.replaceTabs=!Cm())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,ao)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,ao)),e}});function Am(s={}){return[Ys.of(s),Mm()]}let ma=null;function Mm(){return ma||(ma=se.fromClass(class{constructor(s){this.view=s,this.decorations=z.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(s.state.facet(Ys)),this.decorations=this.decorator.createDeco(s)}makeDecorator(s){return new vm({regexp:s.specialChars,decoration:(e,t,i)=>{let{doc:n}=t.state,r=Ce(e[0],0);if(r==9){let o=n.lineAt(i),l=t.state.tabSize,a=Ci(o.text,l,i-o.from);return z.replace({widget:new Rm((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=z.replace({widget:new Dm(s,r)}))},boundary:s.replaceTabs?void 0:/[^]/})}update(s){let e=s.state.facet(Ys);s.startState.facet(Ys)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(s.view)):this.decorations=this.decorator.updateDeco(s,this.decorations)}},{decorations:s=>s.decorations}))}const Pm="•";function Tm(s){return s>=32?Pm:s==10?"␤":String.fromCharCode(9216+s)}class Dm extends ct{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Tm(this.code),i=e.state.phrase("Control character")+" "+(Om[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,t);if(n)return n;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Rm extends ct{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function Bm(){return Lm}const Em=z.line({class:"cm-activeLine"}),Lm=se.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(Em.range(n.from)),e=n.from)}return z.set(t)}},{decorations:s=>s.decorations});class Nm extends ct{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?Hi(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),n=Gi(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return n.bottom-n.top>r*1.5?{left:n.left,right:n.right,top:n.top,bottom:n.top+r}:n}ignoreEvent(){return!1}}function Im(s){let e=se.fromClass(class{constructor(t){this.view=t,this.placeholder=s?z.set([z.widget({widget:new Nm(s),side:1}).range(0)]):z.none}get decorations(){return this.view.state.doc.length?z.none:this.placeholder}},{decorations:t=>t.decorations});return typeof s=="string"?[e,L.contentAttributes.of({"aria-placeholder":s})]:e}const ho=2e3;function Wm(s,e,t){let i=Math.min(e.line,t.line),n=Math.max(e.line,t.line),r=[];if(e.off>ho||t.off>ho||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=n;a++){let h=s.doc.line(a);h.length<=l&&r.push(v.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=n;a++){let h=s.doc.line(a),c=Qr(h.text,o,s.tabSize,!0);if(c<0)r.push(v.cursor(h.to));else{let f=Qr(h.text,l,s.tabSize);r.push(v.range(h.from+c,h.from+f))}}}return r}function Fm(s,e){let t=s.coordsAtPos(s.viewport.from);return t?Math.round(Math.abs((t.left-e)/s.defaultCharacterWidth)):-1}function ga(s,e){let t=s.posAtCoords({x:e.clientX,y:e.clientY},!1),i=s.state.doc.lineAt(t),n=t-i.from,r=n>ho?-1:n==i.length?Fm(s,e.clientX):Ci(i.text,s.state.tabSize,t-i.from);return{line:i.number,col:r,off:n}}function Vm(s,e){let t=ga(s,e),i=s.state.selection;return t?{update(n){if(n.docChanged){let r=n.changes.mapPos(n.startState.doc.line(t.line).from),o=n.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(n.changes)}},get(n,r,o){let l=ga(s,n);if(!l)return i;let a=Wm(s.state,t,l);return a.length?o?v.create(a.concat(i.ranges)):v.create(a):i}}:null}function Hm(s){let e=(t=>t.altKey&&t.button==0);return L.mouseSelectionStyle.of((t,i)=>e(i)?Vm(t,i):null)}const zm={Alt:[18,s=>!!s.altKey],Control:[17,s=>!!s.ctrlKey],Shift:[16,s=>!!s.shiftKey],Meta:[91,s=>!!s.metaKey]},Qm={style:"cursor: crosshair"};function $m(s={}){let[e,t]=zm[s.key||"Alt"],i=se.fromClass(class{constructor(n){this.view=n,this.isDown=!1}set(n){this.isDown!=n&&(this.isDown=n,this.view.update([]))}},{eventObservers:{keydown(n){this.set(n.keyCode==e||t(n))},keyup(n){(n.keyCode==e||!t(n))&&this.set(!1)},mousemove(n){this.set(t(n))}}});return[i,L.contentAttributes.of(n=>{var r;return!((r=n.plugin(i))===null||r===void 0)&&r.isDown?Qm:null})]}const Rs="-10000px";class jc{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[h]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function jm(s){let e=s.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const lr=I.define({combine:s=>{var e,t,i;return{position:W.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)||jm}}}),xa=new WeakMap,Uo=se.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(lr);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 jc(s,Yo,(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(lr);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=Rs,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(W.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=$o(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(lr).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)||f.rightMath.min(t.right,i.right)+.1)){c.style.top=Rs;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=xa.get(h))!==null&&e!==void 0?e:u.bottom-u.top,x=h.offset||Xm,k=this.view.textDirection==J.LTR,w=u.width>i.right-i.left?k?i.left:i.right-u.width:k?Math.max(i.left,Math.min(f.left-(d?14:0)+x.x,i.right-m)):Math.min(Math.max(i.left,f.left-m+(d?14:0)-x.x),i.right-m),T=this.above[l];!a.strictSide&&(T?f.top-g-p-x.yi.bottom)&&T==i.bottom-f.bottom>f.top-i.top&&(T=this.above[l]=!T);let S=(T?f.top-i.top:i.bottom-f.bottom)-p;if(Sw&&V.topA&&(A=T?V.top-g-2-p:V.bottom+p+2);if(this.position=="absolute"?(c.style.top=(A-s.parent.top)/r+"px",ba(c,(w-s.parent.left)/n)):(c.style.top=A/r+"px",ba(c,w/n)),d){let V=f.left+(k?x.x:-x.x)-(w+14-7);d.style.left=V/n+"px"}h.overlap!==!0&&o.push({left:w,top:A,right:O,bottom:A+g}),c.classList.toggle("cm-tooltip-above",T),c.classList.toggle("cm-tooltip-below",!T),h.positioned&&h.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=Rs}},{eventObservers:{scroll(){this.maybeMeasure()}}});function ba(s,e){let t=parseInt(s.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(s.style.left=e+"px")}const qm=L.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"}}}),Xm={x:0,y:0},Yo=I.define({enables:[Uo,qm]}),fn=I.define({combine:s=>s.reduce((e,t)=>e.concat(t),[])});class Wn{static create(e){return new Wn(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new jc(e,fn,(t,i)=>this.createHostedView(t,i),t=>t.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let n=i[e];if(n!==void 0){if(t===void 0)t=n;else if(t!==n)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Um=Yo.compute([fn],s=>{let e=s.facet(fn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var i;return(i=t.end)!==null&&i!==void 0?i:t.pos})),create:Wn.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),qc=I.define();class Ym{constructor(e,t,i,n,r,o){this.view=e,this.source=t,this.field=i,this.locked=n,this.setHover=r,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(e){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;eo.bottom||t.xo.right+e.defaultCharacterWidth)return;let l=e.bidiSpans(e.state.doc.lineAt(n)).find(h=>h.from<=n&&h.to>=n),a=l&&l.dir==J.RTL?-1:1;r=t.x{if(l&&!(Array.isArray(l)&&!l.length)){let a=Array.isArray(l)?l:[l];n&&this.locked.set(a,n),e.dispatch({effects:this.setHover.of(a)})}};if(r&&"then"in r){let l=this.pending={pos:t};r.then(a=>{this.pending==l&&(this.pending=null,o(a))},a=>Pe(e.state,a,"hover tooltip"))}else o(r)}get tooltip(){let e=this.view.plugin(Uo),t=e?e.manager.tooltips.findIndex(i=>i.create==Wn.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&!this.locked.has(n)&&r&&!_m(r.dom,e)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(t=n[0])===null||t===void 0?void 0:t.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!Km(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length&&!this.locked.has(t)){let{tooltip:i}=this;i&&i.dom.contains(e.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t);let{active:n}=this;n.length&&!this.locked.has(n)&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Bs=4;function _m(s,e){let{left:t,right:i,top:n,bottom:r}=s.getBoundingClientRect(),o;if(o=s.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();n=Math.min(l.top,n),r=Math.max(l.bottom,r)}return e.clientX>=t-Bs&&e.clientX<=i+Bs&&e.clientY>=n-Bs&&e.clientY<=r+Bs}function Km(s,e,t,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.rightn||Math.min(o.bottom,l)=e&&a<=t}function Gm(s,e={}){let t=$.define(),i=new WeakMap,n=ye.define({create(){return[]},update(o,l){let a=i.get(o);if(o.length&&(e.hideOnChange&&(l.docChanged||l.selection)?o=[]:a&&a(l)?o=[]:e.hideOn&&(o=o.filter(h=>!e.hideOn(l,h)))),l.docChanged&&o.length){let h=[];for(let c of o){let f=l.changes.mapPos(c.pos,-1,Se.TrackDel);if(f!=null){let u=Object.assign(Object.create(null),c);u.pos=f,u.end!=null&&(u.end=l.changes.mapPos(u.end)),h.push(u)}}o=h}for(let h of l.effects)h.is(t)&&(o=h.value,a=void 0),(h.is(Zm)&&!h.value||h.value==n)&&(o=[]);return o.length&&a&&i.set(o,a),o},provide:o=>fn.from(o)});const r=se.define(o=>new Ym(o,s,n,i,t,e.hoverTime||300));return{active:n,extension:[n,r,qc.of(r),Um]}}function Jm(s,e,t,i={}){var n;let r=s.state.facet(qc).map(o=>s.plugin(o)).filter(o=>!!o);if(i.tooltip&&i.tooltip.active){let o=r.find(l=>l.field==i.tooltip.active);o&&(r=[o])}for(let o of r)o.activateHover(s,e,t,(n=i.until)!==null&&n!==void 0?n:(()=>!1))}function Xc(s,e){let t=s.plugin(Uo);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Zm=$.define(),ya=I.define({combine(s){let e,t;for(let i of s)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function _o(s,e){let t=s.plugin(Uc),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Uc=se.fromClass(class{constructor(s){this.input=s.state.facet(Zi),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(s));let e=s.state.facet(ya);this.top=new Es(s,!0,e.topContainer),this.bottom=new Es(s,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(s){let e=s.state.facet(ya);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Es(s.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Es(s.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=s.state.facet(Zi);if(t!=this.input){let i=t.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(s.view),l.push(c)):(c=this.panels[h],c.update&&c.update(s)),n.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>L.scrollMargins.of(e=>{let t=e.plugin(s);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Es{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=ka(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=ka(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function ka(s){let e=s.nextSibling;return s.remove(),e}const Zi=I.define({enables:Uc});function eg(s,e){let t,i=new Promise(o=>t=o),n=o=>tg(o,e,t);s.state.field(ar,!1)?s.dispatch({effects:Yc.of(n)}):s.dispatch({effects:$.appendConfig.of(ar.init(()=>[n]))});let r=_c.of(n);return{close:r,result:i.then(o=>((s.win.queueMicrotask||(a=>s.win.setTimeout(a,10)))(()=>{s.state.field(ar).indexOf(n)>-1&&s.dispatch({effects:r})}),o))}}const ar=ye.define({create(){return[]},update(s,e){for(let t of e.effects)t.is(Yc)?s=[t.value].concat(s):t.is(_c)&&(s=s.filter(i=>i!=t.value));return s},provide:s=>Zi.computeN([s],e=>e.field(s))}),Yc=$.define(),_c=$.define();function tg(s,e,t){let i=e.content?e.content(s,()=>o(null)):null;if(!i){if(i=_("form"),e.input){let l=_("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(_("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(_("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let n=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=_("div",i,_("button",{onclick:()=>o(null),"aria-label":s.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class),r.classList.add("cm-dialog");function o(l){r.contains(r.ownerDocument.activeElement)&&s.focus(),t(l)}return{dom:r,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=i.querySelector(e.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class xt extends Mt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}xt.prototype.elementClass="";xt.prototype.toDOM=void 0;xt.prototype.mapMode=Se.TrackBefore;xt.prototype.startSide=xt.prototype.endSide=-1;xt.prototype.point=!0;const _s=I.define(),ig=I.define(),sg={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>X.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},$i=I.define();function ng(s){return[Kc(),$i.of({...sg,...s})]}const wa=I.define({combine:s=>s.some(e=>e)});function Kc(s){return[rg]}const rg=se.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 Sa(s,e)),this.fixed=!s.state.facet(wa);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(wa)!=!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=X.iter(this.view.state.facet(_s),this.view.viewport.from),i=[],n=this.gutters.map(r=>new og(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==ge.Text&&o){co(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==ge.Text){co(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||!X.eq(s.startState.facet(_s),s.state.facet(_s),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 Sa(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=>L.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==J.LTR?{left:i,right:n}:{right:i,left:n}})});function va(s){return Array.isArray(s)?s:[s]}function co(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class og{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=X.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 Gc(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=[];co(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(ig)){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 Sa{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=va(t.markers(e)),t.initialSpacer&&(this.spacer=new Gc(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=va(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!X.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 Gc{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":""),lg(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,h)||o(l,a,h):o}return i}})}});class hr extends xt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function cr(s,e){return s.state.facet(li).formatNumber(e,s.state)}const cg=$i.compute([li],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(ag)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new hr(cr(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(hg)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(li)!=e.state.facet(li),initialSpacer(e){return new hr(cr(e,Oa(e.state.doc.lines)))},updateSpacer(e,t){let i=cr(t.view,Oa(t.view.state.doc.lines));return i==e.number?e:new hr(i)},domEventHandlers:s.facet(li).domEventHandlers,side:"before"}));function fg(s={}){return[li.of(s),Kc(),cg]}function Oa(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(ug.range(n)))}return X.of(e)});function pg(){return dg}const Jc=1024;let mg=0;class fr{constructor(e,t){this.from=e,this.to=t}}class q{constructor(e={}){this.id=mg++,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=Re.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}q.closedBy=new q({deserialize:s=>s.split(" ")});q.openedBy=new q({deserialize:s=>s.split(" ")});q.group=new q({deserialize:s=>s.split(" ")});q.isolate=new q({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});q.contextHash=new q({perNode:!0});q.lookAhead=new q({perNode:!0});q.mounted=new q({perNode:!0});class ji{constructor(e,t,i,n=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=n}static get(e){return e&&e.props&&e.props[q.mounted.id]}}const gg=Object.create(null);class Re{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):gg,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new Re(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(q.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(q.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}Re.none=new Re("",Object.create(null),0,8);class Ko{constructor(e){this.types=e;for(let t=0;t0;for(let a=this.cursor(o|te.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=n&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!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:Zo(Re.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new re(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new re(Re.none,t,i,n)))}static build(e){return kg(e)}}re.empty=new re(Re.none,[],[],0);class Go{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 Go(this.buffer,this.index)}}class Rt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return Re.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 es(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!=h;e+=t){let c=l[e],f=a[e]+o.from,u;if(!(!(r&te.EnterBracketed&&c instanceof re&&(u=ji.get(c))&&!u.overlay&&u.bracketed&&i>=f&&i<=f+c.length)&&!Zc(n,i,f,f+c.length))){if(c instanceof Rt){if(r&te.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,i-f,n);if(d>-1)return new Ct(new xg(o,c,e,f),null,d)}else if(r&te.IncludeAnonymous||!c.type.isAnonymous||Jo(c)){let d;if(!(r&te.IgnoreMounts)&&(d=ji.get(c))&&!d.overlay)return new He(d.tree,f,e,o);let p=new He(c,f,e,o);return r&te.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,i,n,r)}}}if(r&te.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&te.IgnoreOverlays)&&(n=ji.get(this._tree))&&n.overlay){let r=e-this.from,o=i&te.EnterBracketed&&n.bracketed;for(let{from:l,to:a}of n.overlay)if((t>0||o?l<=r:l=r:a>r))return new He(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 Aa(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 fo(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 xg{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class Ct extends ef{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 Ct(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&te.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 Ct(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 Ct(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 Ct(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 re(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function tf(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;rt.from||o.to=e){let l=new He(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(es(l,e,t,!1))}}return n?tf(n):i}class uo{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~te.EnterBracketed,e instanceof He)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 He?(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&te.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&te.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&te.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&te.IncludeAnonymous||l instanceof Rt||!l.type.isAnonymous||Jo(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 fo(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 Jo(s){return s.children.some(e=>e instanceof Rt||!e.type.isAnonymous||Jo(e))}function kg(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Jc,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new Go(t,t.length):t,a=i.types,h=0,c=0;function f(S,A,O,V,N,P){let{id:D,start:M,end:F,size:R}=l,C=c,B=h;if(R<0)if(l.next(),R==-1){let de=r[D];O.push(de),V.push(M-S);return}else if(R==-3){h=D;return}else if(R==-4){c=D;return}else throw new RangeError(`Unrecognized record size: ${R}`);let j=a[D],oe,Q,ue=M-S;if(F-M<=n&&(Q=g(l.pos-A,N))){let de=new Uint16Array(Q.size-Q.skip),we=l.pos-Q.size,Be=de.length;for(;l.pos>we;)Be=x(Q.start,de,Be);oe=new Rt(de,F-Q.start,i),ue=Q.start-S}else{let de=l.pos-R;l.next();let we=[],Be=[],K=D>=o?D:-1,Qe=0,Nt=F;for(;l.pos>de;)K>=0&&l.id==K&&l.size>=0?(l.end<=Nt-n&&(p(we,Be,M,Qe,l.end,Nt,K,C,B),Qe=we.length,Nt=l.end),l.next()):P>2500?u(M,de,we,Be):f(M,de,we,Be,K,P+1);if(K>=0&&Qe>0&&Qe-1&&Qe>0){let ti=d(j,B);oe=Zo(j,we,Be,0,we.length,0,F-M,ti,ti)}else oe=m(j,we,Be,F-M,C-F,B)}O.push(oe),V.push(ue)}function u(S,A,O,V){let N=[],P=0,D=-1;for(;l.pos>A;){let{id:M,start:F,end:R,size:C}=l;if(C>4)l.next();else{if(D>-1&&F=0;R-=3)M[C++]=N[R],M[C++]=N[R+1]-F,M[C++]=N[R+2]-F,M[C++]=C;O.push(new Rt(M,N[2]-F,i)),V.push(F-S)}}function d(S,A){return(O,V,N)=>{let P=0,D=O.length-1,M,F;if(D>=0&&(M=O[D])instanceof re){if(!D&&M.type==S&&M.length==N)return M;(F=M.prop(q.lookAhead))&&(P=V[D]+M.length+F)}return m(S,O,V,N,P,A)}}function p(S,A,O,V,N,P,D,M,F){let R=[],C=[];for(;S.length>V;)R.push(S.pop()),C.push(A.pop()+O-N);S.push(m(i.types[D],R,C,P-N,M-P,F)),A.push(N-O)}function m(S,A,O,V,N,P,D){if(P){let M=[q.contextHash,P];D=D?[M].concat(D):[M]}if(N>25){let M=[q.lookAhead,N];D=D?[M].concat(D):[M]}return new re(S,A,O,V,D)}function g(S,A){let O=l.fork(),V=0,N=0,P=0,D=O.end-n,M={size:0,start:0,skip:0};e:for(let F=O.pos-S;O.pos>F;){let R=O.size;if(O.id==A&&R>=0){M.size=V,M.start=N,M.skip=P,P+=4,V+=4,O.next();continue}let C=O.pos-R;if(R<0||C=o?4:0,j=O.start;for(O.next();O.pos>C;){if(O.size<0)if(O.size==-3||O.size==-4)B+=4;else break e;else O.id>=o&&(B+=4);O.next()}N=j,V+=R,P+=B}return(A<0||V==S)&&(M.size=V,M.start=N,M.skip=P),M.size>4?M:void 0}function x(S,A,O){let{id:V,start:N,end:P,size:D}=l;if(l.next(),D>=0&&V4){let F=l.pos-(D-4);for(;l.pos>F;)O=x(S,A,O)}A[--O]=M,A[--O]=P-S,A[--O]=N-S,A[--O]=V}else D==-3?h=V:D==-4&&(c=V);return O}let k=[],w=[];for(;l.pos>0;)f(s.start||0,s.bufferStart||0,k,w,-1,0);let T=(e=s.length)!==null&&e!==void 0?e:k.length?w[0]+k[0].length:0;return new re(a[s.topID],k.reverse(),w.reverse(),T)}const Ma=new WeakMap;function Ks(s,e){if(!s.isAnonymous||e instanceof Rt||e.type!=s)return 1;let t=Ma.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof re)){t=1;break}t+=Ks(s,i)}Ma.set(e,t)}return t}function Zo(s,e,t,i,n,r,o,l,a){let h=0;for(let p=i;p=c)break;A+=O}if(w==T+1){if(A>c){let O=p[T];d(O.children,O.positions,0,O.children.length,m[T]+k);continue}f.push(p[T])}else{let O=m[w-1]+p[w-1].length-S;f.push(Zo(s,p,m,T,w,S,O,null,a))}u.push(S+k-r)}}return d(e,t,i,n,0),(l||a)(f,u,o)}class Yt{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 Yt(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,h=0;;l++){let c=l=i)for(;o&&o.from=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Yt(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&n.push(u),o.to>f)break;o=rnew fr(n.from,n.to)):[new fr(0,0)]:[new fr(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 wg{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 q({perNode:!0});let vg=0,ft=class po{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=vg++}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 po&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let n=new po(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 un(e);return i=>i.modified.indexOf(t)>-1?i:un.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}},Sg=0;class un{constructor(e){this.name=e,this.instances=[],this.id=Sg++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Og(t,l.modified));if(i)return i;let n=[],r=new ft(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=Cg(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(un.get(l,a));return r}}function Og(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function Cg(s){let e=[[]];for(let t=0;ti.length-t.length)}function nf(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 f=0;;){if(l=="..."&&f>0&&f+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]),f+=u[0].length,f==n.length)break;let d=n[f++];if(f==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(f)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+n);let c=new ts(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return rf.add(e)}const rf=new q({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 ts(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class ts{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 h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Ag(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function Mg(s,e,t,i=0,n=s.length){let r=new Pg(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class Pg{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 h=n,c=Tg(e)||ts.empty,f=Ag(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(n+=(n?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(q.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),m=e.firstChild();for(let g=0,x=l;;g++){let k=g=w||!e.nextSibling())););if(!k||w>i)break;x=k.to+l,x>t&&(this.highlightRange(d.cursor(),Math.max(t,k.from+l),Math.min(i,x),"",p),this.startSpan(Math.min(i,x),h))}m&&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),h)}while(e.nextSibling());e.parent()}}}function Tg(s){let e=s.type.prop(rf);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const E=ft.define,Ns=E(),yt=E(),Pa=E(yt),Ta=E(yt),kt=E(),Is=E(kt),ur=E(kt),et=E(),Ft=E(et),Je=E(),Ze=E(),mo=E(),Ri=E(mo),Ws=E(),b={comment:Ns,lineComment:E(Ns),blockComment:E(Ns),docComment:E(Ns),name:yt,variableName:E(yt),typeName:Pa,tagName:E(Pa),propertyName:Ta,attributeName:E(Ta),className:E(yt),labelName:E(yt),namespace:E(yt),macroName:E(yt),literal:kt,string:Is,docString:E(Is),character:E(Is),attributeValue:E(Is),number:ur,integer:E(ur),float:E(ur),bool:E(kt),regexp:E(kt),escape:E(kt),color:E(kt),url:E(kt),keyword:Je,self:E(Je),null:E(Je),atom:E(Je),unit:E(Je),modifier:E(Je),operatorKeyword:E(Je),controlKeyword:E(Je),definitionKeyword:E(Je),moduleKeyword:E(Je),operator:Ze,derefOperator:E(Ze),arithmeticOperator:E(Ze),logicOperator:E(Ze),bitwiseOperator:E(Ze),compareOperator:E(Ze),updateOperator:E(Ze),definitionOperator:E(Ze),typeOperator:E(Ze),controlOperator:E(Ze),punctuation:mo,separator:E(mo),bracket:Ri,angleBracket:E(Ri),squareBracket:E(Ri),paren:E(Ri),brace:E(Ri),content:et,heading:Ft,heading1:E(Ft),heading2:E(Ft),heading3:E(Ft),heading4:E(Ft),heading5:E(Ft),heading6:E(Ft),contentSeparator:E(et),list:E(et),quote:E(et),emphasis:E(et),strong:E(et),link:E(et),monospace:E(et),strikethrough:E(et),inserted:E(),deleted:E(),changed:E(),invalid:E(),meta:Ws,documentMeta:E(Ws),annotation:E(Ws),processingInstruction:E(Ws),definition:ft.defineModifier("definition"),constant:ft.defineModifier("constant"),function:ft.defineModifier("function"),standard:ft.defineModifier("standard"),local:ft.defineModifier("local"),special:ft.defineModifier("special")};for(let s in b){let e=b[s];e instanceof ft&&(e.name=s)}of([{tag:b.link,class:"tok-link"},{tag:b.heading,class:"tok-heading"},{tag:b.emphasis,class:"tok-emphasis"},{tag:b.strong,class:"tok-strong"},{tag:b.keyword,class:"tok-keyword"},{tag:b.atom,class:"tok-atom"},{tag:b.bool,class:"tok-bool"},{tag:b.url,class:"tok-url"},{tag:b.labelName,class:"tok-labelName"},{tag:b.inserted,class:"tok-inserted"},{tag:b.deleted,class:"tok-deleted"},{tag:b.literal,class:"tok-literal"},{tag:b.string,class:"tok-string"},{tag:b.number,class:"tok-number"},{tag:[b.regexp,b.escape,b.special(b.string)],class:"tok-string2"},{tag:b.variableName,class:"tok-variableName"},{tag:b.local(b.variableName),class:"tok-variableName tok-local"},{tag:b.definition(b.variableName),class:"tok-variableName tok-definition"},{tag:b.special(b.variableName),class:"tok-variableName2"},{tag:b.definition(b.propertyName),class:"tok-propertyName tok-definition"},{tag:b.typeName,class:"tok-typeName"},{tag:b.namespace,class:"tok-namespace"},{tag:b.className,class:"tok-className"},{tag:b.macroName,class:"tok-macroName"},{tag:b.propertyName,class:"tok-propertyName"},{tag:b.operator,class:"tok-operator"},{tag:b.comment,class:"tok-comment"},{tag:b.meta,class:"tok-meta"},{tag:b.invalid,class:"tok-invalid"},{tag:b.punctuation,class:"tok-punctuation"}]);var dr;const ai=new q;function Dg(s){return I.define({combine:s?e=>e.concat(s):void 0})}const Rg=new q;class qe{constructor(e,t,i=[],n=""){this.data=e,this.name=n,U.prototype.hasOwnProperty("tree")||Object.defineProperty(U.prototype,"tree",{get(){return be(this)}}),this.parser=t,this.extension=[Bt.of(this),U.languageData.of((r,o,l)=>{let a=Da(r,o,l),h=a.type.prop(ai);if(!h)return[];let c=r.facet(h),f=a.type.prop(Rg);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return Da(e,t,i).type.prop(ai)==this.data}findRegions(e){let t=e.facet(Bt);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(ai)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(q.mounted);if(l){if(l.tree.prop(ai)==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 dn(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function be(s){let e=s.field(qe.state,!1);return e?e.tree:re.empty}class Bg{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 Bi=null;class pn{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 pn(e,t,[],re.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Bg(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=re.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(Yt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Bi;Bi=this;try{return e()}finally{Bi=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Ra(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((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Yt.applyChanges(i,a),n=re.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);ce.from&&(this.fragments=Ra(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 sf{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=Bi;if(a){for(let h of n)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new re(Re.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 Bi}}function Ra(s,e,t){return Yt.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class vi{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 vi(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=pn.create(e.facet(Bt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new vi(i)}}qe.state=ye.define({create:vi.init,update(s,e){for(let t of e.effects)if(t.is(qe.setState))return t.value;return e.startState.facet(Bt)!=e.state.facet(Bt)?vi.init(e.state):s.apply(e)}});let lf=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(lf=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const pr=typeof navigator<"u"&&(!((dr=navigator.scheduling)===null||dr===void 0)&&dr.isInputPending)?()=>navigator.scheduling.isInputPending():null,Eg=se.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(qe.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(qe.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=lf(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndn+1e3,a=r.context.work(()=>pr&&pr()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:qe.setState.of(new vi(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=>Pe(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()}}}),Bt=I.define({combine(s){return s.length?s[0]:null},enables:s=>[qe.state,Eg,L.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class Lg{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Ng=I.define(),Fn=I.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 mn(s){let e=s.facet(Fn);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function is(s,e){let t="",i=s.tabSize,n=s.facet(Fn)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r=e?Ig(s,t,e):null}class Vn{constructor(e,t={}){this.state=e,this.options=t,this.unit=mn(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 Ci(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 af=new q;function Ig(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 hf(i,s,t)}function hf(s,e,t){for(let i=s;i;i=i.next){let n=Fg(i.node);if(n)return n(tl.create(e,t,i))}return 0}function Wg(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function Fg(s){let e=s.type.prop(af);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(q.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>cf(o,!0,1,void 0,r&&!Wg(o)?n.from:void 0)}return s.parent==null?Vg:null}function Vg(){return 0}class tl extends Vn{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 tl(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(Hg(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return hf(this.context.next,this.base,this.pos)}}function Hg(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function zg(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 h=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function Ba({closing:s,align:e=!0,units:t=1}){return i=>cf(i,e,t,s)}function cf(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=e?zg(s):null;return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}const Qg=200;function $g(){return U.transactionFilter.of(s=>{if(!s.docChanged||!s.isUserEvent("input.type")&&!s.isUserEvent("input.complete"))return s;let e=s.startState.languageDataAt("indentOnInput",s.startState.selection.main.head);if(!e.length)return s;let t=s.newDoc,{head:i}=s.newSelection.main,n=t.lineAt(i);if(i>n.from+Qg)return s;let r=t.sliceString(n.from,i);if(!e.some(h=>h.test(r)))return s;let{state:o}=s,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let f=el(o,c.from);if(f==null)continue;let u=/^\s*/.exec(c.text)[0],d=is(o,f);u!=d&&a.push({from:c.from,to:c.from+u.length,insert:d})}return a.length?[s,{changes:a,sequential:!0}]:s})}const jg=I.define(),ff=new q;function qg(s){let e=s.firstChild,t=s.lastChild;return e&&e.tot)continue;if(r&&l.from=e&&h.to>t&&(r=h)}}return r}function Ug(s){let e=s.lastChild;return e&&e.to==s.to&&e.type.isError}function gn(s,e,t){for(let i of s.facet(jg)){let n=i(s,e,t);if(n)return n}return Xg(s,e,t)}function uf(s,e){let t=e.mapPos(s.from,1),i=e.mapPos(s.to,-1);return t>=i?void 0:{from:t,to:i}}const Hn=$.define({map:uf}),us=$.define({map:uf});function df(s){let e=[];for(let{head:t}of s.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(s.lineBlockAt(t));return e}const Zt=ye.define({create(){return z.none},update(s,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,i)=>s=Ea(s,t,i)),s=s.map(e.changes);for(let t of e.effects)if(t.is(Hn)&&!Yg(s,t.value.from,t.value.to)){let{preparePlaceholder:i}=e.state.facet(gf),n=i?z.replace({widget:new t0(i(e.state,t.value))}):La;s=s.update({add:[n.range(t.value.from,t.value.to)]})}else t.is(us)&&(s=s.update({filter:(i,n)=>t.value.from!=i||t.value.to!=n,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(s=Ea(s,e.selection.main.head)),s},provide:s=>L.decorations.from(s),toJSON(s,e){let t=[];return s.between(0,e.doc.length,(i,n)=>{t.push(i,n)}),t},fromJSON(s){if(!Array.isArray(s)||s.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t{ne&&(i=!0)}),i?s.update({filterFrom:e,filterTo:t,filter:(n,r)=>n>=t||r<=e}):s}function xn(s,e,t){var i;let n=null;return(i=s.field(Zt,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!n||n.from>r)&&(n={from:r,to:o})}),n}function Yg(s,e,t){let i=!1;return s.between(e,e,(n,r)=>{n==e&&r==t&&(i=!0)}),i}function pf(s,e){return s.field(Zt,!1)?e:e.concat($.appendConfig.of(xf()))}const _g=s=>{for(let e of df(s)){let t=gn(s.state,e.from,e.to);if(t)return s.dispatch({effects:pf(s.state,[Hn.of(t),mf(s,t)])}),!0}return!1},Kg=s=>{if(!s.state.field(Zt,!1))return!1;let e=[];for(let t of df(s)){let i=xn(s.state,t.from,t.to);i&&e.push(us.of(i),mf(s,i,!1))}return e.length&&s.dispatch({effects:e}),e.length>0};function mf(s,e,t=!0){let i=s.state.doc.lineAt(e.from).number,n=s.state.doc.lineAt(e.to).number;return L.announce.of(`${s.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${s.state.phrase("to")} ${n}.`)}const Gg=s=>{let{state:e}=s,t=[];for(let i=0;i{let e=s.state.field(Zt,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,s.state.doc.length,(i,n)=>{t.push(us.of({from:i,to:n}))}),s.dispatch({effects:t}),!0},Zg=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:_g},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Kg},{key:"Ctrl-Alt-[",run:Gg},{key:"Ctrl-Alt-]",run:Jg}],e0={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},gf=I.define({combine(s){return ht(s,e0)}});function xf(s){return[Zt,n0]}function bf(s,e){let{state:t}=s,i=t.facet(gf),n=o=>{let l=s.lineBlockAt(s.posAtDOM(o.target)),a=xn(s.state,l.from,l.to);a&&s.dispatch({effects:us.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(s,n,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=n,r}const La=z.replace({widget:new class extends ct{toDOM(s){return bf(s,null)}}});class t0 extends ct{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return bf(e,this.value)}}const i0={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class mr extends xt{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function s0(s={}){let e={...i0,...s},t=new mr(e,!0),i=new mr(e,!1),n=se.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Bt)!=o.state.facet(Bt)||o.startState.field(Zt,!1)!=o.state.field(Zt,!1)||be(o.startState)!=be(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new mt;for(let a of o.viewportLineBlocks){let h=xn(o.state,a.from,a.to)?i:gn(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:r}=e;return[n,ng({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(n))===null||l===void 0?void 0:l.markers)||X.empty},initialSpacer(){return new mr(e,!1)},domEventHandlers:{...r,click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let h=xn(o.state,l.from,l.to);if(h)return o.dispatch({effects:us.of(h)}),!0;let c=gn(o.state,l.from,l.to);return c?(o.dispatch({effects:Hn.of(c)}),!0):!1}}}),xf()]}const n0=L.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class ds{constructor(e,t){this.specs=e;let i;function n(l){let a=Pt.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?n(t.all):void 0,o=t.scope;this.scope=o instanceof qe?l=>l.prop(ai)==o.data:o?l=>l==o:void 0,this.style=of(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new Pt(i):null,this.themeType=t.themeType}static define(e,t){return new ds(e,t||{})}}const go=I.define(),yf=I.define({combine(s){return s.length?[s[0]]:null}});function gr(s){let e=s.facet(go);return e.length?e:s.facet(yf)}function kf(s,e){let t=[o0],i;return s instanceof ds&&(s.module&&t.push(L.styleModule.of(s.module)),i=s.themeType),e?.fallback?t.push(yf.of(s)):i?t.push(go.computeN([L.darkTheme],n=>n.facet(L.darkTheme)==(i=="dark")?[s]:[])):t.push(go.of(s)),t}class r0{constructor(e){this.markCache=Object.create(null),this.tree=be(e.state),this.decorations=this.buildDeco(e,gr(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=be(e.state),i=gr(e.state),n=i!=gr(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 z.none;let i=new mt;for(let{from:n,to:r}of e.visibleRanges)Mg(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=z.mark({class:a})))},n,r);return i.finish()}}const o0=ei.high(se.fromClass(r0,{decorations:s=>s.decorations})),l0=ds.define([{tag:b.meta,color:"#404740"},{tag:b.link,textDecoration:"underline"},{tag:b.heading,textDecoration:"underline",fontWeight:"bold"},{tag:b.emphasis,fontStyle:"italic"},{tag:b.strong,fontWeight:"bold"},{tag:b.strikethrough,textDecoration:"line-through"},{tag:b.keyword,color:"#708"},{tag:[b.atom,b.bool,b.url,b.contentSeparator,b.labelName],color:"#219"},{tag:[b.literal,b.inserted],color:"#164"},{tag:[b.string,b.deleted],color:"#a11"},{tag:[b.regexp,b.escape,b.special(b.string)],color:"#e40"},{tag:b.definition(b.variableName),color:"#00f"},{tag:b.local(b.variableName),color:"#30a"},{tag:[b.typeName,b.namespace],color:"#085"},{tag:b.className,color:"#167"},{tag:[b.special(b.variableName),b.macroName],color:"#256"},{tag:b.definition(b.propertyName),color:"#00c"},{tag:b.comment,color:"#940"},{tag:b.invalid,color:"#f00"}]),a0=L.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),wf=1e4,vf="()[]{}",Sf=I.define({combine(s){return ht(s,{afterCursor:!0,brackets:vf,maxScanDistance:wf,renderMatch:f0})}}),h0=z.mark({class:"cm-matchingBracket"}),c0=z.mark({class:"cm-nonmatchingBracket"});function f0(s){let e=[],t=s.matched?h0:c0;return e.push(t.range(s.start.from,s.start.to)),s.end&&e.push(t.range(s.end.from,s.end.to)),e}function Na(s){let e=[],t=s.facet(Sf);for(let i of s.selection.ranges){if(!i.empty)continue;let n=rt(s,i.head,-1,t)||i.head>0&&rt(s,i.head-1,1,t)||t.afterCursor&&(rt(s,i.head,1,t)||i.heads.decorations}),d0=[u0,a0];function p0(s={}){return[Sf.of(s),d0]}const m0=new q;function xo(s,e,t){let i=s.prop(e<0?q.openedBy:q.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 bo(s){let e=s.type.prop(m0);return e?e(s.node):s}function rt(s,e,t,i={}){let n=i.maxScanDistance||wf,r=i.brackets||vf,o=be(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=xo(a.type,t,r);if(h&&a.from0?e>=c.from&&ec.from&&e<=c.to))return g0(s,e,t,a,c,h,r)}}return x0(s,e,t,o,l.type,n,r)}function g0(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},h=0,c=l?.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=s.doc.iterRange(e,t>0?s.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let x=o.indexOf(d[m]);if(!(x<0||i.resolveInner(p+m,1).type!=n))if(x%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:x>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}const b0=Object.create(null),Ia=[Re.none],Wa=[],Fa=Object.create(null),y0=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"]])y0[s]=k0(b0,e);function xr(s,e){Wa.indexOf(s)>-1||(Wa.push(s),console.warn(e))}function k0(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=s[h]||b[h];c?typeof c=="function"?a.length?a=a.map(c):xr(h,`Modifier ${h} used at start of tag`):a.length?xr(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:xr(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=Fa[n];if(r)return r.id;let o=Fa[n]=Re.define({id:Ia.length,name:i,props:[nf({[i]:t})]});return Ia.push(o),o.id}J.RTL,J.LTR;const w0=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=sl(s.state,t.from);return i.line?v0(s):i.block?O0(s):!1};function il(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 v0=il(M0,0),S0=il(Of,0),O0=il((s,e)=>Of(s,e,A0(e)),0);function sl(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Ei=50;function C0(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-Ei,i),o=s.sliceDoc(n,n+Ei),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let c,f;n-i<=2*Ei?c=f=s.sliceDoc(i,n):(c=s.sliceDoc(i,i+Ei),f=s.sliceDoc(n-Ei,n));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function A0(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 Of(s,e,t=e.selection.ranges){let i=t.map(r=>sl(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>C0(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>f.from)){n=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;ur.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+h,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 h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}const yo=at.define(),P0=at.define(),T0=I.define(),Cf=I.define({combine(s){return ht(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)})}}),Af=ye.define({create(){return ot.empty},update(s,e){let t=e.state.facet(Cf),i=e.annotation(yo);if(i){let a=Te.fromTransaction(e,i.selection),h=i.side,c=h==0?s.undone:s.done;return a?c=bn(c,c.length,t.minDepth,a):c=Tf(c,e.startState.selection),new ot(h==0?i.rest:c,h==0?c:i.rest)}let n=e.annotation(P0);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(he.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=Te.fromTransaction(e),o=e.annotation(he.time),l=e.annotation(he.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 ot(s.done.map(Te.fromJSON),s.undone.map(Te.fromJSON))}});function D0(s={}){return[Af,Cf.of(s),L.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Mf:e.inputType=="historyRedo"?ko:null;return i?(e.preventDefault(),i(t)):!1}})]}function zn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(Af,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const Mf=zn(0,!1),ko=zn(1,!1),R0=zn(0,!0),B0=zn(1,!0);class Te{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 Te(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 Te(e.changes&&ae.fromJSON(e.changes),[],e.mapped&<.fromJSON(e.mapped),e.startSelection&&v.fromJSON(e.startSelection),e.selectionsAfter.map(v.fromJSON))}static fromTransaction(e,t){let i=Fe;for(let n of e.startState.facet(T0)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new Te(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Fe)}static selection(e){return new Te(void 0,Fe,void 0,void 0,e)}}function bn(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 E0(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=h&&o<=c&&(i=!0)}}),i}function L0(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function Pf(s,e){return s.length?e.length?s.concat(e):s:e}const Fe=[],N0=200;function Tf(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-N0));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),bn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[Te.selection([e])]}function I0(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 br(s,e){if(!s.length)return s;let t=s.length,i=Fe;for(;t;){let n=W0(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?[Te.selection(i)]:Fe}function W0(s,e,t){let i=Pf(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):Fe,t);if(!s.changes)return Te.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new Te(n,$.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const F0=/^(input\.type|delete)($|\.)/;class ot{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 ot(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||F0.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?s.moveByChar(t,e):Qn(t,e))}function ke(s){return s.textDirectionAt(s.state.selection.main.head)==J.LTR}const Rf=s=>Df(s,!ke(s)),Bf=s=>Df(s,ke(s));function Ef(s,e){return Ye(s,t=>t.empty?s.moveByGroup(t,e):Qn(t,e))}const H0=s=>Ef(s,!ke(s)),z0=s=>Ef(s,ke(s));function Q0(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 $n(s,e,t){let i=be(s).resolveInner(e.head),n=t?q.closedBy:q.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Q0(s,h,n)?i=h:a=t?h.to:h.from}let r=i.type.prop(n),o,l;return r&&(o=t?rt(s,i.from,1):rt(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,v.cursor(l,t?-1:1)}const $0=s=>Ye(s,e=>$n(s.state,e,!ke(s))),j0=s=>Ye(s,e=>$n(s.state,e,ke(s)));function Lf(s,e){return Ye(s,t=>{if(!t.empty)return Qn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const Nf=s=>Lf(s,!1),If=s=>Lf(s,!0);function Wf(s){let e=s.scrollDOM.clientHeighto.empty?s.moveVertically(o,e,t.height):Qn(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,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottomFf(s,!1),wo=s=>Ff(s,!0);function Lt(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=v.cursor(i.from+r))}return n}const q0=s=>Ye(s,e=>Lt(s,e,!0)),X0=s=>Ye(s,e=>Lt(s,e,!1)),U0=s=>Ye(s,e=>Lt(s,e,!ke(s))),Y0=s=>Ye(s,e=>Lt(s,e,ke(s))),_0=s=>Ye(s,e=>v.cursor(s.lineBlockAt(e.head).from,1)),K0=s=>Ye(s,e=>v.cursor(s.lineBlockAt(e.head).to,-1));function G0(s,e,t){let i=!1,n=Ai(s.selection,r=>{let o=rt(s,r.head,-1)||rt(s,r.head,1)||r.head>0&&rt(s,r.head-1,1)||r.headG0(s,e);function ze(s,e){let t=Ai(s.state.selection,i=>{let n=e(i);return v.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return t.eq(s.state.selection)?!1:(s.dispatch(Ue(s.state,t)),!0)}function Vf(s,e){return ze(s,t=>s.moveByChar(t,e))}const Hf=s=>Vf(s,!ke(s)),zf=s=>Vf(s,ke(s));function Qf(s,e){return ze(s,t=>s.moveByGroup(t,e))}const Z0=s=>Qf(s,!ke(s)),ex=s=>Qf(s,ke(s)),tx=s=>ze(s,e=>$n(s.state,e,!ke(s))),ix=s=>ze(s,e=>$n(s.state,e,ke(s)));function $f(s,e){return ze(s,t=>s.moveVertically(t,e))}const jf=s=>$f(s,!1),qf=s=>$f(s,!0);function Xf(s,e){return ze(s,t=>s.moveVertically(t,e,Wf(s).height))}const Ha=s=>Xf(s,!1),za=s=>Xf(s,!0),sx=s=>ze(s,e=>Lt(s,e,!0)),nx=s=>ze(s,e=>Lt(s,e,!1)),rx=s=>ze(s,e=>Lt(s,e,!ke(s))),ox=s=>ze(s,e=>Lt(s,e,ke(s))),lx=s=>ze(s,e=>v.cursor(s.lineBlockAt(e.head).from)),ax=s=>ze(s,e=>v.cursor(s.lineBlockAt(e.head).to)),Qa=({state:s,dispatch:e})=>(e(Ue(s,{anchor:0})),!0),$a=({state:s,dispatch:e})=>(e(Ue(s,{anchor:s.doc.length})),!0),ja=({state:s,dispatch:e})=>(e(Ue(s,{anchor:s.selection.main.anchor,head:0})),!0),qa=({state:s,dispatch:e})=>(e(Ue(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),hx=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),cx=({state:s,dispatch:e})=>{let t=jn(s).map(({from:i,to:n})=>v.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:v.create(t),userEvent:"select"})),!0},fx=({state:s,dispatch:e})=>{let t=Ai(s.selection,i=>{let n=be(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 v.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Ue(s,t)),!0)};function Uf(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(h=>h.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(Ue(t,v.create(n,n.length-1))),!0)}const ux=s=>Uf(s,!1),dx=s=>Uf(s,!0),px=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=v.create([t.main]):t.main.empty||(i=v.create([v.cursor(t.main.head)])),i?(e(Ue(s,i)),!0):!1};function ps(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=Fs(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Fs(s,o,!1),l=Fs(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:v.cursor(o,on(s)))i.between(e,e,(n,r)=>{ne&&(e=t?r:n)});return e}const Yf=(s,e,t)=>ps(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(t&&!e&&n>o.from&&nYf(s,!1,!0),_f=s=>Yf(s,!0,!1),Kf=(s,e)=>ps(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=fe(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t.head)&&(l=c),i=a}return i}),Gf=s=>Kf(s,!1),mx=s=>Kf(s,!0),gx=s=>ps(s,e=>{let t=s.lineBlockAt(e.head).to;return e.headps(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),bx=s=>ps(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:Y.of(["",""])},range:v.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},kx=({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:fe(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:fe(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:v.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function jn(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 Jf(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of jn(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(v.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(v.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:v.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const wx=({state:s,dispatch:e})=>Jf(s,e,!1),vx=({state:s,dispatch:e})=>Jf(s,e,!0);function Zf(s,e,t){if(s.readOnly)return!1;let i=[];for(let r of jn(s))t?i.push({from:r.from,insert:s.doc.slice(r.from,r.to)+s.lineBreak}):i.push({from:r.to,insert:s.lineBreak+s.doc.slice(r.from,r.to)});let n=s.changes(i);return e(s.update({changes:n,selection:s.selection.map(n,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Sx=({state:s,dispatch:e})=>Zf(s,e,!1),Ox=({state:s,dispatch:e})=>Zf(s,e,!0),Cx=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(jn(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 Ax(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=be(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(q.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 Xa=eu(!1),Mx=eu(!0);function eu(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&&Ax(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Vn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=el(h,r);for(c==null&&(c=Ci(/^\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:v.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Px=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new Vn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=nl(s,(r,o,l)=>{let a=el(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=is(s,a);(h!=c||l.froms.readOnly?!1:(e(s.update(nl(s,(t,i)=>{i.push({from:t.from,insert:s.facet(Fn)})}),{userEvent:"input.indent"})),!0),iu=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(nl(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=Ci(n,s.tabSize),o=0,l=is(s,Math.max(0,r-mn(s)));for(;o(s.setTabFocusMode(),!0),Dx=[{key:"Ctrl-b",run:Rf,shift:Hf,preventDefault:!0},{key:"Ctrl-f",run:Bf,shift:zf},{key:"Ctrl-p",run:Nf,shift:jf},{key:"Ctrl-n",run:If,shift:qf},{key:"Ctrl-a",run:_0,shift:lx},{key:"Ctrl-e",run:K0,shift:ax},{key:"Ctrl-d",run:_f},{key:"Ctrl-h",run:vo},{key:"Ctrl-k",run:gx},{key:"Ctrl-Alt-h",run:Gf},{key:"Ctrl-o",run:yx},{key:"Ctrl-t",run:kx},{key:"Ctrl-v",run:wo}],Rx=[{key:"ArrowLeft",run:Rf,shift:Hf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:H0,shift:Z0,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:U0,shift:rx,preventDefault:!0},{key:"ArrowRight",run:Bf,shift:zf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:z0,shift:ex,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Y0,shift:ox,preventDefault:!0},{key:"ArrowUp",run:Nf,shift:jf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Qa,shift:ja},{mac:"Ctrl-ArrowUp",run:Va,shift:Ha},{key:"ArrowDown",run:If,shift:qf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:$a,shift:qa},{mac:"Ctrl-ArrowDown",run:wo,shift:za},{key:"PageUp",run:Va,shift:Ha},{key:"PageDown",run:wo,shift:za},{key:"Home",run:X0,shift:nx,preventDefault:!0},{key:"Mod-Home",run:Qa,shift:ja},{key:"End",run:q0,shift:sx,preventDefault:!0},{key:"Mod-End",run:$a,shift:qa},{key:"Enter",run:Xa,shift:Xa},{key:"Mod-a",run:hx},{key:"Backspace",run:vo,shift:vo,preventDefault:!0},{key:"Delete",run:_f,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Gf,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:mx,preventDefault:!0},{mac:"Mod-Backspace",run:xx,preventDefault:!0},{mac:"Mod-Delete",run:bx,preventDefault:!0}].concat(Dx.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),Bx=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:$0,shift:tx},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:j0,shift:ix},{key:"Alt-ArrowUp",run:wx},{key:"Shift-Alt-ArrowUp",run:Sx},{key:"Alt-ArrowDown",run:vx},{key:"Shift-Alt-ArrowDown",run:Ox},{key:"Mod-Alt-ArrowUp",run:ux},{key:"Mod-Alt-ArrowDown",run:dx},{key:"Escape",run:px},{key:"Mod-Enter",run:Mx},{key:"Alt-l",mac:"Ctrl-l",run:cx},{key:"Mod-i",run:fx,preventDefault:!0},{key:"Mod-[",run:iu},{key:"Mod-]",run:tu},{key:"Mod-Alt-\\",run:Px},{key:"Shift-Mod-k",run:Cx},{key:"Shift-Mod-\\",run:J0},{key:"Mod-/",run:w0},{key:"Alt-A",run:S0},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Tx}].concat(Rx),Ex={key:"Tab",run:tu,shift:iu},Ua=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class Si{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(Ua(l)):Ua,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 Ce(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=Ro(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=it(e);let n=this.normalize(t);if(n.length)for(let r=0,o=i,l=!0;;r++){let a=n.charCodeAt(r),h=this.match(a,o,l,this.bufferPos+this.bufferStart,r==n.length-1);if(h)return this.value=h,this;if(r==n.length-1)break;l&&rthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,n=i+t[0].length;if(this.matchPos=yn(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length=i||n.to<=t){let l=new pi(t,e.sliceString(t,i));return yr.set(e,l),l}if(n.from==t&&n.to==i)return n;let{text:r,from:o}=n;return o>t&&(r=e.sliceString(t,o)+r,o=t),n.to=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,n=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,precise:!0,match:t},this.matchPos=yn(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=pi.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(nu.prototype[Symbol.iterator]=ru.prototype[Symbol.iterator]=function(){return this});function Lx(s){try{return new RegExp(s,rl),!0}catch{return!1}}function yn(s,e){if(e>=s.length)return e;let t=s.lineAt(e),i;for(;e=56320&&i<57344;)e++;return e}const Nx=s=>{let{state:e}=s,t=String(e.doc.lineAt(s.state.selection.main.head).number),{close:i,result:n}=eg(s,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return n.then(r=>{let o=r&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.elements.line.value);if(!o){s.dispatch({effects:i});return}let l=e.doc.lineAt(e.selection.main.head),[,a,h,c,f]=o,u=c?+c.slice(1):0,d=h?+h:l.number;if(h&&f){let g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/e.doc.lines),d=Math.round(e.doc.lines*g)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=e.doc.line(Math.max(1,Math.min(e.doc.lines,d))),m=v.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[i,L.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},Ix={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Wx=I.define({combine(s){return ht(s,Ix,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Fx(s){return[$x,Qx]}const Vx=z.mark({class:"cm-selectionMatch"}),Hx=z.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Ya(s,e,t,i){return(t==0||s(e.sliceDoc(t-1,t))!=ee.Word)&&(i==e.doc.length||s(e.sliceDoc(i,i+1))!=ee.Word)}function zx(s,e,t,i){return s(e.sliceDoc(t,t+1))==ee.Word&&s(e.sliceDoc(i-1,i))==ee.Word}const Qx=se.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(Wx),{state:t}=s,i=t.selection;if(i.ranges.length>1)return z.none;let n=i.main,r,o=null;if(n.empty){if(!e.highlightWordAroundCursor)return z.none;let a=t.wordAt(n.head);if(!a)return z.none;o=t.charCategorizer(n.head),r=t.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a200)return z.none;if(e.wholeWords){if(r=t.sliceDoc(n.from,n.to),o=t.charCategorizer(n.head),!(Ya(o,t,n.from,n.to)&&zx(o,t,n.from,n.to)))return z.none}else if(r=t.sliceDoc(n.from,n.to),!r)return z.none}let l=[];for(let a of s.visibleRanges){let h=new Si(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:f}=h.value;if((!o||Ya(o,t,c,f))&&(n.empty&&c<=n.from&&f>=n.to?l.push(Hx.range(c,f)):(c>=n.to||f<=n.from)&&l.push(Vx.range(c,f)),l.length>e.maxMatches))return z.none}}return z.set(l)}},{decorations:s=>s.decorations}),$x=L.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),jx=({state:s,dispatch:e})=>{let{selection:t}=s,i=v.create(t.ranges.map(n=>s.wordAt(n.head)||v.cursor(n.head)),t.mainIndex);return i.eq(t)?!1:(e(s.update({selection:i})),!0)};function qx(s,e){let{main:t,ranges:i}=s.selection,n=s.wordAt(t.head),r=n&&n.from==t.from&&n.to==t.to;for(let o=!1,l=new Si(s.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Si(s.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=s.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const Xx=({state:s,dispatch:e})=>{let{ranges:t}=s.selection;if(t.some(r=>r.from===r.to))return jx({state:s,dispatch:e});let i=s.sliceDoc(t[0].from,t[0].to);if(s.selection.ranges.some(r=>s.sliceDoc(r.from,r.to)!=i))return!1;let n=qx(s,i);return n?(e(s.update({selection:s.selection.addRange(v.range(n.from,n.to),!1),effects:L.scrollIntoView(n.to)})),!0):!1},Mi=I.define({combine(s){return ht(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new ob(e),scrollToMatch:e=>L.scrollIntoView(e)})}});class ou{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Lx(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?` `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Jx(this):new _x(this)}getCursor(e,t=0,i){let n=e.doc?e:U.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?ni(this,n,t,i):si(this,n,t,i)}}class lu{constructor(e){this.spec=e}}function Ux(s,e,t){return(i,n,r,o)=>{if(t&&!t(i,n,r,o))return!1;let l=i>=o&&n<=o+r.length?r.slice(i-o,n-o):e.doc.sliceString(i,n);return s(l,e,i,n)}}function si(s,e,t,i){let n;return s.wholeWord&&(n=Yx(e.doc,e.charCategorizer(e.selection.main.head))),s.test&&(n=Ux(s.test,e,n)),new Si(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:r=>r.toLowerCase(),n)}function Yx(s,e){return(t,i,n,r)=>((r>t||r+n.length=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=si(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function Kx(s,e,t){return(i,n,r)=>(!t||t(i,n,r))&&s(r[0],e,i,n)}function ni(s,e,t,i){let n;return s.wholeWord&&(n=Gx(e.charCategorizer(e.selection.main.head))),s.test&&(n=Kx(s.test,e,n)),new nu(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:n},t,i)}function kn(s,e){return s.slice(fe(s,e,!1),e)}function wn(s,e){return s.slice(e,fe(s,e))}function Gx(s){return(e,t,i)=>!i[0].length||(s(kn(i.input,i.index))!=ee.Word||s(wn(i.input,i.index))!=ee.Word)&&(s(wn(i.input,i.index+i[0].length))!=ee.Word||s(kn(i.input,i.index+i[0].length))!=ee.Word)}class Jx extends lu{nextMatch(e,t,i){let n=ni(this.spec,e,i,e.doc.length).next();return n.done&&(n=ni(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-n*1e4),o=ni(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let n=i.length;n>0;n--){let r=+i.slice(0,n);if(r>0&&r=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=ni(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const ss=$.define(),ol=$.define(),At=ye.define({create(s){return new kr(So(s).create(),null)},update(s,e){for(let t of e.effects)t.is(ss)?s=new kr(t.value.create(),s.panel):t.is(ol)&&(s=new kr(s.query,t.value?ll:null));return s},provide:s=>Zi.from(s,e=>e.panel)});class kr{constructor(e,t){this.query=e,this.panel=t}}const Zx=z.mark({class:"cm-searchMatch"}),eb=z.mark({class:"cm-searchMatch cm-searchMatch-selected"}),tb=se.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(At))}update(s){let e=s.state.field(At);(e!=s.startState.field(At)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return z.none;let{view:t}=this,i=new mt;for(let n=0,r=t.visibleRanges,o=r.length;nr[n+1].from-500;)a=r[++n].to;s.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?eb:Zx)})}return i.finish()}},{decorations:s=>s.decorations});function ms(s){return e=>{let t=e.state.field(At,!1);return t&&t.query.spec.valid?s(e,t):cu(e)}}const vn=ms((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=v.single(i.from,i.to),r=s.state.facet(Mi);return s.dispatch({selection:n,effects:[al(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),hu(s),!0}),Sn=ms((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=v.single(n.from,n.to),o=s.state.facet(Mi);return s.dispatch({selection:r,effects:[al(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),hu(s),!0}),ib=ms((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:v.create(t.map(i=>v.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),sb=({state:s,dispatch:e})=>{let t=s.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:n}=t.main,r=[],o=0;for(let l=new Si(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(v.range(l.value.from,l.value.to))}return e(s.update({selection:v.create(r,o),userEvent:"select.search.matches"})),!0},_a=ms((s,{query:e})=>{let{state:t}=s,{from:i,to:n}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=r,l=[],a,h,c=[];o.precise?o.from==i&&o.to==n&&(h=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(t,o.from,o.to),c.push(L.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))):o=e.nextMatch(t,o.from,o.to);let f=s.state.changes(l);return o&&(a=v.single(o.from,o.to).map(f),c.push(al(s,o)),c.push(t.facet(Mi).scrollToMatch(a.main,s))),s.dispatch({changes:f,selection:a,effects:c,userEvent:"input.replace"}),!0}),nb=ms((s,{query:e})=>{if(s.state.readOnly)return!1;let t=[];for(let n of e.matchAll(s.state,1e9)){let{from:r,to:o,precise:l}=n;l&&t.push({from:r,to:o,insert:e.getReplacement(n)})}if(!t.length)return!1;let i=s.state.phrase("replaced $ matches",t.length)+".";return s.dispatch({changes:t,effects:L.announce.of(i),userEvent:"input.replace.all"}),!0});function ll(s){return s.state.facet(Mi).createPanel(s)}function So(s,e){var t,i,n,r,o;let l=s.selection.main,a=l.empty||l.to>l.from+100?"":s.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=s.facet(Mi);return new ou({search:((t=e?.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e?.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function au(s){let e=_o(s,ll);return e&&e.dom.querySelector("[main-field]")}function hu(s){let e=au(s);e&&e==s.root.activeElement&&e.select()}const cu=s=>{let e=s.state.field(At,!1);if(e&&e.panel){let t=au(s);if(t&&t!=s.root.activeElement){let i=So(s.state,e.query.spec);i.valid&&s.dispatch({effects:ss.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[ol.of(!0),e?ss.of(So(s.state,e.query.spec)):$.appendConfig.of(ab)]});return!0},fu=s=>{let e=s.state.field(At,!1);if(!e||!e.panel)return!1;let t=_o(s,ll);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:ol.of(!1)}),!0},rb=[{key:"Mod-f",run:cu,scope:"editor search-panel"},{key:"F3",run:vn,shift:Sn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:vn,shift:Sn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:fu,scope:"editor search-panel"},{key:"Mod-Shift-l",run:sb},{key:"Mod-Alt-g",run:Nx},{key:"Mod-d",run:Xx,preventDefault:!0}];class ob{constructor(e){this.view=e;let t=this.query=e.state.field(At).query.spec;this.commit=this.commit.bind(this),this.searchField=_("input",{value:t.search,placeholder:Ee(e,"Find"),"aria-label":Ee(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=_("input",{value:t.replace,placeholder:Ee(e,"Replace"),"aria-label":Ee(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=_("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=_("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=_("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return _("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=_("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>vn(e),[Ee(e,"next")]),i("prev",()=>Sn(e),[Ee(e,"previous")]),i("select",()=>ib(e),[Ee(e,"all")]),_("label",null,[this.caseField,Ee(e,"match case")]),_("label",null,[this.reField,Ee(e,"regexp")]),_("label",null,[this.wordField,Ee(e,"by word")]),...e.state.readOnly?[]:[_("br"),this.replaceField,i("replace",()=>_a(e),[Ee(e,"replace")]),i("replaceAll",()=>nb(e),[Ee(e,"replace all")])],_("button",{name:"close",onclick:()=>fu(e),"aria-label":Ee(e,"close"),type:"button"},["×"])])}commit(){let e=new ou({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:ss.of(e)}))}keydown(e){hm(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Sn:vn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),_a(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(ss)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Mi).top}}function Ee(s,e){return s.state.phrase(e)}const Vs=30,Hs=/[\s\.,:;?!]/;function al(s,{from:e,to:t}){let i=s.state.doc.lineAt(e),n=s.state.doc.lineAt(t).to,r=Math.max(i.from,e-Vs),o=Math.min(n,t+Vs),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;al.length-Vs;a--)if(!Hs.test(l[a-1])&&Hs.test(l[a])){l=l.slice(0,a);break}}return L.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const lb=L.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),ab=[At,ei.low(tb),lb];class uu{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=be(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(du(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 Ka(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 hb(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+$/]:hb(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}class Ga{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function _t(s){return s.selection.main.from}function du(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 pu=at.define();function fb(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:v.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Ja=new WeakMap;function ub(s){if(!Array.isArray(s))return s;let e=Ja.get(s);return e||Ja.set(s,e=cb(s)),e}const On=$.define(),ns=$.define();class db{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:(A=Ro(S))!=A.toLowerCase()?1:A!=A.toUpperCase()?2:0;(!k||O==1&&g||T==0&&O!=0)&&(t[f]==S||i[f]==S&&(u=!0)?o[f++]=k:o.length&&(x=!1)),T=O,k+=it(S)}return f==a&&o[0]==0&&x?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(x?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?it(Ce(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 pb{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:mb,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=>Za(e(i),t(i)),optionClass:(e,t)=>i=>Za(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Za(s,e){return s?e?s+" "+e:s:e}function mb(s,e,t,i,n,r){let o=s.textDirection==J.RTL,l=o,a=!1,h="top",c,f,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u=m||k>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,x=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${f/x}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const hl=$.define();function gb(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 h=0;ha&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return at.position-i.position).map(t=>t.render)}function wr(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.ceil((s-e)/t);return{from:s-i*t,to:s-(i-1)*t}}class xb{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(ce);this.optionContent=gb(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=wr(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:h}=e.state.field(t).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:hl.of(c)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ce).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:ns.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=wr(r.length,o,e.state.facet(ce).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=wr(t.options.length,t.selected,this.view.state.facet(ce).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=>Pe(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&&yb(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 h!="string"&&h.header)n.appendChild(h.header(h));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=n.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew xb(t,s,e)}function yb(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 eh(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function kb(s,e){let t=[],i=null,n=null,r=c=>{t.push(c);let{section:f}=c.completion;if(f){i||(i=[]);let u=typeof f=="string"?f:f.name;i.some(d=>d.name==u)||i.push(typeof f=="string"?{name:u}:f)}},o=e.facet(ce);for(let c of s)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)r(new Ga(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new pb(u):new db(u);for(let m of c.result.options)if(d=p.match(m.label)){let g=m.displayLabel?f?f(m,d.matched):[]:d.matched,x=d.score+(m.boost||0);if(r(new Ga(m,c.source,g,x)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:k}=m.section;n||(n=Object.create(null)),n[k]=Math.max(x,n[k]||-1e9)}}}}if(i){let c=Object.create(null),f=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-f.score||h(f.completion,u.completion))){let f=c.completion;!a||a.label!=f.label||a.detail!=f.detail||a.type!=null&&f.type!=null&&a.type!=f.type||a.apply!=f.apply||a.boost!=f.boost?l.push(c):eh(c.completion)>eh(a)&&(l[l.length-1]=c),a=c.completion}return l}class hi{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 hi(this.options,th(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r,o){if(n&&!o&&e.some(h=>h.isPending))return n.setDisabled();let l=kb(e,t);if(!l.length)return n&&e.some(h=>h.isPending)?n.setDisabled():null;let a=t.facet(ce).selectOnOpen?0:-1;if(n&&n.selected!=a&&n.selected!=-1){let h=n.options[n.selected].completion;for(let c=0;cc.hasResult()?Math.min(h,c.from):h,1e8),create:Ab,above:r.aboveCursor},n?n.timestamp:Date.now(),a,!1)}map(e){return new hi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new hi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Cn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Cn(Ob,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(ce),r=(i.override||t.languageDataAt("autocomplete",_t(t)).map(ub)).map(a=>(this.active.find(c=>c.source==a)||new Ve(a,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((a,h)=>a==this.active[h])&&(r=this.active);let o=this.open,l=e.effects.some(a=>a.is(cl));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!wb(r,this.active)||l?o=hi.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 Ve(a.source,0):a));for(let a of e.effects)a.is(hl)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new Cn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?vb:Sb}}function wb(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t-1&&(t["aria-activedescendant"]=s+"-"+e),t}const Ob=[];function mu(s,e){if(s.isUserEvent("input.complete")){let i=s.annotation(pu);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 Ve{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=mu(e,t),n=this;(i&8||i&16&&this.touches(e))&&(n=new Ve(n.source,0)),i&4&&n.state==0&&(n=new Ve(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(On))n=new Ve(n.source,1,r.value);else if(r.is(ns))n=new Ve(n.source,0);else if(r.is(cl))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(_t(e.state))}}class mi extends Ve{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=_t(e.state);if(l>o||!n||t&2&&(_t(e.startState)==this.from||lt.map(e))}}),Ae=ye.define({create(){return Cn.start()},update(s,e){return s.update(e)},provide:s=>[Yo.from(s,e=>e.tooltip),L.contentAttributes.from(s,e=>e.attrs)]});function fl(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(Ae).active.find(n=>n.source==e.source);return i instanceof mi?(typeof t=="string"?s.dispatch({...fb(s.state,t,i.from,i.to),annotations:pu.of(e.completion)}):t(s,e.completion,i.from,i.to),!0):!1}const Ab=bb(Ae,fl);function zs(s,e="option"){return t=>{let i=t.state.field(Ae,!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:hl.of(l)}),!0}}const Mb=s=>{let e=s.state.field(Ae,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamps.state.field(Ae,!1)?(s.dispatch({effects:On.of(!0)}),!0):!1,Pb=s=>{let e=s.state.field(Ae,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:ns.of(null)}),!0)};class Tb{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Db=50,Rb=1e3,Bb=se.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(Ae).active)e.isPending&&this.startQuery(e)}update(s){let e=s.state.field(Ae),t=s.state.facet(ce);if(!s.selectionSet&&!s.docChanged&&s.startState.field(Ae)==e)return;let i=s.transactions.some(r=>{let o=mu(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;rDb&&Date.now()-o.time>Rb){for(let l of o.context.abortListeners)try{l()}catch(a){Pe(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(On)))&&(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(Ae);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(ce).updateSyncTime))}startQuery(s){let{state:e}=this.view,t=_t(e),i=new uu(e,t,s.explicit,this.view),n=new Tb(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:ns.of(null)}),Pe(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(ce).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ce),i=this.view.state.field(Ae);for(let n=0;nl.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Ve(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:cl.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(Ae,!1);if(e&&e.tooltip&&this.view.state.facet(ce).closeOnBlur){let t=e.open&&Xc(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:ns.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:On.of(!1)}),20),this.composing=0}}}),Eb=typeof navigator=="object"&&/Win/.test(navigator.platform),Lb=ei.highest(L.domEventHandlers({keydown(s,e){let t=e.state.field(Ae,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||s.key.length>1||s.ctrlKey&&!(Eb&&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&&fl(e,i),!1}})),Nb=L.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),rs={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},qt=$.define({map(s,e){let t=e.mapPos(s,-1,Se.TrackAfter);return t??void 0}}),ul=new class extends Mt{};ul.startSide=1;ul.endSide=-1;const gu=ye.define({create(){return X.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(qt)&&(s=s.update({add:[ul.range(t.value,t.value+1)]}));return s}});function Ib(){return[Fb,gu]}const Sr="()[]{}<>«»»«[]{}";function xu(s){for(let e=0;e{if((Wb?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&it(Ce(i,0))==1||e!=n.from||t!=n.to)return!1;let r=zb(s.state,i);return r?(s.dispatch(r),!0):!1}),Vb=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let i=bu(s,s.selection.main.head).brackets||rs.brackets,n=null,r=s.changeByRange(o=>{if(o.empty){let l=Qb(s.doc,o.head);for(let a of i)if(a==l&&qn(s.doc,o.head)==xu(Ce(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:v.cursor(o.head-a.length)}}return{range:n=o}});return n||e(s.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!n},Hb=[{key:"Backspace",run:Vb}];function zb(s,e){let t=bu(s,s.selection.main.head),i=t.brackets||rs.brackets;for(let n of i){let r=xu(Ce(n,0));if(e==n)return r==n?qb(s,n,i.indexOf(n+n+n)>-1,t):$b(s,n,r,t.before||rs.before);if(e==r&&yu(s,s.selection.main.from))return jb(s,n,r)}return null}function yu(s,e){let t=!1;return s.field(gu).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,it(Ce(t,0)))}function Qb(s,e){let t=s.sliceString(e-2,e);return it(Ce(t,0))==t.length?t:t.slice(1)}function $b(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:qt.of(o.to+e.length),range:v.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:qt.of(o.head+e.length),range:v.cursor(o.head+e.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function jb(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:v.cursor(r.head+t.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function qb(s,e,t,i){let n=i.stringPrefixes||rs.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:qt.of(l.to+e.length),range:v.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=qn(s.doc,a),c;if(h==e){if(ih(s,a))return{changes:{insert:e+e,from:a},effects:qt.of(a+e.length),range:v.cursor(a+e.length)};if(yu(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:v.cursor(a+u.length)}}}else{if(t&&s.sliceDoc(a-2*e.length,a)==e+e&&(c=sh(s,a-2*e.length,n))>-1&&ih(s,c))return{changes:{insert:e+e+e+e,from:a},effects:qt.of(a+e.length),range:v.cursor(a+e.length)};if(s.charCategorizer(a)(h)!=ee.Word&&sh(s,a,n)>-1&&!Xb(s,a,e,n))return{changes:{insert:e+e,from:a},effects:qt.of(a+e.length),range:v.cursor(a+e.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function ih(s,e){let t=be(s).resolveInner(e+1);return t.parent&&t.from==e}function Xb(s,e,t,i){let n=be(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 c=n.firstChild;for(;c&&c.from==n.from&&c.to-c.from>t.length+a;){if(s.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=n.to==e&&n.parent;if(!h)break;n=h}return!1}function sh(s,e,t){let i=s.charCategorizer(e);if(i(s.sliceDoc(e-1,e))!=ee.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))!=ee.Word)return r}return-1}function Ub(s={}){return[Lb,Ae,ce.of(s),Bb,Yb,Nb]}const ku=[{key:"Ctrl-Space",run:vr},{mac:"Alt-`",run:vr},{mac:"Alt-i",run:vr},{key:"Escape",run:Pb},{key:"ArrowDown",run:zs(!0)},{key:"ArrowUp",run:zs(!1)},{key:"PageDown",run:zs(!0,"page")},{key:"PageUp",run:zs(!1,"page")},{key:"Enter",run:Mb}],Yb=ei.highest(In.computeN([ce],s=>s.facet(ce).defaultKeymap?[ku]:[]));class nh{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class zt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(os).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((d,p)=>d.from-p.from||d.to-p.to),o=new mt,l=[],a=0,h=i.doc.iter(),c=0,f=i.doc.length;for(let d=0;;){let p=d==r.length?null:r[d];if(!p&&!l.length)break;let m,g;if(l.length)m=a,g=l.reduce((w,T)=>Math.min(w,T.to),p&&p.from>m?p.from:1e8);else{if(m=p.from,m>f)break;g=p.to,l.push(p),d++}for(;dw.from||w.to==m))l.push(w),d++,g=Math.min(w.to,g);else{g=Math.min(w.from,g);break}}g=Math.min(g,f);let x=!1;if(l.some(w=>w.from==m&&(w.to==g||g==f))&&(x=m==g,!x&&g-m<10)){let w=m-(c+h.value.length);w>0&&(h.next(w),c=m);for(let T=m;;){if(T>=g){x=!0;break}if(!h.lineBreak&&c+h.value.length>T)break;T=c+h.value.length,c+=h.value.length,h.next()}}let k=l1(l);if(x)o.add(m,m,z.widget({widget:new s1(k),diagnostics:l.slice()}));else{let w=l.reduce((T,S)=>S.markClass?T+" "+S.markClass:T,"");o.add(m,g,z.mark({class:"cm-lintRange cm-lintRange-"+k+w,diagnostics:l.slice(),inclusiveEnd:l.some(T=>T.to>g)}))}if(a=g,a==f)break;for(let w=0;w{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new nh(n,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new nh(i.from,r,i.diagnostic)}}),i}function _b(s,e){let t=e.pos,i=e.end||t,n=s.state.facet(os).hideOn(s,t,i);if(n!=null)return n;let r=s.startState.doc.lineAt(e.pos);return!!(s.effects.some(o=>o.is(wu))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function Kb(s,e){return s.field(Ie,!1)?e:e.concat($.appendConfig.of(a1))}const wu=$.define(),dl=$.define(),vu=$.define(),Ie=ye.define({create(){return new zt(z.none,null,null)},update(s,e){if(e.docChanged&&s.diagnostics.size){let t=s.diagnostics.map(e.changes),i=null,n=s.panel;if(s.selected){let r=e.changes.mapPos(s.selected.from,1);i=Et(t,s.selected.diagnostic,r)||Et(t,null,r)}!t.size&&n&&e.state.facet(os).autoPanel&&(n=null),s=new zt(t,n,i)}for(let t of e.effects)if(t.is(wu)){let i=e.state.facet(os).autoPanel?t.value.length?ls.open:null:s.panel;s=zt.init(t.value,i,e.state)}else t.is(dl)?s=new zt(s.diagnostics,t.value?ls.open:null,s.selected):t.is(vu)&&(s=new zt(s.diagnostics,s.panel,t.value));return s},provide:s=>[Zi.from(s,e=>e.panel),L.decorations.from(s,e=>e.diagnostics)]}),Gb=z.mark({class:"cm-lintRange cm-lintRange-active"});function Jb(s,e,t){let{diagnostics:i}=s.state.field(Ie),n,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,h,{spec:c})=>{if(e>=a&&e<=h&&(a==h||(e>a||t>0)&&(eOu(s,t,!1)))}const e1=s=>{let e=s.state.field(Ie,!1);(!e||!e.panel)&&s.dispatch({effects:Kb(s.state,[dl.of(!0)])});let t=_o(s,ls.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},rh=s=>{let e=s.state.field(Ie,!1);return!e||!e.panel?!1:(s.dispatch({effects:dl.of(!1)}),!0)},t1=s=>{let e=s.state.field(Ie,!1);if(!e)return!1;let t=s.state.selection.main,i=Et(e.diagnostics,null,t.to+1);return!i&&(i=Et(e.diagnostics,null,0),!i||i.from==t.from&&i.to==t.to)?!1:(s.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),Jm(s,i.from,1,{tooltip:Cu,until:n=>n.docChanged||n.newSelection.main.headi.to}),!0)},i1=[{key:"Mod-Shift-m",run:e1,preventDefault:!0},{key:"F8",run:t1}],os=I.define({combine(s){return{sources:s.map(e=>e.source).filter(e=>e!=null),...ht(s.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:oh,tooltipFilter:oh,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})}}});function oh(s,e){return s?e?(t,i)=>e(s(t,i),i):s:e}function Su(s){let e=[];if(s)e:for(let{name:t}of s){for(let i=0;ir.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function Ou(s,e,t){var i;let n=t?Su(e.actions):[];return _("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},_("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(s):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=d=>{if(d.preventDefault(),l)return;l=!0;let p=Et(s.state.field(Ie).diagnostics,e);p&&r.apply(s,p.from,p.to)},{name:h}=r,c=n[o]?h.indexOf(n[o]):-1,f=c<0?h:[h.slice(0,c),_("u",h.slice(c,c+1)),h.slice(c+1)],u=r.markClass?" "+r.markClass:"";return _("button",{type:"button",class:"cm-diagnosticAction"+u,onclick:a,onmousedown:a,"aria-label":` Action: ${h}${c<0?"":` (access key "${n[o]})"`}.`},f)}),e.source&&_("div",{class:"cm-diagnosticSource"},e.source))}class s1 extends ct{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return _("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class lh{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=Ou(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ls{constructor(e){this.view=e,this.items=[];let t=n=>{if(!(n.ctrlKey||n.altKey||n.metaKey)){if(n.keyCode==27)rh(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=Su(r.actions);for(let l=0;l{for(let r=0;rrh(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Ie).selected;if(!e)return-1;for(let t=0;t{for(let c of h.diagnostics){if(o.has(c))continue;o.add(c);let f=-1,u;for(let d=i;di&&(this.items.splice(i,f-i),n=!0)),t&&u.diagnostic==t.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let h=a.height/this.list.offsetHeight;l.topa.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Ie),i=Et(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:vu.of(i)})}static open(e){return new ls(e)}}function n1(s,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(s)}')`}function Qs(s){return n1(``,'width="6" height="3"')}const r1=L.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Qs("#f11")},".cm-lintRange-warning":{backgroundImage:Qs("orange")},".cm-lintRange-info":{backgroundImage:Qs("#999")},".cm-lintRange-hint":{backgroundImage:Qs("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function o1(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function l1(s){let e="hint",t=1;for(let i of s){let n=o1(i.severity);n>t&&(t=n,e=i.severity)}return e}const Cu=Gm(Jb,{hideOn:_b}),a1=[Ie,L.decorations.compute([Ie],s=>{let{selected:e,panel:t}=s.field(Ie);return!e||!t||e.from==e.to?z.none:z.set([Gb.range(e.from,e.to)])}),Cu,r1];var ah=function(e){e===void 0&&(e={});var t=e,i=t.crosshairCursor,n=i===void 0?!1:i,r=[];e.closeBracketsKeymap!==!1&&(r=r.concat(Hb)),e.defaultKeymap!==!1&&(r=r.concat(Bx)),e.searchKeymap!==!1&&(r=r.concat(rb)),e.historyKeymap!==!1&&(r=r.concat(V0)),e.foldKeymap!==!1&&(r=r.concat(Zg)),e.completionKeymap!==!1&&(r=r.concat(ku)),e.lintKeymap!==!1&&(r=r.concat(i1));var o=[];return e.lineNumbers!==!1&&o.push(fg()),e.highlightActiveLineGutter!==!1&&o.push(pg()),e.highlightSpecialChars!==!1&&o.push(Am()),e.history!==!1&&o.push(D0()),e.foldGutter!==!1&&o.push(s0()),e.drawSelection!==!1&&o.push(mm()),e.dropCursor!==!1&&o.push(km()),e.allowMultipleSelections!==!1&&o.push(U.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&o.push($g()),e.syntaxHighlighting!==!1&&o.push(kf(l0,{fallback:!0})),e.bracketMatching!==!1&&o.push(p0()),e.closeBrackets!==!1&&o.push(Ib()),e.autocompletion!==!1&&o.push(Ub()),e.rectangularSelection!==!1&&o.push(Hm()),n!==!1&&o.push($m()),e.highlightActiveLine!==!1&&o.push(Bm()),e.highlightSelectionMatches!==!1&&o.push(Fx()),e.tabSize&&typeof e.tabSize=="number"&&o.push(Fn.of(" ".repeat(e.tabSize))),o.concat([In.of(r.flat())]).filter(Boolean)};const h1="#e5c07b",hh="#e06c75",c1="#56b6c2",f1="#ffffff",Gs="#abb2bf",Oo="#7d8799",u1="#61afef",d1="#98c379",ch="#d19a66",p1="#c678dd",m1="#21252b",fh="#2c313a",uh="#282c34",Or="#353a42",g1="#3E4451",dh="#528bff",x1=L.theme({"&":{color:Gs,backgroundColor:uh},".cm-content":{caretColor:dh},".cm-cursor, .cm-dropCursor":{borderLeftColor:dh},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:g1},".cm-panels":{backgroundColor:m1,color:Gs},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:uh,color:Oo,border:"none"},".cm-activeLineGutter":{backgroundColor:fh},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Or},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Or,borderBottomColor:Or},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:fh,color:Gs}}},{dark:!0}),b1=ds.define([{tag:b.keyword,color:p1},{tag:[b.name,b.deleted,b.character,b.propertyName,b.macroName],color:hh},{tag:[b.function(b.variableName),b.labelName],color:u1},{tag:[b.color,b.constant(b.name),b.standard(b.name)],color:ch},{tag:[b.definition(b.name),b.separator],color:Gs},{tag:[b.typeName,b.className,b.number,b.changed,b.annotation,b.modifier,b.self,b.namespace],color:h1},{tag:[b.operator,b.operatorKeyword,b.url,b.escape,b.regexp,b.link,b.special(b.string)],color:c1},{tag:[b.meta,b.comment],color:Oo},{tag:b.strong,fontWeight:"bold"},{tag:b.emphasis,fontStyle:"italic"},{tag:b.strikethrough,textDecoration:"line-through"},{tag:b.link,color:Oo,textDecoration:"underline"},{tag:b.heading,fontWeight:"bold",color:hh},{tag:[b.atom,b.bool,b.special(b.variableName)],color:ch},{tag:[b.processingInstruction,b.string,b.inserted],color:d1},{tag:b.invalid,color:f1}]),Co=[x1,kf(b1)];var y1=L.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),k1=function(e){e===void 0&&(e={});var t=e,i=t.indentWithTab,n=i===void 0?!0:i,r=t.editable,o=r===void 0?!0:r,l=t.readOnly,a=l===void 0?!1:l,h=t.theme,c=h===void 0?"light":h,f=t.placeholder,u=f===void 0?"":f,d=t.basicSetup,p=d===void 0?!0:d,m=[];switch(n&&m.unshift(In.of([Ex])),p&&(typeof p=="boolean"?m.unshift(ah()):m.unshift(ah(p))),u&&m.unshift(Im(u)),c){case"light":m.push(y1);break;case"dark":m.push(Co);break;case"none":break;default:m.push(c);break}return o===!1&&m.push(L.editable.of(!1)),a&&m.push(U.readOnly.of(!0)),[...m]},w1=s=>({line:s.state.doc.lineAt(s.state.selection.main.from),lineCount:s.state.doc.lines,lineBreak:s.state.lineBreak,length:s.state.doc.length,readOnly:s.state.readOnly,tabSize:s.state.tabSize,selection:s.state.selection,selectionAsSingle:s.state.selection.asSingle().main,ranges:s.state.selection.ranges,selectionCode:s.state.sliceDoc(s.state.selection.main.from,s.state.selection.main.to),selections:s.state.selection.ranges.map(e=>s.state.sliceDoc(e.from,e.to)),selectedText:s.state.selection.ranges.some(e=>!e.empty)});class v1{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(t=>{try{t()}catch(i){console.error("TimeoutLatch callback error:",i)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class ph{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var Cr=null,S1=()=>typeof window>"u"?new ph:(Cr||(Cr=new ph),Cr),mh=at.define(),O1=200,C1=[];function A1(s){var e=s.value,t=s.selection,i=s.onChange,n=s.onStatistics,r=s.onCreateEditor,o=s.onUpdate,l=s.extensions,a=l===void 0?C1:l,h=s.autoFocus,c=s.theme,f=c===void 0?"light":c,u=s.height,d=u===void 0?null:u,p=s.minHeight,m=p===void 0?null:p,g=s.maxHeight,x=g===void 0?null:g,k=s.width,w=k===void 0?null:k,T=s.minWidth,S=T===void 0?null:T,A=s.maxWidth,O=A===void 0?null:A,V=s.placeholder,N=V===void 0?"":V,P=s.editable,D=P===void 0?!0:P,M=s.readOnly,F=M===void 0?!1:M,R=s.indentWithTab,C=R===void 0?!0:R,B=s.basicSetup,j=B===void 0?!0:B,oe=s.root,Q=s.initialState,ue=H.useState(),de=ue[0],we=ue[1],Be=H.useState(),K=Be[0],Qe=Be[1],Nt=H.useState(),ti=Nt[0],Un=Nt[1],_e=H.useState(()=>({current:null}))[0],gs=H.useState(()=>({current:null}))[0],Eu=L.theme({"&":{height:d,minHeight:m,maxHeight:x,width:w,minWidth:S,maxWidth:O},"& .cm-scroller":{height:"100% !important"}}),Lu=L.updateListener.of(Ke=>{if(Ke.docChanged&&typeof i=="function"&&!Ke.transactions.some(Yn=>Yn.annotation(mh))){_e.current?_e.current.reset():(_e.current=new v1(()=>{if(gs.current){var Yn=gs.current;gs.current=null,Yn()}_e.current=null},O1),S1().add(_e.current));var It=Ke.state.doc,Wt=It.toString();i(Wt,Ke)}n&&n(w1(Ke))}),Nu=k1({theme:f,editable:D,readOnly:F,placeholder:N,indentWithTab:C,basicSetup:j}),Pi=[Lu,Eu,...Nu];return o&&typeof o=="function"&&Pi.push(L.updateListener.of(o)),Pi=Pi.concat(a),H.useLayoutEffect(()=>{if(de&&!ti){var Ke={doc:e,selection:t,extensions:Pi},It=Q?U.fromJSON(Q.json,Ke,Q.fields):U.create(Ke);if(Un(It),!K){var Wt=new L({state:It,parent:de,root:oe});Qe(Wt),r&&r(Wt,It)}}return()=>{K&&(Un(void 0),Qe(void 0))}},[de,ti]),H.useEffect(()=>{s.container&&we(s.container)},[s.container]),H.useEffect(()=>()=>{K&&(K.destroy(),Qe(void 0)),_e.current&&(_e.current.cancel(),_e.current=null)},[K]),H.useEffect(()=>{h&&K&&K.focus()},[h,K]),H.useEffect(()=>{K&&K.dispatch({effects:$.reconfigure.of(Pi)})},[f,a,d,m,x,w,S,O,N,D,F,C,j,i,o]),H.useEffect(()=>{if(e!==void 0){var Ke=K?K.state.doc.toString():"";if(K&&e!==Ke){var It=_e.current&&!_e.current.isDone,Wt=()=>{K&&e!==K.state.doc.toString()&&K.dispatch({changes:{from:0,to:K.state.doc.toString().length,insert:e||""},annotations:[mh.of(!0)]})};It?gs.current=Wt:Wt()}}},[e,K]),{state:ti,setState:Un,view:K,setView:Qe,container:de,setContainer:we}}var M1=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],Ao=H.forwardRef((s,e)=>{var t=s.className,i=s.value,n=i===void 0?"":i,r=s.selection,o=s.extensions,l=o===void 0?[]:o,a=s.onChange,h=s.onStatistics,c=s.onCreateEditor,f=s.onUpdate,u=s.autoFocus,d=s.theme,p=d===void 0?"light":d,m=s.height,g=s.minHeight,x=s.maxHeight,k=s.width,w=s.minWidth,T=s.maxWidth,S=s.basicSetup,A=s.placeholder,O=s.indentWithTab,V=s.editable,N=s.readOnly,P=s.root,D=s.initialState,M=id(s,M1),F=H.useRef(null),R=A1({root:P,value:n,autoFocus:u,theme:p,height:m,minHeight:g,maxHeight:x,width:k,minWidth:w,maxWidth:T,basicSetup:S,placeholder:A,indentWithTab:O,editable:V,readOnly:N,selection:r,onChange:a,onStatistics:h,onCreateEditor:c,onUpdate:f,extensions:l,initialState:D}),C=R.state,B=R.view,j=R.container,oe=R.setContainer;H.useImperativeHandle(e,()=>({editor:F.current,state:C,view:B}),[F,j,C,B]);var Q=H.useCallback(de=>{F.current=de,oe(de)},[oe]);if(typeof n!="string")throw new Error("value must be typeof string but got "+typeof n);var ue=typeof p=="string"?"cm-theme-"+p:"cm-theme";return y.jsx("div",Tr({ref:Q,className:""+ue+(t?" "+t:"")},M))});Ao.displayName="CodeMirror";var gh={};class An{constructor(e,t,i,n,r,o,l,a,h,c=0,f){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=h,this.lookAhead=c,this.parent=f}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 An(e,[],t,i,i,0,[],0,n?new xh(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)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSizea;)this.stack.pop();this.reduceContext(n,h)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(t==i)return;if(this.buffer[o-2]>=t){this.buffer[o-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let 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;this.pos=n;let l=o.stateFlag(r,1);!l&&(n>i||t<=o.maxNode)&&(this.reducePos=n),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,n,4)}else this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4)}apply(e,t,i,n){e&65536?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(t&&e.buffer[t-4]==0&&(t-=4);t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new An(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 P1(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,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],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 xh{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class P1{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 Mn{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 Mn(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 Mn(this.stack,this.pos,this.index)}}function $s(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 Js{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const bh=new Js;class T1{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=bh,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=bh,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 gi{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;D1(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}gi.prototype.contextual=gi.prototype.fallback=gi.prototype.extend=!1;gi.prototype.fallback=gi.prototype.extend=!1;class Xn{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function D1(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||R1(p,e.token.value,n,r))){e.acceptToken(p);break}}let c=e.next,f=0,u=s[o+2];if(e.next<0&&u>f&&s[h+u*3-3]==65535){o=s[h+u*3-1];continue e}for(;f>1,p=h+d+(d<<1),m=s[p],g=s[p+1]||65536;if(c=g)f=d+1;else{o=s[p+2],e.advance();continue e}}break}}function yh(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function R1(s,e,t,i){let n=yh(t,i,e);return n<0||yh(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 B1{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?kh(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?kh(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 re){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 E1{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new Js)}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 h=0;hf.end+25&&(a=Math.max(f.lookAhead,a)),f.value!=0)){let u=t;if(f.extended>-1&&(t=this.addActions(e,f.extended,f.end,t)),t=this.addActions(e,f.value,f.end,t),!c.extend&&(i=f,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new Js,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 Js,{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 B1(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&&W1(n);if(o)return Le&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw Le&&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 Le&&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&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,c=h?e.curContext.hash:0;for(let f=this.fragments.nodeAt(n);f;){let u=this.parser.nodeSet.types[f.type.id]==f.type?r.getGoto(e.state,f.type.id):-1;if(u>-1&&f.length&&(!h||(f.prop(q.contextHash)||0)==c))return e.useNode(f,u),Le&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(f.type.id)})`),!0;if(!(f instanceof re)||f.children.length==0||f.positions[0]>0)break;let d=f.children[0];if(d instanceof re&&f.positions[0]==0)f=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),Le&&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 h=0;hn?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 wh(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(),Le&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let f=l.split(),u=c;for(let d=0;d<10&&f.forceReduce()&&(Le&&console.log(u+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,i));d++)Le&&(u=this.stackID(f)+" -> ");for(let d of l.recoverByInsert(a))Le&&console.log(c+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),Le&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),wh(l,i)):(!n||n.scores;class I1{constructor(e){this.start=e.start,this.shift=e.shift||Mr,this.reduce=e.reduce||Mr,this.reuse=e.reuse||Mr,this.hash=e.hash||(()=>0),this.strict=e.strict!==!1}}class Pn extends sf{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;le.topRules[l][1]),n=[];for(let l=0;l=0)r(c,a,l[h++]);else{let f=l[h+-c];for(let u=-c;u>0;u--)r(l[h++],a,f);h++}}}this.nodeSet=new Ko(t.map((l,a)=>Re.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=Jc;let o=$s(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 gi(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 L1(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 h=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=ut(this.data,r+2);else break;n=t(ut(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=ut(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(Pn.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]=vh(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 ri=63,Sh=64,F1=1,V1=2,Au=3,H1=4,Mu=5,z1=6,Q1=7,Pu=65,$1=66,j1=8,q1=9,X1=10,U1=11,Y1=12,Tu=13,_1=19,K1=20,G1=29,J1=33,Z1=34,ey=47,ty=0,pl=1,Mo=2,as=3,Po=4;class Qt{constructor(e,t,i){this.parent=e,this.depth=t,this.type=i,this.hash=(e?e.hash+e.hash<<8:0)+t+(t<<4)+i}}Qt.top=new Qt(null,-1,ty);function qi(s,e){for(let t=0,i=e-s.pos-1;;i--,t++){let n=s.peek(i);if(bt(n)||n==-1)return t}}function To(s){return s==32||s==9}function bt(s){return s==10||s==13}function Du(s){return To(s)||bt(s)}function Xt(s){return s<0||Du(s)}const iy=new I1({start:Qt.top,reduce(s,e){return s.type==as&&(e==K1||e==Z1)?s.parent:s},shift(s,e,t,i){if(e==Au)return new Qt(s,qi(i,i.pos),pl);if(e==Pu||e==Mu)return new Qt(s,qi(i,i.pos),Mo);if(e==ri)return s.parent;if(e==_1||e==J1)return new Qt(s,0,as);if(e==Tu&&s.type==Po)return s.parent;if(e==ey){let n=/[1-9]/.exec(i.read(i.pos,t.pos));if(n)return new Qt(s,s.depth+ +n[0],Po)}return s},hash(s){return s.hash}});function Oi(s,e,t=0){return s.peek(t)==e&&s.peek(t+1)==e&&s.peek(t+2)==e&&Xt(s.peek(t+3))}const sy=new Xn((s,e)=>{if(s.next==-1&&e.canShift(Sh))return s.acceptToken(Sh);let t=s.peek(-1);if((bt(t)||t<0)&&e.context.type!=as){if(Oi(s,45))if(e.canShift(ri))s.acceptToken(ri);else return s.acceptToken(F1,3);if(Oi(s,46))if(e.canShift(ri))s.acceptToken(ri);else return s.acceptToken(V1,3);let i=0;for(;s.next==32;)i++,s.advance();(i{if(e.context.type==as){s.next==63&&(s.advance(),Xt(s.next)&&s.acceptToken(Q1));return}if(s.next==45)s.advance(),Xt(s.next)&&s.acceptToken(e.context.type==pl&&e.context.depth==qi(s,s.pos-1)?H1:Au);else if(s.next==63)s.advance(),Xt(s.next)&&s.acceptToken(e.context.type==Mo&&e.context.depth==qi(s,s.pos-1)?z1:Mu);else{let t=s.pos;for(;;)if(To(s.next)){if(s.pos==t)return;s.advance()}else if(s.next==33)Ru(s);else if(s.next==38)Do(s);else if(s.next==42){Do(s);break}else if(s.next==39||s.next==34){if(ml(s,!0))break;return}else if(s.next==91||s.next==123){if(!oy(s))return;break}else{Bu(s,!0,!1,0);break}for(;To(s.next);)s.advance();if(s.next==58){if(s.pos==t&&e.canShift(G1))return;let i=s.peek(1);Xt(i)&&s.acceptTokenTo(e.context.type==Mo&&e.context.depth==qi(s,t)?$1:Pu,t)}}},{contextual:!0});function ry(s){return s>32&&s<127&&s!=34&&s!=37&&s!=44&&s!=60&&s!=62&&s!=92&&s!=94&&s!=96&&s!=123&&s!=124&&s!=125}function Oh(s){return s>=48&&s<=57||s>=97&&s<=102||s>=65&&s<=70}function Ch(s,e){return s.next==37?(s.advance(),Oh(s.next)&&s.advance(),Oh(s.next)&&s.advance(),!0):ry(s.next)||e&&s.next==44?(s.advance(),!0):!1}function Ru(s){if(s.advance(),s.next==60){for(s.advance();;)if(!Ch(s,!0)){s.next==62&&s.advance();break}}else for(;Ch(s,!1););}function Do(s){for(s.advance();!Xt(s.next)&&Tn(s.next)!="f";)s.advance()}function ml(s,e){let t=s.next,i=!1,n=s.pos;for(s.advance();;){let r=s.next;if(r<0)break;if(s.advance(),r==t)if(r==39)if(s.next==39)s.advance();else break;else break;else if(r==92&&t==34)s.next>=0&&s.advance();else if(bt(r)){if(e)return!1;i=!0}else if(e&&s.pos>=n+1024)return!1}return!i}function oy(s){for(let e=[],t=s.pos+1024;;)if(s.next==91||s.next==123)e.push(s.next),s.advance();else if(s.next==39||s.next==34){if(!ml(s,!0))return!1}else if(s.next==93||s.next==125){if(e[e.length-1]!=s.next-2)return!1;if(e.pop(),s.advance(),!e.length)return!0}else{if(s.next<0||s.pos>t||bt(s.next))return!1;s.advance()}}const ly="iiisiiissisfissssssssssssisssiiissssssssssssssssssssssssssfsfssissssssssssssssssssssssssssfif";function Tn(s){return s<33?"u":s>125?"s":ly[s-33]}function Pr(s,e){let t=Tn(s);return t!="u"&&!(e&&t=="f")}function Bu(s,e,t,i){if(Tn(s.next)=="s"||(s.next==63||s.next==58||s.next==45)&&Pr(s.peek(1),t))s.advance();else return!1;let n=s.pos;for(;;){let r=s.next,o=0,l=i+1;for(;Du(r);){if(bt(r)){if(e)return!1;l=0}else l++;r=s.peek(++o)}if(!(r>=0&&(r==58?Pr(s.peek(o+1),t):r==35?s.peek(o-1)!=32:Pr(r,t)))||!t&&l<=i||l==0&&!t&&(Oi(s,45,o)||Oi(s,46,o)))break;if(e&&Tn(r)=="f")return!1;for(let h=o;h>=0;h--)s.advance();if(e&&s.pos>n+1024)return!1}return!0}const ay=new Xn((s,e)=>{if(s.next==33)Ru(s),s.acceptToken(Y1);else if(s.next==38||s.next==42){let t=s.next==38?X1:U1;Do(s),s.acceptToken(t)}else s.next==39||s.next==34?(ml(s,!1),s.acceptToken(q1)):Bu(s,!1,e.context.type==as,e.context.depth)&&s.acceptToken(j1)}),hy=new Xn((s,e)=>{let t=e.context.type==Po?e.context.depth:-1,i=s.pos;e:for(;;){let n=0,r=s.next;for(;r==32;)r=s.peek(++n);if(!n&&(Oi(s,45,n)||Oi(s,46,n))||!bt(r)&&(t<0&&(t=Math.max(e.context.depth+1,n)),nYAN>Y",stateData:";S~O!fOS!gOS^OS~OP_OQbORSOTUOWROXROYYOZZO[XOcPOqQO!PVO!V[O!cTO~O`cO~P]OVkOWROXROYeOZfO[dOcPOmhOqQO~OboO~P!bOVtOWROXROYeOZfO[dOcPOmrOqQO~OpwO~P#WORSOTUOWROXROYYOZZO[XOcPOqQO!PVO!cTO~OSvP!avP!bvP~P#|OWROXROYeOZfO[dOcPOqQO~OmzO~P%OOm!OOUzP!azP!bzP!dzP~P#|O^!SO!b!QO!f!TO!g!RO~ORSOTUOWROXROcPOqQO!PVO!cTO~OY!UOP!QXQ!QX!V!QX!`!QXS!QX!a!QX!b!QXU!QXm!QX!d!QX~P&aO[!WOP!SXQ!SX!V!SX!`!SXS!SX!a!SX!b!SXU!SXm!SX!d!SX~P&aO^!ZO!W![O!b!YO!f!]O!g!YO~OP!_O!V[OQaX!`aX~OPaXQaX!VaX!`aX~P#|OP!bOQ!cO!V[O~OP_O!V[O~P#|OWROXROY!fOcPOqQObfXmfXofXpfX~OWROXRO[!hOcPOqQObhXmhXohXphX~ObeXmlXoeX~ObkXokX~P%OOm!kO~Om!lObnPonP~P%OOb!pOo!oO~Ob!pO~P!bOm!sOosXpsX~OosXpsX~P%OOm!uOotPptP~P%OOo!xOp!yO~Op!yO~P#WOS!|O!a#OO!b#OO~OUyX!ayX!byX!dyX~P#|Om#QO~OU#SO!a#UO!b#UO!d#RO~Om#WOUzX!azX!bzX!dzX~O]#XO~O!b#XO!g#YO~O^#ZO!b#XO!g#YO~OP!RXQ!RX!V!RX!`!RXS!RX!a!RX!b!RXU!RXm!RX!d!RX~P&aOP!TXQ!TX!V!TX!`!TXS!TX!a!TX!b!TXU!TXm!TX!d!TX~P&aO!b#^O!g#^O~O^#_O!b#^O!f#`O!g#^O~O^#_O!W#aO!b#^O!g#^O~OPaaQaa!Vaa!`aa~P#|OP#cO!V[OQ!XX!`!XX~OP!XXQ!XX!V!XX!`!XX~P#|OP_O!V[OQ!_X!`!_X~P#|OWROXROcPOqQObgXmgXogXpgX~OWROXROcPOqQObiXmiXoiXpiX~Obkaoka~P%OObnXonX~P%OOm#kO~Ob#lOo!oO~Oosapsa~P%OOotXptX~P%OOm#pO~Oo!xOp#qO~OSwP!awP!bwP~P#|OS!|O!a#vO!b#vO~OUya!aya!bya!dya~P#|Om#xO~P%OOm#{OU}P!a}P!b}P!d}P~P#|OU#SO!a$OO!b$OO!d#RO~O]$QO~O!b$QO!g$RO~O!b$SO!g$SO~O^$TO!b$SO!g$SO~O^$TO!b$SO!f$UO!g$SO~OP!XaQ!Xa!V!Xa!`!Xa~P#|Obnaona~P%OOotapta~P%OOo!xO~OU|X!a|X!b|X!d|X~P#|Om$ZO~Om$]OU}X!a}X!b}X!d}X~O]$^O~O!b$_O!g$_O~O^$`O!b$_O!g$_O~OU|a!a|a!b|a!d|a~P#|O!b$cO!g$cO~O",goto:",]!mPPPPPPPPPPPPPPPPP!nPP!v#v#|$`#|$c$f$j$nP%VPPP!v%Y%^%a%{&O%a&R&U&X&_&b%aP&e&{&e'O'RPP']'a'g'm's'y(XPPPPPPPP(_)e*X+c,VUaObcR#e!c!{ROPQSTUXY_bcdehknrtvz!O!U!W!_!b!c!f!h!k!l!s!u!|#Q#R#S#W#c#k#p#x#{$Z$]QmPR!qnqfPQThknrtv!k!l!s!u#R#k#pR!gdR!ieTlPnTjPnSiPnSqQvQ{TQ!mkQ!trQ!vtR#y#RR!nkTsQvR!wt!RWOSUXY_bcz!O!U!W!_!b!c!|#Q#S#W#c#x#{$Z$]RySR#t!|R|TR|UQ!PUR#|#SR#z#RR#z#SyZOSU_bcz!O!_!b!c!|#Q#S#W#c#x#{$Z$]R!VXR!XYa]O^abc!a!c!eT!da!eQnPR!rnQvQR!{vQ!}yR#u!}Q#T|R#}#TW^Obc!cS!^^!aT!aa!eQ!eaR#f!eW`Obc!cQxSS}U#SQ!`_Q#PzQ#V!OQ#b!_Q#d!bQ#s!|Q#w#QQ$P#WQ$V#cQ$Y#xQ$[#{Q$a$ZR$b$]xZOSU_bcz!O!_!b!c!|#Q#S#W#c#x#{$Z$]Q!VXQ!XYQ#[!UR#]!W!QWOSUXY_bcz!O!U!W!_!b!c!|#Q#S#W#c#x#{$Z$]pfPQThknrtv!k!l!s!u#R#k#pQ!gdQ!ieQ#g!fR#h!hSgPn^pQTkrtv#RQ!jhQ#i!kQ#j!lQ#n!sQ#o!uQ$W#kR$X#pQuQR!zv",nodeNames:"⚠ DirectiveEnd DocEnd - - ? ? ? Literal QuotedLiteral Anchor Alias Tag BlockLiteralContent Comment Stream BOM Document ] [ FlowSequence Item Tagged Anchored Anchored Tagged FlowMapping Pair Key : Pair , } { FlowMapping Pair Pair BlockSequence Item Item BlockMapping Pair Pair Key Pair Pair BlockLiteral BlockLiteralHeader Tagged Anchored Anchored Tagged Directive DirectiveName DirectiveContent Document",maxTerm:74,context:iy,nodeProps:[["isolate",-3,8,9,14,""],["openedBy",18,"[",32,"{"],["closedBy",19,"]",33,"}"]],propSources:[cy],skippedNodes:[0],repeatNodeCount:6,tokenData:"-Y~RnOX#PXY$QYZ$]Z]#P]^$]^p#Ppq$Qqs#Pst$btu#Puv$yv|#P|}&e}![#P![!]'O!]!`#P!`!a'i!a!}#P!}#O*g#O#P#P#P#Q+Q#Q#o#P#o#p+k#p#q'i#q#r,U#r;'S#P;'S;=`#z<%l?HT#P?HT?HU,o?HUO#PQ#UU!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PQ#kTOY#PZs#Pt;'S#P;'S;=`#z<%lO#PQ#}P;=`<%l#P~$VQ!f~XY$Qpq$Q~$bO!g~~$gS^~OY$bZ;'S$b;'S;=`$s<%lO$b~$vP;=`<%l$bR%OX!WQOX%kXY#PZ]%k]^#P^p%kpq#hq;'S%k;'S;=`&_<%lO%kR%rX!WQ!VPOX%kXY#PZ]%k]^#P^p%kpq#hq;'S%k;'S;=`&_<%lO%kR&bP;=`<%l%kR&lUoP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR'VUmP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR'p[!PP!WQOY#PZp#Ppq#hq{#P{|(f|}#P}!O(f!O!R#P!R![)p![;'S#P;'S;=`#z<%lO#PR(mW!PP!WQOY#PZp#Ppq#hq!R#P!R![)V![;'S#P;'S;=`#z<%lO#PR)^U!PP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR)wY!PP!WQOY#PZp#Ppq#hq{#P{|)V|}#P}!O)V!O;'S#P;'S;=`#z<%lO#PR*nUcP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR+XUbP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR+rUqP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR,]UpP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR,vU`P!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#P",tokenizers:[sy,ny,ay,hy,0,1],topRules:{Stream:[0,15]},tokenPrec:0}),uy=dn.define({name:"yaml",parser:fy.configure({props:[af.add({Stream:s=>{for(let e=s.node.resolve(s.pos,-1);e&&e.to>=s.pos;e=e.parent){if(e.name=="BlockLiteralContent"&&e.froms.pos)return null}}return null},FlowMapping:Ba({closing:"}"}),FlowSequence:Ba({closing:"]"})}),ff.add({"FlowMapping FlowSequence":qg,"Item Pair BlockLiteral":(s,e)=>({from:e.doc.lineAt(s.from).to,to:s.to})})]}),languageData:{commentTokens:{line:"#"},indentOnInput:/^\s*[\]\}]$/}});function dy(){return new Lg(uy)}function Vy({clusterCode:s,namespace:e,resource:t,name:i,onClose:n,onSaved:r,cleanBeforeEdit:o=!1,autoEdit:l=!1,inline:a=!1,initialYaml:h}){const{toast:c}=Ah(),[f,u]=H.useState(h||""),[d,p]=H.useState(""),[m,g]=H.useState(!h),[x,k]=H.useState(!1),[w,T]=H.useState(l),[S,A]=H.useState(!1),O=o||l,V=async()=>{if(h){u(h),p(O?bs(h):h),g(!1);return}g(!0);try{const B=await wt.getResourceYaml(s,e,t,i);u(B),p(O?bs(B):B)}catch(B){c({title:"获取YAML失败",description:B.message,variant:"destructive"});const j=`# Error: ${B.message}`;u(j),p(j)}finally{g(!1)}},N=()=>{const B=O?bs(f):f;p(B),T(!0),O&&c({title:"已清理只读字段",description:"已剥离 status / managedFields / uid 等"})},[P,D]=H.useState(!1),M=async()=>{k(!0);try{await wt.updateResourceYaml(s,e,t,i,d),c({title:"YAML已应用",description:`${t}/${i} 更新成功`}),T(!1),u(d),r?.()}catch(B){c({title:"保存失败",description:B.message,variant:"destructive"})}finally{k(!1)}},F=async()=>{const B=w?d:f;await navigator.clipboard.writeText(B),A(!0),setTimeout(()=>A(!1),2e3)};H.useEffect(()=>{V()},[]);const R=w?d:O&&!P?bs(f):f,C=H.useMemo(()=>[dy(),L.lineWrapping,...w?[]:[L.editable.of(!1)]],[w]);return a?y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:113:7",className:"space-y-3",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:114:9",className:"flex items-center justify-between",children:[y.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:115:11",className:"text-xs text-slate-500",children:[y.jsxs("code",{"code-path":"src/components/kubernetes/YamlViewer.tsx:116:13",className:"text-slate-400",children:[t,"/",i]})," · ",e," · ",s]}),y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:118:11",className:"flex items-center gap-2",children:[y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:119:13",variant:"outline",size:"sm",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:F,children:[S?y.jsx(gl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:120:25",className:"h-3 w-3 mr-1 text-emerald-400"}):y.jsx(bl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:120:79",className:"h-3 w-3 mr-1"}),S?"已复制":"复制"]}),O&&!w&&y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:124:15",variant:"outline",size:"sm",className:`h-7 text-xs ${P?"border-slate-700 text-slate-500":"border-emerald-700/50 text-emerald-400"}`,onClick:()=>D(B=>!B),title:"切换 精简/原始 视图",children:[y.jsx(xs,{"code-path":"src/components/kubernetes/YamlViewer.tsx:126:17",className:"h-3 w-3 mr-1"}),P?"原始":"精简"]}),w?y.jsxs(y.Fragment,{children:[y.jsx(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:144:17",variant:"outline",size:"sm",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>{T(!1),V()},children:"取消"}),y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:147:17",size:"sm",className:"h-7 bg-blue-600 hover:bg-blue-700 text-xs",onClick:M,disabled:x,children:[x?y.jsx(St,{"code-path":"src/components/kubernetes/YamlViewer.tsx:148:29",className:"h-3 w-3 animate-spin mr-1"}):y.jsx(yl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:148:81",className:"h-3 w-3 mr-1"}),"保存"]})]}):y.jsxs(y.Fragment,{children:[O&&y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:132:19",variant:"outline",size:"sm",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:N,title:"清理 status / managedFields 等只读字段后编辑",children:[y.jsx(xs,{"code-path":"src/components/kubernetes/YamlViewer.tsx:133:19",className:"h-3 w-3 mr-1 text-amber-400"}),"编辑"]}),!O&&y.jsx(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:137:19",variant:"outline",size:"sm",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>T(!0),children:"编辑"})]})]})]}),y.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:155:9",className:"border border-slate-700 rounded-lg overflow-hidden",children:m?y.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:157:13",className:"flex items-center justify-center h-96",children:y.jsx(St,{"code-path":"src/components/kubernetes/YamlViewer.tsx:157:68",className:"h-6 w-6 animate-spin text-slate-500"})}):y.jsx(Ao,{"code-path":"src/components/kubernetes/YamlViewer.tsx:159:13",value:R,height:"600px",theme:Co,extensions:C,onChange:B=>w&&p(B),basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:w,highlightActiveLineGutter:w,autocompletion:!0,bracketMatching:!0,closeBrackets:!0,indentOnInput:!0},style:{fontSize:"12px"}})})]}):y.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:185:5",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:n,children:y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:186:7",className:"bg-slate-900 border border-slate-700 rounded-xl w-[90vw] max-w-4xl max-h-[85vh] flex flex-col shadow-2xl",onClick:B=>B.stopPropagation(),children:[y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:188:9",className:"flex items-center justify-between p-4 border-b border-slate-700",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:189:11",children:[y.jsxs("h2",{"code-path":"src/components/kubernetes/YamlViewer.tsx:190:13",className:"text-lg font-bold text-slate-100",children:[t,"/",i]}),y.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:191:13",className:"text-xs text-slate-500",children:[e," · ",s]})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:193:11",className:"flex items-center gap-2",children:[y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:194:13",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300",onClick:F,children:[S?y.jsx(gl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:195:25",className:"h-3 w-3 mr-1 text-emerald-400"}):y.jsx(bl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:195:79",className:"h-3 w-3 mr-1"}),S?"已复制":"复制"]}),O&&!w&&y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:199:15",variant:"outline",size:"sm",className:`h-8 text-xs ${P?"border-slate-700 text-slate-500":"border-emerald-700/50 text-emerald-400"}`,onClick:()=>D(B=>!B),title:"切换 精简/原始 视图",children:[y.jsx(xs,{"code-path":"src/components/kubernetes/YamlViewer.tsx:201:17",className:"h-3 w-3 mr-1"}),P?"原始":"精简"]}),w?y.jsxs(y.Fragment,{children:[y.jsx(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:219:17",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300",onClick:()=>{T(!1),V()},children:"取消"}),y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:222:17",size:"sm",className:"h-8 bg-blue-600 hover:bg-blue-700",onClick:M,disabled:x,children:[x?y.jsx(St,{"code-path":"src/components/kubernetes/YamlViewer.tsx:223:29",className:"h-3 w-3 animate-spin mr-1"}):y.jsx(yl,{"code-path":"src/components/kubernetes/YamlViewer.tsx:223:81",className:"h-3 w-3 mr-1"}),"保存"]})]}):y.jsxs(y.Fragment,{children:[O&&y.jsxs(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:207:19",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300",onClick:N,title:"清理 status / managedFields 等只读字段后编辑",children:[y.jsx(xs,{"code-path":"src/components/kubernetes/YamlViewer.tsx:208:21",className:"h-3 w-3 mr-1 text-amber-400"}),"清理并编辑"]}),!O&&y.jsx(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:212:19",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300",onClick:()=>T(!0),children:"编辑"})]}),y.jsx(le,{"code-path":"src/components/kubernetes/YamlViewer.tsx:228:13",variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-400",onClick:n,children:y.jsx(Zs,{"code-path":"src/components/kubernetes/YamlViewer.tsx:228:102",className:"h-4 w-4"})})]})]}),y.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:232:9",className:"flex-1 overflow-auto p-4",children:m?y.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:234:13",className:"flex items-center justify-center h-full",children:y.jsx(St,{"code-path":"src/components/kubernetes/YamlViewer.tsx:234:70",className:"h-6 w-6 animate-spin text-slate-500"})}):y.jsx(Ao,{"code-path":"src/components/kubernetes/YamlViewer.tsx:236:13",value:R,height:"600px",theme:Co,extensions:C,onChange:B=>w&&p(B),basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:w,highlightActiveLineGutter:w,autocompletion:!0,bracketMatching:!0,closeBrackets:!0,indentOnInput:!0},style:{fontSize:"12px"}})})]})})}const py=[{value:"sh",label:"/bin/sh"},{value:"bash",label:"/bin/bash"}];function Hy({open:s,onOpenChange:e,clusterId:t,namespace:i,podName:n,containers:r=[],initialContainer:o}){const{toast:l}=Ah(),a=H.useRef(null),h=H.useRef(null),c=H.useRef(null),f=H.useRef(null),u=H.useRef(!1),d=H.useRef(!1),[p,m]=H.useState("idle"),[g,x]=H.useState(!1),[k,w]=H.useState(o||r[0]||""),[T,S]=H.useState("sh");H.useEffect(()=>{s||(x(!1),u.current=!1)},[s]),H.useEffect(()=>{s&&!k&&r.length>0&&w(o||r[0])},[s,r,o,k]);const A=H.useCallback(()=>{if(!h.current){console.error("[PodExec:connect] ABORT: termRef.current is null");return}const P=h.current;if(c.current){try{c.current.close()}catch{}c.current=null}m("connecting"),P.clear(),P.writeln(`\x1B[36m[正在连接 ${n}${k?"/"+k:""} shell=${T} ...]\x1B[0m`);const D=wt.buildPodExecWsUrl(t,i,n,k||void 0,T),M=new WebSocket(D);c.current=M,M.onopen=()=>{m("connected"),P.reset();try{const{cols:R,rows:C}=P;M.send(JSON.stringify({status:1,cols:R,rows:C}))}catch(R){console.error("[PodExec:connect] resize error:",R)}const F=()=>{try{P.focus()}catch{}};F(),setTimeout(F,100),setTimeout(F,300)},M.onmessage=F=>{try{const R=JSON.parse(F.data);if(R.status===0&&typeof R.data=="string")P.write(R.data);else if(R.status===2||R.error){const C=R.data||R.message||R.error||"执行错误";if(C.includes("not found")&&T==="bash"){P.writeln(`\r \x1B[33m⚠ bash 不可用,请切换 /bin/sh 后重连。\x1B[0m`),d.current=!0;return}P.write(C.includes("\x1B")?C:`\r \x1B[31m${C}\x1B[0m\r `)}}catch{typeof F.data=="string"&&P.write(F.data)}},M.onclose=F=>{m(R=>R==="error"?R:"closed"),d.current||P.write(`\r \x1B[33m[连接已关闭]\x1B[0m\r `)},M.onerror=F=>{console.error("[PodExec:connect] WS error event fired, readyState=",M.readyState,"type=",F.type),m("error"),P.write(`\r \x1B[31m[连接发生错误]\x1B[0m\r `)}},[t,i,n,k,T]);H.useEffect(()=>{if(!s)return;if(!t){console.error("[PodExec:initEffect] ABORT: clusterId is falsy:",t);return}if(!n){console.error("[PodExec:initEffect] ABORT: podName is falsy:",n);return}let P=!1,D=0;const M=performance.now(),F=()=>{if(P)return;const R=a.current;if(!R){D++,D<20?requestAnimationFrame(F):console.error("[PodExec:tryInit] FAILED: containerRef still null after 20 retries (",Math.round(performance.now()-M),"ms)");return}const C=new Qu.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,scrollback:5e3,theme:{background:"#0f172a",foreground:"#e2e8f0",cursor:"#38bdf8",selectionBackground:"#1e40af",black:"#1e293b",red:"#ef4444",green:"#10b981",yellow:"#f59e0b",blue:"#3b82f6",magenta:"#a855f7",cyan:"#06b6d4",white:"#e2e8f0",brightBlack:"#475569",brightRed:"#f87171",brightGreen:"#34d399",brightYellow:"#fbbf24",brightBlue:"#60a5fa",brightMagenta:"#c084fc",brightCyan:"#22d3ee",brightWhite:"#f8fafc"}}),B=new $u.FitAddon;C.loadAddon(B),h.current=C,f.current=B,C.onData(j=>{c.current&&c.current.readyState===WebSocket.OPEN?c.current.send(JSON.stringify({status:0,data:j})):console.warn("[PodExec:term] TX dropped — WS not open, readyState=",c.current?.readyState)}),C.open(R),requestAnimationFrame(()=>{try{B.fit()}catch{}}),u.current=!0,A()};return requestAnimationFrame(F),()=>{P=!0}},[s,t,n]),H.useEffect(()=>{if(!s){try{c.current?.close()}catch{}try{h.current?.dispose()}catch{}h.current=null,c.current=null,f.current=null,u.current=!1,m("idle")}},[s]),H.useEffect(()=>{s&&h.current&&u.current&&A()},[k,T]),H.useEffect(()=>{if(!s)return;const P=a.current;if(!P)return;let D;const M=new ResizeObserver(()=>{clearTimeout(D),D=setTimeout(()=>{if(f.current&&h.current)try{f.current.fit(),h.current.focus();const{cols:F,rows:R}=h.current;c.current?.readyState===WebSocket.OPEN&&c.current.send(JSON.stringify({status:1,cols:F,rows:R}))}catch{}},60)});return M.observe(P),()=>{clearTimeout(D),M.disconnect()}},[s,g]);const O=p==="connected"?"bg-emerald-400":p==="error"?"bg-red-400":p==="closed"?"bg-slate-500":"bg-amber-400",V=p==="connected"?"已连接":p==="connecting"?"连接中":p==="error"?"连接错误":p==="closed"?"已断开":"空闲",N=H.useCallback(()=>{try{h.current?.focus()}catch{}},[]);return y.jsx(Iu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:279:5",open:s,onOpenChange:e,children:y.jsxs(Wu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:280:7",showCloseButton:!1,className:xl("bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] p-0 gap-0","!duration-0 !transition-none",g?"!max-w-none !w-screen !h-screen !rounded-none !translate-x-0 !translate-y-0 !left-0 !top-0":""),style:g?{maxWidth:"100vw",width:"100vw",height:"100vh"}:{maxWidth:"960px",width:"92vw"},children:[y.jsxs(Fu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:289:9",className:"sr-only",children:["exec — ",n]}),y.jsx(Vu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:290:9",className:"sr-only",children:"进入 Pod 容器执行命令"}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:293:9",className:"flex items-center justify-between gap-2 px-4 py-2 border-b border-[var(--dg-border)] flex-wrap",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:294:11",className:"flex items-center gap-2 text-sm min-w-0",children:[y.jsx("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:295:13",className:xl("w-2 h-2 rounded-full shrink-0",O),title:V}),y.jsx(Hu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:296:13",className:"h-4 w-4 text-blue-400 shrink-0"}),y.jsxs("span",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:297:13",className:"text-[var(--dg-text-primary)] font-medium truncate",children:["exec — ",n]}),p==="connecting"&&y.jsx(St,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:298:44",className:"h-3 w-3 animate-spin text-[var(--dg-text-muted)]"}),y.jsx("span",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:299:13",className:"text-xs text-[var(--dg-text-muted)]",children:V})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:301:11",className:"flex items-center gap-2",children:[r.length>0&&y.jsxs(kl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:303:15",value:k,onValueChange:w,children:[y.jsxs(wl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:304:17",className:"h-8 w-[150px] text-xs bg-[var(--dg-bg-hover)] border-[var(--dg-border)]",children:[y.jsx(ju,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:305:19",className:"h-3 w-3 mr-1 text-[var(--dg-text-muted)]"}),y.jsx(vl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:306:19",placeholder:"容器"})]}),y.jsx(Sl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:17",children:r.map(P=>y.jsx(Ol,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:55",value:P,children:P},P))})]}),y.jsxs(kl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:311:13",value:T,onValueChange:S,children:[y.jsx(wl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:312:15",className:"h-8 w-[110px] text-xs bg-[var(--dg-bg-hover)] border-[var(--dg-border)]",children:y.jsx(vl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:313:17"})}),y.jsx(Sl,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:15",children:py.map(P=>y.jsx(Ol,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:47",value:P.value,children:P.label},P.value))})]}),y.jsx(le,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:317:13",variant:"ghost",size:"sm",className:"h-8 px-2 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]",onClick:()=>{A(),l({title:"正在重连…"})},title:"重连",children:y.jsx(qu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:319:15",className:"h-3.5 w-3.5"})}),y.jsx("button",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:321:13",onClick:()=>x(!g),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:g?"退出全屏":"全屏",children:g?y.jsx(Xu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:322:29",className:"h-4 w-4"}):y.jsx(Uu,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:322:65",className:"h-4 w-4"})}),y.jsx("button",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:324:13",onClick:()=>e(!1),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:"关闭",children:y.jsx(Zs,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:325:15",className:"h-4 w-4"})})]})]}),y.jsx("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:331:9",ref:a,className:"bg-[#0f172a] cursor-text",style:{height:g?"calc(100vh - 49px)":"480px"},onClick:N})]})})}function zy({open:s,onOpenChange:e,clusterCode:t,namespace:i,podName:n,containers:r=[],initialContainer:o}){const[l,a]=H.useState(o||r[0]||""),[h,c]=H.useState("/"),[f,u]=H.useState([]),[d,p]=H.useState(!1),[m,g]=H.useState(""),[x,k]=H.useState(null),[w,T]=H.useState(!1),S=H.useRef(null),A=H.useRef(!1),O=H.useCallback(async C=>{p(!0),g(""),k(null);try{const B=await wt.listPodFiles(t,i,n,C,l||void 0),oe=(B?.entries||B?.files||B?.data?.entries||B?.data?.files||(Array.isArray(B)?B:[])).map(Q=>({name:Q.name??Q.Name??"",isDir:!!(Q.isDir??Q.is_dir??Q.IsDir??Q.dir??Q.directory),size:typeof Q.size=="number"?Q.size:Q.Size?Number(Q.Size):void 0,modTime:Q.modTime??Q.mod_time??Q.ModTime??Q.mtime??Q.modified})).filter(Q=>Q.name&&Q.name!==".");u(oe),c(C)}catch(B){g(B.message||"加载文件列表失败"),u([])}finally{p(!1)}},[t,i,n,l]);H.useEffect(()=>{s?(async()=>{if(A.current){O(h);return}p(!0);try{const B=await wt.execPod(t,i,n,["pwd"],l||void 0),j=(B?.stdout||B?.data?.stdout||"").trim(),oe=j&&j.startsWith("/")?j:"/";A.current=!0,c(oe),O(oe)}catch{A.current=!0,O("/")}})():A.current=!1},[s,l]);const V=C=>{if(C.isDir){const B=h==="/"?`/${C.name}`:`${h}/${C.name}`;O(B)}else N(C.name)},N=async C=>{const B=h==="/"?`/${C}`:`${h}/${C}`;try{const j=await wt.readPodFileText(t,i,n,B,l||void 0);k({file:C,content:j})}catch(j){k({file:C,content:`读取失败: ${j.message}`})}},P=C=>{const B=h==="/"?`/${C}`:`${h}/${C}`,j=wt.buildPodFileDownloadUrl(t,i,n,B,l||void 0);window.open(j,"_blank")},D=async C=>{const B=C.target.files?.[0];if(B){T(!0);try{await wt.uploadPodFile(t,i,n,h,B,l||void 0),O(h)}catch(j){g(`上传失败: ${j.message}`)}finally{T(!1),S.current&&(S.current.value="")}}},M=()=>{if(h==="/")return;const C=h.split("/").filter(Boolean);C.pop(),O(C.length===0?"/":`/${C.join("/")}`)},F=C=>C==null?"-":C<1024?`${C} B`:C<1024*1024?`${(C/1024).toFixed(1)} KB`:`${(C/(1024*1024)).toFixed(1)} MB`,R=h.split("/").filter(Boolean);return s?y.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:163:5",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70",onClick:()=>e(!1),children:y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:164:7",className:"bg-slate-900 border border-slate-700 rounded-xl w-[90vw] max-w-5xl h-[80vh] flex flex-col shadow-2xl",onClick:C=>C.stopPropagation(),children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:169:9",className:"flex items-center justify-between p-3 border-b border-slate-700 shrink-0",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:170:11",className:"flex items-center gap-2",children:[y.jsx(_u,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:171:13",className:"h-4 w-4 text-amber-400"}),y.jsxs("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:172:13",className:"text-sm font-semibold text-slate-200",children:["文件浏览器: ",n]}),y.jsx(Yu,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:173:13",variant:"outline",className:"border-slate-700 text-slate-400 text-[10px]",children:i})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:175:11",className:"flex items-center gap-2",children:[r.length>0&&y.jsx("select",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:177:15",value:l,onChange:C=>{a(C.target.value)},className:"bg-slate-800 border border-slate-700 rounded text-xs text-slate-300 px-2 py-1",children:r.map(C=>y.jsx("option",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:182:40",value:C,children:C},C))}),y.jsx(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:185:13",variant:"ghost",size:"icon",className:"h-7 w-7 text-slate-400",onClick:()=>e(!1),children:y.jsx(Zs,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:186:15",className:"h-4 w-4"})})]})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:192:9",className:"flex items-center justify-between p-2 border-b border-slate-800 shrink-0",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:193:11",className:"flex items-center gap-1 text-xs text-slate-400",children:[y.jsx(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:194:13",variant:"ghost",size:"icon",className:"h-6 w-6 text-slate-500",onClick:M,disabled:h==="/",children:y.jsx(Ku,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:195:15",className:"h-3.5 w-3.5"})}),y.jsx("button",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:197:13",className:"hover:text-slate-200",onClick:()=>O("/"),children:"root"}),R.map((C,B)=>{const j=`/${R.slice(0,B+1).join("/")}`;return y.jsxs("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:201:17",className:"flex items-center gap-1",children:[y.jsx(zu,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:202:19",className:"h-3 w-3"}),y.jsx("button",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:203:19",className:"hover:text-slate-200",onClick:()=>O(j),children:C})]},j)})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:208:11",className:"flex items-center gap-2",children:[y.jsx("input",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:209:13",type:"file",ref:S,className:"hidden",onChange:D}),y.jsxs(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:210:13",size:"sm",variant:"outline",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>S.current?.click(),disabled:w,children:[w?y.jsx(St,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:211:28",className:"h-3 w-3 animate-spin mr-1"}):y.jsx(Gu,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:211:80",className:"h-3 w-3 mr-1"}),"上传"]}),y.jsx(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:213:13",size:"sm",variant:"outline",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>O(h),disabled:d,children:d?y.jsx(St,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:214:26",className:"h-3 w-3 animate-spin"}):y.jsx(Ju,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:214:73",className:"h-3 w-3"})})]})]}),y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:220:9",className:"flex-1 overflow-hidden flex",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:222:11",className:`${x?"w-1/2":"w-full"} overflow-auto p-2 border-r border-slate-800`,children:[m&&y.jsx("p",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:223:23",className:"text-xs text-red-400 p-2",children:m}),d?y.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:15",className:"flex items-center justify-center h-32",children:y.jsx(St,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:70",className:"h-5 w-5 animate-spin text-slate-500"})}):f.length===0?y.jsx("p",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:227:15",className:"text-xs text-slate-500 p-4 text-center",children:"空目录"}):y.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:229:15",className:"space-y-0.5",children:f.sort((C,B)=>C.isDir===B.isDir?C.name.localeCompare(B.name):C.isDir?-1:1).map(C=>y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:231:19",className:"flex items-center gap-2 px-2 py-1.5 rounded hover:bg-slate-800/50 cursor-pointer group",onClick:()=>V(C),children:[C.isDir?y.jsx(Zu,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:237:23",className:"h-4 w-4 text-blue-400 shrink-0"}):y.jsx(ed,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:239:23",className:"h-4 w-4 text-slate-500 shrink-0"}),y.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:241:21",className:`text-xs truncate ${C.isDir?"text-blue-300":"text-slate-300"}`,children:C.name}),!C.isDir&&y.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:245:23",className:"text-[10px] text-slate-600 ml-auto shrink-0",children:F(C.size)}),!C.isDir&&y.jsx(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:248:23",variant:"ghost",size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 text-slate-400 hover:text-emerald-400 shrink-0",onClick:B=>{B.stopPropagation(),P(C.name)},title:"下载",children:y.jsx(td,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:253:25",className:"h-3 w-3"})})]},C.name))})]}),x&&y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:264:13",className:"w-1/2 flex flex-col overflow-hidden",children:[y.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:265:15",className:"flex items-center justify-between p-2 border-b border-slate-800 shrink-0",children:[y.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:266:17",className:"text-xs text-slate-300 font-mono",children:x.file}),y.jsx(le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:267:17",variant:"ghost",size:"icon",className:"h-6 w-6 text-slate-400",onClick:()=>k(null),children:y.jsx(Zs,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:268:19",className:"h-3.5 w-3.5"})})]}),y.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:271:15",className:"flex-1 overflow-auto p-3",children:y.jsx("pre",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:272:17",className:"text-xs text-slate-300 font-mono whitespace-pre-wrap break-all bg-slate-950 rounded p-3",children:x.content||"(空文件)"})})]})]})]})}):null}export{Hy as P,Ao as R,ys as S,Vy as Y,zy as a,Iy as b,bs as c,Ny as e,Ly as f,Co as o,Ey as s,dy as y};