var lsp=function(t){"use strict";let e=[],i=[];function n(t){if(t<768)return!1;for(let n=0,s=e.length;;){let r=n+s>>1;if(t=i[r]))return!0;n=r+1}if(n==s)return!1}}function s(t){return t>=127462&&t<=127487}(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let n=0,s=0;n=0&&s(a(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function l(t,e,i){for(;e>0;){let n=o(t,e-2,i);if(n=56320&&t<57344}function c(t){return t>=55296&&t<56320}function u(t){return t<65536?1:2}class d{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=x(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),p.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=x(this,t,e);let i=[];return this.decompose(t,e,i,0),p.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new v(this),s=new v(t);for(let t=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){return new v(this,t)}iterRange(t,e=this.length){return new w(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new b(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new f(t):p.from(f.split(t,[])):d.empty}}class f extends d{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((e?i:o)>=t)return new y(n,o,i,r);n=o+1,i++}}decompose(t,e,i,n){let s=t<=0&&e>=this.length?this:new f(g(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&n){let t=i.pop(),e=m(s.text,t.text.slice(),0,s.length);if(e.length<=32)i.push(new f(e,t.length+s.length));else{let t=e.length>>1;i.push(new f(e.slice(0,t)),new f(e.slice(t)))}}else i.push(s)}replace(t,e,i){if(!(i instanceof f))return super.replace(t,e,i);[t,e]=x(this,t,e);let n=m(this.text,m(i.text,g(this.text,0,t)),e),s=this.length+i.length-(e-t);return n.length<=32?new f(n,s):p.from(f.split(n,[]),s)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;s<=e&&rt&&r&&(n+=i),ts&&(n+=o.slice(Math.max(0,t-s),e-s)),s=l+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let s of t)i.push(s),n+=s.length+1,32==i.length&&(e.push(new f(i,n)),i=[],n=-1);return n>-1&&e.push(new f(i,n)),e}}class p extends d{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,l=i+r.lines-1;if((e?l:o)>=t)return r.lineInner(t,e,i,n);n=o+1,i=l+1}}decompose(t,e,i,n){for(let s=0,r=0;r<=e&&s=r){let s=n&((r<=t?1:0)|(l>=e?2:0));r>=t&&l<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=l+1}}replace(t,e,i){if([t,e]=x(this,t,e),i.lines=s&&e<=o){let l=r.replace(t-s,e-s,i),a=this.lines-r.lines+l.lines;if(l.lines>4&&l.lines>a>>6){let s=this.children.slice();return s[n]=l,new p(s,this.length-(e-t)+i.length)}return super.replace(s,o,l)}s=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;st&&s&&(n+=i),tr&&(n+=o.sliceString(t-r,e-r,i)),r=l+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof p))return 0;let i=0,[n,s,r,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==r||s==o)return i;let l=this.children[n],a=t.children[s];if(l!=a)return i+l.scanIdentical(a,e);i+=l.length+1}}static from(t,e=t.reduce((t,e)=>t+e.length+1,-1)){let i=0;for(let e of t)i+=e.lines;if(i<32){let i=[];for(let e of t)e.flatten(i);return new f(i,e)}let n=Math.max(32,i>>5),s=n<<1,r=n>>1,o=[],l=0,a=-1,h=[];function c(t){let e;if(t.lines>s&&t instanceof p)for(let e of t.children)c(e);else t.lines>r&&(l>r||!l)?(u(),o.push(t)):t instanceof f&&l&&(e=h[h.length-1])instanceof f&&t.lines+e.lines<=32?(l+=t.lines,a+=t.length+1,h[h.length-1]=new f(e.text.concat(t.text),e.length+1+t.length)):(l+t.lines>n&&u(),l+=t.lines,a+=t.length+1,h.push(t))}function u(){0!=l&&(o.push(1==h.length?h[0]:p.from(h,a)),a=-1,l=h.length=0)}for(let e of t)c(e);return u(),1==o.length?o[0]:new p(o,e)}}function m(t,e,i=0,n=1e9){for(let s=0,r=0,o=!0;r=i&&(a>n&&(l=l.slice(0,n-s)),s0?1:(t instanceof f?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],r=s>>1,o=n instanceof f?n.text.length:n.children.length;if(r==(e>0?o:0)){if(0==i)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&s)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(n instanceof f){let s=n.text[r+(e<0?-1:0)];if(this.offsets[i]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=n.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof f?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class w{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new v(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class b{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(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}}"undefined"!=typeof Symbol&&(d.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=w.prototype[Symbol.iterator]=b.prototype[Symbol.iterator]=function(){return this});class y{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function x(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}function k(t,e,i=!0,n=!0){return r(t,e,i,n)}function S(t,e){let i=t.charCodeAt(e);if(!(n=i,n>=55296&&n<56320&&e+1!=t.length))return i;var n;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(i-55296<<10)+65536:i}function C(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function M(t){return t<65536?1:2}const A=/\r\n?|\n/;var T=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(T||(T={}));class D{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=T.Simple&&a>=t&&(i==T.TrackDel&&nt||i==T.TrackBefore&&nt))return null;if(a>t||a==t&&e<0&&!o)return t==n||e<0?s:s+l;s+=l}n=a}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let i=0,n=0;i=0&&n<=e&&s>=t)return!(ne)||"cover";n=s}return!1}toString(){let t="";for(let e=0;e=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(t=>"number"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeDesc");return new D(t)}static create(t){return new D(t)}}class O extends D{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return P(this,(e,i,n,s,r)=>t=t.replace(n,n+(i-e),r),!1),t}mapDesc(t,e=!1){return L(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,s=0;n=0){e[n]=o,e[n+1]=r;let l=n>>1;for(;i.length0&&E(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(t,e,i){let n=[],s=[],r=0,o=null;function l(t=!1){if(!t&&!n.length)return;ro||t<0||o>e)throw new RangeError(`Invalid change range ${t} to ${o} (in doc of length ${e})`);let c=h?"string"==typeof h?d.of(h.split(i||A)):h:d.empty,u=c.length;if(t==o&&0==u)return;tr&&R(n,t-r,-1),R(n,o-t,u),E(s,n,c),r=o}}(t),l(!o),o}static empty(t){return new O(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;ne&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;i.length=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function E(t,e,i){if(0==i.length)return;let n=e.length-2>>1;if(n>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)l=t.sections[o++],a=t.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function L(t,e,i,n=!1){let s=[],r=n?[]:null,o=new B(t),l=new B(e);for(let t=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);R(s,t,-1),o.forward(t),l.forward(t)}else if(l.ins>=0&&(o.ins<0||t==o.i||0==o.off&&(l.len=0&&t=0)){if(o.done&&l.done)return r?O.createSet(s,r):D.create(s);throw new Error("Mismatched change set lengths")}{let e=0,i=o.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.lene||o.ins>=0&&o.len>e)&&(t||n.length>i),r.forward2(e),o.forward(e)}}else R(n,0,o.ins,t),s&&E(s,n,o.text),o.next()}}class B{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?d.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?d.empty:e[i].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class N{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new N(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return z.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return z.range(this.anchor,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return z.range(t.anchor,t.head)}static create(t,e,i){return new N(t,e,i)}}class z{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:z.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;it.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new z(t.ranges.map(t=>N.fromJSON(t)),t.main)}static single(t,e=t){return new z([z.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;nt?8:0)|s)}static normalized(t,e=0){let i=t[e];t.sort((t,e)=>t.from-e.from),e=t.indexOf(i);for(let i=1;in.head?z.range(o,r):z.range(r,o))}}return new z(t,e)}}function H(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let F=0;class q{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=F++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new q(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:V),!!t.static,t.enables)}of(t){return new W([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],i=>e(i.field(t)))}}function V(t,e){return t==e||t.length==e.length&&t.every((t,i)=>t===e[i])}class W{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=F++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,s=this.id,r=t[s]>>1,o=2==this.type,l=!1,a=!1,h=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?a=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||h.push(t[i.id]);return{create:t=>(t.values[r]=i(t),1),update(t,e){if(l&&e.docChanged||a&&(e.docChanged||e.selection)||$(t,h)){let e=i(t);if(o?!_(e,t.values[r],n):!n(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let l,a=e.config.address[s];if(null!=a){let s=rt(e,a);if(this.dependencies.every(i=>i instanceof q?e.facet(i)===t.facet(i):!(i instanceof U)||e.field(i,!1)==t.field(i,!1))||(o?_(l=i(t),s,n):n(l=i(t),s)))return t.values[r]=s,0}else l=i(t);return t.values[r]=l,1}}}}function _(t,e,i){if(t.length!=e.length)return!1;for(let n=0;nt[e.id]),s=i.map(t=>t.type),r=n.filter(t=>!(1&t)),o=t[e.id]>>1;function l(t){let i=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(K).find(t=>t.field==this);return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let n=t.values[e],s=this.updateF(n,i);return this.compareF(n,s)?0:(t.values[e]=s,1)},reconfigure:(t,i)=>{let n,s=t.facet(K),r=i.facet(K);return(n=s.find(t=>t.field==this))&&n!=r.find(t=>t.field==this)?(t.values[e]=n.create(t),1):null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,K.of({field:this,create:t})]}get extension(){return this}}const Y=4,G=3,X=2,J=1;function Z(t){return e=>new tt(e,t)}const Q={highest:Z(0),high:Z(J),default:Z(X),low:Z(G),lowest:Z(Y)};class tt{constructor(t,e){this.inner=t,this.prec=e}}class et{of(t){return new it(this,t)}reconfigure(t){return et.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class it{constructor(t,e){this.compartment=t,this.inner=e}}class nt{constructor(t,e,i,n,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let n=[],s=Object.create(null),r=new Map;for(let i of function(t,e,i){let n=[[],[],[],[],[]],s=new Map;function r(t,o){let l=s.get(t);if(null!=l){if(l<=o)return;let e=n[l].indexOf(t);e>-1&&n[l].splice(e,1),t instanceof it&&i.delete(t.compartment)}if(s.set(t,o),Array.isArray(t))for(let e of t)r(e,o);else if(t instanceof it){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(t.compartment)||t.inner;i.set(t.compartment,n),r(n,o)}else if(t instanceof tt)r(t.inner,t.prec);else if(t instanceof U)n[o].push(t),t.provides&&r(t.provides,o);else if(t instanceof W)n[o].push(t),t.facet.extensions&&r(t.facet.extensions,X);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(e,o)}}return r(t,X),n.reduce((t,e)=>t.concat(e))}(t,e,r))i instanceof U?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),l=[],a=[];for(let t of n)o[t.id]=a.length<<1,a.push(e=>t.slot(e));let h=null==i?void 0:i.config.facets;for(let t in s){let e=s[t],n=e[0].facet,r=h&&h[t]||[];if(e.every(t=>0==t.type))if(o[n.id]=l.length<<1|1,V(r,e))l.push(i.facet(n));else{let t=n.combine(e.map(t=>t.value));l.push(i&&n.compare(t,i.facet(n))?i.facet(n):t)}else{for(let t of e)0==t.type?(o[t.id]=l.length<<1|1,l.push(t.value)):(o[t.id]=a.length<<1,a.push(e=>t.dynamicSlot(e)));o[n.id]=a.length<<1,a.push(t=>j(t,n,e))}}let c=a.map(t=>t(o));return new nt(t,r,c,o,l,s)}}function st(t,e){if(1&e)return 2;let i=e>>1,n=t.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function rt(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const ot=q.define(),lt=q.define({combine:t=>t.some(t=>t),static:!0}),at=q.define({combine:t=>t.length?t[0]:void 0,static:!0}),ht=q.define(),ct=q.define(),ut=q.define(),dt=q.define({combine:t=>!!t.length&&t[0]});class ft{constructor(t,e){this.type=t,this.value=e}static define(){return new pt}}class pt{of(t){return new ft(this,t)}}class mt{constructor(t){this.map=t}of(t){return new gt(this,t)}}class gt{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new gt(this.type,e)}is(t){return this.type==t}static define(t={}){return new mt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let t=n.map(e);t&&i.push(t)}return i}}gt.reconfigure=gt.define(),gt.appendConfig=gt.define();class vt{constructor(t,e,i,n,s,r){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&H(i,e.newLength),s.some(t=>t.type==vt.time)||(this.annotations=s.concat(vt.time.of(Date.now())))}static create(t,e,i,n,s,r){return new vt(t,e,i,n,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(vt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function wt(t,e){let i=[];for(let n=0,s=0;;){let r,o;if(n=t[n]))r=t[n++],o=t[n++];else{if(!(s=0;s--){let r=i[s](t);r&&Object.keys(r).length&&(n=bt(n,yt(e,r,t.changes.newLength),!0))}return n==t?t:vt.create(e,t.changes,t.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let n of e.facet(ht)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:wt(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=O.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=vt.create(e,n,t.selection&&t.selection.map(s),gt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(ct);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof vt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof vt?s[0]:xt(e,St(s),!1)}return t}(s):s)}vt.time=ft.define(),vt.userEvent=ft.define(),vt.addToHistory=ft.define(),vt.remote=ft.define();const kt=[];function St(t){return null==t?kt:Array.isArray(t)?t:[t]}var Ct=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ct||(Ct={}));const Mt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let At;try{At=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Tt(t){return e=>{if(!/\S/.test(e))return Ct.Space;if(function(t){if(At)return At.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||Mt.test(i)))return!0}return!1}(e))return Ct.Word;for(let i=0;i-1)return Ct.Word;return Ct.Other}}class Dt{constructor(t,e,i,n,s,r){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t)),i=null),s.set(e.value.compartment,e.value.extension)):e.is(gt.reconfigure)?(i=null,n=e.value):e.is(gt.appendConfig)&&(i=null,n=St(n).concat(e.value));if(i)e=t.startState.values.slice();else{i=nt.resolve(n,s,this),e=new Dt(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(lt)?t.newSelection:t.newSelection.asSingle();new Dt(i,t.newDoc,r,e,(e,i)=>i.update(e,t),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:z.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),s=[i.range],r=St(i.effects);for(let i=1;is.spec.fromJSON(r,t)))}return Dt.create({doc:t.doc,selection:z.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),i=t.doc instanceof d?t.doc:d.of((t.doc||"").split(e.staticFacet(Dt.lineSeparator)||A)),n=t.selection?t.selection instanceof z?t.selection:z.single(t.selection.anchor,t.selection.head):z.single(0);return H(n,i.length),e.staticFacet(lt)||(n=n.asSingle()),new Dt(e,i,n,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Dt.tabSize)}get lineBreak(){return this.facet(Dt.lineSeparator)||"\n"}get readOnly(){return this.facet(dt)}phrase(t,...e){for(let e of this.facet(Dt.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(t,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>e.length?t:e[n-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let s of this.facet(ot))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){return Tt(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-i,o=t-i;for(;r>0;){let t=k(e,r,!1);if(s(e.slice(t,r))!=Ct.Word)break;r=t}for(;ot.length?t[0]:4}),Dt.lineSeparator=at,Dt.readOnly=dt,Dt.phrases=q.define({compare(t,e){let i=Object.keys(t),n=Object.keys(e);return i.length==n.length&&i.every(i=>t[i]==e[i])}}),Dt.languageData=ot,Dt.changeFilter=ht,Dt.transactionFilter=ct,Dt.transactionExtender=ut,et.reconfigure=gt.define();class Rt{eq(t){return this==t}range(t,e=t){return Et.create(t,e,this)}}Rt.prototype.startSide=Rt.prototype.endSide=0,Rt.prototype.point=!1,Rt.prototype.mapMode=T.TrackDel;let Et=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,n){return new t(e,i,n)}};function Pt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Lt{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,l=s[n]-t||(i?this.value[n].endSide:this.value[n].startSide)-e;if(n==r)return l>=0?r:o;l>=0?o=n:r=n+1}}between(t,e,i,n){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(i,1e9,!1,s);sh||a==h&&c.startSide>0&&c.endSide<=0)continue;(h-a||c.endSide-c.startSide)<0||(r<0&&(r=a),c.point&&(o=Math.max(o,h-a)),i.push(c),n.push(a-r),s.push(h-r))}return{mapped:i.length?new Lt(n,s,i,o):null,pos:r}}}class It{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new It(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(i&&(e=e.slice().sort(Pt)),this.isEmpty)return e.length?It.of(e):this;let o=new zt(this,null,-1).goto(0),l=0,a=[],h=new Bt;for(;o.value||l=0){let t=e[l++];h.addInner(t.from,t.to,t.value)||a.push(t)}else 1==o.rangeIndex&&o.chunkIndexthis.chunkEnd(o.chunkIndex)||so.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Ht.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ht.from(t).goto(e)}static compare(t,e,i,n,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),l=Nt(r,o,i),a=new qt(r,l,s),h=new qt(o,l,s);i.iterGaps((t,e,i)=>Vt(a,t,h,e,i,n)),i.empty&&0==i.length&&Vt(a,0,h,0,0,n)}static eq(t,e,i=0,n){null==n&&(n=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Nt(s,r),l=new qt(s,o,0).goto(i),a=new qt(r,o,0).goto(i);for(;;){if(l.to!=a.to||!Wt(l.active,a.active)||l.point&&(!a.point||!l.point.eq(a.point)))return!1;if(l.to>n)return!0;l.next(),a.next()}}static spans(t,e,i,n,s=-1){let r=new qt(t,null,s).goto(e),o=e,l=r.openStart;for(;;){let t=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFromo&&(n.span(o,t,r.active,l),l=r.openEnd(t));if(r.to>i)return l+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(t,e=!1){let i=new Bt;for(let n of t instanceof Et?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(Pt);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return It.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=It.empty;n=n.nextLayer)e=new It(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}It.empty=new It([],[],null,-1),It.empty.nextLayer=It.empty;class Bt{finishChunk(t){this.chunks.push(new Lt(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Bt)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(It.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=It.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Nt(t,e,i){let n=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new zt(r,e,i,s));return 1==n.length?n[0]:new Ht(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ft(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ft(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Ft(this.heap,0)}}}function Ft(t,e){for(let i=t[e];;){let n=1+(e<<1);if(n>=t.length)break;let s=t[n];if(n+1=0&&(s=t[n+1],n++),i.compare(s)<0)break;t[n]=i,t[e]=s,e=n}}class qt{constructor(t,e,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=Ht.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){_t(this.active,t),_t(this.activeTo,t),_t(this.activeRank,t),this.minActive=jt(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e0;)e++;$t(this.active,e,i),$t(this.activeTo,e,n),$t(this.activeRank,e,s),t&&$t(t,e,this.cursor.from),this.minActive=jt(this.active,this.activeTo)}next(){let t=this.to,e=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]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&_t(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&i[e]=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function Vt(t,e,i,n,s,r){t.goto(e),i.goto(n);let o=n+s,l=n,a=n-e;for(;;){let e=t.to+a-i.to,n=e||t.endSide-i.endSide,s=n<0?t.to+a:i.to,h=Math.min(s,o);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&Wt(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,h,t.point,i.point):h>l&&!Wt(t.active,i.active)&&r.compareRange(l,h,t.active,i.active),s>o)break;(e||t.openEnd!=i.openEnd)&&r.boundChange&&r.boundChange(s),l=s,n<=0&&t.next(),n>=0&&i.next()}}function Wt(t,e){if(t.length!=e.length)return!1;for(let i=0;i=e;i--)t[i+1]=t[i];t[e]=i}function jt(t,e){let i=-1,n=1e9;for(let s=0;s=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=k(t,n)}return!0===n?-1:t.length}const Yt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Gt="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Xt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Jt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function s(t,e,r,o){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return r.push(t[0]+";");for(let i in e){let o=e[i];if(/&/.test(i))s(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),o,r);else if(o&&"object"==typeof o){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,l,h)}else null!=o&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+o+";")}(l.length||h)&&r.push((!i||a||o?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)s(n(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Xt[Yt]||1;return Xt[Yt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Gt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new Qt(t,s),n.mount(Array.isArray(e)?e:[e],t)}}let Zt=new Map;class Qt{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=Zt.get(i);if(e)return t[Gt]=e;this.sheet=new n.CSSStyleSheet,Zt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Gt]=this}mount(t,e){let i=this.sheet,n=0,s=0;for(let e=0;e-1&&(this.modules.splice(o,1),s--,o=-1),-1==o){if(this.modules.splice(s++,0,r),i)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ie="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ne="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),se=0;se<10;se++)te[48+se]=te[96+se]=String(se);for(se=1;se<=24;se++)te[se+111]="F"+se;for(se=65;se<=90;se++)te[se]=String.fromCharCode(se+32),ee[se]=String.fromCharCode(se);for(var re in te)ee.hasOwnProperty(re)||(ee[re]=te[re]);function oe(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var s=i[n];"string"==typeof s?t.setAttribute(n,s):null!=s&&(t[n]=s)}e++}for(;e2);var be={mac:we||/Mac/.test(ae.platform),windows:/Win/.test(ae.platform),linux:/Linux|X11/.test(ae.platform),ie:fe,ie_version:ue?he.documentMode||6:de?+de[1]:ce?+ce[1]:0,gecko:pe,gecko_version:pe?+(/Firefox\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,chrome:!!me,chrome_version:me?+me[1]:0,ios:we,android:/Android\b/.test(ae.userAgent),webkit_version:ge?+(/\bAppleWebKit\/(\d+)/.exec(ae.userAgent)||[0,0])[1]:0,safari:ve,safari_version:ve?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ae.userAgent)||[0,0])[1]:0,tabSize:null!=he.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function ye(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function xe(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function ke(t,e){if(!e.anchorNode)return!1;try{return xe(t,e.anchorNode)}catch(t){return!1}}function Se(t){return 3==t.nodeType?Ne(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function Ce(t,e,i,n){return!!i&&(Te(t,e,i,n,-1)||Te(t,e,i,n,1))}function Me(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function Ae(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function Te(t,e,i,n,s){for(;;){if(t==i&&e==n)return!0;if(e==(s<0?0:De(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=Me(t)+(s<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(s<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=s<0?De(t):0}}}function De(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Oe(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function Re(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function Ee(t,e){let i=e.width/t.offsetWidth,n=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-t.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}class Pe{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?De(e):0),i,Math.min(t.focusOffset,i?De(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Le,Ie=null;function Be(t){if(t.setActive)return t.setActive();if(Ie)return t.focus(Ie);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==Ie?{get preventScroll(){return Ie={preventScroll:!0},!0}}:void 0),!Ie){Ie=!1;for(let t=0;tMath.max(1,t.scrollHeight-t.clientHeight-4)}function qe(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=De(i)}else{if(!i.parentNode||Ae(i))return null;n=Me(i),i=i.parentNode}}}function Ve(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n=26&&(Ie=!1);class We{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new We(t.parentNode,Me(t),e)}static after(t,e){return new We(t.parentNode,Me(t)+1,e)}}const _e=[];class $e{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(2&this.flags){let i,n=this.dom,s=null;for(let r of this.children){if(7&r.flags){if(!r.dom&&(i=s?s.nextSibling:n.firstChild)){let t=$e.get(i);(!t||!t.parent&&t.canReuseDOM(r))&&r.reuseDOM(i)}r.sync(t,e),r.flags&=-8}if(i=s?s.nextSibling:n.firstChild,e&&!e.written&&e.node==n&&i!=r.dom&&(e.written=!0),r.dom.parentNode==n)for(;i&&i!=r.dom;)i=je(i);else n.insertBefore(r.dom,i);s=r.dom}for(i=s?s.nextSibling:n.firstChild,i&&e&&e.node==n&&(e.written=!0);i;)i=je(i)}else if(1&this.flags)for(let i of this.children)7&i.flags&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=0==De(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==this.dom)break;0==n&&e.firstChild!=e.lastChild&&(n=t==e.firstChild?-1:1),t=e}i=n<0?t:t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!$e.get(i);)i=i.nextSibling;if(!i)return this.length;for(let t=0,e=0;;t++){let n=this.children[t];if(n.dom==i)return e;e+=n.length+n.breakAfter}}domBoundsAround(t,e,i=0){let n=-1,s=-1,r=-1,o=-1;for(let l=0,a=i,h=i;le)return i.domBoundsAround(t,e,a);if(c>=t&&-1==n&&(n=l,s=a),a>e&&i.dom.parentNode==this.dom){r=l,o=h;break}h=c,a=c+i.breakAfter}return{from:s,to:o<0?i+this.length:o,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:r=0?this.children[r].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),1&e.flags)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,7&this.flags&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=_e){this.markDirty();for(let n=t;nthis.pos||t==this.pos&&(e>0||0==this.i||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Ue(t,e,i,n,s,r,o,l,a){let{children:h}=t,c=h.length?h[e]:null,u=r.length?r[r.length-1]:null,d=u?u.breakAfter:o;if(!(e==n&&c&&!o&&!d&&r.length<2&&c.merge(i,s,r.length?u:null,0==i,l,a))){if(n0&&(!o&&r.length&&c.merge(i,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(i256||8&i.flags))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ge(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=8&this.flags,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new We(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return function(t,e,i){let n=t.nodeValue.length;e>n&&(e=n);let s=e,r=e,o=0;0==e&&i<0||e==n&&i>=0?be.chrome||be.gecko||(e?(s--,o=1):r=0)?0:l.length-1];be.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,t=>t.width)||a);return o?Oe(a,o<0):a||null}(this.dom,t,e)}}class Xe extends $e{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let t of e)t.setParent(this)}setAttrs(t){if(He(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!(8&(this.flags|t.flags))}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?4&this.flags&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,s,r){return(!i||!(!(i instanceof Xe&&i.mark.eq(this.mark))||t&&s<=0||et&&e.push(i=t&&(n=s),i=o,s++}let r=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Xe(this.mark,e,r)}domAtPos(t){return Qe(this,t)}coordsAt(t,e){return ei(this,t,e)}}class Je extends $e{static create(t,e,i){return new Je(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Je.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){this.dom&&this.widget.updateDOM(this.dom,t)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof Je&&this.widget.compare(i.widget))||t>0&&s<=0||e0)?We.before(this.dom):We.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),s=null;if(!n.length)return null;let r=this.side?this.side<0:t>0;for(let e=r?n.length-1:0;s=n[e],!(t>0?0==e:e==n.length-1||s.top0?We.before(this.dom):We.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return d.empty}get isHidden(){return!0}}function Qe(t,e){let i=t.dom,{children:n}=t,s=0;for(let t=0;st&&e0;t--){let e=n[t-1];if(e.dom.parentNode==i)return e.domAtPos(e.length)}for(let t=s;t0&&e instanceof Xe&&s.length&&(n=s[s.length-1])instanceof Xe&&n.mark.eq(e.mark)?ti(n,e.children[0],i-1):(s.push(e),e.setParent(t)),t.length+=e.length}function ei(t,e,i){let n=null,s=-1,r=null,o=-1;!function t(e,l){for(let a=0,h=0;a=l&&(c.children.length?t(c,l-h):(!r||r.isHidden&&(i>0||ii(r,c)))&&(u>l||h==u&&c.getSide()>0)?(r=c,o=l-h):(h-1?1:0)!=s.length-(i&&s.indexOf(i)>-1?1:0))return!1;for(let r of n)if(r!=i&&(-1==s.indexOf(r)||t[r]!==e[r]))return!1;return!0}function oi(t,e,i){let n=!1;if(e)for(let s in e)i&&s in i||(n=!0,"style"==s?t.style.cssText="":t.removeAttribute(s));if(i)for(let s in i)e&&e[s]==i[s]||(n=!0,"style"==s?t.style.cssText=i[s]:t.setAttribute(s,i[s]));return n}function li(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new fi(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,n=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:s,end:r}=pi(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new fi(t,e,i,n,t.widget||null,!0)}static line(t){return new di(t)}static set(t,e=!1){return It.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ci.none=It.empty;class ui extends ci{constructor(t){let{start:e,end:i}=pi(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof ui&&this.tagName==t.tagName&&(this.class||(null===(e=this.attrs)||void 0===e?void 0:e.class))==(t.class||(null===(i=t.attrs)||void 0===i?void 0:i.class))&&ri(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}ui.prototype.point=!1;class di extends ci{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof di&&this.spec.class==t.spec.class&&ri(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}di.prototype.mapMode=T.TrackBefore,di.prototype.point=!0;class fi extends ci{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?T.TrackBefore:T.TrackAfter:T.TrackDel}get type(){return this.startSide!=this.endSide?hi.WidgetRange:this.startSide<=0?hi.WidgetBefore:hi.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof fi&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}function pi(t,e=!1){let{inclusiveStart:i,inclusiveEnd:n}=t;return null==i&&(i=t.inclusive),null==n&&(n=t.inclusive),{start:null!=i?i:e,end:null!=n?n:e}}function mi(t,e,i,n=0){let s=i.length-1;s>=0&&i[s]+n>=t?i[s]=Math.max(i[s],e):i.push(t,e)}fi.prototype.point=!0;class gi extends $e{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,s,r){if(i){if(!(i instanceof gi))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Ye(this,t,e,i?i.children.slice():[],s,r),!0}split(t){let e=new gi;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i:i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let t=i;t0&&0==this.children[i-1].length;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){ri(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){ti(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=ni(e,this.attrs||{})),i&&(this.attrs=ni({class:i},this.attrs||{}))}domAtPos(t){return Qe(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(He(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),void 0!==this.prevAttrs&&(oi(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&$e.get(n)instanceof Xe;)n=n.lastChild;if(!(n&&this.length&&("BR"==n.nodeName||0!=(null===(i=$e.get(n))||void 0===i?void 0:i.isEditable)||be.ios&&this.children.some(t=>t instanceof Ge)))){let t=document.createElement("BR");t.cmIgnore=!0,this.dom.appendChild(t)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let t,e=0;for(let i of this.children){if(!(i instanceof Ge)||/[^ -~]/.test(i.text))return null;let n=Se(i.dom);if(1!=n.length)return null;e+=n[0].width,t=n[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(t,e){let i=ei(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:t}=this.parent.view.viewState,e=i.bottom-i.top;if(Math.abs(e-t.lineHeight)<2&&t.textHeight=e){if(s instanceof gi)return s;if(r>e)break}n=r+s.breakAfter}return null}}class vi extends $e{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof vi&&this.widget.compare(i.widget))||t>0&&s<=0||e0)}}class wi extends ai{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class bi{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(0==this.content.length)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof vi&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new gi),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(yi(new Ze(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||t&&this.content.length&&this.content[this.content.length-1]instanceof vi||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:n}=this.cursor.next(this.skip);if(this.skip=0,n)throw new Error("Ran out of text content when drawing inline views");if(i){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}this.text=e,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t),s=Math.min(n,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(yi(new Ge(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=n<=s?0:e.length}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,s,r){if(this.disallowBlockEffectsFor[r]&&i instanceof fi){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let o=e-t;if(i instanceof fi)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new vi(i.widget||xi.block,o,i));else{let r=Je.create(i.widget||xi.inline,o,o?0:i.startSide),l=this.atCursorPos&&!r.isEditable&&s<=n.length&&(t0),a=!r.isEditable&&(tn.length||i.startSide<=0),h=this.getLine();2!=this.pendingBuffer||l||r.isEditable||(this.pendingBuffer=0),this.flushBuffer(n),l&&(h.append(yi(new Ze(1),n),s),s=n.length+Math.max(0,s-n.length)),h.append(yi(r,n),s),this.atCursorPos=a,this.pendingBuffer=a?tn.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=s)}static build(t,e,i,n,s){let r=new bi(t,e,i,s);return r.openEnd=It.spans(n,e,i,r),r.openStart<0&&(r.openStart=r.openEnd),r.finish(r.openEnd),r}}function yi(t,e){for(let i of e)t=new Xe(i,[t],t.length);return t}class xi extends ai{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}xi.inline=new xi("span"),xi.block=new xi("div");var ki=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(ki||(ki={}));const Si=ki.LTR,Ci=ki.RTL;function Mi(t){let e=[];for(let i=0;i=e){if(o.level==i)return r;(s<0||(0!=n?n<0?o.frome:t[s].level>o.level))&&(s=r)}}if(s<0)throw new RangeError("Index out of range");return s}}function Li(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new Pi(a,p.from,d)),Ni(t,p.direction==Si!=!(d%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to}f=p.to}else{if(f==i||(e?Ii[f]!=l:Ii[f]==l))break;f++}u?Bi(t,a,f,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=Ii[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],d=i?n:n+1,f=a;t:for(;;)if(h&&f==r[h-1].to){if(c)break t;let p=r[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||r[i-1].to!=t){if(Ii[t-1]==l)break t;break}t=r[--i].from}if(u)u.push(p);else{p.to=0;t-=3)if(Oi[t+1]==-i){let e=Oi[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(Ii[o]=Ii[Oi[t]]=i),l=t;break}}else{if(189==Oi.length)break;Oi[l++]=o,Oi[l++]=e,Oi[l++]=a}else if(2==(n=Ii[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Oi[e+2];if(2&i)break;if(t)Oi[e+2]|=2;else{if(4&i)break;Oi[e+2]|=4}}}}}(t,s,r,n,l),function(t,e,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:t,l=sa;)e==r&&(e=i[--n].from,r=n?i[n-1].to:t),Ii[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),Bi(t,s,r,e,i,n,o)}function zi(t){return[new Pi(0,t,0)]}let Hi="";function Fi(t,e,i,n,s){var r;let o=n.head-t.from,l=Pi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc),a=e[l],h=a.side(s,i);if(o==h){let t=l+=s?1:-1;if(t<0||t>=e.length)return null;a=e[l=t],o=a.side(!s,i),h=a.side(s,i)}let c=k(t.text,o,a.forward(s,i));(ca.to)&&(c=h),Hi=t.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)t.some(t=>t)}),Ji=q.define({combine:t=>t.some(t=>t)}),Zi=q.define();class Qi{constructor(t,e="nearest",i="nearest",n=5,s=5,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s,this.isSnapshot=r}map(t){return t.empty?this:new Qi(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Qi(z.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const tn=gt.define({map:(t,e)=>t.map(e)}),en=gt.define();function nn(t,e,i){let n=t.facet($i);n.length?n[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const sn=q.define({combine:t=>!t.length||t[0]});let rn=0;const on=q.define({combine:t=>t.filter((e,i)=>{for(let n=0;n{let e=[];return r&&e.push(un.of(e=>{let i=e.plugin(t);return i?r(i):ci.none})),s&&e.push(s(t)),e})}static fromClass(t,e){return ln.define((e,i)=>new t(e,i),e)}}class an{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(nn(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){nn(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){nn(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const hn=q.define(),cn=q.define(),un=q.define(),dn=q.define(),fn=q.define(),pn=q.define();function mn(t,e){let i=t.state.facet(pn);if(!i.length)return i;let n=i.map(e=>e instanceof Function?e(t):e),s=[];return It.spans(n,e.from,e.to,{point(){},span(t,i,n,r){let o=t-e.from,l=i-e.from,a=s;for(let t=n.length-1;t>=0;t--,r--){let i,s=n[t].spec.bidiIsolate;if(null==s&&(s=qi(e.text,o,l)),r>0&&a.length&&(i=a[a.length-1]).to==o&&i.direction==s)i.to=l,a=i.inner;else{let t={from:o,to:l,direction:s,inner:[]};a.push(t),a=t.inner}}}}),s}const gn=q.define();function vn(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(gn)){let o=r(t);o&&(null!=o.left&&(e=Math.max(e,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(s=Math.max(s,o.bottom)))}return{left:e,right:i,top:n,bottom:s}}const wn=q.define();class bn{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new bn(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAh)break;s+=2}if(!l)return i;new bn(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),r=l.toA,o=l.toB}}}class yn{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=O.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let n=[];this.changes.iterChangedRanges((t,e,i,s)=>n.push(new bn(t,e,i,s))),this.changedRanges=n}static create(t,e,i){return new yn(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}class xn extends $e{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=ci.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new gi],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new bn(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:t,toA:e})=>ethis.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,n)=>{te.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=kn(t,i);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc,h=new bn(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let e=s.parentNode;;e=e.parentNode){let i=$e.get(e);if(i instanceof Xe)c.push({node:e,deco:i.mark});else{if(i instanceof gi||"DIV"==e.nodeName&&e.parentNode==t.contentDOM)return{range:h,text:s,marks:c,line:e};if(e==t.contentDOM)return null;c.push({node:e,deco:new ui({inclusive:!0,attributes:li(e),tagName:e.tagName.toLowerCase()})})}}}(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:e,to:n}=this.hasComposition;i=new bn(e,n,t.changes.mapPos(e,-1),t.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(be.ie||be.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=function(t,e,i){let n=new Sn;return It.compare(t,e,i,n),n.changes}(this.decorations,this.updateDeco(),t.changes);return i=bn.extendWithRanges(i,r),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,t.startState.doc.length,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=be.chrome||be.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,t),this.flags&=-8,t&&(t.written||n.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(t=>t.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?n[t]:null;if(!e)break;let r,o,l,a,{fromA:h,toA:c,fromB:u,toB:d}=e;if(i&&i.range.fromBu){let t=bi.build(this.view.state.doc,u,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=bi.build(this.view.state.doc,i.range.toB,d,this.decorations,this.dynamicDecorationMap);o=t.breakAtStart,l=t.openStart,a=e.openEnd;let n=this.compositionView(i);e.breakAtStart?n.breakAfter=1:e.content.length&&n.merge(n.length,n.length,e.content[0],!1,e.openStart,0)&&(n.breakAfter=e.content[0].breakAfter,e.content.shift()),t.content.length&&n.merge(0,0,t.content[t.content.length-1],!0,0,t.openEnd)&&t.content.pop(),r=t.content.concat(n).concat(e.content)}else({content:r,breakAtStart:o,openStart:l,openEnd:a}=bi.build(this.view.state.doc,u,d,this.decorations,this.dynamicDecorationMap));let{i:f,off:p}=s.findPos(c,1),{i:m,off:g}=s.findPos(h,-1);Ue(this,m,g,f,p,r,o,l,a)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)t.is(en)&&(this.editContextFormatting=t.value)}compositionView(t){let e=new Ge(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new Xe(i,[e],e.length);let i=new gi;return i.append(e,0),i}fixCompositionDOM(t){let e=(t,e)=>{e.flags|=8|(e.children.some(t=>7&t.flags)?1:0),this.markedForComposition.add(e);let i=$e.get(t);i&&i!=e&&(i.dom=null),e.setDOM(t)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let s=t.marks.length-1;s>=-1;s--)i=n.childPos(i.off,1),n=n.children[i.i],e(s>=0?t.marks[s].node:t.text,n)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,s=!n&&!(this.view.state.facet(sn)||this.dom.tabIndex>-1)&&ke(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||s))return;let r=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(o.anchor)),a=o.empty?l:this.moveToLine(this.domAtPos(o.head));if(be.gecko&&o.empty&&!this.hasComposition&&(1==(h=l).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new We(t,0),r=!0}var h;let c=this.view.observer.selectionRange;!r&&c.focusNode&&(Ce(l.node,l.offset,c.anchorNode,c.anchorOffset)&&Ce(a.node,a.offset,c.focusNode,c.focusOffset)||this.suppressWidgetCursorChange(c,o))||(this.view.observer.ignore(()=>{be.android&&be.chrome&&this.dom.contains(c.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=ye(this.view.root);if(t)if(o.empty){if(be.gecko){let t=(e=l.node,n=l.offset,1!=e.nodeType?0:(n&&"false"==e.childNodes[n-1].contentEditable?1:0)|(no.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,n;s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new We(c.anchorNode,c.anchorOffset),this.impreciseHead=a.precise?null:new We(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Ce(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ye(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=gi.find(this,e.head);if(!r)return;let o=r.posAtStart;if(e.head==o||e.head==o+r.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,s)}moveToLine(t){let e,i=this.dom;if(t.node!=i)return t;for(let n=t.offset;!e&&n=0;n--){let t=$e.get(i.childNodes[n]);t instanceof gi&&(e=t.domAtPos(t.length))}return e?new We(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=$e.get(e);if(t&&t.rootView==this)return t;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e=0;r--){let o=this.children[r],l=s-o.breakAfter,a=l-o.length;if(lt||o.covers(1))&&(!i||o instanceof gi&&!(i instanceof gi&&e>=0)))i=o,n=a;else if(i&&a==t&&l==t&&o instanceof vi&&Math.abs(e)<2){if(o.deco.startSide<0)break;r&&(i=null)}s=a}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof gi))return null;for(;n.children.length;){let{i:t,off:e}=n.childPos(i,1);for(;;t++){if(t==n.children.length)return null;if((n=n.children[t]).length)break}i=e}if(!(n instanceof Ge))return null;let s=k(n.text,i);if(s==i)return null;let r=Ne(n.dom,i,s).getClientRects();for(let t=0;tMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==ki.LTR;for(let t=0,a=0;an)break;if(t>=i){let i=h.dom.getBoundingClientRect();if(e.push(i.height),r){let e=h.dom.lastChild,n=e?Se(e):[];if(n.length){let e=n[n.length-1],r=l?e.right-i.left:i.right-e.left;r>o&&(o=r,this.minWidth=s,this.minWidthFrom=t,this.minWidthTo=c)}}}t=c+h.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?ki.RTL:ki.LTR}measureTextSize(){for(let t of this.children)if(t instanceof gi){let e=t.measureTextSize();if(e)return e}let t,e,i,n=document.createElement("div");return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(n);let s=Se(n.firstChild)[0];t=n.getBoundingClientRect().height,e=s?s.width/27:7,i=s?s.height:t,n.remove()}),{lineHeight:t,charWidth:e,textHeight:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Ke(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],r=s?s.from-1:this.length;if(r>i){let n=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(ci.replace({widget:new wi(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return ci.set(t)}updateDeco(){let t=1,e=this.view.state.facet(un).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,n=this.view.state.facet(dn).map((t,e)=>{let n="function"==typeof t;return n&&(i=!0),n?t(this.view):t});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(It.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];ti.anchor?-1:1);if(!n)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,e.left),top:Math.min(n.top,e.top),right:Math.max(n.right,e.right),bottom:Math.max(n.bottom,e.bottom)});let s=vn(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,n,s,r,o,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,u=!1;c&&!u;)if(1==c.nodeType){let t,d=c==a.body,f=1,p=1;if(d)t=Re(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:f,scaleY:p}=Ee(c,e)),t={left:e.left,right:e.left+c.clientWidth*f,top:e.top,bottom:e.top+c.clientHeight*p}}let m=0,g=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+o)):e.bottom>t.bottom&&(g=e.bottom-t.bottom+o,i<0&&e.top-g0&&e.right>t.right+m&&(m=e.right-t.right+r)):e.right>t.right&&(m=e.right-t.right+r,i<0&&e.leftt.bottom||e.leftt.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,r,i.headt?e.left-t:Math.max(0,t-e.right)}function Mn(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function An(t,e){return t.tope.top+1}function Tn(t,e){return et.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function On(t,e,i){let n,s,r,o,l,a,h,c,u=!1;for(let d=t.firstChild;d;d=d.nextSibling){let t=Se(d);for(let f=0;fg||o==g&&r>m)&&(n=d,s=p,r=m,o=g,u=!m||(e0:fp.bottom&&(!h||h.bottomp.top)&&(a=d,c=p):h&&An(h,p)?h=Dn(h,p.bottom):c&&An(c,p)&&(c=Tn(c,p.top))}}if(h&&h.bottom>=i?(n=l,s=h):c&&c.top<=i&&(n=a,s=c),!n)return{node:t,offset:0};let d=Math.max(s.left,Math.min(s.right,e));return 3==n.nodeType?Rn(n,d,i):u&&"false"!=n.contentEditable?On(n,d,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,n)+(e>=(s.left+s.right)/2?1:0)}}function Rn(t,e,i){let n=t.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;li?h.top-i:i-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&c=(h.left+h.right)/2,n=i;if(be.chrome||be.gecko){Ne(t,l).getBoundingClientRect().left==h.right&&(n=!i)}if(c<=0)return{node:t,offset:l+(n?1:0)};s=l+(n?1:0),r=c}}}return{node:t,offset:s>-1?s:o>0?t.nodeValue.length:0}}function En(t,e,i,n=-1){var s,r;let o,l=t.contentDOM.getBoundingClientRect(),a=l.top+t.viewState.paddingTop,{docHeight:h}=t.viewState,{x:c,y:u}=e,d=u-a;if(d<0)return 0;if(d>h)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,s=!1;o=t.elementAtHeight(d),o.type!=hi.Text;)for(;d=n>0?o.bottom+e:o.top-e,!(d>=0&&d<=h);){if(s)return i?null:0;s=!0,n=-n}u=a+d;let f=o.from;if(ft.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:Pn(t,l,o,c,u);let p=t.dom.ownerDocument,m=t.root.elementFromPoint?t.root:p,g=m.elementFromPoint(c,u);g&&!t.contentDOM.contains(g)&&(g=null),g||(c=Math.max(l.left+1,Math.min(l.right-1,c)),g=m.elementFromPoint(c,u),g&&!t.contentDOM.contains(g)&&(g=null));let v,w=-1;if(g&&0!=(null===(s=t.docView.nearest(g))||void 0===s?void 0:s.isEditable)){if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(c,u);t&&({offsetNode:v,offset:w}=t)}else if(p.caretRangeFromPoint){let t=p.caretRangeFromPoint(c,u);t&&({startContainer:v,startOffset:w}=t)}v&&(!t.contentDOM.contains(v)||be.safari&&function(t,e,i){return Ln(t,e,i)}(v,w,c)||be.chrome&&function(t,e,i){if(0!=e)return Ln(t,e,i);for(let e=t;;){let t=e.parentNode;if(!t||1!=t.nodeType||t.firstChild!=e)return!1;if(t.classList.contains("cm-line"))break;e=t}let n=1==t.nodeType?t.getBoundingClientRect():Ne(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect();return i-n.left>5}(v,w,c))&&(v=void 0),v&&(w=Math.min(De(v),w))}if(!v||!t.docView.dom.contains(v)){let e=gi.find(t.docView,f);if(!e)return d>o.top+o.height/2?o.to:o.from;({node:v,offset:w}=On(e.dom,c,u))}let b=t.docView.nearest(v);if(!b)return null;if(b.isWidget&&1==(null===(r=b.dom)||void 0===r?void 0:r.nodeType)){let t=b.dom.getBoundingClientRect();return e.y1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let o=t.state.sliceDoc(i.from,i.to);return i.from+Ut(o,r,t.state.tabSize)}function Ln(t,e,i){let n,s=t;if(3!=t.nodeType||e!=(n=t.nodeValue.length))return!1;for(;;){let t=s.nextSibling;if(t){if("BR"==t.nodeName)break;return!1}{let t=s.parentNode;if(!t||"DIV"==t.nodeName)break;s=t}}return Ne(t,n-1,n).getBoundingClientRect().right>i}function In(t,e,i){let n=t.lineBlockAt(e);if(Array.isArray(n.type)){let t;for(let s of n.type){if(s.from>e)break;if(!(s.toe)return s;t&&(s.type!=hi.Text||t.type==s.type&&!(i<0?s.frome))||(t=s)}}return t||n}return n}function Bn(t,e,i,n){let s=t.state.doc.lineAt(e.head),r=t.bidiSpans(s),o=t.textDirectionAt(s.from);for(let l=e,a=null;;){let e=Fi(s,r,o,l,i),h=Hi;if(!e){if(s.number==(i?t.state.doc.lines:1))return l;h="\n",s=t.state.doc.line(s.number+(i?1:-1)),r=t.bidiSpans(s),e=t.visualLineSide(s,!i)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function Nn(t,e,i){for(;;){let n=0;for(let s of t)s.between(e-1,e+1,(t,s,r)=>{if(e>t&&ee(t)),i.from,e.head>i.from?-1:1);return n==i.from?i:z.cursor(n,nt)&&!Wn(s,e)&&this.lineBreak(),n=s}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(e))&&(r=s.index,o=s[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=$e.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Vn(t,i.node,i.offset)?e:0))}}function Vn(t,e,i){for(;;){if(!e||i-1;let{impreciseHead:s,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let e=s||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=t.observer.selectionRange;i&&(e.push(new _n(i,n)),s==i&&r==n||e.push(new _n(s,r)));return e}(t),i=new qn(e,t.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,n=2==t.length?t[1].pos:i;return i>-1&&n>-1?z.single(i+e,n+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=s&&s.node==e.focusNode&&s.offset==e.focusOffset||!xe(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),n=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!xe(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),o=t.viewport;if((be.ios||be.chrome)&&t.state.selection.main.empty&&i!=n&&(o.from>0||o.toDate.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:n,to:o}=e.bounds,l=s.from,a=null;(8===r||be.android&&e.text.length=s.from&&i.to<=s.to&&(i.from!=s.from||i.to!=s.to)&&s.to-s.from-(i.to-i.from)<=4?i={from:s.from,to:s.to,insert:t.state.doc.slice(s.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,s.to))}:be.chrome&&i&&i.from==i.to&&i.from==s.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(n&&(n=z.single(n.main.anchor-1,n.main.head-1)),i={from:s.from,to:s.to,insert:d.of([" "])}),i)return Kn(t,i,n,r);if(n&&!n.main.eq(s)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=zn(t.state.facet(fn).map(e=>e(t)),n))),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}function Kn(t,e,i,n=-1){if(be.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(be.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&" "==t.state.sliceDoc(e.from,s.from))&&1==e.insert.length&&2==e.insert.lines&&ze(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&0==e.insert.length||8==n&&e.insert.lengths.head)&&ze(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&0==e.insert.length&&ze(t.contentDOM,"Delete",46)))return!0;let r,o=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let l=()=>r||(r=function(t,e,i){let n,s=t.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.fromr.to){let i=e.frome(t)),n,i);e.from==l&&(o=l)}if(o>-1)n={changes:e,selection:z.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&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.frome.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let o=s.changes(e),l=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&t.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let a,h=t.state.sliceDoc(e.from,e.to),c=i&&kn(t,i.main.head);if(c){let t=e.insert.length-(e.to-e.from);a={from:c.from,to:c.to-t}}else a=t.state.doc.lineAt(r.head);let u=r.to-e.to,d=r.to-r.from;n=s.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:l||i.map(o)};let n=i.to-u,c=n-h.length;if(i.to-i.from!=d||t.state.sliceDoc(c,n)!=h||i.to>=a.from&&i.from<=a.to)return{range:i};let f=s.changes({from:c,to:n,insert:e.insert}),p=i.to-r.to;return{changes:f,range:l?z.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(f)}})}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let l="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,l+=".compose",t.inputState.compositionFirstChange&&(l+=".start",t.inputState.compositionFirstChange=!1));return s.update(n,{userEvent:l,scrollIntoView:!0})}(t,e,i));return t.state.facet(Ki).some(i=>i(t,e.from,e.to,o,l))||t.dispatch(l()),!0}function Un(t,e,i,n){let s=Math.min(t.length,e.length),r=0;for(;r0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if("end"==n){i-=o+Math.max(0,r-Math.min(o,l))-r}if(o=o?r-i:0,l=r+(l-o),o=r}else if(l=l?r-i:0,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}class Yn{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,be.safari&&t.contentDOM.addEventListener("input",()=>null),be.gecko&&function(t){xs.has(t)||(xs.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,n=e.target;n!=t.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=$e.get(n))&&i.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Xn(t),i=this.handlers,n=this.view.contentDOM;for(let t in e)if("scroll"!=t){let s=!e[t].handlers.length,r=i[t];r&&s!=!r.handlers.length&&(n.removeEventListener(t,this.handleEvent),r=null),r||n.addEventListener(t,this.handleEvent,{passive:s})}for(let t in i)"scroll"==t||e[t]||n.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&Qn.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),be.android&&be.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!be.ios||t.synthetic||t.altKey||t.metaKey||!((e=Jn.find(e=>e.keyCode==t.keyCode))&&!t.ctrlKey||Zn.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from0||!!(be.safari&&!be.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Gn(t,e){return(i,n)=>{try{return e.call(t,n,i)}catch(t){nn(i.state,t)}}}function Xn(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,n=t&&t.plugin.domEventHandlers,s=t&&t.plugin.domEventObservers;if(n)for(let t in n){let s=n[t];s&&i(t).handlers.push(Gn(e.value,s))}if(s)for(let t in s){let n=s[t];n&&i(t).observers.push(Gn(e.value,n))}}for(let t in is)i(t).handlers.push(is[t]);for(let t in ns)i(t).observers.push(ns[t]);return e}const Jn=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Zn="dthko",Qn=[16,17,18,20,91,92,224,225];function ts(t){return.7*Math.max(0,t)+8}class es{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=function(t){let e,i,n=t.ownerDocument;for(let s=t.parentNode;s&&!(s==n.body||e&&i);)if(1==s.nodeType)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else{if(11!=s.nodeType)break;s=s.host}return{x:e,y:i}}(t.contentDOM),this.atoms=t.state.facet(fn).map(e=>e(t));let s=t.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Dt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Vi);return i.length?i[0](e):be.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let n=ye(t.root);if(!n||0==n.rangeCount)return!0;let s=n.getRangeAt(0).getClientRects();for(let t=0;t=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=ms(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let n=0,s=0,r=0,o=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=vn(this.view);t.clientX-h.left<=r+6?n=-ts(r-t.clientX):t.clientX+h.right>=l-6&&(n=ts(t.clientX-l)),t.clientY-h.top<=o+6?s=-ts(o-t.clientY):t.clientY+h.bottom>=a-6&&(s=ts(t.clientY-a)),this.setScrollSpeed(n,s)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=zn(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const is=Object.create(null),ns=Object.create(null),ss=be.ie&&be.ie_version<15||be.ios&&be.webkit_version<604;function rs(t,e,i){for(let n of t.facet(e))i=n(i,t);return i}function os(t,e){e=rs(t.state,Yi,e);let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=vs&&n.selection.ranges.every(t=>t.empty)&&vs==r.toString()){let t=-1;i=n.changeByRange(i=>{let l=n.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let a=n.toText((o?r.line(s++).text:e)+n.lineBreak);return{changes:{from:l.from,insert:a},range:z.cursor(i.from+a.length)}})}else i=o?n.changeByRange(t=>{let e=r.line(s++);return{changes:{from:t.from,to:t.to,insert:e.text},range:z.cursor(t.from+e.length)}}):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function ls(t,e,i,n){if(1==n)return z.cursor(e,i);if(2==n)return function(t,e,i=1){let n=t.charCategorizer(e),s=t.doc.lineAt(e),r=e-s.from;if(0==s.length)return z.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=k(s.text,r,!1):l=k(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=k(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},is.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),ns.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},ns.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},is.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of t.state.facet(_i))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=cs(t,e),n=ms(e),s=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),s=s.map(t.changes))},get(e,r,o){let l,a=cs(t,e),h=ls(t,a.pos,a.bias,n);if(i.pos!=a.pos&&!r){let e=ls(t,i.pos,i.bias,n),s=Math.min(e.from,h.from),r=Math.max(e.to,h.to);h=s1&&(l=function(t,e){for(let i=0;i=e)return z.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(s,a.pos))?l:o?s.addRange(h):z.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new es(t,e,i,n)),n&&t.observer.ignore(()=>{Be(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),!1===s.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};let as=(t,e,i)=>e>=i.top&&e<=i.bottom&&t>=i.left&&t<=i.right;function hs(t,e,i,n){let s=gi.find(t.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(0==r)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&as(i,n,o))return-1;let l=s.coordsAt(r,1);return l&&as(i,n,l)?1:o&&o.bottom>=n?-1:1}function cs(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:hs(t,i,e.clientX,e.clientY)}}const us=be.ie&&be.ie_version<=11;let ds=null,fs=0,ps=0;function ms(t){if(!us)return t.detail;let e=ds,i=ps;return ds=t,ps=Date.now(),fs=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(fs+1)%3:1}function gs(t,e,i,n){if(!(i=rs(t.state,Yi,i)))return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=t.inputState,o=n&&r&&function(t,e){let i=t.state.facet(Wi);return i.length?i[0](e):be.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.from,to:r.to}:null,l={from:s,insert:i},a=t.state.changes(o?[o,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}is.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let n=t.docView.nearest(e.target);if(n&&n.isWidget){let t=n.posAtStart,e=t+n.length;(t>=i.to||e<=i.from)&&(i=z.range(t,e))}}let{inputState:n}=t;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",rs(t.state,Gi,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},is.dragend=t=>(t.inputState.draggedContent=null,!1),is.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&gs(t,e,n.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(n[t]=e.result),r()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return gs(t,e,i,!0),!0}return!1},is.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=ss?null:e.clipboardData;return i?(os(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),os(t,i.value)},50)}(t),!1)};let vs=null;is.copy=is.cut=(t,e)=>{let{text:i,ranges:n,linewise:s}=function(t){let e=[],i=[],n=!1;for(let n of t.selection.ranges)n.empty||(e.push(t.sliceDoc(n.from,n.to)),i.push(n));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let r=t.doc.lineAt(n);r.number>s&&(e.push(r.text),i.push({from:r.from,to:Math.min(t.doc.length,r.to+1)})),s=r.number}n=!0}return{text:rs(t,Gi,e.join(t.lineBreak)),ranges:i,linewise:n}}(t.state);if(!i&&!s)return!1;vs=s?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=ss?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),t.focus()},50)}(t,i),!1)};const ws=ft.define();function bs(t,e){let i=[];for(let n of t.facet(Ui)){let s=n(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:ws.of(!0)}):null}function ys(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=bs(t.state,e);i?t.dispatch(i):t.update([])}},10)}ns.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),ys(t)},ns.blur=t=>{t.observer.clearSelectionRange(),ys(t)},ns.compositionstart=ns.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},ns.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,be.chrome&&be.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},ns.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},is.beforeinput=(t,e)=>{var i,n;if("insertReplacementText"==e.inputType&&t.observer.editContext){let n=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),s=e.getTargetRanges();if(n&&s.length){let e=s[0],i=t.posAtDOM(e.startContainer,e.startOffset),r=t.posAtDOM(e.endContainer,e.endOffset);return Kn(t,{from:i,to:r,insert:t.state.toText(n)},null),!0}}let s;if(be.chrome&&be.android&&(s=Jn.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return be.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),be.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>ns.compositionend(t,e),20),!1};const xs=new Set;const ks=["pre-wrap","normal","pre-line","break-spaces"];let Ss=!1;function Cs(){Ss=!1}class Ms{constructor(t){this.lineWrapping=t,this.doc=d.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return ks.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=s,l){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Os&&(Ss=!0),this.height=t)}replace(t,e,i){return Rs.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=n[o],u=s.lineAt(l,Ds.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=a?u:s.lineAt(a,Ds.ByPosNoHeight,i,0,0);for(c+=d.to-a,a=d.to;o>0&&u.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,l2*s){let s=t[e-1];s.break?t.splice(--e,1,s.left,null,s.right):t.splice(--e,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,s-=e.size}}else if(n=s&&r(this.blockAt(0,i,n,s))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ls extends Ps{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new Ts(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Ls||n instanceof Is&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Is?n=new Ls(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Rs.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Is extends Rs{constructor(t){super(t,0)}heightMetrics(t,e){let i,n=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-n+1,o=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*r);i=e/r,this.length>r+1&&(o=(this.height-e)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(t,e,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:l}=this.heightMetrics(e,n);if(e.lineWrapping){let s=n+(t0){let t=i[i.length-1];t instanceof Is?i[i.length-1]=new Is(t.length+n):i.push(null,new Is(n-1))}if(t>0){let e=i[0];e instanceof Is?i[0]=new Is(t+e.length):i.unshift(new Is(t-1),null)}return Rs.of(i)}decomposeLeft(t,e){e.push(new Is(t-1),null)}decomposeRight(t,e){e.push(null,new Is(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let i=[],r=Math.max(e,n.from),o=-1;for(n.from>e&&i.push(new Is(n.from-e-1).updateHeight(t,e));r<=s&&n.more;){let e=t.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++];-1==o?o=s:Math.abs(s-o)>=Os&&(o=-2);let l=new Ls(e,s);l.outdated=!1,i.push(l),r+=e+1}r<=s&&i.push(null,new Is(s-r).updateHeight(t,r));let l=Rs.of(i);return(o<0||Math.abs(l.height-this.height)>=Os||Math.abs(o-this.heightMetrics(t,e).perLine)>=Os)&&(Ss=!0),Es(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Bs extends Rs{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return 1&this.flags}blockAt(t,e,i,n){let s=i+this.left.height;return to))return a;let h=e==Ds.ByPosNoHeight?Ds.ByPosNoHeight:Ds.ByPos;return l?a.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(a)}forEachLine(t,e,i,n,s,r){let o=n+this.left.height,l=s+this.left.length+this.break;if(this.break)t=l&&this.right.forEachLine(t,e,i,o,l,r);else{let a=this.lineAt(l,Ds.ByPos,i,n,s);t=t&&a.from<=e&&r(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,o,l,r)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let s=[];t>0&&this.decomposeLeft(t,s);let r=s.length;for(let t of i)s.push(t);if(t>0&&Ns(s,r-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Rs.of(this.break?[t,null,e]:[t,e]):(this.left=Es(this.left,t),this.right=Es(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:s,right:r}=this,o=e+s.length+this.break,l=null;return n&&n.from<=e+s.length&&n.more?l=s=s.updateHeight(t,e,i,n):s.updateHeight(t,e,i),n&&n.from<=o+r.length&&n.more?l=r=r.updateHeight(t,o,i,n):r.updateHeight(t,o,i),l?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ns(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Is&&(n=t[e+1])instanceof Is&&t.splice(e-1,3,new Is(i.length+1+n.length))}class zs{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof Ls?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Ls(t-this.pos,-1)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=5)&&this.addLineDeco(n,s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new Ls(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Is(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Ls)return t;let e=new Ls(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof Ls||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),l=Math.max(l,n.top),a=Math.min(e==t.parentNode?s.innerHeight:a,n.bottom)}e="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function qs(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class Vs{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new Ms(e),this.stateDeco=t.facet(un).filter(t=>"function"!=typeof t),this.heightMap=Rs.empty().applyChanges(this.stateDeco,d.empty,this.heightOracle.setDoc(t.doc),[new bn(0,0,0,t.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ci.set(this.lineGaps.map(t=>t.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:t,to:e})=>n>=t&&n<=e)){let{from:e,to:i}=this.lineBlockAt(n);t.push(new $s(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Us:new Ys(this.heightOracle,this.heightMap,this.viewports),t.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,t=>{this.viewportLines.push(Gs(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(un).filter(t=>"function"!=typeof t);let n=t.changedRanges,s=bn.extendWithRanges(n,function(t,e,i){let n=new Hs;return It.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:O.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Cs(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=r||Ss)&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let l=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let a=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,t.flags|=this.updateForViewport(),(a||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ji)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?ki.RTL:ki.LTR;let r=this.heightOracle.mustRefreshForWrapping(s),o=e.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let a=0,h=0;if(o.width&&o.height){let{scaleX:t,scaleY:i}=Ee(e,o);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,r=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==u||(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let f=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=f&&(this.scrollAnchorHeight=-1,this.scrollTop=f),this.scrolledToBottom=Fe(t.scrollDOM);let p=(this.printing?qs:Fs)(e,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left0&&e.top0}(t.dom))return 0;let w=o.width;if(this.contentDOMWidth==w&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=o.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(e)&&(r=!0),r||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:o,textHeight:l}=t.docView.measureTextSize();r=i>0&&n.refresh(s,i,o,l,Math.max(5,w/o),e),r&&(t.docView.minWidth=0,a|=16)}m>0&&g>0?h=Math.max(m,g):m<0&&g<0&&(h=Math.min(m,g)),Cs();for(let i of this.viewports){let s=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Rs.empty().applyChanges(this.stateDeco,d.empty,this.heightOracle,[new bn(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new As(i.from,s))}Ss&&(a|=2)}let b=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,l=new $s(n.lineAt(r-1e3*i,Ds.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),Ds.ByHeight,s,0,0).to);if(e){let{head:t}=e.range;if(tl.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(t,Ds.ByPos,s,0,0);i="center"==e.y?(o.top+o.bottom)/2-r/2:"start"==e.y||"nearest"==e.y&&t=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=ki.LTR&&!i)return[];let o=[],l=(n,r,a,h)=>{if(r-nn&&tt.from>=a.from&&t.to<=a.to&&Math.abs(t.from-n)t.frome));if(!d){if(rt.from<=r&&t.to>=r)){let t=e.moveToLineBoundary(z.cursor(r),!1,!0).head;t>n&&(r=t)}let t=this.gapSize(a,n,r,h);d=new Vs(n,r,t,i||t<2e6?t:2e6)}o.push(d)},a=e=>{if(e.lengths&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s2e6)for(let i of t)i.from>=e.from&&i.frome.from&&l(e.from,o,e,s),at.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];It.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let e=0;e=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Gs(this.heightMap.lineAt(t,Ds.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Gs(this.heightMap.lineAt(this.scaler.fromDOM(t),Ds.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Gs(this.heightMap.blockAt(this.scaler.fromDOM(t),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 $s{constructor(t,e){this.from=t,this.to=e}}function js({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let n=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:s}=e[t],r=s-i;if(n<=r)return i+n;n-=r}}function Ks(t,e){let i=0;for(let{from:n,to:s}of t.ranges){if(e<=s){i+=e-n;break}i+=s-n}return i/t.total}const Us={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};class Ys{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map(({from:i,to:s})=>{let r=e.lineAt(i,Ds.ByPos,t,0,0).top,o=e.lineAt(s,Ds.ByPos,t,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let t of this.viewports)t.domTop=r+(t.top-s)*this.scale,r=t.domBottom=t.domTop+(t.bottom-t.top),s=t.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let s=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function Gs(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),n=e.toDOM(t.bottom);return new Ts(t.from,t.length,i,n-i,Array.isArray(t._content)?t._content.map(t=>Gs(t,e)):t._content)}const Xs=q.define({combine:t=>t.join(" ")}),Js=q.define({combine:t=>t.indexOf(!0)>-1}),Zs=Jt.newName(),Qs=Jt.newName(),tr=Jt.newName(),er={"&light":"."+Qs,"&dark":"."+tr};function ir(t,e,i){return new Jt(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]}):t+" "+e})}const nr=ir("."+Zs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},er),sr={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},rr=be.ie&&be.ie_version<=11;class or{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new Pe,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=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(be.ie&&be.ie_version<=11||be.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!be.android||!1===t.constructor.EDIT_CONTEXT||be.chrome&&be.chrome_version<126||(this.editContext=new hr(t),t.state.facet(sn)&&(t.contentDOM.editContext=this.editContext.editContext)),rr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(sn)?i.root.activeElement!=this.dom:!ke(this.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);s&&s.ignoreEvent(t)?e||(this.selectionChanged=!1):(be.ie&&be.ie_version<=11||be.android&&be.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Ce(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ye(t.root);if(!e)return!1;let i=be.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return ar(t,i)}let i=null;function n(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",n,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",n,!0),i?ar(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=ke(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&ze(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let s of t){let t=this.readMutation(s);t&&(t.typeOver&&(n=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&ke(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new $n(this.view,t,e,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=jn(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty("attributes"==t.type),"attributes"==t.type&&(e.flags|=4),"childList"==t.type){let i=lr(e,t.previousSibling||t.target.previousSibling,-1),n=lr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(sn)!=t.state.facet(sn)&&(t.view.contentDOM.editContext=t.state.facet(sn)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.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 lr(t,e,i){for(;e;){let n=$e.get(e);if(n&&n.parent==t)return n;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function ar(t,e){let i=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor);return Ce(o.node,o.offset,s,r)&&([i,n,s,r]=[s,r,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}}class hr{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let n=t.state.selection.main,{anchor:s,head:r}=n,o=this.toEditorPos(i.updateRangeStart),l=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:o,drifted:!1});let a=l-o>i.text.length;o==this.from&&sthis.to&&(l=s);let h=Un(t.state.sliceDoc(o,l),i.text,(a?n.from:n.to)-o,a?"end":null);if(!h){let e=z.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(e.main.eq(n)||t.dispatch({selection:e,userEvent:"select"}))}let c={from:h.from+o,to:h.toA+o,insert:d.of(i.text.slice(h.from,h.toB).split("\n"))};if((be.mac||be.android)&&c.from==r-1&&/^\. ?$/.test(i.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(c={from:o,to:l,insert:d.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!t.state.readOnly){let e=this.to-this.from+(c.to-c.from+c.insert.length);Kn(t,c,z.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),c.from=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],s=null;for(let e=this.toEditorPos(i.rangeStart),r=this.toEditorPos(i.rangeEnd);e{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,n=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(n)){let s=this.toEditorPos(t.rangeStart),r=this.toEditorPos(t.rangeEnd);if(s{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=ye(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((s,r,o,l,a)=>{if(i)return;let h=a.length-(r-s);if(n&&r>=n.to){if(n.from==s&&n.to==r&&n.insert.eq(a))return n=this.pendingContextChange=null,e+=h,void(this.to+=h);n=null,this.revertPending(t.state)}if(s+=e,(r+=e)<=this.from)this.from+=h,this.to+=h;else if(sthis.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(s),this.toContextPos(r),a.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class cr{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(t={}){var e;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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new _s(t.state||Dt.create(t)),t.scrollTo&&t.scrollTo.is(tn)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(on).map(t=>new an(t));for(let t of this.plugins)t.update(this);this.observer=new or(this),this.inputState=new Yn(this),this.inputState.ensureHandlers(this.plugins),this.docView=new xn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=1==t.length&&t[0]instanceof vt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,n=!1,s=this.state;for(let e of t){if(e.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=e.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,l=null;t.some(t=>t.annotation(ws))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=bs(s,r),l||(o=1));let a=this.observer.delayedAndroidKey,h=null;if(a?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Dt.phrases)!=this.state.facet(Dt.phrases))return this.setState(s);e=yn.create(this,s,t),e.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(c&&(c=c.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;c=new Qi(t.empty?t:z.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(tn)&&(c=t.value.clip(this.state))}this.viewState.update(e,c),this.bidiCache=fr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(wn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(Xs)!=e.state.facet(Xs)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(ji))try{t(e)}catch(t){nn(this.state,t,"update listener")}(l||h)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!jn(this,h)&&a.force&&ze(this.contentDOM,a.key,a.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new _s(t),this.plugins=t.facet(on).map(t=>new an(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new xn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(on),i=t.state.facet(on);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new an(s));else{let e=this.plugins[i];e.mustUpdate=t,n.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(r<0)if(Fe(i))s=-1,r=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(n);s=t.from,r=t.top}this.updateState=1;let o=this.viewState.measure(this);if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return nn(this.state,t),dr}}),h=yn.create(this,this.state,[]),c=!1;h.flags|=o,e?e.flags|=o:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t1||t<-1){n+=t,i.scrollTop=n/this.scaleY,r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(ji))t(e)}get themeClasses(){return Zs+" "+(this.state.facet(Js)?tr:Qs)+" "+this.state.facet(Xs)}updateAttrs(){let t=pr(this,hn,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(sn)?"true":"false",class:"cm-content",style:`${be.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),pr(this,cn,e);let i=this.observer.ignore(()=>{let i=oi(this.contentDOM,this.contentAttrs,e),n=oi(this.dom,this.editorAttrs,t);return i||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(cr.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(wn);let t=this.state.facet(cr.cspNonce);Jt.mount(this.root,this.styleModules.concat(nr).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(null!=t.key)for(let e=0;ee.plugin==t)||null),e&&e.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(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Hn(this,t,Bn(this,t,e,i))}moveByGroup(t,e){return Hn(this,t,Bn(this,t,e,e=>function(t,e,i){let n=t.state.charCategorizer(e),s=n(i);return t=>{let e=n(t);return s==Ct.Space&&(s=e),s==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=i[e?i.length-1:0];return z.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=In(t,e.head,e.assoc||-1),r=n&&s.type==hi.Text&&(t.lineWrapping||s.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),n=t.textDirectionAt(s.from),o=t.posAtCoords({x:i==(n==ki.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return z.cursor(o,i?-1:1)}return z.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return Hn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return z.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s,e.assoc||-1),c=t.documentTop;if(h)null==l&&(l=h.left-a.left),o=r<0?h.top:h.bottom;else{let e=t.viewState.lineBlockAt(s);null==l&&(l=Math.min(a.right-a.left,t.defaultCharacterWidth*(s-e.from))),o=(r<0?e.top:e.bottom)+c}let u=a.left+l,d=null!=n?n:t.viewState.heightOracle.textHeight>>1;for(let e=0;;e+=10){let i=o+(d+e)*r,n=En(t,{x:u,y:i},!1,r);if(ia.bottom||(r<0?ns)){let e=t.docView.coordsForChar(n),s=!e||i0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Xi)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>ur)return zi(t.length);let e,i=this.textDirectionAt(t.from);for(let n of this.bidiCache)if(n.from==t.from&&n.dir==i&&(n.fresh||Li(n.isolates,e=mn(this,t))))return n.order;e||(e=mn(this,t));let n=function(t,e,i){if(!t)return[new Pi(0,0,e==Ci?1:0)];if(e==Si&&!i.length&&!Ei.test(t))return zi(t.length);if(i.length)for(;t.length>Ii.length;)Ii[Ii.length]=256;let n=[],s=e==Si?0:1;return Ni(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new fr(t.from,t.to,i,e,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||be.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Be(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.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(t,e={}){return tn.of(new Qi("number"==typeof t?z.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return tn.of(new Qi(z.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ln.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ln.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Jt.newName(),n=[Xs.of(i),wn.of(ir(`.${i}`,t))];return e&&e.dark&&n.push(Js.of(!0)),n}static baseTheme(t){return Q.lowest(wn.of(ir("."+Zs,t,er)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&$e.get(i)||$e.get(t);return(null===(e=null==n?void 0:n.rootView)||void 0===e?void 0:e.view)||null}}cr.styleModule=wn,cr.inputHandler=Ki,cr.clipboardInputFilter=Yi,cr.clipboardOutputFilter=Gi,cr.scrollHandler=Zi,cr.focusChangeEffect=Ui,cr.perLineTextDirection=Xi,cr.exceptionSink=$i,cr.updateListener=ji,cr.editable=sn,cr.mouseSelectionStyle=_i,cr.dragMovesSelection=Wi,cr.clickAddsSelectionRange=Vi,cr.decorations=un,cr.outerDecorations=dn,cr.atomicRanges=fn,cr.bidiIsolatedRanges=pn,cr.scrollMargins=gn,cr.darkTheme=Js,cr.cspNonce=q.define({combine:t=>t.length?t[0]:""}),cr.contentAttributes=cn,cr.editorAttributes=hn,cr.lineWrapping=cr.contentAttributes.of({class:"cm-lineWrapping"}),cr.announce=gt.define();const ur=4096,dr={};class fr{constructor(t,e,i,n,s,r){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:ki.LTR;for(let s=Math.max(0,t.length-10);s=0;s--){let e=n[s],r="function"==typeof e?e(t):e;r&&ni(r,i)}return i}const mr=be.mac?"mac":be.windows?"win":be.linux?"linux":"key";function gr(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const vr=Q.default(cr.domEventHandlers({keydown:(t,e)=>Cr(yr(e.state),t,e,"editor")})),wr=q.define({enables:vr}),br=new WeakMap;function yr(t){let e=t.facet(wr),i=br.get(e);return i||br.set(e,i=function(t,e=mr){let i=Object.create(null),n=Object.create(null),s=(t,e)=>{let i=n[t];if(null==i)n[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},r=(t,n,r,o,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),u=n.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let n,s,r,o,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t{let n=xr={view:e,prefix:i,scope:t};return setTimeout(()=>{xr==n&&(xr=null)},kr),!0}]})}let d=u.join(" ");s(d,!1);let f=c[d]||(c[d]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});r&&f.run.push(r),o&&(f.preventDefault=!0),l&&(f.stopPropagation=!0)};for(let n of t){let t=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:s}=n;for(let e in t)t[e].run.push(t=>s(t,Sr))}let s=n[e]||n.key;if(s)for(let e of t)r(e,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(e,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}let xr=null;const kr=4e3;let Sr=null;function Cr(t,e,i,n){Sr=e;let s=function(t){var e=!(ie&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||ne&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?ee:te)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),r=M(S(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;xr&&xr.view==i&&xr.scope==n&&(o=xr.prefix+" ",Qn.indexOf(e.keyCode)<0&&(a=!0,xr=null));let c,u,d=new Set,f=t=>{if(t){for(let e of t.run)if(!d.has(e)&&(d.add(e),e(i)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(f(p[o+gr(s,e,!r)])?l=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||be.windows&&e.ctrlKey&&e.altKey||be.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(c=te[e.keyCode])||c==s?r&&e.shiftKey&&f(p[o+gr(s,e,!0)])&&(l=!0):(f(p[o+gr(c,e,!0)])||e.shiftKey&&(u=ee[e.keyCode])!=s&&u!=c&&f(p[o+gr(u,e,!1)]))&&(l=!0),!l&&f(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),Sr=null,l}class Mr{constructor(t,e,i,n,s){this.className=t,this.left=e,this.top=i,this.width=n,this.height=s}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=Ar(t);return[new Mr(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let n=Math.max(i.from,t.viewport.from),s=Math.min(i.to,t.viewport.to),r=t.textDirection==ki.LTR,o=t.contentDOM,l=o.getBoundingClientRect(),a=Ar(t),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),u=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),d=l.right-(c?parseInt(c.paddingRight):0),f=In(t,n,1),p=In(t,s,-1),m=f.type==hi.Text?f:null,g=p.type==hi.Text?p:null;m&&(t.lineWrapping||f.widgetLineBreaks)&&(m=Tr(t,n,1,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=Tr(t,s,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return w(b(i.from,i.to,m));{let e=m?b(i.from,null,m):y(f,!1),n=g?b(null,i.to,g):y(p,!0),s=[];return(m||f).to<(g||p).from-(m&&g?1:0)||f.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2h&&n.from=r)break;l>s&&a(Math.max(t,s),null==e&&t<=h,Math.min(l,r),null==i&&l>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:s,bottom:o,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function Ar(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==ki.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Tr(t,e,i,n){let s=t.coordsAtPos(e,2*i);if(!s)return n;let r=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=t.posAtCoords({x:r.left+1,y:o}),a=t.posAtCoords({x:r.right-1,y:o});return null==l||null==a?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}class Dr{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Or)!=t.state.facet(Or)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Or);for(;e{return i=t,n=this.drawn[e],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t,be.safari&&be.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Or=q.define();function Rr(t){return[ln.define(e=>new Dr(e,t)),Or.of(t)]}const Er=q.define({combine:t=>Ot(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function Pr(t){return t.startState.facet(Er)!=t.state.facet(Er)}const Lr=Rr({above:!0,markers(t){let{state:e}=t,i=e.facet(Er),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||i.drawRangeCursor){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:z.cursor(s.head,s.head>s.anchor?-1:1);for(let s of Mr.forRange(t,e,i))n.push(s)}}return n},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=Pr(t);return i&&Ir(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){Ir(e.state,t)},class:"cm-cursorLayer"});function Ir(t,e){e.style.animationDuration=t.facet(Er).cursorBlinkRate+"ms"}const Br=Rr({above:!1,markers:t=>t.state.selection.ranges.map(e=>e.empty?[]:Mr.forRange(t,"cm-selectionBackground",e)).reduce((t,e)=>t.concat(e)),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||Pr(t),class:"cm-selectionLayer"}),Nr=Q.highest(cr.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),zr=gt.define({map:(t,e)=>null==t?null:e.mapPos(t)}),Hr=U.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(zr)?e.value:t,t))}),Fr=ln.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(Hr);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(Hr)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(Hr),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let n=t.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-n.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(Hr)!=t&&this.view.dispatch({effects:zr.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function qr(t,e,i,n,s){e.lastIndex=0;for(let r,o=t.iterRange(i,n),l=i;!o.next().done;l+=o.value.length)if(!o.lineBreak)for(;r=e.exec(o.value);)s(l+r.index,r)}class Vr{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(t,e,i,s)=>n(s,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,n,s)=>{let r=i(t,e,n);r&&s(n,n+t[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,n,s)=>s(n,n+t[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(t){let e=new Bt,i=e.add.bind(e);for(let{from:e,to:n}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let n=[];for(let{from:s,to:r}of i)s=Math.max(t.state.doc.lineAt(s).from,s-e),r=Math.min(t.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(t,this.maxLength))qr(t.state.doc,this.regexp,e,n,(e,n)=>this.addMatch(n,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((e,s,r,o)=>{o>=t.view.viewport.from&&r<=t.view.viewport.to&&(i=Math.min(r,i),n=Math.max(o,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let s of t.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>=r){let i=t.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){l=r;break}for(;oc.push(i.range(t,e));if(i==n)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,t,e,u));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>ta,add:c})}}return e}}const Wr=ci.line({class:"cm-activeLine"}),_r=ln.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let n of t.state.selection.ranges){let s=t.lineBlockAt(n.head);s.from>e&&(i.push(Wr.range(s.from)),e=s.from)}return ci.set(i)}},{decorations:t=>t.decorations}),$r=2e3;function jr(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t.state.doc.lineAt(i),s=i-n.from,r=s>$r?-1:s==n.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Kt(n.text,t.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function Kr(t,e){let i=jr(t,e),n=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(t.changes)}},get(e,s,r){let o=jr(t,e);if(!o)return n;let l=function(t,e,i){let n=Math.min(e.line,i.line),s=Math.max(e.line,i.line),r=[];if(e.off>$r||i.off>$r||e.col<0||i.col<0){let o=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=n;e<=s;e++){let i=t.doc.line(e);i.length<=l&&r.push(z.range(i.from+o,i.to+l))}}else{let o=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=n;e<=s;e++){let i=t.doc.line(e),n=Ut(i.text,o,t.tabSize,!0);if(n<0)r.push(z.cursor(i.to));else{let e=Ut(i.text,l,t.tabSize);r.push(z.range(i.from+n,i.from+e))}}}return r}(t.state,i,o);return l.length?r?z.create(l.concat(n.ranges)):z.create(l):n}}:null}const Ur={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Yr={style:"cursor: crosshair"};const Gr="-10000px";class Xr{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let s=null;this.tooltipViews=this.tooltips.map(t=>s=i(t,s))}update(t,e){var i;let n=t.state.facet(this.facet),s=n.filter(t=>t);if(n===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let r=[],o=e?[]:null;for(let i=0;ie[i]=t),e.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function Jr(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Zr=q.define({combine:t=>{var e,i,n;return{position:be.ios?"absolute":(null===(e=t.find(t=>t.position))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find(t=>t.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=t.find(t=>t.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||Jr}}}),Qr=new WeakMap,to=ln.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(Zr);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Xr(t,so,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,n=t.state.facet(Zr);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),n=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Gr,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(be.gecko)i=t.offsetParent!=this.container.ownerDocument.body;else if(t.style.top==Gr&&"0px"==t.style.left){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=vn(this.view);return{visible:{left:n.left+s.left,top:n.top+s.top,right:n.right-s.right,bottom:n.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(Zr).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:n,scaleX:s,scaleY:r}=t,o=[];for(let l=0;l=Math.min(i.bottom,n.bottom)||u.rightMath.min(i.right,n.right)+.1)){c.style.top=Gr;continue}let f=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=f?7:0,m=d.right-d.left,g=null!==(e=Qr.get(h))&&void 0!==e?e:d.bottom-d.top,v=h.offset||no,w=this.view.textDirection==ki.LTR,b=d.width>n.right-n.left?w?n.left:n.right-d.width:w?Math.max(n.left,Math.min(u.left-(f?14:0)+v.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(f?14:0)-v.x),n.right-m),y=this.above[l];!a.strictSide&&(y?u.top-g-p-v.yn.bottom)&&y==n.bottom-u.bottom>u.top-n.top&&(y=this.above[l]=!y);let x=(y?u.top-n.top:n.bottom-u.bottom)-p;if(xb&&t.topk&&(k=y?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(k-t.parent.top)/r+"px",eo(c,(b-t.parent.left)/s)):(c.style.top=k/r+"px",eo(c,b/s)),f){let t=u.left+(w?v.x:-v.x)-(b+14-7);f.style.left=t/s+"px"}!0!==h.overlap&&o.push({left:b,top:k,right:S,bottom:k+g}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Gr}},{eventObservers:{scroll(){this.maybeMeasure()}}});function eo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const io=cr.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"}}}),no={x:0,y:0},so=q.define({enables:[to,io]}),ro=q.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class oo{static create(t){return new oo(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Xr(t,ro,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(void 0!==n)if(void 0===e)e=n;else if(e!==n)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const lo=so.compute([ro],t=>{let e=t.facet(ro);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:oo.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class ao{constructor(t,e,i,n,s){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;ti.bottom||e.xi.right+t.defaultCharacterWidth)return;let r=t.bidiSpans(t.state.doc.lineAt(n)).find(t=>t.from<=n&&t.to>=n),o=r&&r.dir==ki.RTL?-1:1;s=e.x{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},e=>nn(t.state,e,"hover tooltip"))}else!r||Array.isArray(r)&&!r.length||t.dispatch({effects:this.setHover.of(Array.isArray(r)?r:[r])})}get tooltip(){let t=this.view.plugin(to),e=t?t.manager.tooltips.findIndex(t=>t.create==oo.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&s&&!function(t,e){let i,{left:n,right:s,top:r,bottom:o}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();r=Math.min(t.top,r),o=Math.max(t.bottom,o)}return e.clientX>=n-ho&&e.clientX<=s+ho&&e.clientY>=r-ho&&e.clientY<=o+ho}(s.dom,t)||this.pending){let{pos:s}=n[0]||this.pending,r=null!==(i=null===(e=n[0])||void 0===e?void 0:e.end)&&void 0!==i?i:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,n,s){let r=t.scrollDOM.getBoundingClientRect(),o=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>n||r.rights||Math.min(r.bottom,o)=e&&l<=i}(this.view,s,r,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const ho=4;function co(t,e={}){let i=gt.define(),n=U.define({create:()=>[],update(t,n){if(t.length&&(e.hideOnChange&&(n.docChanged||n.selection)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(n,t))),n.docChanged)){let e=[];for(let i of t){let t=n.changes.mapPos(i.pos,-1,T.TrackDel);if(null!=t){let s=Object.assign(Object.create(null),i);s.pos=t,null!=s.end&&(s.end=n.changes.mapPos(s.end)),e.push(s)}}t=e}for(let e of n.effects)e.is(i)&&(t=e.value),e.is(fo)&&(t=[]);return t},provide:t=>ro.from(t)});return{active:n,extension:[n,ln.define(s=>new ao(s,t,n,i,e.hoverTime||300)),lo]}}function uo(t,e){let i=t.plugin(to);if(!i)return null;let n=i.manager.tooltips.indexOf(e);return n<0?null:i.manager.tooltipViews[n]}const fo=gt.define(),po=q.define({combine(t){let e,i;for(let n of t)e=e||n.topContainer,i=i||n.bottomContainer;return{topContainer:e,bottomContainer:i}}});function mo(t,e){let i=t.plugin(go),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const go=ln.fromClass(class{constructor(t){this.input=t.state.facet(bo),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(po);this.top=new vo(t,!0,e.topContainer),this.bottom=new vo(t,!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(t){let e=t.state.facet(po);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new vo(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new vo(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(bo);if(i!=this.input){let e=i.filter(t=>t),n=[],s=[],r=[],o=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),o.push(e)):(e=this.panels[l],e.update&&e.update(t)),n.push(e),(e.top?s:r).push(e)}this.specs=e,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let t of o)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>cr.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class vo{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));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 t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=wo(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=wo(t)}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 t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function wo(t){let e=t.nextSibling;return t.remove(),e}const bo=q.define({enables:go});function yo(t,e){let i,n=new Promise(t=>i=t),s=t=>function(t,e,i){let n=e.content?e.content(t,()=>o(null)):null;if(!n){if(n=oe("form"),e.input){let t=oe("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),n.appendChild(oe("label",(e.label||"")+": ",t))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(oe("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let t=0;t{27==t.keyCode?(t.preventDefault(),o(null)):13==t.keyCode&&(t.preventDefault(),o(e))}),e.addEventListener("submit",t=>{t.preventDefault(),o(e)})}let r=oe("div",n,oe("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class);function o(e){r.contains(r.ownerDocument.activeElement)&&t.focus(),i(e)}return r.classList.add("cm-dialog"),{dom:r,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?n.querySelector(e.focus):n.querySelector("input")||n.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(xo,!1)?t.dispatch({effects:ko.of(s)}):t.dispatch({effects:gt.appendConfig.of(xo.init(()=>[s]))});let r=So.of(s);return{close:r,result:n.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(xo).indexOf(s)>-1&&t.dispatch({effects:r})}),e))}}const xo=U.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(ko)?t=[i.value].concat(t):i.is(So)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>bo.computeN([t],e=>e.field(t))}),ko=gt.define(),So=gt.define();class Co extends Rt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Co.prototype.elementClass="",Co.prototype.toDOM=void 0,Co.prototype.mapMode=T.TrackBefore,Co.prototype.startSide=Co.prototype.endSide=-1,Co.prototype.point=!0;const Mo=q.define(),Ao=q.define(),To={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>It.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Do=q.define();function Oo(t){return[Eo(),Do.of({...To,...t})]}const Ro=q.define({combine:t=>t.some(t=>t)});function Eo(t){return[Po]}const Po=ln.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.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=t.state.facet(Do).map(e=>new No(t,e)),this.fixed=!t.state.facet(Ro);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.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(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,n=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Ro)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=It.iter(this.view.state.facet(Mo),this.view.viewport.from),n=[],s=this.gutters.map(t=>new Bo(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(t.type)){let e=!0;for(let r of t.type)if(r.type==hi.Text&&e){Io(i,n,r.from);for(let t of s)t.line(this.view,r,n);e=!1}else if(r.widget)for(let t of s)t.widget(this.view,r)}else if(t.type==hi.Text){Io(i,n,t.from);for(let e of s)e.line(this.view,t,n)}else if(t.widget)for(let e of s)e.widget(this.view,t);for(let t of s)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Do),i=t.state.facet(Do),n=t.docChanged||t.heightChanged||t.viewportChanged||!It.eq(t.startState.facet(Mo),t.state.facet(Mo),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=e.indexOf(n);i<0?s.push(new No(this.view,n)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>cr.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ki.LTR?{left:n,right:s}:{right:n,left:s}})});function Lo(t){return Array.isArray(t)?t:[t]}function Io(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class Bo{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=It.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==n.elements.length){let e=new zo(t,r,s,i);n.elements.push(e),n.dom.appendChild(e.dom)}else n.elements[this.i].update(t,r,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];Io(this.cursor,n,e.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let i of t.state.facet(Ao)){let s=i(t,e.widget,e);s&&(n||(n=[])).push(s)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class No{constructor(t,e){this.view=t,this.config=e,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 e.domEventHandlers)this.dom.addEventListener(i,n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let t=r.getBoundingClientRect();s=(t.top+t.bottom)/2}else s=n.clientY;let o=t.lineBlockAtHeight(s-t.documentTop);e.domEventHandlers[i](t,o,n)&&n.preventDefault()});this.markers=Lo(e.markers(t)),e.initialSpacer&&(this.spacer=new zo(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Lo(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!It.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class zo{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iOt(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let n=i[t],s=e[t];i[t]=n?(t,e,i)=>n(t,e,i)||s(t,e,i):s}return i}})});class Vo extends Co{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Wo(t,e){return t.state.facet(qo).formatNumber(e,t.state)}const _o=Do.compute([qo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(Ho),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new Vo(Wo(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let n of t.state.facet(Fo)){let s=n(t,e,i);if(s)return s}return null},lineMarkerChange:t=>t.startState.facet(qo)!=t.state.facet(qo),initialSpacer:t=>new Vo(Wo(t,$o(t.state.doc.lines))),updateSpacer(t,e){let i=Wo(e.view,$o(e.view.state.doc.lines));return i==t.number?t:new Vo(i)},domEventHandlers:t.facet(qo).domEventHandlers,side:"before"}));function $o(t){let e=9;for(;e{let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.head).from;s>i&&(i=s,e.push(jo.range(s)))}return It.of(e)});function Uo(t){return ln.define(e=>({decorations:t.createDeco(e),update(e){this.decorations=t.updateDeco(e,this.decorations)}}),{decorations:t=>t.decorations})}const Yo=ci.mark({class:"cm-highlightTab"}),Go=ci.mark({class:"cm-highlightSpace"}),Xo=Uo(new Vr({regexp:/\t| /g,decoration:t=>"\t"==t[0]?Yo:Go,boundary:/\S/}));const Jo="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class Zo{constructor(t,e,i=0,n=t.length,s,r){this.test=r,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=s?t=>s(Jo(t)):Jo,this.query=this.normalize(e)}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 S(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=C(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=M(t);let n=this.normalize(e);if(n.length)for(let t=0,s=i;;t++){let r=n.charCodeAt(t),o=this.match(r,s,this.bufferPos+this.bufferStart);if(t==n.length-1){if(o)return this.value=o,this;break}s==i&&tthis.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 t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,n=i+e[0].length;if(this.matchPos=rl(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||n.to<=e){let n=new nl(e,t.sliceString(e,i));return il.set(t,n),n}if(n.from==e&&n.to==i)return n;let{text:s,from:r}=n;return r>e&&(s=t.sliceString(e,r)+s,r=e),n.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,match:e},this.matchPos=rl(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=nl.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function rl(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}function ol(t){let e=oe("input",{class:"cm-textfield",name:"line",value:String(t.state.doc.lineAt(t.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:n}=t,s=n.doc.lineAt(n.selection.main.head),[,r,o,l,a]=i,h=l?+l.slice(1):0,c=o?+o:s.number;if(o&&a){let t=c/100;r&&(t=t*("-"==r?-1:1)+s.number/n.doc.lines),c=Math.round(n.doc.lines*t)}else o&&r&&(c=c*("-"==r?-1:1)+s.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,c))),d=z.cursor(u.from+Math.max(0,Math.min(h,u.length)));t.dispatch({effects:[ll.of(!1),cr.scrollIntoView(d.from,{y:"center"})],selection:d}),t.focus()}return{dom:oe("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:ll.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},oe("label",t.state.phrase("Go to line"),": ",e)," ",oe("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),oe("button",{name:"close",onclick:()=>{t.dispatch({effects:ll.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]))}}"undefined"!=typeof Symbol&&(el.prototype[Symbol.iterator]=sl.prototype[Symbol.iterator]=function(){return this});const ll=gt.define(),al=U.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(ll)&&(t=i.value);return t},provide:t=>bo.from(t,t=>t?ol:null)}),hl=cr.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),cl={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ul=q.define({combine:t=>Ot(t,cl,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});const dl=ci.mark({class:"cm-selectionMatch"}),fl=ci.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function pl(t,e,i,n){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ct.Word||n!=e.doc.length&&t(e.sliceDoc(n,n+1))==Ct.Word)}const ml=ln.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(ul),{state:i}=t,n=i.selection;if(n.ranges.length>1)return ci.none;let s,r=n.main,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return ci.none;let t=i.wordAt(r.head);if(!t)return ci.none;o=i.charCategorizer(r.head),s=i.sliceDoc(t.from,t.to)}else{let t=r.to-r.from;if(t200)return ci.none;if(e.wholeWords){if(s=i.sliceDoc(r.from,r.to),o=i.charCategorizer(r.head),!pl(o,i,r.from,r.to)||!function(t,e,i,n){return t(e.sliceDoc(i,i+1))==Ct.Word&&t(e.sliceDoc(n-1,n))==Ct.Word}(o,i,r.from,r.to))return ci.none}else if(s=i.sliceDoc(r.from,r.to),!s)return ci.none}let l=[];for(let n of t.visibleRanges){let t=new Zo(i.doc,s,n.from,n.to);for(;!t.next().done;){let{from:n,to:s}=t.value;if((!o||pl(o,i,n,s))&&(r.empty&&n<=r.from&&s>=r.to?l.push(fl.range(n,s)):(n>=r.to||s<=r.from)&&l.push(dl.range(n,s)),l.length>e.maxMatches))return ci.none}}return ci.set(l)}},{decorations:t=>t.decorations}),gl=cr.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const vl=q.define({combine:t=>Ot(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Kl(t),scrollToMatch:t=>cr.scrollIntoView(t)})});class wl{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,tl),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Ml(this):new xl(this)}getCursor(t,e=0,i){let n=t.doc?t:Dt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?kl(this,n,e,i):yl(this,n,e,i)}}class bl{constructor(t){this.spec=t}}function yl(t,e,i,n){return new Zo(e.doc,t.unquoted,i,n,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?function(t,e){return(i,n,s,r)=>((r>i||r+s.length=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=yl(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}function kl(t,e,i,n){return new el(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(s=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(s(Sl(i.input,i.index))!=Ct.Word||s(Cl(i.input,i.index))!=Ct.Word)&&(s(Cl(i.input,i.index+i[0].length))!=Ct.Word||s(Sl(i.input,i.index+i[0].length))!=Ct.Word)):void 0},i,n);var s}function Sl(t,e){return t.slice(k(t,e,!1),e)}function Cl(t,e){return t.slice(e,k(t,e))}class Ml extends bl{nextMatch(t,e,i){let n=kl(this.spec,t,i,t.doc.length).next();return n.done&&(n=kl(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let s=Math.max(e,i-1e4*n),r=kl(this.spec,t,s,i),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==e||o.from>s+10))return o;if(s==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(e,i)=>{if("&"==i)return t.match[0];if("$"==i)return"$";for(let e=i.length;e>0;e--){let n=+i.slice(0,e);if(n>0&&n=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=kl(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}const Al=gt.define(),Tl=gt.define(),Dl=U.define({create:t=>new Ol(ql(t).create(),null),update(t,e){for(let i of e.effects)i.is(Al)?t=new Ol(i.value.create(),t.panel):i.is(Tl)&&(t=new Ol(t.query,i.value?Fl:null));return t},provide:t=>bo.from(t,t=>t.panel)});class Ol{constructor(t,e){this.query=t,this.panel=e}}const Rl=ci.mark({class:"cm-searchMatch"}),El=ci.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Pl=ln.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Dl))}update(t){let e=t.state.field(Dl);(e!=t.startState.field(Dl)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ci.none;let{view:i}=this,n=new Bt;for(let e=0,s=i.visibleRanges,r=s.length;es[e+1].from-500;)l=s[++e].to;t.highlight(i.state,o,l,(t,e)=>{let s=i.state.selection.ranges.some(i=>i.from==t&&i.to==e);n.add(t,e,s?El:Rl)})}return n.finish()}},{decorations:t=>t.decorations});function Ll(t){return e=>{let i=e.state.field(Dl,!1);return i&&i.query.spec.valid?t(e,i):_l(e)}}const Il=Ll((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=z.single(n.from,n.to),r=t.state.facet(vl);return t.dispatch({selection:s,effects:[Xl(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),Wl(t),!0}),Bl=Ll((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=z.single(s.from,s.to),o=t.state.facet(vl);return t.dispatch({selection:r,effects:[Xl(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),Wl(t),!0}),Nl=Ll((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:z.create(i.map(t=>z.range(t.from,t.to))),userEvent:"select.search.matches"}),!0)}),zl=Ll((t,{query:e})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let r=e.nextMatch(i,n,n);if(!r)return!1;let o,l,a=r,h=[],c=[];a.from==n&&a.to==s&&(l=i.toText(e.getReplacement(a)),h.push({from:a.from,to:a.to,insert:l}),a=e.nextMatch(i,a.from,a.to),c.push(cr.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+".")));let u=t.state.changes(h);return a&&(o=z.single(a.from,a.to).map(u),c.push(Xl(t,a)),c.push(i.facet(vl).scrollToMatch(o.main,t))),t.dispatch({changes:u,selection:o,effects:c,userEvent:"input.replace"}),!0}),Hl=Ll((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state,1e9).map(t=>{let{from:i,to:n}=t;return{from:i,to:n,insert:e.getReplacement(t)}});if(!i.length)return!1;let n=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:cr.announce.of(n),userEvent:"input.replace.all"}),!0});function Fl(t){return t.state.facet(vl).createPanel(t)}function ql(t,e){var i,n,s,r,o;let l=t.selection.main,a=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=t.facet(vl);return new wl({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==e?void 0:e.caseSensitive)&&void 0!==n?n:h.caseSensitive,literal:null!==(s=null==e?void 0:e.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==e?void 0:e.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==e?void 0:e.wholeWord)&&void 0!==o?o:h.wholeWord})}function Vl(t){let e=mo(t,Fl);return e&&e.dom.querySelector("[main-field]")}function Wl(t){let e=Vl(t);e&&e==t.root.activeElement&&e.select()}const _l=t=>{let e=t.state.field(Dl,!1);if(e&&e.panel){let i=Vl(t);if(i&&i!=t.root.activeElement){let n=ql(t.state,e.query.spec);n.valid&&t.dispatch({effects:Al.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Tl.of(!0),e?Al.of(ql(t.state,e.query.spec)):gt.appendConfig.of(Zl)]});return!0},$l=t=>{let e=t.state.field(Dl,!1);if(!e||!e.panel)return!1;let i=mo(t,Fl);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Tl.of(!1)}),!0},jl=[{key:"Mod-f",run:_l,scope:"editor search-panel"},{key:"F3",run:Il,shift:Bl,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Il,shift:Bl,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:$l,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:n,to:s}=i.main,r=[],o=0;for(let e=new Zo(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(z.range(e.value.from,e.value.to))}return e(t.update({selection:z.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let e=mo(t,ol);if(!e){let i=[ll.of(!0)];null==t.state.field(al,!1)&&i.push(gt.appendConfig.of([al,hl])),t.dispatch({effects:i}),e=mo(t,ol)}return e&&e.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some(t=>t.from===t.to))return(({state:t,dispatch:e})=>{let{selection:i}=t,n=z.create(i.ranges.map(e=>t.wordAt(e.head)||z.cursor(e.head)),i.mainIndex);return!n.eq(i)&&(e(t.update({selection:n})),!0)})({state:t,dispatch:e});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some(e=>t.sliceDoc(e.from,e.to)!=n))return!1;let s=function(t,e){let{main:i,ranges:n}=t.selection,s=t.wordAt(i.head),r=s&&s.from==i.from&&s.to==i.to;for(let i=!1,s=new Zo(t.doc,e,n[n.length-1].to);;){if(s.next(),!s.done){if(i&&n.some(t=>t.from==s.value.from))continue;if(r){let e=t.wordAt(s.value.from);if(!e||e.from!=s.value.from||e.to!=s.value.to)continue}return s.value}if(i)return null;s=new Zo(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),i=!0}}(t,n);return!!s&&(e(t.update({selection:t.selection.addRange(z.range(s.from,s.to),!1),effects:cr.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class Kl{constructor(t){this.view=t;let e=this.query=t.state.field(Dl).query.spec;function i(t,e,i){return oe("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=oe("input",{value:e.search,placeholder:Ul(t,"Find"),"aria-label":Ul(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=oe("input",{value:e.replace,placeholder:Ul(t,"Replace"),"aria-label":Ul(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=oe("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=oe("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=oe("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=oe("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",()=>Il(t),[Ul(t,"next")]),i("prev",()=>Bl(t),[Ul(t,"previous")]),i("select",()=>Nl(t),[Ul(t,"all")]),oe("label",null,[this.caseField,Ul(t,"match case")]),oe("label",null,[this.reField,Ul(t,"regexp")]),oe("label",null,[this.wordField,Ul(t,"by word")]),...t.state.readOnly?[]:[oe("br"),this.replaceField,i("replace",()=>zl(t),[Ul(t,"replace")]),i("replaceAll",()=>Hl(t),[Ul(t,"replace all")])],oe("button",{name:"close",onclick:()=>$l(t),"aria-label":Ul(t,"close"),type:"button"},["×"])])}commit(){let t=new wl({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Al.of(t)}))}keydown(t){!function(t,e,i){return Cr(yr(t.state),e,t,i)}(this.view,t,"search-panel")?13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Bl:Il)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),zl(this.view)):t.preventDefault()}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Al)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(vl).top}}function Ul(t,e){return t.state.phrase(e)}const Yl=30,Gl=/[\s\.,:;?!]/;function Xl(t,{from:e,to:i}){let n=t.state.doc.lineAt(e),s=t.state.doc.lineAt(i).to,r=Math.max(n.from,e-Yl),o=Math.min(s,i+Yl),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-Yl;t--)if(!Gl.test(l[t-1])&&Gl.test(l[t])){l=l.slice(0,t);break}return cr.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const Jl=cr.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"}}),Zl=[Dl,Q.low(Pl),Jl];class Ql{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class ta{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(ga).markerFilter;n&&(t=n(t,i));let s=t.slice().sort((t,e)=>t.from-e.from||t.to-e.to),r=new Bt,o=[],l=0,a=i.doc.iter(),h=0,c=i.doc.length;for(let t=0;;){let e,i,n=t==s.length?null:s[t];if(!n&&!o.length)break;if(o.length)e=l,i=o.reduce((t,e)=>Math.min(t,e.to),n&&n.from>e?n.from:1e8);else{if(e=n.from,e>c)break;i=n.to,o.push(n),t++}for(;tn.from||n.to==e)){i=Math.min(n.from,i);break}o.push(n),t++,i=Math.min(n.to,i)}i=Math.min(i,c);let u=!1;if(o.some(t=>t.from==e&&(t.to==i||i==c))&&(u=e==i,!u&&i-e<10)){let t=e-(h+a.value.length);t>0&&(a.next(t),h=e);for(let t=e;;){if(t>=i){u=!0;break}if(!a.lineBreak&&h+a.value.length>t)break;t=h+a.value.length,h+=a.value.length,a.next()}}let d=Ta(o);if(u)r.add(e,e,ci.widget({widget:new ya(d),diagnostics:o.slice()}));else{let t=o.reduce((t,e)=>e.markClass?t+" "+e.markClass:t,"");r.add(e,i,ci.mark({class:"cm-lintRange cm-lintRange-"+d+t,diagnostics:o.slice(),inclusiveEnd:o.some(t=>t.to>i)}))}if(l=i,l==c)break;for(let t=0;t{if(!(e&&s.diagnostics.indexOf(e)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new Ql(n.from,i,n.diagnostic)}else n=new Ql(t,i,e||s.diagnostics[0])}),n}function ia(t,e){let i=e.pos,n=e.end||i,s=t.state.facet(ga).hideOn(t,i,n);if(null!=s)return s;let r=t.startState.doc.lineAt(e.pos);return!(!t.effects.some(t=>t.is(ra))&&!t.changes.touchesRange(r.from,Math.max(r.to,n)))}function na(t,e){return t.field(aa,!1)?e:e.concat(gt.appendConfig.of(Ba))}function sa(t,e){return{effects:na(t,[ra.of(e)])}}const ra=gt.define(),oa=gt.define(),la=gt.define(),aa=U.define({create:()=>new ta(ci.none,null,null),update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),n=null,s=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);n=ea(i,t.selected.diagnostic,s)||ea(i,null,s)}!i.size&&s&&e.state.facet(ga).autoPanel&&(s=null),t=new ta(i,s,n)}for(let i of e.effects)if(i.is(ra)){let n=e.state.facet(ga).autoPanel?i.value.length?ka.open:null:t.panel;t=ta.init(i.value,n,e.state)}else i.is(oa)?t=new ta(t.diagnostics,i.value?ka.open:null,t.selected):i.is(la)&&(t=new ta(t.diagnostics,t.panel,i.value));return t},provide:t=>[bo.from(t,t=>t.panel),cr.decorations.from(t,t=>t.diagnostics)]});const ha=ci.mark({class:"cm-lintRange cm-lintRange-active"});function ca(t,e,i){let n,{diagnostics:s}=t.state.field(aa),r=-1,o=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(t,s,{spec:l})=>{if(e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:ua(t,n)})}:null}function ua(t,e){return oe("ul",{class:"cm-tooltip-lint"},e.map(e=>ba(t,e,!1)))}const da=t=>{let e=t.state.field(aa,!1);e&&e.panel||t.dispatch({effects:na(t.state,[oa.of(!0)])});let i=mo(t,ka.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0},fa=t=>{let e=t.state.field(aa,!1);return!(!e||!e.panel)&&(t.dispatch({effects:oa.of(!1)}),!0)},pa=[{key:"Mod-Shift-m",run:da,preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(aa,!1);if(!e)return!1;let i=t.state.selection.main,n=e.diagnostics.iter(i.to+1);return!(!n.value&&(n=e.diagnostics.iter(0),!n.value||n.from==i.from&&n.to==i.to))&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)}}],ma=ln.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(ga);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let t=Date.now();if(t{n.push(i),clearTimeout(s),n.length==t.length?e(n):s=setTimeout(()=>e(n),200)},i)}(e.map(t=>Promise.resolve(t(this.view))),e=>{this.view.state.doc==t.doc&&this.view.dispatch(sa(this.view.state,e.reduce((t,e)=>t.concat(e))))},t=>{nn(this.view.state,t)})}}update(t){let e=t.state.facet(ga);(t.docChanged||e!=t.startState.facet(ga)||e.needsRefresh&&e.needsRefresh(t))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});const ga=q.define({combine:t=>({sources:t.map(t=>t.source).filter(t=>null!=t),...Ot(t.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:va,tooltipFilter:va,needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e,hideOn:(t,e)=>t?e?(i,n,s)=>t(i,n,s)||e(i,n,s):t:e,autoPanel:(t,e)=>t||e})})});function va(t,e){return t?e?(i,n)=>e(t(i,n),n):t:e}function wa(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==n.toLowerCase())){e.push(n);continue t}}e.push("")}return e}function ba(t,e,i){var n;let s=i?wa(e.actions):[];return oe("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},oe("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(n=e.actions)||void 0===n?void 0:n.map((i,n)=>{let r=!1,o=n=>{if(n.preventDefault(),r)return;r=!0;let s=ea(t.state.field(aa).diagnostics,e);s&&i.apply(t,s.from,s.to)},{name:l}=i,a=s[n]?l.indexOf(s[n]):-1,h=a<0?l:[l.slice(0,a),oe("u",l.slice(a,a+1)),l.slice(a+1)];return oe("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:o,onmousedown:o,"aria-label":` Action: ${l}${a<0?"":` (access key "${s[n]})"`}.`},h)}),e.source&&oe("div",{class:"cm-diagnosticSource"},e.source))}class ya extends ai{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return oe("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class xa{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=ba(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ka{constructor(t){this.view=t,this.items=[];this.list=oe("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)fa(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=wa(i.actions);for(let s=0;s{for(let e=0;efa(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(aa).selected;if(!t)return-1;for(let e=0;e{for(let t of l.diagnostics){if(r.has(t))continue;r.add(t);let o,l=-1;for(let e=i;ei&&(this.items.splice(i,l-i),n=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),s=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}});i({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.tope.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=ea(this.view.state.field(aa).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:la.of(e)})}static open(t){return new ka(t)}}function Sa(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}function Ca(t){return Sa(``,'width="6" height="3"')}const Ma=cr.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Ca("#d11")},".cm-lintRange-warning":{backgroundImage:Ca("orange")},".cm-lintRange-info":{backgroundImage:Ca("#999")},".cm-lintRange-hint":{backgroundImage:Ca("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function Aa(t){return"error"==t?4:"warning"==t?3:"info"==t?2:1}function Ta(t){let e="hint",i=1;for(let n of t){let t=Aa(n.severity);t>i&&(i=t,e=n.severity)}return e}class Da extends Co{constructor(t){super(),this.diagnostics=t,this.severity=Ta(t)}toDOM(t){let e=document.createElement("div");e.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,n=t.state.facet(Na).tooltipFilter;return n&&(i=n(i,t.state)),i.length&&(e.onmouseover=()=>function(t,e,i){function n(){let n=t.elementAtHeight(e.getBoundingClientRect().top+5-t.documentTop);t.coordsAtPos(n.from)&&t.dispatch({effects:Pa.of({pos:n.from,above:!1,clip:!1,create:()=>({dom:ua(t,i),getCoords:()=>e.getBoundingClientRect()})})}),e.onmouseout=e.onmousemove=null,function(t,e){let i=n=>{let s=e.getBoundingClientRect();if(!(n.clientX>s.left-10&&n.clientXs.top-10&&n.clientY{clearTimeout(r),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(r),r=setTimeout(n,s)}}(t,e,i)),e}}function Oa(t,e){let i=Object.create(null);for(let n of e){let e=t.lineAt(n.from);(i[e.from]||(i[e.from]=[])).push(n)}let n=[];for(let t in i)n.push(new Da(i[t]).range(+t));return It.of(n,!0)}const Ra=Oo({class:"cm-gutter-lint",markers:t=>t.state.field(Ea),widgetMarker:(t,e,i)=>{let n=[];return t.state.field(Ea).between(i.from,i.to,(t,e,s)=>{t>i.from&&tIt.empty,update(t,e){t=t.map(e.changes);let i=e.state.facet(Na).markerFilter;for(let n of e.effects)if(n.is(ra)){let s=n.value;i&&(s=i(s||[],e.state)),t=Oa(e.state.doc,s.slice(0))}return t}}),Pa=gt.define(),La=U.define({create:()=>null,update:(t,e)=>(t&&e.docChanged&&(t=ia(e,t)?null:{...t,pos:e.changes.mapPos(t.pos)}),e.effects.reduce((t,e)=>e.is(Pa)?e.value:t,t)),provide:t=>so.from(t)}),Ia=cr.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:Sa('')},".cm-lint-marker-warning":{content:Sa('')},".cm-lint-marker-error":{content:Sa('')}}),Ba=[aa,cr.decorations.compute([aa],t=>{let{selected:e,panel:i}=t.field(aa);return e&&i&&e.from!=e.to?ci.set([ha.range(e.from,e.to)]):ci.none}),co(ca,{hideOn:ia}),Ma],Na=q.define({combine:t=>Ot(t,{hoverTime:300,markerFilter:null,tooltipFilter:null})});const za=1024;let Ha=0;class Fa{constructor(t,e){this.from=t,this.to=e}}class qa{constructor(t={}){this.id=Ha++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=_a.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}qa.closedBy=new qa({deserialize:t=>t.split(" ")}),qa.openedBy=new qa({deserialize:t=>t.split(" ")}),qa.group=new qa({deserialize:t=>t.split(" ")}),qa.isolate=new qa({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),qa.contextHash=new qa({perNode:!0}),qa.lookAhead=new qa({perNode:!0}),qa.mounted=new qa({perNode:!0});class Va{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[qa.mounted.id]}}const Wa=Object.create(null);class _a{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):Wa,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new _a(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(n)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return n}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(qa.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let n of i.split(" "))e[n]=t[i];return t=>{for(let i=t.prop(qa.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}_a.none=new _a("",Object.create(null),0,8);class $a{constructor(t){this.types=t;for(let e=0;e=e){let o=new th(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Za(o,e,i,!1))}}return s?rh(s):n}(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:s=this.length}=t,r=t.mode||0,o=(r&Ua.IncludeAnonymous)>0;for(let t=this.cursor(r|Ua.IncludeAnonymous);;){let r=!1;if(t.from<=s&&t.to>=n&&(!o&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;r=!0}for(;r&&i&&(o||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;r=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:uh(_a.none,this.children,this.positions,0,this.children.length,0,this.length,(t,e,i)=>new Ya(this.type,t,e,i,this.propValues),t.makeTree||((t,e,i)=>new Ya(_a.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=za,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Ga(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,w,b,y){let{id:x,start:k,end:S,size:C}=l,M=c,A=h;if(C<0){if(l.next(),-1==C){let e=r[x];return i.push(e),void w.push(k-t)}if(-3==C)return void(h=x);if(-4==C)return void(c=x);throw new RangeError(`Unrecognized record size: ${C}`)}let T,D,O=a[x],R=k-t;if(S-k<=s&&(D=g(l.pos-e,b))){let e=new Uint16Array(D.size-D.skip),i=l.pos-D.size,s=e.length;for(;l.pos>i;)s=v(D.start,e,s);T=new Xa(e,S-D.start,n),R=D.start-t}else{let t=l.pos-C;l.next();let e=[],i=[],n=x>=o?x:-1,r=0,a=S;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(p(e,i,k,r,l.end,a,n,M,A),r=e.length,a=l.end),l.next()):y>2500?d(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=f(O,A);T=uh(O,e,i,0,e.length,0,S-k,t,t)}else T=m(O,e,i,S-k,M-S,A)}i.push(T),w.push(R)}function d(t,e,i,r){let o=[],a=0,h=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:n}=l;if(n>4)l.next();else{if(h>-1&&e=0;t-=3)e[i++]=o[t],e[i++]=o[t+1]-s,e[i++]=o[t+2]-s,e[i++]=i;i.push(new Xa(e,o[2]-s,n)),r.push(s-t)}}function f(t,e){return(i,n,s)=>{let r,o,l=0,a=i.length-1;if(a>=0&&(r=i[a])instanceof Ya){if(!a&&r.type==t&&r.length==s)return r;(o=r.prop(qa.lookAhead))&&(l=n[a]+r.length+o)}return m(t,i,n,s,l,e)}}function p(t,e,i,s,r,o,l,a,h){let c=[],u=[];for(;t.length>s;)c.push(t.pop()),u.push(e.pop()+i-r);t.push(m(n.types[l],c,u,o-r,a-o,h)),e.push(r-i)}function m(t,e,i,n,s,r,o){if(r){let t=[qa.contextHash,r];o=o?[t].concat(o):[t]}if(s>25){let t=[qa.lookAhead,s];o=o?[t].concat(o):[t]}return new Ya(t,e,i,n,o)}function g(t,e){let i=l.fork(),n=0,r=0,a=0,h=i.end-s,c={size:0,start:0,skip:0};t:for(let s=i.pos-t;i.pos>s;){let t=i.size;if(i.id==e&&t>=0){c.size=n,c.start=r,c.skip=a,a+=4,n+=4,i.next();continue}let l=i.pos-t;if(t<0||l=o?4:0,d=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size)break t;u+=4}else i.id>=o&&(u+=4);i.next()}r=d,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}function v(t,e,i){let{id:n,start:s,end:r,size:a}=l;if(l.next(),a>=0&&n4){let n=l.pos-(a-4);for(;l.pos>n;)i=v(t,e,i)}e[--i]=o,e[--i]=r-t,e[--i]=s-t,e[--i]=n}else-3==a?h=n:-4==a&&(c=n);return i}let w=[],b=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,w,b,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:w.length?b[0]+w[0].length:0;return new Ya(a[t.topID],w.reverse(),b.reverse(),y)}(t)}}Ya.empty=new Ya(_a.none,[],[],0);class Ga{constructor(t,e){this.buffer=t,this.index=e}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 Ga(this.buffer,this.index)}}class Xa{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return _a.none}toString(){let t=[];for(let e=0;e0));l=r[l+3]);return o}slice(t,e,i){let n=this.buffer,s=new Uint16Array(e-t),r=0;for(let o=t,l=0;o=e&&ie;case 1:return i<=e&&n>e;case 2:return n>e;case 4:return!0}}function Za(t,e,i,n){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?o.length:-1;t!=a;t+=e){let a=o[t],h=l[t]+r.from;if(Ja(n,i,h,h+a.length))if(a instanceof Xa){if(s&Ua.ExcludeBuffers)continue;let o=a.findChild(0,a.buffer.length,e,i-h,n);if(o>-1)return new sh(new nh(r,a,t,h),null,o)}else if(s&Ua.IncludeAnonymous||!a.type.isAnonymous||ah(a)){let o;if(!(s&Ua.IgnoreMounts)&&(o=Va.get(a))&&!o.overlay)return new th(o.tree,h,t,r);let l=new th(a,h,t,r);return s&Ua.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?a.children.length-1:0,e,i,n)}}if(s&Ua.IncludeAnonymous||!r.type.isAnonymous)return null;if(t=r.index>=0?r.index+e:e<0?-1:r._parent._tree.children.length,r=r._parent,!r)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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let n;if(!(i&Ua.IgnoreOverlays)&&(n=Va.get(this._tree))&&n.overlay){let i=t-this.from;for(let{from:t,to:s}of n.overlay)if((e>0?t<=i:t=i:s>i))return new th(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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 eh(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(let t=!1;!t;)if(t=s.type.is(i),!s.nextSibling())return r;for(;;){if(null!=n&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return null==n?r:[]}}function ih(t,e,i=e.length-1){for(let n=t;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[i]&&e[i]!=n.name)return!1;i--}}return!0}class nh{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class sh 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(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return s<0?null:new sh(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,i=0){if(i&Ua.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new sh(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new sh(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new sh(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let r=i.buffer[this.index+1];t.push(i.slice(n,s,r)),e.push(0)}return new Ya(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function rh(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;ni.from||s.to0){if(this.index-1)for(let n=e+t,s=t<0?-1:i._tree.children.length;n!=s;n+=t){let t=i._tree.children[n];if(this.mode&Ua.IncludeAnonymous||t instanceof Xa||!t.type.isAnonymous||ah(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let r=t;r;r=r._parent)if(r.index==n){if(n==this.index)return r;e=r,i=s+1;break t}n=this.stack[--s]}for(let t=i;t=0;s--){if(s<0)return ih(this._tree,t,n);let r=i[e.buffer[this.stack[s]]];if(!r.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}}function ah(t){return t.children.some(t=>t instanceof Xa||!t.type.isAnonymous||ah(t))}const hh=new WeakMap;function ch(t,e){if(!t.isAnonymous||e instanceof Xa||e.type!=t)return 1;let i=hh.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof Ya)){i=1;break}i+=ch(t,n)}hh.set(e,i)}return i}function uh(t,e,i,n,s,r,o,l,a){let h=0;for(let i=n;i=c)break;p+=e}if(h==s+1){if(p>c){let t=i[s];e(t.children,t.positions,0,t.children.length,n[s]+l);continue}u.push(i[s])}else{let e=n[h-1]+i[h-1].length-f;u.push(uh(t,i,n,s,h,f,e,null,a))}d.push(f+l-r)}}(e,i,n,s,0),(l||a)(u,d,o)}class dh{constructor(t,e,i,n,s=!1,r=!1){this.from=t,this.to=e,this.tree=i,this.offset=n,this.open=(s?1:0)|(r?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let n=[new dh(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&n.push(i);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],s=1,r=t.length?t[0]:null;for(let o=0,l=0,a=0;;o++){let h=o=i)for(;r&&r.from=e.from||c<=e.to||a){let t=Math.max(e.from,l)-a,i=Math.min(e.to,c)-a;e=t>=i?null:new dh(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew Fa(t.from,t.to)):[new Fa(0,0)]:[new Fa(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let t=n.advance();if(t)return t}}}class ph{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new qa({perNode:!0});let mh=0;class gh{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=mh++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof gh&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let n=new gh(i,[],null,[]);if(n.set.push(n),e)for(let t of e.set)n.set.push(t);return n}static defineModifier(t){let e=new wh(t);return t=>t.modified.indexOf(e)>-1?t:wh.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let vh=0;class wh{constructor(t){this.name=t,this.instances=[],this.id=vh++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(i=>{return i.base==t&&(n=e,s=i.modified,n.length==s.length&&n.every((t,e)=>t==s[e]));var n,s});if(i)return i;let n=[],s=new gh(t.name,n,t,e);for(let t of e)t.instances.push(s);let r=function(t){let e=[[]];for(let i=0;ie.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of r)n.push(wh.get(e,t));return s}}function bh(t){let e=Object.create(null);for(let i in t){let n=t[i];Array.isArray(n)||(n=[n]);for(let t of i.split(" "))if(t){let i=[],s=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){s=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!n)throw new RangeError("Invalid path: "+t);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),e+=n[0].length,e==t.length)break;let o=t[e++];if(e==t.length&&"!"==o){s=0;break}if("/"!=o)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let o=i.length-1,l=i[o];if(!l)throw new RangeError("Invalid path: "+t);let a=new xh(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return yh.add(e)}const yh=new qa({combine(t,e){let i,n,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),i&&i.mode==s.mode&&!s.context&&!i.context)continue;let r=new xh(s.tags,s.mode,s.context);i?i.next=r:n=r,i=r}return n}});class xh{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=s;for(let n of t)for(let t of n.set){let n=i[t.id];if(n){e=e?e+" "+n:n;break}}return e},scope:n}}function Sh(t,e,i,n=0,s=t.length){let r=new Mh(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}function Ch(t,e,i,n,s,r=0,o=t.length){let l=r;function a(e,i){if(!(e<=l)){for(let r=t.slice(l,e),o=0;;){let t=r.indexOf("\n",o),e=t<0?r.length:t;if(e>o&&n(r.slice(o,e),i),t<0)break;s(),o=t+1}l=e}}Sh(e,i,(t,e,i)=>{a(t,""),a(e,i)},r,o),a(o,"")}xh.empty=new xh([],2,null);class Mh{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,n,s){let{type:r,from:o,to:l}=t;if(o>=i||l<=e)return;r.isTop&&(s=this.highlighters.filter(t=>!t.scope||t.scope(r)));let a=n,h=function(t){let e=t.type.prop(yh);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||xh.empty,c=function(t,e){let i=null;for(let n of t){let t=n.style(e);t&&(i=i?i+" "+t:t)}return i}(s,h.tags);if(c&&(a&&(a+=" "),a+=c,1==h.mode&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,o),a),h.opaque)return;let u=t.tree&&t.tree.prop(qa.mounted);if(u&&u.overlay){let r=t.node.enter(u.overlay[0].from+o,1),h=this.highlighters.filter(t=>!t.scope||t.scope(u.tree.type)),c=t.firstChild();for(let d=0,f=o;;d++){let p=d=m)&&t.nextSibling()););if(!p||m>i)break;f=p.to+o,f>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,f),"",h),this.startSpan(Math.min(i,f),a))}c&&t.parent()}else if(t.firstChild()){u&&(n="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,s),this.startSpan(Math.min(i,t.to),a)}}while(t.nextSibling());t.parent()}}}const Ah=gh.define,Th=Ah(),Dh=Ah(),Oh=Ah(Dh),Rh=Ah(Dh),Eh=Ah(),Ph=Ah(Eh),Lh=Ah(Eh),Ih=Ah(),Bh=Ah(Ih),Nh=Ah(),zh=Ah(),Hh=Ah(),Fh=Ah(Hh),qh=Ah(),Vh={comment:Th,lineComment:Ah(Th),blockComment:Ah(Th),docComment:Ah(Th),name:Dh,variableName:Ah(Dh),typeName:Oh,tagName:Ah(Oh),propertyName:Rh,attributeName:Ah(Rh),className:Ah(Dh),labelName:Ah(Dh),namespace:Ah(Dh),macroName:Ah(Dh),literal:Eh,string:Ph,docString:Ah(Ph),character:Ah(Ph),attributeValue:Ah(Ph),number:Lh,integer:Ah(Lh),float:Ah(Lh),bool:Ah(Eh),regexp:Ah(Eh),escape:Ah(Eh),color:Ah(Eh),url:Ah(Eh),keyword:Nh,self:Ah(Nh),null:Ah(Nh),atom:Ah(Nh),unit:Ah(Nh),modifier:Ah(Nh),operatorKeyword:Ah(Nh),controlKeyword:Ah(Nh),definitionKeyword:Ah(Nh),moduleKeyword:Ah(Nh),operator:zh,derefOperator:Ah(zh),arithmeticOperator:Ah(zh),logicOperator:Ah(zh),bitwiseOperator:Ah(zh),compareOperator:Ah(zh),updateOperator:Ah(zh),definitionOperator:Ah(zh),typeOperator:Ah(zh),controlOperator:Ah(zh),punctuation:Hh,separator:Ah(Hh),bracket:Fh,angleBracket:Ah(Fh),squareBracket:Ah(Fh),paren:Ah(Fh),brace:Ah(Fh),content:Ih,heading:Bh,heading1:Ah(Bh),heading2:Ah(Bh),heading3:Ah(Bh),heading4:Ah(Bh),heading5:Ah(Bh),heading6:Ah(Bh),contentSeparator:Ah(Ih),list:Ah(Ih),quote:Ah(Ih),emphasis:Ah(Ih),strong:Ah(Ih),link:Ah(Ih),monospace:Ah(Ih),strikethrough:Ah(Ih),inserted:Ah(),deleted:Ah(),changed:Ah(),invalid:Ah(),meta:qh,documentMeta:Ah(qh),annotation:Ah(qh),processingInstruction:Ah(qh),definition:gh.defineModifier("definition"),constant:gh.defineModifier("constant"),function:gh.defineModifier("function"),standard:gh.defineModifier("standard"),local:gh.defineModifier("local"),special:gh.defineModifier("special")};for(let t in Vh){let e=Vh[t];e instanceof gh&&(e.name=t)}var Wh;kh([{tag:Vh.link,class:"tok-link"},{tag:Vh.heading,class:"tok-heading"},{tag:Vh.emphasis,class:"tok-emphasis"},{tag:Vh.strong,class:"tok-strong"},{tag:Vh.keyword,class:"tok-keyword"},{tag:Vh.atom,class:"tok-atom"},{tag:Vh.bool,class:"tok-bool"},{tag:Vh.url,class:"tok-url"},{tag:Vh.labelName,class:"tok-labelName"},{tag:Vh.inserted,class:"tok-inserted"},{tag:Vh.deleted,class:"tok-deleted"},{tag:Vh.literal,class:"tok-literal"},{tag:Vh.string,class:"tok-string"},{tag:Vh.number,class:"tok-number"},{tag:[Vh.regexp,Vh.escape,Vh.special(Vh.string)],class:"tok-string2"},{tag:Vh.variableName,class:"tok-variableName"},{tag:Vh.local(Vh.variableName),class:"tok-variableName tok-local"},{tag:Vh.definition(Vh.variableName),class:"tok-variableName tok-definition"},{tag:Vh.special(Vh.variableName),class:"tok-variableName2"},{tag:Vh.definition(Vh.propertyName),class:"tok-propertyName tok-definition"},{tag:Vh.typeName,class:"tok-typeName"},{tag:Vh.namespace,class:"tok-namespace"},{tag:Vh.className,class:"tok-className"},{tag:Vh.macroName,class:"tok-macroName"},{tag:Vh.propertyName,class:"tok-propertyName"},{tag:Vh.operator,class:"tok-operator"},{tag:Vh.comment,class:"tok-comment"},{tag:Vh.meta,class:"tok-meta"},{tag:Vh.invalid,class:"tok-invalid"},{tag:Vh.punctuation,class:"tok-punctuation"}]);const _h=new qa;const $h=new qa;class jh{constructor(t,e,i=[],n=""){this.data=t,this.name=n,Dt.prototype.hasOwnProperty("tree")||Object.defineProperty(Dt.prototype,"tree",{get(){return Uh(this)}}),this.parser=e,this.extension=[ic.of(this),Dt.languageData.of((t,e,i)=>{let n=Kh(t,e,i),s=n.type.prop(_h);if(!s)return[];let r=t.facet(s),o=n.type.prop($h);if(o){let s=n.resolve(e-n.from,i);for(let e of o)if(e.test(s,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(r)}}return r})].concat(i)}isActiveAt(t,e,i=-1){return Kh(t,e,i).type.prop(_h)==this.data}findRegions(t){let e=t.facet(ic);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(t,e)=>{if(t.prop(_h)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(qa.mounted);if(s){if(s.tree.prop(_h)==this.data){if(s.overlay)for(let t of s.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(s.overlay){let t=i.length;if(n(s.tree,s.overlay[0].from+e),i.length>t)return}}for(let i=0;i=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Gh=null;class Xh{constructor(t,e,i=[],n,s,r,o,l){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Xh(t,e,[],Ya.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Yh(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=Ya.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(dh.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Gh;Gh=this;try{return t()}finally{Gh=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Jh(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,i,n,s)=>e.push({fromA:t,toA:i,fromB:n,toB:s})),i=dh.applyChanges(i,e),n=Ya.empty,s=0,r={from:t.mapPos(r.from,-1),to:t.mapPos(r.to,1)},this.skipped.length){o=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),n=t.mapPos(e.to,-1);it.from&&(this.fragments=Jh(this.fragments,i,n),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends fh{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Gh;if(e){for(let t of n)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=r,new Ya(_a.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Gh}}function Jh(t,e,i){return dh.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Zh{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Zh(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Xh.create(t.facet(ic).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Zh(i)}}jh.state=U.define({create:Zh.init,update(t,e){for(let t of e.effects)if(t.is(jh.setState))return t.value;return e.startState.facet(ic)!=e.state.facet(ic)?Zh.init(e.state):t.apply(e)}});let Qh=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Qh=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const tc="undefined"!=typeof navigator&&(null===(Wh=navigator.scheduling)||void 0===Wh?void 0:Wh.isInputPending)?()=>navigator.scheduling.isInputPending():null,ec=ln.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(jh.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(jh.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Qh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work(()=>tc&&tc()||Date.now()>r,n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:jh.setState.of(new Zh(s.context))})),this.chunkBudget>0&&(!l||o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(t=>nn(this.view.state,t)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),ic=q.define({combine:t=>t.length?t[0]:null,enables:t=>[jh.state,ec,cr.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]}),nc=q.define(),sc=q.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function rc(t){let e=t.facet(sc);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function oc(t,e){let i="",n=t.tabSize,s=t.facet(sc)[0];if("\t"==s){for(;e>=n;)i+="\t",e-=n;s=" "}for(let t=0;t=e?function(t,e,i){let n=e.resolveStack(i),s=e.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e&&!(e.fromn.node.to||e.from==n.node.from&&e.type==n.node.type);e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return cc(n,t,i)}(t,i,e):null}class ac{constructor(t,e={}){this.state=t,this.options=e,this.unit=rc(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return null!=n&&n>=i.from&&n<=i.to?s&&n==t?{text:"",from:t}:(e<0?n-1&&(s+=r-this.countColumn(i,i.search(/\S|$/))),s}countColumn(t,e=t.length){return Kt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let t=s(n);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const hc=new qa;function cc(t,e,i){for(let n=t;n;n=n.next){let t=uc(n.node);if(t)return t(fc.create(e,i,n))}return 0}function uc(t){let e=t.type.prop(hc);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(qa.closedBy))){let e=t.lastChild,n=e&&i.indexOf(e.name)>-1;return t=>function(t,e,i,n,s){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==t.pos+o,a=function(t){let e=t.node,i=e.childAfter(e.from),n=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(i.from),o=null==s||s<=r.from?r.to:Math.min(r.to,s);for(let t=i.to;;){let s=e.childAfter(t);if(!s||s==n)return null;if(!s.type.isSkipped){if(s.from>=o)return null;let t=/^ */.exec(r.text.slice(i.to-r.from))[0].length;return{from:i.from,to:i.to+t}}t=s.to}}(t);return a?l?t.column(a.from):t.column(a.to):t.baseIndent+(l?0:t.unit*i)}(t,0,1,void 0,n&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?dc:null}function dc(){return 0}class fc extends ac{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new fc(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(pc(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return cc(this.context.next,this.base,this.pos)}}function pc(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}const mc=q.define(),gc=new qa;function vc(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function wc(t,e,i){for(let n of t.facet(mc)){let s=n(t,e,i);if(s)return s}return function(t,e,i){let n=Uh(t);if(n.lengthi)continue;if(s&&o.from=e&&n.to>i&&(s=n)}}return s}(t,e,i)}function bc(t,e){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);return i>=n?void 0:{from:i,to:n}}const yc=gt.define({map:bc}),xc=gt.define({map:bc});function kc(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some(t=>t.from<=i&&t.to>=i)||e.push(t.lineBlockAt(i));return e}const Sc=U.define({create:()=>ci.none,update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((e,i)=>t=Cc(t,e,i)),t=t.map(e.changes);for(let i of e.effects)if(i.is(yc)&&!Ac(t,i.value.from,i.value.to)){let{preparePlaceholder:n}=e.state.facet(Ec),s=n?ci.replace({widget:new Bc(n(e.state,i.value))}):Ic;t=t.update({add:[s.range(i.value.from,i.value.to)]})}else i.is(xc)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));return e.selection&&(t=Cc(t,e.selection.main.head)),t},provide:t=>cr.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,(t,e)=>{i.push(t,e)}),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i{te&&(n=!0)}),n?t.update({filterFrom:e,filterTo:i,filter:(t,n)=>t>=i||n<=e}):t}function Mc(t,e,i){var n;let s=null;return null===(n=t.field(Sc,!1))||void 0===n||n.between(e,i,(t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}),s}function Ac(t,e,i){let n=!1;return t.between(e,e,(t,s)=>{t==e&&s==i&&(n=!0)}),n}function Tc(t,e){return t.field(Sc,!1)?e:e.concat(gt.appendConfig.of(Pc()))}function Dc(t,e,i=!0){let n=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return cr.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${n} ${t.state.phrase("to")} ${s}.`)}const Oc=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of kc(t)){let i=wc(t.state,e.from,e.to);if(i)return t.dispatch({effects:Tc(t.state,[yc.of(i),Dc(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Sc,!1))return!1;let e=[];for(let i of kc(t)){let n=Mc(t.state,i.from,i.to);n&&e.push(xc.of(n),Dc(t,n,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let n=0;n{let e=t.state.field(Sc,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,(t,e)=>{i.push(xc.of({from:t,to:e}))}),t.dispatch({effects:i}),!0}}],Rc={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Ec=q.define({combine:t=>Ot(t,Rc)});function Pc(t){return[Sc,Hc]}function Lc(t,e){let{state:i}=t,n=i.facet(Ec),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),n=Mc(t.state,i.from,i.to);n&&t.dispatch({effects:xc.of(n)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",i.phrase("folded code")),r.title=i.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const Ic=ci.replace({widget:new class extends ai{toDOM(t){return Lc(t,null)}}});class Bc extends ai{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Lc(t,this.value)}}const Nc={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class zc extends Co{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}const Hc=cr.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class Fc{constructor(t,e){let i;function n(t){let e=Jt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const s="string"==typeof e.all?e.all:e.all?n(e.all):void 0,r=e.scope;this.scope=r instanceof jh?t=>t.prop(_h)==r.data:r?t=>t==r:void 0,this.style=kh(t.map(t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))})),{all:s}).style,this.module=i?new Jt(i):null,this.themeType=e.themeType}static define(t,e){return new Fc(t,e||{})}}const qc=q.define(),Vc=q.define({combine:t=>t.length?[t[0]]:null});function Wc(t){let e=t.facet(qc);return e.length?e:t.facet(Vc)}function _c(t,e,i){let n=Wc(t),s=null;if(n)for(let t of n)if(!t.scope||i){let i=t.style(e);i&&(s=s?s+" "+i:i)}return s}class $c{constructor(t){this.markCache=Object.create(null),this.tree=Uh(t.state),this.decorations=this.buildDeco(t,Wc(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Uh(t.state),i=Wc(t.state),n=i!=Wc(t.startState),{viewport:s}=t.view,r=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=r):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return ci.none;let i=new Bt;for(let{from:n,to:s}of t.visibleRanges)Sh(this.tree,e,(t,e,n)=>{i.add(t,e,this.markCache[n]||(this.markCache[n]=ci.mark({class:n})))},n,s);return i.finish()}}const jc=Q.high(ln.fromClass($c,{decorations:t=>t.decorations})),Kc=Fc.define([{tag:Vh.meta,color:"#404740"},{tag:Vh.link,textDecoration:"underline"},{tag:Vh.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Vh.emphasis,fontStyle:"italic"},{tag:Vh.strong,fontWeight:"bold"},{tag:Vh.strikethrough,textDecoration:"line-through"},{tag:Vh.keyword,color:"#708"},{tag:[Vh.atom,Vh.bool,Vh.url,Vh.contentSeparator,Vh.labelName],color:"#219"},{tag:[Vh.literal,Vh.inserted],color:"#164"},{tag:[Vh.string,Vh.deleted],color:"#a11"},{tag:[Vh.regexp,Vh.escape,Vh.special(Vh.string)],color:"#e40"},{tag:Vh.definition(Vh.variableName),color:"#00f"},{tag:Vh.local(Vh.variableName),color:"#30a"},{tag:[Vh.typeName,Vh.namespace],color:"#085"},{tag:Vh.className,color:"#167"},{tag:[Vh.special(Vh.variableName),Vh.macroName],color:"#256"},{tag:Vh.definition(Vh.propertyName),color:"#00c"},{tag:Vh.comment,color:"#940"},{tag:Vh.invalid,color:"#f00"}]),Uc=cr.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Yc="()[]{}",Gc=q.define({combine:t=>Ot(t,{afterCursor:!0,brackets:Yc,maxScanDistance:1e4,renderMatch:Zc})}),Xc=ci.mark({class:"cm-matchingBracket"}),Jc=ci.mark({class:"cm-nonmatchingBracket"});function Zc(t){let e=[],i=t.matched?Xc:Jc;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}const Qc=U.define({create:()=>ci.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],n=e.state.facet(Gc);for(let t of e.state.selection.ranges){if(!t.empty)continue;let s=su(e.state,t.head,-1,n)||t.head>0&&su(e.state,t.head-1,1,n)||n.afterCursor&&(su(e.state,t.head,1,n)||t.headcr.decorations.from(t)}),tu=[Qc,Uc];const eu=new qa;function iu(t,e,i){let n=t.prop(e<0?qa.openedBy:qa.closedBy);if(n)return n;if(1==t.name.length){let n=i.indexOf(t.name);if(n>-1&&n%2==(e<0?1:0))return[i[n+e]]}return null}function nu(t){let e=t.type.prop(eu);return e?e(t.node):t}function su(t,e,i,n={}){let s=n.maxScanDistance||1e4,r=n.brackets||Yc,o=Uh(t),l=o.resolveInner(e,i);for(let n=l;n;n=n.parent){let s=iu(n.type,i,r);if(s&&n.from0?e>=o.from&&eo.from&&e<=o.to))return ru(t,e,i,n,o,s,r)}}return function(t,e,i,n,s,r,o){let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=i>0)return null;let h={from:i<0?e-1:e,to:i>0?e+1:e},c=t.doc.iterRange(e,i>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=r;){let r=c.value;i<0&&(t+=r.length);let l=e+t*i;for(let t=i>0?0:r.length-1,e=i>0?r.length:-1;t!=e;t+=i){let e=o.indexOf(r[t]);if(!(e<0||n.resolveInner(l+t,1).type!=s))if(e%2==0==i>0)u++;else{if(1==u)return{start:h,end:{from:l+t,to:l+t+1},matched:e>>1==a>>1};u--}}i>0&&(t+=r.length)}return c.done?{start:h,matched:!1}:null}(t,e,i,o,l.type,s,r)}function ru(t,e,i,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},h=0,c=null==l?void 0:l.cursor();if(c&&(i<0?c.childBefore(n.from):c.childAfter(n.to)))do{if(i<0?c.to<=n.from:c.from>=n.to){if(0==h&&r.indexOf(c.type.name)>-1&&c.from=this.string.length}sol(){return 0==this.pos}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pose}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPosi?t.toLowerCase():t;return n(this.string.substr(this.pos,t.length))==n(t)?(!1!==e&&(this.pos+=t.length),!0):null}{let i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&!1!==e&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function au(t){if("object"!=typeof t)return t;let e={};for(let i in t){let n=t[i];e[i]=n instanceof Array?n.slice():n}return e}const hu=new WeakMap;class cu extends jh{constructor(t){let e=(i=t.languageData,q.define({combine:i?t=>t.concat(i):void 0}));var i;let n,s={name:(r=t).name||"",token:r.token,blankLine:r.blankLine||(()=>{}),startState:r.startState||(()=>!0),copyState:r.copyState||au,indent:r.indent||(()=>null),languageData:r.languageData||{},tokenTable:r.tokenTable||mu,mergeTokens:!1!==r.mergeTokens};var r;super(e,new class extends fh{createParse(t,e,i){return new fu(n,t,e,i)}},[],t.name),this.topNode=function(t,e){let i=_a.define({id:gu.length,name:"Document",props:[_h.add(()=>t),hc.add(()=>t=>e.getIndent(t))],top:!0});return gu.push(i),i}(e,this),n=this,this.streamParser=s,this.stateAfter=new qa({perNode:!0}),this.tokenTable=t.tokenTable?new xu(s.tokenTable):ku}static define(t){return new cu(t)}getIndent(t){let e,{overrideIndentation:i}=t.options;i&&(e=hu.get(t.state),null!=e&&e1e4)return null;for(;n=n&&i+e.length<=s&&e.prop(t.stateAfter);if(r)return{state:t.streamParser.copyState(r),pos:i+e.length};for(let r=e.children.length-1;r>=0;r--){let o=e.children[r],l=i+e.positions[r],a=o instanceof Ya&&l=e.length)return e;s||0!=i||e.type!=t.topNode||(s=!0);for(let r=e.children.length-1;r>=0;r--){let o,l=e.positions[r],a=e.children[r];if(li&&uu(t,s.tree,0-s.offset,i,o);if(l&&l.pos<=n&&(e=du(t,s.tree,i+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:e}}return{state:t.streamParser.startState(s?rc(s):4),tree:Ya.empty}}(t,i,r,this.to,null==s?void 0:s.state);this.state=o,this.parsedPos=this.chunkStart=r+l.length;for(let t=0;tt.from<=s.viewport.from&&t.to>=s.viewport.from)&&(this.state=this.lang.streamParser.startState(rc(s.state)),s.skipUntilInView(this.parsedPos,s.viewport.from),this.parsedPos=s.viewport.from),this.moveRangeIndex()}advance(){let t=Xh.get(),e=null==this.stoppedAt?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(e,this.chunkStart+512);for(t&&(i=Math.min(i,t.viewport.to));this.parsedPos=e?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,e),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let e=this.input.chunk(t);if(this.input.lineChunks)"\n"==e&&(e="");else{let t=e.indexOf("\n");t>-1&&(e=e.slice(0,t))}return t+e.length<=this.to?e:e.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,e=this.lineAfter(t),i=t+e.length;for(let t=this.rangeIndex;;){let n=this.ranges[t].to;if(n>=i)break;if(e=e.slice(0,n-(i-e.length)),t++,t==this.ranges.length)break;let s=this.ranges[t].from,r=this.lineAfter(s);e+=r,i=s+r.length}return{line:e,end:i}}skipGapsTo(t,e,i){for(;;){let n=this.ranges[this.rangeIndex].to,s=t+e;if(i>0?n>s:n>=s)break;e+=this.ranges[++this.rangeIndex].from-n}return e}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){e+=n=this.skipGapsTo(e,n,1);let t=this.chunk.length;i+=n=this.skipGapsTo(i,n,-1),s+=this.chunk.length-t}let r=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&4==s&&r>=0&&this.chunk[r]==t&&this.chunk[r+2]==e?this.chunk[r+2]=i:this.chunk.push(t,e,i,s),n}parseLine(t){let{line:e,end:i}=this.nextLine(),n=0,{streamParser:s}=this.lang,r=new lu(e,t?t.state.tabSize:4,t?rc(t.state):2);if(r.eol())s.blankLine(this.state,r.indentUnit);else for(;!r.eol();){let t=pu(s.token,r,this.state);if(t&&(n=this.emitToken(this.lang.tokenTable.resolve(t),this.parsedPos+r.start,this.parsedPos+r.pos,n)),r.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return n}throw new Error("Stream parser failed to advance stream.")}const mu=Object.create(null),gu=[_a.none],vu=new $a(gu),wu=[],bu=Object.create(null),yu=Object.create(null);for(let[t,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"]])yu[t]=Cu(mu,e);class xu{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),yu)}resolve(t){return t?this.table[t]||(this.table[t]=Cu(this.extra,t)):0}}const ku=new xu(mu);function Su(t,e){wu.indexOf(t)>-1||(wu.push(t),console.warn(e))}function Cu(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||Vh[i];n?"function"==typeof n?e.length?e=e.map(n):Su(i,`Modifier ${i} used at start of tag`):e.length?Su(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:Su(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+i.map(t=>t.id),r=bu[s];if(r)return r.id;let o=bu[s]=_a.define({id:gu.length,name:n,props:[bh({[n]:i})]});return gu.push(o),o.id}ki.RTL,ki.LTR;function Mu(t,e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=t(e,i);return!!s&&(n(i.update(s)),!0)}}const Au=Mu(Pu,0),Tu=Mu(Eu,0),Du=Mu((t,e)=>Eu(t,e,function(t){let e=[];for(let i of t.selection.ranges){let n=t.doc.lineAt(i.from),s=i.to<=n.to?n:t.doc.lineAt(i.to);s.from>n.from&&s.from==i.to&&(s=i.to==n.to+1?n:t.doc.lineAt(i.to-1));let r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:s.to})}return e}(e)),0);function Ou(t,e){let i=t.languageDataAt("commentTokens",e,1);return i.length?i[0]:{}}const Ru=50;function Eu(t,e,i=e.selection.ranges){let n=i.map(t=>Ou(e,t.from).block);if(!n.every(t=>t))return null;let s=i.map((t,i)=>function(t,{open:e,close:i},n,s){let r,o,l=t.sliceDoc(n-Ru,n),a=t.sliceDoc(s,s+Ru),h=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(a)[0].length,u=l.length-h;if(l.slice(u-e.length,u)==e&&a.slice(c,c+i.length)==i)return{open:{pos:n-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-n<=2*Ru?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Ru),o=t.sliceDoc(s-Ru,s));let d=/^\s*/.exec(r)[0].length,f=/\s*$/.exec(o)[0].length,p=o.length-f-i.length;return r.slice(d,d+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+d+e.length,margin:/\s/.test(r.charAt(d+e.length))?1:0},close:{pos:s-f-i.length,margin:/\s/.test(o.charAt(p-1))?1:0}}:null}(e,n[i],t.from,t.to));if(2!=t&&!s.every(t=>t))return{changes:e.changes(i.map((t,e)=>s[e]?[]:[{from:t.from,insert:n[e].open+" "},{from:t.to,insert:" "+n[e].close}]))};if(1!=t&&s.some(t=>t)){let t=[];for(let e,i=0;is&&(t==r||r>a.from)){s=a.from;let t=/^\s*/.exec(a.text)[0].length,e=t==a.length,i=a.text.slice(t,t+l.length)==l?t:-1;tt.comment<0&&(!t.empty||t.single))){let t=[];for(let{line:e,token:i,indent:s,empty:r,single:o}of n)!o&&r||t.push({from:e.from+s,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&n.some(t=>t.comment>=0)){let t=[];for(let{line:e,comment:i,token:s}of n)if(i>=0){let n=e.from+i,r=n+s.length;" "==e.text[r-e.from]&&r++,t.push({from:n,to:r})}return{changes:t}}return null}const Lu=ft.define(),Iu=ft.define(),Bu=q.define(),Nu=q.define({combine:t=>Ot(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}),zu=U.define({create:()=>Qu.empty,update(t,e){let i=e.state.facet(Nu),n=e.annotation(Lu);if(n){let s=_u.fromTransaction(e,n.selection),r=n.side,o=0==r?t.undone:t.done;return o=s?$u(o,o.length,i.minDepth,s):Yu(o,e.startState.selection),new Qu(0==r?n.rest:o,0==r?o:n.rest)}let s=e.annotation(Iu);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(vt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=_u.fromTransaction(e),o=e.annotation(vt.time),l=e.annotation(vt.userEvent);return r?t=t.addChanges(r,o,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,i.newGroupDelay)),"full"!=s&&"after"!=s||(t=t.isolate()),t},toJSON:t=>({done:t.done.map(t=>t.toJSON()),undone:t.undone.map(t=>t.toJSON())}),fromJSON:t=>new Qu(t.done.map(_u.fromJSON),t.undone.map(_u.fromJSON))});function Hu(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(zu,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const Fu=Hu(0,!1),qu=Hu(1,!1),Vu=Hu(0,!0),Wu=Hu(1,!0);class _u{constructor(t,e,i,n,s){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(t){return new _u(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(t=>t.toJSON())}}static fromJSON(t){return new _u(t.changes&&O.fromJSON(t.changes),[],t.mapped&&D.fromJSON(t.mapped),t.startSelection&&z.fromJSON(t.startSelection),t.selectionsAfter.map(z.fromJSON))}static fromTransaction(t,e){let i=Ku;for(let e of t.startState.facet(Bu)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new _u(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Ku)}static selection(t){return new _u(void 0,Ku,void 0,void 0,t)}}function $u(t,e,i,n){let s=e+1>i+20?e-i-1:0,r=t.slice(s,e);return r.push(n),r}function ju(t,e){return t.length?e.length?t.concat(e):t:e}const Ku=[],Uu=200;function Yu(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Uu));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),$u(t,t.length-1,1e9,i.setSelAfter(n)))}return[_u.selection([e])]}function Gu(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function Xu(t,e){if(!t.length)return t;let i=t.length,n=Ku;for(;i;){let s=Ju(t[i-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let e=t.slice(0,i);return e[i-1]=s,e}e=s.mapped,i--,n=s.selectionsAfter}return n.length?[_u.selection(n)]:Ku}function Ju(t,e,i){let n=ju(t.selectionsAfter.length?t.selectionsAfter.map(t=>t.map(e)):Ku,i);if(!t.changes)return _u.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new _u(s,gt.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const Zu=/^(input\.type|delete)($|\.)/;class Qu{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Qu(this.done,this.undone):this}addChanges(t,e,i,n,s){let r=this.done,o=r[r.length-1];return r=o&&o.changes&&!o.changes.empty&&t.changes&&(!i||Zu.test(i))&&(!o.selectionsAfter.length&&e-this.prevTimei.push(t,e)),e.iterChangedRanges((t,e,s,r)=>{for(let t=0;t=e&&s<=o&&(n=!0)}}),n}(o.changes,t.changes))||"input.type.compose"==i)?$u(r,r.length-1,n.minDepth,new _u(t.changes.compose(o.changes),ju(gt.mapEffects(t.effects,o.changes),o.effects),o.mapped,o.startSelection,Ku)):$u(r,r.length,n.minDepth,t),new Qu(r,Ku,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Ku;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty).length)?this:new Qu(Yu(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new Qu(Xu(this.done,t),Xu(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=0==t?this.done:this.undone;if(0==n.length)return null;let s=n[n.length-1],r=s.selectionsAfter[0]||e.selection;if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Lu.of({side:t,rest:Gu(n),selection:r}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?Ku:n.slice(0,n.length-1);return s.mapped&&(i=Xu(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Lu.of({side:t,rest:i,selection:r}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Qu.empty=new Qu(Ku,Ku);const td=[{key:"Mod-z",run:Fu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:qu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:qu,preventDefault:!0},{key:"Mod-u",run:Vu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Wu,preventDefault:!0}];function ed(t,e){return z.create(t.ranges.map(e),t.mainIndex)}function id(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function nd({state:t,dispatch:e},i){let n=ed(t.selection,i);return!n.eq(t.selection,!0)&&(e(id(t,n)),!0)}function sd(t,e){return z.cursor(e?t.to:t.from)}function rd(t,e){return nd(t,i=>i.empty?t.moveByChar(i,e):sd(i,e))}function od(t){return t.textDirectionAt(t.state.selection.main.head)==ki.LTR}const ld=t=>rd(t,!od(t)),ad=t=>rd(t,od(t));function hd(t,e){return nd(t,i=>i.empty?t.moveByGroup(i,e):sd(i,e))}function cd(t,e,i){if(e.type.prop(i))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function ud(t,e,i){let n,s,r=Uh(t).resolveInner(e.head),o=i?qa.closedBy:qa.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;cd(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?su(t,r.from,1):su(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,z.cursor(s,i?-1:1)}function dd(t,e){return nd(t,i=>{if(!i.empty)return sd(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)})}const fd=t=>dd(t,!1),pd=t=>dd(t,!0);function md(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):sd(i,e));if(r.eq(s.selection))return!1;if(n.selfScroll){let e=t.coordsAtPos(s.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,a=o.bottom-n.marginBottom;e&&e.top>l&&e.bottomgd(t,!1),wd=t=>gd(t,!0);function bd(t,e,i){let n=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,i);if(s.head==e.head&&s.head!=(i?n.to:n.from)&&(s=t.moveToLineBoundary(e,i,!1)),!i&&s.head==n.from&&n.length){let i=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&e.head!=n.from+i&&(s=z.cursor(n.from+i))}return s}function yd(t,e){let i=ed(t.state.selection,t=>{let i=e(t);return z.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)});return!i.eq(t.state.selection)&&(t.dispatch(id(t.state,i)),!0)}function xd(t,e){return yd(t,i=>t.moveByChar(i,e))}const kd=t=>xd(t,!od(t)),Sd=t=>xd(t,od(t));function Cd(t,e){return yd(t,i=>t.moveByGroup(i,e))}function Md(t,e){return yd(t,i=>t.moveVertically(i,e))}const Ad=t=>Md(t,!1),Td=t=>Md(t,!0);function Dd(t,e){return yd(t,i=>t.moveVertically(i,e,md(t).height))}const Od=t=>Dd(t,!1),Rd=t=>Dd(t,!0),Ed=({state:t,dispatch:e})=>(e(id(t,{anchor:0})),!0),Pd=({state:t,dispatch:e})=>(e(id(t,{anchor:t.doc.length})),!0),Ld=({state:t,dispatch:e})=>(e(id(t,{anchor:t.selection.main.anchor,head:0})),!0),Id=({state:t,dispatch:e})=>(e(id(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Bd(t,e){let{state:i}=t,n=i.selection,s=i.selection.ranges.slice();for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head);if(e?r.to0)for(let i=n;;){let n=t.moveVertically(i,e);if(n.headr.to){s.some(t=>t.head==n.head)||s.push(n);break}if(n.head==i.head)break;i=n}}return s.length!=n.ranges.length&&(t.dispatch(id(i,z.create(s,s.length-1))),!0)}function Nd(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:n}=t,s=n.changeByRange(n=>{let{from:s,to:r}=n;if(s==r){let o=e(n);os&&(i="delete.forward",o=zd(t,o,!0)),s=Math.min(s,o),r=Math.max(r,o)}else s=zd(t,s,!1),r=zd(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:z.cursor(s,se(t)))n.between(e,e,(t,n)=>{te&&(e=i?n:t)});return e}const Hd=(t,e,i)=>Nd(t,n=>{let s,r,o=n.from,{state:l}=t,a=l.doc.lineAt(o);if(i&&!e&&o>a.from&&oHd(t,!1,!0),qd=t=>Hd(t,!0,!1),Vd=(t,e)=>Nd(t,i=>{let n=i.head,{state:s}=t,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let t=null;;){if(n==(e?r.to:r.from)){n==i.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=k(r.text,n-r.from,e)+r.from,a=r.text.slice(Math.min(n,l)-r.from,Math.max(n,l)-r.from),h=o(a);if(null!=t&&h!=t)break;" "==a&&n==i.head||(t=h),n=l}return n}),Wd=t=>Vd(t,!1);function _d(t){let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),r=t.doc.lineAt(n.to);if(n.empty||n.to!=r.from||(r=t.doc.lineAt(n.to-1)),i>=s.number){let t=e[e.length-1];t.to=r.to,t.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});i=r.number+1}return e}function $d(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of _d(t)){if(i?e.to==t.doc.length:0==e.from)continue;let r=t.doc.lineAt(i?e.to+1:e.from-1),o=r.length+1;if(i){n.push({from:e.to,to:r.to},{from:e.from,insert:r.text+t.lineBreak});for(let i of e.ranges)s.push(z.range(Math.min(t.doc.length,i.anchor+o),Math.min(t.doc.length,i.head+o)))}else{n.push({from:r.from,to:e.from},{from:e.to,insert:t.lineBreak+r.text});for(let t of e.ranges)s.push(z.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:z.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function jd(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of _d(t))i?n.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):n.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Kd=Ud(!1);function Ud(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:n,to:s}=i,r=e.doc.lineAt(n),o=!t&&n==s&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=Uh(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(qa.closedBy))&&i.indexOf(r.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(r.from).from&&!/\S/.test(t.sliceDoc(s.to,r.from))?{from:s.to,to:r.from}:null}(e,n);t&&(n=s=(s<=r.to?r:e.doc.lineAt(s)).to);let l=new ac(e,{simulateBreak:n,simulateDoubleBreak:!!o}),a=lc(l,n);for(null==a&&(a=Kt(/^\s*/.exec(e.doc.lineAt(n).text)[0],e.tabSize));sr.from&&n{let s=[];for(let r=n.from;r<=n.to;){let o=t.doc.lineAt(r);o.number>i&&(n.empty||n.to>o.from)&&(e(o,s,n),i=o.number),r=o.to+1}let r=t.changes(s);return{changes:s,range:z.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const Gd=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Yd(t,(e,i)=>{i.push({from:e.from,insert:t.facet(sc)})}),{userEvent:"input.indent"})),!0),Xd=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Yd(t,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Kt(n,t.tabSize),r=0,o=oc(t,Math.max(0,s-rc(t)));for(;rnd(t,e=>ud(t.state,e,!od(t))),shift:t=>yd(t,e=>ud(t.state,e,!od(t)))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>nd(t,e=>ud(t.state,e,od(t))),shift:t=>yd(t,e=>ud(t.state,e,od(t)))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>$d(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>jd(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>$d(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>jd(t,e,!0)},{key:"Mod-Alt-ArrowUp",run:t=>Bd(t,!1)},{key:"Mod-Alt-ArrowDown",run:t=>Bd(t,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=z.create([i.main]):i.main.empty||(n=z.create([z.cursor(i.main.head)])),!!n&&(e(id(t,n)),!0)}},{key:"Mod-Enter",run:Ud(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=_d(t).map(({from:e,to:i})=>z.range(e,Math.min(i+1,t.doc.length)));return e(t.update({selection:z.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=ed(t.selection,e=>{let i=Uh(t),n=i.resolveStack(e.from,1);if(e.empty){let t=i.resolveStack(e.from,-1);t.node.from>=n.node.from&&t.node.to<=n.node.to&&(n=t)}for(let t=n;t;t=t.next){let{node:i}=t;if((i.from=e.to||i.to>e.to&&i.from<=e.from)&&t.next)return z.range(i.to,i.from)}return e});return!i.eq(t.selection)&&(e(id(t,i)),!0)},preventDefault:!0},{key:"Mod-[",run:Xd},{key:"Mod-]",run:Gd},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new ac(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=Yd(t,(e,s,r)=>{let o=lc(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=oc(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(_d(e).map(({from:t,to:i})=>(t>0?t--:i{let i;if(t.lineWrapping){let n=t.lineBlockAt(e.head),s=t.coordsAtPos(e.head,e.assoc||1);s&&(i=n.bottom+t.documentTop-s.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)}).map(i);return t.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e){let i=!1,n=ed(t.selection,e=>{let n=su(t,e.head,-1)||su(t,e.head,1)||e.head>0&&su(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Ou(t.state,i.from);return n.line?Au(t):!!n.block&&Du(t)}},{key:"Alt-A",run:Tu},{key:"Ctrl-m",mac:"Shift-Alt-m",run:t=>(t.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:ld,shift:kd,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>hd(t,!od(t)),shift:t=>Cd(t,!od(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>nd(t,e=>bd(t,e,!od(t))),shift:t=>yd(t,e=>bd(t,e,!od(t))),preventDefault:!0},{key:"ArrowRight",run:ad,shift:Sd,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>hd(t,od(t)),shift:t=>Cd(t,od(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>nd(t,e=>bd(t,e,od(t))),shift:t=>yd(t,e=>bd(t,e,od(t))),preventDefault:!0},{key:"ArrowUp",run:fd,shift:Ad,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ed,shift:Ld},{mac:"Ctrl-ArrowUp",run:vd,shift:Od},{key:"ArrowDown",run:pd,shift:Td,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Pd,shift:Id},{mac:"Ctrl-ArrowDown",run:wd,shift:Rd},{key:"PageUp",run:vd,shift:Od},{key:"PageDown",run:wd,shift:Rd},{key:"Home",run:t=>nd(t,e=>bd(t,e,!1)),shift:t=>yd(t,e=>bd(t,e,!1)),preventDefault:!0},{key:"Mod-Home",run:Ed,shift:Ld},{key:"End",run:t=>nd(t,e=>bd(t,e,!0)),shift:t=>yd(t,e=>bd(t,e,!0)),preventDefault:!0},{key:"Mod-End",run:Pd,shift:Id},{key:"Enter",run:Kd,shift:Kd},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Fd,shift:Fd,preventDefault:!0},{key:"Delete",run:qd,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Wd,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Vd(t,!0),preventDefault:!0},{mac:"Mod-Backspace",run:t=>Nd(t,e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)}),preventDefault:!0},{mac:"Mod-Delete",run:t=>Nd(t,e=>{let i=t.moveToLineBoundary(e,!0).head;return e.headnd(t,e=>z.cursor(t.lineBlockAt(e.head).from,1)),shift:t=>yd(t,e=>z.cursor(t.lineBlockAt(e.head).from))},{key:"Ctrl-e",run:t=>nd(t,e=>z.cursor(t.lineBlockAt(e.head).to,-1)),shift:t=>yd(t,e=>z.cursor(t.lineBlockAt(e.head).to))},{key:"Ctrl-d",run:qd},{key:"Ctrl-h",run:Fd},{key:"Ctrl-k",run:t=>Nd(t,e=>{let i=t.lineBlockAt(e.head).to;return e.head{if(t.readOnly)return!1;let i=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:d.of(["",""])},range:z.cursor(t.from)}));return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,n=t.doc.lineAt(i),s=i==n.from?i-1:k(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:k(n.text,i-n.from,!0)+n.from;return{changes:{from:s,to:r,insert:t.doc.slice(i,r).append(t.doc.slice(s,i))},range:z.cursor(r)}});return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:wd}].map(t=>({mac:t.key,run:t.run,shift:t.shift})))),Zd={key:"Tab",run:Gd,shift:Xd};class Qd{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=Uh(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),s=n.search(rf(t,!1));return s<0?null:{from:i+s,to:this.pos,text:n.slice(s)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,i){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function tf(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function ef(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[i,n]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:n}of t){e[n[0]]=!0;for(let t=1;t{let s=t.matchBefore(n);return s||t.explicit?{from:s?s.from:t.pos,options:e,validFor:i}:null}}class nf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function sf(t){return t.selection.main.from}function rf(t,e){var i;let{source:n}=t,s=e&&"^"!=n[0],r="$"!=n[n.length-1];return s||r?new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const of=ft.define();function lf(t,e,i,n){let{main:s}=t.selection,r=i-s.from,o=n-s.from;return{...t.changeByRange(l=>{if(l!=s&&i!=n&&t.sliceDoc(l.from+r,l.from+o)!=t.sliceDoc(i,n))return{range:l};let a=t.toText(e);return{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:a},range:z.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const af=new WeakMap;function hf(t){if(!Array.isArray(t))return t;let e=af.get(t);return e||af.set(t,e=ef(t)),e}const cf=gt.define(),uf=gt.define();class df{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&a<=57||a>=97&&a<=122?2:a>=65&&a<=90?1:0:(w=C(a))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!n||1==b&&m||0==v&&0!=b)&&(e[c]==a||i[c]==a&&(u=!0)?r[c++]=n:r.length&&(g=!1)),v=b,n+=M(a)}return c==l&&0==r[0]&&g?this.result((u?-200:0)-100,r,t):d==l&&0==f?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):o>-1?this.ret(-700-t.length,[o,o+this.pattern.length]):d==l?this.ret(-900-t.length,[f,p]):c==l?this.result((u?-200:0)-100-700+(g?0:-1100),r,t):2==e.length?null:this.result((n[0]?-700:0)-200-1100,n,t)}result(t,e,i){let n=[],s=0;for(let t of e){let e=t+(this.astral?M(S(i,t)):1);s&&n[s-1]==t?n[s-1]=e:(n[s++]=t,n[s++]=e)}return this.ret(t-i.length,n)}}class ff{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.lengthOt(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:gf,filterStrict:!1,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>mf(t(i),e(i)),optionClass:(t,e)=>i=>mf(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function mf(t,e){return t?e?t+" "+e:t:e}function gf(t,e,i,n,s,r){let o,l,a=t.textDirection==ki.RTL,h=a,c=!1,u="top",d=e.left-s.left,f=s.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(h&&d=m||t>e.top?o=i.bottom-e.top:(u="bottom",o=e.bottom-i.top)}return{style:`${u}: ${o/((e.bottom-e.top)/r.offsetHeight)}px; max-width: ${l/((e.right-e.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(c?a?"left-narrow":"right-narrow":h?"left":"right")}}function vf(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let n=Math.floor((t-e)/i);return{from:t-(n+1)*i,to:t-n*i}}class wf{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:s,selected:r}=n.open,o=t.state.facet(pf);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map(t=>"cm-completionIcon-"+t)),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i,n){let s=document.createElement("span");s.className="cm-completionLabel";let r=t.displayLabel||t.label,o=0;for(let t=0;to&&s.appendChild(document.createTextNode(r.slice(o,e)));let l=s.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(r.slice(e,i))),l.className="cm-completionMatchedText",o=i}return ot.position-e.position).map(t=>t.render)}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=vf(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=t.state.field(e).open;for(let e,s=i.target;s&&s!=this.dom;s=s.parentNode)if("LI"==s.nodeName&&(e=/-(\d+)$/.exec(s.id))&&+e[1]{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(pf).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:uf.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:s,selected:r,disabled:o}=i.open;n.open&&n.open.options==s||(this.range=vf(s.length,r,t.state.facet(pf).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),o!=(null===(e=n.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected=this.range.to)&&(this.range=vf(e.options.length,e.selected,this.view.state.facet(pf).maxRenderedOptions),this.showOptions(e.options,t.id));let i=this.updateSelectedOption(e.selected);if(i){this.destroyInfo();let{completion:n}=e.options[e.selected],{info:s}=n;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(n);if(!r)return;"then"in r?r.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,n)}).catch(t=>nn(this.view.state,t,"completion info")):(this.addInfoPane(r,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:n}=t;i.appendChild(e),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby")):n--;return e&&function(t,e){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=i.height/t.offsetHeight;n.topi.bottom&&(t.scrollTop+=(n.bottom-i.bottom)/s)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),s=this.space;if(!s){let t=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottom{t.target==n&&t.preventDefault()});let s=null;for(let r=i.from;ri.from||0==i.from))if(s=t,"string"!=typeof a&&a.header)n.appendChild(a.header(a));else{n.appendChild(document.createElement("completion-section")).textContent=t}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+r,h.setAttribute("role","option");let c=this.optionClass(o);c&&(h.className=c);for(let t of this.optionContent){let e=t(o,this.view.state,this.view,l);e&&h.appendChild(e)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew wf(i,t,e)}function yf(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class xf{constructor(t,e,i,n,s,r){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=s,this.disabled=r}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new xf(this.options,Mf(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,s,r){if(n&&!r&&t.some(t=>t.isPending))return n.setDisabled();let o=function(t,e){let i=[],n=null,s=null,r=t=>{i.push(t);let{section:e}=t.completion;if(e){n||(n=[]);let t="string"==typeof e?e:e.name;n.some(e=>e.name==t)||n.push("string"==typeof e?{name:t}:e)}},o=e.facet(pf);for(let n of t)if(n.hasResult()){let t=n.result.getMatch;if(!1===n.result.filter)for(let e of n.result.options)r(new nf(e,n.source,t?t(e):[],1e9-i.length));else{let i,l=e.sliceDoc(n.from,n.to),a=o.filterStrict?new ff(l):new df(l);for(let e of n.result.options)if(i=a.match(e.label)){let o=e.displayLabel?t?t(e,i.matched):[]:i.matched,l=i.score+(e.boost||0);if(r(new nf(e,n.source,o,l)),"object"==typeof e.section&&"dynamic"===e.section.rank){let{name:t}=e.section;s||(s=Object.create(null)),s[t]=Math.max(l,s[t]||-1e9)}}}}if(n){let t=Object.create(null),e=0,r=(t,e)=>("dynamic"===t.rank&&"dynamic"===e.rank?s[e.name]-s[t.name]:0)||("number"==typeof t.rank?t.rank:1e9)-("number"==typeof e.rank?e.rank:1e9)||(t.namee.score-t.score||h(t.completion,e.completion))){let e=t.completion;!a||a.label!=e.label||a.detail!=e.detail||null!=a.type&&null!=e.type&&a.type!=e.type||a.apply!=e.apply||a.boost!=e.boost?l.push(t):yf(t.completion)>yf(a)&&(l[l.length-1]=t),a=t.completion}return l}(t,e);if(!o.length)return n&&t.some(t=>t.isPending)?n.setDisabled():null;let l=e.facet(pf).selectOnOpen?0:-1;if(n&&n.selected!=l&&-1!=n.selected){let t=n.options[n.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t,1e8),create:If,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new xf(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new xf(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class kf{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new kf(Af,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(pf),n=(i.override||e.languageDataAt("autocomplete",sf(e)).map(hf)).map(e=>(this.active.find(t=>t.source==e)||new Df(e,this.active.some(t=>0!=t.state)?1:0)).update(t,i));n.length==this.active.length&&n.every((t,e)=>t==this.active[e])&&(n=this.active);let s=this.open,r=t.effects.some(t=>t.is(Rf));s&&t.docChanged&&(s=s.map(t.changes)),t.selection||n.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let i=0,n=0;;){for(;it.isPending)&&(s=null),!s&&n.every(t=>!t.isPending)&&n.some(t=>t.hasResult())&&(n=n.map(t=>t.hasResult()?new Df(t.source,0):t));for(let e of t.effects)e.is(Ef)&&(s=s&&s.setSelected(e.value,this.id));return n==this.active&&s==this.open?this:new kf(n,this.id,s)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Sf:Cf}}const Sf={"aria-autocomplete":"list"},Cf={};function Mf(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const Af=[];function Tf(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(of);if(i&&e.activateOnCompletion(i))return 12}let i=t.isUserEvent("input.type");return i&&e.activateOnTyping?5:i?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class Df{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let i=Tf(t,e),n=this;(8&i||16&i&&this.touches(t))&&(n=new Df(n.source,0)),4&i&&0==n.state&&(n=new Df(this.source,1)),n=n.updateFor(t,i);for(let e of t.effects)if(e.is(cf))n=new Df(n.source,1,e.value);else if(e.is(uf))n=new Df(n.source,0);else if(e.is(Rf))for(let t of e.value)t.source==n.source&&(n=t);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(sf(t.state))}}class Of extends Df{constructor(t,e,i,n,s,r){super(t,3,e),this.limit=i,this.result=n,this.from=s,this.to=r}hasResult(){return!0}updateFor(t,e){var i;if(!(3&e))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let s=t.changes.mapPos(this.from),r=t.changes.mapPos(this.to,1),o=sf(t.state);if(o>r||!n||2&e&&(sf(t.startState)==this.from||ot.map(t=>t.map(e))}),Ef=gt.define(),Pf=U.define({create:()=>kf.start(),update:(t,e)=>t.update(e),provide:t=>[so.from(t,t=>t.tooltip),cr.contentAttributes.from(t,t=>t.attrs)]});function Lf(t,e){const i=e.completion.apply||e.completion.label;let n=t.state.field(Pf).active.find(t=>t.source==e.source);return n instanceof Of&&("string"==typeof i?t.dispatch({...lf(t.state,i,n.from,n.to),annotations:of.of(e.completion)}):i(t,e.completion,n.from,n.to),!0)}const If=bf(Pf,Lf);function Bf(t,e="option"){return i=>{let n=i.state.field(Pf,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+r*(t?1:-1):t?0:o-1;return l<0?l="page"==e?0:o-1:l>=o&&(l="page"==e?o-1:0),i.dispatch({effects:Ef.of(l)}),!0}}const Nf=t=>!!t.state.field(Pf,!1)&&(t.dispatch({effects:cf.of(!0)}),!0);class zf{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Hf=ln.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Pf).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Pf),i=t.state.facet(pf);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Pf)==e)return;let n=t.transactions.some(t=>{let e=Tf(t,i);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){nn(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(cf)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Pf);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(pf).updateSyncTime))}startQuery(t){let{state:e}=this.view,i=sf(e),n=new Qd(e,i,t.explicit,this.view),s=new zf(t,n);this.running.push(s),Promise.resolve(t.source(n)).then(t=>{s.context.aborted||(s.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:uf.of(null)}),nn(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(pf).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(pf),n=this.view.state.field(Pf);for(let s=0;st.source==r.active.source);if(o&&o.isPending)if(null==r.done){let t=new Df(r.active.source,0);for(let e of r.updates)t=t.update(e,i);t.isPending||e.push(t)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:Rf.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Pf,!1);if(e&&e.tooltip&&this.view.state.facet(pf).closeOnBlur){let i=e.open&&uo(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:uf.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:cf.of(!1)}),20),this.composing=0}}}),Ff="object"==typeof navigator&&/Win/.test(navigator.platform),qf=Q.highest(cr.domEventHandlers({keydown(t,e){let i=e.state.field(Pf,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!Ff||!t.altKey)||t.metaKey)return!1;let n=i.open.options[i.open.selected],s=i.active.find(t=>t.source==n.source),r=n.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(t.key)>-1&&Lf(e,n),!1}})),Vf=cr.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 Wf{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class _f{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,T.TrackDel),i=t.mapPos(this.to,1,T.TrackDel);return null==e||null==i?null:new _f(this.field,e,i)}}class $f{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],s=t.doc.lineAt(e),r=/^\s*/.exec(s.text)[0];for(let s of this.lines){if(i.length){let i=r,o=/^\t*/.exec(s)[0].length;for(let e=0;enew _f(t.field,n[t.line]+t.from,n[t.line]+t.to));return{text:i,ranges:o}}static parse(t){let e,i=[],n=[],s=[];for(let r of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(r);){let t=e[1]?+e[1]:null,o=e[2]||e[3]||"",l=-1,a=o.replace(/\\[{}]/g,t=>t[1]);for(let e=0;e=l&&t.field++}for(let t of s)if(t.line==n.length&&t.from>e.index){let i=e[2]?3+(e[1]||"").length:2;t.from-=i,t.to-=i}s.push(new Wf(l,n.length,e.index,e.index+a.length)),r=r.slice(0,e.index)+o+r.slice(e.index+e[0].length)}r=r.replace(/\\([{}])/g,(t,e,i)=>{for(let t of s)t.line==n.length&&t.from>i&&(t.from--,t.to--);return e}),n.push(r)}return new $f(n,s)}}let jf=ci.widget({widget:new class extends ai{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Kf=ci.mark({class:"cm-snippetField"});class Uf{constructor(t,e){this.ranges=t,this.active=e,this.deco=ci.set(t.map(t=>(t.from==t.to?jf:Kf).range(t.from,t.to)),!0)}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new Uf(e,this.active)}selectionInsideField(t){return t.ranges.every(t=>this.ranges.some(e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))}}const Yf=gt.define({map:(t,e)=>t&&t.map(e)}),Gf=gt.define(),Xf=U.define({create:()=>null,update(t,e){for(let i of e.effects){if(i.is(Yf))return i.value;if(i.is(Gf)&&t)return new Uf(t.ranges,i.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>cr.decorations.from(t,t=>t?t.deco:ci.none)});function Jf(t,e){return z.create(t.filter(t=>t.field==e).map(t=>z.range(t.from,t.to)))}function Zf(t){return({state:e,dispatch:i})=>{let n=e.field(Xf,!1);if(!n||t<0&&0==n.active)return!1;let s=n.active+t,r=t>0&&!n.ranges.some(e=>e.field==s+t);return i(e.update({selection:Jf(n.ranges,s),effects:Yf.of(r?null:new Uf(n.ranges,s)),scrollIntoView:!0})),!0}}const Qf=[{key:"Tab",run:Zf(1),shift:Zf(-1)},{key:"Escape",run:({state:t,dispatch:e})=>!!t.field(Xf,!1)&&(e(t.update({effects:Yf.of(null)})),!0)}],tp=q.define({combine:t=>t.length?t[0]:Qf}),ep=Q.highest(wr.compute([tp],t=>t.facet(tp))),ip=cr.domEventHandlers({mousedown(t,e){let i,n=e.state.field(Xf,!1);if(!n||null==(i=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let s=n.ranges.find(t=>t.from<=i&&t.to>=i);return!(!s||s.field==n.active)&&(e.dispatch({selection:Jf(n.ranges,s.field),effects:Yf.of(n.ranges.some(t=>t.field>s.field)?new Uf(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),np={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},sp=gt.define({map(t,e){let i=e.mapPos(t,-1,T.TrackAfter);return null==i?void 0:i}}),rp=new class extends Rt{};rp.startSide=1,rp.endSide=-1;const op=U.define({create:()=>It.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(sp)&&(t=t.update({add:[rp.range(i.value,i.value+1)]}));return t}});const lp="()[]{}<>«»»«[]{}";function ap(t){for(let e=0;e<16;e+=2)if(lp.charCodeAt(e)==t)return lp.charAt(e+1);return C(t<128?t:t+1)}function hp(t,e){return t.languageDataAt("closeBrackets",e)[0]||np}const cp="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),up=cr.inputHandler.of((t,e,i,n)=>{if((cp?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(n.length>2||2==n.length&&1==M(S(n,0))||e!=s.from||i!=s.to)return!1;let r=function(t,e){let i=hp(t,t.selection.main.head),n=i.brackets||np.brackets;for(let s of n){let r=ap(S(s,0));if(e==s)return r==s?vp(t,s,n.indexOf(s+s+s)>-1,i):mp(t,s,r,i.before||np.before);if(e==r&&fp(t,t.selection.main.from))return gp(t,s,r)}return null}(t.state,n);return!!r&&(t.dispatch(r),!0)}),dp=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=hp(t,t.selection.main.head).brackets||np.brackets,n=null,s=t.changeByRange(e=>{if(e.empty){let n=function(t,e){let i=t.sliceString(e-2,e);return M(S(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let s of i)if(s==n&&pp(t.doc,e.head)==ap(S(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:z.cursor(e.head-s.length)}}return{range:n=e}});return n||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!n}}];function fp(t,e){let i=!1;return t.field(op).between(0,t.doc.length,t=>{t==e&&(i=!0)}),i}function pp(t,e){let i=t.sliceString(e,e+2);return i.slice(0,M(S(i,0)))}function mp(t,e,i,n){let s=null,r=t.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:i,from:r.to}],effects:sp.of(r.to+e.length),range:z.range(r.anchor+e.length,r.head+e.length)};let o=pp(t.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+i,from:r.head},effects:sp.of(r.head+e.length),range:z.cursor(r.head+e.length)}:{range:s=r}});return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function gp(t,e,i){let n=null,s=t.changeByRange(e=>e.empty&&pp(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:z.cursor(e.head+i.length)}:n={range:e});return n?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function vp(t,e,i,n){let s=n.stringPrefixes||np.stringPrefixes,r=null,o=t.changeByRange(n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:e,from:n.to}],effects:sp.of(n.to+e.length),range:z.range(n.anchor+e.length,n.head+e.length)};let o,l=n.head,a=pp(t.doc,l);if(a==e){if(wp(t,l))return{changes:{insert:e+e,from:l},effects:sp.of(l+e.length),range:z.cursor(l+e.length)};if(fp(t,l)){let n=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+n.length,insert:n},range:z.cursor(l+n.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(o=bp(t,l-2*e.length,s))>-1&&wp(t,o))return{changes:{insert:e+e+e+e,from:l},effects:sp.of(l+e.length),range:z.cursor(l+e.length)};if(t.charCategorizer(l)(a)!=Ct.Word&&bp(t,l,s)>-1&&!function(t,e,i,n){let s=Uh(t).resolveInner(e,-1),r=n.reduce((t,e)=>Math.max(t,e.length),0);for(let o=0;o<5;o++){let o=t.sliceDoc(s.from,Math.min(s.to,s.from+i.length+r)),l=o.indexOf(i);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let e=s.firstChild;for(;e&&e.from==s.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let a=s.to==e&&s.parent;if(!a)break;s=a}return!1}(t,l,e,s))return{changes:{insert:e+e,from:l},effects:sp.of(l+e.length),range:z.cursor(l+e.length)}}return{range:r=n}});return r?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function wp(t,e){let i=Uh(t).resolveInner(e+1);return i.parent&&i.from==e}function bp(t,e,i){let n=t.charCategorizer(e);if(n(t.sliceDoc(e-1,e))!=Ct.Word)return e;for(let s of i){let i=e-s.length;if(t.sliceDoc(i,e)==s&&n(t.sliceDoc(i-1,i))!=Ct.Word)return i}return-1}function yp(t={}){return[qf,Pf,pf.of(t),Hf,kp,Vf]}const xp=[{key:"Ctrl-Space",run:Nf},{mac:"Alt-`",run:Nf},{mac:"Alt-i",run:Nf},{key:"Escape",run:t=>{let e=t.state.field(Pf,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:uf.of(null)}),!0)}},{key:"ArrowDown",run:Bf(!0)},{key:"ArrowUp",run:Bf(!1)},{key:"PageDown",run:Bf(!0,"page")},{key:"PageUp",run:Bf(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Pf,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampt.facet(pf).defaultKeymap?[xp]:[]));function Sp(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Cp={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function Mp(t){Cp=t}var Ap={exec:()=>null};function Tp(t,e=""){let i="string"==typeof t?t:t.source;const n={replace:(t,e)=>{let s="string"==typeof e?e:e.source;return s=s.replace(Dp.caret,"$1"),i=i.replace(t,s),n},getRegex:()=>new RegExp(i,e)};return n}var Dp={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Op=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Rp=/(?:[*+-]|\d{1,9}[.)])/,Ep=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Pp=Tp(Ep).replace(/bull/g,Rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Lp=Tp(Ep).replace(/bull/g,Rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Ip=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Bp=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Np=Tp(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Bp).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),zp=Tp(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Rp).getRegex(),Hp="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Fp=/|$))/,qp=Tp("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",Fp).replace("tag",Hp).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Vp=Tp(Ip).replace("hr",Op).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Hp).getRegex(),Wp={blockquote:Tp(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Vp).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:Np,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:Op,html:qp,lheading:Pp,list:zp,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:Vp,table:Ap,text:/^[^\n]+/},_p=Tp("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Op).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Hp).getRegex(),$p={...Wp,lheading:Lp,table:_p,paragraph:Tp(Ip).replace("hr",Op).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",_p).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Hp).getRegex()},jp={...Wp,html:Tp("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",Fp).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Ap,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Tp(Ip).replace("hr",Op).replace("heading"," *#{1,6} *[^\n]").replace("lheading",Pp).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Kp=/^( {2,}|\\)\n(?!\s*$)/,Up=/[\p{P}\p{S}]/u,Yp=/[\s\p{P}\p{S}]/u,Gp=/[^\s\p{P}\p{S}]/u,Xp=Tp(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Yp).getRegex(),Jp=/(?!~)[\p{P}\p{S}]/u,Zp=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Qp=Tp(Zp,"u").replace(/punct/g,Up).getRegex(),tm=Tp(Zp,"u").replace(/punct/g,Jp).getRegex(),em="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",im=Tp(em,"gu").replace(/notPunctSpace/g,Gp).replace(/punctSpace/g,Yp).replace(/punct/g,Up).getRegex(),nm=Tp(em,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,Jp).getRegex(),sm=Tp("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Gp).replace(/punctSpace/g,Yp).replace(/punct/g,Up).getRegex(),rm=Tp(/\\(punct)/,"gu").replace(/punct/g,Up).getRegex(),om=Tp(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),lm=Tp(Fp).replace("(?:--\x3e|$)","--\x3e").getRegex(),am=Tp("^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^").replace("comment",lm).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),hm=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,cm=Tp(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",hm).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),um=Tp(/^!?\[(label)\]\[(ref)\]/).replace("label",hm).replace("ref",Bp).getRegex(),dm=Tp(/^!?\[(ref)\](?:\[\])?/).replace("ref",Bp).getRegex(),fm={_backpedal:Ap,anyPunctuation:rm,autolink:om,blockSkip:/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,br:Kp,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:Ap,emStrongLDelim:Qp,emStrongRDelimAst:im,emStrongRDelimUnd:sm,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:cm,nolink:dm,punctuation:Xp,reflink:um,reflinkSearch:Tp("reflink|nolink(?!\\()","g").replace("reflink",um).replace("nolink",dm).getRegex(),tag:am,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\":">",'"':""","'":"'"},ym=t=>bm[t];function xm(t,e){if(e){if(Dp.escapeTest.test(t))return t.replace(Dp.escapeReplace,ym)}else if(Dp.escapeTestNoEncode.test(t))return t.replace(Dp.escapeReplaceNoEncode,ym);return t}function km(t){try{t=encodeURI(t).replace(Dp.percentDecode,"%")}catch{return null}return t}function Sm(t,e){const i=t.replace(Dp.findPipe,(t,e,i)=>{let n=!1,s=e;for(;--s>=0&&"\\"===i[s];)n=!n;return n?"|":" |"}).split(Dp.splitPipe);let n=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const t=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:Cm(t,"\n")}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const t=e[0],i=function(t,e,i){const n=t.match(i.other.indentCodeCompensation);if(null===n)return e;const s=n[1];return e.split("\n").map(t=>{const e=t.match(i.other.beginningSpace);if(null===e)return t;const[n]=e;return n.length>=s.length?t.slice(s.length):t}).join("\n")}(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:i}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){const e=Cm(t,"#");this.options.pedantic?t=e.trim():e&&!this.rules.other.endingSpaceChar.test(e)||(t=e.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Cm(e[0],"\n")}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let t=Cm(e[0],"\n").split("\n"),i="",n="";const s=[];for(;t.length>0;){let e=!1;const r=[];let o;for(o=0;o1,s={type:"list",raw:"",ordered:n,start:n?+i.slice(0,-1):"",loose:!1,items:[]};i=n?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=n?i:"[*+-]");const r=this.rules.other.listItemRegex(i);let o=!1;for(;t;){let i=!1,n="",l="";if(!(e=r.exec(t)))break;if(this.rules.block.hr.test(t))break;n=e[0],t=t.substring(n.length);let a=e[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,t=>" ".repeat(3*t.length)),h=t.split("\n",1)[0],c=!a.trim(),u=0;if(this.options.pedantic?(u=2,l=a.trimStart()):c?u=e[1].length+1:(u=e[2].search(this.rules.other.nonSpaceChar),u=u>4?1:u,l=a.slice(u),u+=e[1].length),c&&this.rules.other.blankLine.test(h)&&(n+=h+"\n",t=t.substring(h.length+1),i=!0),!i){const e=this.rules.other.nextBulletRegex(u),i=this.rules.other.hrRegex(u),s=this.rules.other.fencesBeginRegex(u),r=this.rules.other.headingBeginRegex(u),o=this.rules.other.htmlBeginRegex(u);for(;t;){const d=t.split("\n",1)[0];let f;if(h=d,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),f=h):f=h.replace(this.rules.other.tabCharGlobal," "),s.test(h))break;if(r.test(h))break;if(o.test(h))break;if(e.test(h))break;if(i.test(h))break;if(f.search(this.rules.other.nonSpaceChar)>=u||!h.trim())l+="\n"+f.slice(u);else{if(c)break;if(a.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4)break;if(s.test(a))break;if(r.test(a))break;if(i.test(a))break;l+="\n"+h}c||h.trim()||(c=!0),n+=d+"\n",t=t.substring(d.length+1),a=f.slice(u)}}s.loose||(o?s.loose=!0:this.rules.other.doubleBlankLine.test(n)&&(o=!0));let d,f=null;this.options.gfm&&(f=this.rules.other.listIsTask.exec(l),f&&(d="[ ] "!==f[0],l=l.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:n,task:!!f,checked:d,loose:!1,text:l,tokens:[]}),s.raw+=n}const l=s.items.at(-1);if(!l)return;l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd(),s.raw=s.raw.trimEnd();for(let t=0;t"space"===t.type),i=e.length>0&&e.some(t=>this.rules.other.anyLine.test(t.raw));s.loose=i}if(s.loose)for(let t=0;t({text:t,tokens:this.lexer.inline(t),header:!1,align:r.align[e]})));return r}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:"="===e[2].charAt(0)?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const t="\n"===e[1].charAt(e[1].length-1)?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;const e=Cm(t.slice(0,-1),"\\");if((t.length-e.length)%2==0)return}else{const t=function(t,e){if(-1===t.indexOf(e[1]))return-1;let i=0;for(let n=0;n0?-2:-1}(e[2],"()");if(-2===t)return;if(t>-1){const i=(0===e[0].indexOf("!")?5:4)+e[1].length+t;e[2]=e[2].substring(0,t),e[0]=e[0].substring(0,i).trim(),e[3]=""}}let i=e[2],n="";if(this.options.pedantic){const t=this.rules.other.pedanticHrefTitle.exec(i);t&&(i=t[1],n=t[3])}else n=e[3]?e[3].slice(1,-1):"";return i=i.trim(),this.rules.other.startAngleBracket.test(i)&&(i=this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?i.slice(1):i.slice(1,-1)),Mm(e,{href:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i,title:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n},e[0],this.lexer,this.rules)}}reflink(t,e){let i;if((i=this.rules.inline.reflink.exec(t))||(i=this.rules.inline.nolink.exec(t))){const t=e[(i[2]||i[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!t){const t=i[0].charAt(0);return{type:"text",raw:t,text:t}}return Mm(i,t,i[0],this.lexer,this.rules)}}emStrong(t,e,i=""){let n=this.rules.inline.emStrongLDelim.exec(t);if(!n)return;if(n[3]&&i.match(this.rules.other.unicodeAlphaNumeric))return;if(!(n[1]||n[2]||"")||!i||this.rules.inline.punctuation.exec(i)){const i=[...n[0]].length-1;let s,r,o=i,l=0;const a="*"===n[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,e=e.slice(-1*t.length+i);null!=(n=a.exec(e));){if(s=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!s)continue;if(r=[...s].length,n[3]||n[4]){o+=r;continue}if((n[5]||n[6])&&i%3&&!((i+r)%3)){l+=r;continue}if(o-=r,o>0)continue;r=Math.min(r,r+o+l);const e=[...n[0]][0].length,a=t.slice(0,i+n.index+e+r);if(Math.min(i,r)%2){const t=a.slice(1,-1);return{type:"em",raw:a,text:t,tokens:this.lexer.inlineTokens(t)}}const h=a.slice(2,-2);return{type:"strong",raw:a,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," ");const i=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return i&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let t,i;return"@"===e[2]?(t=e[1],i="mailto:"+t):(t=e[1],i=t),{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let t,i;if("@"===e[2])t=e[0],i="mailto:"+t;else{let n;do{n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??""}while(n!==e[0]);t=e[0],i="www."===e[1]?"http://"+e[0]:e[0]}return{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},Tm=class t{tokens;options;state;tokenizer;inlineQueue;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Cp,this.options.tokenizer=this.options.tokenizer||new Am,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={other:Dp,block:vm.normal,inline:wm.normal};this.options.pedantic?(e.block=vm.pedantic,e.inline=wm.pedantic):this.options.gfm&&(e.block=vm.gfm,this.options.breaks?e.inline=wm.breaks:e.inline=wm.gfm),this.tokenizer.rules=e}static get rules(){return{block:vm,inline:wm}}static lex(e,i){return new t(i).lex(e)}static lexInline(e,i){return new t(i).inlineTokens(e)}lex(t){t=t.replace(Dp.carriageReturn,"\n"),this.blockTokens(t,this.tokens);for(let t=0;t!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.space(t)){t=t.substring(n.raw.length);const i=e.at(-1);1===n.raw.length&&void 0!==i?i.raw+="\n":e.push(n);continue}if(n=this.tokenizer.code(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(n=this.tokenizer.fences(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.heading(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.hr(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.blockquote(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.list(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.html(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.def(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.lheading(t)){t=t.substring(n.raw.length),e.push(n);continue}let s=t;if(this.options.extensions?.startBlock){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startBlock.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(s=t.substring(0,e+1))}if(this.state.top&&(n=this.tokenizer.paragraph(s))){const r=e.at(-1);i&&"paragraph"===r?.type?(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):e.push(n),i=s.length!==t.length,t=t.substring(n.raw.length);continue}if(n=this.tokenizer.text(t)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return this.state.top=!0,e}inline(t,e=[]){return this.inlineQueue.push({src:t,tokens:e}),e}inlineTokens(t,e=[]){let i=t,n=null;if(this.tokens.links){const t=Object.keys(this.tokens.links);if(t.length>0)for(;null!=(n=this.tokenizer.rules.inline.reflinkSearch.exec(i));)t.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(n=this.tokenizer.rules.inline.anyPunctuation.exec(i));)i=i.slice(0,n.index)+"++"+i.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(n=this.tokenizer.rules.inline.blockSkip.exec(i));)i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let s=!1,r="";for(;t;){let n;if(s||(r=""),s=!1,this.options.extensions?.inline?.some(i=>!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.escape(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.tag(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.link(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===n.type&&"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(n=this.tokenizer.emStrong(t,i,r)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.codespan(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.br(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.del(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.autolink(t)){t=t.substring(n.raw.length),e.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(t))){t=t.substring(n.raw.length),e.push(n);continue}let o=t;if(this.options.extensions?.startInline){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startInline.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(o=t.substring(0,e+1))}if(n=this.tokenizer.inlineText(o)){t=t.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(r=n.raw.slice(-1)),s=!0;const i=e.at(-1);"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return e}},Dm=class{options;parser;constructor(t){this.options=t||Cp}space(t){return""}code({text:t,lang:e,escaped:i}){const n=(e||"").match(Dp.notSpaceStart)?.[0],s=t.replace(Dp.endingNewline,"")+"\n";return n?'
'+(i?s:xm(s,!0))+"
\n":"
"+(i?s:xm(s,!0))+"
\n"}blockquote({tokens:t}){return`
\n${this.parser.parse(t)}
\n`}html({text:t}){return t}heading({tokens:t,depth:e}){return`${this.parser.parseInline(t)}\n`}hr(t){return"
\n"}list(t){const e=t.ordered,i=t.start;let n="";for(let e=0;e\n"+n+"\n"}listitem(t){let e="";if(t.task){const i=this.checkbox({checked:!!t.checked});t.loose?"paragraph"===t.tokens[0]?.type?(t.tokens[0].text=i+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&"text"===t.tokens[0].tokens[0].type&&(t.tokens[0].tokens[0].text=i+" "+xm(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:i+" ",text:i+" ",escaped:!0}):e+=i+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`
  • ${e}
  • \n`}checkbox({checked:t}){return"'}paragraph({tokens:t}){return`

    ${this.parser.parseInline(t)}

    \n`}table(t){let e="",i="";for(let e=0;e${n}`),"\n\n"+e+"\n"+n+"
    \n"}tablerow({text:t}){return`\n${t}\n`}tablecell(t){const e=this.parser.parseInline(t.tokens),i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`\n`}strong({tokens:t}){return`${this.parser.parseInline(t)}`}em({tokens:t}){return`${this.parser.parseInline(t)}`}codespan({text:t}){return`${xm(t,!0)}`}br(t){return"
    "}del({tokens:t}){return`${this.parser.parseInline(t)}`}link({href:t,title:e,tokens:i}){const n=this.parser.parseInline(i),s=km(t);if(null===s)return n;let r='
    ",r}image({href:t,title:e,text:i,tokens:n}){n&&(i=this.parser.parseInline(n,this.parser.textRenderer));const s=km(t);if(null===s)return xm(i);let r=`${i}{const s=t[n].flat(1/0);i=i.concat(this.walkTokens(s,e))}):t.tokens&&(i=i.concat(this.walkTokens(t.tokens,e)))}}return i}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(t=>{const i={...t};if(i.async=this.defaults.async||i.async||!1,t.extensions&&(t.extensions.forEach(t=>{if(!t.name)throw new Error("extension name required");if("renderer"in t){const i=e.renderers[t.name];e.renderers[t.name]=i?function(...e){let n=t.renderer.apply(this,e);return!1===n&&(n=i.apply(this,e)),n}:t.renderer}if("tokenizer"in t){if(!t.level||"block"!==t.level&&"inline"!==t.level)throw new Error("extension level must be 'block' or 'inline'");const i=e[t.level];i?i.unshift(t.tokenizer):e[t.level]=[t.tokenizer],t.start&&("block"===t.level?e.startBlock?e.startBlock.push(t.start):e.startBlock=[t.start]:"inline"===t.level&&(e.startInline?e.startInline.push(t.start):e.startInline=[t.start]))}"childTokens"in t&&t.childTokens&&(e.childTokens[t.name]=t.childTokens)}),i.extensions=e),t.renderer){const e=this.defaults.renderer||new Dm(this.defaults);for(const i in t.renderer){if(!(i in e))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const n=i,s=t.renderer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i||""}}i.renderer=e}if(t.tokenizer){const e=this.defaults.tokenizer||new Am(this.defaults);for(const i in t.tokenizer){if(!(i in e))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const n=i,s=t.tokenizer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.tokenizer=e}if(t.hooks){const e=this.defaults.hooks||new Em;for(const i in t.hooks){if(!(i in e))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const n=i,s=t.hooks[n],r=e[n];Em.passThroughHooks.has(i)?e[n]=t=>{if(this.defaults.async)return Promise.resolve(s.call(e,t)).then(t=>r.call(e,t));const i=s.call(e,t);return r.call(e,i)}:e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.hooks=e}if(t.walkTokens){const e=this.defaults.walkTokens,n=t.walkTokens;i.walkTokens=function(t){let i=[];return i.push(n.call(this,t)),e&&(i=i.concat(e.call(this,t))),i}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Tm.lex(t,e??this.defaults)}parser(t,e){return Rm.parse(t,e??this.defaults)}parseMarkdown(t){return(e,i)=>{const n={...i},s={...this.defaults,...n},r=this.onError(!!s.silent,!!s.async);if(!0===this.defaults.async&&!1===n.async)return r(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(null==e)return r(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof e)return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));s.hooks&&(s.hooks.options=s,s.hooks.block=t);const o=s.hooks?s.hooks.provideLexer():t?Tm.lex:Tm.lexInline,l=s.hooks?s.hooks.provideParser():t?Rm.parse:Rm.parseInline;if(s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(e):e).then(t=>o(t,s)).then(t=>s.hooks?s.hooks.processAllTokens(t):t).then(t=>s.walkTokens?Promise.all(this.walkTokens(t,s.walkTokens)).then(()=>t):t).then(t=>l(t,s)).then(t=>s.hooks?s.hooks.postprocess(t):t).catch(r);try{s.hooks&&(e=s.hooks.preprocess(e));let t=o(e,s);s.hooks&&(t=s.hooks.processAllTokens(t)),s.walkTokens&&this.walkTokens(t,s.walkTokens);let i=l(t,s);return s.hooks&&(i=s.hooks.postprocess(i)),i}catch(t){return r(t)}}}onError(t,e){return i=>{if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",t){const t="

    An error occurred:

    "+xm(i.message+"",!0)+"
    ";return e?Promise.resolve(t):t}if(e)return Promise.reject(i);throw i}}},Lm=new Pm;function Im(t,e){return Lm.parse(t,e)}Im.options=Im.setOptions=function(t){return Lm.setOptions(t),Im.defaults=Lm.defaults,Mp(Im.defaults),Im},Im.getDefaults=Sp,Im.defaults=Cp,Im.use=function(...t){return Lm.use(...t),Im.defaults=Lm.defaults,Mp(Im.defaults),Im},Im.walkTokens=function(t,e){return Lm.walkTokens(t,e)},Im.parseInline=Lm.parseInline,Im.Parser=Rm,Im.parser=Rm.parse,Im.Renderer=Dm,Im.TextRenderer=Om,Im.Lexer=Tm,Im.lexer=Tm.lex,Im.Tokenizer=Am,Im.Hooks=Em,Im.parse=Im,Im.options,Im.setOptions,Im.use,Im.walkTokens,Im.parseInline,Rm.parse,Tm.lex;let Bm=null;const Nm=new Pm({walkTokens(t){if(!Bm||"code"!=t.type)return;let e=Bm.language&&Bm.language(t.lang);if(!e){let i=Bm.view.state.facet(ic);i&&i.name==t.lang&&(e=i)}if(!e)return;let i={style:t=>_c(Bm.view.state,t)},n="";Ch(t.text,e.parser.parse(t.text),i,(t,e)=>{n+=e?`${zm(t)}`:zm(t)},()=>{n+="
    "}),t.escaped=!0,t.text=n}});function zm(t){return t.replace(/[\n<&]/g,t=>"\n"==t?"
    ":"<"==t?"<":"&")}function Hm(t,e){let i=t.lineAt(e);return{line:i.number-1,character:e-i.from}}function Fm(t,e){return t.line(e.line+1).from+e.character}class qm{constructor(t,{client:e,uri:i,languageID:n}){if(this.view=t,this.client=e,this.uri=i,!n){let e=t.state.facet(ic);n=e?e.name:""}e.workspace.openFile(i,n,t),this.syncedDoc=t.state.doc,this.unsyncedChanges=O.empty(t.state.doc.length)}docToHTML(t,e="plaintext"){let i=function(t,e,i){let n=Bm;try{return Bm={view:t,language:e},i()}finally{Bm=n}}(this.view,this.client.config.highlightLanguage,()=>function(t,e){let i=e,n=t;return"string"!=typeof n&&(i=n.kind,n=n.value),"plaintext"==i?zm(n):Nm.parse(n,{async:!1})}(t,e));return this.client.config.sanitizeHTML?this.client.config.sanitizeHTML(i):i}toPosition(t,e=this.view.state.doc){return Hm(e,t)}fromPosition(t,e=this.view.state.doc){return Fm(e,t)}reportError(t,e){yo(this.view,{label:this.view.state.phrase(t)+": "+(e.message||e),class:"cm-lsp-message cm-lsp-message-error",top:!0})}clear(){this.syncedDoc=this.view.state.doc,this.unsyncedChanges=O.empty(this.view.state.doc.length)}update(t){t.docChanged&&(this.unsyncedChanges=this.unsyncedChanges.compose(t.changes))}destroy(){this.client.workspace.closeFile(this.uri,this.view)}static get(t){return t.plugin(Vm)}static create(t,e,i){return t.plugin(e,i)}}const Vm=ln.fromClass(qm);class Wm{constructor(t){this.client=t}getFile(t){return this.files.find(e=>e.uri==t)||null}requestFile(t){return Promise.resolve(this.getFile(t))}connected(){for(let t of this.files)this.client.didOpen(t)}disconnected(){}updateFile(t,e){var i;let n=this.getFile(t);n&&(null===(i=n.getView())||void 0===i||i.dispatch(e))}displayFile(t){let e=this.getFile(t);return Promise.resolve(e?e.getView():null)}}class _m{constructor(t,e,i,n,s){this.uri=t,this.languageId=e,this.version=i,this.doc=n,this.view=s}getView(){return this.view}}class $m extends Wm{constructor(){super(...arguments),this.files=[],this.fileVersions=Object.create(null)}nextFileVersion(t){var e;return this.fileVersions[t]=(null!==(e=this.fileVersions[t])&&void 0!==e?e:-1)+1}syncFiles(){let t=[];for(let e of this.files){let i=qm.get(e.view);if(!i)continue;let n=i.unsyncedChanges;n.empty||(t.push({changes:n,file:e,prevDoc:e.doc}),e.doc=e.view.state.doc,e.version=this.nextFileVersion(e.uri),i.clear())}return t}openFile(t,e,i){if(this.getFile(t))throw new Error("Default workspace implementation doesn't support multiple views on the same file");let n=new _m(t,e,this.nextFileVersion(t),i.state.doc,i);this.files.push(n),this.client.didOpen(n)}closeFile(t){let e=this.getFile(t);e&&(this.files=this.files.filter(t=>t!=e),this.client.didClose(t))}}const jm=cr.baseTheme({".cm-lsp-documentation":{padding:"0 7px","& p, & pre":{margin:"2px 0"}},".cm-lsp-signature-tooltip":{padding:"2px 6px",borderRadius:"2.5px",position:"relative",maxWidth:"30em",maxHeight:"10em",overflowY:"scroll","& .cm-lsp-documentation":{padding:"0",fontSize:"80%"},"& .cm-lsp-signature-num":{fontFamily:"monospace",position:"absolute",left:"2px",top:"4px",fontSize:"70%",lineHeight:"1.3"},"& .cm-lsp-signature":{fontFamily:"monospace",textIndent:"1em hanging"},"& .cm-lsp-active-parameter":{fontWeight:"bold"}},".cm-lsp-signature-multiple":{paddingLeft:"1.5em"},".cm-panel.cm-lsp-rename-panel":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}},".cm-lsp-message button[type=submit]":{display:"block"},".cm-lsp-reference-panel":{fontFamily:"monospace",whiteSpace:"pre",padding:"3px 6px",maxHeight:"120px",overflow:"auto","& .cm-lsp-reference-file":{fontWeight:"bold"},"& .cm-lsp-reference":{cursor:"pointer","&[aria-selected]":{backgroundColor:"#0077ee44"}},"& .cm-lsp-reference-line":{opacity:"0.7"}}});class Km{constructor(t,e,i){this.id=t,this.params=e,this.timeout=i,this.promise=new Promise((t,e)=>{this.resolve=t,this.reject=e})}}const Um={general:{markdown:{parser:"marked"}},textDocument:{completion:{completionItem:{snippetSupport:!0,documentationFormat:["plaintext","markdown"],insertReplaceSupport:!1},completionList:{itemDefaults:["commitCharacters","editRange","insertTextFormat"]},completionItemKind:{valueSet:[]},contextSupport:!0},hover:{contentFormat:["markdown","plaintext"]},formatting:{},rename:{},signatureHelp:{contextSupport:!0,signatureInformation:{documentationFormat:["markdown","plaintext"],parameterInformation:{labelOffsetSupport:!0},activeParameterSupport:!0}},definition:{},declaration:{},implementation:{},typeDefinition:{},references:{},diagnostic:{}},window:{showMessage:{}}};class Ym{constructor(t){this.client=t,this.mappings=new Map,this.startDocs=new Map;for(let e of t.workspace.files)this.mappings.set(e.uri,O.empty(e.doc.length)),this.startDocs.set(e.uri,e.doc)}addChanges(t,e){let i=this.mappings.get(t);i&&this.mappings.set(t,i.composeDesc(e))}getMapping(t){let e=this.mappings.get(t);if(!e)return null;let i=this.client.workspace.getFile(t),n=null==i?void 0:i.getView(),s=n&&qm.get(n);return s?e.composeDesc(s.unsyncedChanges):e}mapPos(t,e,i=-1,n=T.Simple){let s=this.getMapping(t);return s?s.mapPos(e,i,n):e}mapPosition(t,e,i=-1,n=T.Simple){let s=this.startDocs.get(t);if(!s)throw new Error("Cannot map from a file that's not in the workspace");let r=Fm(s,e),o=this.getMapping(t);return o?o.mapPos(r,i,n):r}destroy(){this.client.activeMappings=this.client.activeMappings.filter(t=>t!=this)}}const Gm={"window/logMessage":(t,e)=>{1==e.type?console.error("[lsp] "+e.message):2==e.type&&console.warn("[lsp] "+e.message)},"window/showMessage":(t,e)=>{if(e.type>3)return;let i;for(let e of t.workspace.files)if(i=e.getView())break;i&&yo(i,{label:e.message,class:"cm-lsp-message cm-lsp-message-"+(1==e.type?"error":2==e.type?"warning":"info"),top:!0})}};function Xm(t,e,i,n){if(!n||t.doc.length<1024)return[{text:t.doc.toString()}];let s=[];return i.iterChanges((t,i,n,r,o)=>{s.push({range:{start:Hm(e,t),end:Hm(e,i)},text:o.toString()})}),s.reverse()}function Jm(t,e){if(null==e)return t;if("object"!=typeof t||"object"!=typeof e)return e;let i={},n=Object.keys(t),s=Object.keys(e);for(let r of n)i[r]=s.indexOf(r)>-1?Jm(t[r],e[r]):t[r];for(let t of s)n.indexOf(t)<0&&(i[t]=e[t]);return i}function Zm(t={}){let e;if(t.override)e=[yp({override:[eg]})];else{let t=[{autocomplete:eg}];e=[yp(),Dt.languageData.of(()=>t)]}return t.validFor&&e.push(Qm.of({validFor:t.validFor})),e}const Qm=q.define({combine:t=>t.length?t[0]:{validFor:null}});function tg(t){var e;let i=Math.ceil(t.length/50),n=[];for(let s=0;st.replace(/[^\w\s]/g,"\\$&"))).join("|")+")?\\w*$"):/^\w*$/}const eg=t=>{var e,i;const n=t.view&&qm.get(t.view);if(!n)return null;let s="";if(!t.explicit){s=t.view.state.sliceDoc(t.pos-1,t.pos);let r=null===(i=null===(e=n.client.serverCapabilities)||void 0===e?void 0:e.completionProvider)||void 0===i?void 0:i.triggerCharacters;if(!(/[a-zA-Z_]/.test(s)||r&&r.indexOf(s)>-1))return null}return function(t,e,i,n){if(!1===t.client.hasCapability("completionProvider"))return Promise.resolve(null);t.client.sync();let s={position:t.toPosition(e),textDocument:{uri:t.uri},context:i};return n&&n.addEventListener("abort",()=>t.client.cancelRequest(s)),t.client.request("textDocument/completion",s)}(n,t.pos,{triggerCharacter:s,triggerKind:t.explicit?1:2},t).then(e=>{var i,s;if(!e)return null;Array.isArray(e)&&(e={items:e});let{from:r,to:o}=function(t,e){var i;if(!e.items.length)return{from:t.pos,to:t.pos};let n=null===(i=e.itemDefaults)||void 0===i?void 0:i.editRange,s=e.items[0],r=n?"insert"in n?n.insert:n:s.textEdit?"range"in s.textEdit?s.textEdit.range:s.textEdit.insert:null;if(!r)return t.state.wordAt(t.pos)||{from:t.pos,to:t.pos};let o=t.state.doc.lineAt(t.pos);return{from:o.from+r.start.character,to:o.from+r.end.character}}(t,e),l=null===(i=e.itemDefaults)||void 0===i?void 0:i.commitCharacters,a=t.state.facet(Qm);return{from:r,to:o,options:e.items.map(t=>{var e;let i=(null===(e=t.textEdit)||void 0===e?void 0:e.newText)||t.textEditText||t.insertText||t.label,s={label:i,type:t.kind&&ig[t.kind]};return t.commitCharacters&&t.commitCharacters!=l&&(s.commitCharacters=t.commitCharacters),t.detail&&(s.detail=t.detail),2==t.insertTextFormat&&(s.apply=(t,e,n,s)=>function(t){let e=$f.parse(t);return(t,i,n,s)=>{let{text:r,ranges:o}=e.instantiate(t.state,n),{main:l}=t.state.selection,a={changes:{from:n,to:s==l.from?l.to:s,insert:d.of(r)},scrollIntoView:!0,annotations:i?[of.of(i),vt.userEvent.of("input.complete")]:void 0};if(o.length&&(a.selection=Jf(o,0)),o.some(t=>t.field>0)){let e=new Uf(o,0),i=a.effects=[Yf.of(e)];void 0===t.state.field(Xf,!1)&&i.push(gt.appendConfig.of([Xf,ep,ip,Vf]))}t.dispatch(t.state.update(a))}}(i)(t,e,n,s),s.label=t.label),t.documentation&&(s.info=()=>function(t,e){let i=document.createElement("div");return i.className="cm-lsp-documentation cm-lsp-completion-documentation",i.innerHTML=t.docToHTML(e),i}(n,t.documentation)),s}),commitCharacters:l,validFor:null!==(s=a.validFor)&&void 0!==s?s:tg(e.items),map:(t,e)=>({...t,from:e.mapPos(t.from)})}},t=>{if("code"in t&&-32800==t.code)return null;throw t})};const ig={1:"text",2:"method",3:"function",4:"class",5:"property",6:"variable",7:"class",8:"interface",9:"namespace",10:"property",11:"keyword",12:"constant",13:"constant",14:"keyword",16:"constant",20:"constant",21:"constant",22:"class",25:"type"};function ng(t={}){return co(sg,{hideOn:t=>t.docChanged,hoverTime:t.hoverTime})}function sg(t,e){const i=qm.get(t);return i?function(t,e){return!1===t.client.hasCapability("hoverProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/hover",{position:t.toPosition(e),textDocument:{uri:t.uri}}))}(i,e).then(n=>n?{pos:n.range?Fm(t.state.doc,n.range.start):e,end:n.range?Fm(t.state.doc,n.range.end):e,create(){let t=document.createElement("div");return t.className="cm-lsp-hover-tooltip cm-lsp-documentation",t.innerHTML=function(t,e){return Array.isArray(e)?e.map(e=>rg(t,e)).join("
    "):"string"==typeof e||"object"==typeof e&&"language"in e?rg(t,e):t.docToHTML(e)}(i,n.contents),{dom:t}},above:!0}:null):Promise.resolve(null)}function rg(t,e){if("string"==typeof e)return t.docToHTML(e,"markdown");let{language:i,value:n}=e,s=t.client.config.highlightLanguage&&t.client.config.highlightLanguage(i||"");if(!s){let e=t.view.state.facet(ic);!e||i&&e.name!=i||(s=e)}if(!s)return zm(n);let r="";return Ch(n,s.parser.parse(n),{style:e=>_c(t.view.state,e)},(t,e)=>{r+=e?`${zm(t)}`:zm(t)},()=>{r+="
    "}),r}const og=t=>{const e=qm.get(t);return!!e&&(e.client.sync(),e.client.withMapping(i=>function(t,e){return t.client.request("textDocument/formatting",{options:e,textDocument:{uri:t.uri}})}(e,{tabSize:rc(t.state),insertSpaces:t.state.facet(sc).indexOf("\t")<0}).then(n=>{if(!n)return;let s=i.getMapping(e.uri),r=[];for(let t of n){let n=i.mapPosition(e.uri,t.range.start),o=i.mapPosition(e.uri,t.range.end);if(s){if(s.touchesRange(n,o))return;n=s.mapPos(n,1),o=s.mapPos(o,-1)}r.push({from:n,to:o,insert:t.newText})}t.dispatch({changes:r,userEvent:"format"})},t=>{e.reportError("Formatting request failed",t)})),!0)},lg=[{key:"Shift-Alt-f",run:og,preventDefault:!0}];const ag=[{key:"F2",run:t=>{let e=t.state.wordAt(t.state.selection.main.head),i=qm.get(t);if(!e||!i||!1===i.client.hasCapability("renameProvider"))return!1;const n=t.state.sliceDoc(e.from,e.to);let s=function(t,e){let i=t.state.field(xo,!1)||[];for(let n of i){let i=mo(t,n);if(i&&i.dom.classList.contains(e))return i}return null}(t,"cm-lsp-rename-panel");if(s){let t=s.dom.querySelector("[name=name]");t.value=n,t.select()}else{let{close:e,result:i}=yo(t,{label:t.state.phrase("New name"),input:{name:"name",value:n},focus:!0,submitLabel:t.state.phrase("rename"),class:"cm-lsp-rename-panel"});i.then(i=>{t.dispatch({effects:e}),i&&function(t,e){const i=qm.get(t),n=t.state.wordAt(t.state.selection.main.head);if(!i||!n)return!1;i.client.sync(),i.client.withMapping(t=>function(t,e,i){return t.client.request("textDocument/rename",{newName:i,position:t.toPosition(e),textDocument:{uri:t.uri}})}(i,n.from,e).then(e=>{if(e)for(let n in e.changes){let s=e.changes[n],r=i.client.workspace.getFile(n);s.length&&r&&i.client.workspace.updateFile(n,{changes:s.map(e=>({from:t.mapPosition(n,e.range.start),to:t.mapPosition(n,e.range.end),insert:e.newText})),userEvent:"rename"})}},t=>{i.reportError("Rename request failed",t)}))}(t,i.elements.namedItem("name").value)})}return!0},preventDefault:!0}];const hg=ln.fromClass(class{constructor(){this.activeRequest=null,this.delayedRequest=0}update(t){var e;this.activeRequest&&(t.selectionSet?(this.activeRequest.drop=!0,this.activeRequest=null):t.docChanged&&(this.activeRequest.pos=t.changes.mapPos(this.activeRequest.pos)));const i=qm.get(t.view);if(!i)return;const n=t.view.state.field(ug);let s="";if(t.docChanged&&t.transactions.some(t=>t.isUserEvent("input.type"))){const r=null===(e=i.client.serverCapabilities)||void 0===e?void 0:e.signatureHelpProvider,o=((null==r?void 0:r.triggerCharacters)||[]).concat(n&&(null==r?void 0:r.retriggerCharacters)||[]);o&&t.changes.iterChanges((t,e,i,n,r)=>{let l=r.toString();if(l)for(let t of o)l.indexOf(t)>-1&&(s=t)})}s?this.startRequest(i,{triggerKind:2,isRetrigger:!!n,triggerCharacter:s,activeSignatureHelp:n?n.data:void 0}):n&&t.selectionSet&&(this.delayedRequest&&clearTimeout(this.delayedRequest),this.delayedRequest=setTimeout(()=>{this.startRequest(i,{triggerKind:3,isRetrigger:!0,activeSignatureHelp:n.data})},250))}startRequest(t,e){this.delayedRequest&&clearTimeout(this.delayedRequest);let{view:i}=t,n=i.state.selection.main.head;this.activeRequest&&(this.activeRequest.drop=!0);let s=this.activeRequest={pos:n,drop:!1};(function(t,e,i){return!1===t.client.hasCapability("signatureHelpProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/signatureHelp",{context:i,position:t.toPosition(e),textDocument:{uri:t.uri}}))})(t,n,e).then(t=>{var n,r,o;if(!s.drop)if(t&&t.signatures.length){let l=i.state.field(ug),a=l&&(r=l.data,o=t,r.signatures.length==o.signatures.length&&r.signatures.every((t,e)=>t.label==o.signatures[e].label)),h=a&&3==e.triggerKind?l.active:null!==(n=t.activeSignature)&&void 0!==n?n:0;if(a&&function(t,e,i){var n,s;return(null!==(n=t.signatures[i].activeParameter)&&void 0!==n?n:t.activeParameter)==(null!==(s=e.signatures[i].activeParameter)&&void 0!==s?s:e.activeParameter)}(l.data,t,h))return;i.dispatch({effects:dg.of({data:t,active:h,pos:a?l.tooltip.pos:s.pos})})}else i.state.field(ug)&&i.dispatch({effects:dg.of(null)})},1==e.triggerKind?e=>t.reportError("Signature request failed",e):void 0)}destroy(){this.delayedRequest&&clearTimeout(this.delayedRequest),this.activeRequest&&(this.activeRequest.drop=!0)}});class cg{constructor(t,e,i){this.data=t,this.active=e,this.tooltip=i}}const ug=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(dg))return t.value?new cg(t.value.data,t.value.active,fg(t.value.data,t.value.active,t.value.pos)):null;return t&&e.docChanged?new cg(t.data,t.active,{...t.tooltip,pos:e.changes.mapPos(t.tooltip.pos)}):t},provide:t=>so.from(t,t=>t&&t.tooltip)}),dg=gt.define();function fg(t,e,i){return{pos:i,above:!0,create:i=>function(t,e,i){var n;let s=document.createElement("div");if(s.className="cm-lsp-signature-tooltip",e.signatures.length>1){s.classList.add("cm-lsp-signature-multiple");let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-num",t.textContent=`${i+1}/${e.signatures.length}`}let r=e.signatures[i],o=s.appendChild(document.createElement("div"));o.className="cm-lsp-signature";let l=0,a=0,h=null!==(n=r.activeParameter)&&void 0!==n?n:e.activeParameter,c=null!=h&&r.parameters?r.parameters[h]:null;if(c&&Array.isArray(c.label))[l,a]=c.label;else if(c){let t=r.label.indexOf(c.label);t>-1&&(l=t,a=t+c.label.length)}if(a){o.appendChild(document.createTextNode(r.label.slice(0,l)));let t=o.appendChild(document.createElement("span"));t.className="cm-lsp-active-parameter",t.textContent=r.label.slice(l,a),o.appendChild(document.createTextNode(r.label.slice(a)))}else o.textContent=r.label;if(r.documentation){let e=qm.get(t);if(e){let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-documentation cm-lsp-documentation",t.innerHTML=e.docToHTML(r.documentation)}}return{dom:s}}(i,t,e)}}const pg=[{key:"Mod-Shift-Space",run:t=>{let e=t.plugin(hg);e||(t.dispatch({effects:gt.appendConfig.of([ug,hg])}),e=t.plugin(hg));let i=t.state.field(ug);if(!e||void 0===i)return!1;let n=qm.get(t);return!!n&&(e.startRequest(n,{triggerKind:1,activeSignatureHelp:i?i.data:void 0,isRetrigger:!!i}),!0)}},{key:"Mod-Shift-ArrowUp",run:t=>{let e=t.state.field(ug);return!!e&&(e.active>0&&t.dispatch({effects:dg.of({data:e.data,active:e.active-1,pos:e.tooltip.pos})}),!0)}},{key:"Mod-Shift-ArrowDown",run:t=>{let e=t.state.field(ug);return!!e&&(e.activefunction(t,e){const i=qm.get(t);return!(!i||!1===i.client.hasCapability(e.capability)||(i.client.sync(),i.client.withMapping(n=>e.get(i,t.state.selection.main.head).then(e=>{if(!e)return;let s=Array.isArray(e)?e[0]:e;return(s.uri==i.uri?Promise.resolve(t):i.client.workspace.displayFile(s.uri)).then(t=>{if(!t)return;let e=n.getMapping(s.uri)?n.mapPosition(s.uri,s.range.start):i.fromPosition(s.range.start,t.state.doc);t.dispatch({selection:{anchor:e},scrollIntoView:!0,userEvent:"select.definition"})})},t=>i.reportError("Find definition failed",t))),0))}(t,{get:gg,capability:"definitionProvider"}),preventDefault:!0}];const wg=t=>!!t.state.field(bg,!1)&&(t.dispatch({effects:yg.of(null)}),!0),bg=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(yg))return t.value;return t},provide:t=>bo.from(t)}),yg=gt.define();const xg=[{key:"Shift-F12",run:t=>{const e=qm.get(t);if(!e||!1===e.client.hasCapability("referencesProvider"))return!1;e.client.sync();let i=e.client.workspaceMapping(),n=!1;return function(t,e){return t.client.request("textDocument/references",{textDocument:{uri:t.uri},position:t.toPosition(e),context:{includeDeclaration:!0}})}(e,t.state.selection.main.head).then(t=>{if(t)return Promise.all(t.map(t=>e.client.workspace.requestFile(t.uri).then(e=>e?{file:e,range:t.range}:null))).then(t=>{let s=t.filter(t=>t);s.length&&(!function(t,e,i){let n=function(t,e){let i=!1;return setTimeout(()=>{i||e.destroy()},500),n=>{i=!0;let s=function(t){let e=t[0],i=e.length;for(let n=1;nt.file.uri)),r=document.createElement("div"),o=null;r.className="cm-lsp-reference-panel",r.tabIndex=0,r.role="listbox",r.setAttribute("aria-label",n.state.phrase("Reference list"));let l=[];for(let{file:i,range:n}of t){let t=i.uri.slice(s);if(t!=o){o=t;let e=r.appendChild(document.createElement("div"));e.className="cm-lsp-reference-file",e.textContent=t}let a=r.appendChild(document.createElement("div"));a.className="cm-lsp-reference",a.role="option";let h=e.mapPosition(i.uri,n.start,1),c=e.mapPosition(i.uri,n.end,-1),u=i.getView(),d=(u?u.state.doc:i.doc).lineAt(h),f=a.appendChild(document.createElement("span"));f.className="cm-lsp-reference-line",f.textContent=(d.number+": ").padStart(5," ");let p=d.text.slice(Math.max(0,h-d.from-50),h-d.from);p&&a.appendChild(document.createTextNode(p)),a.appendChild(document.createElement("strong")).textContent=d.text.slice(h-d.from,c-d.from);let m=d.text.slice(c-d.from,Math.min(d.length,100-p.length));m&&a.appendChild(document.createTextNode(m)),l.length||a.setAttribute("aria-selected","true"),l.push(a)}function a(){for(let t=0;t{if(!t)return;let i=e.mapPosition(s.uri,r.start,1);t.focus(),t.dispatch({selection:{anchor:i},scrollIntoView:!0})})}r.addEventListener("keydown",e=>{if(27==e.keyCode)wg(n),n.focus();else if(38==e.keyCode||33==e.keyCode)h((a()-1+t.length)%t.length);else if(40==e.keyCode||34==e.keyCode)h((a()+1)%t.length);else if(36==e.keyCode)h(0);else if(35==e.keyCode)h(l.length-1);else{if(13!=e.keyCode&&10!=e.keyCode)return;c(a())}e.preventDefault()}),r.addEventListener("click",t=>{for(let e=0;ewg(n)),d.setAttribute("aria-label",n.state.phrase("close")),{dom:u,destroy:()=>e.destroy(),mount:()=>r.focus()}}}(e,i),s=void 0===t.state.field(bg,!1)?gt.appendConfig.of(bg.init(()=>n)):yg.of(n);t.dispatch({effects:s})}(e.view,s,i),n=!0)})},t=>e.reportError("Finding references failed",t)).finally(()=>{n||i.destroy()}),!0},preventDefault:!0},{key:"Escape",run:wg}];const kg=ln.fromClass(class{constructor(){this.pending=-1}update(t){t.docChanged&&(this.pending>-1&&clearTimeout(this.pending),this.pending=setTimeout(()=>{this.pending=-1;let e=qm.get(t.view);e&&e.client.sync()},500))}destroy(){this.pending>-1&&clearTimeout(this.pending)}});var Sg=function(){function t(t){return{type:t,style:"keyword"}}for(var e=t("operator"),i={type:"atom",style:"atom"},n={type:"axis_specifier",style:"qualifier"},s={",":{type:"punctuation",style:null}},r=["after","all","allowing","ancestor","ancestor-or-self","any","array","as","ascending","at","attribute","base-uri","before","boundary-space","by","case","cast","castable","catch","child","collation","comment","construction","contains","content","context","copy","copy-namespaces","count","decimal-format","declare","default","delete","descendant","descendant-or-self","descending","diacritics","different","distance","document","document-node","element","else","empty","empty-sequence","encoding","end","entire","every","exactly","except","external","first","following","following-sibling","for","from","ftand","ftnot","ft-option","ftor","function","fuzzy","greatest","group","if","import","in","inherit","insensitive","insert","instance","intersect","into","invoke","is","item","language","last","lax","least","let","levels","lowercase","map","modify","module","most","namespace","next","no","node","nodes","no-inherit","no-preserve","not","occurs","of","only","option","order","ordered","ordering","paragraph","paragraphs","parent","phrase","preceding","preceding-sibling","preserve","previous","processing-instruction","relationship","rename","replace","return","revalidation","same","satisfies","schema","schema-attribute","schema-element","score","self","sensitive","sentence","sentences","sequence","skip","sliding","some","stable","start","stemming","stop","strict","strip","switch","text","then","thesaurus","times","to","transform","treat","try","tumbling","type","typeswitch","union","unordered","update","updating","uppercase","using","validate","value","variable","version","weight","when","where","wildcards","window","with","without","word","words","xquery"],o=0,l=r.length;o",">=","<","<=",".","|","?","and","or","div","idiv","mod","*","/","+","-"];for(o=0,l=h.length;o\"\'\/?]/);)l+=o;return Cg(t,e,function(t,e){return function(i,n){return i.eatSpace(),e&&i.eat(">")?(zg(n),n.tokenize=Mg,"tag"):(i.eat("/")||Ng(n,{type:"tag",name:t,tokenize:Mg}),i.eat(">")?(n.tokenize=Mg,"tag"):(n.tokenize=Og,"tag"))}}(l,r))}if("{"==i)return Ng(e,{type:"codeblock"}),null;if("}"==i)return zg(e),null;if(Lg(e))return">"==i?"tag":"/"==i&&t.eat(">")?(zg(e),"tag"):"variable";if(/\d/.test(i))return t.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/),"atom";if("("===i&&t.eat(":"))return Ng(e,{type:"comment"}),Cg(t,e,Ag);if(s||'"'!==i&&"'"!==i){if("$"===i)return Cg(t,e,Dg);if(":"===i&&t.eat("="))return"keyword";if("("===i)return Ng(e,{type:"paren"}),null;if(")"===i)return zg(e),null;if("["===i)return Ng(e,{type:"bracket"}),null;if("]"===i)return zg(e),null;var a=Sg.propertyIsEnumerable(i)&&Sg[i];if(s&&'"'===i)for(;'"'!==t.next(););if(s&&"'"===i)for(;"'"!==t.next(););a||t.eatWhile(/[\w\$_-]/);var h=t.eat(":");!t.eat(":")&&h&&t.eatWhile(/[\w\$_-]/),t.match(/^[ \t]*\(/,!1)&&(n=!0);var c=t.current();return a=Sg.propertyIsEnumerable(c)&&Sg[c],n&&!a&&(a={type:"function_call",style:"def"}),function(t){return Bg(t,"xmlconstructor")}(e)?(zg(e),"variable"):("element"!=c&&"attribute"!=c&&"axis_specifier"!=a.type||Ng(e,{type:"xmlconstructor"}),a?a.style:"variable")}return Tg(t,e,i)}function Ag(t,e){for(var i,n=!1,s=!1,r=0;i=t.next();){if(")"==i&&n){if(!(r>0)){zg(e);break}r--}else":"==i&&s&&r++;n=":"==i,s="("==i}return"comment"}function Tg(t,e,i,n){let s=function(t,e){return function(i,n){for(var s;s=i.next();){if(s==t){zg(n),e&&(n.tokenize=e);break}if(i.match("{",!1)&&Ig(n))return Ng(n,{type:"codeblock"}),n.tokenize=Mg,"string"}return"string"}}(i,n);return Ng(e,{type:"string",name:i,tokenize:s}),Cg(t,e,s)}function Dg(t,e){var i=/[\w\$_-]/;if(t.eat('"')){for(;'"'!==t.next(););t.eat(":")}else t.eatWhile(i),t.match(":=",!1)||t.eat(":");return t.eatWhile(i),e.tokenize=Mg,"variable"}function Og(t,e){var i=t.next();return"/"==i&&t.eat(">")?(Ig(e)&&zg(e),Lg(e)&&zg(e),"tag"):">"==i?(Ig(e)&&zg(e),"tag"):"="==i?null:'"'==i||"'"==i?Tg(t,e,i,Og):(Ig(e)||Ng(e,{type:"attribute",tokenize:Og}),t.eat(/[a-zA-Z_:]/),t.eatWhile(/[-a-zA-Z0-9_:.]/),t.eatSpace(),(t.match(">",!1)||t.match("/",!1))&&(zg(e),e.tokenize=Mg),"attribute")}function Rg(t,e){for(var i;i=t.next();)if("-"==i&&t.match("->",!0))return e.tokenize=Mg,"comment"}function Eg(t,e){for(var i;i=t.next();)if("]"==i&&t.match("]",!0))return e.tokenize=Mg,"comment"}function Pg(t,e){for(var i;i=t.next();)if("?"==i&&t.match(">",!0))return e.tokenize=Mg,"processingInstruction"}function Lg(t){return Bg(t,"tag")}function Ig(t){return Bg(t,"attribute")}function Bg(t,e){return t.stack.length&&t.stack[t.stack.length-1].type==e}function Ng(t,e){t.stack.push(e)}function zg(t){t.stack.pop();var e=t.stack.length&&t.stack[t.stack.length-1].tokenize;t.tokenize=e||Mg}const Hg={name:"xquery",startState:function(){return{tokenize:Mg,cc:[],stack:[]}},token:function(t,e){return t.eatSpace()?null:e.tokenize(t,e)},languageData:{commentTokens:{block:{open:"(:",close:":)"}}}};var Fg=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s{const e=[];for(let i of t){if(!i)continue;const{create:t,gutters:n}=i,s=Fg(i,["create","gutters"]);e.push(Object.assign(Object.assign({},s),{enabled:!0,gutters:n?n.filter(t=>Object.keys(t).length>0):void 0}))}return Ot(e,{enabled:e.length>0,displayText:"characters",eventHandlers:{},showOverlay:"always",gutters:[]})}}),Vg={PixelMultiplier:2,SizeRatio:4,MaxWidth:120},Wg=cr.theme({".cm-minimap-overlay-container":{position:"absolute",top:0,height:"100%",width:"100%","&.cm-minimap-overlay-mouse-over":{opacity:0,transition:"visibility 0s linear 300ms, opacity 300ms"},"&.cm-minimap-overlay-mouse-over:hover":{opacity:1,transition:"visibility 0s linear 0ms, opacity 300ms"},"&.cm-minimap-overlay-off":{display:"none"},"& .cm-minimap-overlay":{background:"rgb(121, 121, 121)",opacity:"0.2",position:"absolute",right:0,top:0,width:"100%",transition:"top 0s ease-in 0ms","&:hover":{opacity:"0.3"}},"&.cm-minimap-overlay-active":{opacity:1,visibility:"visible",transition:"visibility 0s linear 0ms, opacity 300ms","& .cm-minimap-overlay":{opacity:"0.4"}}}}),_g=Vg.PixelMultiplier*Vg.SizeRatio,$g=ln.fromClass(class{constructor(t){this.view=t,this._isDragging=!1,t.state.facet(qg).enabled&&this.create(t)}create(t){this.container=oe("div",{class:"cm-minimap-overlay-container"}),this.dom=oe("div",{class:"cm-minimap-overlay"}),this.container.appendChild(this.dom),this.container.addEventListener("mousedown",this.onMouseDown.bind(this)),window.addEventListener("mouseup",this.onMouseUp.bind(this)),window.addEventListener("mousemove",this.onMouseMove.bind(this));const e=t.dom.querySelector(".cm-minimap-inner");e&&e.appendChild(this.container),this.computeShowOverlay(),this.computeHeight(),this.computeTop()}remove(){this.container&&(this.container.removeEventListener("mousedown",this.onMouseDown),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("mousemove",this.onMouseMove),this.container.remove())}update(t){const e=t.startState.facet(qg).enabled,i=t.state.facet(qg).enabled;!e||i?(!e&&i&&this.create(t.view),i&&(this.computeShowOverlay(),t.geometryChanged&&(this.computeHeight(),this.computeTop()))):this.remove()}computeHeight(){if(!this.dom)return;const t=this.view.dom.clientHeight/_g;this.dom.style.height=t+"px"}computeTop(){if(!this._isDragging&&this.dom){const{clientHeight:t,scrollHeight:e,scrollTop:i}=this.view.scrollDOM,n=i/_g,s=t-t/_g;let r=i/(e-t);isNaN(r)&&(r=0);const o=s*r,l=Math.min(o,n);this.dom.style.top=l+"px"}}computeShowOverlay(){if(!this.container)return;const{showOverlay:t}=this.view.state.facet(qg);"mouse-over"===t?this.container.classList.add("cm-minimap-overlay-mouse-over"):this.container.classList.remove("cm-minimap-overlay-mouse-over");const{clientHeight:e,scrollHeight:i}=this.view.scrollDOM;e===i?this.container.classList.add("cm-minimap-overlay-off"):this.container.classList.remove("cm-minimap-overlay-off")}onMouseDown(t){if(!this.container)return;if(2===t.button)return;const{clientY:e,target:i}=t;if(i===this.dom)return this._dragStartY=t.clientY,this._isDragging=!0,void this.container.classList.add("cm-minimap-overlay-active");const{clientHeight:n,scrollHeight:s,scrollTop:r}=this.view.scrollDOM,o=(e-i.getBoundingClientRect().top)*_g,l=(n*_g-n)*(r/(s-n)),a=Math.max(0,r-l);this.view.scrollDOM.scrollTop=a+o-n/2}onMouseUp(t){this._isDragging&&this.container&&(this._dragStartY=void 0,this._isDragging=!1,this.container.classList.remove("cm-minimap-overlay-active"))}onMouseMove(t){if(!this._isDragging||!this.dom)return;if(t.preventDefault(),t.stopPropagation(),!this._dragStartY)return void(this._dragStartY=t.clientY);const e=t.clientY-this._dragStartY,i=e<0,n=e>0;this._dragStartY=t.clientY;const s=this.dom.getBoundingClientRect().height,r=this.dom.getBoundingClientRect().y,o=r+s,l=parseFloat(this.dom.style.top),a=this.view.scrollDOM.scrollTop,h=this.view.scrollDOM.clientHeight,c=this.view.scrollDOM.scrollHeight,u=0===a,d=Math.round(a)>=Math.round(c-h);if(u&&i||u&&t.clientYo)return;const f=this.view.scrollDOM.scrollHeight,p=this.view.scrollDOM.clientHeight,m=(f-p)/_g,g=p-p/_g,v=l+e,w=(f-p)*(v/g),b=v*_g;this.view.scrollDOM.scrollTop=Math.max(w,b);const y=Math.min(Math.max(0,v),Math.min(g,m));this.dom.style.top=y+"px"}destroy(){this.remove()}},{eventHandlers:{scroll(){requestAnimationFrame(()=>this.computeTop())}}}),jg=[Wg,$g];class Kg{constructor(t){this.map=new Map,this.view=t}get(t){return this.map.get(t)}set(t,e){this.map.set(t,e)}}function Ug(t){var e;if(!t.facet(qg).enabled)return[];const i=[],n=t.doc.iterLines(),s=function(t){return t.field(Sc,!1)||It.empty}(t).iter();let r=0;for(n.next();!n.done;){let t=r,o=t+n.value.length;for(;s.value&&s.tol&&o<=a;if(t>=l&&tUg(t),update:(t,e)=>Gg([e])||e.docChanged?Ug(e.state):t});function Gg(t){return t.find(t=>t.effects.find(t=>t.is(yc)||t.is(xc)))}class Xg extends Kg{constructor(t){super(t),this.count=void 0}shouldUpdate(t){if(!t.state.facet(qg).enabled)return!1;if(t.docChanged)return!0;for(const e of t.transactions)for(const t of e.effects)if(t.is(ra))return!0;return!!Gg(t.transactions)||void 0===this.count}update(t){if(!this.shouldUpdate(t))return;this.map.clear();const e=t.state.field(Yg);this.count=function(t){let e=t.field(aa,!1);return e?e.diagnostics.size:0}(t.state),function(t,e){let i=t.field(aa,!1);if(i&&i.diagnostics.size){let t=[],n=[],s=-1;for(let r=It.iter([i.diagnostics]);;r.next()){for(let i=0;i{const s=this.findLine(i,e),r=this.findLine(n,e);let o=t.severity;for(let t=s;t<=r;t++){const e=this.get(t);e&&(o=[o,e].sort(this.sort.bind(this)).slice(0,1)[0]),this.set(t,o)}})}drawLine(t,e){const{context:i,lineHeight:n,offsetX:s,offsetY:r}=t,o=this.get(e);o&&(i.globalAlpha=.65,i.beginPath(),i.rect(s,r,i.canvas.width-s,n),i.fillStyle=this.color(o),i.fill())}findLine(t,e){return e.findIndex(e=>{const i=e.slice(0,1)[0],n=e.slice(-1)[0];return!(!i||!n)&&(i.from<=t&&t<=n.to)})+1}color(t){return"error"===t?"#d11":"warning"===t?"orange":"#999"}sort(t,e){return this.score(e)-this.score(t)}score(t){switch(t){case"error":return 3;case"warning":return 2;default:return 1}}}class Jg extends Kg{constructor(t){super(t),this.getDrawInfo(),this._themeClasses=t.dom.classList.value}shouldUpdate(t){return!!t.state.facet(qg).enabled&&(!!t.docChanged||(!!t.selectionSet||(this._themeClasses!==this.view.dom.classList.value||!!Gg(t.transactions))))}update(t){if(!this.shouldUpdate(t))return;this.map.clear(),this._themeClasses!==this.view.dom.classList.value&&(this._drawInfo=void 0,this._themeClasses=this.view.dom.classList.value);const{ranges:e}=t.state.selection;let i=0;for(const[n,s]of t.state.field(Yg).entries()){const t=[];let r=0;for(const n of s){do{if(i>=e.length)continue;if(n.ton.to},l=t.slice(-1)[0];if(l&&l.to===o.from){let{to:e}=o;n.folded&&o.extends?e=o.from+1:n.folded&&!o.extends&&(e=l.to),t[t.length-1]=Object.assign(Object.assign({},l),{to:e,extends:o.extends})}else n.folded||t.push(o);if(o.extends)break;i++}while(i=e[i].from);r+=n.folded?1:n.to-n.from}if(0===t.length)continue;const o=n+1;this.map.set(o,t)}}drawLine(t,e){let{context:i,lineHeight:n,charWidth:s,offsetX:r,offsetY:o}=t;const l=this.get(e);if(l)for(const t of l){const e=r+t.from*s,l=(t.to-t.from)*s,a=i.canvas.width-e;t.extends&&(i.globalAlpha=.65,i.beginPath(),i.rect(e,o,a,n),i.fillStyle=this.getDrawInfo().backgroundColor,i.fill()),i.globalAlpha=1,i.beginPath(),i.rect(e,o,l,n),i.fillStyle=this.getDrawInfo().backgroundColor,i.fill()}}getDrawInfo(){if(this._drawInfo)return this._drawInfo;const t=document.createElement("span");t.setAttribute("class","cm-selectionBackground"),this.view.dom.appendChild(t);const e={backgroundColor:window.getComputedStyle(t).backgroundColor};return this._drawInfo=e,this.view.dom.removeChild(t),e}}class Zg extends Kg{constructor(t){super(t),this._fontInfoMap=new Map,this._themeClasses=new Set(t.dom.classList.values()),t.state.facet(qg).enabled&&this.updateImpl(t.state)}shouldUpdate(t){return!!t.docChanged||(t.state.facet(qg)!==t.startState.facet(qg)||(!!this.themeChanged()||!!Gg(t.transactions)))}update(t){this.shouldUpdate(t)&&(this._highlightingCallbackId&&(void 0!==window.requestIdleCallback?cancelIdleCallback(this._highlightingCallbackId):clearTimeout(this._highlightingCallbackId)),this.updateImpl(t.state,t.changes))}updateImpl(t,e){var i;let n;if(this.map.clear(),this._displayText=t.facet(qg).displayText,this.themeChanged()&&this._fontInfoMap.clear(),this._previousTree&&e){const t=dh.addTree(this._previousTree),i=[];e.iterChangedRanges((t,e,n,s)=>i.push({fromA:t,toA:e,fromB:n,toB:s})),n=dh.applyChanges(t,i)}const s=t.doc.toString(),r=null===(i=t.facet(ic))||void 0===i?void 0:i.parser,o=r?r.parse(s,n):void 0;this._previousTree=o;const l={style:e=>_c(t,e)};let a=[];if(o){const e=t.doc.lineAt(this.view.viewport.from).number,i=t.doc.lineAt(this.view.viewport.to).number,n=i-e,s=e/(t.doc.lines-n),{SizeRatio:r,PixelMultiplier:h}=Vg,c=n*r*h,u=s*c,d=Math.max(1,Math.floor(e-u)),f=Math.min(i+Math.floor(c-u),t.doc.lines);Sh(o,l,(t,e,i)=>{a.push({from:t,to:e,tags:i})},t.doc.line(d).from,t.doc.line(f).to)}this.updateMapImpl(t,a),a=[];const h=()=>{o&&(Sh(o,l,(t,e,i)=>{a.push({from:t,to:e,tags:i})}),this.updateMapImpl(t,a),this._highlightingCallbackId=void 0)};this._highlightingCallbackId=void 0!==window.requestIdleCallback?requestIdleCallback(h):setTimeout(h)}updateMapImpl(t,e){this.map.clear();const i=t.doc.toString(),n=e.values();let s=n.next();for(const[e,r]of t.field(Yg).entries()){const t=[];for(const e of r){if(e.from===e.to)continue;if(e.folded){t.push({text:"…",tags:""});continue}let r=e.from;for(;!s.done&&s.value.fromr&&t.push({text:i.slice(r,o),tags:""});const h=Math.max(o,e.from),c=Math.min(l,e.to);if(t.push({text:i.slice(h,c),tags:a}),r=c,l>c)break;s=n.next()}r!==e.to&&t.push({text:i.slice(r,e.to),tags:""})}const o=e+1;this.map.set(o,t)}}measure(t){const{color:e,font:i,lineHeight:n}=this.getFontInfo("");return t.textBaseline="ideographic",t.fillStyle=e,t.font=i,{charWidth:t.measureText("_").width,lineHeight:n}}beforeDraw(){this._fontInfoMap.clear()}drawLine(t,e){const i=this.get(e);if(!i)return;let n,{context:s,charWidth:r,lineHeight:o,offsetX:l,offsetY:a}=t;s.textBaseline="ideographic";for(const t of i){const e=this.getFontInfo(t.tags);switch(n&&n.color===e.color||(s.fillStyle=e.color),n&&n.font===e.font||(s.font=e.font),n=e,o=Math.max(o,e.lineHeight),this._displayText){case"characters":s.fillText(t.text,l,a+o),l+=t.text.length*r;break;case"blocks":{const i=/\S+/g;let n;for(;null!==(n=i.exec(t.text));){const t=l+n.index*r;let h=(i.lastIndex-n.index)*r;if(t>s.canvas.width)break;t+h>s.canvas.width&&(h=s.canvas.width-t);const c=o-2/Vg.SizeRatio;s.fillStyle=e.color,s.globalAlpha=.65,s.beginPath(),s.rect(t,a,h,c),s.fill()}l+=t.text.length*r;break}}}}getFontInfo(t){const e=this._fontInfoMap.get(t);if(e)return e;const i=oe("span",{class:t}),n=oe("div",{class:"cm-line",style:"display: none"},i);this.view.contentDOM.appendChild(n);const s=window.getComputedStyle(i),r=parseFloat(s.lineHeight)/Vg.SizeRatio,o={color:s.color,font:`${s.fontStyle} ${s.fontWeight} ${r}px ${s.fontFamily}`,lineHeight:r};return this._fontInfoMap.set(t,o),this.view.contentDOM.removeChild(n),o}themeChanged(){const t=this._themeClasses,e=new Set(this.view.dom.classList.values());if(this._themeClasses=e,!t)return!0;if(t.delete("cm-focused"),e.delete("cm-focused"),t.size!==e.size)return!0;let i=!0;return t.forEach(t=>{e.has(t)||(i=!1)}),!i}}function Qg(t,e,i){const n=t[i];n&&(e.context.fillStyle=n,e.context.globalAlpha=1,e.context.beginPath(),e.context.rect(e.offsetX,e.offsetY,4,e.lineHeight),e.context.fill())}const tv=cr.theme({"&":{height:"100%",overflowY:"auto"},"& .cm-minimap-gutter":{borderRight:0,flexShrink:0,left:"unset",position:"sticky",right:0,top:0},"& .cm-minimap-inner":{height:"100%",position:"absolute",right:0,top:0,overflowY:"hidden","& canvas":{display:"block"}},"& .cm-minimap-box-shadow":{boxShadow:"12px 0px 20px 5px #6c6c6c"}}),ev=ln.fromClass(class{constructor(t){this.view=t,this.text=function(t){return new Zg(t)}(t),this.selection=function(t){return new Jg(t)}(t),this.diagnostic=function(t){return new Xg(t)}(t),t.state.facet(iv)&&this.create(t)}create(t){const e=t.state.facet(iv);if(!e)throw Error("Expected nonnull");this.inner=oe("div",{class:"cm-minimap-inner"}),this.canvas=oe("canvas"),this.dom=e.create(t).dom,this.dom.classList.add("cm-gutters"),this.dom.classList.add("cm-minimap-gutter"),this.inner.appendChild(this.canvas),this.dom.appendChild(this.inner),this.view.scrollDOM.insertBefore(this.dom,this.view.contentDOM.nextSibling);for(const t in this.view.state.facet(qg).eventHandlers){const e=this.view.state.facet(qg).eventHandlers[t];e&&this.dom.addEventListener(t,t=>e(t,this.view))}}remove(){this.dom&&this.dom.remove()}update(t){const e=t.startState.facet(iv),i=t.state.facet(iv);!e||i?(!e&&i&&this.create(t.view),i&&(this.text.update(t),this.selection.update(t),this.diagnostic.update(t),this.render())):this.remove()}getWidth(){const t=this.view.dom.clientWidth;if(t<=6*Vg.MaxWidth){return Vg.MaxWidth*(t/(6*Vg.MaxWidth))}return Vg.MaxWidth}render(){if(!this.dom||!this.canvas||!this.inner)return;this.text.beforeDraw(),this.updateBoxShadow(),this.dom.style.width=this.getWidth()+"px",this.canvas.style.maxWidth=this.getWidth()+"px",this.canvas.width=this.getWidth()*Vg.PixelMultiplier;const t=this.view.dom.getBoundingClientRect().height;this.inner.style.minHeight=t+"px",this.canvas.height=t*Vg.PixelMultiplier,this.canvas.style.height=t+"px";const e=this.canvas.getContext("2d");if(!e)return;e.clearRect(0,0,this.canvas.width,this.canvas.height);const{charWidth:i,lineHeight:n}=this.text.measure(e);let{startIndex:s,endIndex:r,offsetY:o}=this.canvasStartAndEndIndex(e,n);const l=this.view.state.facet(qg).gutters;for(let t=s;t=this.view.state.field(Yg).length)break;const s={offsetX:0,offsetY:o,context:e,lineHeight:n,charWidth:i};if(l.length){s.offsetX+=2;for(let e of l)Qg(e,s,t+1),s.offsetX+=4;s.offsetX+=2}this.text.drawLine(s,t+1),this.selection.drawLine(s,t+1),this.diagnostic.drawLine(s,t+1),o+=n}e.restore()}canvasStartAndEndIndex(t,e){let{top:i,bottom:n}=this.view.documentPadding;i/=Vg.SizeRatio,n/=Vg.SizeRatio;const s=t.canvas.height,{clientHeight:r,scrollHeight:o,scrollTop:l}=this.view.scrollDOM;let a=l/(o-r);isNaN(a)&&(a=0);const h=i+n+this.view.state.field(Yg).length*e,c=Math.max(0,a*(h-s)),u=Math.max(0,i-c),d=Math.round(Math.max(0,c-i)/e);return{startIndex:d,endIndex:d+Math.round((s-u)/e),offsetY:u}}updateBoxShadow(){if(!this.canvas)return;const{clientWidth:t,scrollWidth:e,scrollLeft:i}=this.view.scrollDOM;t+ithis.render())}},provide:t=>cr.scrollMargins.of(e=>{var i;const n=null===(i=e.plugin(t))||void 0===i?void 0:i.getWidth();return n?{right:n}:null})}),iv=q.define({combine:t=>{var e;return null!==(e=t.find(t=>null!==t))&&void 0!==e?e:null},enables:t=>[[qg.compute([t],e=>e.facet(t)),tv,Yg,ev,jg]]});let nv=t=>({dom:document.createElement("div")});const sv=new et;let rv={lineWrap:!0,minimap:!0,highlightWhitespace:!0};function ov(t){let e=[];return t.lineWrap&&e.push(cr.lineWrapping),t.highlightWhitespace&&e.push(Xo),t.minimap&&e.push(iv.compute(["doc"],t=>({create:nv,displayText:"characters"}))),e}const lv=[function(t={}){return[qo.of(t),Eo(),_o]}(),Ko,function(t={}){return[zu,Nu.of(t),cr.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?Fu:"historyRedo"==t.inputType?qu:null;return!!i&&(t.preventDefault(),i(e))}})]}(),function(t={}){let e={...Nc,...t},i=new zc(e,!0),n=new zc(e,!1),s=ln.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(ic)!=t.state.facet(ic)||t.startState.field(Sc,!1)!=t.state.field(Sc,!1)||Uh(t.startState)!=Uh(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new Bt;for(let s of t.viewportLineBlocks){let r=Mc(t.state,s.from,s.to)?n:wc(t.state,s.from,s.to)?i:null;r&&e.add(s.from,s.from,r)}return e.finish()}}),{domEventHandlers:r}=e;return[s,Oo({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.markers)||It.empty},initialSpacer:()=>new zc(e,!1),domEventHandlers:{...r,click:(t,e,i)=>{if(r.click&&r.click(t,e,i))return!0;let n=Mc(t.state,e.from,e.to);if(n)return t.dispatch({effects:xc.of(n)}),!0;let s=wc(t.state,e.from,e.to);return!!s&&(t.dispatch({effects:yc.of(s)}),!0)}}}),Pc()]}(),function(t={}){return[Na.of(t),Ea,Ra,Ia,La]}(),function(t={}){return[Er.of(t),Lr,Br,Nr,Ji.of(!0)]}(),[Hr,Fr],Dt.allowMultipleSelections.of(!0),function(t={}){return Zr.of(t)}({}),wr.of([Zd]),Dt.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:n}=t.newSelection.main,s=i.lineAt(n);if(n>s.from+200)return t;let r=i.sliceString(s.from,n);if(!e.some(t=>t.test(r)))return t;let{state:o}=t,l=-1,a=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=lc(o,e.from);if(null==i)continue;let n=/^\s*/.exec(e.text)[0],s=oc(o,i);n!=s&&a.push({from:e.from,to:e.from+n.length,insert:s})}return a.length?[t,{changes:a,sequential:!0}]:t}),function(t,e){let i,n=[jc];return t instanceof Fc&&(t.module&&n.push(cr.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?n.push(Vc.of(t)):i?n.push(qc.computeN([cr.darkTheme],e=>e.facet(cr.darkTheme)==("dark"==i)?[t]:[])):n.push(qc.of(t)),n}(Kc,{fallback:!0}),function(t={}){return[Gc.of(t),tu]}(),[up,op],yp(),cr.mouseSelectionStyle.of((t,e)=>{return(i=e).altKey&&0==i.button?Kr(t,e):null;var i}),function(t={}){let[e,i]=Ur[t.key||"Alt"],n=ln.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[n,cr.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(n))||void 0===e?void 0:e.isDown)?Yr:null})]}(),_r,[gl,ml],wr.of([...dp,...Jd,...jl,...td,...Oc,...xp,...pa]),cu.define(Hg),sv.of(ov(rv))];return t.EditorState=Dt,t.EditorView=cr,t.LSPClient=class{constructor(t={}){var e;if(this.config=t,this.transport=null,this.nextReqID=0,this.requests=[],this.activeMappings=[],this.serverCapabilities=null,this.supportSync=-1,this.extensions=[],this.receiveMessage=this.receiveMessage.bind(this),this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.timeout=null!==(e=t.timeout)&&void 0!==e?e:3e3,this.workspace=t.workspace?t.workspace(this):new $m(this),t.extensions)for(let e of t.extensions)Array.isArray(e)||e.extension?this.extensions.push(e):e.editorExtension&&this.extensions.push(e.editorExtension)}get connected(){return!!this.transport}connect(t){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.transport=t,t.subscribe(this.receiveMessage);let e=Um;if(this.config.extensions)for(let t of this.config.extensions){let{clientCapabilities:i}=t;i&&(e=Jm(e,i))}return this.requestInner("initialize",{processId:null,clientInfo:{name:"@codemirror/lsp-client"},rootUri:this.config.rootUri||null,capabilities:e}).promise.then(e=>{var i;this.serverCapabilities=e.capabilities;let n=e.capabilities.textDocumentSync;this.supportSync=null==n?0:"number"==typeof n?n:null!==(i=n.change)&&void 0!==i?i:0,t.send(JSON.stringify({jsonrpc:"2.0",method:"initialized",params:{}})),this.init.resolve(null)},this.init.reject),this.workspace.connected(),this}disconnect(){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.serverCapabilities=null,this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.workspace.disconnected()}plugin(t,e){return[Vm.of({client:this,uri:t,languageID:e}),jm,this.extensions]}didOpen(t){this.notification("textDocument/didOpen",{textDocument:{uri:t.uri,languageId:t.languageId,text:t.doc.toString(),version:t.version}})}didClose(t){this.notification("textDocument/didClose",{textDocument:{uri:t}})}receiveMessage(t){var e;const i=JSON.parse(t);if("id"in i&&!("method"in i)){let t=this.requests.findIndex(t=>t.id==i.id);if(t<0)console.warn(`[lsp] Received a response for non-existent request ${i.id}`);else{let e=this.requests[t];clearTimeout(e.timeout),this.requests.splice(t,1),i.error?e.reject(i.error):e.resolve(i.result)}}else if("id"in i){let t={jsonrpc:"2.0",id:i.id,error:{code:-32601,message:"Method not implemented"}};this.transport.send(JSON.stringify(t))}else{let t=null===(e=this.config.notificationHandlers)||void 0===e?void 0:e[i.method];if(t&&t(this,i.params))return;if(this.config.extensions)for(let t of this.config.extensions){let{notificationHandlers:e}=t,n=null==e?void 0:e[i.method];if(n&&n(this,i.params))return}let n=Gm[i.method];n?n(this,i.params):this.config.unhandledNotification&&this.config.unhandledNotification(this,i.method,i.params)}}request(t,e){return this.transport?this.initializing.then(()=>this.requestInner(t,e).promise):Promise.reject(new Error("Client not connected"))}requestInner(t,e,i=!1){let n=++this.nextReqID,s={jsonrpc:"2.0",id:n,method:t,params:e},r=new Km(n,e,setTimeout(()=>this.timeoutRequest(r),this.timeout));this.requests.push(r);try{this.transport.send(JSON.stringify(s))}catch(t){r.reject(t)}return r}notification(t,e){this.transport&&this.initializing.then(()=>{let i={jsonrpc:"2.0",method:t,params:e};this.transport.send(JSON.stringify(i))})}cancelRequest(t){let e=this.requests.find(e=>e.params===t);e&&this.notification("$/cancelRequest",e.id)}hasCapability(t){return this.serverCapabilities?!!this.serverCapabilities[t]:null}workspaceMapping(){let t=new Ym(this);return this.activeMappings.push(t),t}withMapping(t){let e=this.workspaceMapping();return t(e).finally(()=>e.destroy())}sync(){for(let{file:t,changes:e,prevDoc:i}of this.workspace.syncFiles()){for(let i of this.activeMappings)i.addChanges(t.uri,e);this.supportSync&&this.notification("textDocument/didChange",{textDocument:{uri:t.uri,version:t.version},contentChanges:Xm(t,i,e,2==this.supportSync)})}}timeoutRequest(t){let e=this.requests.indexOf(t);e>-1&&(t.reject(new Error("Request timed out")),this.requests.splice(e,1))}},t.LSPPlugin=qm,t.StateEffect=gt,t.baseExts=lv,t.curOpts=rv,t.formatDocument=og,t.formatKeymap=lg,t.keymap=wr,t.languageServerExtensions=function(){return[Zm(),ng(),wr.of([...lg,...ag,...vg,...xg]),mg(),{clientCapabilities:{textDocument:{publishDiagnostics:{versionSupport:!0}}},notificationHandlers:{"textDocument/publishDiagnostics":(t,e)=>{let i=t.workspace.getFile(e.uri);if(!i||null!=e.version&&e.version!=i.version)return!1;const n=i.getView(),s=n&&qm.get(n);return!(!n||!s||(n.dispatch(sa(n.state,e.diagnostics.map(t=>{var e,i;return{from:s.unsyncedChanges.mapPos(s.fromPosition(t.range.start,s.syncedDoc)),to:s.unsyncedChanges.mapPos(s.fromPosition(t.range.end,s.syncedDoc)),severity:(i=null!==(e=t.severity)&&void 0!==e?e:1,1==i?"error":2==i?"warning":3==i?"info":"hint"),message:t.message}}))),0))}},editorExtension:kg}]},t.languageServerSupport=function(t,e,i){return[qm.create(t,e,i),Zm(),ng(),wr.of([...lg,...ag,...vg,...xg]),mg()]},t.linter=function(t,e={}){return[ga.of({source:t,config:e}),ma,Ba]},t.listCommands=function(t){const e=new Map,i=t.state.facet(wr);for(let t of i)for(let i of t)i.run&&i.run.name&&e.set(i.run.name,{key:i.key,fn:i.run});return e},t.openLintPanel=da,t.openSearchPanel=_l,t.simpleWebSocketTransport=function(t){let e=[];return new Promise(function(i,n){let s=new WebSocket(t);s.onmessage=t=>{for(let i of e)i(t.data.toString())},s.onerror=t=>n(t),s.onopen=()=>i({socket:s,send:t=>s.send(t),subscribe:t=>e.push(t),unsubscribe:t=>e=e.filter(e=>e!=t)})})},t.updateCompartment=function(t){view.dispatch({effects:[sv.reconfigure(ov(t))]})},t}({});