groove-dev 0.27.141 → 0.27.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@groove-dev/cli/package.json +1 -1
- package/node_modules/@groove-dev/daemon/package.json +1 -1
- package/node_modules/@groove-dev/daemon/src/api.js +18 -7
- package/node_modules/@groove-dev/daemon/src/introducer.js +1 -1
- package/node_modules/@groove-dev/daemon/src/journalist.js +3 -2
- package/node_modules/@groove-dev/daemon/src/keeper.js +2 -2
- package/node_modules/@groove-dev/daemon/src/memory.js +8 -5
- package/node_modules/@groove-dev/daemon/src/process.js +5 -16
- package/node_modules/@groove-dev/daemon/src/rotator.js +25 -8
- package/node_modules/@groove-dev/gui/dist/assets/{codemirror-BQqYnZfL.js → codemirror-BYKpdS2W.js} +10 -10
- package/node_modules/@groove-dev/gui/dist/assets/index-Bjd91ufV.js +984 -0
- package/node_modules/@groove-dev/gui/dist/assets/index-BqdwIFn4.css +1 -0
- package/node_modules/@groove-dev/gui/dist/index.html +3 -3
- package/node_modules/@groove-dev/gui/package.json +1 -1
- package/node_modules/@groove-dev/gui/src/app.jsx +0 -2
- package/node_modules/@groove-dev/gui/src/components/agents/agent-chat.jsx +6 -7
- package/node_modules/@groove-dev/gui/src/components/agents/agent-feed.jsx +8 -2
- package/node_modules/@groove-dev/gui/src/components/agents/agent-file-tree.jsx +5 -6
- package/node_modules/@groove-dev/gui/src/components/agents/agent-panel.jsx +79 -5
- package/node_modules/@groove-dev/gui/src/components/agents/workspace-mode.jsx +2 -53
- package/node_modules/@groove-dev/gui/src/components/dashboard/context-gauges.jsx +111 -0
- package/node_modules/@groove-dev/gui/src/components/dashboard/routing-chart.jsx +70 -33
- package/node_modules/@groove-dev/gui/src/components/editor/code-editor.jsx +2 -68
- package/node_modules/@groove-dev/gui/src/components/layout/activity-bar.jsx +1 -2
- package/node_modules/@groove-dev/gui/src/components/layout/terminal-panel.jsx +0 -1
- package/node_modules/@groove-dev/gui/src/stores/groove.js +3 -3
- package/node_modules/@groove-dev/gui/src/views/dashboard.jsx +2 -0
- package/node_modules/@groove-dev/gui/src/views/marketplace.jsx +3 -71
- package/node_modules/@groove-dev/gui/src/views/models.jsx +3 -3
- package/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/daemon/package.json +1 -1
- package/packages/daemon/src/api.js +18 -7
- package/packages/daemon/src/introducer.js +1 -1
- package/packages/daemon/src/journalist.js +3 -2
- package/packages/daemon/src/keeper.js +2 -2
- package/packages/daemon/src/memory.js +8 -5
- package/packages/daemon/src/process.js +5 -16
- package/packages/daemon/src/rotator.js +25 -8
- package/packages/gui/dist/assets/{codemirror-BQqYnZfL.js → codemirror-BYKpdS2W.js} +10 -10
- package/packages/gui/dist/assets/index-Bjd91ufV.js +984 -0
- package/packages/gui/dist/assets/index-BqdwIFn4.css +1 -0
- package/packages/gui/dist/index.html +3 -3
- package/packages/gui/package.json +1 -1
- package/packages/gui/src/app.jsx +0 -2
- package/packages/gui/src/components/agents/agent-chat.jsx +6 -7
- package/packages/gui/src/components/agents/agent-feed.jsx +8 -2
- package/packages/gui/src/components/agents/agent-file-tree.jsx +5 -6
- package/packages/gui/src/components/agents/agent-panel.jsx +79 -5
- package/packages/gui/src/components/agents/workspace-mode.jsx +2 -53
- package/packages/gui/src/components/dashboard/context-gauges.jsx +111 -0
- package/packages/gui/src/components/dashboard/routing-chart.jsx +70 -33
- package/packages/gui/src/components/editor/code-editor.jsx +2 -68
- package/packages/gui/src/components/layout/activity-bar.jsx +1 -2
- package/packages/gui/src/components/layout/terminal-panel.jsx +0 -1
- package/packages/gui/src/stores/groove.js +3 -3
- package/packages/gui/src/views/dashboard.jsx +2 -0
- package/packages/gui/src/views/marketplace.jsx +3 -71
- package/packages/gui/src/views/models.jsx +3 -3
- package/node_modules/@groove-dev/gui/dist/assets/index-A4e1gIDh.css +0 -1
- package/node_modules/@groove-dev/gui/dist/assets/index-P1hsM27-.js +0 -8696
- package/node_modules/@groove-dev/gui/src/components/toys/toy-card.jsx +0 -78
- package/node_modules/@groove-dev/gui/src/components/toys/toy-creator.jsx +0 -144
- package/node_modules/@groove-dev/gui/src/components/toys/toy-launcher.jsx +0 -187
- package/node_modules/@groove-dev/gui/src/views/toys.jsx +0 -162
- package/packages/gui/dist/assets/index-A4e1gIDh.css +0 -1
- package/packages/gui/dist/assets/index-P1hsM27-.js +0 -8696
- package/packages/gui/src/components/toys/toy-card.jsx +0 -78
- package/packages/gui/src/components/toys/toy-creator.jsx +0 -144
- package/packages/gui/src/components/toys/toy-launcher.jsx +0 -187
- package/packages/gui/src/views/toys.jsx +0 -162
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
let ys=[],xl=[];(()=>{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<s.length;e++)(e%2?xl:ys).push(t=t+s[e])})();function
|
|
1
|
+
let ys=[],xl=[];(()=>{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<s.length;e++)(e%2?xl:ys).push(t=t+s[e])})();function Uh(s){if(s<768)return!1;for(let e=0,t=ys.length;;){let i=e+t>>1;if(s<ys[i])t=i;else if(s>=xl[i])e=i+1;else return!0;if(e==t)return!1}}function Kr(s){return s>=127462&&s<=127487}const $r=8205;function Gh(s,e,t=!0,i=!0){return(t?wl:Jh)(s,e,i)}function wl(s,e,t){if(e==s.length)return e;e&&vl(s.charCodeAt(e))&&kl(s.charCodeAt(e-1))&&e--;let i=Un(s,e);for(e+=jr(i);e<s.length;){let n=Un(s,e);if(i==$r||n==$r||t&&Uh(n))e+=jr(n),i=n;else if(Kr(n)){let r=0,o=e-2;for(;o>=0&&Kr(Un(s,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Jh(s,e,t){for(;e>0;){let i=wl(s,e-2,t);if(i<e)return i;e--}return 0}function Un(s,e){let t=s.charCodeAt(e);if(!kl(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return vl(i)?(t-55296<<10)+(i-56320)+65536:t}function vl(s){return s>=56320&&s<57344}function kl(s){return s>=55296&&s<56320}function jr(s){return s<65536?1:2}class P{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]=qt(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),ze.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]=qt(this,e,t);let i=[];return this.decompose(e,t,i,0),ze.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 ai(this),r=new ai(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 ai(this,e)}iterRange(e,t=this.length){return new Sl(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 Cl(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]?P.empty:e.length<=32?new J(e):ze.from(J.split(e,[]))}}class J extends P{constructor(e,t=_h(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((t?i:l)>=e)return new Yh(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new J(Ur(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=en(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new J(l,o.length+r.length));else{let a=l.length>>1;i.push(new J(l.slice(0,a)),new J(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof J))return super.replace(e,t,i);[e,t]=qt(this,e,t);let n=en(this.text,en(i.text,Ur(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new J(n,r):ze.from(J.split(n,[]),r)}sliceString(e,t=this.length,i=`
|
|
2
2
|
`){[e,t]=qt(this,e,t);let n="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(n+=i),e<a&&t>r&&(n+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,i.length==32&&(t.push(new J(i,n)),i=[],n=-1);return n>-1&&t.push(new J(i,n)),t}}class ze extends P{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<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=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]=qt(this,e,t),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let f=this.children.slice();return f[n]=a,new ze(f,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=`
|
|
3
|
-
`){[e,t]=qt(this,e,t);let n="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(n+=i),e<a&&t>o&&(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 ze))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 J(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,h=-1,f=[];function c(d){let p;if(d.lines>r&&d instanceof ze)for(let m of d.children)c(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof J&&a&&(p=f[f.length-1])instanceof J&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,f[f.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,h+=d.length+1,f.push(d))}function u(){a!=0&&(l.push(f.length==1?f[0]:ze.from(f,h)),h=-1,a=f.length=0)}for(let d of e)c(d);return u(),l.length==1?l[0]:new ze(l,t)}}P.empty=new J([""],0);function
|
|
4
|
-
`,this;e--}else if(n instanceof J){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof J?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Sl{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ai(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 Cl{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"&&(P.prototype[Symbol.iterator]=function(){return this.iter()},ai.prototype[Symbol.iterator]=Sl.prototype[Symbol.iterator]=Cl.prototype[Symbol.iterator]=function(){return this});class Xh{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 qt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function te(s,e,t=!0,i=!0){return Jh(s,e,t,i)}function Qh(s){return s>=56320&&s<57344}function Zh(s){return s>=55296&&s<56320}function tt(s,e){let t=s.charCodeAt(e);if(!Zh(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return Qh(i)?(t-55296<<10)+(i-56320)+65536:t}function Al(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function bt(s){return s<65536?1:2}const bs=/\r\n?|\n/;var he=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(he||(he={}));class Ge{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(e,t=!1){xs(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new Ge(e)}composeDesc(e){return this.empty?e:e.empty?this:Ml(this,e)}mapDesc(e,t=!1){return e.empty?this:ws(this,e,t)}mapPos(e,t=-1,i=he.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=n+l;if(a<0){if(h>e)return r+(e-n);r+=l}else{if(i!=he.Simple&&h>=e&&(i==he.TrackDel&&n<e&&h>e||i==he.TrackBefore&&n<e||i==he.TrackAfter&&h>e))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<this.sections.length&&n<=t;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Ge(e)}static create(e){return new Ge(e)}}class Q extends Ge{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 xs(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return ws(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length<a;)i.push(P.empty);i.push(o?e.slice(r,r+o):P.empty)}r+=o}return new Q(t,i)}compose(e){return this.empty?e:e.empty?this:Ml(this,e,!0)}map(e,t=!1){return e.empty?this:ws(this,e,t,!0)}iterChanges(e,t=!1){xs(this,e,t)}get desc(){return Ge.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new pi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let f=Math.min(r.len,a-l);re(n,f,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;re(t,f,c),c>0&&rt(i,t,r.text),r.forward(f),l+=f}let h=e[o++];for(;l<h;){if(r.done)break e;let f=Math.min(r.len,h-l);re(t,f,-1),re(n,f,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(f),l+=f}}return{changes:new Q(t,i),filtered:Ge.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):n==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(f=!1){if(!f&&!n.length)return;o<t&&re(n,t-o,-1);let c=new Q(n,r);l=l?l.compose(c.map(l)):c,n=[],r=[],o=0}function h(f){if(Array.isArray(f))for(let c of f)h(c);else if(f instanceof Q){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);a(),l=l?l.compose(f.map(l)):f}else{let{from:c,to:u=c,insert:d}=f;if(c>u||c<0||u>t)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?P.of(d.split(i||bs)):d:P.empty,m=p.length;if(c==u&&m==0)return;c<o&&a(),c>o&&re(n,c-o,-1),re(n,u-c,m),rt(r,n,p),o=u}}return h(e),a(!l),l}static empty(e){return new Q(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<n;)i.push(P.empty);i[n]=P.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new Q(t,i)}static createSet(e,t){return new Q(e,t)}}function re(s,e,t,i=!1){if(e==0&&t<=0)return;let n=s.length-2;n>=0&&t<=0&&t==s[n+1]?s[n]+=e:n>=0&&e==0&&s[n]==0?s[n+1]+=t:i?(s[n]+=e,s[n+1]+=t):s.push(e,t)}function rt(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(t);else{for(;s.length<i;)s.push(P.empty);s.push(t)}}function xs(s,e,t){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],a=s.sections[o++];if(a<0)n+=l,r+=l;else{let h=n,f=r,c=P.empty;for(;h+=l,f+=a,a&&i&&(c=c.append(i[o-2>>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];e(n,h,r,f,c),n=h,r=f}}}function ws(s,e,t,i=!1){let n=[],r=i?[]:null,o=new pi(s),l=new pi(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);re(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<o.len||l.len==o.len&&!t))){let h=l.len;for(re(n,l.ins,-1);h;){let f=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=f&&(re(n,0,o.ins),r&&rt(r,n,o.text),a=o.i),o.forward(f),h-=f}l.next()}else if(o.ins>=0){let h=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);h+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.len<f)f-=l.len,l.next();else break;re(n,h,a<o.i?o.ins:0),r&&a<o.i&&rt(r,n,o.text),a=o.i,o.forward(o.len-f)}else{if(o.done&&l.done)return r?Q.createSet(n,r):Ge.create(n);throw new Error("Mismatched change set lengths")}}}function Ml(s,e,t=!1){let i=[],n=t?[]:null,r=new pi(s),o=new pi(e);for(let l=!1;;){if(r.done&&o.done)return n?Q.createSet(i,n):Ge.create(i);if(r.ins==0)re(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)re(i,0,o.ins,l),n&&rt(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let f=o.ins==-1?-1:o.off?0:o.ins;re(i,a,f,l),n&&f&&rt(n,i,o.text)}else o.ins==-1?(re(i,r.off?0:r.len,a,l),n&&rt(n,i,r.textBit(a))):(re(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&rt(n,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class pi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?P.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?P.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 wt{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 wt(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(e.anchor,e.head)}static create(e,t,i){return new wt(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(e.ranges.map(t=>wt.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,n){return wt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(e,t,i,n,r){let o=(i??16777215)<<6|(n==null?7:Math.min(6,n));return!r&&e!=t&&(r=t<e?1:-1),t<e?wt.create(t,e,48|o):wt.create(e,t,(r?r<0?8:16:0)|o)}static normalized(e,t=0){let i=e[t];e.sort((n,r)=>n.from-r.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let r=e[n],o=e[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);n<=t&&t--,e.splice(--n,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(e,t)}}function Tl(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let or=0;class C{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=or++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new C(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:lr),!!e.static,e.enables)}of(e){return new nn([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new nn(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new nn(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function lr(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class nn{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=or++}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,f=[];for(let c of this.dependencies)c=="doc"?a=!0:c=="selection"?h=!0:(((t=e[c.id])!==null&&t!==void 0?t:1)&1)==0&&f.push(e[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||vs(c,f)){let d=i(c);if(l?!Gr(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[r];if(p!=null){let m=hn(u,p);if(this.dependencies.every(g=>g instanceof C?u.facet(g)===c.facet(g):g instanceof De?u.field(g,!1)==c.field(g,!1):!0)||(l?Gr(d=i(c),m,n):n(d=i(c),m)))return c.values[o]=m,0}else d=i(c);return c.values[o]=d,1}}}}function Gr(s,e,t){if(s.length!=e.length)return!1;for(let i=0;i<s.length;i++)if(!t(s[i],e[i]))return!1;return!0}function vs(s,e){let t=!1;for(let i of e)hi(s,i)&1&&(t=!0);return t}function ef(s,e,t){let i=t.map(a=>s[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 f=0;f<i.length;f++){let c=hn(a,i[f]);if(n[f]==2)for(let u of c)h.push(u);else h.push(c)}return e.combine(h)}return{create(a){for(let h of i)hi(a,h);return a.values[o]=l(a),1},update(a,h){if(!vs(a,r))return 0;let f=l(a);return e.compare(f,a.values[o])?0:(a.values[o]=f,1)},reconfigure(a,h){let f=vs(a,i),c=h.config.facets[e.id],u=h.facet(e);if(c&&!f&&lr(t,c))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Ii=C.define({static:!0});class De{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new De(or++,e.create,e.update,e.compare||((i,n)=>i===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ii).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>{let r=i.facet(Ii),o=n.facet(Ii),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,Ii.of({field:this,create:e})]}get extension(){return this}}const xt={lowest:4,low:3,default:2,high:1,highest:0};function ti(s){return e=>new Dl(e,s)}const Mt={highest:ti(xt.highest),high:ti(xt.high),default:ti(xt.default),low:ti(xt.low),lowest:ti(xt.lowest)};class Dl{constructor(e,t){this.inner=e,this.prec=t}}class Rn{of(e){return new ks(this,e)}reconfigure(e){return Rn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ks{constructor(e,t){this.compartment=e,this.inner=t}}class an{constructor(e,t,i,n,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),o=new Map;for(let u of tf(e,t,o))u instanceof De?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 f=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,m=f&&f[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,lr(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(y=>y.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(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>ef(g,p,d))}}let c=h.map(u=>u(l));return new an(e,o,c,l,a,r)}}function tf(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 ks&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof ks){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 Dl)r(o.inner,o.prec);else if(o instanceof De)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof nn)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,xt.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,xt.default),i.reduce((o,l)=>o.concat(l))}function hi(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 hn(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const Ol=C.define(),Ss=C.define({combine:s=>s.some(e=>e),static:!0}),Bl=C.define({combine:s=>s.length?s[0]:void 0,static:!0}),Ll=C.define(),El=C.define(),Rl=C.define(),Il=C.define({combine:s=>s.length?s[0]:!1});class Ze{constructor(e,t){this.type=e,this.value=t}static define(){return new nf}}class nf{of(e){return new Ze(this,e)}}class sf{constructor(e){this.map=e}of(e){return new N(this,e)}}class N{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 N(this.type,t)}is(e){return this.type==e}static define(e={}){return new sf(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}}N.reconfigure=N.define();N.appendConfig=N.define();class Y{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&&Tl(i,t.newLength),r.some(l=>l.type==Y.time)||(this.annotations=r.concat(Y.time.of(Date.now())))}static create(e,t,i,n,r,o){return new Y(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(Y.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Y.time=Ze.define();Y.userEvent=Ze.define();Y.addToHistory=Ze.define();Y.remote=Ze.define();function rf(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==e.length||e[n]>=s[i]))r=s[i++],o=s[i++];else if(n<e.length)r=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Pl(s,e,t){var i;let n,r,o;return t?(n=e.changes,r=Q.empty(e.changes.length),o=s.changes.compose(e.changes)):(n=e.changes.map(s.changes),r=s.changes.mapDesc(e.changes,!0),o=s.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:N.mapEffects(s.effects,n).concat(N.mapEffects(e.effects,r)),annotations:s.annotations.length?s.annotations.concat(e.annotations):e.annotations,scrollIntoView:s.scrollIntoView||e.scrollIntoView}}function Cs(s,e,t){let i=e.selection,n=Pt(e.annotations);return e.userEvent&&(n=n.concat(Y.userEvent.of(e.userEvent))),{changes:e.changes instanceof Q?e.changes:Q.of(e.changes||[],t,s.facet(Bl)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Pt(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function Nl(s,e,t){let i=Cs(s,e.length?e[0]:{},s.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Pl(i,Cs(s,e[r],o?i.changes.newLength:s.doc.length),o)}let n=Y.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return lf(t?of(n):n)}function of(s){let e=s.startState,t=!0;for(let n of e.facet(Ll)){let r=n(s);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:rf(t,r))}if(t!==!0){let n,r;if(t===!1)r=s.changes.invertedDesc,n=Q.empty(e.doc.length);else{let o=s.changes.filter(t);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=Y.create(e,n,s.selection&&s.selection.map(r),N.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=e.facet(El);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof Y?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Y?s=r[0]:s=Nl(e,Pt(r),!1)}return s}function lf(s){let e=s.startState,t=e.facet(Rl),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=Pl(i,Cs(e,r,s.changes.newLength),!0))}return i==s?s:Y.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const af=[];function Pt(s){return s==null?af:Array.isArray(s)?s:[s]}var _=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(_||(_={}));const hf=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let As;try{As=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ff(s){if(As)return As.test(s);for(let e=0;e<s.length;e++){let t=s[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||hf.test(t)))return!0}return!1}function cf(s){return e=>{if(!/\S/.test(e))return _.Space;if(ff(e))return _.Word;for(let t=0;t<s.length;t++)if(e.indexOf(s[t])>-1)return _.Word;return _.Other}}class F{constructor(e,t,i,n,r,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)hi(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return hi(this,i),hn(this,i)}update(...e){return Nl(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:n}=t;for(let l of e.effects)l.is(Rn.reconfigure)?(t&&(n=new Map,t.compartments.forEach((a,h)=>n.set(h,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(N.reconfigure)?(t=null,i=l.value):l.is(N.appendConfig)&&(t=null,i=Pt(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=an.resolve(i,n,this),r=new F(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Ss)?e.newSelection:e.newSelection.asSingle();new F(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:b.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Pt(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),f=h.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(f);let c=n.mapDesc(h,!0);r.push(a.range.map(c)),n=n.compose(f),o=N.mapEffects(o,f).concat(N.mapEffects(Pt(a.effects),c))}return{changes:n,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Q?e:Q.of(e,this.doc.length,this.facet(F.lineSeparator))}toText(e){return P.of(e.split(this.facet(F.lineSeparator)||bs))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(hi(this,t),hn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof De&&this.config.address[n.id]!=null&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return F.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=an.resolve(e.extensions||[],new Map),i=e.doc instanceof P?e.doc:P.of((e.doc||"").split(t.staticFacet(F.lineSeparator)||bs)),n=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return Tl(n,i.length),t.staticFacet(Ss)||(n=n.asSingle()),new F(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(F.tabSize)}get lineBreak(){return this.facet(F.lineSeparator)||`
|
|
5
|
-
`}get readOnly(){return this.facet(Il)}phrase(e,...t){for(let i of this.facet(F.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet(Ol))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return cf(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=te(t,o,!1);if(r(t.slice(a,o))!=_.Word)break;o=a}for(;l<n;){let a=te(t,l);if(r(t.slice(l,a))!=_.Word)break;l=a}return o==l?null:b.range(o+i,l+i)}}F.allowMultipleSelections=Ss;F.tabSize=C.define({combine:s=>s.length?s[0]:4});F.lineSeparator=Bl;F.readOnly=Il;F.phrases=C.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])}});F.languageData=Ol;F.changeFilter=Ll;F.transactionFilter=El;F.transactionExtender=Rl;Rn.reconfigure=N.define();function Yt(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 lt{eq(e){return this==e}range(e,t=e){return Ms.create(e,t,this)}}lt.prototype.startSide=lt.prototype.endSide=0;lt.prototype.point=!1;lt.prototype.mapMode=he.TrackDel;function ar(s,e){return s==e||s.constructor==e.constructor&&s.eq(e)}let Ms=class Wl{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Wl(e,t,i)}};function Ts(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class hr{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);r<o;r++)if(n(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],n=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],f=this.from[a]+e,c=this.to[a]+e,u,d;if(f==c){let p=t.mapPos(f,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(f,h.endSide),d<u)))continue}else if(u=t.mapPos(f,h.startSide),d=t.mapPos(c,h.endSide),u>d||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 hr(n,r,i,l):null,pos:o}}}class R{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 R(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(Ts)),this.isEmpty)return t.length?R.of(t):this;let l=new Fl(this,null,-1).goto(0),a=0,h=[],f=new Kt;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let c=t[a++];f.addInner(c.from,c.to,c.value)||h.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&f.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||n>l.to||r<l.from||o(l.from,l.to,l.value))&&(f.addInner(l.from,l.to,l.value)||h.push(Ms.create(l.from,l.to,l.value))),l.next());return f.finishInner(this.nextLayer.isEmpty&&!h.length?R.empty:this.nextLayer.update({add:h,filter:o,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)n=Math.max(n,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:f,pos:c}=a.map(l,e);f&&(n=Math.max(n,f.maxPoint),t.push(f),i.push(c))}}let r=this.nextLayer.map(e);return t.length==0?r:new R(i,t,r||R.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return mi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return mi.from(e).goto(t)}static compare(e,t,i,n,r=-1){let o=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),a=Jr(o,l,i),h=new ii(o,a,r),f=new ii(l,a,r);i.iterGaps((c,u,d)=>_r(h,c,f,u,d,n)),i.empty&&i.length==0&&_r(h,0,f,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),o=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Jr(r,o),a=new ii(r,l,0).goto(i),h=new ii(o,l,0).goto(i);for(;;){if(a.to!=h.to||!Ds(a.active,h.active)||a.point&&(!h.point||!ar(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 ii(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFrom<t?f.length+1:o.point.startSide<0?f.length:Math.min(f.length,a);n.point(l,h,o.point,f,c,o.pointRank),a=Math.min(o.openEnd(h),f.length)}else h>l&&(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 Kt;for(let n of e instanceof Ms?[e]:t?uf(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return R.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=R.empty;n=n.nextLayer)t=new R(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}R.empty=new R([],[],null,-1);function uf(s){if(s.length>1)for(let e=s[0],t=1;t<s.length;t++){let i=s[t];if(Ts(e,i)>0)return s.slice().sort(Ts);e=i}return s}R.empty.nextLayer=R.empty;class Kt{finishChunk(e){this.chunks.push(new hr(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 Kt)).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(R.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=R.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Jr(s,e,t){let i=new Map;for(let r of s)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let n=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class Fl{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<e||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class mi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Fl(o,t,i,r));return n.length==1?n[0]:new mi(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--)Gn(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--)Gn(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(),Gn(this.heap,0)}}}function Gn(s,e){for(let t=s[e];;){let i=(e<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1<s.length&&n.compare(s[i+1])>=0&&(n=s[i+1],i++),t.compare(n)<0)break;s[i]=t,s[e]=n,e=i}}class ii{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=mi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Pi(this.active,e),Pi(this.activeTo,e),Pi(this.activeRank,e),this.minActive=Yr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;Ni(this.active,t,i),Ni(this.activeTo,t,n),Ni(this.activeRank,t,r),e&&Ni(e,t,this.cursor.from),this.minActive=Yr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Pi(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<e;n--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function _r(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 f=!1;;){let c=s.to+a-t.to,u=c||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&&ar(s.point,t.point)&&Ds(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,p,s.point,t.point),f=!1):(f&&r.boundChange(l),p>l&&!Ds(s.active,t.active)&&r.compareRange(l,p,s.active,t.active),h&&p<o&&(c||s.openEnd(d)!=t.openEnd(d))&&(f=!0)),d>o)break;l=d,u<=0&&s.next(),u>=0&&t.next()}}function Ds(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(s[t]!=e[t]&&!ar(s[t],e[t]))return!1;return!0}function Pi(s,e){for(let t=e,i=s.length-1;t<i;t++)s[t]=s[t+1];s.pop()}function Ni(s,e,t){for(let i=s.length-1;i>=e;i--)s[i+1]=s[i];s[e]=t}function Yr(s,e){let t=-1,i=1e9;for(let n=0;n<e.length;n++)(e[n]-i||s[n].endSide-s[t].endSide)<0&&(t=n,i=e[n]);return t}function In(s,e,t=s.length){let i=0;for(let n=0;n<t&&n<s.length;)s.charCodeAt(n)==9?(i+=e-i%e,n++):(i++,n=te(s,n));return i}function df(s,e,t,i){for(let n=0,r=0;;){if(r>=e)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?t-r%t:1,n=te(s,n)}return s.length}const Os="ͼ",Xr=typeof Symbol>"u"?"__"+Os:Symbol.for(Os),Bs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Qr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class at{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 f=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,f,u)}else p!=null&&f.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(f.length||u)&&a.push((i&&!c&&!h?o.map(i):o).join(", ")+" {"+f.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
6
|
-
`)}static newName(){let e=Qr[Xr]||1;return Qr[Xr]=e+1,Os+e.toString(36)}static mount(e,t,i){let n=e[Bs],r=i&&i.nonce;n?r&&n.setNonce(r):n=new
|
|
7
|
-
`;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var ht={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},gi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},mf=typeof navigator<"u"&&/Mac/.test(navigator.platform),gf=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var se=0;se<10;se++)ht[48+se]=ht[96+se]=String(se);for(var se=1;se<=24;se++)ht[se+111]="F"+se;for(var se=65;se<=90;se++)ht[se]=String.fromCharCode(se+32),gi[se]=String.fromCharCode(se);for(var Jn in ht)gi.hasOwnProperty(Jn)||(gi[Jn]=ht[Jn]);function yf(s){var e=mf&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||gf&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?gi:ht)[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 Z(){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(;e<arguments.length;e++)Hl(s,arguments[e]);return s}function Hl(s,e){if(typeof e=="string")s.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)s.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)Hl(s,e[t]);else throw new RangeError("Unsupported child node: "+e)}let ae=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ls=typeof document<"u"?document:{documentElement:{style:{}}};const Es=/Edge\/(\d+)/.exec(ae.userAgent),Vl=/MSIE \d/.test(ae.userAgent),Rs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ae.userAgent),Pn=!!(Vl||Rs||Es),eo=!Pn&&/gecko\/(\d+)/i.test(ae.userAgent),_n=!Pn&&/Chrome\/(\d+)/.exec(ae.userAgent),bf="webkitFontSmoothing"in Ls.documentElement.style,Is=!Pn&&/Apple Computer/.test(ae.vendor),to=Is&&(/Mobile\/\w+/.test(ae.userAgent)||ae.maxTouchPoints>2);var k={mac:to||/Mac/.test(ae.platform),windows:/Win/.test(ae.platform),linux:/Linux|X11/.test(ae.platform),ie:Pn,ie_version:Vl?Ls.documentMode||6:Rs?+Rs[1]:Es?+Es[1]:0,gecko:eo,gecko_version:eo?+(/Firefox\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,chrome:!!_n,chrome_version:_n?+_n[1]:0,ios:to,android:/Android\b/.test(ae.userAgent),webkit_version:bf?+(/\bAppleWebKit\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,safari:Is,safari_version:Is?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ae.userAgent)||[0,0])[1]:0,tabSize:Ls.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function fr(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 fn=Object.create(null);function cr(s,e,t){if(s==e)return!0;s||(s=fn),e||(e=fn);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 xf(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 io(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 wf(s){let e=Object.create(null);for(let t=0;t<s.attributes.length;t++){let i=s.attributes[t];e[i.name]=i.value}return e}class Ai{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var me=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(me||(me={}));class L extends lt{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new Mi(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new St(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}=zl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new St(e,i,n,t,e.widget||null,!0)}static line(e){return new Ti(e)}static set(e,t=!1){return R.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}L.none=R.empty;class Mi extends L{constructor(e){let{start:t,end:i}=zl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?fr(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||fn}eq(e){return this==e||e instanceof Mi&&this.tagName==e.tagName&&cr(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)}}Mi.prototype.point=!1;class Ti extends L{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ti&&this.spec.class==e.spec.class&&cr(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)}}Ti.prototype.mapMode=he.TrackBefore;Ti.prototype.point=!0;class St extends L{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?he.TrackBefore:he.TrackAfter:he.TrackDel}get type(){return this.startSide!=this.endSide?me.WidgetRange:this.startSide<=0?me.WidgetBefore:me.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof St&&vf(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)}}St.prototype.point=!0;function zl(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 vf(s,e){return s==e||!!(s&&e&&s.compare(e))}function Nt(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 yi extends lt{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof yi&&this.tagName==e.tagName&&cr(this.attributes,e.attributes)}static create(e){return new yi(e.tagName,e.attributes||fn)}static set(e,t=!1){return R.of(e,t)}}yi.prototype.startSide=yi.prototype.endSide=-1;function bi(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function Ps(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function fi(s,e){if(!e.anchorNode)return!1;try{return Ps(s,e.anchorNode)}catch{return!1}}function sn(s){return s.nodeType==3?xi(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ci(s,e,t,i){return t?no(s,e,t,i,-1)||no(s,e,t,i,1):!1}function ft(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function cn(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function no(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:Qe(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=ft(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?Qe(s):0}else return!1}}function Qe(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function un(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function kf(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 ql(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 Sf(s,e,t,i,n,r,o,l){let a=s.ownerDocument,h=a.defaultView||window;for(let f=s,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==a.body,p=1,m=1;if(d)u=kf(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let x=f.getBoundingClientRect();({scaleX:p,scaleY:m}=ql(f,x)),u={left:x.left,right:x.left+f.clientWidth*p,top:x.top,bottom:x.top+f.clientHeight*m}}let g=0,y=0;if(n=="nearest")e.top<u.top+o?(y=e.top-(u.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=e.top-(u.top+o)));else{let x=e.bottom-e.top,v=u.bottom-u.top;y=(n=="center"&&x<=v?e.top+x/2-v/2:n=="start"||n=="center"&&t<0?e.top-o:e.bottom-v+o)-u.top}if(i=="nearest"?e.left<u.left+r?(g=e.left-(u.left+r),t>0&&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.left<u.left+g&&(g=e.left-(u.left+r))):g=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,g||y)if(d)h.scrollBy(g,y);else{let x=0,v=0;if(y){let D=f.scrollTop;f.scrollTop+=y/m,v=(f.scrollTop-D)*m}if(g){let D=f.scrollLeft;f.scrollLeft+=g/p,x=(f.scrollLeft-D)*p}e={left:e.left-x,top:e.top-v,right:e.right-x,bottom:e.bottom-v},x&&Math.abs(x-g)<1&&(i="nearest"),v&&Math.abs(v-y)<1&&(n="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function Kl(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 Cf{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?Qe(t):0),i,Math.min(e.focusOffset,i?Qe(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let yt=null;k.safari&&k.safari_version>=26&&(yt=!1);function $l(s){if(s.setActive)return s.setActive();if(yt)return s.focus(yt);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(yt==null?{get preventScroll(){return yt={preventScroll:!0},!0}}:void 0),!yt){yt=!1;for(let t=0;t<e.length;){let i=e[t++],n=e[t++],r=e[t++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let so;function xi(s,e,t=e){let i=so||(so=document.createRange());return i.setEnd(s,t),i.setStart(s,e),i}function Wt(s,e,t,i){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Af(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Mf(s,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Qe(t));;)if(i){if(t.nodeType!=1)return!1;let n=t.childNodes[i-1];n.contentEditable=="false"?i--:(t=n,i=Qe(t))}else{if(t==s)return!0;i=ft(t),t=t.parentNode}}function jl(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Ul(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=Qe(t)}else if(t.parentNode&&!cn(t))i=ft(t),t=t.parentNode;else return null}}function Gl(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!cn(t))i=ft(t)+1,t=t.parentNode;else return null}}class Le{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Le(e.parentNode,ft(e),t)}static after(e,t){return new Le(e.parentNode,ft(e)+1,t)}}var j=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(j||(j={}));const Ct=j.LTR,ur=j.RTL;function Jl(s){let e=[];for(let t=0;t<s.length;t++)e.push(1<<+s[t]);return e}const Tf=Jl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Df=Jl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ns=Object.create(null),We=[];for(let s of["()","[]","{}"]){let e=s.charCodeAt(0),t=s.charCodeAt(1);Ns[e]=t,Ns[t]=-e}function _l(s){return s<=247?Tf[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?Df[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const Of=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ke{get dir(){return this.level%2?ur:Ct}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Yl(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++){let i=s[t],n=e[t];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Yl(i.inner,n.inner))return!1}return!0}const H=[];function Bf(s,e,t,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:n;for(let h=o,f=a,c=a;h<l;h++){let u=_l(s.charCodeAt(h));u==512?u=f:u==8&&c==4&&(u=16),H[h]=u==4?2:u,u&7&&(c=u),f=u}for(let h=o,f=a,c=a;h<l;h++){let u=H[h];if(u==128)h<l-1&&f==H[h+1]&&f&24?u=H[h]=f:H[h]=256;else if(u==64){let d=h+1;for(;d<l&&H[d]==64;)d++;let p=h&&f==8||d<t&&H[d]==8?c==1?1:8:256;for(let m=h;m<d;m++)H[m]=p;h=d-1}else u==8&&c==1&&(H[h]=1);f=u,u&7&&(c=u)}}}function Lf(s,e,t,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,f=o<i.length?i[o].from:t;for(let c=h,u,d,p;c<f;c++)if(d=Ns[u=s.charCodeAt(c)])if(d<0){for(let m=l-3;m>=0;m-=3)if(We[m+1]==-d){let g=We[m+2],y=g&2?n:g&4?g&1?r:n:0;y&&(H[c]=H[We[m]]=y),l=m;break}}else{if(We.length==189)break;We[l++]=c,We[l++]=u,We[l++]=a}else if((p=H[c])==2||p==1){let m=p==n;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=We[g+2];if(y&2)break;if(m)We[g+2]|=2;else{if(y&4)break;We[g+2]|=4}}}}}function Ef(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=n<t.length?t[n].from:e;for(let a=o;a<l;){let h=H[a];if(h==256){let f=a+1;for(;;)if(f==l){if(n==t.length)break;f=t[n++].to,l=n<t.length?t[n].from:e}else if(H[f]==256)f++;else break;let c=r==1,u=(f<e?H[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,m=n,g=m?t[m-1].to:s;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:s),H[--p]=d;a=f}else r=h,a++}}}function Ws(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=e,h=0;a<t;){let f=!0,c=!1;if(h==r.length||a<r[h].from){let m=H[a];m!=l&&(f=!1,c=m==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(c)break e;let m=r[h];if(!f)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<r.length&&r[y].from==g)g=r[y++].to;else{if(H[g]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new Ke(a,m.from,d));let g=m.direction==Ct!=!(d%2);Fs(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(f?H[p]!=l:H[p]==l))break;p++}u?Ws(s,a,p,i+1,n,u,o):a<p&&o.push(new Ke(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let f=!0,c=!1;if(!h||a>r[h-1].to){let m=H[a-1];m!=l&&(f=!1,c=m==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(c)break e;let m=r[--h];if(!f)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&r[y-1].to==g)g=r[--y].from;else{if(H[g-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new Ke(m.to,a,d));let g=m.direction==Ct!=!(d%2);Fs(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(f?H[p-1]!=l:H[p-1]==l))break;p--}u?Ws(s,p,a,i+1,n,u,o):p<a&&o.push(new Ke(p,a,d)),a=p}}function Fs(s,e,t,i,n,r,o){let l=e%2?2:1;Bf(s,n,r,i,l),Lf(s,n,r,i,l),Ef(n,r,i,l),Ws(s,n,r,e,t,i,o)}function Rf(s,e,t){if(!s)return[new Ke(0,0,e==ur?1:0)];if(e==Ct&&!t.length&&!Of.test(s))return Xl(s.length);if(t.length)for(;s.length>H.length;)H[H.length]=256;let i=[],n=e==Ct?0:1;return Fs(s,n,n,t,0,s.length,i),i}function Xl(s){return[new Ke(0,s,0)]}let Ql="";function If(s,e,t,i,n){var r;let o=i.head-s.from,l=Ke.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 f=te(s.text,o,a.forward(n,t));(f<a.from||f>a.to)&&(f=h),Ql=s.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return c&&f==h&&c.level+(n?0:1)<a.level?b.cursor(c.side(!n,t)+s.from,c.forward(n,t)?1:-1,c.level):b.cursor(f+s.from,a.forward(n,t)?-1:1,a.level)}function Pf(s,e,t){for(let i=e;i<t;i++){let n=_l(s.charCodeAt(i));if(n==1)return Ct;if(n==2||n==4)return ur}return Ct}const Zl=C.define(),ea=C.define(),ta=C.define(),ia=C.define(),Hs=C.define(),na=C.define(),sa=C.define(),dr=C.define(),pr=C.define(),ra=C.define({combine:s=>s.some(e=>e)}),Nf=C.define({combine:s=>s.some(e=>e)}),oa=C.define();class Ft{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 Ft(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 Ft(b.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Wi=N.define({map:(s,e)=>s.map(e)}),la=N.define();function we(s,e,t){let i=s.facet(ia);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 _e=C.define({combine:s=>s.length?s[0]:!0});let Wf=0;const Lt=C.define({combine(s){return s.filter((e,t)=>{for(let i=0;i<t;i++)if(s[i].plugin==e.plugin)return!1;return!0})}});class ce{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(Lt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Lt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=t||{};return new ce(Wf++,e,i,n,l=>{let a=[];return o&&a.push(Nn.of(h=>{let f=h.plugin(l);return f?o(f):L.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return ce.define((i,n)=>new e(i,n),t)}}class Yn{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(we(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){we(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){we(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const aa=C.define(),mr=C.define(),Nn=C.define(),ha=C.define(),gr=C.define(),Di=C.define(),fa=C.define();function ro(s,e){let t=s.state.facet(fa);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return R.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,f=o-e.from,c=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Pf(e.text,h,f)),a>0&&c.length&&(p=c[c.length-1]).to==h&&p.direction==d)p.to=f,c=p.inner;else{let m={from:h,to:f,direction:d,inner:[]};c.push(m),c=m.inner}}}}),n}const ca=C.define();function yr(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(ca)){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 oi=C.define();class Se{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Se(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let n=0,r=0,o=0;;){let l=n<e.length?e[n].fromB:1e9,a=r<t.length?t[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let f=h+o,c=h,u=f;for(;;)if(r<t.length&&t[r]<=c){let d=t[r+1];r+=2,c=Math.max(c,d);for(let p=n;p<e.length&&e[p].fromB<=c;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(n<e.length&&e[n].fromB<=c){let d=e[n++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new Se(f,u,h,c))}return i}}class dn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Q.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new Se(r,o,l,a))),this.changedRanges=n}static create(e,t,i){return new dn(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 Ff=[];class G{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Ff}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&&xf(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=ft(this.dom),n=this.length?e>0:t>0;return new Le(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 Fn)return e;return null}static get(e){return e.cmTile}}class Wn extends G{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,n,r=(e==null?void 0: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=oo(n);else t.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:t.firstChild,r&&n&&(r.written=!0);n;)n=oo(n);this.length=o}}function oo(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class Fn extends Wn{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=G.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let o=i.children[n++];if(o instanceof Ye)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)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,n=e-a),(h>e||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 Ye extends Wn{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 Ye(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class $t extends Wn{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new $t(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(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],m=d+p.length;m>=c&&(p.isComposite()?a(p,c-d):(!o||o.isHidden&&(t>0||i&&Vf(o,p)))&&(m>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(n=p,r=c-d)),d=m}}a(this,e);let h=(t<0?n:o)||n||o;return h?{tile:h,offset:h==n?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):Hf(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:n,offset:r}=i;if(this.dom.contains(n.dom))return n.isText()?new Le(n.dom,Math.min(n.dom.nodeValue.length,r)):n.domPosFor(r,n.flags&16?1:n.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new Le(a.dom,0);a==i.tile&&(l=!0)}}return new Le(this.dom,0)}}function Hf(s){let e=s.dom.lastChild;if(!e)return s.dom.getBoundingClientRect();let t=sn(e);return t[t.length-1]||null}function Vf(s,e){let t=s.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class de extends Wn{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new de(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class vt extends G{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?k.chrome||k.gecko||(e?(n--,o=1):r<i&&(r++,o=-1)):t<0?n--:r<i&&r++;let l=xi(this.dom,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return k.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?un(a,o<0):a||null}static of(e,t){let i=new vt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class At extends G{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return un(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.top<o.bottom);a+=l?-1:1);return un(o,!l)}}get overrideDOMText(){if(!this.length)return P.empty;let{root:e}=this;if(!e)return P.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new At(r,i,e,n)}}class pn extends G{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return P.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class zf{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(n.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==n.children.length){if(!e&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let a=n.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,e-=a.length):(l.push({tile:n,index:r}),n=a,r=0,i&&a.isComposite()&&i.enter(a))}else if(r==n.length)o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++;else if(e){let a=Math.min(e,n.length-r);i&&i.skip(n,r,r+a),e-=a,r+=a}else break;return this.tile=n,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class qf{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class Kf{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new vt(l.dom,l.text+e);a.parent=o}else o.append(n||vt.of(e,(r=this.cache.find(vt))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Xn(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=n.lastChild;if(h instanceof de&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(Xn(a.dom)),n=h;else{if(this.cache.reused.get(a)){let c=G.get(a.dom);c&&c.setDOM(Xn(a.dom))}let f=de.of(a.mark,a.dom);n.append(f),n=f}this.cache.reused.set(a,2)}let r=G.get(e.text);r&&this.cache.reused.set(r,2);let o=new vt(e.text,e.text.nodeValue);o.flags|=8,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=ua);let n=$t.start(e,t||((i=this.cache.find($t))===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 de&&l.mark.eq(o))n=l,t--;else{let a=de.of(o,(i=this.cache.find(de,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||!lo(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(k.ios&&lo(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Qn,0,32)||new At(Qn.toDOM(),0,Qn,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new qf(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof Ye&&n.wrapper.eq(i.wrapper))t=n;else{let r=Ye.of(i.wrapper,(e=this.cache.find(Ye,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(pn,void 0,1);return i&&(i.flags=t),i||new pn(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class $f{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 mn=[At,$t,vt,de,pn,Ye,Fn];for(let s=0;s<mn.length;s++)mn[s].bucket=s;class jf{constructor(e){this.view=e,this.buckets=mn.map(()=>[]),this.index=mn.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<o&&this.index[n]--,this.reused.set(h,i),h}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,o=0;;r++){if(r==n.length){if(o)return null;o=1,r=0}let l=n[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new At(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class Uf{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new jf(e),this.text=new $f(e.state.doc),this.builder=new Kf(this.cache,new Fn(e,e.contentDOM),R.iter(i)),this.cache.reused.set(t,2),this.old=new zf(t),this.reuseWalker={skip:(o,l,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=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>n){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<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,n=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=_f(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?At.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,n,r),r=n.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,n,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),n,r)),r=n.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof pn)this.cache.add(o);else if(o instanceof de)this.builder.ensureLine(null),this.builder.addMark(o,n,r),this.cache.reused.set(o,1),r=n.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof de&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof de&&(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=R.spans(this.decorations,e,t,{point:(l,a,h,f,c,u)=>{if(h instanceof St){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=f.length,c>f.length)n.continueWidget(a-l);else{let d=h.widget||(h.block?jt.block:jt.inline),p=Gf(h),m=this.cache.findWidget(d,a-l,p)||At.of(d,this.view,a-l,p);h.block?(h.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(m)):(n.ensureLine(i),n.addInlineWidget(m,f,c))}i=null}else i=Jf(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,f)=>{for(let c=l;c<a;){let u=this.text.next(Math.min(512,a-c));u==null?(n.addLineStartIfNotCovered(i),n.addBreak(),c++):(n.ensureLine(i),n.addText(u,h,c==l?f:h.length),c+=u.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let r=G.get(n);if(n==this.view.contentDOM)break;r instanceof de?t.push(r):r!=null&&r.isLine()?i=r:r instanceof Ye||(n.nodeName=="DIV"&&!i&&n!=this.view.contentDOM?i=new $t(n,ua):i||t.push(de.of(new Mi({tagName:n.nodeName.toLowerCase(),attributes:wf(n)}),n)))}return{line:i,marks:t}}}function lo(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 Gf(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 ua={class:"cm-line"};function Jf(s,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(s||(s={class:"cm-line"}),t&&fr(t,s),i&&(s.class+=" "+i)),s}function _f(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 de&&e.push(i.mark)}return e}function Xn(s){let e=G.get(s);return e&&e.setDOM(s.cloneNode()),s}class jt extends Ai{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}}jt.inline=new jt("span");jt.block=new jt("div");const Qn=new class extends Ai{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class ao{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=L.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 Fn(e,e.contentDOM),this.updateInner([new Se(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?n=this.domChanged.newSel.head:!sc(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Xf(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new Se(f,c,e.changes.mapPos(f,-1),e.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(k.ie||k.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=ec(o,this.decorations,e.changes);a.length&&(i=Se.extendWithRanges(i,a));let h=ic(l,this.blockWrappers,e.changes);return h.length&&(i=Se.extendWithRanges(i,h)),r&&!i.some(f=>f.fromA<=r.range.fromA&&f.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new Uf(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&G.get(t.text)&&l.cache.reused.set(G.get(t.text),2),this.tile=l.run(e,t),Vs(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=k.chrome||k.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof Zn&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(la)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,o=!r&&!(this.view.state.facet(_e)||i.tabIndex>-1)&&fi(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,f;if(a.empty?f=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(f=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),k.gecko&&a.empty&&!this.hasComposition&&Yf(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=f=new Le(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!ci(h.node,h.offset,c.anchorNode,c.anchorOffset)||!ci(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,a))&&(this.view.observer.ignore(()=>{k.android&&k.chrome&&i.contains(c.focusNode)&&nc(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=bi(this.view.root);if(u)if(a.empty){if(k.gecko){let d=Qf(h.node,h.offset);if(d&&d!=3){let p=(d==1?Ul:Gl)(h.node,h.offset);p&&(h=new Le(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(f.node,f.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,f]=[f,h]),d.setEnd(f.node,f.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,f)),this.impreciseAnchor=h.precise?null:new Le(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new Le(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ci(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=bi(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 f=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(f.node,f.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let n=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=Qe(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!G.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let 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,f)=>{if(h.isWidget()){if(h.flags&32&&f>=e)return!0;h.flags&16&&(r=!0)}else{let c=f+h.length;if(f<=e&&(i=h,n=e-f,r=c<e),c>=e&&!o&&(o=h,l=e-f,a=f>e),f>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 Zn?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()&&o<r.length){let l=te(r.text,o);if(l==o)return null;let a=xi(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let f=a[h];if(h==a.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return n(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==j.LTR,h=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>n);p++){let m=c.children[p],g=u+m.length,y=m.dom.getBoundingClientRect(),{height:x}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof Ye)g>i&&f(m,u,y);else if(u>=i&&(h>0&&t.push(-h),t.push(x+h),h=0,o)){let v=m.dom.lastChild,D=v?sn(v):[];if(D.length){let S=D[D.length-1],M=a?S.right-y.left:y.right-S.left;M>l&&(l=M,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=g)}}d&&p==c.children.length-1&&(h+=d.bottom-y.bottom),u=g+m.breakAfter}};return f(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 f=sn(h.dom);if(f.length!=1)return;l+=f[0].width,a=f[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=sn(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(L.replace({widget:new Zn(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return L.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Nn).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(gr).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(R.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ha).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(oa))try{if(f(this.view,e.range,e))return!0}catch(c){we(this.view.state,c,"scroll handler")}let{range:i}=e,n=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!n)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let o=yr(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(Sf(this.view.scrollDOM,l,i.head<i.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,a),-a),Math.max(Math.min(e.yMargin,h),-h),this.view.textDirection==j.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(i.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Vs(this.tile)}}function Vs(s,e){let t=e==null?void 0:e.get(s);if(t!=1){t==null&&s.destroy();for(let i of s.children)Vs(i,e)}}function Yf(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 da(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=Ul(t.focusNode,t.focusOffset),n=Gl(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=G.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=G.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 Xf(s,e,t){let i=da(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 Se(a.mapPos(r),a.mapPos(o),r,o),text:n}}function Qf(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e<s.childNodes.length&&s.childNodes[e].contentEditable=="false"?2:0)}let Zf=class{constructor(){this.changes=[]}compareRange(e,t){Nt(e,t,this.changes)}comparePoint(e,t){Nt(e,t,this.changes)}boundChange(e){Nt(e,e,this.changes)}};function ec(s,e,t){let i=new Zf;return R.compare(s,e,t,i),i.changes}class tc{constructor(){this.changes=[]}compareRange(e,t){Nt(e,t,this.changes)}comparePoint(){}boundChange(e){Nt(e,e,this.changes)}}function ic(s,e,t){let i=new tc;return R.compare(s,e,t,i),i.changes}function nc(s,e){for(let t=s;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function sc(s,e){let t=!1;return e&&s.iterChangedRanges((i,n)=>{i<e.to&&n>e.from&&(t=!0)}),t}class Zn extends Ai{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 rc(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return b.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=te(n.text,r,!1):l=te(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let h=te(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;l<n.length;){let h=te(n.text,l);if(i(n.text.slice(l,h))!=a)break;l=h}return b.range(o+n.from,l+n.from)}function oc(s,e,t,i,n){let r=Math.round((i-e.left)*s.defaultCharacterWidth);if(s.lineWrapping&&t.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,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+df(o,r,s.state.tabSize)}function lc(s,e,t){let i=s.lineBlockAt(e);if(Array.isArray(i.type)){let n;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!n||r.type==me.Text&&(n.type!=r.type||(t<0?r.from<e:r.to>e)))&&(n=r)}}return n||i}return i}function ac(s,e,t,i){let n=lc(s,e.head,e.assoc||-1),r=!i||n.type!=me.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 b.cursor(a,t?-1:1)}return b.cursor(t?n.to:n.from,t?-1:1)}function ho(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=If(n,r,o,l,t),f=Ql;if(!h){if(n.number==(t?s.state.doc.lines:1))return l;f=`
|
|
8
|
-
`,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),h=s.visualLineSide(n,!t)}if(a){if(!a(f))return l}else{if(!i)return h;a=i(f)}l=h}}function hc(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==_.Space&&(n=o),n==o}}function fc(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return b.cursor(n,e.assoc);let o=e.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(n,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),f=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)+f}let c=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=zs(s,{x:c,y:m},!1,r);if(t?m>a.bottom:m<a.top)return b.cursor(g.pos,g.assoc);let y=s.coordsAtPos(g.pos,g.assoc),x=y?(y.top+y.bottom)/2:0;if(!y||(t?x>l:x<l))return b.cursor(g.pos,g.assoc,void 0,o)}}function ui(s,e,t){for(;;){let i=0;for(let n of s)n.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function pa(s,e){let t=null;for(let i=0;i<e.ranges.length;i++){let n=e.ranges[i],r=null;if(n.empty){let o=ui(s,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=ui(s,n.from,-1),l=ui(s,n.to,1);(o!=n.from||l!=n.to)&&(r=b.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}function es(s,e,t){let i=ui(s.state.facet(Di).map(n=>n(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class qe{constructor(e,t){this.pos=e,this.assoc=t}}function zs(s,e,t,i){let n=s.contentDOM.getBoundingClientRect(),r=n.top+s.viewState.paddingTop,{x:o,y:l}=e,a=l-r,h;for(;;){if(a<0)return new qe(0,1);if(a>s.viewState.docHeight)return new qe(s.state.doc.length,-1);if(h=s.elementAtHeight(a),i==null)break;if(h.type==me.Text){if(i<0?h.to<s.viewport.from:h.from>s.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 c=s.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+c:h.top-c}if(s.viewport.from>=h.to||s.viewport.to<=h.from){if(t)return null;if(h.type==me.Text){let c=oc(s,n,h,o,l);return new qe(c,c==h.from?1:-1)}}if(h.type!=me.Text)return a<(h.top+h.bottom)/2?new qe(h.from,1):new qe(h.to,-1);let f=s.docView.lineAt(h.from,2);return(!f||f.length!=h.length)&&(f=s.docView.lineAt(h.from,-2)),new cc(s,o,l,s.textDirectionAt(h.from)).scanTile(f,h.from)}class cc{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Ke.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Ke.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t){let i=0,n=e.length-1,r=new Set,o=this.bidiIn(e[0],e[n]),l,a,h=-1,f=1e9,c;e:for(;i<n;){let d=n-i,p=i+n>>1;t:if(r.has(p)){let g=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!r.has(g)){p=g;break t}g++,g==n&&(g=i)}break e}r.add(p);let m=t(p);if(m)for(let g=0;g<m.length;g++){let y=m[g],x=0;if(!(y.width==0&&m.length>1)){if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),x=-1;else{let v=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,D=Math.abs(v);D<f&&(h=p,f=D,c=y),v&&(x=v<0==(this.baseDir==j.LTR)?-1:1)}x==-1&&(!o||this.baseDirAt(e[p],1))?n=p:x==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}}if(!c){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}if(f){if(l&&l.bottom>c.top)return this.y=l.bottom-1,this.scan(e,t);if(a&&a.top<c.bottom)return this.y=a.top+1,this.scan(e,t)}let u=(o?this.dirAt(e[h],1):this.baseDir)==j.LTR;return{i:h,after:this.x>(c.left+c.right)/2==u}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=te(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return xi(e.dom,o,l).getClientRects()});return n.after?new qe(i[n.i+1],-1):new qe(i[n.i],1)}scanTile(e,t){if(!e.length)return new qe(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<e.children.length;l++)i.push(a+=e.children[l].length);let n=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:xi(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 qe(i[n.i+1],-1):new qe(o,1)}}const Dt="";class uc{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(F.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Dt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=G.get(n),l=n.nextSibling;if(l==t){o!=null&&o.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=G.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:cn(n))||cn(l)&&(n.nodeName!="BR"||o!=null&&o.isWidget())&&this.text.length>r)&&!pc(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=G.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(dc(e,i.node,i.offset)?t:0))}}function dc(s,e,t){for(;;){if(!e||t<Qe(e))return!1;if(e==s)return!0;t=ft(e)+1,e=e.parentNode}}function pc(s,e){let t;for(;!(s==e||!s);s=s.nextSibling){let i=G.get(s);if(!(i!=null&&i.isWidget()))return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let n=i.overrideDOMText;if(n!=null&&n.length)return!1}return!0}class fo{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class mc{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=ma(e.docView.tile,t,i,0))){let a=r||o?[]:yc(e),h=new uc(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=bc(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!Ps(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),f=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!Ps(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),c=e.viewport;if((k.ios||k.chrome)&&l.main.empty&&h!=f&&(c.from>0||c.to<e.state.doc.length)){let u=Math.min(h,f),d=Math.max(h,f),p=c.from-u,m=c.to-d;(p==0||p==1||u==0)&&(m==0||m==-1||d==e.state.doc.length)&&(h=0,f=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(b.range(f,h));else if(e.lineWrapping&&f==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=b.create([b.cursor(h,d)])}else this.newSel=b.single(f,h)}}}function ma(s,e,t,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,f=i;a<s.children.length;a++){let c=s.children[a],u=h+c.length;if(h<e&&u>t)return ma(c,e,t,h);if(u>=e&&n==-1&&(n=a,r=h),h>t&&c.dom.parentNode==s.dom){o=a,l=f;break}f=u,h=u+c.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o<s.children.length&&o>=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function ga(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,f=null;(o===8||k.android&&e.text.length<a-l)&&(h=r.to,f="end");let c=n.doc.sliceString(l,a,Dt),u,d;!r.empty&&r.from>=l&&r.to<=a&&(e.typeOver||c!=e.text)&&c.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&c.slice(r.to-l)==e.text.slice(u=e.text.length-(c.length-(r.to-l)))?t={from:r.from,to:r.to,insert:P.of(e.text.slice(r.from-l,u).split(Dt))}:(d=ya(c,e.text,h-l,f))&&(k.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==Dt+Dt&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:P.of(e.text.slice(d.from,d.toB).split(Dt))})}else i&&(!s.hasFocus&&n.facet(_e)||gn(i,r))&&(i=null);if(!t&&!i)return!1;if((k.mac||k.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:P.of([t.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).to<r.to&&s.docView.lineHasWidget(r.to)&&s.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:k.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
|
|
9
|
-
`&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:P.of([" "])}),t)return br(s,t,i,o);if(i&&!gn(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=pa(n.facet(Di).map(h=>h(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function br(s,e,t,i=-1){if(k.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(k.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&&Wt(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>n.head)&&Wt(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&Wt(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=gc(s,e,t));return s.state.facet(na).some(a=>a(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function gc(s,e,t){let i,n=s.state,r=n.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let a=e.from<r.from?-1:1,h=a<0?r.from:r.to,f=ui(n.facet(Di).map(c=>c(s)),h,a);e.from==f&&(o=f)}if(o>-1)i={changes:e,selection:b.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&s.inputState.composing<0){let a=r.from<e.from?n.sliceDoc(r.from,e.from):"",h=r.to>e.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 f=s.state.sliceDoc(e.from,e.to),c,u=t&&da(s,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);c={from:u.from,to:u.to-p}}else c=s.state.doc.lineAt(r.head);let d=r.to-e.to;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-f.length;if(s.state.sliceDoc(g,m)!=f||m>=c.from&&g<=c.to)return{range:p};let y=n.changes({from:g,to:m,insert:e.insert}),x=p.to-r.to;return{changes:y,range:h?b.range(Math.max(0,h.anchor+x),Math.max(0,h.head+x)):p.map(y)}})}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 ya(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r<n&&s.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==n&&s.length==e.length)return null;let o=s.length,l=e.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&s.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function yc(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 fo(t,i)),(n!=t||r!=i)&&e.push(new fo(n,r))),e}function bc(s,e){if(s.length==0)return null;let t=s[0].pos,i=s.length==2?s[1].pos:t;return t>-1&&i>-1?b.single(t+e,i+e):null}function gn(s,e){return e.head==s.main.head&&e.anchor==s.main.anchor}class xc{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,k.safari&&e.contentDOM.addEventListener("input",()=>null),k.gecko&&Ic(e.contentDOM.ownerDocument)}handleEvent(e){!Tc(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=wc(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&&xa.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),k.android&&k.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return k.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=ba.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||vc.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Wt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:k.safari&&!k.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 co(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){we(t.state,n)}}}function wc(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(co(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(co(i.value,a))}}for(let i in Re)t(i).handlers.push(Re[i]);for(let i in ge)t(i).observers.push(ge[i]);return e}const ba=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],vc="dthko",xa=[16,17,18,20,91,92,224,225],Fi=6;function Hi(s){return Math.max(0,s)*.7+8}function kc(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class Sc{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=Kl(e.contentDOM),this.atoms=e.state.facet(Di).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(F.allowMultipleSelections)&&Cc(e,t),this.dragging=Mc(e,t)&&ka(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&&kc(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=yr(this.view);e.clientX-a.left<=n+Fi?t=-Hi(n-e.clientX):e.clientX+a.right>=o-Fi&&(t=Hi(e.clientX-o)),e.clientY-a.top<=r+Fi?i=-Hi(r-e.clientY):e.clientY+a.bottom>=l-Fi&&(i=Hi(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=pa(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 Cc(s,e){let t=s.state.facet(Zl);return t.length?t[0](e):k.mac?e.metaKey:e.ctrlKey}function Ac(s,e){let t=s.state.facet(ea);return t.length?t[0](e):k.mac?!e.altKey:!e.ctrlKey}function Mc(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=bi(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Tc(s,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=s.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Re=Object.create(null),ge=Object.create(null),wa=k.ie&&k.ie_version<15||k.ios&&k.webkit_version<604;function Dc(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(),va(s,t.value)},50)}function Hn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function va(s,e){e=Hn(s.state,dr,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(qs!=null&&t.selection.ranges.every(a=>a.empty)&&qs==r.toString()){let a=-1;i=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==a)return{range:h};a=f.from;let c=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:b.cursor(h.from+c.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:b.cursor(a.from+h.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}ge.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ge.wheel=ge.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};Re.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);ge.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")};ge.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Re.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(ta))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Bc(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new Sc(s,e,t,i)),i&&s.observer.ignore(()=>{$l(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 uo(s,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return rc(s.state,e,t);{let n=s.docView.lineAt(e,t),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,b.range(o,l)}}const Oc=k.ie&&k.ie_version<=11;let po=null,mo=0,go=0;function ka(s){if(!Oc)return s.detail;let e=po,t=go;return po=s,go=Date.now(),mo=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(mo+1)%3:1}function Bc(s,e){let t=s.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=ka(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,f=uo(s,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let c=uo(s,t.pos,t.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?b.range(u,d,f.assoc):b.range(d,u,f.assoc)}return o?n.replaceRange(n.main.extend(f.from,f.to,f.assoc)):l&&i==1&&n.ranges.length>1&&(h=Lc(n,a.pos))?h:l?n.addRange(f):b.create([f])}}}function Lc(s,e){for(let t=0;t<s.ranges.length;t++){let{from:i,to:n}=s.ranges[t];if(i<=e&&n>=e)return b.create(s.ranges.slice(0,t).concat(s.ranges.slice(t+1)),s.mainIndex==t?0:s.mainIndex-(s.mainIndex>t?1:0))}return null}Re.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.tile.nearest(e.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Hn(s.state,pr,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Re.dragend=s=>(s.inputState.draggedContent=null,!1);function yo(s,e,t,i){if(t=Hn(s.state,dr,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Ac(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}Re.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&&yo(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return yo(s,e,i,!0),!0}return!1};Re.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=wa?null:e.clipboardData;return t?(va(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Dc(s),!1)};function Ec(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 Rc(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:Hn(s,pr,e.join(s.lineBreak)),ranges:t,linewise:i}}let qs=null;Re.copy=Re.cut=(s,e)=>{if(!fi(s.contentDOM,s.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:n}=Rc(s.state);if(!t&&!n)return!1;qs=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=wa?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Ec(s,t),!1)};const Sa=Ze.define();function Ca(s,e){let t=[];for(let i of s.facet(sa)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:Sa.of(!0)}):null}function Aa(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Ca(s.state,e);t?s.dispatch(t):s.update([])}},10)}ge.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),Aa(s)};ge.blur=s=>{s.observer.clearSelectionRange(),Aa(s)};ge.compositionstart=ge.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};ge.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,k.chrome&&k.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};ge.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Re.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 br(s,{from:a,to:h,insert:s.state.toText(r)},null),!0}}let n;if(k.chrome&&k.android&&(n=ba.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 k.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),k.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>ge.compositionend(s,e),20),!1};const bo=new Set;function Ic(s){bo.has(s)||(bo.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const xo=["pre-wrap","normal","pre-line","break-spaces"];let Ut=!1;function wo(){Ut=!1}class Pc{constructor(e){this.lineWrapping=e,this.doc=P.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 xo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(t=!0,this.heightSamples[Math.floor(n*10)]=!0)}return t}refresh(e,t,i,n,r,o){let l=xo.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let f=o[h];f<0?h++:this.heightSamples[Math.floor(f*10)]=!0}}return a}}class Nc{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Be{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?me.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof St?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Be(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var q=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})(q||(q={}));const rn=.001;class fe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>rn&&(Ut=!0),this.height=e)}replace(e,t,i){return fe.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:f,toB:c}=n[l],u=r.lineAt(a,q.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,q.ByPosNoHeight,i,0,0);for(c+=d.to-h,h=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,f=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,q.ByPosNoHeight,i,0,0));f+=u.from-a,a=u.from;let p=xr.build(i.setDoc(o),e,f,c);r=yn(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new xe(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=e[t++];l&&(n+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Fc(fe.of(e.slice(0,t)),o,fe.of(e.slice(i)))}}function yn(s,e){return s==e?s:(s.constructor!=e.constructor&&(Ut=!0),e)}fe.prototype.size=1;const Wc=L.replace({});class Ma extends fe{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new Be(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new Be(n,0,i,this.spaceAbove,Wc):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let o=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(o):o}forEachLine(e,t,i,n,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,q.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 xe extends Ma{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 Be(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 xe||n instanceof ne&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof ne?n=new xe(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):fe.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 ne extends fe{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+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),f=t.doc.lineAt(h),c=l+f.length*a,u=Math.max(i,e-c/2);return new Be(f.from,f.length,u,c,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:f,length:c}=t.doc.line(r+h);return new Be(f,c,i+l*h,l,0)}}lineAt(e,t,i,n,r){if(t==q.ByHeight)return this.blockAt(e,i,n,r);if(t==q.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Be(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),f=l+h.length*a,c=h.number-o,u=n+l*c+a*(h.from-r-c);return new Be(h.from,h.length,Math.max(n,Math.min(u,n+this.height-f)),f,0)}forEachLine(e,t,i,n,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let f=e,c=n;f<=t;){let u=i.doc.lineAt(f);if(f==e){let p=u.number-l;c+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new Be(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let r=i[i.length-1];r instanceof ne?i[i.length-1]=new ne(r.length+n):i.push(null,new ne(n-1))}if(e>0){let r=i[0];r instanceof ne?i[0]=new ne(e+r.length):i.unshift(new ne(e-1),null)}return fe.of(i)}decomposeLeft(e,t){t.push(new ne(e-1),null)}decomposeRight(e,t){t.push(null,new ne(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 ne(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++],u=0;c<0&&(u=-c,c=n.heights[n.index++]),a==-1?a=c:Math.abs(c-a)>=rn&&(a=-2);let d=new xe(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new ne(r-l).updateHeight(e,l));let h=fe.of(o);return(a<0||Math.abs(h.height-this.height)>=rn||Math.abs(a-this.heightMetrics(e,t).perLine)>=rn)&&(Ut=!0),yn(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 Fc extends fe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=t==q.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let f=t==q.ByPosNoHeight?q.ByPosNoHeight:q.ByPos;return a?h.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,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.left.forEachLine(e,t,i,n,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,q.ByPos,i,n,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,n,r,o),h.to>=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(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&vo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),vo(r,l)}return fe.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fe.of(this.break?[e,null,t]:[e,t]):(this.left=yn(this.left,e),this.right=yn(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 vo(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof ne&&(i=s[e+1])instanceof ne&&s.splice(e-1,3,new ne(t.length+1+i.length))}const Hc=5;class xr{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 xe?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new xe(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Ma(o,n,i)):(o||r||n>=Hc)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new xe(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new ne(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 xe)return e;let t=new xe(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 xe)&&!this.isCovered?this.nodes.push(new xe(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let n of this.nodes)n instanceof xe&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new xr(i,e);return R.spans(t,i,n,r,0),r.finish(i)}}function Vc(s,e,t){let i=new zc;return R.compare(s,e,t,i,0),i.changes}class zc{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&Nt(e,t,this.changes,5)}}function qc(s,e){let t=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(n.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(n.innerHeight,t.bottom);for(let h=s.parentNode;h&&h!=i.body;)if(h.nodeType==1){let f=h,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==s.parentNode?n.innerHeight:a,u.bottom)}h=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.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 Kc(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function $c(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class ts{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return L.replace({widget:new jc(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class jc extends Ai{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class ko{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=So,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=j.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet(mr).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Pc(i),this.stateDeco=Co(t),this.heightMap=fe.empty().applyChanges(this.stateDeco,P.empty,this.heightOracle.setDoc(t.doc),[new Se(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=L.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 Vi(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?So:new wr(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(li(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=Co(this.state);let n=e.changedRanges,r=Se.extendWithRanges(n,Vc(i,this.stateDeco,e?e.changes:Q.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);wo(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Ut)&&(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.head<a.from||t.range.head>a.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(Nf)&&(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,f=0;if(l.width&&l.height){let{scaleX:S,scaleY:M}=ql(t,l);(S>.005&&Math.abs(this.scaleX-S)>.005||M>.005&&Math.abs(this.scaleY-M)>.005)&&(this.scaleX=S,this.scaleY=M,h|=16,o=a=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=Kl(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=jl(this.scrollParent||e.win);let m=(this.printing?$c:qc)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let x=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(x!=this.inView&&(this.inView=x,x&&(a=!0)),!this.inView&&!this.scrollTarget&&!Kc(e.dom))return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let S=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(S)&&(o=!0),o||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:M,charWidth:A,textHeight:W}=e.docView.measureTextSize();o=M>0&&n.refresh(r,M,A,W,Math.max(5,v/A),S),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?f=Math.max(g,y):g<0&&y<0&&(f=Math.min(g,y)),wo();for(let M of this.viewports){let A=M.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(M);this.heightMap=(o?fe.empty().applyChanges(this.stateDeco,P.empty,this.heightOracle,[new Se(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Nc(M.from,A))}Ut&&(h|=2)}let D=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return D&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),h|=this.updateForViewport()),(h&2||D)&&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 Vi(n.lineAt(o-i*1e3,q.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,q.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(h,q.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=c.top:u=c.bottom-f,a=new Vi(n.lineAt(u-1e3/2,q.ByHeight,r,0,0).from,n.lineAt(u+f+1e3/2,q.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new Vi(this.heightMap.lineAt(i,q.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,q.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,q.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,q.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||n<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new ts(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=j.LTR&&!i)return[];let l=[],a=(f,c,u,d)=>{if(c-f<r)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>f&&y<c){a(f,y-10,u,d),a(y+10,c,u,d);return}let g=Gc(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-f)<r&&Math.abs(y.to-c)<r&&!m.some(x=>y.from<x&&y.to>x));if(!g){if(c<u.to&&t&&i&&t.visibleRanges.some(v=>v.from<=c&&v.to>=c)){let v=t.moveToLineBoundary(b.cursor(c),!1,!0).head;v>f&&(c=v)}let y=this.gapSize(u,f,c,d),x=i||y<2e6?y:2e6;g=new ts(f,c,y,x)}l.push(g)},h=f=>{if(f.length<o||f.type!=me.Text)return;let c=Uc(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(u!=null){let x=qi(c,u),v=((this.visibleBottom-this.visibleTop)/2+m)/f.height;g=x-v,y=x+v}else g=(this.visibleTop-f.top-m)/f.height,y=(this.visibleBottom-f.top+m)/f.height;d=zi(c,g),p=zi(c,y)}else{let m=c.total*this.heightOracle.charWidth,g=n*this.heightOracle.charWidth,y=0;if(m>2e6)for(let M of e)M.from>=f.from&&M.from<f.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=M.size-M.displaySize);let x=this.pixelViewport.left+y,v=this.pixelViewport.right+y,D,S;if(u!=null){let M=qi(c,u),A=((v-x)/2+g)/m;D=M-A,S=M+A}else D=(x-g)/m,S=(v+g)/m;d=zi(c,D),p=zi(c,S)}d>f.from&&a(f.from,d,f,c),p<f.to&&a(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(h):h(f);return l}gapSize(e,t,i,n){let r=qi(n,i)-qi(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){ts.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=L.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];R.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(n&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(n|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||li(this.heightMap.lineAt(e,q.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)||li(this.heightMap.lineAt(this.scaler.fromDOM(e),q.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 li(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 Vi{constructor(e,t){this.from=e,this.to=t}}function Uc(s,e,t){let i=[],n=s,r=0;return R.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<e&&(i.push({from:n,to:e}),r+=e-n),{total:r,ranges:i}}function zi({total:s,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(s*t);for(let n=0;;n++){let{from:r,to:o}=e[n],l=o-r;if(i<=l)return r+i;i-=l}}function qi(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 Gc(s,e){for(let t of s)if(e(t))return t}const So={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function Co(s){let e=s.facet(Nn).filter(i=>typeof i!="function"),t=s.facet(gr).filter(i=>typeof i!="function");return t.length&&e.push(R.join(t)),e}class wr{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,q.ByPos,e,0,0).top,f=t.lineAt(a,q.ByPos,e,0,0).bottom;return n+=f-h,{from:l,to:a,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof wr?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function li(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new Be(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>li(n,e)):s._content)}const Ki=C.define({combine:s=>s.join(" ")}),Ks=C.define({combine:s=>s.indexOf(!0)>-1}),$s=at.newName(),Ta=at.newName(),Da=at.newName(),Oa={"&light":"."+Ta,"&dark":"."+Da};function js(s,e,t){return new at(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 Jc=js("."+$s,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Oa),_c={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},is=k.ie&&k.ie_version<=11;class Yc{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Cf,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);(k.ie&&k.ie_version<=11||k.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&&k.android&&e.constructor.EDIT_CONTEXT!==!1&&!(k.chrome&&k.chrome_version<126)&&(this.editContext=new Qc(e),e.state.facet(_e)&&(e.contentDOM.editContext=this.editContext.editContext)),is&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(_e)?i.root.activeElement!=this.dom:!fi(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}(k.ie&&k.ie_version<=11||k.android&&k.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ci(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=bi(e.root);if(!t)return!1;let i=k.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Xc(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=fi(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Mf(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,_c),is&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),is&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Wt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&fi(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 mc(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=ga(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!gn(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=Ao(t,e.previousSibling||e.target.previousSibling,-1),n=Ao(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(_e)!=e.state.facet(_e)&&(e.view.contentDOM.editContext=e.state.facet(_e)?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 Ao(s,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==s)return i;let n=e.parentNode;e=n!=s.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function Mo(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 ci(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function Xc(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return Mo(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?Mo(s,t):null}class Qc{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let n=e.state.selection.main,{anchor:r,head:o}=n,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let f=ya(e.state.sliceDoc(l,a),i.text,(h?n.from:n.to)-l,h?"end":null);if(!f){let u=b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));gn(u,n)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:P.of(i.text.slice(f.from,f.toB).split(`
|
|
10
|
-
`))};if((k.mac||k.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:a,insert:P.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!e.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);br(e,c,b.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),c.from<c.to&&!c.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,n.push(r)}t.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;n.push(L.mark({attributes:{style:f}}).range(a,h))}}}e.dispatch({effects:la.of(L.set(n))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=bi(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 f=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+=f,this.to+=f;return}else n=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=f,this.to+=f;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=f}t+=f}),n&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(n=>!n.isUserEvent("input.type")&&n.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),n=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class T{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||Af(e.parent)||document,this.viewState=new ko(this,e.state||F.create(e)),e.scrollTo&&e.scrollTo.is(Wi)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Lt).map(n=>new Yn(n));for(let n of this.plugins)n.update(this);this.observer=new Yc(this),this.inputState=new xc(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ao(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 Y?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(Sa))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Ca(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(f=null)):this.observer.clear(),r.facet(F.phrases)!=this.state.facet(F.phrases))return this.setState(r);n=dn.create(this,r,e),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(T.cursorScrollMargin);c=new Ft(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(Wi)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=bn.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(oi)!=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(Ki)!=n.state.facet(Ki)&&(this.viewState.mustMeasureContent=!0),(t||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Hs))try{u(n)}catch(d){we(this.state,d,"update listener")}(a||f)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),f&&!ga(this,f)&&h.force&&Wt(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 ko(this,e),this.plugins=e.facet(Lt).map(i=>new Yn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new ao(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(Lt),i=e.state.facet(Lt);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new Yn(r));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){we(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(jl(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 f=h.map(d=>{try{return d.read(this)}catch(p){return we(this.state,p),To}}),c=dn.create(this,this.state,[]),u=!1;c.flags|=a,t?t.flags|=a:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<h.length;d++)if(f[d]!=To)try{let p=h[d];p.write&&p.write(f[d],this)}catch(p){we(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o)/this.scaleY;if((p>1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n=n+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Hs))l(t)}get themeClasses(){return $s+" "+(this.state.facet(Ks)?Da:Ta)+" "+this.state.facet(Ki)}updateAttrs(){let e=Do(this,aa,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(_e)?"true":"false",class:"cm-content",style:`${k.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Do(this,mr,t);let i=this.observer.ignore(()=>{let n=io(this.contentDOM,this.contentAttrs,t),r=io(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(T.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(oi);let e=this.state.facet(T.cspNonce);at.mount(this.root,this.styleModules.concat(Jc).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return es(this,e,ho(this,e,t,i))}moveByGroup(e,t){return es(this,e,ho(this,e,t,i=>hc(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return b.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return ac(this,e,t,i)}moveVertically(e,t,i){return es(this,e,fc(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=zs(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),zs(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[Ke.find(r,e-n.from,-1,t)];return un(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(ra)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Zc)return Xl(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||Yl(r.isolates,i=ro(this,e))))return r.order;i||(i=ro(this,e));let n=Rf(e.text,t,i);return this.bidiCache.push(new bn(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||k.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{$l(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 Wi.of(new Ft(typeof e=="number"?b.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(n=t.x)!==null&&n!==void 0?n:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Wi.of(new Ft(b.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return ce.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return ce.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=at.newName(),n=[Ki.of(i),oi.of(js(`.${i}`,e))];return t&&t.dark&&n.push(Ks.of(!0)),n}static baseTheme(e){return Mt.lowest(oi.of(js("."+$s,e,Oa)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&G.get(i)||G.get(e);return((t=n==null?void 0:n.root)===null||t===void 0?void 0:t.view)||null}}T.styleModule=oi;T.inputHandler=na;T.clipboardInputFilter=dr;T.clipboardOutputFilter=pr;T.scrollHandler=oa;T.focusChangeEffect=sa;T.perLineTextDirection=ra;T.exceptionSink=ia;T.updateListener=Hs;T.editable=_e;T.mouseSelectionStyle=ta;T.dragMovesSelection=ea;T.clickAddsSelectionRange=Zl;T.decorations=Nn;T.blockWrappers=ha;T.outerDecorations=gr;T.atomicRanges=Di;T.bidiIsolatedRanges=fa;T.cursorScrollMargin=C.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}}});T.scrollMargins=ca;T.darkTheme=Ks;T.cspNonce=C.define({combine:s=>s.length?s[0]:""});T.contentAttributes=mr;T.editorAttributes=aa;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=N.define();const Zc=4096,To={};class bn{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<e.length;r++){let o=e[r];o.dir==n&&!t.touchesRange(o.from,o.to)&&i.push(new bn(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Do(s,e,t){for(let i=s.state.facet(e),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&fr(o,t)}return t}const eu=k.mac?"mac":k.windows?"win":k.linux?"linux":"key";function tu(s,e){const t=s.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))n=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function $i(s,e,t){return e.altKey&&(s="Alt-"+s),e.ctrlKey&&(s="Ctrl-"+s),e.metaKey&&(s="Meta-"+s),t!==!1&&e.shiftKey&&(s="Shift-"+s),s}const iu=Mt.default(T.domEventHandlers({keydown(s,e){return La(Ba(e.state),s,e,"editor")}})),vr=C.define({enables:iu}),Oo=new WeakMap;function Ba(s){let e=s.facet(vr),t=Oo.get(e);return t||Oo.set(e,t=ru(e.reduce((i,n)=>i.concat(n),[]))),t}function nu(s,e,t){return La(Ba(s.state),e,s,t)}let st=null;const su=4e3;function ru(s,e=eu){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,f)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>tu(y,e));for(let y=1;y<p.length;y++){let x=p.slice(0,y).join(" ");n(x,!0),d[x]||(d[x]={preventDefault:!0,stopPropagation:!1,run:[v=>{let D=st={view:v,prefix:x,scope:o};return setTimeout(()=>{st==D&&(st=null)},su),!0}]})}let m=p.join(" ");n(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),f&&(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 f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in f)f[u].run.push(d=>c(d,Us))}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 Us=null;function La(s,e,t,i){Us=e;let n=yf(e),r=tt(n,0),o=bt(r)==n.length&&n!=" ",l="",a=!1,h=!1,f=!1;st&&st.view==t&&st.scope==i&&(l=st.prefix+" ",xa.indexOf(e.keyCode)<0&&(h=!0,st=null));let c=new Set,u=g=>{if(g){for(let y of g.run)if(!c.has(y)&&(c.add(y),y(t)))return g.stopPropagation&&(f=!0),!0;g.preventDefault&&(g.stopPropagation&&(f=!0),h=!0)}return!1},d=s[i],p,m;return d&&(u(d[l+$i(n,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(k.windows&&e.ctrlKey&&e.altKey)&&!(k.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ht[e.keyCode])&&p!=n?(u(d[l+$i(p,e,!0)])||e.shiftKey&&(m=gi[e.keyCode])!=n&&m!=p&&u(d[l+$i(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+$i(n,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&f&&e.stopPropagation(),Us=null,a}function jm(){return lu}const ou=L.line({class:"cm-activeLine"}),lu=ce.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(ou.range(n.from)),e=n.from)}return L.set(t)}},{decorations:s=>s.decorations}),ji="-10000px";class au{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;a<r.length;a++){let h=r[a],f=-1;if(h){for(let c=0;c<this.tooltips.length;c++){let u=this.tooltips[c];u&&u.create==h.create&&(f=c)}if(f<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let c=o[a]=this.tooltipViews[f];l&&(l[a]=t[f]),c.update&&c.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function hu(s){let e=s.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const ns=C.define({combine:s=>{var e,t,i;return{position:k.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)||hu}}}),Bo=new WeakMap,Ea=ce.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(ns);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 au(s,Ra,(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(ns);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=ji,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(k.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=yr(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(ns).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<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:f}=h,c=s.pos[l],u=s.size[l];if(!c||a.clip!==!1&&(c.bottom<=Math.max(t.top,i.top)||c.top>=Math.min(t.bottom,i.bottom)||c.right<Math.max(t.left,i.left)-.1||c.left>Math.min(t.right,i.right)+.1)){f.style.top=ji;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=Bo.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||cu,x=this.view.textDirection==j.LTR,v=u.width>i.right-i.left?x?i.left:i.right-u.width:x?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,c.left-m+(d?14:0)-y.x),i.right-m),D=this.above[l];!a.strictSide&&(D?c.top-g-p-y.y<i.top:c.bottom+g+p+y.y>i.bottom)&&D==i.bottom-c.bottom>c.top-i.top&&(D=this.above[l]=!D);let S=(D?c.top-i.top:i.bottom-c.bottom)-p;if(S<g&&h.resize!==!1){if(S<this.view.defaultLineHeight){f.style.top=ji;continue}Bo.set(h,g),f.style.height=(g=S)/r+"px"}else f.style.height&&(f.style.height="");let M=D?c.top-g-p-y.y:c.bottom+p+y.y,A=v+m;if(h.overlap!==!0)for(let W of o)W.left<A&&W.right>v&&W.top<M+g&&W.bottom>M&&(M=D?W.top-g-2-p:W.bottom+p+2);if(this.position=="absolute"?(f.style.top=(M-s.parent.top)/r+"px",Lo(f,(v-s.parent.left)/n)):(f.style.top=M/r+"px",Lo(f,v/n)),d){let W=c.left+(x?y.x:-y.x)-(v+14-7);d.style.left=W/n+"px"}h.overlap!==!0&&o.push({left:v,top:M,right:A,bottom:M+g}),f.classList.toggle("cm-tooltip-above",D),f.classList.toggle("cm-tooltip-below",!D),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=ji}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Lo(s,e){let t=parseInt(s.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(s.style.left=e+"px")}const fu=T.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"}}}),cu={x:0,y:0},Ra=C.define({enables:[Ea,fu]});function Ia(s,e){let t=s.plugin(Ea);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Eo=C.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 Pa(s,e){let t=s.plugin(Na),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Na=ce.fromClass(class{constructor(s){this.input=s.state.facet(xn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(s));let e=s.state.facet(Eo);this.top=new Ui(s,!0,e.topContainer),this.bottom=new Ui(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(Eo);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Ui(s.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ui(s.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=s.state.facet(xn);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),f;h<0?(f=a(s.view),l.push(f)):(f=this.panels[h],f.update&&f.update(s)),n.push(f),(f.top?r:o).push(f)}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=>T.scrollMargins.of(e=>{let t=e.plugin(s);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Ui{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=Ro(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Ro(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 Ro(s){let e=s.nextSibling;return s.remove(),e}const xn=C.define({enables:Na});function uu(s,e){let t,i=new Promise(o=>t=o),n=o=>du(o,e,t);s.state.field(ss,!1)?s.dispatch({effects:Wa.of(n)}):s.dispatch({effects:N.appendConfig.of(ss.init(()=>[n]))});let r=Fa.of(n);return{close:r,result:i.then(o=>((s.win.queueMicrotask||(a=>s.win.setTimeout(a,10)))(()=>{s.state.field(ss).indexOf(n)>-1&&s.dispatch({effects:r})}),o))}}const ss=De.define({create(){return[]},update(s,e){for(let t of e.effects)t.is(Wa)?s=[t.value].concat(s):t.is(Fa)&&(s=s.filter(i=>i!=t.value));return s},provide:s=>xn.computeN([s],e=>e.field(s))}),Wa=N.define(),Fa=N.define();function du(s,e,t){let i=e.content?e.content(s,()=>o(null)):null;if(!i){if(i=Z("form"),e.input){let l=Z("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(Z("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(Z("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let n=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<n.length;l++){let a=n[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=Z("div",i,Z("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 ct extends lt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}ct.prototype.elementClass="";ct.prototype.toDOM=void 0;ct.prototype.mapMode=he.TrackBefore;ct.prototype.startSide=ct.prototype.endSide=-1;ct.prototype.point=!0;const on=C.define(),pu=C.define(),mu={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>R.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},di=C.define();function Um(s){return[Ha(),di.of({...mu,...s})]}const Io=C.define({combine:s=>s.some(e=>e)});function Ha(s){return[gu]}const gu=ce.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(di).map(e=>new No(s,e)),this.fixed=!s.state.facet(Io);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(Io)!=!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=R.iter(this.view.state.facet(on),this.view.viewport.from),i=[],n=this.gutters.map(r=>new yu(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==me.Text&&o){Gs(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==me.Text){Gs(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(di),t=s.state.facet(di),i=s.docChanged||s.heightChanged||s.viewportChanged||!R.eq(s.startState.facet(on),s.state.facet(on),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 No(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=>T.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 Po(s){return Array.isArray(s)?s:[s]}function Gs(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class yu{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=R.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 Va(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=[];Gs(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(pu)){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 No{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=Po(t.markers(e)),t.initialSpacer&&(this.spacer=new Va(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=Po(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!R.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 Va{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":""),bu(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=r<t.length?t[r++]:null,h=!1;if(a){let f=a.elementClass;f&&(i+=" "+f);for(let c=o;c<this.markers.length;c++)if(this.markers[c].compare(a)){l=c,h=!0;break}}else l=this.markers.length;for(;o<l;){let f=this.markers[o++];if(f.toDOM){f.destroy(n);let c=n.nextSibling;n.remove(),n=c}}if(!a)break;a.toDOM&&(h?n=n.nextSibling:this.dom.insertBefore(a.toDOM(e),n)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function bu(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(!s[t].compare(e[t]))return!1;return!0}const xu=C.define(),wu=C.define(),Et=C.define({combine(s){return Yt(s,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let r=i[n],o=t[n];i[n]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class rs extends ct{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function os(s,e){return s.state.facet(Et).formatNumber(e,s.state)}const vu=di.compute([Et],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(xu)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new rs(os(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(wu)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Et)!=e.state.facet(Et),initialSpacer(e){return new rs(os(e,Wo(e.state.doc.lines)))},updateSpacer(e,t){let i=os(t.view,Wo(t.view.state.doc.lines));return i==e.number?e:new rs(i)},domEventHandlers:s.facet(Et).domEventHandlers,side:"before"}));function Gm(s={}){return[Et.of(s),Ha(),vu]}function Wo(s){let e=9;for(;e<s;)e=e*10+9;return e}const ku=new class extends ct{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Su=on.compute(["selection"],s=>{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(ku.range(n)))}return R.of(e)});function Jm(){return Su}const Cu=1024;let Au=0;class Ce{constructor(e,t){this.from=e,this.to=t}}class E{constructor(e={}){this.id=Au++,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=ye.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}E.closedBy=new E({deserialize:s=>s.split(" ")});E.openedBy=new E({deserialize:s=>s.split(" ")});E.group=new E({deserialize:s=>s.split(" ")});E.isolate=new E({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});E.contextHash=new E({perNode:!0});E.lookAhead=new E({perNode:!0});E.mounted=new E({perNode:!0});class Ht{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[E.mounted.id]}}const Mu=Object.create(null);class ye{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):Mu,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new ye(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(E.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(E.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}ye.none=new ye("",Object.create(null),0,8);class za{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let r of e){let o=r(i);if(o){n||(n=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in n&&(l=a.combine(n[a.id],l)),n[a.id]=l}}t.push(n?new ye(i.name,n,i.id,i.flags):i)}return new za(t)}}const Gi=new WeakMap,Fo=new WeakMap;var V;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(V||(V={}));class X{constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Ht.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new wn(this.topNode,e)}cursorAt(e,t=0,i=0){let n=Gi.get(this)||this.topNode,r=new wn(n);return r.moveTo(e,t),Gi.set(this,r._tree),r}get topNode(){return new oe(this,0,0,null)}resolve(e,t=0){let i=wi(Gi.get(this)||this.topNode,e,t,!1);return Gi.set(this,i),i}resolveInner(e,t=0){let i=wi(Fo.get(this)||this.topNode,e,t,!0);return Fo.set(this,i),i}resolveStack(e,t=0){return Ou(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,o=e.mode||0,l=(o&V.IncludeAnonymous)>0;for(let a=this.cursor(o|V.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:Cr(ye.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new X(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new X(ye.none,t,i,n)))}static build(e){return Bu(e)}}X.empty=new X(ye.none,[],[],0);class kr{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 kr(this.buffer,this.index)}}class ut{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ye.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,n,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(qa(r,n,o[a+1],o[a+2])&&(l=a,i>0));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<t;){r[a++]=n[l++],r[a++]=n[l++]-i;let h=r[a++]=n[l++]-i;r[a++]=n[l++]-e,o=Math.max(o,h)}return new ut(r,o,this.set)}}function qa(s,e,t,i){switch(s){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function wi(s,e,t,i){for(var n;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let o=!i&&s instanceof oe&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:V.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof oe&&o.index<0&&((n=l.enter(e,t,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(e,t,r);if(!o)return s;s=o}}class Ka{cursor(e=0){return new wn(this,e)}getChild(e,t=null,i=null){let n=Ho(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Ho(this,e,t,i)}resolve(e,t=0){return wi(this,e,t,!1)}resolveInner(e,t=0){return wi(this,e,t,!0)}matchContext(e){return Js(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}get node(){return this}get next(){return this.parent}}class oe extends Ka{constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let f=l[e],c=a[e]+o.from,u;if(!(!(r&V.EnterBracketed&&f instanceof X&&(u=Ht.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!qa(n,i,c,c+f.length))){if(f instanceof ut){if(r&V.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,t,i-c,n);if(d>-1)return new $e(new Tu(o,f,e,c),null,d)}else if(r&V.IncludeAnonymous||!f.type.isAnonymous||Sr(f)){let d;if(!(r&V.IgnoreMounts)&&(d=Ht.get(f))&&!d.overlay)return new oe(d.tree,c,e,o);let p=new oe(f,c,e,o);return r&V.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?f.children.length-1:0,t,i,n,r)}}}if(r&V.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&V.IgnoreOverlays)&&(n=Ht.get(this._tree))&&n.overlay){let r=e-this.from,o=i&V.EnterBracketed&&n.bracketed;for(let{from:l,to:a}of n.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new oe(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 Ho(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 Js(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 Tu{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class $e extends Ka{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 $e(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&V.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 $e(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 $e(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 $e(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 X(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function $a(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof oe&&t.index<0?null:t.parent,n=s.slice();return i?n[e]=i:n.splice(e,1),new Du(n,t)}class Du{constructor(e,t){this.heads=e,this.node=t}get next(){return $a(this.heads)}}function Ou(s,e,t){let i=s.resolveInner(e,t),n=null;for(let r=i instanceof oe?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(e,t)),r=o}else{let o=Ht.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new oe(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(wi(l,e,t,!1))}}return n?$a(n):i}class wn{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&~V.EnterBracketed,e instanceof oe)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 oe?(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&V.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&V.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&V.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(n.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&V.IncludeAnonymous||l instanceof ut||!l.type.isAnonymous||Sr(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new $e(this.buffer,t,this.stack[n]);return this.bufferNode=new $e(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return Js(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return Js(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 Sr(s){return s.children.some(e=>e instanceof ut||!e.type.isAnonymous||Sr(e))}function Bu(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Cu,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new kr(t,t.length):t,a=i.types,h=0,f=0;function c(S,M,A,W,z,U){let{id:I,start:O,end:K,size:$}=l,ie=f,et=h;if($<0)if(l.next(),$==-1){let Je=r[I];A.push(Je),W.push(O-S);return}else if($==-3){h=I;return}else if($==-4){f=I;return}else throw new RangeError(`Unrecognized record size: ${$}`);let ei=a[I],Ei,pt,zr=O-S;if(K-O<=n&&(pt=g(l.pos-M,z))){let Je=new Uint16Array(pt.size-pt.skip),ve=l.pos-pt.size,Ne=Je.length;for(;l.pos>ve;)Ne=y(pt.start,Je,Ne);Ei=new ut(Je,K-pt.start,i),zr=pt.start-S}else{let Je=l.pos-$;l.next();let ve=[],Ne=[],mt=I>=o?I:-1,Tt=0,Ri=K;for(;l.pos>Je;)mt>=0&&l.id==mt&&l.size>=0?(l.end<=Ri-n&&(p(ve,Ne,O,Tt,l.end,Ri,mt,ie,et),Tt=ve.length,Ri=l.end),l.next()):U>2500?u(O,Je,ve,Ne):c(O,Je,ve,Ne,mt,U+1);if(mt>=0&&Tt>0&&Tt<ve.length&&p(ve,Ne,O,Tt,O,Ri,mt,ie,et),ve.reverse(),Ne.reverse(),mt>-1&&Tt>0){let qr=d(ei,et);Ei=Cr(ei,ve,Ne,0,ve.length,0,K-O,qr,qr)}else Ei=m(ei,ve,Ne,K-O,ie-K,et)}A.push(Ei),W.push(zr)}function u(S,M,A,W){let z=[],U=0,I=-1;for(;l.pos>M;){let{id:O,start:K,end:$,size:ie}=l;if(ie>4)l.next();else{if(I>-1&&K<I)break;I<0&&(I=$-n),z.push(O,K,$),U++,l.next()}}if(U){let O=new Uint16Array(U*4),K=z[z.length-2];for(let $=z.length-3,ie=0;$>=0;$-=3)O[ie++]=z[$],O[ie++]=z[$+1]-K,O[ie++]=z[$+2]-K,O[ie++]=ie;A.push(new ut(O,z[2]-K,i)),W.push(K-S)}}function d(S,M){return(A,W,z)=>{let U=0,I=A.length-1,O,K;if(I>=0&&(O=A[I])instanceof X){if(!I&&O.type==S&&O.length==z)return O;(K=O.prop(E.lookAhead))&&(U=W[I]+O.length+K)}return m(S,A,W,z,U,M)}}function p(S,M,A,W,z,U,I,O,K){let $=[],ie=[];for(;S.length>W;)$.push(S.pop()),ie.push(M.pop()+A-z);S.push(m(i.types[I],$,ie,U-z,O-U,K)),M.push(z-A)}function m(S,M,A,W,z,U,I){if(U){let O=[E.contextHash,U];I=I?[O].concat(I):[O]}if(z>25){let O=[E.lookAhead,z];I=I?[O].concat(I):[O]}return new X(S,M,A,W,I)}function g(S,M){let A=l.fork(),W=0,z=0,U=0,I=A.end-n,O={size:0,start:0,skip:0};e:for(let K=A.pos-S;A.pos>K;){let $=A.size;if(A.id==M&&$>=0){O.size=W,O.start=z,O.skip=U,U+=4,W+=4,A.next();continue}let ie=A.pos-$;if($<0||ie<K||A.start<I)break;let et=A.id>=o?4:0,ei=A.start;for(A.next();A.pos>ie;){if(A.size<0)if(A.size==-3||A.size==-4)et+=4;else break e;else A.id>=o&&(et+=4);A.next()}z=ei,W+=$,U+=et}return(M<0||W==S)&&(O.size=W,O.start=z,O.skip=U),O.size>4?O:void 0}function y(S,M,A){let{id:W,start:z,end:U,size:I}=l;if(l.next(),I>=0&&W<o){let O=A;if(I>4){let K=l.pos-(I-4);for(;l.pos>K;)A=y(S,M,A)}M[--A]=O,M[--A]=U-S,M[--A]=z-S,M[--A]=W}else I==-3?h=W:I==-4&&(f=W);return A}let x=[],v=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,x,v,-1,0);let D=(e=s.length)!==null&&e!==void 0?e:x.length?v[0]+x[0].length:0;return new X(a[s.topID],x.reverse(),v.reverse(),D)}const Vo=new WeakMap;function ln(s,e){if(!s.isAnonymous||e instanceof ut||e.type!=s)return 1;let t=Vo.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof X)){t=1;break}t+=ln(s,i)}Vo.set(e,t)}return t}function Cr(s,e,t,i,n,r,o,l,a){let h=0;for(let p=i;p<n;p++)h+=ln(s,e[p]);let f=Math.ceil(h*1.5/8),c=[],u=[];function d(p,m,g,y,x){for(let v=g;v<y;){let D=v,S=m[v],M=ln(s,p[v]);for(v++;v<y;v++){let A=ln(s,p[v]);if(M+A>=f)break;M+=A}if(v==D+1){if(M>f){let A=p[D];d(A.children,A.positions,0,A.children.length,m[D]+x);continue}c.push(p[D])}else{let A=m[v-1]+p[v-1].length-S;c.push(Cr(s,p,m,D,v,S,A,null,a))}u.push(S+x-r)}}return d(e,t,i,n,0),(l||a)(c,u,o)}class _m{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof $e?this.setBuffer(e.context.buffer,e.index,t):e instanceof oe&&this.map.set(e.tree,t)}get(e){return e instanceof $e?this.getBuffer(e.context.buffer,e.index):e instanceof oe?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Xe{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 Xe(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 f=l<t.length?t[l]:null,c=f?f.fromA:1e9;if(c-a>=i)for(;o&&o.from<c;){let u=o;if(a>=u.from||c<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,c)-h;u=d>=p?null:new Xe(d,p,u.tree,u.offset+h,l>0,!!f)}if(u&&n.push(u),o.to>c)break;o=r<e.length?e[r++]:null}if(!f)break;a=f.toA,h=f.toA-f.toB}return n}}class Lu{startParse(e,t,i){return typeof e=="string"&&(e=new Eu(e)),i=i?i.length?i.map(n=>new Ce(n.from,n.to)):[new Ce(0,0)]:[new Ce(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 Eu{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function Ym(s){return(e,t,i,n)=>new Iu(e,s,t,i,n)}class zo{constructor(e,t,i,n,r,o){this.parser=e,this.parse=t,this.overlay=i,this.bracketed=n,this.target=r,this.from=o}}function qo(s){if(!s.length||s.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}class Ru{constructor(e,t,i,n,r,o,l,a){this.parser=e,this.predicate=t,this.mounts=i,this.index=n,this.start=r,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const _s=new E({perNode:!0});class Iu{constructor(e,t,i,n,r){this.nest=t,this.input=i,this.fragments=n,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let n of this.inner)n.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new X(i.type,i.children,i.positions,i.length,i.propValues.concat([[_s,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[E.mounted.id]=new Ht(t,e.overlay,e.parser,e.bracketed),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Wu(this.fragments),t=null,i=null,n=new wn(new oe(this.baseTree,this.ranges[0].from,0,null),V.IncludeAnonymous|V.IgnoreMounts);e:for(let r,o;;){let l=!0,a;if(this.stoppedAt!=null&&n.from>=this.stoppedAt)l=!1;else if(e.hasNode(n)){if(t){let h=t.mounts.find(f=>f.frag.from<=n.from&&f.frag.to>=n.to&&f.mount.overlay);if(h)for(let f of h.mount.overlay){let c=f.from+h.pos,u=f.to+h.pos;c>=n.from&&u<=n.to&&!t.ranges.some(d=>d.from<u&&d.to>c)&&t.ranges.push({from:c,to:u})}}l=!1}else if(i&&(o=Pu(i.ranges,n.from,n.to)))l=o!=2;else if(!n.type.isAnonymous&&(r=this.nest(n,this.input))&&(n.from<n.to||!r.overlay)){n.tree||(Nu(n),t&&t.depth++,i&&i.depth++);let h=e.findMounts(n.from,r.parser);if(typeof r.overlay=="function")t=new Ru(r.parser,r.overlay,h,this.inner.length,n.from,!!r.bracketed,n.tree,t);else{let f=jo(this.ranges,r.overlay||(n.from<n.to?[new Ce(n.from,n.to)]:[]));f.length&&qo(f),(f.length||!r.overlay)&&this.inner.push(new zo(r.parser,f.length?r.parser.startParse(this.input,Uo(h,f),f):r.parser.startParse(""),r.overlay?r.overlay.map(c=>new Ce(c.from-n.from,c.to-n.from)):null,!!r.bracketed,n.tree,f.length?f[0].from:n.from)),r.overlay?f.length&&(i={ranges:f,depth:0,prev:i}):l=!1}}else if(t&&(a=t.predicate(n))&&(a===!0&&(a=new Ce(n.from,n.to)),a.from<a.to)){let h=t.ranges.length-1;h>=0&&t.ranges[h].to==a.from?t.ranges[h]={from:t.ranges[h].from,to:a.to}:t.ranges.push(a)}if(l&&n.firstChild())t&&t.depth++,i&&i.depth++;else for(;!n.nextSibling();){if(!n.parent())break e;if(t&&!--t.depth){let h=jo(this.ranges,t.ranges);h.length&&(qo(h),this.inner.splice(t.index,0,new zo(t.parser,t.parser.startParse(this.input,Uo(t.mounts,h),h),t.ranges.map(f=>new Ce(f.from-t.start,f.to-t.start)),t.bracketed,t.target,h[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function Pu(s,e,t){for(let i of s){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function Ko(s,e,t,i,n,r){if(e<t){let o=s.buffer[e+1];i.push(s.slice(e,t,o)),n.push(o-r)}}function Nu(s){let{node:e}=s,t=[],i=e.context.buffer;do t.push(s.index),s.parent();while(!s.tree);let n=s.tree,r=n.children.indexOf(i),o=n.children[r],l=o.buffer,a=[r];function h(f,c,u,d,p,m){let g=t[m],y=[],x=[];Ko(o,f,g,y,x,d);let v=l[g+1],D=l[g+2];a.push(y.length);let S=m?h(g+4,l[g+3],o.set.types[l[g]],v,D-v,m-1):e.toTree();return y.push(S),x.push(v-d),Ko(o,l[g+3],c,y,x,d),new X(u,y,x,p)}n.children[r]=h(0,l.length,ye.none,0,o.length,t.length-1);for(let f of a){let c=s.tree.children[f],u=s.tree.positions[f];s.yield(new oe(c,u+s.from,f,s._tree))}}class $o{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(V.IncludeAnonymous|V.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,V.IgnoreOverlays|V.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof X)t=t.children[0];else break}return!1}}class Wu{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(_s))!==null&&t!==void 0?t:i.to,this.inner=new $o(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(_s))!==null&&e!==void 0?e:t.to,this.inner=new $o(t.tree,-t.offset)}}findMounts(e,t){var i;let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(i=r.tree)===null||i===void 0?void 0:i.prop(E.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=r.to)break;a.tree==this.curFrag.tree&&n.push({frag:a,pos:r.from-a.offset,mount:o})}}}return n}}function jo(s,e){let t=null,i=e;for(let n=1,r=0;n<s.length;n++){let o=s[n-1].to,l=s[n].from;for(;r<i.length;r++){let a=i[r];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[r]=new Ce(a.from,o),a.to>l&&t.splice(r+1,0,new Ce(l,a.to))):a.to>l?t[r--]=new Ce(l,a.to):t.splice(r--,1))}}return i}function Fu(s,e,t,i){let n=0,r=0,o=!1,l=!1,a=-1e9,h=[];for(;;){let f=n==s.length?1e9:o?s[n].to:s[n].from,c=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let u=Math.max(a,t),d=Math.min(f,c,i);u<d&&h.push(new Ce(u,d))}if(a=Math.min(f,c),a==1e9)break;f==a&&(o?(o=!1,n++):o=!0),c==a&&(l?(l=!1,r++):l=!0)}return h}function Uo(s,e){let t=[];for(let{pos:i,mount:n,frag:r}of s){let o=i+(n.overlay?n.overlay[0].from:0),l=o+n.tree.length,a=Math.max(r.from,o),h=Math.min(r.to,l);if(n.overlay){let f=n.overlay.map(u=>new Ce(u.from+i,u.to+i)),c=Fu(e,f,a,h);for(let u=0,d=a;;u++){let p=u==c.length,m=p?h:c[u].from;if(m>d&&t.push(new Xe(d,m,n.tree,-o,r.from>=d||r.openStart,r.to<=m||r.openEnd)),p)break;d=c[u].to}}else t.push(new Xe(a,h,n.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let Hu=0;class ke{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=Hu++}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 ke&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let n=new ke(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 vn(e);return i=>i.modified.indexOf(t)>-1?i:vn.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}}let Vu=0;class vn{constructor(e){this.name=e,this.instances=[],this.id=Vu++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&zu(t,l.modified));if(i)return i;let n=[],r=new ke(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=qu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(vn.get(l,a));return r}}function zu(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function qu(s){let e=[[]];for(let t=0;t<s.length;t++)for(let i=0,n=e.length;i<n;i++)e.push(e[i].concat(s[t]));return e.sort((t,i)=>i.length-t.length)}function Ku(s){let e=Object.create(null);for(let t in s){let i=s[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let r=[],o=2,l=n;for(let c=0;;){if(l=="..."&&c>0&&c+3==n.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+n);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(c)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+n);let f=new vi(i,o,a>0?r.slice(0,a):null);e[h]=f.sort(e[h])}}return ja.add(e)}const ja=new E({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 vi(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class vi{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}vi.empty=new vi([],2,null);function Ua(s,e){let t=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:n=null}=e||{};return{style:r=>{let o=n;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function $u(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function ju(s,e,t,i=0,n=s.length){let r=new Uu(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class Uu{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,f=Gu(e)||vi.empty,c=$u(r,f.tags);if(c&&(h&&(h+=" "),h+=c,f.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(t,l),h),f.opaque)return;let u=e.tree&&e.tree.prop(E.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,y=l;;g++){let x=g<u.overlay.length?u.overlay[g]:null,v=x?x.from+l:a,D=Math.max(t,y),S=Math.min(i,v);if(D<S&&m)for(;e.from<S&&(this.highlightRange(e,D,S,n,r),this.startSpan(Math.min(S,e.to),h),!(e.to>=v||!e.nextSibling())););if(!x||v>i)break;y=x.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,x.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),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 Gu(s){let e=s.type.prop(ja);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const w=ke.define,Ji=w(),it=w(),Go=w(it),Jo=w(it),nt=w(),_i=w(nt),ls=w(nt),Ve=w(),gt=w(Ve),Fe=w(),He=w(),Ys=w(),ni=w(Ys),Yi=w(),B={comment:Ji,lineComment:w(Ji),blockComment:w(Ji),docComment:w(Ji),name:it,variableName:w(it),typeName:Go,tagName:w(Go),propertyName:Jo,attributeName:w(Jo),className:w(it),labelName:w(it),namespace:w(it),macroName:w(it),literal:nt,string:_i,docString:w(_i),character:w(_i),attributeValue:w(_i),number:ls,integer:w(ls),float:w(ls),bool:w(nt),regexp:w(nt),escape:w(nt),color:w(nt),url:w(nt),keyword:Fe,self:w(Fe),null:w(Fe),atom:w(Fe),unit:w(Fe),modifier:w(Fe),operatorKeyword:w(Fe),controlKeyword:w(Fe),definitionKeyword:w(Fe),moduleKeyword:w(Fe),operator:He,derefOperator:w(He),arithmeticOperator:w(He),logicOperator:w(He),bitwiseOperator:w(He),compareOperator:w(He),updateOperator:w(He),definitionOperator:w(He),typeOperator:w(He),controlOperator:w(He),punctuation:Ys,separator:w(Ys),bracket:ni,angleBracket:w(ni),squareBracket:w(ni),paren:w(ni),brace:w(ni),content:Ve,heading:gt,heading1:w(gt),heading2:w(gt),heading3:w(gt),heading4:w(gt),heading5:w(gt),heading6:w(gt),contentSeparator:w(Ve),list:w(Ve),quote:w(Ve),emphasis:w(Ve),strong:w(Ve),link:w(Ve),monospace:w(Ve),strikethrough:w(Ve),inserted:w(),deleted:w(),changed:w(),invalid:w(),meta:Yi,documentMeta:w(Yi),annotation:w(Yi),processingInstruction:w(Yi),definition:ke.defineModifier("definition"),constant:ke.defineModifier("constant"),function:ke.defineModifier("function"),standard:ke.defineModifier("standard"),local:ke.defineModifier("local"),special:ke.defineModifier("special")};for(let s in B){let e=B[s];e instanceof ke&&(e.name=s)}Ua([{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 as;const Rt=new E;function Ju(s){return C.define({combine:s?e=>e.concat(s):void 0})}const _u=new E;class Ee{constructor(e,t,i=[],n=""){this.data=e,this.name=n,F.prototype.hasOwnProperty("tree")||Object.defineProperty(F.prototype,"tree",{get(){return Te(this)}}),this.parser=t,this.extension=[Jt.of(this),F.languageData.of((r,o,l)=>{let a=_o(r,o,l),h=a.type.prop(Rt);if(!h)return[];let f=r.facet(h),c=a.type.prop(_u);if(c){let u=a.resolve(o-a.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(e,t,i=-1){return _o(e,t,i).type.prop(Rt)==this.data}findRegions(e){let t=e.facet(Jt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(Rt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(E.mounted);if(l){if(l.tree.prop(Rt)==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;a<r.children.length;a++){let h=r.children[a];h instanceof X&&n(h,r.positions[a]+o)}};return n(Te(e),0),i}get allowsNesting(){return!0}}Ee.setState=N.define();function _o(s,e,t){let i=s.facet(Jt),n=Te(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(e,t,V.ExcludeBuffers|V.EnterBracketed))r.type.isTop&&(n=r);return n}class Xs extends Ee{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Ju(e.languageData);return new Xs(t,e.parser.configure({props:[Rt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Xs(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Te(s){let e=s.field(Ee.state,!1);return e?e.tree:X.empty}class Yu{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let si=null;class kn{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 kn(e,t,[],X.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Yu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=X.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Xe.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Xe.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=si;si=this;try{return e()}finally{si=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Yo(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,f,c,u)=>a.push({fromA:h,toA:f,fromB:c,toB:u})),i=Xe.applyChanges(i,a),n=X.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 f=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);f<c&&l.push({from:f,to:c})}}}return new kn(this.parser,t,i,n,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<e.to&&r>e.from&&(this.fragments=Yo(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 Lu{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=si;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 X(ye.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 si}}function Yo(s,e,t){return Xe.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class Gt{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 Gt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=kn.create(e.facet(Jt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Gt(i)}}Ee.state=De.define({create:Gt.init,update(s,e){for(let t of e.effects)if(t.is(Ee.setState))return t.value;return e.startState.facet(Jt)!=e.state.facet(Jt)?Gt.init(e.state):s.apply(e)}});let Ga=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Ga=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const hs=typeof navigator<"u"&&(!((as=navigator.scheduling)===null||as===void 0)&&as.isInputPending)?()=>navigator.scheduling.isInputPending():null,Xu=ce.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(Ee.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(Ee.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Ga(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Ee.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!hs?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,a=r.context.work(()=>hs&&hs()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Ee.setState.of(new Gt(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=>we(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()}}}),Jt=C.define({combine(s){return s.length?s[0]:null},enables:s=>[Ee.state,Xu,T.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class Qm{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class Ja{constructor(e,t,i,n,r,o=void 0){this.name=e,this.alias=t,this.extensions=i,this.filename=n,this.loadFunc=r,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new Ja(e.name,(e.alias||[]).concat(e.name).map(n=>n.toLowerCase()),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let i=/\.([^.]+)$/.exec(t);if(i){for(let n of e)if(n.extensions.indexOf(i[1])>-1)return n}return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(r=>r==t))return n;if(i)for(let n of e)for(let r of n.alias){let o=t.indexOf(r);if(o>-1&&(r.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+r.length])))return n}return null}}const Qu=C.define(),Vn=C.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 Sn(s){let e=s.facet(Vn);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function Cn(s,e){let t="",i=s.tabSize,n=s.facet(Vn)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r<e;r++)t+=n;return t}function _a(s,e){s instanceof F&&(s=new zn(s));for(let i of s.state.facet(Qu)){let n=i(s,e);if(n!==void 0)return n}let t=Te(s.state);return t.length>=e?ed(s,t,e):null}class zn{constructor(e,t={}){this.state=e,this.options=t,this.unit=Sn(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return In(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 Zu=new E;function ed(s,e,t){let i=e.resolveStack(t),n=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Ya(i,s,t)}function Ya(s,e,t){for(let i=s;i;i=i.next){let n=id(i.node);if(n)return n(Ar.create(e,t,i))}return 0}function td(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function id(s){let e=s.type.prop(Zu);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(E.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>Xa(o,!0,1,void 0,r&&!td(o)?n.from:void 0)}return s.parent==null?nd:null}function nd(){return 0}class Ar extends zn{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 Ar(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(sd(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Ya(this.context.next,this.base,this.pos)}}function sd(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function rd(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 Zm({closing:s,align:e=!0,units:t=1}){return i=>Xa(i,e,t,s)}function Xa(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?rd(s):null;return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}const eg=s=>s.baseIndent;function tg({except:s,units:e=1}={}){return t=>{let i=s&&s.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const ig=C.define(),ng=new E;function sg(s){let e=s.firstChild,t=s.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?s.to:t.from}:null}class Mr{constructor(e,t){this.specs=e;let i;function n(l){let a=at.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 Ee?l=>l.prop(Rt)==o.data:o?l=>l==o:void 0,this.style=Ua(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new at(i):null,this.themeType=t.themeType}static define(e,t){return new Mr(e,t||{})}}const Qs=C.define(),od=C.define({combine(s){return s.length?[s[0]]:null}});function fs(s){let e=s.facet(Qs);return e.length?e:s.facet(od)}function rg(s,e){let t=[ad],i;return s instanceof Mr&&(s.module&&t.push(T.styleModule.of(s.module)),i=s.themeType),i?t.push(Qs.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):t.push(Qs.of(s)),t}class ld{constructor(e){this.markCache=Object.create(null),this.tree=Te(e.state),this.decorations=this.buildDeco(e,fs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Te(e.state),i=fs(e.state),n=i!=fs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return L.none;let i=new Kt;for(let{from:n,to:r}of e.visibleRanges)ju(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=L.mark({class:a})))},n,r);return i.finish()}}const ad=Mt.high(ce.fromClass(ld,{decorations:s=>s.decorations})),hd=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Qa=1e4,Za="()[]{}",eh=C.define({combine(s){return Yt(s,{afterCursor:!0,brackets:Za,maxScanDistance:Qa,renderMatch:ud})}}),fd=L.mark({class:"cm-matchingBracket"}),cd=L.mark({class:"cm-nonmatchingBracket"});function ud(s){let e=[],t=s.matched?fd:cd;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 Xo(s){let e=[],t=s.facet(eh);for(let i of s.selection.ranges){if(!i.empty)continue;let n=je(s,i.head,-1,t)||i.head>0&&je(s,i.head-1,1,t)||t.afterCursor&&(je(s,i.head,1,t)||i.head<s.doc.length&&je(s,i.head+1,-1,t));n&&(e=e.concat(t.renderMatch(n,s)))}return L.set(e,!0)}const dd=ce.fromClass(class{constructor(s){this.paused=!1,this.decorations=Xo(s.state)}update(s){(s.docChanged||s.selectionSet||this.paused)&&(s.view.composing?(this.decorations=this.decorations.map(s.changes),this.paused=!0):(this.decorations=Xo(s.state),this.paused=!1))}},{decorations:s=>s.decorations}),pd=[dd,hd];function og(s={}){return[eh.of(s),pd]}const md=new E;function Zs(s,e,t){let i=s.prop(e<0?E.openedBy:E.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 er(s){let e=s.type.prop(md);return e?e(s.node):s}function je(s,e,t,i={}){let n=i.maxScanDistance||Qa,r=i.brackets||Za,o=Te(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Zs(a.type,t,r);if(h&&a.from<a.to){let f=er(a);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return gd(s,e,t,a,f,h,r)}}return yd(s,e,t,o,l.type,n,r)}function gd(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},h=0,f=l==null?void 0:l.cursor();if(f&&(t<0?f.childBefore(i.from):f.childAfter(i.to)))do if(t<0?f.to<=i.from:f.from>=i.to){if(h==0&&r.indexOf(f.type.name)>-1&&f.from<f.to){let c=er(f);return{start:a,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(Zs(f.type,t,o))h++;else if(Zs(f.type,-t,o)){if(h==0){let c=er(f);return{start:a,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}h--}}while(t<0?f.prevSibling():f.nextSibling());return{start:a,matched:!1}}function yd(s,e,t,i,n,r,o){if(t<0?!e:e==s.doc.length)return null;let l=t<0?s.sliceDoc(e-1,e):s.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},f=s.doc.iterRange(e,t>0?s.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=r;){let d=f.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=n))if(y%2==0==t>0)c++;else{if(c==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};c--}}t>0&&(u+=d.length)}return f.done?{start:h,matched:!1}:null}const bd=Object.create(null),Qo=[ye.none],Zo=[],el=Object.create(null),xd=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"]])xd[s]=wd(bd,e);function cs(s,e){Zo.indexOf(s)>-1||(Zo.push(s),console.warn(e))}function wd(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let f=s[h]||B[h];f?typeof f=="function"?a.length?a=a.map(f):cs(h,`Modifier ${h} used at start of tag`):a.length?cs(h,`Tag ${h} used as modifier`):a=Array.isArray(f)?f:[f]:cs(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=el[n];if(r)return r.id;let o=el[n]=ye.define({id:Qo.length,name:i,props:[Ku({[i]:t})]});return Qo.push(o),o.id}j.RTL,j.LTR;const vd=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=Dr(s.state,t.from);return i.line?kd(s):i.block?Cd(s):!1};function Tr(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const kd=Tr(Td,0),Sd=Tr(th,0),Cd=Tr((s,e)=>th(s,e,Md(e)),0);function Dr(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const ri=50;function Ad(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-ri,i),o=s.sliceDoc(n,n+ri),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 f,c;n-i<=2*ri?f=c=s.sliceDoc(i,n):(f=s.sliceDoc(i,i+ri),c=s.sliceDoc(n-ri,n));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function Md(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 th(s,e,t=e.selection.ranges){let i=t.map(r=>Dr(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>Ad(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let a=i[o],{open:h,close:f}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:f.pos-f.margin,to:f.pos+a.close.length})}return{changes:r}}return null}function Td(s,e,t=e.selection.ranges){let i=[],n=-1;e:for(let{from:r,to:o}of t){let l=i.length,a=1e9,h;for(let f=r;f<=o;){let c=e.doc.lineAt(f);if(h==null&&(h=Dr(e,c.from).line,!h))continue e;if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+h.length)==h?u:-1;u<c.text.length&&u<a&&(a=u),i.push({line:c,comment:p,token:h,indent:u,empty:d,single:!1})}f=c.to+1}if(a<1e9)for(let f=l;f<i.length;f++)i[f].indent<i[f].line.text.length&&(i[f].indent=a);i.length==l+1&&(i[l].single=!0)}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:f,single:c}of i)(c||!f)&&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,f=h+a.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}const tr=Ze.define(),Dd=Ze.define(),Od=C.define(),ih=C.define({combine(s){return Yt(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)})}}),nh=De.define({create(){return Ue.empty},update(s,e){let t=e.state.facet(ih),i=e.annotation(tr);if(i){let a=pe.fromTransaction(e,i.selection),h=i.side,f=h==0?s.undone:s.done;return a?f=An(f,f.length,t.minDepth,a):f=oh(f,e.startState.selection),new Ue(h==0?i.rest:f,h==0?f:i.rest)}let n=e.annotation(Dd);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(Y.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=pe.fromTransaction(e),o=e.annotation(Y.time),l=e.annotation(Y.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 Ue(s.done.map(pe.fromJSON),s.undone.map(pe.fromJSON))}});function lg(s={}){return[nh,ih.of(s),T.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?sh:e.inputType=="historyRedo"?ir:null;return i?(e.preventDefault(),i(t)):!1}})]}function qn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(nh,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const sh=qn(0,!1),ir=qn(1,!1),Bd=qn(0,!0),Ld=qn(1,!0);class pe{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 pe(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 pe(e.changes&&Q.fromJSON(e.changes),[],e.mapped&&Ge.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=Ae;for(let n of e.startState.facet(Od)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new pe(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ae)}static selection(e){return new pe(void 0,Ae,void 0,void 0,e)}}function An(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 Ed(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<t.length;){let h=t[a++],f=t[a++];l>=h&&o<=f&&(i=!0)}}),i}function Rd(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function rh(s,e){return s.length?e.length?s.concat(e):s:e}const Ae=[],Id=200;function oh(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Id));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),An(s,s.length-1,1e9,t.setSelAfter(i)))}else return[pe.selection([e])]}function Pd(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 us(s,e){if(!s.length)return s;let t=s.length,i=Ae;for(;t;){let n=Nd(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?[pe.selection(i)]:Ae}function Nd(s,e,t){let i=rh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):Ae,t);if(!s.changes)return pe.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new pe(n,N.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const Wd=/^(input\.type|delete)($|\.)/;class Ue{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 Ue(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||Wd.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Ed(l.changes,e.changes))||i=="input.type.compose")?o=An(o,o.length-1,n.minDepth,new pe(e.changes.compose(l.changes),rh(N.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ae)):o=An(o,o.length,n.minDepth,e),new Ue(o,Ae,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ae;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Rd(r[r.length-1],e)?this:new Ue(oh(this.done,e),this.undone,t,i)}addMapping(e){return new Ue(us(this.done,e),us(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:tr.of({side:e,rest:Pd(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?Ae:n.slice(0,n.length-1);return r.mapped&&(l=us(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:tr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Ue.empty=new Ue(Ae,Ae);const ag=[{key:"Mod-z",run:sh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:ir,preventDefault:!0},{linux:"Ctrl-Shift-z",run:ir,preventDefault:!0},{key:"Mod-u",run:Bd,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ld,preventDefault:!0}];function Xt(s,e){return b.create(s.ranges.map(e),s.mainIndex)}function Ie(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Pe({state:s,dispatch:e},t){let i=Xt(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Ie(s,i)),!0)}function Kn(s,e){return b.cursor(e?s.to:s.from)}function lh(s,e){return Pe(s,t=>t.empty?s.moveByChar(t,e):Kn(t,e))}function le(s){return s.textDirectionAt(s.state.selection.main.head)==j.LTR}const ah=s=>lh(s,!le(s)),hh=s=>lh(s,le(s));function fh(s,e){return Pe(s,t=>t.empty?s.moveByGroup(t,e):Kn(t,e))}const Fd=s=>fh(s,!le(s)),Hd=s=>fh(s,le(s));function Vd(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=Te(s).resolveInner(e.head),n=t?E.closedBy:E.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Vd(s,h,n)?i=h:a=t?h.to:h.from}let r=i.type.prop(n),o,l;return r&&(o=t?je(s,i.from,1):je(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const zd=s=>Pe(s,e=>$n(s.state,e,!le(s))),qd=s=>Pe(s,e=>$n(s.state,e,le(s)));function ch(s,e){return Pe(s,t=>{if(!t.empty)return Kn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const uh=s=>ch(s,!1),dh=s=>ch(s,!0);function ph(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function mh(s,e){let t=ph(s),{state:i}=s,n=Xt(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):Kn(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-a}))}return s.dispatch(Ie(i,n),{effects:r}),!0}const tl=s=>mh(s,!1),nr=s=>mh(s,!0);function dt(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const Kd=s=>Pe(s,e=>dt(s,e,!0)),$d=s=>Pe(s,e=>dt(s,e,!1)),jd=s=>Pe(s,e=>dt(s,e,!le(s))),Ud=s=>Pe(s,e=>dt(s,e,le(s))),Gd=s=>Pe(s,e=>b.cursor(s.lineBlockAt(e.head).from,1)),Jd=s=>Pe(s,e=>b.cursor(s.lineBlockAt(e.head).to,-1));function _d(s,e,t){let i=!1,n=Xt(s.selection,r=>{let o=je(s,r.head,-1)||je(s,r.head,1)||r.head>0&&je(s,r.head-1,1)||r.head<s.doc.length&&je(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return b.cursor(l)});return i?(e(Ie(s,n)),!0):!1}const Yd=({state:s,dispatch:e})=>_d(s,e);function Oe(s,e){let t=Xt(s.state.selection,i=>{let n=e(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return t.eq(s.state.selection)?!1:(s.dispatch(Ie(s.state,t)),!0)}function gh(s,e){return Oe(s,t=>s.moveByChar(t,e))}const yh=s=>gh(s,!le(s)),bh=s=>gh(s,le(s));function xh(s,e){return Oe(s,t=>s.moveByGroup(t,e))}const Xd=s=>xh(s,!le(s)),Qd=s=>xh(s,le(s)),Zd=s=>Oe(s,e=>$n(s.state,e,!le(s))),ep=s=>Oe(s,e=>$n(s.state,e,le(s)));function wh(s,e){return Oe(s,t=>s.moveVertically(t,e))}const vh=s=>wh(s,!1),kh=s=>wh(s,!0);function Sh(s,e){return Oe(s,t=>s.moveVertically(t,e,ph(s).height))}const il=s=>Sh(s,!1),nl=s=>Sh(s,!0),tp=s=>Oe(s,e=>dt(s,e,!0)),ip=s=>Oe(s,e=>dt(s,e,!1)),np=s=>Oe(s,e=>dt(s,e,!le(s))),sp=s=>Oe(s,e=>dt(s,e,le(s))),rp=s=>Oe(s,e=>b.cursor(s.lineBlockAt(e.head).from)),op=s=>Oe(s,e=>b.cursor(s.lineBlockAt(e.head).to)),sl=({state:s,dispatch:e})=>(e(Ie(s,{anchor:0})),!0),rl=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.doc.length})),!0),ol=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.selection.main.anchor,head:0})),!0),ll=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),lp=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),ap=({state:s,dispatch:e})=>{let t=jn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:b.create(t),userEvent:"select"})),!0},hp=({state:s,dispatch:e})=>{let t=Xt(s.selection,i=>{let n=Te(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return b.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Ie(s,t)),!0)};function Ch(s,e){let{state:t}=s,i=t.selection,n=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let a=s.moveVertically(l,e);if(a.head<o.from||a.head>o.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(Ie(t,b.create(n,n.length-1))),!0)}const fp=s=>Ch(s,!1),cp=s=>Ch(s,!0),up=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Ie(s,i)),!0):!1};function Oi(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);a<o?(t="delete.backward",a=Xi(s,a,!1)):a>o&&(t="delete.forward",a=Xi(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Xi(s,o,!1),l=Xi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Xi(s,e,t){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const Ah=(s,e,t)=>Oi(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(t&&!e&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let h=In(l,r.tabSize),f=h%Sn(r)||Sn(r);for(let c=0;c<f&&l[l.length-1-c]==" ";c++)n--;a=n}else a=te(o.text,n-o.from,e,e)+o.from,a==n&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,n-o.from))&&(a=te(o.text,a-o.from,!1,!1)+o.from);return a}),sr=s=>Ah(s,!1,!0),Mh=s=>Ah(s,!0,!1),Th=(s,e)=>Oi(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=te(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||i!=t.head)&&(l=f),i=a}return i}),Dh=s=>Th(s,!1),dp=s=>Th(s,!0),pp=s=>Oi(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),mp=s=>Oi(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),gp=s=>Oi(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),yp=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:P.of(["",""])},range:b.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},bp=({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:te(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:te(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:b.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function 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 Oh(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(b.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(b.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const xp=({state:s,dispatch:e})=>Oh(s,e,!1),wp=({state:s,dispatch:e})=>Oh(s,e,!0);function Bh(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 vp=({state:s,dispatch:e})=>Bh(s,e,!1),kp=({state:s,dispatch:e})=>Bh(s,e,!0),Sp=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<e.doc.length&&r++,{from:n,to:r}))),i=Xt(e.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Cp(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Te(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(E.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 al=Lh(!1),Ap=Lh(!0);function Lh(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&&Cp(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new zn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),f=_a(h,r);for(f==null&&(f=In(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",Cn(e,f)];return a&&c.push(Cn(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:P.of(c)},range:b.cursor(r+1+c[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Or(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Mp=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new zn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=Or(s,(r,o,l)=>{let a=_a(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],f=Cn(s,a);(h!=f||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:f}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},Tp=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Or(s,(t,i)=>{i.push({from:t.from,insert:s.facet(Vn)})}),{userEvent:"input.indent"})),!0),Dp=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Or(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=In(n,s.tabSize),o=0,l=Cn(s,Math.max(0,r-Sn(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Op=s=>(s.setTabFocusMode(),!0),Bp=[{key:"Ctrl-b",run:ah,shift:yh,preventDefault:!0},{key:"Ctrl-f",run:hh,shift:bh},{key:"Ctrl-p",run:uh,shift:vh},{key:"Ctrl-n",run:dh,shift:kh},{key:"Ctrl-a",run:Gd,shift:rp},{key:"Ctrl-e",run:Jd,shift:op},{key:"Ctrl-d",run:Mh},{key:"Ctrl-h",run:sr},{key:"Ctrl-k",run:pp},{key:"Ctrl-Alt-h",run:Dh},{key:"Ctrl-o",run:yp},{key:"Ctrl-t",run:bp},{key:"Ctrl-v",run:nr}],Lp=[{key:"ArrowLeft",run:ah,shift:yh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Fd,shift:Xd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:jd,shift:np,preventDefault:!0},{key:"ArrowRight",run:hh,shift:bh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Hd,shift:Qd,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Ud,shift:sp,preventDefault:!0},{key:"ArrowUp",run:uh,shift:vh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:sl,shift:ol},{mac:"Ctrl-ArrowUp",run:tl,shift:il},{key:"ArrowDown",run:dh,shift:kh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:rl,shift:ll},{mac:"Ctrl-ArrowDown",run:nr,shift:nl},{key:"PageUp",run:tl,shift:il},{key:"PageDown",run:nr,shift:nl},{key:"Home",run:$d,shift:ip,preventDefault:!0},{key:"Mod-Home",run:sl,shift:ol},{key:"End",run:Kd,shift:tp,preventDefault:!0},{key:"Mod-End",run:rl,shift:ll},{key:"Enter",run:al,shift:al},{key:"Mod-a",run:lp},{key:"Backspace",run:sr,shift:sr,preventDefault:!0},{key:"Delete",run:Mh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Dh,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:dp,preventDefault:!0},{mac:"Mod-Backspace",run:mp,preventDefault:!0},{mac:"Mod-Delete",run:gp,preventDefault:!0}].concat(Bp.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),hg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:zd,shift:Zd},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:qd,shift:ep},{key:"Alt-ArrowUp",run:xp},{key:"Shift-Alt-ArrowUp",run:vp},{key:"Alt-ArrowDown",run:wp},{key:"Shift-Alt-ArrowDown",run:kp},{key:"Mod-Alt-ArrowUp",run:fp},{key:"Mod-Alt-ArrowDown",run:cp},{key:"Escape",run:up},{key:"Mod-Enter",run:Ap},{key:"Alt-l",mac:"Ctrl-l",run:ap},{key:"Mod-i",run:hp,preventDefault:!0},{key:"Mod-[",run:Dp},{key:"Mod-]",run:Tp},{key:"Mod-Alt-\\",run:Mp},{key:"Shift-Mod-k",run:Sp},{key:"Shift-Mod-\\",run:Yd},{key:"Mod-/",run:vd},{key:"Alt-A",run:Sd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Op}].concat(Lp),hl=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class _t{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(hl(l)):hl,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 tt(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=Al(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=bt(e);let n=this.normalize(t);if(n.length)for(let r=0,o=i;;r++){let l=n.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,i){let n=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?n={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?n={from:t,to:i}:this.matches.push(1,t)),n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null),n}}typeof Symbol<"u"&&(_t.prototype[Symbol.iterator]=function(){return this});const Eh={from:-1,to:-1,match:/.*/.exec("")},Br="gm"+(/x/.unicode==null?"":"u");class Rh{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Eh,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Ih(e,t,i,n,r);this.re=new RegExp(t,Br+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(n);this.curLineStart=o.from,this.matchPos=Mn(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.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=Mn(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const ds=new WeakMap;class Vt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=ds.get(e);if(!n||n.from>=i||n.to<=t){let l=new Vt(t,e.sliceString(t,i));return ds.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<i&&(r+=e.sliceString(n.to,i)),ds.set(e,new Vt(o,r)),new Vt(t,r.slice(t-o,i-o))}}class Ih{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=Eh,this.matchPos=Mn(e,n),this.re=new RegExp(t,Br+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Vt.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=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,match:t},this.matchPos=Mn(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Vt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Rh.prototype[Symbol.iterator]=Ih.prototype[Symbol.iterator]=function(){return this});function Ep(s){try{return new RegExp(s,Br),!0}catch{return!1}}function Mn(s,e){if(e>=s.length)return e;let t=s.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const Rp=s=>{let{state:e}=s,t=String(e.doc.lineAt(s.state.selection.main.head).number),{close:i,result:n}=uu(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,f,c]=o,u=f?+f.slice(1):0,d=h?+h:l.number;if(h&&c){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=b.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[i,T.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},Ip={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Pp=C.define({combine(s){return Yt(s,Ip,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function fg(s){return[Vp,Hp]}const Np=L.mark({class:"cm-selectionMatch"}),Wp=L.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function fl(s,e,t,i){return(t==0||s(e.sliceDoc(t-1,t))!=_.Word)&&(i==e.doc.length||s(e.sliceDoc(i,i+1))!=_.Word)}function Fp(s,e,t,i){return s(e.sliceDoc(t,t+1))==_.Word&&s(e.sliceDoc(i-1,i))==_.Word}const Hp=ce.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(Pp),{state:t}=s,i=t.selection;if(i.ranges.length>1)return L.none;let n=i.main,r,o=null;if(n.empty){if(!e.highlightWordAroundCursor)return L.none;let a=t.wordAt(n.head);if(!a)return L.none;o=t.charCategorizer(n.head),r=t.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a<e.minSelectionLength||a>200)return L.none;if(e.wholeWords){if(r=t.sliceDoc(n.from,n.to),o=t.charCategorizer(n.head),!(fl(o,t,n.from,n.to)&&Fp(o,t,n.from,n.to)))return L.none}else if(r=t.sliceDoc(n.from,n.to),!r)return L.none}let l=[];for(let a of s.visibleRanges){let h=new _t(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:f,to:c}=h.value;if((!o||fl(o,t,f,c))&&(n.empty&&f<=n.from&&c>=n.to?l.push(Wp.range(f,c)):(f>=n.to||c<=n.from)&&l.push(Np.range(f,c)),l.length>e.maxMatches))return L.none}}return L.set(l)}},{decorations:s=>s.decorations}),Vp=T.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),zp=({state:s,dispatch:e})=>{let{selection:t}=s,i=b.create(t.ranges.map(n=>s.wordAt(n.head)||b.cursor(n.head)),t.mainIndex);return i.eq(t)?!1:(e(s.update({selection:i})),!0)};function qp(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 _t(s.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new _t(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 Kp=({state:s,dispatch:e})=>{let{ranges:t}=s.selection;if(t.some(r=>r.from===r.to))return zp({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=qp(s,i);return n?(e(s.update({selection:s.selection.addRange(b.range(n.from,n.to),!1),effects:T.scrollIntoView(n.to)})),!0):!1},Qt=C.define({combine(s){return Yt(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new im(e),scrollToMatch:e=>T.scrollIntoView(e)})}});class Ph{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||Ep(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"?`
|
|
11
|
-
`: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 _p(this):new Up(this)}getCursor(e,t=0,i){let n=e.doc?e:F.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?Bt(this,n,t,i):Ot(this,n,t,i)}}class Nh{constructor(e){this.spec=e}}function $p(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 Ot(s,e,t,i){let n;return s.wholeWord&&(n=jp(e.doc,e.charCategorizer(e.selection.main.head))),s.test&&(n=$p(s.test,e,n)),new _t(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:r=>r.toLowerCase(),n)}function jp(s,e){return(t,i,n,r)=>((r>t||r+n.length<i)&&(r=Math.max(0,t-2),n=s.sliceString(r,Math.min(s.length,i+2))),(e(Tn(n,t-r))!=_.Word||e(Dn(n,t-r))!=_.Word)&&(e(Dn(n,i-r))!=_.Word||e(Tn(n,i-r))!=_.Word))}class Up extends Nh{constructor(e){super(e)}nextMatch(e,t,i){let n=Ot(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);n=Ot(this.spec,e,0,r).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length),o=Ot(this.spec,e,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),n&&(n.from!=t||n.to!=i)?n:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Ot(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Ot(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 Gp(s,e,t){return(i,n,r)=>(!t||t(i,n,r))&&s(r[0],e,i,n)}function Bt(s,e,t,i){let n;return s.wholeWord&&(n=Jp(e.charCategorizer(e.selection.main.head))),s.test&&(n=Gp(s.test,e,n)),new Rh(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:n},t,i)}function Tn(s,e){return s.slice(te(s,e,!1),e)}function Dn(s,e){return s.slice(e,te(s,e))}function Jp(s){return(e,t,i)=>!i[0].length||(s(Tn(i.input,i.index))!=_.Word||s(Dn(i.input,i.index))!=_.Word)&&(s(Dn(i.input,i.index+i[0].length))!=_.Word||s(Tn(i.input,i.index+i[0].length))!=_.Word)}class _p extends Nh{nextMatch(e,t,i){let n=Bt(this.spec,e,i,e.doc.length).next();return n.done&&(n=Bt(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=Bt(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<e.match.length)return e.match[r]+i.slice(n)}return t})}matchAll(e,t){let i=Bt(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Bt(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 ki=N.define(),Lr=N.define(),ot=De.define({create(s){return new ps(rr(s).create(),null)},update(s,e){for(let t of e.effects)t.is(ki)?s=new ps(t.value.create(),s.panel):t.is(Lr)&&(s=new ps(s.query,t.value?Er:null));return s},provide:s=>xn.from(s,e=>e.panel)});class ps{constructor(e,t){this.query=e,this.panel=t}}const Yp=L.mark({class:"cm-searchMatch"}),Xp=L.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Qp=ce.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(ot))}update(s){let e=s.state.field(ot);(e!=s.startState.field(ot)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return L.none;let{view:t}=this,i=new Kt;for(let n=0,r=t.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-500;)a=r[++n].to;s.highlight(t.state,l,a,(h,f)=>{let c=t.state.selection.ranges.some(u=>u.from==h&&u.to==f);i.add(h,f,c?Xp:Yp)})}return i.finish()}},{decorations:s=>s.decorations});function Bi(s){return e=>{let t=e.state.field(ot,!1);return t&&t.query.spec.valid?s(e,t):Hh(e)}}const On=Bi((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=b.single(i.from,i.to),r=s.state.facet(Qt);return s.dispatch({selection:n,effects:[Rr(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),Fh(s),!0}),Bn=Bi((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=b.single(n.from,n.to),o=s.state.facet(Qt);return s.dispatch({selection:r,effects:[Rr(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),Fh(s),!0}),Zp=Bi((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:b.create(t.map(i=>b.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),em=({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 _t(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(b.range(l.value.from,l.value.to))}return e(s.update({selection:b.create(r,o),userEvent:"select.search.matches"})),!0},cl=Bi((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,f=[];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),f.push(T.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let c=s.state.changes(l);return o&&(a=b.single(o.from,o.to).map(c),f.push(Rr(s,o)),f.push(t.facet(Qt).scrollToMatch(a.main,s))),s.dispatch({changes:c,selection:a,effects:f,userEvent:"input.replace"}),!0}),tm=Bi((s,{query:e})=>{if(s.state.readOnly)return!1;let t=e.matchAll(s.state,1e9).map(n=>{let{from:r,to:o}=n;return{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:T.announce.of(i),userEvent:"input.replace.all"}),!0});function Er(s){return s.state.facet(Qt).createPanel(s)}function rr(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(Qt);return new Ph({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e==null?void 0:e.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Wh(s){let e=Pa(s,Er);return e&&e.dom.querySelector("[main-field]")}function Fh(s){let e=Wh(s);e&&e==s.root.activeElement&&e.select()}const Hh=s=>{let e=s.state.field(ot,!1);if(e&&e.panel){let t=Wh(s);if(t&&t!=s.root.activeElement){let i=rr(s.state,e.query.spec);i.valid&&s.dispatch({effects:ki.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[Lr.of(!0),e?ki.of(rr(s.state,e.query.spec)):N.appendConfig.of(sm)]});return!0},Vh=s=>{let e=s.state.field(ot,!1);if(!e||!e.panel)return!1;let t=Pa(s,Er);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Lr.of(!1)}),!0},cg=[{key:"Mod-f",run:Hh,scope:"editor search-panel"},{key:"F3",run:On,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:On,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Vh,scope:"editor search-panel"},{key:"Mod-Shift-l",run:em},{key:"Mod-Alt-g",run:Rp},{key:"Mod-d",run:Kp,preventDefault:!0}];class im{constructor(e){this.view=e;let t=this.query=e.state.field(ot).query.spec;this.commit=this.commit.bind(this),this.searchField=Z("input",{value:t.search,placeholder:be(e,"Find"),"aria-label":be(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Z("input",{value:t.replace,placeholder:be(e,"Replace"),"aria-label":be(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Z("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=Z("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=Z("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return Z("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=Z("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>On(e),[be(e,"next")]),i("prev",()=>Bn(e),[be(e,"previous")]),i("select",()=>Zp(e),[be(e,"all")]),Z("label",null,[this.caseField,be(e,"match case")]),Z("label",null,[this.reField,be(e,"regexp")]),Z("label",null,[this.wordField,be(e,"by word")]),...e.state.readOnly?[]:[Z("br"),this.replaceField,i("replace",()=>cl(e),[be(e,"replace")]),i("replaceAll",()=>tm(e),[be(e,"replace all")])],Z("button",{name:"close",onclick:()=>Vh(e),"aria-label":be(e,"close"),type:"button"},["×"])])}commit(){let e=new Ph({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:ki.of(e)}))}keydown(e){nu(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Bn:On)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),cl(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(ki)&&!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(Qt).top}}function be(s,e){return s.state.phrase(e)}const Qi=30,Zi=/[\s\.,:;?!]/;function Rr(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-Qi),o=Math.min(n,t+Qi),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Qi;a++)if(!Zi.test(l[a+1])&&Zi.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-Qi;a--)if(!Zi.test(l[a-1])&&Zi.test(l[a])){l=l.slice(0,a);break}}return T.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const nm=T.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"}}),sm=[ot,Mt.low(Qp),nm];class zh{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=Te(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(qh(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 ul(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 rm(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=ul(e)+ul(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function om(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:rm(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}function ug(s,e){return t=>{for(let i=Te(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class dl{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function kt(s){return s.selection.main.from}function qh(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 Ir=Ze.define();function lm(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:b.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const pl=new WeakMap;function am(s){if(!Array.isArray(s))return s;let e=pl.get(s);return e||pl.set(s,e=om(s)),e}const Ln=N.define(),Si=N.define();class hm{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<e.length;){let i=tt(e,t),n=bt(i);this.chars.push(i);let r=e.slice(t,t+n),o=r.toUpperCase();this.folded.push(tt(o==r?r.toLowerCase():o,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:n,precise:r,byWord:o}=this;if(t.length==1){let x=tt(e,0),v=bt(x),D=v==e.length?0:-100;if(x!=t[0])if(x==i[0])D+=-200;else return null;return this.ret(D,[0,v])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let x=0,v=Math.min(e.length,200);x<v&&h<a;){let D=tt(e,x);(D==t[h]||D==i[h])&&(n[h++]=x),x+=bt(D)}if(h<a)return null}let f=0,c=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let x=0,v=Math.min(e.length,200),D=0;x<v&&c<a;){let S=tt(e,x);l<0&&(f<a&&S==t[f]&&(r[f++]=x),d<a&&(S==t[d]||S==i[d]?(d==0&&(p=x),m=x+1,d++):d=0));let M,A=S<255?S>=48&&S<=57||S>=97&&S<=122?2:S>=65&&S<=90?1:0:(M=Al(S))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!x||A==1&&g||D==0&&A!=0)&&(t[c]==S||i[c]==S&&(u=!0)?o[c++]=x:o.length&&(y=!1)),D=A,x+=bt(S)}return c==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(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]):c==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,e)}result(e,t,i){let n=[],r=0;for(let o of t){let l=o+(this.astral?bt(tt(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 fm{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const ee=C.define({combine(s){return Yt(s,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:cm,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=>ml(e(i),t(i)),optionClass:(e,t)=>i=>ml(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function ml(s,e){return s?e?s+" "+e:s:e}function cm(s,e,t,i,n,r){let o=s.textDirection==j.RTL,l=o,a=!1,h="top",f,c,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))f=Math.max(n.top,Math.min(t.top,n.bottom-m))-e.top,c=Math.min(400,l?u:d);else{a=!0,c=Math.min(400,(o?e.right:n.right-e.left)-30);let x=n.bottom-e.bottom;x>=m||x>e.top?f=t.bottom-e.top:(h="bottom",f=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${f/g}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const Pr=N.define();function um(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;h<r.length;){let f=r[h++],c=r[h++];f>a&&o.appendChild(document.createTextNode(l.slice(a,f)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(f,c))),u.className="cm-completionMatchedText",a=c}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function ms(s,e,t){if(s<=t)return{from:0,to:s};if(e<0&&(e=0),e<=s>>1){let n=Math.floor(e/t);return{from:n*t,to:(n+1)*t}}let i=Math.floor((s-e)/t);return{from:s-(i+1)*t,to:s-i*t}}class dm{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(ee);this.optionContent=um(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ms(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 f=a.target,c;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(c=/-(\d+)$/.exec(f.id))&&+c[1]<h.length){this.applyCompletion(e,h[+c[1]]),a.preventDefault();return}if(a.target==this.list){let f=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;f!=null&&(e.dispatch({effects:Pr.of(f)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ee).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Si.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=ms(r.length,o,e.state.facet(ee).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.from||t.selected>=this.range.to)&&(this.range=ms(t.options.length,t.selected,this.view.state.facet(ee).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=>we(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&&mm(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<Math.max(r.top,t.top)+10?null:this.view.state.facet(ee).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",o=>{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.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 f=n.appendChild(document.createElement("li"));f.id=t+"-"+o,f.setAttribute("role","option");let c=this.optionClass(l);c&&(f.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&f.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function pm(s,e){return t=>new dm(t,s,e)}function mm(s,e){let t=s.getBoundingClientRect(),i=e.getBoundingClientRect(),n=t.height/s.offsetHeight;i.top<t.top?s.scrollTop-=(t.top-i.top)/n:i.bottom>t.bottom&&(s.scrollTop+=(i.bottom-t.bottom)/n)}function gl(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function gm(s,e){let t=[],i=null,n=null,r=f=>{t.push(f);let{section:c}=f.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=e.facet(ee);for(let f of s)if(f.hasResult()){let c=f.result.getMatch;if(f.result.filter===!1)for(let u of f.result.options)r(new dl(u,f.source,c?c(u):[],1e9-t.length));else{let u=e.sliceDoc(f.from,f.to),d,p=o.filterStrict?new fm(u):new hm(u);for(let m of f.result.options)if(d=p.match(m.label)){let g=m.displayLabel?c?c(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(r(new dl(m,f.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:x}=m.section;n||(n=Object.create(null)),n[x]=Math.max(y,n[x]||-1e9)}}}}if(i){let f=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?n[p.name]-n[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(u))c-=1e5,f[d.name]=c;for(let d of t){let{section:p}=d.completion;p&&(d.score+=f[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let f of t.sort((c,u)=>u.score-c.score||h(c.completion,u.completion))){let c=f.completion;!a||a.label!=c.label||a.detail!=c.detail||a.type!=null&&c.type!=null&&a.type!=c.type||a.apply!=c.apply||a.boost!=c.boost?l.push(f):gl(f.completion)>gl(a)&&(l[l.length-1]=f),a=f.completion}return l}class It{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 It(this.options,yl(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=gm(e,t);if(!l.length)return n&&e.some(h=>h.isPending)?n.setDisabled():null;let a=t.facet(ee).selectOnOpen?0:-1;if(n&&n.selected!=a&&n.selected!=-1){let h=n.options[n.selected].completion;for(let f=0;f<l.length;f++)if(l[f].completion==h){a=f;break}}return new It(l,yl(i,a),{pos:e.reduce((h,f)=>f.hasResult()?Math.min(h,f.from):h,1e8),create:km,above:r.aboveCursor},n?n.timestamp:Date.now(),a,!1)}map(e){return new It(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new It(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class En{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new En(wm,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(ee),r=(i.override||t.languageDataAt("autocomplete",kt(t)).map(am)).map(a=>(this.active.find(f=>f.source==a)||new Me(a,this.active.some(f=>f.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(Nr));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!ym(r,this.active)||l?o=It.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 Me(a.source,0):a));for(let a of e.effects)a.is(Pr)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new En(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?bm:xm}}function ym(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t<s.length&&!s[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let n=t==s.length,r=i==e.length;if(n||r)return n==r;if(s[t++].result!=e[i++].result)return!1}}const bm={"aria-autocomplete":"list"},xm={};function yl(s,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return e>-1&&(t["aria-activedescendant"]=s+"-"+e),t}const wm=[];function Kh(s,e){if(s.isUserEvent("input.complete")){let i=s.annotation(Ir);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 Me{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=Kh(e,t),n=this;(i&8||i&16&&this.touches(e))&&(n=new Me(n.source,0)),i&4&&n.state==0&&(n=new Me(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(Ln))n=new Me(n.source,1,r.value);else if(r.is(Si))n=new Me(n.source,0);else if(r.is(Nr))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(kt(e.state))}}class zt extends Me{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=kt(e.state);if(l>o||!n||t&2&&(kt(e.startState)==this.from||l<this.limit))return new Me(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return vm(n.validFor,e.state,r,o)?new zt(this.source,this.explicit,a,n,r,o):n.update&&(n=n.update(n,r,o,new zh(e.state,l,!1)))?new zt(this.source,this.explicit,a,n,n.from,(i=n.to)!==null&&i!==void 0?i:kt(e.state)):new Me(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new zt(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Me(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function vm(s,e,t,i){if(!s)return!1;let n=e.sliceDoc(t,i);return typeof s=="function"?s(n,t,i,e):qh(s,!0).test(n)}const Nr=N.define({map(s,e){return s.map(t=>t.map(e))}}),ue=De.define({create(){return En.start()},update(s,e){return s.update(e)},provide:s=>[Ra.from(s,e=>e.tooltip),T.contentAttributes.from(s,e=>e.attrs)]});function Wr(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(ue).active.find(n=>n.source==e.source);return i instanceof zt?(typeof t=="string"?s.dispatch({...lm(s.state,t,i.from,i.to),annotations:Ir.of(e.completion)}):t(s,e.completion,i.from,i.to),!0):!1}const km=pm(ue,Wr);function en(s,e="option"){return t=>{let i=t.state.field(ue,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(ee).interactionDelay)return!1;let n=1,r;e=="page"&&(r=Ia(t,i.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-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:Pr.of(l)}),!0}}const Sm=s=>{let e=s.state.field(ue,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<s.state.facet(ee).interactionDelay?!1:Wr(s,e.open.options[e.open.selected])},gs=s=>s.state.field(ue,!1)?(s.dispatch({effects:Ln.of(!0)}),!0):!1,Cm=s=>{let e=s.state.field(ue,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:Si.of(null)}),!0)};class Am{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Mm=50,Tm=1e3,Dm=ce.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(ue).active)e.isPending&&this.startQuery(e)}update(s){let e=s.state.field(ue),t=s.state.facet(ee);if(!s.selectionSet&&!s.docChanged&&s.startState.field(ue)==e)return;let i=s.transactions.some(r=>{let o=Kh(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&s.docChanged||o.updates.length+s.transactions.length>Mm&&Date.now()-o.time>Tm){for(let l of o.context.abortListeners)try{l()}catch(a){we(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(Ln)))&&(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(ue);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(ee).updateSyncTime))}startQuery(s){let{state:e}=this.view,t=kt(e),i=new zh(e,t,s.explicit,this.view),n=new Am(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:Si.of(null)}),we(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(ee).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ee),i=this.view.state.field(ue);for(let n=0;n<this.running.length;n++){let r=this.running[n];if(r.done===void 0)continue;if(this.running.splice(n--,1),r.done){let l=kt(r.updates.length?r.updates[0].startState:this.view.state),a=Math.min(l,r.done.from+(r.active.explicit?0:1)),h=new zt(r.active.source,r.active.explicit,a,r.done,r.done.from,(s=r.done.to)!==null&&s!==void 0?s:l);for(let f of r.updates)h=h.update(f,t);if(h.hasResult()){e.push(h);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Me(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:Nr.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(ue,!1);if(e&&e.tooltip&&this.view.state.facet(ee).closeOnBlur){let t=e.open&&Ia(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Si.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Ln.of(!1)}),20),this.composing=0}}}),Om=typeof navigator=="object"&&/Win/.test(navigator.platform),Bm=Mt.highest(T.domEventHandlers({keydown(s,e){let t=e.state.field(ue,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||s.key.length>1||s.ctrlKey&&!(Om&&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&&Wr(e,i),!1}})),$h=T.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Lm{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class Fr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,he.TrackDel),i=e.mapPos(this.to,1,he.TrackDel);return t==null||i==null?null:new Fr(this.field,t,i)}}class Hr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let h=o,f=/^\t*/.exec(a)[0].length;for(let c=0;c<f;c++)h+=e.facet(Vn);n.push(t+h.length-f),a=h+a.slice(f)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Fr(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1,f=a.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:f&&t[c].name==f)&&(h=c);if(h<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:f}),h=c;for(let u of n)u.field>=h&&u.field++}for(let c of n)if(c.line==i.length&&c.from>r.index){let u=r[2]?3+(r[1]||"").length:2;c.from-=u,c.to-=u}n.push(new Lm(h,i.length,r.index,r.index+f.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let f of n)f.line==i.length&&f.from>h&&(f.from--,f.to--);return a}),i.push(o)}return new Hr(i,n)}}let Em=L.widget({widget:new class extends Ai{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Rm=L.mark({class:"cm-snippetField"});class Zt{constructor(e,t){this.ranges=e,this.active=t,this.deco=L.set(e.map(i=>(i.from==i.to?Em:Rm).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new Zt(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const Li=N.define({map(s,e){return s&&s.map(e)}}),Im=N.define(),Ci=De.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(Li))return t.value;if(t.is(Im)&&s)return new Zt(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>T.decorations.from(s,e=>e?e.deco:L.none)});function Vr(s,e){return b.create(s.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Pm(s){let e=Hr.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),{main:a}=t.state.selection,h={changes:{from:n,to:r==a.from?a.to:r,insert:P.of(o)},scrollIntoView:!0,annotations:i?[Ir.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(h.selection=Vr(l,0)),l.some(f=>f.field>0)){let f=new Zt(l,0),c=h.effects=[Li.of(f)];t.state.field(Ci,!1)===void 0&&c.push(N.appendConfig.of([Ci,Vm,zm,$h]))}t.dispatch(t.state.update(h))}}function jh(s){return({state:e,dispatch:t})=>{let i=e.field(Ci,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:Vr(i.ranges,n),effects:Li.of(r?null:new Zt(i.ranges,n)),scrollIntoView:!0})),!0}}const Nm=({state:s,dispatch:e})=>s.field(Ci,!1)?(e(s.update({effects:Li.of(null)})),!0):!1,Wm=jh(1),Fm=jh(-1),Hm=[{key:"Tab",run:Wm,shift:Fm},{key:"Escape",run:Nm}],bl=C.define({combine(s){return s.length?s[0]:Hm}}),Vm=Mt.highest(vr.compute([bl],s=>s.facet(bl)));function dg(s,e){return{...e,apply:Pm(s)}}const zm=T.domEventHandlers({mousedown(s,e){let t=e.state.field(Ci,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:Vr(t.ranges,n.field),effects:Li.of(t.ranges.some(r=>r.field>n.field)?new Zt(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),Uh=new class extends lt{};Uh.startSide=1;Uh.endSide=-1;function pg(s={}){return[Bm,ue,ee.of(s),Dm,Km,$h]}const qm=[{key:"Ctrl-Space",run:gs},{mac:"Alt-`",run:gs},{mac:"Alt-i",run:gs},{key:"Escape",run:Cm},{key:"ArrowDown",run:en(!0)},{key:"ArrowUp",run:en(!1)},{key:"PageDown",run:en(!0,"page")},{key:"PageUp",run:en(!1,"page")},{key:"Enter",run:Sm}],Km=Mt.highest(vr.computeN([ee],s=>s.facet(ee).defaultKeymap?[qm]:[]));export{lg as $,Ee as A,Vn as B,zh as C,Cu as D,T as E,F,Rt as G,Ja as H,V as I,kn as J,Mr as K,Qm as L,rg as M,za as N,De as O,Lu as P,Um as Q,ct as R,N as S,X as T,R as U,Rn as V,Gm as W,jm as X,Jm as Y,og as Z,fg as _,ye as a,pg as a0,hg as a1,ag as a2,cg as a3,E as b,om as c,_u as d,Xs as e,Zu as f,eg as g,tg as h,ug as i,Zm as j,ng as k,sg as l,dg as m,Te as n,b as o,Ju as p,_m as q,Ym as r,Ku as s,B as t,md as u,ke as v,Mt as w,vr as x,ig as y,In as z};
|
|
3
|
+
`){[e,t]=qt(this,e,t);let n="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(n+=i),e<a&&t>o&&(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 ze))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 J(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,h=-1,f=[];function c(d){let p;if(d.lines>r&&d instanceof ze)for(let m of d.children)c(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof J&&a&&(p=f[f.length-1])instanceof J&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,f[f.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,h+=d.length+1,f.push(d))}function u(){a!=0&&(l.push(f.length==1?f[0]:ze.from(f,h)),h=-1,a=f.length=0)}for(let d of e)c(d);return u(),l.length==1?l[0]:new ze(l,t)}}P.empty=new J([""],0);function _h(s){let e=-1;for(let t of s)e+=t.length+1;return e}function en(s,e,t=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],a=n+l.length;a>=t&&(a>i&&(l=l.slice(0,i-n)),n<t&&(l=l.slice(t-n)),o?(e[e.length-1]+=l,o=!1):e.push(l)),n=a+1}return e}function Ur(s,e,t){return en(s,[""],e,t)}class ai{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof J?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],o=r>>1,l=n instanceof J?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
4
|
+
`,this;e--}else if(n instanceof J){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof J?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Sl{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ai(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 Cl{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"&&(P.prototype[Symbol.iterator]=function(){return this.iter()},ai.prototype[Symbol.iterator]=Sl.prototype[Symbol.iterator]=Cl.prototype[Symbol.iterator]=function(){return this});class Yh{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 qt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function te(s,e,t=!0,i=!0){return Gh(s,e,t,i)}function Xh(s){return s>=56320&&s<57344}function Qh(s){return s>=55296&&s<56320}function tt(s,e){let t=s.charCodeAt(e);if(!Qh(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return Xh(i)?(t-55296<<10)+(i-56320)+65536:t}function Al(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function bt(s){return s<65536?1:2}const bs=/\r\n?|\n/;var he=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(he||(he={}));class Ge{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(e,t=!1){xs(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new Ge(e)}composeDesc(e){return this.empty?e:e.empty?this:Ml(this,e)}mapDesc(e,t=!1){return e.empty?this:ws(this,e,t)}mapPos(e,t=-1,i=he.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=n+l;if(a<0){if(h>e)return r+(e-n);r+=l}else{if(i!=he.Simple&&h>=e&&(i==he.TrackDel&&n<e&&h>e||i==he.TrackBefore&&n<e||i==he.TrackAfter&&h>e))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<this.sections.length&&n<=t;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Ge(e)}static create(e){return new Ge(e)}}class Q extends Ge{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 xs(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return ws(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length<a;)i.push(P.empty);i.push(o?e.slice(r,r+o):P.empty)}r+=o}return new Q(t,i)}compose(e){return this.empty?e:e.empty?this:Ml(this,e,!0)}map(e,t=!1){return e.empty?this:ws(this,e,t,!0)}iterChanges(e,t=!1){xs(this,e,t)}get desc(){return Ge.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new di(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let f=Math.min(r.len,a-l);re(n,f,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;re(t,f,c),c>0&&rt(i,t,r.text),r.forward(f),l+=f}let h=e[o++];for(;l<h;){if(r.done)break e;let f=Math.min(r.len,h-l);re(t,f,-1),re(n,f,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(f),l+=f}}return{changes:new Q(t,i),filtered:Ge.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):n==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(f=!1){if(!f&&!n.length)return;o<t&&re(n,t-o,-1);let c=new Q(n,r);l=l?l.compose(c.map(l)):c,n=[],r=[],o=0}function h(f){if(Array.isArray(f))for(let c of f)h(c);else if(f instanceof Q){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);a(),l=l?l.compose(f.map(l)):f}else{let{from:c,to:u=c,insert:d}=f;if(c>u||c<0||u>t)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?P.of(d.split(i||bs)):d:P.empty,m=p.length;if(c==u&&m==0)return;c<o&&a(),c>o&&re(n,c-o,-1),re(n,u-c,m),rt(r,n,p),o=u}}return h(e),a(!l),l}static empty(e){return new Q(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<n;)i.push(P.empty);i[n]=P.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new Q(t,i)}static createSet(e,t){return new Q(e,t)}}function re(s,e,t,i=!1){if(e==0&&t<=0)return;let n=s.length-2;n>=0&&t<=0&&t==s[n+1]?s[n]+=e:n>=0&&e==0&&s[n]==0?s[n+1]+=t:i?(s[n]+=e,s[n+1]+=t):s.push(e,t)}function rt(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(t);else{for(;s.length<i;)s.push(P.empty);s.push(t)}}function xs(s,e,t){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],a=s.sections[o++];if(a<0)n+=l,r+=l;else{let h=n,f=r,c=P.empty;for(;h+=l,f+=a,a&&i&&(c=c.append(i[o-2>>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];e(n,h,r,f,c),n=h,r=f}}}function ws(s,e,t,i=!1){let n=[],r=i?[]:null,o=new di(s),l=new di(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);re(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<o.len||l.len==o.len&&!t))){let h=l.len;for(re(n,l.ins,-1);h;){let f=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=f&&(re(n,0,o.ins),r&&rt(r,n,o.text),a=o.i),o.forward(f),h-=f}l.next()}else if(o.ins>=0){let h=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);h+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.len<f)f-=l.len,l.next();else break;re(n,h,a<o.i?o.ins:0),r&&a<o.i&&rt(r,n,o.text),a=o.i,o.forward(o.len-f)}else{if(o.done&&l.done)return r?Q.createSet(n,r):Ge.create(n);throw new Error("Mismatched change set lengths")}}}function Ml(s,e,t=!1){let i=[],n=t?[]:null,r=new di(s),o=new di(e);for(let l=!1;;){if(r.done&&o.done)return n?Q.createSet(i,n):Ge.create(i);if(r.ins==0)re(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)re(i,0,o.ins,l),n&&rt(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let f=o.ins==-1?-1:o.off?0:o.ins;re(i,a,f,l),n&&f&&rt(n,i,o.text)}else o.ins==-1?(re(i,r.off?0:r.len,a,l),n&&rt(n,i,r.textBit(a))):(re(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&rt(n,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class di{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?P.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?P.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 wt{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 wt(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(e.anchor,e.head)}static create(e,t,i){return new wt(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(e.ranges.map(t=>wt.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,n){return wt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(e,t,i,n,r){let o=(i??16777215)<<6|(n==null?7:Math.min(6,n));return!r&&e!=t&&(r=t<e?1:-1),t<e?wt.create(t,e,48|o):wt.create(e,t,(r?r<0?8:16:0)|o)}static normalized(e,t=0){let i=e[t];e.sort((n,r)=>n.from-r.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let r=e[n],o=e[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);n<=t&&t--,e.splice(--n,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(e,t)}}function Tl(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let or=0;class C{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=or++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new C(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:lr),!!e.static,e.enables)}of(e){return new tn([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new tn(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new tn(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function lr(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class tn{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=or++}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,f=[];for(let c of this.dependencies)c=="doc"?a=!0:c=="selection"?h=!0:(((t=e[c.id])!==null&&t!==void 0?t:1)&1)==0&&f.push(e[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||vs(c,f)){let d=i(c);if(l?!Gr(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[r];if(p!=null){let m=hn(u,p);if(this.dependencies.every(g=>g instanceof C?u.facet(g)===c.facet(g):g instanceof De?u.field(g,!1)==c.field(g,!1):!0)||(l?Gr(d=i(c),m,n):n(d=i(c),m)))return c.values[o]=m,0}else d=i(c);return c.values[o]=d,1}}}}function Gr(s,e,t){if(s.length!=e.length)return!1;for(let i=0;i<s.length;i++)if(!t(s[i],e[i]))return!1;return!0}function vs(s,e){let t=!1;for(let i of e)hi(s,i)&1&&(t=!0);return t}function Zh(s,e,t){let i=t.map(a=>s[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 f=0;f<i.length;f++){let c=hn(a,i[f]);if(n[f]==2)for(let u of c)h.push(u);else h.push(c)}return e.combine(h)}return{create(a){for(let h of i)hi(a,h);return a.values[o]=l(a),1},update(a,h){if(!vs(a,r))return 0;let f=l(a);return e.compare(f,a.values[o])?0:(a.values[o]=f,1)},reconfigure(a,h){let f=vs(a,i),c=h.config.facets[e.id],u=h.facet(e);if(c&&!f&&lr(t,c))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Ri=C.define({static:!0});class De{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new De(or++,e.create,e.update,e.compare||((i,n)=>i===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ri).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>{let r=i.facet(Ri),o=n.facet(Ri),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,Ri.of({field:this,create:e})]}get extension(){return this}}const xt={lowest:4,low:3,default:2,high:1,highest:0};function ti(s){return e=>new Dl(e,s)}const Mt={highest:ti(xt.highest),high:ti(xt.high),default:ti(xt.default),low:ti(xt.low),lowest:ti(xt.lowest)};class Dl{constructor(e,t){this.inner=e,this.prec=t}}class Rn{of(e){return new ks(this,e)}reconfigure(e){return Rn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ks{constructor(e,t){this.compartment=e,this.inner=t}}class an{constructor(e,t,i,n,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),o=new Map;for(let u of ef(e,t,o))u instanceof De?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 f=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,m=f&&f[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,lr(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(y=>y.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(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>Zh(g,p,d))}}let c=h.map(u=>u(l));return new an(e,o,c,l,a,r)}}function ef(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 ks&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof ks){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 Dl)r(o.inner,o.prec);else if(o instanceof De)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof tn)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,xt.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,xt.default),i.reduce((o,l)=>o.concat(l))}function hi(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 hn(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const Ol=C.define(),Ss=C.define({combine:s=>s.some(e=>e),static:!0}),Bl=C.define({combine:s=>s.length?s[0]:void 0,static:!0}),Ll=C.define(),El=C.define(),Rl=C.define(),Il=C.define({combine:s=>s.length?s[0]:!1});class Ze{constructor(e,t){this.type=e,this.value=t}static define(){return new tf}}class tf{of(e){return new Ze(this,e)}}class nf{constructor(e){this.map=e}of(e){return new N(this,e)}}class N{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 N(this.type,t)}is(e){return this.type==e}static define(e={}){return new nf(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}}N.reconfigure=N.define();N.appendConfig=N.define();class Y{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&&Tl(i,t.newLength),r.some(l=>l.type==Y.time)||(this.annotations=r.concat(Y.time.of(Date.now())))}static create(e,t,i,n,r,o){return new Y(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(Y.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Y.time=Ze.define();Y.userEvent=Ze.define();Y.addToHistory=Ze.define();Y.remote=Ze.define();function sf(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==e.length||e[n]>=s[i]))r=s[i++],o=s[i++];else if(n<e.length)r=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Pl(s,e,t){var i;let n,r,o;return t?(n=e.changes,r=Q.empty(e.changes.length),o=s.changes.compose(e.changes)):(n=e.changes.map(s.changes),r=s.changes.mapDesc(e.changes,!0),o=s.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:N.mapEffects(s.effects,n).concat(N.mapEffects(e.effects,r)),annotations:s.annotations.length?s.annotations.concat(e.annotations):e.annotations,scrollIntoView:s.scrollIntoView||e.scrollIntoView}}function Cs(s,e,t){let i=e.selection,n=Pt(e.annotations);return e.userEvent&&(n=n.concat(Y.userEvent.of(e.userEvent))),{changes:e.changes instanceof Q?e.changes:Q.of(e.changes||[],t,s.facet(Bl)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Pt(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function Nl(s,e,t){let i=Cs(s,e.length?e[0]:{},s.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Pl(i,Cs(s,e[r],o?i.changes.newLength:s.doc.length),o)}let n=Y.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return of(t?rf(n):n)}function rf(s){let e=s.startState,t=!0;for(let n of e.facet(Ll)){let r=n(s);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:sf(t,r))}if(t!==!0){let n,r;if(t===!1)r=s.changes.invertedDesc,n=Q.empty(e.doc.length);else{let o=s.changes.filter(t);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=Y.create(e,n,s.selection&&s.selection.map(r),N.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=e.facet(El);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof Y?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Y?s=r[0]:s=Nl(e,Pt(r),!1)}return s}function of(s){let e=s.startState,t=e.facet(Rl),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=Pl(i,Cs(e,r,s.changes.newLength),!0))}return i==s?s:Y.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const lf=[];function Pt(s){return s==null?lf:Array.isArray(s)?s:[s]}var _=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(_||(_={}));const af=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let As;try{As=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function hf(s){if(As)return As.test(s);for(let e=0;e<s.length;e++){let t=s[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||af.test(t)))return!0}return!1}function ff(s){return e=>{if(!/\S/.test(e))return _.Space;if(hf(e))return _.Word;for(let t=0;t<s.length;t++)if(e.indexOf(s[t])>-1)return _.Word;return _.Other}}class F{constructor(e,t,i,n,r,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)hi(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return hi(this,i),hn(this,i)}update(...e){return Nl(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:n}=t;for(let l of e.effects)l.is(Rn.reconfigure)?(t&&(n=new Map,t.compartments.forEach((a,h)=>n.set(h,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(N.reconfigure)?(t=null,i=l.value):l.is(N.appendConfig)&&(t=null,i=Pt(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=an.resolve(i,n,this),r=new F(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Ss)?e.newSelection:e.newSelection.asSingle();new F(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:b.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Pt(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),f=h.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(f);let c=n.mapDesc(h,!0);r.push(a.range.map(c)),n=n.compose(f),o=N.mapEffects(o,f).concat(N.mapEffects(Pt(a.effects),c))}return{changes:n,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Q?e:Q.of(e,this.doc.length,this.facet(F.lineSeparator))}toText(e){return P.of(e.split(this.facet(F.lineSeparator)||bs))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(hi(this,t),hn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof De&&this.config.address[n.id]!=null&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return F.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=an.resolve(e.extensions||[],new Map),i=e.doc instanceof P?e.doc:P.of((e.doc||"").split(t.staticFacet(F.lineSeparator)||bs)),n=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return Tl(n,i.length),t.staticFacet(Ss)||(n=n.asSingle()),new F(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(F.tabSize)}get lineBreak(){return this.facet(F.lineSeparator)||`
|
|
5
|
+
`}get readOnly(){return this.facet(Il)}phrase(e,...t){for(let i of this.facet(F.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet(Ol))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return ff(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=te(t,o,!1);if(r(t.slice(a,o))!=_.Word)break;o=a}for(;l<n;){let a=te(t,l);if(r(t.slice(l,a))!=_.Word)break;l=a}return o==l?null:b.range(o+i,l+i)}}F.allowMultipleSelections=Ss;F.tabSize=C.define({combine:s=>s.length?s[0]:4});F.lineSeparator=Bl;F.readOnly=Il;F.phrases=C.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])}});F.languageData=Ol;F.changeFilter=Ll;F.transactionFilter=El;F.transactionExtender=Rl;Rn.reconfigure=N.define();function Yt(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 lt{eq(e){return this==e}range(e,t=e){return Ms.create(e,t,this)}}lt.prototype.startSide=lt.prototype.endSide=0;lt.prototype.point=!1;lt.prototype.mapMode=he.TrackDel;function ar(s,e){return s==e||s.constructor==e.constructor&&s.eq(e)}let Ms=class Wl{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Wl(e,t,i)}};function Ts(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class hr{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);r<o;r++)if(n(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],n=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],f=this.from[a]+e,c=this.to[a]+e,u,d;if(f==c){let p=t.mapPos(f,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(f,h.endSide),d<u)))continue}else if(u=t.mapPos(f,h.startSide),d=t.mapPos(c,h.endSide),u>d||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 hr(n,r,i,l):null,pos:o}}}class I{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 I(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(Ts)),this.isEmpty)return t.length?I.of(t):this;let l=new Fl(this,null,-1).goto(0),a=0,h=[],f=new Kt;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let c=t[a++];f.addInner(c.from,c.to,c.value)||h.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&f.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||n>l.to||r<l.from||o(l.from,l.to,l.value))&&(f.addInner(l.from,l.to,l.value)||h.push(Ms.create(l.from,l.to,l.value))),l.next());return f.finishInner(this.nextLayer.isEmpty&&!h.length?I.empty:this.nextLayer.update({add:h,filter:o,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)n=Math.max(n,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:f,pos:c}=a.map(l,e);f&&(n=Math.max(n,f.maxPoint),t.push(f),i.push(c))}}let r=this.nextLayer.map(e);return t.length==0?r:new I(i,t,r||I.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return pi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return pi.from(e).goto(t)}static compare(e,t,i,n,r=-1){let o=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),a=Jr(o,l,i),h=new ii(o,a,r),f=new ii(l,a,r);i.iterGaps((c,u,d)=>_r(h,c,f,u,d,n)),i.empty&&i.length==0&&_r(h,0,f,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),o=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Jr(r,o),a=new ii(r,l,0).goto(i),h=new ii(o,l,0).goto(i);for(;;){if(a.to!=h.to||!Ds(a.active,h.active)||a.point&&(!h.point||!ar(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 ii(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFrom<t?f.length+1:o.point.startSide<0?f.length:Math.min(f.length,a);n.point(l,h,o.point,f,c,o.pointRank),a=Math.min(o.openEnd(h),f.length)}else h>l&&(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 Kt;for(let n of e instanceof Ms?[e]:t?cf(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return I.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=I.empty;n=n.nextLayer)t=new I(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}I.empty=new I([],[],null,-1);function cf(s){if(s.length>1)for(let e=s[0],t=1;t<s.length;t++){let i=s[t];if(Ts(e,i)>0)return s.slice().sort(Ts);e=i}return s}I.empty.nextLayer=I.empty;class Kt{finishChunk(e){this.chunks.push(new hr(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 Kt)).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(I.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=I.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Jr(s,e,t){let i=new Map;for(let r of s)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let n=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class Fl{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<e||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class pi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Fl(o,t,i,r));return n.length==1?n[0]:new pi(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--)Gn(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--)Gn(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(),Gn(this.heap,0)}}}function Gn(s,e){for(let t=s[e];;){let i=(e<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1<s.length&&n.compare(s[i+1])>=0&&(n=s[i+1],i++),t.compare(n)<0)break;s[i]=t,s[e]=n,e=i}}class ii{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=pi.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){Ii(this.active,e),Ii(this.activeTo,e),Ii(this.activeRank,e),this.minActive=Yr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;Pi(this.active,t,i),Pi(this.activeTo,t,n),Pi(this.activeRank,t,r),e&&Pi(e,t,this.cursor.from),this.minActive=Yr(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&&Ii(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<e;n--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function _r(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 f=!1;;){let c=s.to+a-t.to,u=c||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&&ar(s.point,t.point)&&Ds(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,p,s.point,t.point),f=!1):(f&&r.boundChange(l),p>l&&!Ds(s.active,t.active)&&r.compareRange(l,p,s.active,t.active),h&&p<o&&(c||s.openEnd(d)!=t.openEnd(d))&&(f=!0)),d>o)break;l=d,u<=0&&s.next(),u>=0&&t.next()}}function Ds(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(s[t]!=e[t]&&!ar(s[t],e[t]))return!1;return!0}function Ii(s,e){for(let t=e,i=s.length-1;t<i;t++)s[t]=s[t+1];s.pop()}function Pi(s,e,t){for(let i=s.length-1;i>=e;i--)s[i+1]=s[i];s[e]=t}function Yr(s,e){let t=-1,i=1e9;for(let n=0;n<e.length;n++)(e[n]-i||s[n].endSide-s[t].endSide)<0&&(t=n,i=e[n]);return t}function In(s,e,t=s.length){let i=0;for(let n=0;n<t&&n<s.length;)s.charCodeAt(n)==9?(i+=e-i%e,n++):(i++,n=te(s,n));return i}function uf(s,e,t,i){for(let n=0,r=0;;){if(r>=e)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?t-r%t:1,n=te(s,n)}return s.length}const Os="ͼ",Xr=typeof Symbol>"u"?"__"+Os:Symbol.for(Os),Bs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Qr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class at{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 f=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,f,u)}else p!=null&&f.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(f.length||u)&&a.push((i&&!c&&!h?o.map(i):o).join(", ")+" {"+f.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
6
|
+
`)}static newName(){let e=Qr[Xr]||1;return Qr[Xr]=e+1,Os+e.toString(36)}static mount(e,t,i){let n=e[Bs],r=i&&i.nonce;n?r&&n.setNonce(r):n=new df(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let Zr=new Map;class df{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let r=Zr.get(i);if(r)return e[Bs]=r;this.sheet=new n.CSSStyleSheet,Zr.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Bs]=this}mount(e,t){let i=this.sheet,n=0,r=0;for(let o=0;o<e.length;o++){let l=e[o],a=this.modules.indexOf(l);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let h=0;h<l.rules.length;h++)i.insertRule(l.rules[h],n++)}else{for(;r<a;)n+=this.modules[r++].rules.length;n+=l.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+`
|
|
7
|
+
`;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var ht={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},mi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},pf=typeof navigator<"u"&&/Mac/.test(navigator.platform),mf=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var se=0;se<10;se++)ht[48+se]=ht[96+se]=String(se);for(var se=1;se<=24;se++)ht[se+111]="F"+se;for(var se=65;se<=90;se++)ht[se]=String.fromCharCode(se+32),mi[se]=String.fromCharCode(se);for(var Jn in ht)mi.hasOwnProperty(Jn)||(mi[Jn]=ht[Jn]);function gf(s){var e=pf&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||mf&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?mi:ht)[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 Z(){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(;e<arguments.length;e++)Hl(s,arguments[e]);return s}function Hl(s,e){if(typeof e=="string")s.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)s.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)Hl(s,e[t]);else throw new RangeError("Unsupported child node: "+e)}let ae=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ls=typeof document<"u"?document:{documentElement:{style:{}}};const Es=/Edge\/(\d+)/.exec(ae.userAgent),Vl=/MSIE \d/.test(ae.userAgent),Rs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ae.userAgent),Pn=!!(Vl||Rs||Es),eo=!Pn&&/gecko\/(\d+)/i.test(ae.userAgent),_n=!Pn&&/Chrome\/(\d+)/.exec(ae.userAgent),yf="webkitFontSmoothing"in Ls.documentElement.style,Is=!Pn&&/Apple Computer/.test(ae.vendor),to=Is&&(/Mobile\/\w+/.test(ae.userAgent)||ae.maxTouchPoints>2);var k={mac:to||/Mac/.test(ae.platform),windows:/Win/.test(ae.platform),linux:/Linux|X11/.test(ae.platform),ie:Pn,ie_version:Vl?Ls.documentMode||6:Rs?+Rs[1]:Es?+Es[1]:0,gecko:eo,gecko_version:eo?+(/Firefox\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,chrome:!!_n,chrome_version:_n?+_n[1]:0,ios:to,android:/Android\b/.test(ae.userAgent),webkit_version:yf?+(/\bAppleWebKit\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,safari:Is,safari_version:Is?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ae.userAgent)||[0,0])[1]:0,tabSize:Ls.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function fr(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 fn=Object.create(null);function cr(s,e,t){if(s==e)return!0;s||(s=fn),e||(e=fn);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 bf(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 io(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 xf(s){let e=Object.create(null);for(let t=0;t<s.attributes.length;t++){let i=s.attributes[t];e[i.name]=i.value}return e}class Ci{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var me=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(me||(me={}));class L extends lt{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new Ai(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new St(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}=zl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new St(e,i,n,t,e.widget||null,!0)}static line(e){return new Mi(e)}static set(e,t=!1){return I.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}L.none=I.empty;class Ai extends L{constructor(e){let{start:t,end:i}=zl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?fr(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||fn}eq(e){return this==e||e instanceof Ai&&this.tagName==e.tagName&&cr(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)}}Ai.prototype.point=!1;class Mi extends L{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Mi&&this.spec.class==e.spec.class&&cr(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Mi.prototype.mapMode=he.TrackBefore;Mi.prototype.point=!0;class St extends L{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?he.TrackBefore:he.TrackAfter:he.TrackDel}get type(){return this.startSide!=this.endSide?me.WidgetRange:this.startSide<=0?me.WidgetBefore:me.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof St&&wf(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)}}St.prototype.point=!0;function zl(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 wf(s,e){return s==e||!!(s&&e&&s.compare(e))}function Nt(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 gi extends lt{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof gi&&this.tagName==e.tagName&&cr(this.attributes,e.attributes)}static create(e){return new gi(e.tagName,e.attributes||fn)}static set(e,t=!1){return I.of(e,t)}}gi.prototype.startSide=gi.prototype.endSide=-1;function yi(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function Ps(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function fi(s,e){if(!e.anchorNode)return!1;try{return Ps(s,e.anchorNode)}catch{return!1}}function nn(s){return s.nodeType==3?bi(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ci(s,e,t,i){return t?no(s,e,t,i,-1)||no(s,e,t,i,1):!1}function ft(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function cn(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function no(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:Qe(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=ft(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?Qe(s):0}else return!1}}function Qe(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function un(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function vf(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 ql(s,e){let t=e.width/s.offsetWidth,i=e.height/s.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-s.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-s.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function kf(s,e,t,i,n,r,o,l){let a=s.ownerDocument,h=a.defaultView||window;for(let f=s,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==a.body,p=1,m=1;if(d)u=vf(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let x=f.getBoundingClientRect();({scaleX:p,scaleY:m}=ql(f,x)),u={left:x.left,right:x.left+f.clientWidth*p,top:x.top,bottom:x.top+f.clientHeight*m}}let g=0,y=0;if(n=="nearest")e.top<u.top+o?(y=e.top-(u.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=e.top-(u.top+o)));else{let x=e.bottom-e.top,v=u.bottom-u.top;y=(n=="center"&&x<=v?e.top+x/2-v/2:n=="start"||n=="center"&&t<0?e.top-o:e.bottom-v+o)-u.top}if(i=="nearest"?e.left<u.left+r?(g=e.left-(u.left+r),t>0&&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.left<u.left+g&&(g=e.left-(u.left+r))):g=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,g||y)if(d)h.scrollBy(g,y);else{let x=0,v=0;if(y){let D=f.scrollTop;f.scrollTop+=y/m,v=(f.scrollTop-D)*m}if(g){let D=f.scrollLeft;f.scrollLeft+=g/p,x=(f.scrollLeft-D)*p}e={left:e.left-x,top:e.top-v,right:e.right-x,bottom:e.bottom-v},x&&Math.abs(x-g)<1&&(i="nearest"),v&&Math.abs(v-y)<1&&(n="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function Kl(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 Sf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Qe(t):0),i,Math.min(e.focusOffset,i?Qe(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let yt=null;k.safari&&k.safari_version>=26&&(yt=!1);function $l(s){if(s.setActive)return s.setActive();if(yt)return s.focus(yt);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(yt==null?{get preventScroll(){return yt={preventScroll:!0},!0}}:void 0),!yt){yt=!1;for(let t=0;t<e.length;){let i=e[t++],n=e[t++],r=e[t++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let so;function bi(s,e,t=e){let i=so||(so=document.createRange());return i.setEnd(s,t),i.setStart(s,e),i}function Wt(s,e,t,i){let n={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Cf(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Af(s,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Qe(t));;)if(i){if(t.nodeType!=1)return!1;let n=t.childNodes[i-1];n.contentEditable=="false"?i--:(t=n,i=Qe(t))}else{if(t==s)return!0;i=ft(t),t=t.parentNode}}function jl(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Ul(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=Qe(t)}else if(t.parentNode&&!cn(t))i=ft(t),t=t.parentNode;else return null}}function Gl(s,e){for(let t=s,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!cn(t))i=ft(t)+1,t=t.parentNode;else return null}}class Le{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Le(e.parentNode,ft(e),t)}static after(e,t){return new Le(e.parentNode,ft(e)+1,t)}}var j=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(j||(j={}));const Ct=j.LTR,ur=j.RTL;function Jl(s){let e=[];for(let t=0;t<s.length;t++)e.push(1<<+s[t]);return e}const Mf=Jl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Tf=Jl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ns=Object.create(null),We=[];for(let s of["()","[]","{}"]){let e=s.charCodeAt(0),t=s.charCodeAt(1);Ns[e]=t,Ns[t]=-e}function _l(s){return s<=247?Mf[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?Tf[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const Df=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ke{get dir(){return this.level%2?ur:Ct}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Yl(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++){let i=s[t],n=e[t];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Yl(i.inner,n.inner))return!1}return!0}const H=[];function Of(s,e,t,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:n;for(let h=o,f=a,c=a;h<l;h++){let u=_l(s.charCodeAt(h));u==512?u=f:u==8&&c==4&&(u=16),H[h]=u==4?2:u,u&7&&(c=u),f=u}for(let h=o,f=a,c=a;h<l;h++){let u=H[h];if(u==128)h<l-1&&f==H[h+1]&&f&24?u=H[h]=f:H[h]=256;else if(u==64){let d=h+1;for(;d<l&&H[d]==64;)d++;let p=h&&f==8||d<t&&H[d]==8?c==1?1:8:256;for(let m=h;m<d;m++)H[m]=p;h=d-1}else u==8&&c==1&&(H[h]=1);f=u,u&7&&(c=u)}}}function Bf(s,e,t,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,f=o<i.length?i[o].from:t;for(let c=h,u,d,p;c<f;c++)if(d=Ns[u=s.charCodeAt(c)])if(d<0){for(let m=l-3;m>=0;m-=3)if(We[m+1]==-d){let g=We[m+2],y=g&2?n:g&4?g&1?r:n:0;y&&(H[c]=H[We[m]]=y),l=m;break}}else{if(We.length==189)break;We[l++]=c,We[l++]=u,We[l++]=a}else if((p=H[c])==2||p==1){let m=p==n;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=We[g+2];if(y&2)break;if(m)We[g+2]|=2;else{if(y&4)break;We[g+2]|=4}}}}}function Lf(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=n<t.length?t[n].from:e;for(let a=o;a<l;){let h=H[a];if(h==256){let f=a+1;for(;;)if(f==l){if(n==t.length)break;f=t[n++].to,l=n<t.length?t[n].from:e}else if(H[f]==256)f++;else break;let c=r==1,u=(f<e?H[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,m=n,g=m?t[m-1].to:s;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:s),H[--p]=d;a=f}else r=h,a++}}}function Ws(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=e,h=0;a<t;){let f=!0,c=!1;if(h==r.length||a<r[h].from){let m=H[a];m!=l&&(f=!1,c=m==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(c)break e;let m=r[h];if(!f)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<r.length&&r[y].from==g)g=r[y++].to;else{if(H[g]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new Ke(a,m.from,d));let g=m.direction==Ct!=!(d%2);Fs(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(f?H[p]!=l:H[p]==l))break;p++}u?Ws(s,a,p,i+1,n,u,o):a<p&&o.push(new Ke(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let f=!0,c=!1;if(!h||a>r[h-1].to){let m=H[a-1];m!=l&&(f=!1,c=m==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(c)break e;let m=r[--h];if(!f)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&r[y-1].to==g)g=r[--y].from;else{if(H[g-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new Ke(m.to,a,d));let g=m.direction==Ct!=!(d%2);Fs(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(f?H[p-1]!=l:H[p-1]==l))break;p--}u?Ws(s,p,a,i+1,n,u,o):p<a&&o.push(new Ke(p,a,d)),a=p}}function Fs(s,e,t,i,n,r,o){let l=e%2?2:1;Of(s,n,r,i,l),Bf(s,n,r,i,l),Lf(n,r,i,l),Ws(s,n,r,e,t,i,o)}function Ef(s,e,t){if(!s)return[new Ke(0,0,e==ur?1:0)];if(e==Ct&&!t.length&&!Df.test(s))return Xl(s.length);if(t.length)for(;s.length>H.length;)H[H.length]=256;let i=[],n=e==Ct?0:1;return Fs(s,n,n,t,0,s.length,i),i}function Xl(s){return[new Ke(0,s,0)]}let Ql="";function Rf(s,e,t,i,n){var r;let o=i.head-s.from,l=Ke.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 f=te(s.text,o,a.forward(n,t));(f<a.from||f>a.to)&&(f=h),Ql=s.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return c&&f==h&&c.level+(n?0:1)<a.level?b.cursor(c.side(!n,t)+s.from,c.forward(n,t)?1:-1,c.level):b.cursor(f+s.from,a.forward(n,t)?-1:1,a.level)}function If(s,e,t){for(let i=e;i<t;i++){let n=_l(s.charCodeAt(i));if(n==1)return Ct;if(n==2||n==4)return ur}return Ct}const Zl=C.define(),ea=C.define(),ta=C.define(),ia=C.define(),Hs=C.define(),na=C.define(),sa=C.define(),dr=C.define(),pr=C.define(),ra=C.define({combine:s=>s.some(e=>e)}),Pf=C.define({combine:s=>s.some(e=>e)}),oa=C.define();class Ft{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 Ft(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 Ft(b.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ni=N.define({map:(s,e)=>s.map(e)}),la=N.define();function we(s,e,t){let i=s.facet(ia);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 _e=C.define({combine:s=>s.length?s[0]:!0});let Nf=0;const Lt=C.define({combine(s){return s.filter((e,t)=>{for(let i=0;i<t;i++)if(s[i].plugin==e.plugin)return!1;return!0})}});class ce{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(Lt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Lt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=t||{};return new ce(Nf++,e,i,n,l=>{let a=[];return o&&a.push(Nn.of(h=>{let f=h.plugin(l);return f?o(f):L.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return ce.define((i,n)=>new e(i,n),t)}}class Yn{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(we(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){we(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){we(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const aa=C.define(),mr=C.define(),Nn=C.define(),ha=C.define(),gr=C.define(),Ti=C.define(),fa=C.define();function ro(s,e){let t=s.state.facet(fa);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return I.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,f=o-e.from,c=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=If(e.text,h,f)),a>0&&c.length&&(p=c[c.length-1]).to==h&&p.direction==d)p.to=f,c=p.inner;else{let m={from:h,to:f,direction:d,inner:[]};c.push(m),c=m.inner}}}}),n}const ca=C.define();function yr(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(ca)){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 oi=C.define();class Se{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Se(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let n=0,r=0,o=0;;){let l=n<e.length?e[n].fromB:1e9,a=r<t.length?t[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let f=h+o,c=h,u=f;for(;;)if(r<t.length&&t[r]<=c){let d=t[r+1];r+=2,c=Math.max(c,d);for(let p=n;p<e.length&&e[p].fromB<=c;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(n<e.length&&e[n].fromB<=c){let d=e[n++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new Se(f,u,h,c))}return i}}class dn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Q.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new Se(r,o,l,a))),this.changedRanges=n}static create(e,t,i){return new dn(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 Wf=[];class G{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Wf}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&&bf(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=ft(this.dom),n=this.length?e>0:t>0;return new Le(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 Fn)return e;return null}static get(e){return e.cmTile}}class Wn extends G{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,n,r=(e==null?void 0: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=oo(n);else t.insertBefore(l.dom,n);i=l.dom}for(n=i?i.nextSibling:t.firstChild,r&&n&&(r.written=!0);n;)n=oo(n);this.length=o}}function oo(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class Fn extends Wn{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=G.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let o=i.children[n++];if(o instanceof Ye)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)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,n=e-a),(h>e||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 Ye extends Wn{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 Ye(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class $t extends Wn{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new $t(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(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],m=d+p.length;m>=c&&(p.isComposite()?a(p,c-d):(!o||o.isHidden&&(t>0||i&&Hf(o,p)))&&(m>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(n=p,r=c-d)),d=m}}a(this,e);let h=(t<0?n:o)||n||o;return h?{tile:h,offset:h==n?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):Ff(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:n,offset:r}=i;if(this.dom.contains(n.dom))return n.isText()?new Le(n.dom,Math.min(n.dom.nodeValue.length,r)):n.domPosFor(r,n.flags&16?1:n.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new Le(a.dom,0);a==i.tile&&(l=!0)}}return new Le(this.dom,0)}}function Ff(s){let e=s.dom.lastChild;if(!e)return s.dom.getBoundingClientRect();let t=nn(e);return t[t.length-1]||null}function Hf(s,e){let t=s.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class de extends Wn{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new de(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class vt extends G{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?k.chrome||k.gecko||(e?(n--,o=1):r<i&&(r++,o=-1)):t<0?n--:r<i&&r++;let l=bi(this.dom,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return k.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?un(a,o<0):a||null}static of(e,t){let i=new vt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class At extends G{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return un(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.top<o.bottom);a+=l?-1:1);return un(o,!l)}}get overrideDOMText(){if(!this.length)return P.empty;let{root:e}=this;if(!e)return P.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new At(r,i,e,n)}}class pn extends G{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return P.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class Vf{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(n.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==n.children.length){if(!e&&!l.length)break;i&&i.leave(n),o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++}else{let a=n.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,e-=a.length):(l.push({tile:n,index:r}),n=a,r=0,i&&a.isComposite()&&i.enter(a))}else if(r==n.length)o=!!n.breakAfter,{tile:n,index:r}=l.pop(),r++;else if(e){let a=Math.min(e,n.length-r);i&&i.skip(n,r,r+a),e-=a,r+=a}else break;return this.tile=n,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class zf{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class qf{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new vt(l.dom,l.text+e);a.parent=o}else o.append(n||vt.of(e,(r=this.cache.find(vt))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Xn(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=n.lastChild;if(h instanceof de&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(Xn(a.dom)),n=h;else{if(this.cache.reused.get(a)){let c=G.get(a.dom);c&&c.setDOM(Xn(a.dom))}let f=de.of(a.mark,a.dom);n.append(f),n=f}this.cache.reused.set(a,2)}let r=G.get(e.text);r&&this.cache.reused.set(r,2);let o=new vt(e.text,e.text.nodeValue);o.flags|=8,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=ua);let n=$t.start(e,t||((i=this.cache.find($t))===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 de&&l.mark.eq(o))n=l,t--;else{let a=de.of(o,(i=this.cache.find(de,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||!lo(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(k.ios&&lo(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Qn,0,32)||new At(Qn.toDOM(),0,Qn,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new zf(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof Ye&&n.wrapper.eq(i.wrapper))t=n;else{let r=Ye.of(i.wrapper,(e=this.cache.find(Ye,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(pn,void 0,1);return i&&(i.flags=t),i||new pn(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Kf{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 mn=[At,$t,vt,de,pn,Ye,Fn];for(let s=0;s<mn.length;s++)mn[s].bucket=s;class $f{constructor(e){this.view=e,this.buckets=mn.map(()=>[]),this.index=mn.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<o&&this.index[n]--,this.reused.set(h,i),h}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,o=0;;r++){if(r==n.length){if(o)return null;o=1,r=0}let l=n[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new At(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class jf{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new $f(e),this.text=new Kf(e.state.doc),this.builder=new qf(this.cache,new Fn(e,e.contentDOM),I.iter(i)),this.cache.reused.set(t,2),this.old=new Vf(t),this.reuseWalker={skip:(o,l,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=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>n){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<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,n=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=Jf(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?At.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,n,r),r=n.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,n,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),n,r)),r=n.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof pn)this.cache.add(o);else if(o instanceof de)this.builder.ensureLine(null),this.builder.addMark(o,n,r),this.cache.reused.set(o,1),r=n.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof de&&n.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?n.length&&(n.length=r=0):o instanceof de&&(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=I.spans(this.decorations,e,t,{point:(l,a,h,f,c,u)=>{if(h instanceof St){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=f.length,c>f.length)n.continueWidget(a-l);else{let d=h.widget||(h.block?jt.block:jt.inline),p=Uf(h),m=this.cache.findWidget(d,a-l,p)||At.of(d,this.view,a-l,p);h.block?(h.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(m)):(n.ensureLine(i),n.addInlineWidget(m,f,c))}i=null}else i=Gf(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,f)=>{for(let c=l;c<a;){let u=this.text.next(Math.min(512,a-c));u==null?(n.addLineStartIfNotCovered(i),n.addBreak(),c++):(n.ensureLine(i),n.addText(u,h,c==l?f:h.length),c+=u.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let r=G.get(n);if(n==this.view.contentDOM)break;r instanceof de?t.push(r):r!=null&&r.isLine()?i=r:r instanceof Ye||(n.nodeName=="DIV"&&!i&&n!=this.view.contentDOM?i=new $t(n,ua):i||t.push(de.of(new Ai({tagName:n.nodeName.toLowerCase(),attributes:xf(n)}),n)))}return{line:i,marks:t}}}function lo(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 Uf(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 ua={class:"cm-line"};function Gf(s,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(s||(s={class:"cm-line"}),t&&fr(t,s),i&&(s.class+=" "+i)),s}function Jf(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 de&&e.push(i.mark)}return e}function Xn(s){let e=G.get(s);return e&&e.setDOM(s.cloneNode()),s}class jt extends Ci{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}}jt.inline=new jt("span");jt.block=new jt("div");const Qn=new class extends Ci{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class ao{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=L.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 Fn(e,e.contentDOM),this.updateInner([new Se(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?n=this.domChanged.newSel.head:!nc(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Yf(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new Se(f,c,e.changes.mapPos(f,-1),e.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(k.ie||k.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=Zf(o,this.decorations,e.changes);a.length&&(i=Se.extendWithRanges(i,a));let h=tc(l,this.blockWrappers,e.changes);return h.length&&(i=Se.extendWithRanges(i,h)),r&&!i.some(f=>f.fromA<=r.range.fromA&&f.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new jf(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&G.get(t.text)&&l.cache.reused.set(G.get(t.text),2),this.tile=l.run(e,t),Vs(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=k.chrome||k.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof Zn&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(la)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,o=!r&&!(this.view.state.facet(_e)||i.tabIndex>-1)&&fi(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,f;if(a.empty?f=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(f=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),k.gecko&&a.empty&&!this.hasComposition&&_f(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=f=new Le(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!ci(h.node,h.offset,c.anchorNode,c.anchorOffset)||!ci(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,a))&&(this.view.observer.ignore(()=>{k.android&&k.chrome&&i.contains(c.focusNode)&&ic(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=yi(this.view.root);if(u)if(a.empty){if(k.gecko){let d=Xf(h.node,h.offset);if(d&&d!=3){let p=(d==1?Ul:Gl)(h.node,h.offset);p&&(h=new Le(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(f.node,f.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,f]=[f,h]),d.setEnd(f.node,f.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,f)),this.impreciseAnchor=h.precise?null:new Le(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new Le(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ci(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=yi(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 f=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(f.node,f.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let n=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=Qe(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!G.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let o=0,l=n;;o++){let 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,f)=>{if(h.isWidget()){if(h.flags&32&&f>=e)return!0;h.flags&16&&(r=!0)}else{let c=f+h.length;if(f<=e&&(i=h,n=e-f,r=c<e),c>=e&&!o&&(o=h,l=e-f,a=f>e),f>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 Zn?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()&&o<r.length){let l=te(r.text,o);if(l==o)return null;let a=bi(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let f=a[h];if(h==a.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return n(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==j.LTR,h=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>n);p++){let m=c.children[p],g=u+m.length,y=m.dom.getBoundingClientRect(),{height:x}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof Ye)g>i&&f(m,u,y);else if(u>=i&&(h>0&&t.push(-h),t.push(x+h),h=0,o)){let v=m.dom.lastChild,D=v?nn(v):[];if(D.length){let S=D[D.length-1],M=a?S.right-y.left:y.right-S.left;M>l&&(l=M,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=g)}}d&&p==c.children.length-1&&(h+=d.bottom-y.bottom),u=g+m.breakAfter}};return f(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 f=nn(h.dom);if(f.length!=1)return;l+=f[0].width,a=f[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=nn(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(L.replace({widget:new Zn(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return L.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Nn).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(gr).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(I.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ha).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(oa))try{if(f(this.view,e.range,e))return!0}catch(c){we(this.view.state,c,"scroll handler")}let{range:i}=e,n=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!n)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let o=yr(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(kf(this.view.scrollDOM,l,i.head<i.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,a),-a),Math.max(Math.min(e.yMargin,h),-h),this.view.textDirection==j.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(i.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Vs(this.tile)}}function Vs(s,e){let t=e==null?void 0:e.get(s);if(t!=1){t==null&&s.destroy();for(let i of s.children)Vs(i,e)}}function _f(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 da(s,e){let t=s.observer.selectionRange;if(!t.focusNode)return null;let i=Ul(t.focusNode,t.focusOffset),n=Gl(t.focusNode,t.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=G.get(n.node);if(!l||l.isText()&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=G.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 Yf(s,e,t){let i=da(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 Se(a.mapPos(r),a.mapPos(o),r,o),text:n}}function Xf(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e<s.childNodes.length&&s.childNodes[e].contentEditable=="false"?2:0)}let Qf=class{constructor(){this.changes=[]}compareRange(e,t){Nt(e,t,this.changes)}comparePoint(e,t){Nt(e,t,this.changes)}boundChange(e){Nt(e,e,this.changes)}};function Zf(s,e,t){let i=new Qf;return I.compare(s,e,t,i),i.changes}class ec{constructor(){this.changes=[]}compareRange(e,t){Nt(e,t,this.changes)}comparePoint(){}boundChange(e){Nt(e,e,this.changes)}}function tc(s,e,t){let i=new ec;return I.compare(s,e,t,i),i.changes}function ic(s,e){for(let t=s;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function nc(s,e){let t=!1;return e&&s.iterChangedRanges((i,n)=>{i<e.to&&n>e.from&&(t=!0)}),t}class Zn extends Ci{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 sc(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return b.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=te(n.text,r,!1):l=te(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let h=te(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;l<n.length;){let h=te(n.text,l);if(i(n.text.slice(l,h))!=a)break;l=h}return b.range(o+n.from,l+n.from)}function rc(s,e,t,i,n){let r=Math.round((i-e.left)*s.defaultCharacterWidth);if(s.lineWrapping&&t.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,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+uf(o,r,s.state.tabSize)}function oc(s,e,t){let i=s.lineBlockAt(e);if(Array.isArray(i.type)){let n;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!n||r.type==me.Text&&(n.type!=r.type||(t<0?r.from<e:r.to>e)))&&(n=r)}}return n||i}return i}function lc(s,e,t,i){let n=oc(s,e.head,e.assoc||-1),r=!i||n.type!=me.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 b.cursor(a,t?-1:1)}return b.cursor(t?n.to:n.from,t?-1:1)}function ho(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=Rf(n,r,o,l,t),f=Ql;if(!h){if(n.number==(t?s.state.doc.lines:1))return l;f=`
|
|
8
|
+
`,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),h=s.visualLineSide(n,!t)}if(a){if(!a(f))return l}else{if(!i)return h;a=i(f)}l=h}}function ac(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==_.Space&&(n=o),n==o}}function hc(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return b.cursor(n,e.assoc);let o=e.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(n,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),f=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)+f}let c=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=zs(s,{x:c,y:m},!1,r);if(t?m>a.bottom:m<a.top)return b.cursor(g.pos,g.assoc);let y=s.coordsAtPos(g.pos,g.assoc),x=y?(y.top+y.bottom)/2:0;if(!y||(t?x>l:x<l))return b.cursor(g.pos,g.assoc,void 0,o)}}function ui(s,e,t){for(;;){let i=0;for(let n of s)n.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function pa(s,e){let t=null;for(let i=0;i<e.ranges.length;i++){let n=e.ranges[i],r=null;if(n.empty){let o=ui(s,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=ui(s,n.from,-1),l=ui(s,n.to,1);(o!=n.from||l!=n.to)&&(r=b.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}function es(s,e,t){let i=ui(s.state.facet(Ti).map(n=>n(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class qe{constructor(e,t){this.pos=e,this.assoc=t}}function zs(s,e,t,i){let n=s.contentDOM.getBoundingClientRect(),r=n.top+s.viewState.paddingTop,{x:o,y:l}=e,a=l-r,h;for(;;){if(a<0)return new qe(0,1);if(a>s.viewState.docHeight)return new qe(s.state.doc.length,-1);if(h=s.elementAtHeight(a),i==null)break;if(h.type==me.Text){if(i<0?h.to<s.viewport.from:h.from>s.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 c=s.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+c:h.top-c}if(s.viewport.from>=h.to||s.viewport.to<=h.from){if(t)return null;if(h.type==me.Text){let c=rc(s,n,h,o,l);return new qe(c,c==h.from?1:-1)}}if(h.type!=me.Text)return a<(h.top+h.bottom)/2?new qe(h.from,1):new qe(h.to,-1);let f=s.docView.lineAt(h.from,2);return(!f||f.length!=h.length)&&(f=s.docView.lineAt(h.from,-2)),new fc(s,o,l,s.textDirectionAt(h.from)).scanTile(f,h.from)}class fc{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Ke.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Ke.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t){let i=0,n=e.length-1,r=new Set,o=this.bidiIn(e[0],e[n]),l,a,h=-1,f=1e9,c;e:for(;i<n;){let d=n-i,p=i+n>>1;t:if(r.has(p)){let g=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!r.has(g)){p=g;break t}g++,g==n&&(g=i)}break e}r.add(p);let m=t(p);if(m)for(let g=0;g<m.length;g++){let y=m[g],x=0;if(!(y.width==0&&m.length>1)){if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),x=-1;else{let v=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,D=Math.abs(v);D<f&&(h=p,f=D,c=y),v&&(x=v<0==(this.baseDir==j.LTR)?-1:1)}x==-1&&(!o||this.baseDirAt(e[p],1))?n=p:x==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}}if(!c){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}if(f){if(l&&l.bottom>c.top)return this.y=l.bottom-1,this.scan(e,t);if(a&&a.top<c.bottom)return this.y=a.top+1,this.scan(e,t)}let u=(o?this.dirAt(e[h],1):this.baseDir)==j.LTR;return{i:h,after:this.x>(c.left+c.right)/2==u}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=te(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return bi(e.dom,o,l).getClientRects()});return n.after?new qe(i[n.i+1],-1):new qe(i[n.i],1)}scanTile(e,t){if(!e.length)return new qe(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<e.children.length;l++)i.push(a+=e.children[l].length);let n=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:bi(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 qe(i[n.i+1],-1):new qe(o,1)}}const Dt="";class cc{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(F.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Dt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=G.get(n),l=n.nextSibling;if(l==t){o!=null&&o.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=G.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:cn(n))||cn(l)&&(n.nodeName!="BR"||o!=null&&o.isWidget())&&this.text.length>r)&&!dc(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=G.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(uc(e,i.node,i.offset)?t:0))}}function uc(s,e,t){for(;;){if(!e||t<Qe(e))return!1;if(e==s)return!0;t=ft(e)+1,e=e.parentNode}}function dc(s,e){let t;for(;!(s==e||!s);s=s.nextSibling){let i=G.get(s);if(!(i!=null&&i.isWidget()))return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let n=i.overrideDOMText;if(n!=null&&n.length)return!1}return!0}class fo{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class pc{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=ma(e.docView.tile,t,i,0))){let a=r||o?[]:gc(e),h=new cc(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=yc(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!Ps(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),f=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!Ps(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),c=e.viewport;if((k.ios||k.chrome)&&l.main.empty&&h!=f&&(c.from>0||c.to<e.state.doc.length)){let u=Math.min(h,f),d=Math.max(h,f),p=c.from-u,m=c.to-d;(p==0||p==1||u==0)&&(m==0||m==-1||d==e.state.doc.length)&&(h=0,f=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(b.range(f,h));else if(e.lineWrapping&&f==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=b.create([b.cursor(h,d)])}else this.newSel=b.single(f,h)}}}function ma(s,e,t,i){if(s.isComposite()){let n=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,f=i;a<s.children.length;a++){let c=s.children[a],u=h+c.length;if(h<e&&u>t)return ma(c,e,t,h);if(u>=e&&n==-1&&(n=a,r=h),h>t&&c.dom.parentNode==s.dom){o=a,l=f;break}f=u,h=u+c.breakAfter}return{from:r,to:l<0?i+s.length:l,startDOM:(n?s.children[n-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o<s.children.length&&o>=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function ga(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,f=null;(o===8||k.android&&e.text.length<a-l)&&(h=r.to,f="end");let c=n.doc.sliceString(l,a,Dt),u,d;!r.empty&&r.from>=l&&r.to<=a&&(e.typeOver||c!=e.text)&&c.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&c.slice(r.to-l)==e.text.slice(u=e.text.length-(c.length-(r.to-l)))?t={from:r.from,to:r.to,insert:P.of(e.text.slice(r.from-l,u).split(Dt))}:(d=ya(c,e.text,h-l,f))&&(k.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==Dt+Dt&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:P.of(e.text.slice(d.from,d.toB).split(Dt))})}else i&&(!s.hasFocus&&n.facet(_e)||gn(i,r))&&(i=null);if(!t&&!i)return!1;if((k.mac||k.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:P.of([t.insert.toString().replace("."," ")])}):n.doc.lineAt(r.from).to<r.to&&s.docView.lineHasWidget(r.to)&&s.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.toText(s.inputState.insertingText)}:k.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
|
|
9
|
+
`&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:P.of([" "])}),t)return br(s,t,i,o);if(i&&!gn(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=pa(n.facet(Ti).map(h=>h(s)),i))),s.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function br(s,e,t,i=-1){if(k.ios&&s.inputState.flushIOSKey(e))return!0;let n=s.state.selection.main;if(k.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&&Wt(s.contentDOM,"Enter",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>n.head)&&Wt(s.contentDOM,"Backspace",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&Wt(s.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=mc(s,e,t));return s.state.facet(na).some(a=>a(s,e.from,e.to,r,l))||s.dispatch(l()),!0}function mc(s,e,t){let i,n=s.state,r=n.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let a=e.from<r.from?-1:1,h=a<0?r.from:r.to,f=ui(n.facet(Ti).map(c=>c(s)),h,a);e.from==f&&(o=f)}if(o>-1)i={changes:e,selection:b.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&s.inputState.composing<0){let a=r.from<e.from?n.sliceDoc(r.from,e.from):"",h=r.to>e.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 f=s.state.sliceDoc(e.from,e.to),c,u=t&&da(s,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);c={from:u.from,to:u.to-p}}else c=s.state.doc.lineAt(r.head);let d=r.to-e.to;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-f.length;if(s.state.sliceDoc(g,m)!=f||m>=c.from&&g<=c.to)return{range:p};let y=n.changes({from:g,to:m,insert:e.insert}),x=p.to-r.to;return{changes:y,range:h?b.range(Math.max(0,h.anchor+x),Math.max(0,h.head+x)):p.map(y)}})}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 ya(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r<n&&s.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==n&&s.length==e.length)return null;let o=s.length,l=e.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&s.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function gc(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 fo(t,i)),(n!=t||r!=i)&&e.push(new fo(n,r))),e}function yc(s,e){if(s.length==0)return null;let t=s[0].pos,i=s.length==2?s[1].pos:t;return t>-1&&i>-1?b.single(t+e,i+e):null}function gn(s,e){return e.head==s.main.head&&e.anchor==s.main.anchor}class bc{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,k.safari&&e.contentDOM.addEventListener("input",()=>null),k.gecko&&Rc(e.contentDOM.ownerDocument)}handleEvent(e){!Mc(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=xc(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&&xa.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),k.android&&k.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return k.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=ba.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||wc.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Wt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:k.safari&&!k.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 co(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){we(t.state,n)}}}function xc(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(co(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(co(i.value,a))}}for(let i in Re)t(i).handlers.push(Re[i]);for(let i in ge)t(i).observers.push(ge[i]);return e}const ba=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],wc="dthko",xa=[16,17,18,20,91,92,224,225],Wi=6;function Fi(s){return Math.max(0,s)*.7+8}function vc(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class kc{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=Kl(e.contentDOM),this.atoms=e.state.facet(Ti).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(F.allowMultipleSelections)&&Sc(e,t),this.dragging=Ac(e,t)&&ka(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&&vc(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=yr(this.view);e.clientX-a.left<=n+Wi?t=-Fi(n-e.clientX):e.clientX+a.right>=o-Wi&&(t=Fi(e.clientX-o)),e.clientY-a.top<=r+Wi?i=-Fi(r-e.clientY):e.clientY+a.bottom>=l-Wi&&(i=Fi(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=pa(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 Sc(s,e){let t=s.state.facet(Zl);return t.length?t[0](e):k.mac?e.metaKey:e.ctrlKey}function Cc(s,e){let t=s.state.facet(ea);return t.length?t[0](e):k.mac?!e.altKey:!e.ctrlKey}function Ac(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=yi(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Mc(s,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=s.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Re=Object.create(null),ge=Object.create(null),wa=k.ie&&k.ie_version<15||k.ios&&k.webkit_version<604;function Tc(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(),va(s,t.value)},50)}function Hn(s,e,t){for(let i of s.facet(e))t=i(t,s);return t}function va(s,e){e=Hn(s.state,dr,e);let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(qs!=null&&t.selection.ranges.every(a=>a.empty)&&qs==r.toString()){let a=-1;i=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==a)return{range:h};a=f.from;let c=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:b.cursor(h.from+c.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:b.cursor(a.from+h.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}ge.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ge.wheel=ge.mousewheel=s=>{s.inputState.lastWheelEvent=Date.now()};Re.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);ge.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")};ge.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Re.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(ta))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Oc(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new kc(s,e,t,i)),i&&s.observer.ignore(()=>{$l(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 uo(s,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return sc(s.state,e,t);{let n=s.docView.lineAt(e,t),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,b.range(o,l)}}const Dc=k.ie&&k.ie_version<=11;let po=null,mo=0,go=0;function ka(s){if(!Dc)return s.detail;let e=po,t=go;return po=s,go=Date.now(),mo=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(mo+1)%3:1}function Oc(s,e){let t=s.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=ka(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,f=uo(s,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let c=uo(s,t.pos,t.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?b.range(u,d,f.assoc):b.range(d,u,f.assoc)}return o?n.replaceRange(n.main.extend(f.from,f.to,f.assoc)):l&&i==1&&n.ranges.length>1&&(h=Bc(n,a.pos))?h:l?n.addRange(f):b.create([f])}}}function Bc(s,e){for(let t=0;t<s.ranges.length;t++){let{from:i,to:n}=s.ranges[t];if(i<=e&&n>=e)return b.create(s.ranges.slice(0,t).concat(s.ranges.slice(t+1)),s.mainIndex==t?0:s.mainIndex-(s.mainIndex>t?1:0))}return null}Re.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.tile.nearest(e.target);if(n&&n.isWidget()){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Hn(s.state,pr,s.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Re.dragend=s=>(s.inputState.draggedContent=null,!1);function yo(s,e,t,i){if(t=Hn(s.state,dr,t),!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Cc(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}Re.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&&yo(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return yo(s,e,i,!0),!0}return!1};Re.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=wa?null:e.clipboardData;return t?(va(s,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Tc(s),!1)};function Lc(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 Ec(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:Hn(s,pr,e.join(s.lineBreak)),ranges:t,linewise:i}}let qs=null;Re.copy=Re.cut=(s,e)=>{if(!fi(s.contentDOM,s.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:n}=Ec(s.state);if(!t&&!n)return!1;qs=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=wa?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Lc(s,t),!1)};const Sa=Ze.define();function Ca(s,e){let t=[];for(let i of s.facet(sa)){let n=i(s,e);n&&t.push(n)}return t.length?s.update({effects:t,annotations:Sa.of(!0)}):null}function Aa(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=Ca(s.state,e);t?s.dispatch(t):s.update([])}},10)}ge.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),Aa(s)};ge.blur=s=>{s.observer.clearSelectionRange(),Aa(s)};ge.compositionstart=ge.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};ge.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,k.chrome&&k.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};ge.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Re.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 br(s,{from:a,to:h,insert:s.state.toText(r)},null),!0}}let n;if(k.chrome&&k.android&&(n=ba.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 k.ios&&e.inputType=="deleteContentForward"&&s.observer.flushSoon(),k.safari&&e.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>ge.compositionend(s,e),20),!1};const bo=new Set;function Rc(s){bo.has(s)||(bo.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const xo=["pre-wrap","normal","pre-line","break-spaces"];let Ut=!1;function wo(){Ut=!1}class Ic{constructor(e){this.lineWrapping=e,this.doc=P.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 xo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(t=!0,this.heightSamples[Math.floor(n*10)]=!0)}return t}refresh(e,t,i,n,r,o){let l=xo.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let f=o[h];f<0?h++:this.heightSamples[Math.floor(f*10)]=!0}}return a}}class Pc{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Be{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?me.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof St?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Be(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var q=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})(q||(q={}));const sn=.001;class fe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>sn&&(Ut=!0),this.height=e)}replace(e,t,i){return fe.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:f,toB:c}=n[l],u=r.lineAt(a,q.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,q.ByPosNoHeight,i,0,0);for(c+=d.to-h,h=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,f=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,q.ByPosNoHeight,i,0,0));f+=u.from-a,a=u.from;let p=xr.build(i.setDoc(o),e,f,c);r=yn(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new xe(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=e[t++];l&&(n+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Wc(fe.of(e.slice(0,t)),o,fe.of(e.slice(i)))}}function yn(s,e){return s==e?s:(s.constructor!=e.constructor&&(Ut=!0),e)}fe.prototype.size=1;const Nc=L.replace({});class Ma extends fe{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new Be(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new Be(n,0,i,this.spaceAbove,Nc):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let o=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(o):o}forEachLine(e,t,i,n,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,q.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 xe extends Ma{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 Be(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 xe||n instanceof ne&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof ne?n=new xe(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):fe.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 ne extends fe{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+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),f=t.doc.lineAt(h),c=l+f.length*a,u=Math.max(i,e-c/2);return new Be(f.from,f.length,u,c,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:f,length:c}=t.doc.line(r+h);return new Be(f,c,i+l*h,l,0)}}lineAt(e,t,i,n,r){if(t==q.ByHeight)return this.blockAt(e,i,n,r);if(t==q.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Be(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),f=l+h.length*a,c=h.number-o,u=n+l*c+a*(h.from-r-c);return new Be(h.from,h.length,Math.max(n,Math.min(u,n+this.height-f)),f,0)}forEachLine(e,t,i,n,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let f=e,c=n;f<=t;){let u=i.doc.lineAt(f);if(f==e){let p=u.number-l;c+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new Be(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let r=i[i.length-1];r instanceof ne?i[i.length-1]=new ne(r.length+n):i.push(null,new ne(n-1))}if(e>0){let r=i[0];r instanceof ne?i[0]=new ne(e+r.length):i.unshift(new ne(e-1),null)}return fe.of(i)}decomposeLeft(e,t){t.push(new ne(e-1),null)}decomposeRight(e,t){t.push(null,new ne(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 ne(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++],u=0;c<0&&(u=-c,c=n.heights[n.index++]),a==-1?a=c:Math.abs(c-a)>=sn&&(a=-2);let d=new xe(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new ne(r-l).updateHeight(e,l));let h=fe.of(o);return(a<0||Math.abs(h.height-this.height)>=sn||Math.abs(a-this.heightMetrics(e,t).perLine)>=sn)&&(Ut=!0),yn(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 Wc extends fe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=t==q.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let f=t==q.ByPosNoHeight?q.ByPosNoHeight:q.ByPos;return a?h.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,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.left.forEachLine(e,t,i,n,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,q.ByPos,i,n,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,n,r,o),h.to>=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(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&vo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),vo(r,l)}return fe.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fe.of(this.break?[e,null,t]:[e,t]):(this.left=yn(this.left,e),this.right=yn(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 vo(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof ne&&(i=s[e+1])instanceof ne&&s.splice(e-1,3,new ne(t.length+1+i.length))}const Fc=5;class xr{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 xe?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new xe(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Ma(o,n,i)):(o||r||n>=Fc)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new xe(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new ne(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 xe)return e;let t=new xe(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 xe)&&!this.isCovered?this.nodes.push(new xe(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let n of this.nodes)n instanceof xe&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new xr(i,e);return I.spans(t,i,n,r,0),r.finish(i)}}function Hc(s,e,t){let i=new Vc;return I.compare(s,e,t,i,0),i.changes}class Vc{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&Nt(e,t,this.changes,5)}}function zc(s,e){let t=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(n.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(n.innerHeight,t.bottom);for(let h=s.parentNode;h&&h!=i.body;)if(h.nodeType==1){let f=h,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==s.parentNode?n.innerHeight:a,u.bottom)}h=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.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 qc(s){let e=s.getBoundingClientRect(),t=s.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function Kc(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class ts{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return L.replace({widget:new $c(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class $c extends Ci{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class ko{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=So,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=j.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet(mr).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Ic(i),this.stateDeco=Co(t),this.heightMap=fe.empty().applyChanges(this.stateDeco,P.empty,this.heightOracle.setDoc(t.doc),[new Se(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=L.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 Hi(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?So:new wr(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(li(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=Co(this.state);let n=e.changedRanges,r=Se.extendWithRanges(n,Hc(i,this.stateDeco,e?e.changes:Q.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);wo(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Ut)&&(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.head<a.from||t.range.head>a.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(Pf)&&(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,f=0;if(l.width&&l.height){let{scaleX:S,scaleY:M}=ql(t,l);(S>.005&&Math.abs(this.scaleX-S)>.005||M>.005&&Math.abs(this.scaleY-M)>.005)&&(this.scaleX=S,this.scaleY=M,h|=16,o=a=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=Kl(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=jl(this.scrollParent||e.win);let m=(this.printing?Kc:zc)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let x=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(x!=this.inView&&(this.inView=x,x&&(a=!0)),!this.inView&&!this.scrollTarget&&!qc(e.dom))return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let S=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(S)&&(o=!0),o||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:M,charWidth:A,textHeight:W}=e.docView.measureTextSize();o=M>0&&n.refresh(r,M,A,W,Math.max(5,v/A),S),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?f=Math.max(g,y):g<0&&y<0&&(f=Math.min(g,y)),wo();for(let M of this.viewports){let A=M.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(M);this.heightMap=(o?fe.empty().applyChanges(this.stateDeco,P.empty,this.heightOracle,[new Se(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Pc(M.from,A))}Ut&&(h|=2)}let D=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return D&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),h|=this.updateForViewport()),(h&2||D)&&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 Hi(n.lineAt(o-i*1e3,q.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,q.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(h,q.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=c.top:u=c.bottom-f,a=new Hi(n.lineAt(u-1e3/2,q.ByHeight,r,0,0).from,n.lineAt(u+f+1e3/2,q.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new Hi(this.heightMap.lineAt(i,q.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,q.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,q.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,q.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||n<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new ts(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=j.LTR&&!i)return[];let l=[],a=(f,c,u,d)=>{if(c-f<r)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>f&&y<c){a(f,y-10,u,d),a(y+10,c,u,d);return}let g=Uc(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-f)<r&&Math.abs(y.to-c)<r&&!m.some(x=>y.from<x&&y.to>x));if(!g){if(c<u.to&&t&&i&&t.visibleRanges.some(v=>v.from<=c&&v.to>=c)){let v=t.moveToLineBoundary(b.cursor(c),!1,!0).head;v>f&&(c=v)}let y=this.gapSize(u,f,c,d),x=i||y<2e6?y:2e6;g=new ts(f,c,y,x)}l.push(g)},h=f=>{if(f.length<o||f.type!=me.Text)return;let c=jc(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(u!=null){let x=zi(c,u),v=((this.visibleBottom-this.visibleTop)/2+m)/f.height;g=x-v,y=x+v}else g=(this.visibleTop-f.top-m)/f.height,y=(this.visibleBottom-f.top+m)/f.height;d=Vi(c,g),p=Vi(c,y)}else{let m=c.total*this.heightOracle.charWidth,g=n*this.heightOracle.charWidth,y=0;if(m>2e6)for(let M of e)M.from>=f.from&&M.from<f.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=M.size-M.displaySize);let x=this.pixelViewport.left+y,v=this.pixelViewport.right+y,D,S;if(u!=null){let M=zi(c,u),A=((v-x)/2+g)/m;D=M-A,S=M+A}else D=(x-g)/m,S=(v+g)/m;d=Vi(c,D),p=Vi(c,S)}d>f.from&&a(f.from,d,f,c),p<f.to&&a(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(h):h(f);return l}gapSize(e,t,i,n){let r=zi(n,i)-zi(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){ts.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=L.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];I.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(n&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(n|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||li(this.heightMap.lineAt(e,q.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)||li(this.heightMap.lineAt(this.scaler.fromDOM(e),q.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 li(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 Hi{constructor(e,t){this.from=e,this.to=t}}function jc(s,e,t){let i=[],n=s,r=0;return I.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<e&&(i.push({from:n,to:e}),r+=e-n),{total:r,ranges:i}}function Vi({total:s,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(s*t);for(let n=0;;n++){let{from:r,to:o}=e[n],l=o-r;if(i<=l)return r+i;i-=l}}function zi(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 Uc(s,e){for(let t of s)if(e(t))return t}const So={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};function Co(s){let e=s.facet(Nn).filter(i=>typeof i!="function"),t=s.facet(gr).filter(i=>typeof i!="function");return t.length&&e.push(I.join(t)),e}class wr{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,q.ByPos,e,0,0).top,f=t.lineAt(a,q.ByPos,e,0,0).bottom;return n+=f-h,{from:l,to:a,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof wr?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function li(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new Be(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>li(n,e)):s._content)}const qi=C.define({combine:s=>s.join(" ")}),Ks=C.define({combine:s=>s.indexOf(!0)>-1}),$s=at.newName(),Ta=at.newName(),Da=at.newName(),Oa={"&light":"."+Ta,"&dark":"."+Da};function js(s,e,t){return new at(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 Gc=js("."+$s,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Oa),Jc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},is=k.ie&&k.ie_version<=11;class _c{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Sf,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(k.ie&&k.ie_version<=11||k.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&&k.android&&e.constructor.EDIT_CONTEXT!==!1&&!(k.chrome&&k.chrome_version<126)&&(this.editContext=new Xc(e),e.state.facet(_e)&&(e.contentDOM.editContext=this.editContext.editContext)),is&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(_e)?i.root.activeElement!=this.dom:!fi(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}(k.ie&&k.ie_version<=11||k.android&&k.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ci(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=yi(e.root);if(!t)return!1;let i=k.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Yc(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=fi(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Af(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Jc),is&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),is&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Wt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&fi(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 pc(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=ga(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!gn(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=Ao(t,e.previousSibling||e.target.previousSibling,-1),n=Ao(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(_e)!=e.state.facet(_e)&&(e.view.contentDOM.editContext=e.state.facet(_e)?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 Ao(s,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==s)return i;let n=e.parentNode;e=n!=s.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function Mo(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 ci(o.node,o.offset,n,r)&&([t,i,n,r]=[n,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}}function Yc(s,e){if(e.getComposedRanges){let n=e.getComposedRanges(s.root)[0];if(n)return Mo(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?Mo(s,t):null}class Xc{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&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let f=ya(e.state.sliceDoc(l,a),i.text,(h?n.from:n.to)-l,h?"end":null);if(!f){let u=b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));gn(u,n)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:P.of(i.text.slice(f.from,f.toB).split(`
|
|
10
|
+
`))};if((k.mac||k.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:a,insert:P.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!e.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);br(e,c,b.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),c.from<c.to&&!c.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,n.push(r)}t.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;n.push(L.mark({attributes:{style:f}}).range(a,h))}}}e.dispatch({effects:la.of(L.set(n))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=yi(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 f=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+=f,this.to+=f;return}else n=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=f,this.to+=f;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=f}t+=f}),n&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(n=>!n.isUserEvent("input.type")&&n.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),n=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class T{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||Cf(e.parent)||document,this.viewState=new ko(this,e.state||F.create(e)),e.scrollTo&&e.scrollTo.is(Ni)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Lt).map(n=>new Yn(n));for(let n of this.plugins)n.update(this);this.observer=new _c(this),this.inputState=new bc(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ao(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 Y?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(Sa))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Ca(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(f=null)):this.observer.clear(),r.facet(F.phrases)!=this.state.facet(F.phrases))return this.setState(r);n=dn.create(this,r,e),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(T.cursorScrollMargin);c=new Ft(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(Ni)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=bn.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(oi)!=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(qi)!=n.state.facet(qi)&&(this.viewState.mustMeasureContent=!0),(t||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Hs))try{u(n)}catch(d){we(this.state,d,"update listener")}(a||f)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),f&&!ga(this,f)&&h.force&&Wt(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 ko(this,e),this.plugins=e.facet(Lt).map(i=>new Yn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new ao(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(Lt),i=e.state.facet(Lt);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new Yn(r));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){we(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(jl(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 f=h.map(d=>{try{return d.read(this)}catch(p){return we(this.state,p),To}}),c=dn.create(this,this.state,[]),u=!1;c.flags|=a,t?t.flags|=a:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<h.length;d++)if(f[d]!=To)try{let p=h[d];p.write&&p.write(f[d],this)}catch(p){we(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o)/this.scaleY;if((p>1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n=n+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Hs))l(t)}get themeClasses(){return $s+" "+(this.state.facet(Ks)?Da:Ta)+" "+this.state.facet(qi)}updateAttrs(){let e=Do(this,aa,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(_e)?"true":"false",class:"cm-content",style:`${k.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Do(this,mr,t);let i=this.observer.ignore(()=>{let n=io(this.contentDOM,this.contentAttrs,t),r=io(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(T.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(oi);let e=this.state.facet(T.cspNonce);at.mount(this.root,this.styleModules.concat(Gc).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return es(this,e,ho(this,e,t,i))}moveByGroup(e,t){return es(this,e,ho(this,e,t,i=>ac(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return b.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return lc(this,e,t,i)}moveVertically(e,t,i){return es(this,e,hc(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=zs(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),zs(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[Ke.find(r,e-n.from,-1,t)];return un(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(ra)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Qc)return Xl(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||Yl(r.isolates,i=ro(this,e))))return r.order;i||(i=ro(this,e));let n=Ef(e.text,t,i);return this.bidiCache.push(new bn(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||k.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{$l(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 Ni.of(new Ft(typeof e=="number"?b.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(n=t.x)!==null&&n!==void 0?n:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Ni.of(new Ft(b.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return ce.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return ce.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=at.newName(),n=[qi.of(i),oi.of(js(`.${i}`,e))];return t&&t.dark&&n.push(Ks.of(!0)),n}static baseTheme(e){return Mt.lowest(oi.of(js("."+$s,e,Oa)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&G.get(i)||G.get(e);return((t=n==null?void 0:n.root)===null||t===void 0?void 0:t.view)||null}}T.styleModule=oi;T.inputHandler=na;T.clipboardInputFilter=dr;T.clipboardOutputFilter=pr;T.scrollHandler=oa;T.focusChangeEffect=sa;T.perLineTextDirection=ra;T.exceptionSink=ia;T.updateListener=Hs;T.editable=_e;T.mouseSelectionStyle=ta;T.dragMovesSelection=ea;T.clickAddsSelectionRange=Zl;T.decorations=Nn;T.blockWrappers=ha;T.outerDecorations=gr;T.atomicRanges=Ti;T.bidiIsolatedRanges=fa;T.cursorScrollMargin=C.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}}});T.scrollMargins=ca;T.darkTheme=Ks;T.cspNonce=C.define({combine:s=>s.length?s[0]:""});T.contentAttributes=mr;T.editorAttributes=aa;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=N.define();const Qc=4096,To={};class bn{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<e.length;r++){let o=e[r];o.dir==n&&!t.touchesRange(o.from,o.to)&&i.push(new bn(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Do(s,e,t){for(let i=s.state.facet(e),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&fr(o,t)}return t}const Zc=k.mac?"mac":k.windows?"win":k.linux?"linux":"key";function eu(s,e){const t=s.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))n=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ki(s,e,t){return e.altKey&&(s="Alt-"+s),e.ctrlKey&&(s="Ctrl-"+s),e.metaKey&&(s="Meta-"+s),t!==!1&&e.shiftKey&&(s="Shift-"+s),s}const tu=Mt.default(T.domEventHandlers({keydown(s,e){return La(Ba(e.state),s,e,"editor")}})),vr=C.define({enables:tu}),Oo=new WeakMap;function Ba(s){let e=s.facet(vr),t=Oo.get(e);return t||Oo.set(e,t=su(e.reduce((i,n)=>i.concat(n),[]))),t}function iu(s,e,t){return La(Ba(s.state),e,s,t)}let st=null;const nu=4e3;function su(s,e=Zc){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,f)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>eu(y,e));for(let y=1;y<p.length;y++){let x=p.slice(0,y).join(" ");n(x,!0),d[x]||(d[x]={preventDefault:!0,stopPropagation:!1,run:[v=>{let D=st={view:v,prefix:x,scope:o};return setTimeout(()=>{st==D&&(st=null)},nu),!0}]})}let m=p.join(" ");n(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),f&&(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 f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in f)f[u].run.push(d=>c(d,Us))}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 Us=null;function La(s,e,t,i){Us=e;let n=gf(e),r=tt(n,0),o=bt(r)==n.length&&n!=" ",l="",a=!1,h=!1,f=!1;st&&st.view==t&&st.scope==i&&(l=st.prefix+" ",xa.indexOf(e.keyCode)<0&&(h=!0,st=null));let c=new Set,u=g=>{if(g){for(let y of g.run)if(!c.has(y)&&(c.add(y),y(t)))return g.stopPropagation&&(f=!0),!0;g.preventDefault&&(g.stopPropagation&&(f=!0),h=!0)}return!1},d=s[i],p,m;return d&&(u(d[l+Ki(n,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(k.windows&&e.ctrlKey&&e.altKey)&&!(k.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ht[e.keyCode])&&p!=n?(u(d[l+Ki(p,e,!0)])||e.shiftKey&&(m=mi[e.keyCode])!=n&&m!=p&&u(d[l+Ki(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Ki(n,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&f&&e.stopPropagation(),Us=null,a}function $m(){return ou}const ru=L.line({class:"cm-activeLine"}),ou=ce.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(ru.range(n.from)),e=n.from)}return L.set(t)}},{decorations:s=>s.decorations}),$i="-10000px";class lu{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;a<r.length;a++){let h=r[a],f=-1;if(h){for(let c=0;c<this.tooltips.length;c++){let u=this.tooltips[c];u&&u.create==h.create&&(f=c)}if(f<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let c=o[a]=this.tooltipViews[f];l&&(l[a]=t[f]),c.update&&c.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function au(s){let e=s.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const ns=C.define({combine:s=>{var e,t,i;return{position:k.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)||au}}}),Bo=new WeakMap,Ea=ce.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(ns);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 lu(s,Ra,(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(ns);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=$i,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(k.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=yr(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(ns).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<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:f}=h,c=s.pos[l],u=s.size[l];if(!c||a.clip!==!1&&(c.bottom<=Math.max(t.top,i.top)||c.top>=Math.min(t.bottom,i.bottom)||c.right<Math.max(t.left,i.left)-.1||c.left>Math.min(t.right,i.right)+.1)){f.style.top=$i;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=Bo.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||fu,x=this.view.textDirection==j.LTR,v=u.width>i.right-i.left?x?i.left:i.right-u.width:x?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,c.left-m+(d?14:0)-y.x),i.right-m),D=this.above[l];!a.strictSide&&(D?c.top-g-p-y.y<i.top:c.bottom+g+p+y.y>i.bottom)&&D==i.bottom-c.bottom>c.top-i.top&&(D=this.above[l]=!D);let S=(D?c.top-i.top:i.bottom-c.bottom)-p;if(S<g&&h.resize!==!1){if(S<this.view.defaultLineHeight){f.style.top=$i;continue}Bo.set(h,g),f.style.height=(g=S)/r+"px"}else f.style.height&&(f.style.height="");let M=D?c.top-g-p-y.y:c.bottom+p+y.y,A=v+m;if(h.overlap!==!0)for(let W of o)W.left<A&&W.right>v&&W.top<M+g&&W.bottom>M&&(M=D?W.top-g-2-p:W.bottom+p+2);if(this.position=="absolute"?(f.style.top=(M-s.parent.top)/r+"px",Lo(f,(v-s.parent.left)/n)):(f.style.top=M/r+"px",Lo(f,v/n)),d){let W=c.left+(x?y.x:-y.x)-(v+14-7);d.style.left=W/n+"px"}h.overlap!==!0&&o.push({left:v,top:M,right:A,bottom:M+g}),f.classList.toggle("cm-tooltip-above",D),f.classList.toggle("cm-tooltip-below",!D),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=$i}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Lo(s,e){let t=parseInt(s.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(s.style.left=e+"px")}const hu=T.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"}}}),fu={x:0,y:0},Ra=C.define({enables:[Ea,hu]});function Ia(s,e){let t=s.plugin(Ea);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Eo=C.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 Pa(s,e){let t=s.plugin(Na),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Na=ce.fromClass(class{constructor(s){this.input=s.state.facet(xn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(s));let e=s.state.facet(Eo);this.top=new ji(s,!0,e.topContainer),this.bottom=new ji(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(Eo);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new ji(s.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new ji(s.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=s.state.facet(xn);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),f;h<0?(f=a(s.view),l.push(f)):(f=this.panels[h],f.update&&f.update(s)),n.push(f),(f.top?r:o).push(f)}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=>T.scrollMargins.of(e=>{let t=e.plugin(s);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class ji{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=Ro(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Ro(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 Ro(s){let e=s.nextSibling;return s.remove(),e}const xn=C.define({enables:Na});function cu(s,e){let t,i=new Promise(o=>t=o),n=o=>uu(o,e,t);s.state.field(ss,!1)?s.dispatch({effects:Wa.of(n)}):s.dispatch({effects:N.appendConfig.of(ss.init(()=>[n]))});let r=Fa.of(n);return{close:r,result:i.then(o=>((s.win.queueMicrotask||(a=>s.win.setTimeout(a,10)))(()=>{s.state.field(ss).indexOf(n)>-1&&s.dispatch({effects:r})}),o))}}const ss=De.define({create(){return[]},update(s,e){for(let t of e.effects)t.is(Wa)?s=[t.value].concat(s):t.is(Fa)&&(s=s.filter(i=>i!=t.value));return s},provide:s=>xn.computeN([s],e=>e.field(s))}),Wa=N.define(),Fa=N.define();function uu(s,e,t){let i=e.content?e.content(s,()=>o(null)):null;if(!i){if(i=Z("form"),e.input){let l=Z("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(Z("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(Z("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let n=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<n.length;l++){let a=n[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=Z("div",i,Z("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 ct extends lt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}ct.prototype.elementClass="";ct.prototype.toDOM=void 0;ct.prototype.mapMode=he.TrackBefore;ct.prototype.startSide=ct.prototype.endSide=-1;ct.prototype.point=!0;const rn=C.define(),du=C.define(),on=C.define(),Io=C.define({combine:s=>s.some(e=>e)});function pu(s){return[mu]}const mu=ce.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(on).map(e=>new No(s,e)),this.fixed=!s.state.facet(Io);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(Io)!=!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=I.iter(this.view.state.facet(rn),this.view.viewport.from),i=[],n=this.gutters.map(r=>new gu(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==me.Text&&o){Gs(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==me.Text){Gs(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(on),t=s.state.facet(on),i=s.docChanged||s.heightChanged||s.viewportChanged||!I.eq(s.startState.facet(rn),s.state.facet(rn),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 No(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=>T.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 Po(s){return Array.isArray(s)?s:[s]}function Gs(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class gu{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=I.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 Ha(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=[];Gs(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(du)){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 No{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=Po(t.markers(e)),t.initialSpacer&&(this.spacer=new Ha(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=Po(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!I.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 Ha{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":""),yu(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=r<t.length?t[r++]:null,h=!1;if(a){let f=a.elementClass;f&&(i+=" "+f);for(let c=o;c<this.markers.length;c++)if(this.markers[c].compare(a)){l=c,h=!0;break}}else l=this.markers.length;for(;o<l;){let f=this.markers[o++];if(f.toDOM){f.destroy(n);let c=n.nextSibling;n.remove(),n=c}}if(!a)break;a.toDOM&&(h?n=n.nextSibling:this.dom.insertBefore(a.toDOM(e),n)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function yu(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(!s[t].compare(e[t]))return!1;return!0}const bu=C.define(),xu=C.define(),Et=C.define({combine(s){return Yt(s,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let r=i[n],o=t[n];i[n]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class rs extends ct{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function os(s,e){return s.state.facet(Et).formatNumber(e,s.state)}const wu=on.compute([Et],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(bu)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new rs(os(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(xu)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Et)!=e.state.facet(Et),initialSpacer(e){return new rs(os(e,Wo(e.state.doc.lines)))},updateSpacer(e,t){let i=os(t.view,Wo(t.view.state.doc.lines));return i==e.number?e:new rs(i)},domEventHandlers:s.facet(Et).domEventHandlers,side:"before"}));function jm(s={}){return[Et.of(s),pu(),wu]}function Wo(s){let e=9;for(;e<s;)e=e*10+9;return e}const vu=new class extends ct{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},ku=rn.compute(["selection"],s=>{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(vu.range(n)))}return I.of(e)});function Um(){return ku}const Su=1024;let Cu=0;class Ce{constructor(e,t){this.from=e,this.to=t}}class E{constructor(e={}){this.id=Cu++,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=ye.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}E.closedBy=new E({deserialize:s=>s.split(" ")});E.openedBy=new E({deserialize:s=>s.split(" ")});E.group=new E({deserialize:s=>s.split(" ")});E.isolate=new E({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});E.contextHash=new E({perNode:!0});E.lookAhead=new E({perNode:!0});E.mounted=new E({perNode:!0});class Ht{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[E.mounted.id]}}const Au=Object.create(null);class ye{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):Au,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new ye(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(E.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(E.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}ye.none=new ye("",Object.create(null),0,8);class Va{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let r of e){let o=r(i);if(o){n||(n=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in n&&(l=a.combine(n[a.id],l)),n[a.id]=l}}t.push(n?new ye(i.name,n,i.id,i.flags):i)}return new Va(t)}}const Ui=new WeakMap,Fo=new WeakMap;var V;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(V||(V={}));class X{constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Ht.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new wn(this.topNode,e)}cursorAt(e,t=0,i=0){let n=Ui.get(this)||this.topNode,r=new wn(n);return r.moveTo(e,t),Ui.set(this,r._tree),r}get topNode(){return new oe(this,0,0,null)}resolve(e,t=0){let i=xi(Ui.get(this)||this.topNode,e,t,!1);return Ui.set(this,i),i}resolveInner(e,t=0){let i=xi(Fo.get(this)||this.topNode,e,t,!0);return Fo.set(this,i),i}resolveStack(e,t=0){return Du(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,o=e.mode||0,l=(o&V.IncludeAnonymous)>0;for(let a=this.cursor(o|V.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:Cr(ye.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new X(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new X(ye.none,t,i,n)))}static build(e){return Ou(e)}}X.empty=new X(ye.none,[],[],0);class kr{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 kr(this.buffer,this.index)}}class ut{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ye.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,n,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(za(r,n,o[a+1],o[a+2])&&(l=a,i>0));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<t;){r[a++]=n[l++],r[a++]=n[l++]-i;let h=r[a++]=n[l++]-i;r[a++]=n[l++]-e,o=Math.max(o,h)}return new ut(r,o,this.set)}}function za(s,e,t,i){switch(s){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function xi(s,e,t,i){for(var n;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let o=!i&&s instanceof oe&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:V.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof oe&&o.index<0&&((n=l.enter(e,t,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(e,t,r);if(!o)return s;s=o}}class qa{cursor(e=0){return new wn(this,e)}getChild(e,t=null,i=null){let n=Ho(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Ho(this,e,t,i)}resolve(e,t=0){return xi(this,e,t,!1)}resolveInner(e,t=0){return xi(this,e,t,!0)}matchContext(e){return Js(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}get node(){return this}get next(){return this.parent}}class oe extends qa{constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let f=l[e],c=a[e]+o.from,u;if(!(!(r&V.EnterBracketed&&f instanceof X&&(u=Ht.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!za(n,i,c,c+f.length))){if(f instanceof ut){if(r&V.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,t,i-c,n);if(d>-1)return new $e(new Mu(o,f,e,c),null,d)}else if(r&V.IncludeAnonymous||!f.type.isAnonymous||Sr(f)){let d;if(!(r&V.IgnoreMounts)&&(d=Ht.get(f))&&!d.overlay)return new oe(d.tree,c,e,o);let p=new oe(f,c,e,o);return r&V.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?f.children.length-1:0,t,i,n,r)}}}if(r&V.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&V.IgnoreOverlays)&&(n=Ht.get(this._tree))&&n.overlay){let r=e-this.from,o=i&V.EnterBracketed&&n.bracketed;for(let{from:l,to:a}of n.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new oe(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 Ho(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 Js(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 Mu{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class $e extends qa{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 $e(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&V.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 $e(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 $e(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 $e(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 X(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Ka(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof oe&&t.index<0?null:t.parent,n=s.slice();return i?n[e]=i:n.splice(e,1),new Tu(n,t)}class Tu{constructor(e,t){this.heads=e,this.node=t}get next(){return Ka(this.heads)}}function Du(s,e,t){let i=s.resolveInner(e,t),n=null;for(let r=i instanceof oe?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(e,t)),r=o}else{let o=Ht.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new oe(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(xi(l,e,t,!1))}}return n?Ka(n):i}class wn{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&~V.EnterBracketed,e instanceof oe)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 oe?(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&V.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&V.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&V.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(n.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&V.IncludeAnonymous||l instanceof ut||!l.type.isAnonymous||Sr(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new $e(this.buffer,t,this.stack[n]);return this.bufferNode=new $e(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return Js(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return Js(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 Sr(s){return s.children.some(e=>e instanceof ut||!e.type.isAnonymous||Sr(e))}function Ou(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Su,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new kr(t,t.length):t,a=i.types,h=0,f=0;function c(S,M,A,W,z,U){let{id:R,start:O,end:K,size:$}=l,ie=f,et=h;if($<0)if(l.next(),$==-1){let Je=r[R];A.push(Je),W.push(O-S);return}else if($==-3){h=R;return}else if($==-4){f=R;return}else throw new RangeError(`Unrecognized record size: ${$}`);let ei=a[R],Li,pt,zr=O-S;if(K-O<=n&&(pt=g(l.pos-M,z))){let Je=new Uint16Array(pt.size-pt.skip),ve=l.pos-pt.size,Ne=Je.length;for(;l.pos>ve;)Ne=y(pt.start,Je,Ne);Li=new ut(Je,K-pt.start,i),zr=pt.start-S}else{let Je=l.pos-$;l.next();let ve=[],Ne=[],mt=R>=o?R:-1,Tt=0,Ei=K;for(;l.pos>Je;)mt>=0&&l.id==mt&&l.size>=0?(l.end<=Ei-n&&(p(ve,Ne,O,Tt,l.end,Ei,mt,ie,et),Tt=ve.length,Ei=l.end),l.next()):U>2500?u(O,Je,ve,Ne):c(O,Je,ve,Ne,mt,U+1);if(mt>=0&&Tt>0&&Tt<ve.length&&p(ve,Ne,O,Tt,O,Ei,mt,ie,et),ve.reverse(),Ne.reverse(),mt>-1&&Tt>0){let qr=d(ei,et);Li=Cr(ei,ve,Ne,0,ve.length,0,K-O,qr,qr)}else Li=m(ei,ve,Ne,K-O,ie-K,et)}A.push(Li),W.push(zr)}function u(S,M,A,W){let z=[],U=0,R=-1;for(;l.pos>M;){let{id:O,start:K,end:$,size:ie}=l;if(ie>4)l.next();else{if(R>-1&&K<R)break;R<0&&(R=$-n),z.push(O,K,$),U++,l.next()}}if(U){let O=new Uint16Array(U*4),K=z[z.length-2];for(let $=z.length-3,ie=0;$>=0;$-=3)O[ie++]=z[$],O[ie++]=z[$+1]-K,O[ie++]=z[$+2]-K,O[ie++]=ie;A.push(new ut(O,z[2]-K,i)),W.push(K-S)}}function d(S,M){return(A,W,z)=>{let U=0,R=A.length-1,O,K;if(R>=0&&(O=A[R])instanceof X){if(!R&&O.type==S&&O.length==z)return O;(K=O.prop(E.lookAhead))&&(U=W[R]+O.length+K)}return m(S,A,W,z,U,M)}}function p(S,M,A,W,z,U,R,O,K){let $=[],ie=[];for(;S.length>W;)$.push(S.pop()),ie.push(M.pop()+A-z);S.push(m(i.types[R],$,ie,U-z,O-U,K)),M.push(z-A)}function m(S,M,A,W,z,U,R){if(U){let O=[E.contextHash,U];R=R?[O].concat(R):[O]}if(z>25){let O=[E.lookAhead,z];R=R?[O].concat(R):[O]}return new X(S,M,A,W,R)}function g(S,M){let A=l.fork(),W=0,z=0,U=0,R=A.end-n,O={size:0,start:0,skip:0};e:for(let K=A.pos-S;A.pos>K;){let $=A.size;if(A.id==M&&$>=0){O.size=W,O.start=z,O.skip=U,U+=4,W+=4,A.next();continue}let ie=A.pos-$;if($<0||ie<K||A.start<R)break;let et=A.id>=o?4:0,ei=A.start;for(A.next();A.pos>ie;){if(A.size<0)if(A.size==-3||A.size==-4)et+=4;else break e;else A.id>=o&&(et+=4);A.next()}z=ei,W+=$,U+=et}return(M<0||W==S)&&(O.size=W,O.start=z,O.skip=U),O.size>4?O:void 0}function y(S,M,A){let{id:W,start:z,end:U,size:R}=l;if(l.next(),R>=0&&W<o){let O=A;if(R>4){let K=l.pos-(R-4);for(;l.pos>K;)A=y(S,M,A)}M[--A]=O,M[--A]=U-S,M[--A]=z-S,M[--A]=W}else R==-3?h=W:R==-4&&(f=W);return A}let x=[],v=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,x,v,-1,0);let D=(e=s.length)!==null&&e!==void 0?e:x.length?v[0]+x[0].length:0;return new X(a[s.topID],x.reverse(),v.reverse(),D)}const Vo=new WeakMap;function ln(s,e){if(!s.isAnonymous||e instanceof ut||e.type!=s)return 1;let t=Vo.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof X)){t=1;break}t+=ln(s,i)}Vo.set(e,t)}return t}function Cr(s,e,t,i,n,r,o,l,a){let h=0;for(let p=i;p<n;p++)h+=ln(s,e[p]);let f=Math.ceil(h*1.5/8),c=[],u=[];function d(p,m,g,y,x){for(let v=g;v<y;){let D=v,S=m[v],M=ln(s,p[v]);for(v++;v<y;v++){let A=ln(s,p[v]);if(M+A>=f)break;M+=A}if(v==D+1){if(M>f){let A=p[D];d(A.children,A.positions,0,A.children.length,m[D]+x);continue}c.push(p[D])}else{let A=m[v-1]+p[v-1].length-S;c.push(Cr(s,p,m,D,v,S,A,null,a))}u.push(S+x-r)}}return d(e,t,i,n,0),(l||a)(c,u,o)}class Gm{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof $e?this.setBuffer(e.context.buffer,e.index,t):e instanceof oe&&this.map.set(e.tree,t)}get(e){return e instanceof $e?this.getBuffer(e.context.buffer,e.index):e instanceof oe?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Xe{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 Xe(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 f=l<t.length?t[l]:null,c=f?f.fromA:1e9;if(c-a>=i)for(;o&&o.from<c;){let u=o;if(a>=u.from||c<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,c)-h;u=d>=p?null:new Xe(d,p,u.tree,u.offset+h,l>0,!!f)}if(u&&n.push(u),o.to>c)break;o=r<e.length?e[r++]:null}if(!f)break;a=f.toA,h=f.toA-f.toB}return n}}class Bu{startParse(e,t,i){return typeof e=="string"&&(e=new Lu(e)),i=i?i.length?i.map(n=>new Ce(n.from,n.to)):[new Ce(0,0)]:[new Ce(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 Lu{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function Jm(s){return(e,t,i,n)=>new Ru(e,s,t,i,n)}class zo{constructor(e,t,i,n,r,o){this.parser=e,this.parse=t,this.overlay=i,this.bracketed=n,this.target=r,this.from=o}}function qo(s){if(!s.length||s.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}class Eu{constructor(e,t,i,n,r,o,l,a){this.parser=e,this.predicate=t,this.mounts=i,this.index=n,this.start=r,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const _s=new E({perNode:!0});class Ru{constructor(e,t,i,n,r){this.nest=t,this.input=i,this.fragments=n,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let n of this.inner)n.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new X(i.type,i.children,i.positions,i.length,i.propValues.concat([[_s,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[E.mounted.id]=new Ht(t,e.overlay,e.parser,e.bracketed),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Nu(this.fragments),t=null,i=null,n=new wn(new oe(this.baseTree,this.ranges[0].from,0,null),V.IncludeAnonymous|V.IgnoreMounts);e:for(let r,o;;){let l=!0,a;if(this.stoppedAt!=null&&n.from>=this.stoppedAt)l=!1;else if(e.hasNode(n)){if(t){let h=t.mounts.find(f=>f.frag.from<=n.from&&f.frag.to>=n.to&&f.mount.overlay);if(h)for(let f of h.mount.overlay){let c=f.from+h.pos,u=f.to+h.pos;c>=n.from&&u<=n.to&&!t.ranges.some(d=>d.from<u&&d.to>c)&&t.ranges.push({from:c,to:u})}}l=!1}else if(i&&(o=Iu(i.ranges,n.from,n.to)))l=o!=2;else if(!n.type.isAnonymous&&(r=this.nest(n,this.input))&&(n.from<n.to||!r.overlay)){n.tree||(Pu(n),t&&t.depth++,i&&i.depth++);let h=e.findMounts(n.from,r.parser);if(typeof r.overlay=="function")t=new Eu(r.parser,r.overlay,h,this.inner.length,n.from,!!r.bracketed,n.tree,t);else{let f=jo(this.ranges,r.overlay||(n.from<n.to?[new Ce(n.from,n.to)]:[]));f.length&&qo(f),(f.length||!r.overlay)&&this.inner.push(new zo(r.parser,f.length?r.parser.startParse(this.input,Uo(h,f),f):r.parser.startParse(""),r.overlay?r.overlay.map(c=>new Ce(c.from-n.from,c.to-n.from)):null,!!r.bracketed,n.tree,f.length?f[0].from:n.from)),r.overlay?f.length&&(i={ranges:f,depth:0,prev:i}):l=!1}}else if(t&&(a=t.predicate(n))&&(a===!0&&(a=new Ce(n.from,n.to)),a.from<a.to)){let h=t.ranges.length-1;h>=0&&t.ranges[h].to==a.from?t.ranges[h]={from:t.ranges[h].from,to:a.to}:t.ranges.push(a)}if(l&&n.firstChild())t&&t.depth++,i&&i.depth++;else for(;!n.nextSibling();){if(!n.parent())break e;if(t&&!--t.depth){let h=jo(this.ranges,t.ranges);h.length&&(qo(h),this.inner.splice(t.index,0,new zo(t.parser,t.parser.startParse(this.input,Uo(t.mounts,h),h),t.ranges.map(f=>new Ce(f.from-t.start,f.to-t.start)),t.bracketed,t.target,h[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function Iu(s,e,t){for(let i of s){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function Ko(s,e,t,i,n,r){if(e<t){let o=s.buffer[e+1];i.push(s.slice(e,t,o)),n.push(o-r)}}function Pu(s){let{node:e}=s,t=[],i=e.context.buffer;do t.push(s.index),s.parent();while(!s.tree);let n=s.tree,r=n.children.indexOf(i),o=n.children[r],l=o.buffer,a=[r];function h(f,c,u,d,p,m){let g=t[m],y=[],x=[];Ko(o,f,g,y,x,d);let v=l[g+1],D=l[g+2];a.push(y.length);let S=m?h(g+4,l[g+3],o.set.types[l[g]],v,D-v,m-1):e.toTree();return y.push(S),x.push(v-d),Ko(o,l[g+3],c,y,x,d),new X(u,y,x,p)}n.children[r]=h(0,l.length,ye.none,0,o.length,t.length-1);for(let f of a){let c=s.tree.children[f],u=s.tree.positions[f];s.yield(new oe(c,u+s.from,f,s._tree))}}class $o{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(V.IncludeAnonymous|V.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,V.IgnoreOverlays|V.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof X)t=t.children[0];else break}return!1}}class Nu{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(_s))!==null&&t!==void 0?t:i.to,this.inner=new $o(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(_s))!==null&&e!==void 0?e:t.to,this.inner=new $o(t.tree,-t.offset)}}findMounts(e,t){var i;let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(i=r.tree)===null||i===void 0?void 0:i.prop(E.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=r.to)break;a.tree==this.curFrag.tree&&n.push({frag:a,pos:r.from-a.offset,mount:o})}}}return n}}function jo(s,e){let t=null,i=e;for(let n=1,r=0;n<s.length;n++){let o=s[n-1].to,l=s[n].from;for(;r<i.length;r++){let a=i[r];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[r]=new Ce(a.from,o),a.to>l&&t.splice(r+1,0,new Ce(l,a.to))):a.to>l?t[r--]=new Ce(l,a.to):t.splice(r--,1))}}return i}function Wu(s,e,t,i){let n=0,r=0,o=!1,l=!1,a=-1e9,h=[];for(;;){let f=n==s.length?1e9:o?s[n].to:s[n].from,c=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let u=Math.max(a,t),d=Math.min(f,c,i);u<d&&h.push(new Ce(u,d))}if(a=Math.min(f,c),a==1e9)break;f==a&&(o?(o=!1,n++):o=!0),c==a&&(l?(l=!1,r++):l=!0)}return h}function Uo(s,e){let t=[];for(let{pos:i,mount:n,frag:r}of s){let o=i+(n.overlay?n.overlay[0].from:0),l=o+n.tree.length,a=Math.max(r.from,o),h=Math.min(r.to,l);if(n.overlay){let f=n.overlay.map(u=>new Ce(u.from+i,u.to+i)),c=Wu(e,f,a,h);for(let u=0,d=a;;u++){let p=u==c.length,m=p?h:c[u].from;if(m>d&&t.push(new Xe(d,m,n.tree,-o,r.from>=d||r.openStart,r.to<=m||r.openEnd)),p)break;d=c[u].to}}else t.push(new Xe(a,h,n.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let Fu=0;class ke{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=Fu++}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 ke&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let n=new ke(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 vn(e);return i=>i.modified.indexOf(t)>-1?i:vn.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}}let Hu=0;class vn{constructor(e){this.name=e,this.instances=[],this.id=Hu++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Vu(t,l.modified));if(i)return i;let n=[],r=new ke(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=zu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(vn.get(l,a));return r}}function Vu(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function zu(s){let e=[[]];for(let t=0;t<s.length;t++)for(let i=0,n=e.length;i<n;i++)e.push(e[i].concat(s[t]));return e.sort((t,i)=>i.length-t.length)}function qu(s){let e=Object.create(null);for(let t in s){let i=s[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let r=[],o=2,l=n;for(let c=0;;){if(l=="..."&&c>0&&c+3==n.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+n);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(c)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+n);let f=new wi(i,o,a>0?r.slice(0,a):null);e[h]=f.sort(e[h])}}return $a.add(e)}const $a=new E({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 wi(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class wi{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}wi.empty=new wi([],2,null);function ja(s,e){let t=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:n=null}=e||{};return{style:r=>{let o=n;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Ku(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function $u(s,e,t,i=0,n=s.length){let r=new ju(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class ju{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,f=Uu(e)||wi.empty,c=Ku(r,f.tags);if(c&&(h&&(h+=" "),h+=c,f.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(t,l),h),f.opaque)return;let u=e.tree&&e.tree.prop(E.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,y=l;;g++){let x=g<u.overlay.length?u.overlay[g]:null,v=x?x.from+l:a,D=Math.max(t,y),S=Math.min(i,v);if(D<S&&m)for(;e.from<S&&(this.highlightRange(e,D,S,n,r),this.startSpan(Math.min(S,e.to),h),!(e.to>=v||!e.nextSibling())););if(!x||v>i)break;y=x.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,x.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),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 Uu(s){let e=s.type.prop($a);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const w=ke.define,Gi=w(),it=w(),Go=w(it),Jo=w(it),nt=w(),Ji=w(nt),ls=w(nt),Ve=w(),gt=w(Ve),Fe=w(),He=w(),Ys=w(),ni=w(Ys),_i=w(),B={comment:Gi,lineComment:w(Gi),blockComment:w(Gi),docComment:w(Gi),name:it,variableName:w(it),typeName:Go,tagName:w(Go),propertyName:Jo,attributeName:w(Jo),className:w(it),labelName:w(it),namespace:w(it),macroName:w(it),literal:nt,string:Ji,docString:w(Ji),character:w(Ji),attributeValue:w(Ji),number:ls,integer:w(ls),float:w(ls),bool:w(nt),regexp:w(nt),escape:w(nt),color:w(nt),url:w(nt),keyword:Fe,self:w(Fe),null:w(Fe),atom:w(Fe),unit:w(Fe),modifier:w(Fe),operatorKeyword:w(Fe),controlKeyword:w(Fe),definitionKeyword:w(Fe),moduleKeyword:w(Fe),operator:He,derefOperator:w(He),arithmeticOperator:w(He),logicOperator:w(He),bitwiseOperator:w(He),compareOperator:w(He),updateOperator:w(He),definitionOperator:w(He),typeOperator:w(He),controlOperator:w(He),punctuation:Ys,separator:w(Ys),bracket:ni,angleBracket:w(ni),squareBracket:w(ni),paren:w(ni),brace:w(ni),content:Ve,heading:gt,heading1:w(gt),heading2:w(gt),heading3:w(gt),heading4:w(gt),heading5:w(gt),heading6:w(gt),contentSeparator:w(Ve),list:w(Ve),quote:w(Ve),emphasis:w(Ve),strong:w(Ve),link:w(Ve),monospace:w(Ve),strikethrough:w(Ve),inserted:w(),deleted:w(),changed:w(),invalid:w(),meta:_i,documentMeta:w(_i),annotation:w(_i),processingInstruction:w(_i),definition:ke.defineModifier("definition"),constant:ke.defineModifier("constant"),function:ke.defineModifier("function"),standard:ke.defineModifier("standard"),local:ke.defineModifier("local"),special:ke.defineModifier("special")};for(let s in B){let e=B[s];e instanceof ke&&(e.name=s)}ja([{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 as;const Rt=new E;function Gu(s){return C.define({combine:s?e=>e.concat(s):void 0})}const Ju=new E;class Ee{constructor(e,t,i=[],n=""){this.data=e,this.name=n,F.prototype.hasOwnProperty("tree")||Object.defineProperty(F.prototype,"tree",{get(){return Te(this)}}),this.parser=t,this.extension=[Jt.of(this),F.languageData.of((r,o,l)=>{let a=_o(r,o,l),h=a.type.prop(Rt);if(!h)return[];let f=r.facet(h),c=a.type.prop(Ju);if(c){let u=a.resolve(o-a.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(e,t,i=-1){return _o(e,t,i).type.prop(Rt)==this.data}findRegions(e){let t=e.facet(Jt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(Rt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(E.mounted);if(l){if(l.tree.prop(Rt)==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;a<r.children.length;a++){let h=r.children[a];h instanceof X&&n(h,r.positions[a]+o)}};return n(Te(e),0),i}get allowsNesting(){return!0}}Ee.setState=N.define();function _o(s,e,t){let i=s.facet(Jt),n=Te(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(e,t,V.ExcludeBuffers|V.EnterBracketed))r.type.isTop&&(n=r);return n}class Xs extends Ee{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Gu(e.languageData);return new Xs(t,e.parser.configure({props:[Rt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Xs(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Te(s){let e=s.field(Ee.state,!1);return e?e.tree:X.empty}class _u{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let si=null;class kn{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 kn(e,t,[],X.empty,0,i,[],null)}startParse(){return this.parser.startParse(new _u(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=X.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Xe.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Xe.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=si;si=this;try{return e()}finally{si=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Yo(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,f,c,u)=>a.push({fromA:h,toA:f,fromB:c,toB:u})),i=Xe.applyChanges(i,a),n=X.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 f=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);f<c&&l.push({from:f,to:c})}}}return new kn(this.parser,t,i,n,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<e.to&&r>e.from&&(this.fragments=Yo(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 Bu{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=si;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 X(ye.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 si}}function Yo(s,e,t){return Xe.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class Gt{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 Gt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=kn.create(e.facet(Jt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Gt(i)}}Ee.state=De.define({create:Gt.init,update(s,e){for(let t of e.effects)if(t.is(Ee.setState))return t.value;return e.startState.facet(Jt)!=e.state.facet(Jt)?Gt.init(e.state):s.apply(e)}});let Ua=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Ua=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const hs=typeof navigator<"u"&&(!((as=navigator.scheduling)===null||as===void 0)&&as.isInputPending)?()=>navigator.scheduling.isInputPending():null,Yu=ce.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(Ee.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(Ee.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Ua(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Ee.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!hs?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,a=r.context.work(()=>hs&&hs()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Ee.setState.of(new Gt(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=>we(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()}}}),Jt=C.define({combine(s){return s.length?s[0]:null},enables:s=>[Ee.state,Yu,T.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class Ym{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class Ga{constructor(e,t,i,n,r,o=void 0){this.name=e,this.alias=t,this.extensions=i,this.filename=n,this.loadFunc=r,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new Ga(e.name,(e.alias||[]).concat(e.name).map(n=>n.toLowerCase()),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let i=/\.([^.]+)$/.exec(t);if(i){for(let n of e)if(n.extensions.indexOf(i[1])>-1)return n}return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(r=>r==t))return n;if(i)for(let n of e)for(let r of n.alias){let o=t.indexOf(r);if(o>-1&&(r.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+r.length])))return n}return null}}const Xu=C.define(),Vn=C.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 Sn(s){let e=s.facet(Vn);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function Cn(s,e){let t="",i=s.tabSize,n=s.facet(Vn)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r<e;r++)t+=n;return t}function Ja(s,e){s instanceof F&&(s=new zn(s));for(let i of s.state.facet(Xu)){let n=i(s,e);if(n!==void 0)return n}let t=Te(s.state);return t.length>=e?Zu(s,t,e):null}class zn{constructor(e,t={}){this.state=e,this.options=t,this.unit=Sn(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return In(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 Qu=new E;function Zu(s,e,t){let i=e.resolveStack(t),n=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return _a(i,s,t)}function _a(s,e,t){for(let i=s;i;i=i.next){let n=td(i.node);if(n)return n(Ar.create(e,t,i))}return 0}function ed(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function td(s){let e=s.type.prop(Qu);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(E.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>Ya(o,!0,1,void 0,r&&!ed(o)?n.from:void 0)}return s.parent==null?id:null}function id(){return 0}class Ar extends zn{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 Ar(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(nd(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return _a(this.context.next,this.base,this.pos)}}function nd(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function sd(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 Xm({closing:s,align:e=!0,units:t=1}){return i=>Ya(i,e,t,s)}function Ya(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?sd(s):null;return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}const Qm=s=>s.baseIndent;function Zm({except:s,units:e=1}={}){return t=>{let i=s&&s.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const eg=C.define(),tg=new E;function ig(s){let e=s.firstChild,t=s.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?s.to:t.from}:null}class Mr{constructor(e,t){this.specs=e;let i;function n(l){let a=at.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 Ee?l=>l.prop(Rt)==o.data:o?l=>l==o:void 0,this.style=ja(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new at(i):null,this.themeType=t.themeType}static define(e,t){return new Mr(e,t||{})}}const Qs=C.define(),rd=C.define({combine(s){return s.length?[s[0]]:null}});function fs(s){let e=s.facet(Qs);return e.length?e:s.facet(rd)}function ng(s,e){let t=[ld],i;return s instanceof Mr&&(s.module&&t.push(T.styleModule.of(s.module)),i=s.themeType),i?t.push(Qs.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):t.push(Qs.of(s)),t}class od{constructor(e){this.markCache=Object.create(null),this.tree=Te(e.state),this.decorations=this.buildDeco(e,fs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Te(e.state),i=fs(e.state),n=i!=fs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return L.none;let i=new Kt;for(let{from:n,to:r}of e.visibleRanges)$u(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=L.mark({class:a})))},n,r);return i.finish()}}const ld=Mt.high(ce.fromClass(od,{decorations:s=>s.decorations})),ad=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Xa=1e4,Qa="()[]{}",Za=C.define({combine(s){return Yt(s,{afterCursor:!0,brackets:Qa,maxScanDistance:Xa,renderMatch:cd})}}),hd=L.mark({class:"cm-matchingBracket"}),fd=L.mark({class:"cm-nonmatchingBracket"});function cd(s){let e=[],t=s.matched?hd:fd;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 Xo(s){let e=[],t=s.facet(Za);for(let i of s.selection.ranges){if(!i.empty)continue;let n=je(s,i.head,-1,t)||i.head>0&&je(s,i.head-1,1,t)||t.afterCursor&&(je(s,i.head,1,t)||i.head<s.doc.length&&je(s,i.head+1,-1,t));n&&(e=e.concat(t.renderMatch(n,s)))}return L.set(e,!0)}const ud=ce.fromClass(class{constructor(s){this.paused=!1,this.decorations=Xo(s.state)}update(s){(s.docChanged||s.selectionSet||this.paused)&&(s.view.composing?(this.decorations=this.decorations.map(s.changes),this.paused=!0):(this.decorations=Xo(s.state),this.paused=!1))}},{decorations:s=>s.decorations}),dd=[ud,ad];function sg(s={}){return[Za.of(s),dd]}const pd=new E;function Zs(s,e,t){let i=s.prop(e<0?E.openedBy:E.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 er(s){let e=s.type.prop(pd);return e?e(s.node):s}function je(s,e,t,i={}){let n=i.maxScanDistance||Xa,r=i.brackets||Qa,o=Te(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Zs(a.type,t,r);if(h&&a.from<a.to){let f=er(a);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return md(s,e,t,a,f,h,r)}}return gd(s,e,t,o,l.type,n,r)}function md(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},h=0,f=l==null?void 0:l.cursor();if(f&&(t<0?f.childBefore(i.from):f.childAfter(i.to)))do if(t<0?f.to<=i.from:f.from>=i.to){if(h==0&&r.indexOf(f.type.name)>-1&&f.from<f.to){let c=er(f);return{start:a,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(Zs(f.type,t,o))h++;else if(Zs(f.type,-t,o)){if(h==0){let c=er(f);return{start:a,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}h--}}while(t<0?f.prevSibling():f.nextSibling());return{start:a,matched:!1}}function gd(s,e,t,i,n,r,o){if(t<0?!e:e==s.doc.length)return null;let l=t<0?s.sliceDoc(e-1,e):s.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},f=s.doc.iterRange(e,t>0?s.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=r;){let d=f.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=n))if(y%2==0==t>0)c++;else{if(c==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};c--}}t>0&&(u+=d.length)}return f.done?{start:h,matched:!1}:null}const yd=Object.create(null),Qo=[ye.none],Zo=[],el=Object.create(null),bd=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"]])bd[s]=xd(yd,e);function cs(s,e){Zo.indexOf(s)>-1||(Zo.push(s),console.warn(e))}function xd(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let f=s[h]||B[h];f?typeof f=="function"?a.length?a=a.map(f):cs(h,`Modifier ${h} used at start of tag`):a.length?cs(h,`Tag ${h} used as modifier`):a=Array.isArray(f)?f:[f]:cs(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=el[n];if(r)return r.id;let o=el[n]=ye.define({id:Qo.length,name:i,props:[qu({[i]:t})]});return Qo.push(o),o.id}j.RTL,j.LTR;const wd=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=Dr(s.state,t.from);return i.line?vd(s):i.block?Sd(s):!1};function Tr(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const vd=Tr(Md,0),kd=Tr(eh,0),Sd=Tr((s,e)=>eh(s,e,Ad(e)),0);function Dr(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const ri=50;function Cd(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-ri,i),o=s.sliceDoc(n,n+ri),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 f,c;n-i<=2*ri?f=c=s.sliceDoc(i,n):(f=s.sliceDoc(i,i+ri),c=s.sliceDoc(n-ri,n));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function Ad(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 eh(s,e,t=e.selection.ranges){let i=t.map(r=>Dr(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>Cd(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let a=i[o],{open:h,close:f}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:f.pos-f.margin,to:f.pos+a.close.length})}return{changes:r}}return null}function Md(s,e,t=e.selection.ranges){let i=[],n=-1;e:for(let{from:r,to:o}of t){let l=i.length,a=1e9,h;for(let f=r;f<=o;){let c=e.doc.lineAt(f);if(h==null&&(h=Dr(e,c.from).line,!h))continue e;if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+h.length)==h?u:-1;u<c.text.length&&u<a&&(a=u),i.push({line:c,comment:p,token:h,indent:u,empty:d,single:!1})}f=c.to+1}if(a<1e9)for(let f=l;f<i.length;f++)i[f].indent<i[f].line.text.length&&(i[f].indent=a);i.length==l+1&&(i[l].single=!0)}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:f,single:c}of i)(c||!f)&&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,f=h+a.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}const tr=Ze.define(),Td=Ze.define(),Dd=C.define(),th=C.define({combine(s){return Yt(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)})}}),ih=De.define({create(){return Ue.empty},update(s,e){let t=e.state.facet(th),i=e.annotation(tr);if(i){let a=pe.fromTransaction(e,i.selection),h=i.side,f=h==0?s.undone:s.done;return a?f=An(f,f.length,t.minDepth,a):f=rh(f,e.startState.selection),new Ue(h==0?i.rest:f,h==0?f:i.rest)}let n=e.annotation(Td);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(Y.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=pe.fromTransaction(e),o=e.annotation(Y.time),l=e.annotation(Y.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 Ue(s.done.map(pe.fromJSON),s.undone.map(pe.fromJSON))}});function rg(s={}){return[ih,th.of(s),T.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?nh:e.inputType=="historyRedo"?ir:null;return i?(e.preventDefault(),i(t)):!1}})]}function qn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(ih,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const nh=qn(0,!1),ir=qn(1,!1),Od=qn(0,!0),Bd=qn(1,!0);class pe{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 pe(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 pe(e.changes&&Q.fromJSON(e.changes),[],e.mapped&&Ge.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=Ae;for(let n of e.startState.facet(Dd)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new pe(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ae)}static selection(e){return new pe(void 0,Ae,void 0,void 0,e)}}function An(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 Ld(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<t.length;){let h=t[a++],f=t[a++];l>=h&&o<=f&&(i=!0)}}),i}function Ed(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function sh(s,e){return s.length?e.length?s.concat(e):s:e}const Ae=[],Rd=200;function rh(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Rd));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),An(s,s.length-1,1e9,t.setSelAfter(i)))}else return[pe.selection([e])]}function Id(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 us(s,e){if(!s.length)return s;let t=s.length,i=Ae;for(;t;){let n=Pd(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?[pe.selection(i)]:Ae}function Pd(s,e,t){let i=sh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):Ae,t);if(!s.changes)return pe.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new pe(n,N.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const Nd=/^(input\.type|delete)($|\.)/;class Ue{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 Ue(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||Nd.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Ld(l.changes,e.changes))||i=="input.type.compose")?o=An(o,o.length-1,n.minDepth,new pe(e.changes.compose(l.changes),sh(N.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ae)):o=An(o,o.length,n.minDepth,e),new Ue(o,Ae,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ae;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Ed(r[r.length-1],e)?this:new Ue(rh(this.done,e),this.undone,t,i)}addMapping(e){return new Ue(us(this.done,e),us(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:tr.of({side:e,rest:Id(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?Ae:n.slice(0,n.length-1);return r.mapped&&(l=us(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:tr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Ue.empty=new Ue(Ae,Ae);const og=[{key:"Mod-z",run:nh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:ir,preventDefault:!0},{linux:"Ctrl-Shift-z",run:ir,preventDefault:!0},{key:"Mod-u",run:Od,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Bd,preventDefault:!0}];function Xt(s,e){return b.create(s.ranges.map(e),s.mainIndex)}function Ie(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Pe({state:s,dispatch:e},t){let i=Xt(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Ie(s,i)),!0)}function Kn(s,e){return b.cursor(e?s.to:s.from)}function oh(s,e){return Pe(s,t=>t.empty?s.moveByChar(t,e):Kn(t,e))}function le(s){return s.textDirectionAt(s.state.selection.main.head)==j.LTR}const lh=s=>oh(s,!le(s)),ah=s=>oh(s,le(s));function hh(s,e){return Pe(s,t=>t.empty?s.moveByGroup(t,e):Kn(t,e))}const Wd=s=>hh(s,!le(s)),Fd=s=>hh(s,le(s));function Hd(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=Te(s).resolveInner(e.head),n=t?E.closedBy:E.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Hd(s,h,n)?i=h:a=t?h.to:h.from}let r=i.type.prop(n),o,l;return r&&(o=t?je(s,i.from,1):je(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const Vd=s=>Pe(s,e=>$n(s.state,e,!le(s))),zd=s=>Pe(s,e=>$n(s.state,e,le(s)));function fh(s,e){return Pe(s,t=>{if(!t.empty)return Kn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const ch=s=>fh(s,!1),uh=s=>fh(s,!0);function dh(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function ph(s,e){let t=dh(s),{state:i}=s,n=Xt(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):Kn(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-a}))}return s.dispatch(Ie(i,n),{effects:r}),!0}const tl=s=>ph(s,!1),nr=s=>ph(s,!0);function dt(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const qd=s=>Pe(s,e=>dt(s,e,!0)),Kd=s=>Pe(s,e=>dt(s,e,!1)),$d=s=>Pe(s,e=>dt(s,e,!le(s))),jd=s=>Pe(s,e=>dt(s,e,le(s))),Ud=s=>Pe(s,e=>b.cursor(s.lineBlockAt(e.head).from,1)),Gd=s=>Pe(s,e=>b.cursor(s.lineBlockAt(e.head).to,-1));function Jd(s,e,t){let i=!1,n=Xt(s.selection,r=>{let o=je(s,r.head,-1)||je(s,r.head,1)||r.head>0&&je(s,r.head-1,1)||r.head<s.doc.length&&je(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return b.cursor(l)});return i?(e(Ie(s,n)),!0):!1}const _d=({state:s,dispatch:e})=>Jd(s,e);function Oe(s,e){let t=Xt(s.state.selection,i=>{let n=e(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return t.eq(s.state.selection)?!1:(s.dispatch(Ie(s.state,t)),!0)}function mh(s,e){return Oe(s,t=>s.moveByChar(t,e))}const gh=s=>mh(s,!le(s)),yh=s=>mh(s,le(s));function bh(s,e){return Oe(s,t=>s.moveByGroup(t,e))}const Yd=s=>bh(s,!le(s)),Xd=s=>bh(s,le(s)),Qd=s=>Oe(s,e=>$n(s.state,e,!le(s))),Zd=s=>Oe(s,e=>$n(s.state,e,le(s)));function xh(s,e){return Oe(s,t=>s.moveVertically(t,e))}const wh=s=>xh(s,!1),vh=s=>xh(s,!0);function kh(s,e){return Oe(s,t=>s.moveVertically(t,e,dh(s).height))}const il=s=>kh(s,!1),nl=s=>kh(s,!0),ep=s=>Oe(s,e=>dt(s,e,!0)),tp=s=>Oe(s,e=>dt(s,e,!1)),ip=s=>Oe(s,e=>dt(s,e,!le(s))),np=s=>Oe(s,e=>dt(s,e,le(s))),sp=s=>Oe(s,e=>b.cursor(s.lineBlockAt(e.head).from)),rp=s=>Oe(s,e=>b.cursor(s.lineBlockAt(e.head).to)),sl=({state:s,dispatch:e})=>(e(Ie(s,{anchor:0})),!0),rl=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.doc.length})),!0),ol=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.selection.main.anchor,head:0})),!0),ll=({state:s,dispatch:e})=>(e(Ie(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),op=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),lp=({state:s,dispatch:e})=>{let t=jn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:b.create(t),userEvent:"select"})),!0},ap=({state:s,dispatch:e})=>{let t=Xt(s.selection,i=>{let n=Te(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return b.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Ie(s,t)),!0)};function Sh(s,e){let{state:t}=s,i=t.selection,n=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let a=s.moveVertically(l,e);if(a.head<o.from||a.head>o.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(Ie(t,b.create(n,n.length-1))),!0)}const hp=s=>Sh(s,!1),fp=s=>Sh(s,!0),cp=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Ie(s,i)),!0):!1};function Di(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);a<o?(t="delete.backward",a=Yi(s,a,!1)):a>o&&(t="delete.forward",a=Yi(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Yi(s,o,!1),l=Yi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Yi(s,e,t){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const Ch=(s,e,t)=>Di(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(t&&!e&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let h=In(l,r.tabSize),f=h%Sn(r)||Sn(r);for(let c=0;c<f&&l[l.length-1-c]==" ";c++)n--;a=n}else a=te(o.text,n-o.from,e,e)+o.from,a==n&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,n-o.from))&&(a=te(o.text,a-o.from,!1,!1)+o.from);return a}),sr=s=>Ch(s,!1,!0),Ah=s=>Ch(s,!0,!1),Mh=(s,e)=>Di(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=te(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||i!=t.head)&&(l=f),i=a}return i}),Th=s=>Mh(s,!1),up=s=>Mh(s,!0),dp=s=>Di(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),pp=s=>Di(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),mp=s=>Di(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),gp=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:P.of(["",""])},range:b.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},yp=({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:te(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:te(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:b.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function 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 Dh(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(b.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(b.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const bp=({state:s,dispatch:e})=>Dh(s,e,!1),xp=({state:s,dispatch:e})=>Dh(s,e,!0);function Oh(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 wp=({state:s,dispatch:e})=>Oh(s,e,!1),vp=({state:s,dispatch:e})=>Oh(s,e,!0),kp=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<e.doc.length&&r++,{from:n,to:r}))),i=Xt(e.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Sp(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Te(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(E.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 al=Bh(!1),Cp=Bh(!0);function Bh(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&&Sp(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new zn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),f=Ja(h,r);for(f==null&&(f=In(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",Cn(e,f)];return a&&c.push(Cn(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:P.of(c)},range:b.cursor(r+1+c[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Or(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Ap=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new zn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=Or(s,(r,o,l)=>{let a=Ja(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],f=Cn(s,a);(h!=f||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:f}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},Mp=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Or(s,(t,i)=>{i.push({from:t.from,insert:s.facet(Vn)})}),{userEvent:"input.indent"})),!0),Tp=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Or(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=In(n,s.tabSize),o=0,l=Cn(s,Math.max(0,r-Sn(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Dp=s=>(s.setTabFocusMode(),!0),Op=[{key:"Ctrl-b",run:lh,shift:gh,preventDefault:!0},{key:"Ctrl-f",run:ah,shift:yh},{key:"Ctrl-p",run:ch,shift:wh},{key:"Ctrl-n",run:uh,shift:vh},{key:"Ctrl-a",run:Ud,shift:sp},{key:"Ctrl-e",run:Gd,shift:rp},{key:"Ctrl-d",run:Ah},{key:"Ctrl-h",run:sr},{key:"Ctrl-k",run:dp},{key:"Ctrl-Alt-h",run:Th},{key:"Ctrl-o",run:gp},{key:"Ctrl-t",run:yp},{key:"Ctrl-v",run:nr}],Bp=[{key:"ArrowLeft",run:lh,shift:gh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Wd,shift:Yd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:$d,shift:ip,preventDefault:!0},{key:"ArrowRight",run:ah,shift:yh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Fd,shift:Xd,preventDefault:!0},{mac:"Cmd-ArrowRight",run:jd,shift:np,preventDefault:!0},{key:"ArrowUp",run:ch,shift:wh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:sl,shift:ol},{mac:"Ctrl-ArrowUp",run:tl,shift:il},{key:"ArrowDown",run:uh,shift:vh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:rl,shift:ll},{mac:"Ctrl-ArrowDown",run:nr,shift:nl},{key:"PageUp",run:tl,shift:il},{key:"PageDown",run:nr,shift:nl},{key:"Home",run:Kd,shift:tp,preventDefault:!0},{key:"Mod-Home",run:sl,shift:ol},{key:"End",run:qd,shift:ep,preventDefault:!0},{key:"Mod-End",run:rl,shift:ll},{key:"Enter",run:al,shift:al},{key:"Mod-a",run:op},{key:"Backspace",run:sr,shift:sr,preventDefault:!0},{key:"Delete",run:Ah,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Th,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:up,preventDefault:!0},{mac:"Mod-Backspace",run:pp,preventDefault:!0},{mac:"Mod-Delete",run:mp,preventDefault:!0}].concat(Op.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),lg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Vd,shift:Qd},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:zd,shift:Zd},{key:"Alt-ArrowUp",run:bp},{key:"Shift-Alt-ArrowUp",run:wp},{key:"Alt-ArrowDown",run:xp},{key:"Shift-Alt-ArrowDown",run:vp},{key:"Mod-Alt-ArrowUp",run:hp},{key:"Mod-Alt-ArrowDown",run:fp},{key:"Escape",run:cp},{key:"Mod-Enter",run:Cp},{key:"Alt-l",mac:"Ctrl-l",run:lp},{key:"Mod-i",run:ap,preventDefault:!0},{key:"Mod-[",run:Tp},{key:"Mod-]",run:Mp},{key:"Mod-Alt-\\",run:Ap},{key:"Shift-Mod-k",run:kp},{key:"Shift-Mod-\\",run:_d},{key:"Mod-/",run:wd},{key:"Alt-A",run:kd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Dp}].concat(Bp),hl=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class _t{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(hl(l)):hl,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 tt(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=Al(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=bt(e);let n=this.normalize(t);if(n.length)for(let r=0,o=i;;r++){let l=n.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,i){let n=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?n={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?n={from:t,to:i}:this.matches.push(1,t)),n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null),n}}typeof Symbol<"u"&&(_t.prototype[Symbol.iterator]=function(){return this});const Lh={from:-1,to:-1,match:/.*/.exec("")},Br="gm"+(/x/.unicode==null?"":"u");class Eh{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Lh,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Rh(e,t,i,n,r);this.re=new RegExp(t,Br+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(n);this.curLineStart=o.from,this.matchPos=Mn(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.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=Mn(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const ds=new WeakMap;class Vt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=ds.get(e);if(!n||n.from>=i||n.to<=t){let l=new Vt(t,e.sliceString(t,i));return ds.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<i&&(r+=e.sliceString(n.to,i)),ds.set(e,new Vt(o,r)),new Vt(t,r.slice(t-o,i-o))}}class Rh{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=Lh,this.matchPos=Mn(e,n),this.re=new RegExp(t,Br+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Vt.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=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,match:t},this.matchPos=Mn(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Vt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Eh.prototype[Symbol.iterator]=Rh.prototype[Symbol.iterator]=function(){return this});function Lp(s){try{return new RegExp(s,Br),!0}catch{return!1}}function Mn(s,e){if(e>=s.length)return e;let t=s.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const Ep=s=>{let{state:e}=s,t=String(e.doc.lineAt(s.state.selection.main.head).number),{close:i,result:n}=cu(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,f,c]=o,u=f?+f.slice(1):0,d=h?+h:l.number;if(h&&c){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=b.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[i,T.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},Rp={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Ip=C.define({combine(s){return Yt(s,Rp,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function ag(s){return[Hp,Fp]}const Pp=L.mark({class:"cm-selectionMatch"}),Np=L.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function fl(s,e,t,i){return(t==0||s(e.sliceDoc(t-1,t))!=_.Word)&&(i==e.doc.length||s(e.sliceDoc(i,i+1))!=_.Word)}function Wp(s,e,t,i){return s(e.sliceDoc(t,t+1))==_.Word&&s(e.sliceDoc(i-1,i))==_.Word}const Fp=ce.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(Ip),{state:t}=s,i=t.selection;if(i.ranges.length>1)return L.none;let n=i.main,r,o=null;if(n.empty){if(!e.highlightWordAroundCursor)return L.none;let a=t.wordAt(n.head);if(!a)return L.none;o=t.charCategorizer(n.head),r=t.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a<e.minSelectionLength||a>200)return L.none;if(e.wholeWords){if(r=t.sliceDoc(n.from,n.to),o=t.charCategorizer(n.head),!(fl(o,t,n.from,n.to)&&Wp(o,t,n.from,n.to)))return L.none}else if(r=t.sliceDoc(n.from,n.to),!r)return L.none}let l=[];for(let a of s.visibleRanges){let h=new _t(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:f,to:c}=h.value;if((!o||fl(o,t,f,c))&&(n.empty&&f<=n.from&&c>=n.to?l.push(Np.range(f,c)):(f>=n.to||c<=n.from)&&l.push(Pp.range(f,c)),l.length>e.maxMatches))return L.none}}return L.set(l)}},{decorations:s=>s.decorations}),Hp=T.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Vp=({state:s,dispatch:e})=>{let{selection:t}=s,i=b.create(t.ranges.map(n=>s.wordAt(n.head)||b.cursor(n.head)),t.mainIndex);return i.eq(t)?!1:(e(s.update({selection:i})),!0)};function zp(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 _t(s.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new _t(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 qp=({state:s,dispatch:e})=>{let{ranges:t}=s.selection;if(t.some(r=>r.from===r.to))return Vp({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=zp(s,i);return n?(e(s.update({selection:s.selection.addRange(b.range(n.from,n.to),!1),effects:T.scrollIntoView(n.to)})),!0):!1},Qt=C.define({combine(s){return Yt(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new tm(e),scrollToMatch:e=>T.scrollIntoView(e)})}});class Ih{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||Lp(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"?`
|
|
11
|
+
`: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 Jp(this):new jp(this)}getCursor(e,t=0,i){let n=e.doc?e:F.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?Bt(this,n,t,i):Ot(this,n,t,i)}}class Ph{constructor(e){this.spec=e}}function Kp(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 Ot(s,e,t,i){let n;return s.wholeWord&&(n=$p(e.doc,e.charCategorizer(e.selection.main.head))),s.test&&(n=Kp(s.test,e,n)),new _t(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:r=>r.toLowerCase(),n)}function $p(s,e){return(t,i,n,r)=>((r>t||r+n.length<i)&&(r=Math.max(0,t-2),n=s.sliceString(r,Math.min(s.length,i+2))),(e(Tn(n,t-r))!=_.Word||e(Dn(n,t-r))!=_.Word)&&(e(Dn(n,i-r))!=_.Word||e(Tn(n,i-r))!=_.Word))}class jp extends Ph{constructor(e){super(e)}nextMatch(e,t,i){let n=Ot(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);n=Ot(this.spec,e,0,r).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length),o=Ot(this.spec,e,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),n&&(n.from!=t||n.to!=i)?n:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Ot(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Ot(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 Up(s,e,t){return(i,n,r)=>(!t||t(i,n,r))&&s(r[0],e,i,n)}function Bt(s,e,t,i){let n;return s.wholeWord&&(n=Gp(e.charCategorizer(e.selection.main.head))),s.test&&(n=Up(s.test,e,n)),new Eh(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:n},t,i)}function Tn(s,e){return s.slice(te(s,e,!1),e)}function Dn(s,e){return s.slice(e,te(s,e))}function Gp(s){return(e,t,i)=>!i[0].length||(s(Tn(i.input,i.index))!=_.Word||s(Dn(i.input,i.index))!=_.Word)&&(s(Dn(i.input,i.index+i[0].length))!=_.Word||s(Tn(i.input,i.index+i[0].length))!=_.Word)}class Jp extends Ph{nextMatch(e,t,i){let n=Bt(this.spec,e,i,e.doc.length).next();return n.done&&(n=Bt(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=Bt(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<e.match.length)return e.match[r]+i.slice(n)}return t})}matchAll(e,t){let i=Bt(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Bt(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 vi=N.define(),Lr=N.define(),ot=De.define({create(s){return new ps(rr(s).create(),null)},update(s,e){for(let t of e.effects)t.is(vi)?s=new ps(t.value.create(),s.panel):t.is(Lr)&&(s=new ps(s.query,t.value?Er:null));return s},provide:s=>xn.from(s,e=>e.panel)});class ps{constructor(e,t){this.query=e,this.panel=t}}const _p=L.mark({class:"cm-searchMatch"}),Yp=L.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Xp=ce.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(ot))}update(s){let e=s.state.field(ot);(e!=s.startState.field(ot)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return L.none;let{view:t}=this,i=new Kt;for(let n=0,r=t.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-500;)a=r[++n].to;s.highlight(t.state,l,a,(h,f)=>{let c=t.state.selection.ranges.some(u=>u.from==h&&u.to==f);i.add(h,f,c?Yp:_p)})}return i.finish()}},{decorations:s=>s.decorations});function Oi(s){return e=>{let t=e.state.field(ot,!1);return t&&t.query.spec.valid?s(e,t):Fh(e)}}const On=Oi((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=b.single(i.from,i.to),r=s.state.facet(Qt);return s.dispatch({selection:n,effects:[Rr(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),Wh(s),!0}),Bn=Oi((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=b.single(n.from,n.to),o=s.state.facet(Qt);return s.dispatch({selection:r,effects:[Rr(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),Wh(s),!0}),Qp=Oi((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:b.create(t.map(i=>b.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),Zp=({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 _t(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(b.range(l.value.from,l.value.to))}return e(s.update({selection:b.create(r,o),userEvent:"select.search.matches"})),!0},cl=Oi((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,f=[];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),f.push(T.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let c=s.state.changes(l);return o&&(a=b.single(o.from,o.to).map(c),f.push(Rr(s,o)),f.push(t.facet(Qt).scrollToMatch(a.main,s))),s.dispatch({changes:c,selection:a,effects:f,userEvent:"input.replace"}),!0}),em=Oi((s,{query:e})=>{if(s.state.readOnly)return!1;let t=e.matchAll(s.state,1e9).map(n=>{let{from:r,to:o}=n;return{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:T.announce.of(i),userEvent:"input.replace.all"}),!0});function Er(s){return s.state.facet(Qt).createPanel(s)}function rr(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(Qt);return new Ih({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e==null?void 0:e.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Nh(s){let e=Pa(s,Er);return e&&e.dom.querySelector("[main-field]")}function Wh(s){let e=Nh(s);e&&e==s.root.activeElement&&e.select()}const Fh=s=>{let e=s.state.field(ot,!1);if(e&&e.panel){let t=Nh(s);if(t&&t!=s.root.activeElement){let i=rr(s.state,e.query.spec);i.valid&&s.dispatch({effects:vi.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[Lr.of(!0),e?vi.of(rr(s.state,e.query.spec)):N.appendConfig.of(nm)]});return!0},Hh=s=>{let e=s.state.field(ot,!1);if(!e||!e.panel)return!1;let t=Pa(s,Er);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Lr.of(!1)}),!0},hg=[{key:"Mod-f",run:Fh,scope:"editor search-panel"},{key:"F3",run:On,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:On,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Hh,scope:"editor search-panel"},{key:"Mod-Shift-l",run:Zp},{key:"Mod-Alt-g",run:Ep},{key:"Mod-d",run:qp,preventDefault:!0}];class tm{constructor(e){this.view=e;let t=this.query=e.state.field(ot).query.spec;this.commit=this.commit.bind(this),this.searchField=Z("input",{value:t.search,placeholder:be(e,"Find"),"aria-label":be(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Z("input",{value:t.replace,placeholder:be(e,"Replace"),"aria-label":be(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Z("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=Z("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=Z("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return Z("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=Z("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>On(e),[be(e,"next")]),i("prev",()=>Bn(e),[be(e,"previous")]),i("select",()=>Qp(e),[be(e,"all")]),Z("label",null,[this.caseField,be(e,"match case")]),Z("label",null,[this.reField,be(e,"regexp")]),Z("label",null,[this.wordField,be(e,"by word")]),...e.state.readOnly?[]:[Z("br"),this.replaceField,i("replace",()=>cl(e),[be(e,"replace")]),i("replaceAll",()=>em(e),[be(e,"replace all")])],Z("button",{name:"close",onclick:()=>Hh(e),"aria-label":be(e,"close"),type:"button"},["×"])])}commit(){let e=new Ih({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:vi.of(e)}))}keydown(e){iu(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Bn:On)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),cl(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(vi)&&!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(Qt).top}}function be(s,e){return s.state.phrase(e)}const Xi=30,Qi=/[\s\.,:;?!]/;function Rr(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-Xi),o=Math.min(n,t+Xi),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Xi;a++)if(!Qi.test(l[a+1])&&Qi.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-Xi;a--)if(!Qi.test(l[a-1])&&Qi.test(l[a])){l=l.slice(0,a);break}}return T.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const im=T.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"}}),nm=[ot,Mt.low(Xp),im];class Vh{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=Te(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(zh(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 ul(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 sm(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=ul(e)+ul(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function rm(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:sm(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}function fg(s,e){return t=>{for(let i=Te(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class dl{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function kt(s){return s.selection.main.from}function zh(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 Ir=Ze.define();function om(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:b.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const pl=new WeakMap;function lm(s){if(!Array.isArray(s))return s;let e=pl.get(s);return e||pl.set(s,e=rm(s)),e}const Ln=N.define(),ki=N.define();class am{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<e.length;){let i=tt(e,t),n=bt(i);this.chars.push(i);let r=e.slice(t,t+n),o=r.toUpperCase();this.folded.push(tt(o==r?r.toLowerCase():o,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:n,precise:r,byWord:o}=this;if(t.length==1){let x=tt(e,0),v=bt(x),D=v==e.length?0:-100;if(x!=t[0])if(x==i[0])D+=-200;else return null;return this.ret(D,[0,v])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let x=0,v=Math.min(e.length,200);x<v&&h<a;){let D=tt(e,x);(D==t[h]||D==i[h])&&(n[h++]=x),x+=bt(D)}if(h<a)return null}let f=0,c=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let x=0,v=Math.min(e.length,200),D=0;x<v&&c<a;){let S=tt(e,x);l<0&&(f<a&&S==t[f]&&(r[f++]=x),d<a&&(S==t[d]||S==i[d]?(d==0&&(p=x),m=x+1,d++):d=0));let M,A=S<255?S>=48&&S<=57||S>=97&&S<=122?2:S>=65&&S<=90?1:0:(M=Al(S))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!x||A==1&&g||D==0&&A!=0)&&(t[c]==S||i[c]==S&&(u=!0)?o[c++]=x:o.length&&(y=!1)),D=A,x+=bt(S)}return c==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(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]):c==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,e)}result(e,t,i){let n=[],r=0;for(let o of t){let l=o+(this.astral?bt(tt(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 hm{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const ee=C.define({combine(s){return Yt(s,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:fm,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=>ml(e(i),t(i)),optionClass:(e,t)=>i=>ml(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function ml(s,e){return s?e?s+" "+e:s:e}function fm(s,e,t,i,n,r){let o=s.textDirection==j.RTL,l=o,a=!1,h="top",f,c,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))f=Math.max(n.top,Math.min(t.top,n.bottom-m))-e.top,c=Math.min(400,l?u:d);else{a=!0,c=Math.min(400,(o?e.right:n.right-e.left)-30);let x=n.bottom-e.bottom;x>=m||x>e.top?f=t.bottom-e.top:(h="bottom",f=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${f/g}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const Pr=N.define();function cm(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;h<r.length;){let f=r[h++],c=r[h++];f>a&&o.appendChild(document.createTextNode(l.slice(a,f)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(f,c))),u.className="cm-completionMatchedText",a=c}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function ms(s,e,t){if(s<=t)return{from:0,to:s};if(e<0&&(e=0),e<=s>>1){let n=Math.floor(e/t);return{from:n*t,to:(n+1)*t}}let i=Math.floor((s-e)/t);return{from:s-(i+1)*t,to:s-i*t}}class um{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(ee);this.optionContent=cm(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ms(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 f=a.target,c;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(c=/-(\d+)$/.exec(f.id))&&+c[1]<h.length){this.applyCompletion(e,h[+c[1]]),a.preventDefault();return}if(a.target==this.list){let f=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;f!=null&&(e.dispatch({effects:Pr.of(f)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ee).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:ki.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=ms(r.length,o,e.state.facet(ee).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.from||t.selected>=this.range.to)&&(this.range=ms(t.options.length,t.selected,this.view.state.facet(ee).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=>we(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&&pm(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<Math.max(r.top,t.top)+10?null:this.view.state.facet(ee).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",o=>{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.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 f=n.appendChild(document.createElement("li"));f.id=t+"-"+o,f.setAttribute("role","option");let c=this.optionClass(l);c&&(f.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&f.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function dm(s,e){return t=>new um(t,s,e)}function pm(s,e){let t=s.getBoundingClientRect(),i=e.getBoundingClientRect(),n=t.height/s.offsetHeight;i.top<t.top?s.scrollTop-=(t.top-i.top)/n:i.bottom>t.bottom&&(s.scrollTop+=(i.bottom-t.bottom)/n)}function gl(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function mm(s,e){let t=[],i=null,n=null,r=f=>{t.push(f);let{section:c}=f.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=e.facet(ee);for(let f of s)if(f.hasResult()){let c=f.result.getMatch;if(f.result.filter===!1)for(let u of f.result.options)r(new dl(u,f.source,c?c(u):[],1e9-t.length));else{let u=e.sliceDoc(f.from,f.to),d,p=o.filterStrict?new hm(u):new am(u);for(let m of f.result.options)if(d=p.match(m.label)){let g=m.displayLabel?c?c(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(r(new dl(m,f.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:x}=m.section;n||(n=Object.create(null)),n[x]=Math.max(y,n[x]||-1e9)}}}}if(i){let f=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?n[p.name]-n[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(u))c-=1e5,f[d.name]=c;for(let d of t){let{section:p}=d.completion;p&&(d.score+=f[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let f of t.sort((c,u)=>u.score-c.score||h(c.completion,u.completion))){let c=f.completion;!a||a.label!=c.label||a.detail!=c.detail||a.type!=null&&c.type!=null&&a.type!=c.type||a.apply!=c.apply||a.boost!=c.boost?l.push(f):gl(f.completion)>gl(a)&&(l[l.length-1]=f),a=f.completion}return l}class It{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 It(this.options,yl(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=mm(e,t);if(!l.length)return n&&e.some(h=>h.isPending)?n.setDisabled():null;let a=t.facet(ee).selectOnOpen?0:-1;if(n&&n.selected!=a&&n.selected!=-1){let h=n.options[n.selected].completion;for(let f=0;f<l.length;f++)if(l[f].completion==h){a=f;break}}return new It(l,yl(i,a),{pos:e.reduce((h,f)=>f.hasResult()?Math.min(h,f.from):h,1e8),create:vm,above:r.aboveCursor},n?n.timestamp:Date.now(),a,!1)}map(e){return new It(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new It(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class En{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new En(xm,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(ee),r=(i.override||t.languageDataAt("autocomplete",kt(t)).map(lm)).map(a=>(this.active.find(f=>f.source==a)||new Me(a,this.active.some(f=>f.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(Nr));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!gm(r,this.active)||l?o=It.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 Me(a.source,0):a));for(let a of e.effects)a.is(Pr)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new En(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?ym:bm}}function gm(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t<s.length&&!s[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let n=t==s.length,r=i==e.length;if(n||r)return n==r;if(s[t++].result!=e[i++].result)return!1}}const ym={"aria-autocomplete":"list"},bm={};function yl(s,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return e>-1&&(t["aria-activedescendant"]=s+"-"+e),t}const xm=[];function qh(s,e){if(s.isUserEvent("input.complete")){let i=s.annotation(Ir);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 Me{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=qh(e,t),n=this;(i&8||i&16&&this.touches(e))&&(n=new Me(n.source,0)),i&4&&n.state==0&&(n=new Me(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(Ln))n=new Me(n.source,1,r.value);else if(r.is(ki))n=new Me(n.source,0);else if(r.is(Nr))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(kt(e.state))}}class zt extends Me{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=kt(e.state);if(l>o||!n||t&2&&(kt(e.startState)==this.from||l<this.limit))return new Me(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return wm(n.validFor,e.state,r,o)?new zt(this.source,this.explicit,a,n,r,o):n.update&&(n=n.update(n,r,o,new Vh(e.state,l,!1)))?new zt(this.source,this.explicit,a,n,n.from,(i=n.to)!==null&&i!==void 0?i:kt(e.state)):new Me(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new zt(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Me(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function wm(s,e,t,i){if(!s)return!1;let n=e.sliceDoc(t,i);return typeof s=="function"?s(n,t,i,e):zh(s,!0).test(n)}const Nr=N.define({map(s,e){return s.map(t=>t.map(e))}}),ue=De.define({create(){return En.start()},update(s,e){return s.update(e)},provide:s=>[Ra.from(s,e=>e.tooltip),T.contentAttributes.from(s,e=>e.attrs)]});function Wr(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(ue).active.find(n=>n.source==e.source);return i instanceof zt?(typeof t=="string"?s.dispatch({...om(s.state,t,i.from,i.to),annotations:Ir.of(e.completion)}):t(s,e.completion,i.from,i.to),!0):!1}const vm=dm(ue,Wr);function Zi(s,e="option"){return t=>{let i=t.state.field(ue,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(ee).interactionDelay)return!1;let n=1,r;e=="page"&&(r=Ia(t,i.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-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:Pr.of(l)}),!0}}const km=s=>{let e=s.state.field(ue,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<s.state.facet(ee).interactionDelay?!1:Wr(s,e.open.options[e.open.selected])},gs=s=>s.state.field(ue,!1)?(s.dispatch({effects:Ln.of(!0)}),!0):!1,Sm=s=>{let e=s.state.field(ue,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:ki.of(null)}),!0)};class Cm{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Am=50,Mm=1e3,Tm=ce.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(ue).active)e.isPending&&this.startQuery(e)}update(s){let e=s.state.field(ue),t=s.state.facet(ee);if(!s.selectionSet&&!s.docChanged&&s.startState.field(ue)==e)return;let i=s.transactions.some(r=>{let o=qh(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&s.docChanged||o.updates.length+s.transactions.length>Am&&Date.now()-o.time>Mm){for(let l of o.context.abortListeners)try{l()}catch(a){we(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(Ln)))&&(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(ue);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(ee).updateSyncTime))}startQuery(s){let{state:e}=this.view,t=kt(e),i=new Vh(e,t,s.explicit,this.view),n=new Cm(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:ki.of(null)}),we(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(ee).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ee),i=this.view.state.field(ue);for(let n=0;n<this.running.length;n++){let r=this.running[n];if(r.done===void 0)continue;if(this.running.splice(n--,1),r.done){let l=kt(r.updates.length?r.updates[0].startState:this.view.state),a=Math.min(l,r.done.from+(r.active.explicit?0:1)),h=new zt(r.active.source,r.active.explicit,a,r.done,r.done.from,(s=r.done.to)!==null&&s!==void 0?s:l);for(let f of r.updates)h=h.update(f,t);if(h.hasResult()){e.push(h);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Me(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:Nr.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(ue,!1);if(e&&e.tooltip&&this.view.state.facet(ee).closeOnBlur){let t=e.open&&Ia(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:ki.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Ln.of(!1)}),20),this.composing=0}}}),Dm=typeof navigator=="object"&&/Win/.test(navigator.platform),Om=Mt.highest(T.domEventHandlers({keydown(s,e){let t=e.state.field(ue,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||s.key.length>1||s.ctrlKey&&!(Dm&&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&&Wr(e,i),!1}})),Kh=T.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Bm{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class Fr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,he.TrackDel),i=e.mapPos(this.to,1,he.TrackDel);return t==null||i==null?null:new Fr(this.field,t,i)}}class Hr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let h=o,f=/^\t*/.exec(a)[0].length;for(let c=0;c<f;c++)h+=e.facet(Vn);n.push(t+h.length-f),a=h+a.slice(f)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Fr(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1,f=a.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:f&&t[c].name==f)&&(h=c);if(h<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:f}),h=c;for(let u of n)u.field>=h&&u.field++}for(let c of n)if(c.line==i.length&&c.from>r.index){let u=r[2]?3+(r[1]||"").length:2;c.from-=u,c.to-=u}n.push(new Bm(h,i.length,r.index,r.index+f.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let f of n)f.line==i.length&&f.from>h&&(f.from--,f.to--);return a}),i.push(o)}return new Hr(i,n)}}let Lm=L.widget({widget:new class extends Ci{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Em=L.mark({class:"cm-snippetField"});class Zt{constructor(e,t){this.ranges=e,this.active=t,this.deco=L.set(e.map(i=>(i.from==i.to?Lm:Em).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new Zt(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const Bi=N.define({map(s,e){return s&&s.map(e)}}),Rm=N.define(),Si=De.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(Bi))return t.value;if(t.is(Rm)&&s)return new Zt(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>T.decorations.from(s,e=>e?e.deco:L.none)});function Vr(s,e){return b.create(s.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Im(s){let e=Hr.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),{main:a}=t.state.selection,h={changes:{from:n,to:r==a.from?a.to:r,insert:P.of(o)},scrollIntoView:!0,annotations:i?[Ir.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(h.selection=Vr(l,0)),l.some(f=>f.field>0)){let f=new Zt(l,0),c=h.effects=[Bi.of(f)];t.state.field(Si,!1)===void 0&&c.push(N.appendConfig.of([Si,Hm,Vm,Kh]))}t.dispatch(t.state.update(h))}}function $h(s){return({state:e,dispatch:t})=>{let i=e.field(Si,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:Vr(i.ranges,n),effects:Bi.of(r?null:new Zt(i.ranges,n)),scrollIntoView:!0})),!0}}const Pm=({state:s,dispatch:e})=>s.field(Si,!1)?(e(s.update({effects:Bi.of(null)})),!0):!1,Nm=$h(1),Wm=$h(-1),Fm=[{key:"Tab",run:Nm,shift:Wm},{key:"Escape",run:Pm}],bl=C.define({combine(s){return s.length?s[0]:Fm}}),Hm=Mt.highest(vr.compute([bl],s=>s.facet(bl)));function cg(s,e){return{...e,apply:Im(s)}}const Vm=T.domEventHandlers({mousedown(s,e){let t=e.state.field(Si,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:Vr(t.ranges,n.field),effects:Bi.of(t.ranges.some(r=>r.field>n.field)?new Zt(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),jh=new class extends lt{};jh.startSide=1;jh.endSide=-1;function ug(s={}){return[Om,ue,ee.of(s),Tm,qm,Kh]}const zm=[{key:"Ctrl-Space",run:gs},{mac:"Alt-`",run:gs},{mac:"Alt-i",run:gs},{key:"Escape",run:Sm},{key:"ArrowDown",run:Zi(!0)},{key:"ArrowUp",run:Zi(!1)},{key:"PageDown",run:Zi(!0,"page")},{key:"PageUp",run:Zi(!1,"page")},{key:"Enter",run:km}],qm=Mt.highest(vr.computeN([ee],s=>s.facet(ee).defaultKeymap?[zm]:[]));export{Ee as A,Vn as B,Vh as C,Su as D,T as E,F,Rt as G,Ga as H,V as I,kn as J,Mr as K,Ym as L,ng as M,Va as N,Rn as O,Bu as P,jm as Q,$m as R,Um as S,X as T,sg as U,ag as V,rg as W,ug as X,lg as Y,og as Z,hg as _,ye as a,E as b,rm as c,Ju as d,Xs as e,Qu as f,Qm as g,Zm as h,fg as i,Xm as j,tg as k,ig as l,cg as m,Te as n,b as o,Gu as p,Gm as q,Jm as r,qu as s,B as t,pd as u,ke as v,Mt as w,vr as x,eg as y,In as z};
|