(()=>{"use strict";class t{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,n){let s=[];return this.decompose(0,t,s,2),n.length&&n.decompose(0,n.length,s,3),this.decompose(e,this.length,s,1),i.from(s,this.length-(e-t)+n.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){let n=[];return this.decompose(t,e,n,0),i.from(n,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 r(this),s=new r(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 r(this,t)}iterRange(t,e=this.length){return new o(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 l(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(n){if(0==n.length)throw new RangeError("A document must have at least one line");return 1!=n.length||n[0]?n.length<=32?new e(n):i.from(e.split(n,[])):t.empty}}class e extends t{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 a(n,o,i,r);n=o+1,i++}}decompose(t,i,r,o){let l=t<=0&&i>=this.length?this:new e(s(this.text,t,i),Math.min(i,this.length)-Math.max(0,t));if(1&o){let t=r.pop(),i=n(l.text,t.text.slice(),0,l.length);if(i.length<=32)r.push(new e(i,t.length+l.length));else{let t=i.length>>1;r.push(new e(i.slice(0,t)),new e(i.slice(t)))}}else r.push(l)}replace(t,r,o){if(!(o instanceof e))return super.replace(t,r,o);let l=n(this.text,n(o.text,s(this.text,0,t)),r),a=this.length+o.length-(r-t);return l.length<=32?new e(l,a):i.from(e.split(l,[]),a)}sliceString(t,e=this.length,i="\n"){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,i){let n=[],s=-1;for(let r of t)n.push(r),s+=r.length+1,32==n.length&&(i.push(new e(n,s)),n=[],s=-1);return s>-1&&i.push(new e(n,s)),i}}class i extends t{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,n){if(n.lines=r&&e<=l){let a=o.replace(t-r,e-r,n),h=this.lines-o.lines+a.lines;if(a.lines>4&&a.lines>h>>6){let r=this.children.slice();return r[s]=a,new i(r,this.length-(e-t)+n.length)}return super.replace(r,l,a)}r=l+1}return super.replace(t,e,n)}sliceString(t,e=this.length,i="\n"){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 i))return 0;let n=0,[s,r,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==o||r==l)return n;let i=this.children[s],a=t.children[r];if(i!=a)return n+i.scanIdentical(a,e);n+=i.length+1}}static from(t,n=t.reduce(((t,e)=>t+e.length+1),-1)){let s=0;for(let e of t)s+=e.lines;if(s<32){let i=[];for(let e of t)e.flatten(i);return new e(i,n)}let r=Math.max(32,s>>5),o=r<<1,l=r>>1,a=[],h=0,c=-1,u=[];function f(t){let n;if(t.lines>o&&t instanceof i)for(let e of t.children)f(e);else t.lines>l&&(h>l||!h)?(d(),a.push(t)):t instanceof e&&h&&(n=u[u.length-1])instanceof e&&t.lines+n.lines<=32?(h+=t.lines,c+=t.length+1,u[u.length-1]=new e(n.text.concat(t.text),n.length+1+t.length)):(h+t.lines>r&&d(),h+=t.lines,c+=t.length+1,u.push(t))}function d(){0!=h&&(a.push(1==u.length?u[0]:i.from(u,c)),c=-1,h=u.length=0)}for(let e of t)f(e);return d(),1==a.length?a[0]:new i(a,n)}}function n(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 e?t.text.length:t.children.length)<<1]}nextInner(t,i){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,s=this.nodes[n],r=this.offsets[n],o=r>>1,l=s instanceof e?s.text.length:s.children.length;if(o==(i>0?l:0)){if(0==n)return this.done=!0,this.value="",this;i>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(i>0?0:1)){if(this.offsets[n]+=i,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(s instanceof e){let e=s.text[o+(i<0?-1:0)];if(this.offsets[n]+=i,e.length>Math.max(0,t))return this.value=0==t?e:i>0?e.slice(t):e.slice(0,e.length-t),this;t-=e.length}else{let r=s.children[o+(i<0?-1:0)];t>r.length?(t-=r.length,this.offsets[n]+=i):(i<0&&this.offsets[n]--,this.nodes.push(r),this.offsets.push(i>0?1:(r instanceof e?r.text.length:r.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class o{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new r(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 l{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.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&&(t.prototype[Symbol.iterator]=function(){return this.iter()},r.prototype[Symbol.iterator]=o.prototype[Symbol.iterator]=l.prototype[Symbol.iterator]=function(){return this});class a{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}let h="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 t=1;tt)return h[e-1]<=t;return!1}function u(t){return t>=127462&&t<=127487}const f=8205;function d(t,e,i=!0,n=!0){return(i?p:g)(t,e,n)}function p(t,e,i){if(e==t.length)return e;e&&m(t.charCodeAt(e))&&w(t.charCodeAt(e-1))&&e--;let n=y(t,e);for(e+=k(n);e=0&&u(y(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function g(t,e,i){for(;e>0;){let n=p(t,e-2,i);if(n=56320&&t<57344}function w(t){return t>=55296&&t<56320}function y(t,e){let i=t.charCodeAt(e);if(!w(i)||e+1==t.length)return i;let n=t.charCodeAt(e+1);return m(n)?n-56320+(i-55296<<10)+65536:i}function v(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function k(t){return t<65536?1:2}const b=/\r\n?|\n/;var x=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(x||(x={}));class S{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=x.Simple&&a>=t&&(i==x.TrackDel&&nt||i==x.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 S(t)}static create(t){return new S(t)}}class A extends S{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 C(this,((e,i,n,s,r)=>t=t.replace(n,n+(i-e),r)),!1),t}mapDesc(t,e=!1){return O(this,t,e,!0)}invert(e){let i=this.sections.slice(),n=[];for(let s=0,r=0;s=0){i[s]=l,i[s+1]=o;let a=s>>1;for(;n.length0&&T(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(e,i,n){let s=[],r=[],o=0,l=null;function a(t=!1){if(!t&&!s.length)return;ol||e<0||l>i)throw new RangeError(`Invalid change range ${e} to ${l} (in doc of length ${i})`);let u=c?"string"==typeof c?t.of(c.split(n||b)):c:t.empty,f=u.length;if(e==l&&0==f)return;eo&&M(s,e-o,-1),M(s,l-e,f),T(r,s,u),o=l}}(e),a(!l),l}static empty(t){return new A(t?[t,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let i=[],n=[];for(let s=0;se&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)i.push(r[0],0);else{for(;n.length=0&&i<=0&&i==t[s+1]?t[s]+=e:0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function T(e,i,n){if(0==n.length)return;let s=i.length-2>>1;if(s>1])),!(n||l==e.sections.length||e.sections[l+1]<0);)a=e.sections[l++],h=e.sections[l++];i(r,c,o,u,f),r=c,o=u}}}function O(t,e,i,n=!1){let s=[],r=n?[]:null,o=new E(t),l=new E(e);for(let t=-1;;)if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);M(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?A.createSet(s,r):S.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 M(n,0,o.ins,t),s&&T(s,n,o.text),o.next()}}class E{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return i>=e.length?t.empty:e[i]}textBit(e){let{inserted:i}=this.set,n=this.i-2>>1;return n>=i.length&&!e?t.empty:i[n].slice(this.off,null==e?void 0:this.off+e)}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 L{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 16&this.flags?this.to:this.from}get head(){return 16&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 4&this.flags?-1:8&this.flags?1:0}get bidiLevel(){let t=3&this.flags;return 3==t?null:t}get goalColumn(){let t=this.flags>>5;return 33554431==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 L(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return B.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return B.range(this.anchor,i)}eq(t){return this.anchor==t.anchor&&this.head==t.head}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 B.range(t.anchor,t.head)}static create(t,e,i){return new L(t,e,i)}}class B{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:B.create(this.ranges.map((i=>i.map(t,e))),this.mainIndex)}eq(t){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let e=0;et.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 B(t.ranges.map((t=>L.fromJSON(t))),t.main)}static single(t,e=t){return new B([B.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?4: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?B.range(o,r):B.range(r,o))}}return new B(t,e)}}function P(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let N=0;class R{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=N++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}static define(t={}){return new R(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:I),!!t.static,t.enables)}of(t){return new H([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new H(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new H(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(i=>e(i.field(t))))}}function I(t,e){return t==e||t.length==e.length&&t.every(((t,i)=>t===e[i]))}class H{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=N++}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: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)||W(t,h)){let e=i(t);if(o?!z(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=X(e,a);if(this.dependencies.every((i=>i instanceof R?e.facet(i)===t.facet(i):!(i instanceof _)||e.field(i,!1)==t.field(i,!1)))||(o?z(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 z(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(F).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)=>null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,F.of({field:this,create:t})]}get extension(){return this}}function q(t){return e=>new K(e,t)}const j={highest:q(0),high:q(1),default:q(2),low:q(3),lowest:q(4)};class K{constructor(t,e){this.inner=t,this.prec=e}}class G{of(t){return new U(this,t)}reconfigure(t){return G.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class U{constructor(t,e){this.compartment=t,this.inner=e}}class J{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;return function t(r,o){let l=s.get(r);if(null!=l){if(l<=o)return;let t=n[l].indexOf(r);t>-1&&n[l].splice(t,1),r instanceof U&&i.delete(r.compartment)}if(s.set(r,o),Array.isArray(r))for(let e of r)t(e,o);else if(r instanceof U){if(i.has(r.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(r.compartment)||r.inner;i.set(r.compartment,n),t(n,o)}else if(r instanceof K)t(r.inner,r.prec);else if(r instanceof _)n[o].push(r),r.provides&&t(r.provides,o);else if(r instanceof H)n[o].push(r),r.facet.extensions&&t(r.facet.extensions,2);else{let e=r.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${r}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);t(e,o)}}(t,2),n.reduce(((t,e)=>t.concat(e)))}(t,e,r))i instanceof _?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,I(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=>V(t,n,e)))}}let c=a.map((t=>t(o)));return new J(t,r,c,o,l,s)}}function Y(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 X(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const Q=R.define(),Z=R.define({combine:t=>t.some((t=>t)),static:!0}),tt=R.define({combine:t=>t.length?t[0]:void 0,static:!0}),et=R.define(),it=R.define(),nt=R.define(),st=R.define({combine:t=>!!t.length&&t[0]});class rt{constructor(t,e){this.type=t,this.value=e}static define(){return new ot}}class ot{of(t){return new rt(this,t)}}class lt{constructor(t){this.map=t}of(t){return new at(this,t)}}class at{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 at(this.type,e)}is(t){return this.type==t}static define(t={}){return new lt(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}}at.reconfigure=at.define(),at.appendConfig=at.define();class ht{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&&P(i,e.newLength),s.some((t=>t.type==ht.time))||(this.annotations=s.concat(ht.time.of(Date.now())))}static create(t,e,i,n,s,r){return new ht(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(ht.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function ct(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=ut(n,ft(e,r,t.changes.newLength),!0))}return n==t?t:ht.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(et)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:ct(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=A.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=ht.create(e,n,t.selection&&t.selection.map(s),at.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(it);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof ht?s:Array.isArray(s)&&1==s.length&&s[0]instanceof ht?s[0]:dt(e,gt(s),!1)}return t}(s):s)}ht.time=rt.define(),ht.userEvent=rt.define(),ht.addToHistory=rt.define(),ht.remote=rt.define();const pt=[];function gt(t){return null==t?pt:Array.isArray(t)?t:[t]}var mt=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(mt||(mt={}));const wt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let yt;try{yt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}class vt{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(at.reconfigure)?(i=null,n=e.value):e.is(at.appendConfig)&&(i=null,n=gt(n).concat(e.value));i?e=t.startState.values.slice():(i=J.resolve(n,s,this),e=new vt(i,this.doc,this.selection,i.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values),new vt(i,t.newDoc,t.newSelection,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:B.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=gt(i.effects);for(let i=1;is.spec.fromJSON(r,t))))}return vt.create({doc:t.doc,selection:B.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(e={}){let i=J.resolve(e.extensions||[],new Map),n=e.doc instanceof t?e.doc:t.of((e.doc||"").split(i.staticFacet(vt.lineSeparator)||b)),s=e.selection?e.selection instanceof B?e.selection:B.single(e.selection.anchor,e.selection.head):B.single(0);return P(s,n.length),i.staticFacet(Z)||(s=s.asSingle()),new vt(i,n,s,i.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(vt.tabSize)}get lineBreak(){return this.facet(vt.lineSeparator)||"\n"}get readOnly(){return this.facet(st)}phrase(t,...e){for(let e of this.facet(vt.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(Q))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){return e=this.languageDataAt("wordChars",t).join(""),t=>{if(!/\S/.test(t))return mt.Space;if(function(t){if(yt)return yt.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||wt.test(i)))return!0}return!1}(t))return mt.Word;for(let i=0;i-1)return mt.Word;return mt.Other};var e}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=d(e,r,!1);if(s(e.slice(t,r))!=mt.Word)break;r=t}for(;ot.length?t[0]:4}),vt.lineSeparator=tt,vt.readOnly=st,vt.phrases=R.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]))}}),vt.languageData=Q,vt.changeFilter=et,vt.transactionFilter=it,vt.transactionExtender=nt,G.reconfigure=at.define();class bt{eq(t){return this==t}range(t,e=t){return xt.create(t,e,this)}}bt.prototype.startSide=bt.prototype.endSide=0,bt.prototype.point=!1,bt.prototype.mapMode=x.TrackDel;class xt{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new xt(t,e,i)}}function St(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class At{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 At(n,s,i,o):null,pos:r}}}class Mt{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 Mt(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(St)),this.isEmpty)return e.length?Mt.of(e):this;let o=new Ot(this,null,-1).goto(0),l=0,a=[],h=new Tt;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 Dt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Dt.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=Ct(r,o,i),a=new Lt(r,l,s),h=new Lt(o,l,s);i.iterGaps(((t,e,i)=>Bt(a,t,h,e,i,n))),i.empty&&0==i.length&&Bt(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=Ct(s,r),l=new Lt(s,o,0).goto(i),a=new Lt(r,o,0).goto(i);for(;;){if(l.to!=a.to||!Pt(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 Lt(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 Tt;for(let n of t instanceof xt?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(St);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}}Mt.empty=new Mt([],[],null,-1),Mt.empty.nextLayer=Mt.empty;class Tt{finishChunk(t){this.chunks.push(new At(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 Tt)).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(Mt.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Mt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Ct(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 Ot(r,e,i,s));return 1==n.length?n[0]:new Dt(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--)Et(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--)Et(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(),Et(this.heap,0)}}}function Et(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 Lt{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=Dt.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){Nt(this.active,t),Nt(this.activeTo,t),Nt(this.activeRank,t),this.minActive=It(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e-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&&Nt(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 Bt(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||t.endSide-i.endSide,n=e<0?t.to+a:i.to,s=Math.min(n,o);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&Pt(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,s,t.point,i.point):s>l&&!Pt(t.active,i.active)&&r.compareRange(l,s,t.active,i.active),n>o)break;l=n,e<=0&&t.next(),e>=0&&i.next()}}function Pt(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 It(t,e){let i=-1,n=1e9;for(let s=0;st.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=Vt[zt]||1;return Vt[zt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Wt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new qt(t,s),n.mount(Array.isArray(e)?e:[e])}}let _t=new Map;class qt{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=_t.get(i);if(e)return t.adoptedStyleSheets=[e.sheet,...t.adoptedStyleSheets],t[Wt]=e;this.sheet=new n.CSSStyleSheet,t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets],_t.set(i,this)}else{this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);let n=t.head||t;n.insertBefore(this.styleTag,n.firstChild)}this.modules=[],t[Wt]=this}mount(t){let e=this.sheet,i=0,n=0;for(let s=0;s-1&&(this.modules.splice(o,1),n--,o=-1),-1==o){if(this.modules.splice(n++,0,r),e)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Kt="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),Gt="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Ut=0;Ut<10;Ut++)jt[48+Ut]=jt[96+Ut]=String(Ut);for(Ut=1;Ut<=24;Ut++)jt[Ut+111]="F"+Ut;for(Ut=65;Ut<=90;Ut++)jt[Ut]=String.fromCharCode(Ut+32),$t[Ut]=String.fromCharCode(Ut);for(var Jt in jt)$t.hasOwnProperty(Jt)||($t[Jt]=jt[Jt]);function Yt(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function Xt(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function Qt(t,e){if(!e.anchorNode)return!1;try{return Xt(t,e.anchorNode)}catch(t){return!1}}function Zt(t){return 3==t.nodeType?ce(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function te(t,e,i,n){return!!i&&(ie(t,e,i,n,-1)||ie(t,e,i,n,1))}function ee(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function ie(t,e,i,n,s){for(;;){if(t==i&&e==n)return!0;if(e==(s<0?0:ne(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=ee(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?ne(t):0}}}function ne(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function se(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function re(t){return{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}class oe{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?ne(e):0),i,Math.min(t.focusOffset,i?ne(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let le,ae=null;function he(t){if(t.setActive)return t.setActive();if(ae)return t.focus(ae);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ae?{get preventScroll(){return ae={preventScroll:!0},!0}}:void 0),!ae){ae=!1;for(let t=0;tMath.max(1,t.scrollHeight-t.clientHeight-4)}class pe{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new pe(t.parentNode,ee(t),e)}static after(t,e){return new pe(t.parentNode,ee(t)+1,e)}}const ge=[];class me{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=me.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=we(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=we(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==ne(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&&!me.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=ge){this.markDirty();for(let i=t;ithis.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 ve(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,f=u?u.breakAfter:o;if(!(e==n&&c&&!o&&!f&&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:(i2);var Be={mac:Le||/Mac/.test(be.platform),windows:/Win/.test(be.platform),linux:/Linux|X11/.test(be.platform),ie:Te,ie_version:Ae?xe.documentMode||6:Me?+Me[1]:Se?+Se[1]:0,gecko:Ce,gecko_version:Ce?+(/Firefox\/(\d+)/.exec(be.userAgent)||[0,0])[1]:0,chrome:!!Oe,chrome_version:Oe?+Oe[1]:0,ios:Le,android:/Android\b/.test(be.userAgent),webkit:De,safari:Ee,webkit_version:De?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:null!=xe.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Pe extends me{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return!(8&this.flags||i&&(!(i instanceof Pe)||this.length-(e-t)+i.length>256||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 Pe(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 pe(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];return Be.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,(t=>t.width))||a),o?se(a,o<0):a||null}(this.dom,t,e)}}class Ne extends me{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(fe(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 Ne&&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 Ne(this.mark,e,r)}domAtPos(t){return He(this,t)}coordsAt(t,e){return We(this,t,e)}}class Re extends me{static create(t,e,i){return new Re(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Re.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.dom.contentEditable="false")}getSide(){return this.side}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof Re&&this.widget.compare(i.widget))||t>0&&s<=0||e0)?pe.before(this.dom):pe.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?pe.before(this.dom):pe.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return t.empty}get isHidden(){return!0}}function He(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 Ne&&s.length&&(n=s[s.length-1])instanceof Ne&&n.mark.eq(e.mark)?ze(n,e.children[0],i-1):(s.push(e),e.setParent(t)),t.length+=e.length}function We(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)&&(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 qe(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 je(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new Ye(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}=Xe(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new Ye(t,e,i,n,t.widget||null,!0)}static line(t){return new Je(t)}static set(t,e=!1){return Mt.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}Ge.none=Mt.empty;class Ue extends Ge{constructor(t){let{start:e,end:i}=Xe(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 Ue&&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))&&_e(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)}}Ue.prototype.point=!1;class Je extends Ge{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Je&&this.spec.class==t.spec.class&&_e(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)}}Je.prototype.mapMode=x.TrackBefore,Je.prototype.point=!0;class Ye extends Ge{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?x.TrackBefore:x.TrackAfter:x.TrackDel}get type(){return this.startSide=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Ye&&((e=this.widget)==(i=t.widget)||!!(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 Xe(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 Qe(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)}Ye.prototype.point=!0;class Ze extends me{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 Ze))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),ke(this,t,e,i?i.children:[],s,r),!0}split(t){let e=new Ze;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{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){_e(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){ze(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Ve(e,this.attrs||{})),i&&(this.attrs=Ve({class:i},this.attrs||{}))}domAtPos(t){return He(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(fe(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&&(qe(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&&me.get(n)instanceof Ne;)n=n.lastChild;if(!(n&&this.length&&("BR"==n.nodeName||0!=(null===(i=me.get(n))||void 0===i?void 0:i.isEditable)||Be.ios&&this.children.some((t=>t instanceof Pe))))){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 Pe)||/[^ -~]/.test(i.text))return null;let n=Zt(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=We(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 Ze)return s;if(r>e)break}n=r+s.breakAfter}return null}}class ti extends me{constructor(t,e,i){super(),this.widget=t,this.length=e,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof ti&&this.widget.compare(i.widget))||t>0&&s<=0||e0;){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,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(ii(new Pe(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}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 Ye){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 Ye)if(i.block){let{type:t}=i;t!=Ke.WidgetAfter||this.posCovered()||this.getLine(),this.addBlockWidget(new ti(i.widget||new ni("div"),o,t))}else{let r=Re.create(i.widget||new ni("span"),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(ii(new Ie(1),n),s),s=n.length+Math.max(0,s-n.length)),h.append(ii(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 ei(t,e,i,s);return r.openEnd=Mt.spans(n,e,i,r),r.openStart<0&&(r.openStart=r.openEnd),r.finish(r.openEnd),r}}function ii(t,e){for(let i of e)t=new Ne(i,[t],t.length);return t}class ni extends $e{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}}const si=R.define(),ri=R.define(),oi=R.define(),li=R.define(),ai=R.define(),hi=R.define(),ci=R.define(),ui=R.define({combine:t=>t.some((t=>t))}),fi=R.define({combine:t=>t.some((t=>t))});class di{constructor(t,e="nearest",i="nearest",n=5,s=5){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s}map(t){return t.empty?this:new di(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin)}}const pi=at.define({map:(t,e)=>t.map(e)});function gi(t,e,i){let n=t.facet(li);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 mi=R.define({combine:t=>!t.length||t[0]});let wi=0;const yi=R.define();class vi{constructor(t,e,i,n){this.id=t,this.create=e,this.domEventHandlers=i,this.extension=n(this)}static define(t,e){const{eventHandlers:i,provide:n,decorations:s}=e||{};return new vi(wi++,t,i,(t=>{let e=[yi.of(t)];return s&&e.push(Si.of((e=>{let i=e.plugin(t);return i?s(i):Ge.none}))),n&&e.push(n(t)),e}))}static fromClass(t,e){return vi.define((e=>new t(e)),e)}}class ki{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}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(gi(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.create(t)}catch(e){gi(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){gi(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const bi=R.define(),xi=R.define(),Si=R.define(),Ai=R.define(),Mi=R.define();function Ti(t,e,i){let n=t.state.facet(Mi);if(!n.length)return n;let s=n.map((e=>e instanceof Function?e(t):e)),r=[];return Mt.spans(s,e,i,{point(){},span(t,e,i,n){let s=r;for(let r=i.length-1;r>=0;r--,n--){let o,l=i[r].spec.bidiIsolate;if(null!=l)if(n>0&&s.length&&(o=s[s.length-1]).to==t&&o.direction==l)o.to=e,s=o.inner;else{let i={from:t,to:e,direction:l,inner:[]};s.push(i),s=i.inner}}}}),r}const Ci=R.define();function Oi(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(Ci)){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 Di=R.define();class Ei{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new Ei(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 Ei(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),r=l.toA,o=l.toB}}}class Li{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=A.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 Ei(t,e,i,s)))),this.changedRanges=n}static create(t,e,i){return new Li(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&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}}var Bi=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(Bi||(Bi={}));const Pi=Bi.LTR,Ni=Bi.RTL;function Ri(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 _i(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new Fi(a,p.from,f)),$i(t,p.direction==Pi!=!(f%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to),d=p.to}else{if(d==i||(e?qi[d]!=l:qi[d]==l))break;d++}u?ji(t,a,d,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=qi[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],f=i?n:n+1,d=a;t:for(;;)if(h&&d==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(qi[t-1]==l)break t;break}t=r[--i].from}u?u.push(p):(p.to=0;t-=3)if(Wi[t+1]==-i){let e=Wi[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(qi[o]=qi[Wi[t]]=i),l=t;break}}else{if(189==Wi.length)break;Wi[l++]=o,Wi[l++]=e,Wi[l++]=a}else if(2==(n=qi[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Wi[e+2];if(2&i)break;if(t)Wi[e+2]|=2;else{if(4&i)break;Wi[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),qi[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),ji(t,s,r,e,i,n,o)}function Ki(t){return[new Fi(0,t,0)]}let Gi="";function Ui(t,e,i,n,s){var r;let o=n.head-t.from,l=-1;if(0==o){if(!s||!t.length)return null;e[0].level!=i&&(o=e[0].side(!1,i),l=0)}else if(o==t.length){if(s)return null;let t=e[e.length-1];t.level!=i&&(o=t.side(!0,i),l=e.length-1)}l<0&&(l=Fi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc));let a=e[l];o==a.side(s,i)&&(a=e[l+=s?1:-1],o=a.side(!s,i));let h=s==(a.dir==i),c=d(t.text,o,h);if(Gi=t.text.slice(Math.min(o,c),Math.max(o,c)),c!=a.side(s,i))return B.cursor(c+t.from,h?-1:1,a.level);let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u||a.level==i?u&&u.level0&&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);let n=-1;this.view.inputState.composing>=0&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;return e&&t.iterChangedRanges(((t,n)=>{te.from&&(i=!0)})),i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=Xi(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 Ei(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let e=s.parentNode;;e=e.parentNode){let i=me.get(e);if(i instanceof Ne)c.push({node:e,deco:i.mark});else{if(i instanceof Ze||"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 Ue({inclusive:!0,attributes:je(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 Ei(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 Zi;return Mt.compare(t,e,i,n),n.changes}(this.decorations,this.updateDeco(),t.changes);return i=Ei.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:f}=e;if(i&&i.range.fromBu){let t=ei.build(this.view.state.doc,u,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=ei.build(this.view.state.doc,i.range.toB,f,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}=ei.build(this.view.state.doc,u,f,this.decorations,this.dynamicDecorationMap));let{i:d,off:p}=s.findPos(c,1),{i:g,off:m}=s.findPos(h,-1);ve(this,g,m,d,p,r,o,l,a)}i&&this.fixCompositionDOM(i)}compositionView(t){let e=new Pe(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new Ne(i,[e],e.length);let i=new Ze;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=me.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&&Qt(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 pe(t,0),r=!0}var h;let c=this.view.observer.selectionRange;!r&&c.focusNode&&te(l.node,l.offset,c.anchorNode,c.anchorOffset)&&te(a.node,a.offset,c.focusNode,c.focusOffset)||(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=Yt(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)}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 pe(c.anchorNode,c.anchorOffset),this.impreciseHead=a.precise?null:new pe(c.focusNode,c.focusOffset)}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Yt(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=Ze.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=me.get(i.childNodes[n]);t instanceof Ze&&(e=t.domAtPos(t.length))}return e?new pe(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=me.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(;er||t==r&&s.type!=Ke.WidgetBefore&&s.type!=Ke.WidgetAfter&&(!n||2==e||this.children[n-1].breakAfter||this.children[n-1].type==Ke.WidgetBefore&&e>-2))return s.coordsAt(t-r,e);i=r}}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof Ze))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 Pe))return null;let s=d(n.text,i);if(s==i)return null;let r=ce(n.dom,i,s).getClientRects();return!r.length||r[0].top>=r[0].bottom?null:r[0]}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,s=this.view.contentDOM.clientWidth,r=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==Bi.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?Zt(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?Bi.RTL:Bi.LTR}measureTextSize(){for(let t of this.children)if(t instanceof Ze){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=Zt(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 ye(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(Ge.replace({widget:new Yi(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return Ge.set(t)}updateDeco(){let t=this.view.state.facet(Si).map(((t,e)=>(this.dynamicDecorationMap[e]="function"==typeof t)?t(this.view):t));for(let e=t.length;ei.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=Oi(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom};!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,f=c==a.body,d=1,p=1;if(f)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();d=e.width/c.offsetWidth,p=e.height/c.offsetHeight,t={left:e.left,right:e.left+c.clientWidth*d,top:e.top,bottom:e.top+c.clientHeight*p}}let g=0,m=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+m&&(m=e.bottom-t.bottom+m+o)):e.bottom>t.bottom&&(m=e.bottom-t.bottom+o,i<0&&e.top-m0&&e.right>t.right+g&&(g=e.right-t.right+g+r)):e.right>t.right&&(g=e.right-t.right+r,i<0&&e.left0))break;i=i.childNodes[n-1],n=ne(i)}if(i>=0)for(let n=t,s=e;;){if(3==n.nodeType)return{node:n,offset:s};if(!(1==n.nodeType&&s=0))break;n=n.childNodes[s],s=0}return null}let Zi=class{constructor(){this.changes=[]}compareRange(t,e){Qe(t,e,this.changes)}comparePoint(t,e){Qe(t,e,this.changes)}};function tn(t,e){return e.left>t?e.left-t:Math.max(0,t-e.right)}function en(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function nn(t,e){return t.tope.top+1}function sn(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 f=t.firstChild;f;f=f.nextSibling){let t=Zt(f);for(let d=0;dm||o==m&&r>g){n=f,s=p,r=g,o=m;let l=m?i0?d0)}0==g?i>p.bottom&&(!h||h.bottomp.top)&&(a=f,c=p):h&&nn(h,p)?h=rn(h,p.bottom):c&&nn(c,p)&&(c=sn(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 f=Math.max(s.left,Math.min(s.right,e));return 3==n.nodeType?ln(n,f,i):u&&"false"!=n.contentEditable?on(n,f,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,n)+(e>=(s.left+s.right)/2?1:0)}}function ln(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)&&ce(t,l).getBoundingClientRect().left==h.right&&(n=!i),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 an(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,f=u-a;if(f<0)return 0;if(f>h)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,s=!1;o=t.elementAtHeight(f),o.type!=Ke.Text;)for(;f=n>0?o.bottom+e:o.top-e,!(f>=0&&f<=h);){if(s)return i?null:0;s=!0,n=-n}u=a+f;let d=o.from;if(dt.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:hn(t,l,o,c,u);let p=t.dom.ownerDocument,g=t.root.elementFromPoint?t.root:p,m=g.elementFromPoint(c,u);m&&!t.contentDOM.contains(m)&&(m=null),m||(c=Math.max(l.left+1,Math.min(l.right-1,c)),m=g.elementFromPoint(c,u),m&&!t.contentDOM.contains(m)&&(m=null));let w,y=-1;if(m&&0!=(null===(s=t.docView.nearest(m))||void 0===s?void 0:s.isEditable))if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(c,u);t&&({offsetNode:w,offset:y}=t)}else if(p.caretRangeFromPoint){let e=p.caretRangeFromPoint(c,u);e&&(({startContainer:w,startOffset:y}=e),(!t.contentDOM.contains(w)||Be.safari&&function(t,e,i){let n;if(3!=t.nodeType||e!=(n=t.nodeValue.length))return!1;for(let e=t.nextSibling;e;e=e.nextSibling)if(1!=e.nodeType||"BR"!=e.nodeName)return!1;return ce(t,n-1,n).getBoundingClientRect().left>i}(w,y,c)||Be.chrome&&function(t,e,i){if(0!=e)return!1;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}return i-(1==t.nodeType?t.getBoundingClientRect():ce(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect()).left>5}(w,y,c))&&(w=void 0))}if(!w||!t.docView.dom.contains(w)){let e=Ze.find(t.docView,d);if(!e)return f>o.top+o.height/2?o.to:o.from;({node:w,offset:y}=on(e.dom,c,u))}let v=t.docView.nearest(w);if(!v)return null;if(v.isWidget&&1==(null===(r=v.dom)||void 0===r?void 0:r.nodeType)){let t=v.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+function(t,e,i,n){for(let n=0,s=0;;){if(s>=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=d(t,n)}return t.length}(o,r,t.state.tabSize)}function cn(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=Ui(s,r,o,l,i),h=Gi;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=B.cursor(i?s.from:s.to)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function un(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:B.cursor(n,n{this.ignoreDuringComposition(i)||"keydown"==i.type&&this.keydown(t,i)||(this.mustFlushObserver(i)&&t.observer.forceFlush(),this.runCustomHandlers(i.type,t,i)?i.preventDefault():e(t,i))};for(let i in kn){let n=kn[i];t.contentDOM.addEventListener(i,(i=>{vn(t,i)&&e(n,i)}),bn[i]),this.registeredEvents.push(i)}t.scrollDOM.addEventListener("mousedown",(i=>{if(i.target==t.scrollDOM&&i.clientY>t.contentDOM.getBoundingClientRect().bottom&&(e(kn.mousedown,i),!i.defaultPrevented&&2==i.button)){let e=t.contentDOM.style.minHeight;t.contentDOM.style.minHeight="100%",setTimeout((()=>t.contentDOM.style.minHeight=e),200)}})),t.scrollDOM.addEventListener("drop",(i=>{i.target==t.scrollDOM&&i.clientY>t.contentDOM.getBoundingClientRect().bottom&&e(kn.drop,i)})),Be.chrome&&102==Be.chrome_version&&t.scrollDOM.addEventListener("wheel",(()=>{this.chromeScrollHack<0?t.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout((()=>{this.chromeScrollHack=-1,t.contentDOM.style.pointerEvents=""}),100)}),{passive:!0}),this.notifiedFocused=t.hasFocus,Be.safari&&t.contentDOM.addEventListener("input",(()=>null)),Be.gecko&&function(t){Wn.has(t)||(Wn.add(t),t.addEventListener("copy",(()=>{})),t.addEventListener("cut",(()=>{})))}(t.contentDOM.ownerDocument)}ensureHandlers(t,e){var i;let n;this.customHandlers=[];for(let s of e)if(n=null===(i=s.update(t).spec)||void 0===i?void 0:i.domEventHandlers){this.customHandlers.push({plugin:s.value,handlers:n});for(let e in n)this.registeredEvents.indexOf(e)<0&&"scroll"!=e&&(this.registeredEvents.push(e),t.contentDOM.addEventListener(e,(i=>{vn(t,i)&&this.runCustomHandlers(e,t,i)&&i.preventDefault()})))}}runCustomHandlers(t,e,i){for(let n of this.customHandlers){let s=n.handlers[t];if(s)try{if(s.call(n.plugin,i,e)||i.defaultPrevented)return!0}catch(t){gi(e.state,t)}}return!1}runScrollHandlers(t,e){this.lastScrollTop=t.scrollDOM.scrollTop,this.lastScrollLeft=t.scrollDOM.scrollLeft;for(let i of this.customHandlers){let n=i.handlers.scroll;if(n)try{n.call(i.plugin,e,t)}catch(e){gi(t.state,e)}}}keydown(t,e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&Date.now()t.keyCode==e.keyCode)))&&!e.ctrlKey||gn.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)||(this.pendingIOSKey=i||e,setTimeout((()=>this.flushIOSKey(t)),250),0))}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(this.pendingIOSKey=void 0,ue(t.contentDOM,e.key,e.keyCode))}ignoreDuringComposition(t){return!!/^key/.test(t.type)&&(this.composing>0||!!(Be.safari&&!Be.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}mustFlushObserver(t){return"keydown"==t.type&&229!=t.keyCode}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.mouseSelection&&this.mouseSelection.update(t),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const pn=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],gn="dthko",mn=[16,17,18,20,91,92,224,225];function wn(t){return.7*Math.max(0,t)+8}class yn{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.scrollParent=function(t){let e=t.ownerDocument;for(let i=t.parentNode;i&&i!=e.body;)if(1==i.nodeType){if(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.assignedSlot||i.parentNode}else{if(11!=i.nodeType)break;i=i.host}return null}(t.contentDOM),this.atoms=t.state.facet(Ai).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(vt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(si);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=Yt(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!=Pn(e))&&null}start(t){!1===this.dragging&&(t.preventDefault(),this.select(t))}move(t){var e,i,n;if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(i=this.startEvent,n=t,Math.max(Math.abs(i.clientX-n.clientX),Math.abs(i.clientY-n.clientY))<10))return;this.select(this.lastEvent=t);let s=0,r=0,o=(null===(e=this.scrollParent)||void 0===e?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},l=Oi(this.view);t.clientX-l.left<=o.left+6?s=-wn(o.left-t.clientX):t.clientX+l.right>=o.right-6&&(s=wn(t.clientX-o.right)),t.clientY-l.top<=o.top+6?r=-wn(o.top-t.clientY):t.clientY+l.bottom>=o.bottom-6&&(r=wn(t.clientY-o.bottom)),this.setScrollSpeed(s,r)}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=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(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;ithis.select(this.lastEvent)),20)}}function vn(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=me.get(n))&&i.ignoreEvent(e))return!1;return!0}const kn=Object.create(null),bn=Object.create(null),xn=Be.ie&&Be.ie_version<15||Be.ios&&Be.webkit_version<604;function Sn(t,e){let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=Rn&&n.selection.ranges.every((t=>t.empty))&&Rn==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:B.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:B.cursor(t.from+e.length)}})):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function An(t,e,i,n){if(1==n)return B.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 B.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=d(s.text,r,!1):l=d(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=d(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{t.inputState.setSelectionOrigin("select"),27==e.keyCode&&(t.inputState.lastEscPress=Date.now())},kn.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},kn.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},bn.touchstart=bn.touchmove={passive:!0},kn.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return;let i=null;for(let n of t.state.facet(oi))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=On(t,e),n=Pn(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=On(t,e),h=An(t,a.pos,a.bias,n);if(i.pos!=a.pos&&!r){let e=An(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 B.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):B.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new yn(t,e,i,n)),n&&t.observer.ignore((()=>he(t.contentDOM))),t.inputState.mouseSelection&&t.inputState.mouseSelection.start(e)}};let Mn=(t,e)=>t>=e.top&&t<=e.bottom,Tn=(t,e,i)=>Mn(e,i)&&t>=i.left&&t<=i.right;function Cn(t,e,i,n){let s=Ze.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&&Tn(i,n,o))return-1;let l=s.coordsAt(r,1);return l&&Tn(i,n,l)?1:o&&Mn(n,o)?-1:1}function On(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:Cn(t,i,e.clientX,e.clientY)}}const Dn=Be.ie&&Be.ie_version<=11;let En=null,Ln=0,Bn=0;function Pn(t){if(!Dn)return t.detail;let e=En,i=Bn;return En=t,Bn=Date.now(),Ln=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Ln+1)%3:1}function Nn(t,e,i,n){if(!i)return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:r}=t.inputState,o=n&&r&&r.dragging&&function(t,e){let i=t.state.facet(ri);return i.length?i[0](e):Be.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.dragging.from,to:r.dragging.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"})}kn.dragstart=(t,e)=>{let{selection:{main:i}}=t.state,{mouseSelection:n}=t.inputState;n&&(n.dragging=i),e.dataTransfer&&(e.dataTransfer.setData("Text",t.state.sliceDoc(i.from,i.to)),e.dataTransfer.effectAllowed="copyMove")},kn.drop=(t,e)=>{if(!e.dataTransfer)return;if(t.state.readOnly)return e.preventDefault();let i=e.dataTransfer.files;if(i&&i.length){e.preventDefault();let n=Array(i.length),s=0,r=()=>{++s==i.length&&Nn(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])}}else Nn(t,e,e.dataTransfer.getData("Text"),!0)},kn.paste=(t,e)=>{if(t.state.readOnly)return e.preventDefault();t.observer.flush();let i=xn?null:e.clipboardData;i?(Sn(t,i.getData("text/plain")||i.getData("text/uri-text")),e.preventDefault()):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(),Sn(t,i.value)}),50)}(t)};let Rn=null;kn.copy=kn.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:e.join(t.lineBreak),ranges:i,linewise:n}}(t.state);if(!i&&!s)return;Rn=s?i:null;let r=xn?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",i)):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),"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"})};const In=rt.define();function Hn(t,e){let i=[];for(let n of t.facet(ci)){let s=n(t,e);s&&i.push(s)}return i?t.update({effects:i,annotations:In.of(!0)}):null}function zn(t){setTimeout((()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=Hn(t.state,e);i?t.dispatch(i):t.update([])}}),10)}kn.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),zn(t)},kn.blur=t=>{t.observer.clearSelectionRange(),zn(t)},kn.compositionstart=kn.compositionupdate=t=>{null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0)},kn.compositionend=t=>{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)},kn.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},kn.beforeinput=(t,e)=>{var i;let n;if(Be.chrome&&Be.android&&(n=pn.find((t=>t.inputType==e.inputType)))&&(t.observer.delayAndroidKey(n.key,n.keyCode),"Backspace"==n.key||"Delete"==n.key)){let e=(null===(i=window.visualViewport)||void 0===i?void 0:i.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)}};const Wn=new Set,Vn=["pre-wrap","normal","pre-line","break-spaces"];class Fn{constructor(e){this.lineWrapping=e,this.doc=t.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}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){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Vn.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,e){this.height!=e&&(Math.abs(this.height-e)>$n&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return Kn.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,jn.ByPosNoHeight,i.setDoc(e),0,0),f=u.to>=a?u:s.lineAt(a,jn.ByPosNoHeight,i,0,0);for(c+=f.to-a,a=f.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(t,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Un extends Gn{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new qn(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Un||n instanceof Jn&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Jn?n=new Un(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Kn.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(t,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(t,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 Jn extends Kn{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+Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length),r=e.doc.lineAt(s),a=o+r.length*l,h=Math.max(i,t-a/2);return new qn(r.from,r.length,h,a,0)}{let n=Math.max(0,Math.min(r-s,Math.floor((t-i)/o))),{from:l,length:a}=e.doc.line(s+n);return new qn(l,a,i+o*n,o,0)}}lineAt(t,e,i,n,s){if(e==jn.ByHeight)return this.blockAt(t,i,n,s);if(e==jn.ByPosNoHeight){let{from:e,to:n}=i.doc.lineAt(t);return new qn(e,n-e,0,0,0)}let{firstLine:r,perLine:o,perChar:l}=this.heightMetrics(i,s),a=i.doc.lineAt(t),h=o+a.length*l,c=a.number-r,u=n+o*c+l*(a.from-s-c);return new qn(a.from,a.length,Math.max(n,Math.min(u,n+this.height-h)),h,0)}forEachLine(t,e,i,n,s,r){t=Math.max(t,s),e=Math.min(e,s+this.length);let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,s);for(let h=t,c=n;h<=e;){let e=i.doc.lineAt(h);if(h==t){let i=e.number-o;c+=l*i+a*(t-s-i)}let n=l+a*e.length;r(new qn(e.from,e.length,c,n,0)),c+=n,h=e.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let t=i[i.length-1];t instanceof Jn?i[i.length-1]=new Jn(t.length+n):i.push(null,new Jn(n-1))}if(t>0){let e=i[0];e instanceof Jn?i[0]=new Jn(t+e.length):i.unshift(new Jn(t-1),null)}return Kn.of(i)}decomposeLeft(t,e){e.push(new Jn(t-1),null)}decomposeRight(t,e){e.push(null,new Jn(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 Jn(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)>=$n&&(o=-2);let l=new Un(e,s);l.outdated=!1,i.push(l),r+=e+1}r<=s&&i.push(null,new Jn(s-r).updateHeight(t,r));let l=Kn.of(i);return(o<0||Math.abs(l.height-this.height)>=$n||Math.abs(o-this.heightMetrics(t,e).perLine)>=$n)&&(t.heightChanged=!0),l}return(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Yn extends Kn{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==jn.ByPosNoHeight?jn.ByPosNoHeight:jn.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,jn.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&&Xn(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?Kn.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=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 Xn(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Jn&&(n=t[e+1])instanceof Jn&&t.splice(e-1,3,new Jn(i.length+1+n.length))}class Qn{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 Un?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Un(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 Un(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Jn(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 Un)return t;let e=new Un(0,-1);return this.nodes.push(e),e}addBlock(t){var e;this.enterLine();let i=null===(e=t.deco)||void 0===e?void 0:e.type;i!=Ke.WidgetAfter||this.isCovered||this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,i!=Ke.WidgetBefore&&(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 Un||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=e==t.parentNode?n.bottom:Math.min(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 es(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class is{constructor(t,e,i){this.from=t,this.to=e,this.size=i}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 Fn(i),this.stateDeco=e.facet(Si).filter((t=>"function"!=typeof t)),this.heightMap=Kn.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle.setDoc(e.doc),[new Ei(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ge.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 rs(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from)),this.scaler=this.heightMap.height<=7e6?hs:new cs(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(t=>{this.viewportLines.push(1==this.scaler.scale?t:us(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Si).filter((t=>"function"!=typeof t));let n=t.changedRanges,s=Ei.extendWithRanges(n,function(t,e,i){let n=new Zn;return Mt.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:A.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=r&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);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=!t.changes.empty||2&t.flags||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),a&&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(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(fi)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let i=e.contentDOM,n=window.getComputedStyle(i),s=this.heightOracle,r=n.whiteSpace;this.defaultTextDirection="rtl"==n.direction?Bi.RTL:Bi.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=i.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let t=l.width/i.offsetWidth,e=l.height/i.offsetHeight;t>.995&&t<1.005&&(t=1),e>.995&&e<1.005&&(e=1),this.scaleX==t&&this.scaleY==e||(this.scaleX=t,this.scaleY=e,h|=8,o=a=!0)}let u=(parseInt(n.paddingTop)||0)*this.scaleY,f=(parseInt(n.paddingBottom)||0)*this.scaleY;this.paddingTop==u&&this.paddingBottom==f||(this.paddingTop=u,this.paddingBottom=f,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=de(e.scrollDOM);let p=(this.printing?es:ts)(i,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let y=l.width;if(this.contentDOMWidth==y&&this.editorHeight==e.scrollDOM.clientHeight||(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let i=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(i)&&(o=!0),o||s.lineWrapping&&Math.abs(y-this.contentDOMWidth)>s.charWidth){let{lineHeight:t,charWidth:n,textHeight:l}=e.docView.measureTextSize();o=t>0&&s.refresh(r,t,n,l,y/n,i),o&&(e.docView.minWidth=0,h|=8)}g>0&&m>0?c=Math.max(g,m):g<0&&m<0&&(c=Math.min(g,m)),s.heightChanged=!1;for(let n of this.viewports){let r=n.from==this.viewport.from?i:e.docView.measureVisibleLineHeights(n);this.heightMap=(o?Kn.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle,[new Ei(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new _n(n.from,r))}s.heightChanged&&(h|=2)}let v=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return v&&(this.viewport=this.getViewport(c,this.scrollTarget)),this.updateForViewport(),(2&h||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(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 rs(n.lineAt(r-1e3*i,jn.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),jn.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,jn.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!=Bi.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(!f){if(rt.from<=r&&t.to>=r))){let t=e.moveToLineBoundary(B.cursor(r),!1,!0).head;t>n&&(r=t)}f=new is(n,r,this.gapSize(a,n,r,h))}o.push(f)};for(let t of this.viewportLines){if(t.lengtht.from&&l(t.from,s,t,e),ot.draw(this,this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];Mt.spans(t,this.viewport.from,this.viewport.to,{span(t,i){e.push({from:t,to:i})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some(((t,i)=>t.from!=e[i].from||t.to!=e[i].to));return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find((e=>e.from<=t&&e.to>=t))||us(this.heightMap.lineAt(t,jn.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return us(this.heightMap.lineAt(this.scaler.fromDOM(t),jn.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 us(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 rs{constructor(t,e){this.from=t,this.to=e}}function os(t,e,i){let n=[],s=t,r=0;return Mt.spans(i,t,e,{span(){},point(t,e){t>s&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s=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 as(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 hs={toDOM:t=>t,fromDOM:t=>t,scale:1};class cs{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map((({from:i,to:s})=>{let r=e.lineAt(i,jn.ByPos,t,0,0).top,o=e.lineAt(s,jn.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=eus(t,e))):t._content)}const fs=R.define({combine:t=>t.join(" ")}),ds=R.define({combine:t=>t.indexOf(!0)>-1}),ps=Ft.newName(),gs=Ft.newName(),ms=Ft.newName(),ws={"&light":"."+gs,"&dark":"."+ms};function ys(t,e,i){return new Ft(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 vs=ys("."+ps,{"&":{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},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",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:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},"&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",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&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},"&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-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"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".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"}},ws),ks="￿";class bs{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(vt.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=ks}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let t=this.text.length;this.readNode(n);let s=n.nextSibling;if(s==e)break;let r=me.get(n),o=me.get(s);(r&&o?r.breakAfter:(r?r.breakAfter:xs(n))||xs(s)&&("BR"!=n.nodeName||n.cmIgnore)&&this.text.length>t)&&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=me.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+Math.min(e,i.offset))}}function xs(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}class Ss{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class As{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="";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;return i&&(e.push(new Ss(i,n)),s==i&&r==n||e.push(new Ss(s,r))),e}(t),i=new bs(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?B.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||!Xt(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||!Xt(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset);this.newSel=B.single(n,i)}}}function Ms(e,i){let n,{newSel:s}=i,r=e.state.selection.main,o=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(i.bounds){let{from:s,to:l}=i.bounds,a=r.from,h=null;(8===o||Be.android&&i.text.length0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;return"end"==n&&(i-=o+Math.max(0,r-Math.min(o,l))-r),o=o?r-i:0,l=r+(l-o),o=r):l=l?r-i:0,o=r+(o-l),l=r),{from:r,toA:o,toB:l}}(e.state.doc.sliceString(s,l,ks),i.text,a-s,h);c&&(Be.chrome&&13==o&&c.toB==c.from+2&&i.text.slice(c.from,c.toB)==ks+ks&&c.toB--,n={from:s+c.from,to:s+c.toA,insert:t.of(i.text.slice(c.from,c.toB).split(ks))})}else s&&(!e.hasFocus&&e.state.facet(mi)||s.main.eq(r))&&(s=null);if(!n&&!s)return!1;if(!n&&i.typeOver&&!r.empty&&s&&s.main.empty?n={from:r.from,to:r.to,insert:e.state.doc.slice(r.from,r.to)}:n&&n.from>=r.from&&n.to<=r.to&&(n.from!=r.from||n.to!=r.to)&&r.to-r.from-(n.to-n.from)<=4?n={from:r.from,to:r.to,insert:e.state.doc.slice(r.from,n.from).append(n.insert).append(e.state.doc.slice(n.to,r.to))}:(Be.mac||Be.android)&&n&&n.from==n.to&&n.from==r.head-1&&/^\. ?$/.test(n.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(s&&2==n.insert.length&&(s=B.single(s.main.anchor-1,s.main.head-1)),n={from:r.from,to:r.to,insert:t.of([" "])}):Be.chrome&&n&&n.from==n.to&&n.from==r.head&&"\n "==n.insert.toString()&&e.lineWrapping&&(s&&(s=B.single(s.main.anchor-1,s.main.head-1)),n={from:r.from,to:r.to,insert:t.of([" "])}),n){if(Be.ios&&e.inputState.flushIOSKey(e))return!0;if(Be.android&&(n.from==r.from&&n.to==r.to&&1==n.insert.length&&2==n.insert.lines&&ue(e.contentDOM,"Enter",13)||(n.from==r.from-1&&n.to==r.to&&0==n.insert.length||8==o&&n.insert.lengthr.head)&&ue(e.contentDOM,"Backspace",8)||n.from==r.from&&n.to==r.to+1&&0==n.insert.length&&ue(e.contentDOM,"Delete",46)))return!0;let t,i=n.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let l=()=>t||(t=function(t,e,i){let n,s=t.state,r=s.selection.main;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&&Xi(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,f=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!=f||t.state.sliceDoc(c,n)!=h||i.to>=a.from&&i.from<=a.to)return{range:i};let d=s.changes({from:c,to:n,insert:e.insert}),p=i.to-r.to;return{changes:d,range:l?B.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(d)}}))}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let o="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),s.update(n,{userEvent:o,scrollIntoView:!0})}(e,n,s));return e.state.facet(hi).some((t=>t(e,n.from,n.to,i,l)))||e.dispatch(l()),!0}if(s&&!s.main.eq(r)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin),e.dispatch({selection:s,scrollIntoView:t,userEvent:i}),!0}return!1}const Ts={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Cs=Be.ie&&Be.ie_version<=11;class Os{constructor(t){this.view=t,this.active=!1,this.selectionRange=new oe,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.resizeContent=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],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()})),Cs&&(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),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver((()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate)this.view.requestMeasure())),this.resizeContent.observe(t.contentDOM)),this.addWindowListeners(this.win=t.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver((t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runScrollHandlers(this.view,t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(){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(mi)?i.root.activeElement!=this.dom:!Qt(i.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&&te(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Be.safari&&11==t.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t){let e=null;function i(t){t.preventDefault(),t.stopImmediatePropagation(),e=t.getTargetRanges()[0]}if(t.contentDOM.addEventListener("beforeinput",i,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",i,!0),!e)return null;let n=e.startContainer,s=e.startOffset,r=e.endContainer,o=e.endOffset,l=t.docView.domAtPos(t.state.selection.main.anchor);return te(l.node,l.offset,r,o)&&([n,s,r,o]=[r,o,n,s]),{anchorNode:n,anchorOffset:s,focusNode:r,focusOffset:o}}(this.view)||Yt(t.root);if(!e||this.selectionRange.eq(e))return!1;let i=Qt(this.dom,e);return i&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;t&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&ue(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&&Qt(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 As(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!1;let i=this.view.state,n=Ms(this.view,e);return this.view.state==i&&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=Ds(e,t.previousSibling||t.target.previousSibling,-1),n=Ds(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),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),t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var t,e,i,n;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(),null===(n=this.resizeContent)||void 0===n||n.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)}}function Ds(t,e,i){for(;e;){let n=me.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}class Es{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.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: fixed; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(t=>t.forEach((t=>e(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 ss(t.state||vt.create(t)),this.plugins=this.state.facet(yi).map((t=>new ki(t)));for(let t of this.plugins)t.update(this);this.observer=new Os(this),this.inputState=new dn(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new Ji(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),t.parent&&t.parent.appendChild(this.dom)}dispatch(...t){let e=1==t.length&&t[0]instanceof ht?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(In)))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=Hn(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(vt.phrases)!=this.state.facet(vt.phrases))return this.setState(s);e=Li.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 di(t.empty?t:B.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(pi)&&(c=t.value)}this.viewState.update(e,c),this.bidiCache=Ps.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(Di)!=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(fs)!=e.state.facet(fs)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!e.empty)for(let t of this.state.facet(ai))t(e);(l||h)&&Promise.resolve().then((()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!Ms(this,h)&&a.force&&ue(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 ss(t),this.plugins=t.facet(yi).map((t=>new ki(t))),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView=new Ji(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(yi),i=t.state.facet(yi);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new ki(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(),this.inputState.ensureHandlers(this,this.plugins)}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(de(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 gi(this.state,t),Bs}})),h=Li.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));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(ai))t(e)}get themeClasses(){return ps+" "+(this.state.facet(ds)?ms:gs)+" "+this.state.facet(fs)}updateAttrs(){let t=Ns(this,bi,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(mi)?"true":"false",class:"cm-content",style:`${Be.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Ns(this,xi,e);let i=this.observer.ignore((()=>{let i=qe(this.contentDOM,this.contentAttrs,e),n=qe(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)t.is(Es.announce)&&(e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value)}mountStyles(){this.styleModules=this.state.facet(Di);let t=this.state.facet(Es.cspNonce);Ft.mount(this.root,this.styleModules.concat(vs).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.spec==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 fn(this,t,cn(this,t,e,i))}moveByGroup(t,e){return fn(this,t,cn(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==mt.Space&&(s=e),s==e}}(this,t.head,e))))}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=function(t,e){let i=t.lineBlockAt(e);if(Array.isArray(i.type))for(let t of i.type)if(t.to>e||t.to==e&&(t.to==i.to||t.type==Ke.Text))return t;return i}(t,e.head),r=n&&s.type==Ke.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==Bi.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return B.cursor(o,i?-1:1)}return B.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return fn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return B.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s),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,f=null!=n?n:t.viewState.heightOracle.textHeight>>1;for(let i=0;;i+=10){let n=o+(f+i)*r,h=an(t,{x:u,y:n},!1,r);if(na.bottom||(r<0?hs))return B.cursor(h,e.assoc,void 0,l)}}(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),an(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),s=this.bidiSpans(n);return se(i,s[Fi.find(s,t-n.from,-1,e)].dir==Bi.LTR==e>0)}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(ui)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Ls)return Ki(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||_i(n.isolates,e=Ti(this,t.from,t.to))))return n.order;e||(e=Ti(this,t.from,t.to));let n=function(t,e,i){if(!t)return[new Fi(0,0,e==Ni?1:0)];if(e==Pi&&!i.length&&!Vi.test(t))return Ki(t.length);if(i.length)for(;t.length>qi.length;)qi[qi.length]=256;let n=[],s=e==Pi?0:1;return $i(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new Ps(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((()=>{he(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(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return pi.of(new di("number"==typeof t?B.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}static domEventHandlers(t){return vi.define((()=>({})),{eventHandlers:t})}static theme(t,e){let i=Ft.newName(),n=[fs.of(i),Di.of(ys(`.${i}`,t))];return e&&e.dark&&n.push(ds.of(!0)),n}static baseTheme(t){return j.lowest(Di.of(ys("."+ps,t,ws)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&me.get(i)||me.get(t);return(null===(e=null==n?void 0:n.rootView)||void 0===e?void 0:e.view)||null}}Es.styleModule=Di,Es.inputHandler=hi,Es.focusChangeEffect=ci,Es.perLineTextDirection=ui,Es.exceptionSink=li,Es.updateListener=ai,Es.editable=mi,Es.mouseSelectionStyle=oi,Es.dragMovesSelection=ri,Es.clickAddsSelectionRange=si,Es.decorations=Si,Es.atomicRanges=Ai,Es.bidiIsolatedRanges=Mi,Es.scrollMargins=Ci,Es.darkTheme=ds,Es.cspNonce=R.define({combine:t=>t.length?t[0]:""}),Es.contentAttributes=xi,Es.editorAttributes=bi,Es.lineWrapping=Es.contentAttributes.of({class:"cm-lineWrapping"}),Es.announce=at.define();const Ls=4096,Bs={};class Ps{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:Bi.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&&Ve(r,i)}return i}const Rs=Be.mac?"mac":Be.windows?"win":Be.linux?"linux":"key";function Is(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 Hs=j.default(Es.domEventHandlers({keydown:(t,e)=>qs(Vs(e.state),t,e,"editor")})),zs=R.define({enables:Hs}),Ws=new WeakMap;function Vs(t){let e=t.facet(zs),i=Ws.get(e);return i||Ws.set(e,i=function(t,e=Rs){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=Fs={view:e,prefix:i,scope:t};return setTimeout((()=>{Fs==n&&(Fs=null)}),_s),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={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&&d.run.push(r),o&&(d.preventDefault=!0),l&&(d.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:[]});for(let e in t)t[e].run.push(n.any)}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 Fs=null;const _s=4e3;function qs(t,e,i,n){let s=function(t){var e=!(Kt&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||Gt&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?$t:jt)[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=k(y(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;Fs&&Fs.view==i&&Fs.scope==n&&(o=Fs.prefix+" ",mn.indexOf(e.keyCode)<0&&(a=!0,Fs=null));let c,u,f=new Set,d=t=>{if(t){for(let n of t.run)if(!f.has(n)&&(f.add(n),n(i,e)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(d(p[o+Is(s,e,!r)])?l=!0:r&&(e.altKey||e.metaKey||e.ctrlKey)&&!(Be.windows&&e.ctrlKey&&e.altKey)&&(c=jt[e.keyCode])&&c!=s?(d(p[o+Is(c,e,!0)])||e.shiftKey&&(u=$t[e.keyCode])!=s&&u!=c&&d(p[o+Is(u,e,!1)]))&&(l=!0):r&&e.shiftKey&&d(p[o+Is(s,e,!0)])&&(l=!0),!l&&d(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),l}Be.ios;const js=R.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 $s(t,e){let i=t.plugin(Ks),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const Ks=vi.fromClass(class{constructor(t){this.input=t.state.facet(Js),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(js);this.top=new Gs(t,!0,e.topContainer),this.bottom=new Gs(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(js);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Gs(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Gs(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(Js);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=>Es.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class Gs{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=Us(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Us(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 Us(t){let e=t.nextSibling;return t.remove(),e}const Js=R.define({enables:Ks});class Ys extends bt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Ys.prototype.elementClass="",Ys.prototype.toDOM=void 0,Ys.prototype.mapMode=x.TrackBefore,Ys.prototype.startSide=Ys.prototype.endSide=-1,Ys.prototype.point=!0;const Xs=R.define(),Qs=R.define(),Zs=R.define({combine:t=>t.some((t=>t))});function tr(t){let e=[er];return t&&!1===t.fixed&&e.push(Zs.of(!0)),e}const er=vi.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Qs).map((e=>new rr(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(Zs),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}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))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(Zs)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let i=Mt.iter(this.view.state.facet(Xs),this.view.viewport.from),n=[],s=this.gutters.map((t=>new sr(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==Ke.Text&&e){nr(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==Ke.Text){nr(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)}updateGutters(t){let e=t.startState.facet(Qs),i=t.state.facet(Qs),n=t.docChanged||t.heightChanged||t.viewportChanged||!Mt.eq(t.startState.facet(Xs),t.state.facet(Xs),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 rr(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)this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>Es.scrollMargins.of((e=>{let i=e.plugin(t);return i&&0!=i.gutters.length&&i.fixed?e.textDirection==Bi.LTR?{left:i.dom.offsetWidth*e.scaleX}:{right:i.dom.offsetWidth*e.scaleX}:null}))});function ir(t){return Array.isArray(t)?t:[t]}function nr(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class sr{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=Mt.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=e.top-this.height;if(this.i==n.elements.length){let r=new or(t,e.height,s,i);n.elements.push(r),n.dom.appendChild(r.dom)}else n.elements[this.i].update(t,e.height,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];nr(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);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class rr{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=ir(e.markers(t)),e.initialSpacer&&(this.spacer=new or(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=ir(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!Mt.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 or{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/t.scaleY+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i/t.scaleY+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;ikt(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 hr extends Ys{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function cr(t,e){return t.state.facet(ar).formatNumber(e,t.state)}const ur=Qs.compute([ar],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(lr),lineMarker:(t,e,i)=>i.some((t=>t.toDOM))?null:new hr(cr(t,t.state.doc.lineAt(e.from).number)),widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(ar)!=t.state.facet(ar),initialSpacer:t=>new hr(cr(t,fr(t.state.doc.lines))),updateSpacer(t,e){let i=cr(e.view,fr(e.view.state.doc.lines));return i==t.number?t:new hr(i)},domEventHandlers:t.facet(ar).domEventHandlers})));function fr(t){let e=9;for(;e0&&void 0!==arguments[0]?arguments[0]:this.defaultExtensions;this.state=vt.create({doc:this.$textarea.textSelection("getContents"),extensions:e}),this.view=new Es({state:this.state,parent:this.$textarea.parent()[0]}),this.$textarea.hide(),this.$textarea[0].form&&this.$textarea[0].form.addEventListener("submit",(function(){t.$textarea.val(t.view.state.doc.toString())})),$(this.view.dom).textSelection("register",this.cmTextSelection),this.$textarea.textSelection("register",this.cmTextSelection),mw.hook("ext.CodeMirror.switch").fire(!0,$(this.view.dom))}},{key:"logUsage",value:function(t){var e=Object.assign({session_token:mw.user.sessionId(),user_id:mw.user.getId()},t),i=mw.config.get("wgUserEditCountBucket");null!==i&&(e.user_edit_count_bucket=i),mw.track("event.CodeMirrorUsage",e)}},{key:"setCodeMirrorPreference",value:function(t){mw.user.isNamed()&&((new mw.Api).saveOption("usecodemirror",t?1:0),mw.user.options.set("usecodemirror",t?1:0))}},{key:"cmTextSelection",get:function(){var t=this,e=$(this.view.dom);return{getContents:function(){return t.view.state.doc.toString()},setContents:function(i){return t.view.dispatch({changes:{from:0,to:t.view.state.doc.length,insert:i}}),e},getSelection:function(){return t.view.state.sliceDoc(t.view.state.selection.main.from,t.view.state.selection.main.to)},setSelection:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{start:0,end:0};return t.view.dispatch({selection:{anchor:i.start,head:i.end||i.start}}),t.view.focus(),e},replaceSelection:function(i){return t.view.dispatch(t.view.state.replaceSelection(i)),e},getCaretPosition:function(e){return e.startAndEnd?[t.view.state.selection.main.from,t.view.state.selection.main.to]:t.view.state.selection.main.head},scrollToCaretPosition:function(){return t.view.dispatch({effects:Es.scrollIntoView(t.view.state.selection.main.head)}),e}}}}],i&&pr(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();const wr=1024;let yr=0;class vr{constructor(t,e){this.from=t,this.to=e}}class kr{constructor(t={}){this.id=yr++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=Sr.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}kr.closedBy=new kr({deserialize:t=>t.split(" ")}),kr.openedBy=new kr({deserialize:t=>t.split(" ")}),kr.group=new kr({deserialize:t=>t.split(" ")}),kr.isolate=new kr({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),kr.contextHash=new kr({perNode:!0}),kr.lookAhead=new kr({perNode:!0}),kr.mounted=new kr({perNode:!0});class br{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[kr.mounted.id]}}const xr=Object.create(null);class Sr{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):xr,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new Sr(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(kr.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(kr.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}Sr.none=new Sr("",Object.create(null),0,8);class Ar{constructor(t){this.types=t;for(let e=0;e=e){let o=new Nr(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Br(o,e,i,!1))}}return s?Wr(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&Cr.IncludeAnonymous)>0;for(let t=this.cursor(r|Cr.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:$r(Sr.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,i)=>new Or(this.type,t,e,i,this.propValues)),t.makeTree||((t,e,i)=>new Or(Sr.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=wr,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Dr(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,m,w,y){let{id:v,start:k,end:b,size:x}=l,S=c;for(;x<0;){if(l.next(),-1==x){let e=r[v];return i.push(e),void m.push(k-t)}if(-3==x)return void(h=v);if(-4==x)return void(c=v);throw new RangeError(`Unrecognized record size: ${x}`)}let A,M,T=a[v],C=k-t;if(b-k<=s&&(M=function(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,f=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=f,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}(l.pos-e,w))){let e=new Uint16Array(M.size-M.skip),i=l.pos-M.size,s=e.length;for(;l.pos>i;)s=g(M.start,e,s);A=new Er(e,b-M.start,n),C=M.start-t}else{let t=l.pos-x;l.next();let e=[],i=[],n=v>=o?v:-1,r=0,a=b;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(d(e,i,k,r,l.end,a,n,S),r=e.length,a=l.end),l.next()):y>2500?f(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=function(t){return(e,i,n)=>{let s,r,o=0,l=e.length-1;if(l>=0&&(s=e[l])instanceof Or){if(!l&&s.type==t&&s.length==n)return s;(r=s.prop(kr.lookAhead))&&(o=i[l]+s.length+r)}return p(t,e,i,n,o)}}(T);A=$r(T,e,i,0,e.length,0,b-k,t,t)}else A=p(T,e,i,b-k,S-b)}i.push(A),m.push(C)}function f(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 Er(e,o[2]-s,n)),r.push(s-t)}}function d(t,e,i,s,r,o,l,a){let h=[],c=[];for(;t.length>s;)h.push(t.pop()),c.push(e.pop()+i-r);t.push(p(n.types[l],h,c,o-r,a-o)),e.push(r-i)}function p(t,e,i,n,s=0,r){if(h){let t=[kr.contextHash,h];r=r?[t].concat(r):[t]}if(s>25){let t=[kr.lookAhead,s];r=r?[t].concat(r):[t]}return new Or(t,e,i,n,r)}function g(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=g(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 m=[],w=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,m,w,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:m.length?w[0]+m[0].length:0;return new Or(a[t.topID],m.reverse(),w.reverse(),y)}(t)}}Or.empty=new Or(Sr.none,[],[],0);class Dr{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 Dr(this.buffer,this.index)}}class Er{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Sr.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 Br(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(Lr(n,i,h,h+a.length))if(a instanceof Er){if(s&Cr.ExcludeBuffers)continue;let o=a.findChild(0,a.buffer.length,e,i-h,n);if(o>-1)return new zr(new Hr(r,a,t,h),null,o)}else if(s&Cr.IncludeAnonymous||!a.type.isAnonymous||_r(a)){let o;if(!(s&Cr.IgnoreMounts)&&(o=br.get(a))&&!o.overlay)return new Nr(o.tree,h,t,r);let l=new Nr(a,h,t,r);return s&Cr.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?a.children.length-1:0,e,i,n)}}if(s&Cr.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&Cr.IgnoreOverlays)&&(n=br.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 Nr(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 Rr(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(;!s.type.is(i);)if(!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 Ir(t,e,i=e.length-1){for(let n=t.parent;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 Hr{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class zr extends Pr{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 zr(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&Cr.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 zr(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 zr(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 zr(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 Or(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Wr(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&Cr.IncludeAnonymous||t instanceof Er||!t.type.isAnonymous||_r(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 Ir(this.node,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 _r(t){return t.children.some((t=>t instanceof Er||!t.type.isAnonymous||_r(t)))}const qr=new WeakMap;function jr(t,e){if(!t.isAnonymous||e instanceof Er||e.type!=t)return 1;let i=qr.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof Or)){i=1;break}i+=jr(t,n)}qr.set(e,i)}return i}function $r(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-d;u.push($r(t,i,n,s,h,d,e,null,a))}f.push(d+l-r)}}(e,i,n,s,0),(l||a)(u,f,o)}class Kr{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 Kr(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 Kr(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew vr(t.from,t.to))):[new vr(0,0)]:[new vr(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 Ur{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 kr({perNode:!0});let Jr=0;class Yr{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=Jr++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new Yr([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new Qr;return e=>e.modified.indexOf(t)>-1?e:Qr.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let Xr=0;class Qr{constructor(){this.instances=[],this.id=Xr++}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 Yr(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(Qr.get(e,t));return s}}function Zr(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 eo(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return to.add(e)}const to=new kr;class eo{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 no(t,e,i,n=0,s=t.length){let r=new so(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}eo.empty=new eo([],2,null);class so{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(to);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||eo.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(kr.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 f=0,d=o;;f++){let p=f=g)&&t.nextSibling()););if(!p||g>i)break;d=p.to+o,d>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,d),"",h),this.startSpan(Math.min(i,d),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 ro=Yr.define,oo=ro(),lo=ro(),ao=ro(lo),ho=ro(lo),co=ro(),uo=ro(co),fo=ro(co),po=ro(),go=ro(po),mo=ro(),wo=ro(),yo=ro(),vo=ro(yo),ko=ro(),bo={comment:oo,lineComment:ro(oo),blockComment:ro(oo),docComment:ro(oo),name:lo,variableName:ro(lo),typeName:ao,tagName:ro(ao),propertyName:ho,attributeName:ro(ho),className:ro(lo),labelName:ro(lo),namespace:ro(lo),macroName:ro(lo),literal:co,string:uo,docString:ro(uo),character:ro(uo),attributeValue:ro(uo),number:fo,integer:ro(fo),float:ro(fo),bool:ro(co),regexp:ro(co),escape:ro(co),color:ro(co),url:ro(co),keyword:mo,self:ro(mo),null:ro(mo),atom:ro(mo),unit:ro(mo),modifier:ro(mo),operatorKeyword:ro(mo),controlKeyword:ro(mo),definitionKeyword:ro(mo),moduleKeyword:ro(mo),operator:wo,derefOperator:ro(wo),arithmeticOperator:ro(wo),logicOperator:ro(wo),bitwiseOperator:ro(wo),compareOperator:ro(wo),updateOperator:ro(wo),definitionOperator:ro(wo),typeOperator:ro(wo),controlOperator:ro(wo),punctuation:yo,separator:ro(yo),bracket:vo,angleBracket:ro(vo),squareBracket:ro(vo),paren:ro(vo),brace:ro(vo),content:po,heading:go,heading1:ro(go),heading2:ro(go),heading3:ro(go),heading4:ro(go),heading5:ro(go),heading6:ro(go),contentSeparator:ro(po),list:ro(po),quote:ro(po),emphasis:ro(po),strong:ro(po),link:ro(po),monospace:ro(po),strikethrough:ro(po),inserted:ro(),deleted:ro(),changed:ro(),invalid:ro(),meta:ko,documentMeta:ro(ko),annotation:ro(ko),processingInstruction:ro(ko),definition:Yr.defineModifier(),constant:Yr.defineModifier(),function:Yr.defineModifier(),standard:Yr.defineModifier(),local:Yr.defineModifier(),special:Yr.defineModifier()};var xo;io([{tag:bo.link,class:"tok-link"},{tag:bo.heading,class:"tok-heading"},{tag:bo.emphasis,class:"tok-emphasis"},{tag:bo.strong,class:"tok-strong"},{tag:bo.keyword,class:"tok-keyword"},{tag:bo.atom,class:"tok-atom"},{tag:bo.bool,class:"tok-bool"},{tag:bo.url,class:"tok-url"},{tag:bo.labelName,class:"tok-labelName"},{tag:bo.inserted,class:"tok-inserted"},{tag:bo.deleted,class:"tok-deleted"},{tag:bo.literal,class:"tok-literal"},{tag:bo.string,class:"tok-string"},{tag:bo.number,class:"tok-number"},{tag:[bo.regexp,bo.escape,bo.special(bo.string)],class:"tok-string2"},{tag:bo.variableName,class:"tok-variableName"},{tag:bo.local(bo.variableName),class:"tok-variableName tok-local"},{tag:bo.definition(bo.variableName),class:"tok-variableName tok-definition"},{tag:bo.special(bo.variableName),class:"tok-variableName2"},{tag:bo.definition(bo.propertyName),class:"tok-propertyName tok-definition"},{tag:bo.typeName,class:"tok-typeName"},{tag:bo.namespace,class:"tok-namespace"},{tag:bo.className,class:"tok-className"},{tag:bo.macroName,class:"tok-macroName"},{tag:bo.propertyName,class:"tok-propertyName"},{tag:bo.operator,class:"tok-operator"},{tag:bo.comment,class:"tok-comment"},{tag:bo.meta,class:"tok-meta"},{tag:bo.invalid,class:"tok-invalid"},{tag:bo.punctuation,class:"tok-punctuation"}]);const So=new kr;const Ao=new kr;class Mo{constructor(t,e,i=[],n=""){this.data=t,this.name=n,vt.prototype.hasOwnProperty("tree")||Object.defineProperty(vt.prototype,"tree",{get(){return Co(this)}}),this.parser=e,this.extension=[Io.of(this),vt.languageData.of(((t,e,i)=>{let n=To(t,e,i),s=n.type.prop(So);if(!s)return[];let r=t.facet(s),o=n.type.prop(Ao);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 To(t,e,i).type.prop(So)==this.data}findRegions(t){let e=t.facet(Io);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(So)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(kr.mounted);if(s){if(s.tree.prop(So)==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 Do=null;class Eo{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 Eo(t,e,[],Or.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Oo(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=Or.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(Kr.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Do;Do=this;try{return t()}finally{Do=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Lo(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=Kr.applyChanges(i,e),n=Or.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=Lo(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 Gr{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Do;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 Or(Sr.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 Do}}function Lo(t,e,i){return Kr.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Bo{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 Bo(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Eo.create(t.facet(Io).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Bo(i)}}Mo.state=_.define({create:Bo.init,update(t,e){for(let t of e.effects)if(t.is(Mo.setState))return t.value;return e.startState.facet(Io)!=e.state.facet(Io)?Bo.init(e.state):t.apply(e)}});let Po=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Po=t=>{let e=-1,i=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const No="undefined"!=typeof navigator&&(null===(xo=navigator.scheduling)||void 0===xo?void 0:xo.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ro=vi.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(Mo.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(Mo.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Po(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work((()=>No&&No()||Date.now()>r),n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Mo.setState.of(new Bo(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=>gi(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()}}}),Io=R.define({combine:t=>t.length?t[0]:null,enables:t=>[Mo.state,Ro,Es.contentAttributes.compute([t],(e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}}))]});class Ho{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const zo=R.define(),Wo=R.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 Vo(t){let e=t.facet(Wo);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Fo(t,e){let i="",n=t.tabSize,s=t.facet(Wo)[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=n.node.enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e!=n.node;e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return $o(n,t,i)}(t,i,e):null}class qo{constructor(t,e={}){this.state=t,this.options=e,this.unit=Vo(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 Ht(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 jo=new kr;function $o(t,e,i){for(let n=t;n;n=n.next){let t=Ko(n.node);if(t)return t(Uo.create(e,i,n))}return 0}function Ko(t){let e=t.type.prop(jo);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(kr.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=e?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)return s.fromt.prop(So)==r.data:r?t=>t==r:void 0,this.style=io(t.map((t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))}))),{all:s}).style,this.module=i?new Ft(i):null,this.themeType=e.themeType}static define(t,e){return new Yo(t,e||{})}}const Xo=R.define(),Qo=R.define({combine:t=>t.length?[t[0]]:null});function Zo(t){let e=t.facet(Xo);return e.length?e:t.facet(Qo)}class tl{constructor(t){this.markCache=Object.create(null),this.tree=Co(t.state),this.decorations=this.buildDeco(t,Zo(t.state))}update(t){let e=Co(t.state),i=Zo(t.state),n=i!=Zo(t.startState);e.length{i.add(t,e,this.markCache[n]||(this.markCache[n]=Ge.mark({class:n})))}),n,s);return i.finish()}}const el=j.high(vi.fromClass(tl,{decorations:t=>t.decorations})),il=(bo.meta,bo.link,bo.heading,bo.emphasis,bo.strong,bo.strikethrough,bo.keyword,bo.atom,bo.bool,bo.url,bo.contentSeparator,bo.labelName,bo.literal,bo.inserted,bo.string,bo.deleted,bo.regexp,bo.escape,bo.string,bo.variableName,bo.variableName,bo.typeName,bo.namespace,bo.className,bo.variableName,bo.macroName,bo.propertyName,bo.comment,bo.invalid,Es.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}})),nl=1e4,sl="()[]{}",rl=R.define({combine:t=>kt(t,{afterCursor:!0,brackets:sl,maxScanDistance:nl,renderMatch:al})}),ol=Ge.mark({class:"cm-matchingBracket"}),ll=Ge.mark({class:"cm-nonmatchingBracket"});function al(t){let e=[],i=t.matched?ol:ll;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 hl=_.define({create:()=>Ge.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],n=e.state.facet(rl);for(let t of e.state.selection.ranges){if(!t.empty)continue;let s=gl(e.state,t.head,-1,n)||t.head>0&&gl(e.state,t.head-1,1,n)||n.afterCursor&&(gl(e.state,t.head,1,n)||t.headEs.decorations.from(t)}),cl=[hl,il];function ul(t={}){return[rl.of(t),cl]}const fl=new kr;function dl(t,e,i){let n=t.prop(e<0?kr.openedBy:kr.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 pl(t){let e=t.type.prop(fl);return e?e(t.node):t}function gl(t,e,i,n={}){let s=n.maxScanDistance||nl,r=n.brackets||sl,o=Co(t),l=o.resolveInner(e,i);for(let t=l;t;t=t.parent){let n=dl(t.type,i,r);if(n&&t.from0?e>=s.from&&es.from&&e<=s.to))return ml(0,0,i,t,s,n,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 ml(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 vl(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 kl=new WeakMap;class bl extends Mo{constructor(t){let e,i=(s=t.languageData,R.define({combine:s?t=>t.concat(s):void 0})),n={name:(r=t).name||"",token:r.token,blankLine:r.blankLine||(()=>{}),startState:r.startState||(()=>!0),copyState:r.copyState||vl,indent:r.indent||(()=>null),languageData:r.languageData||{},tokenTable:r.tokenTable||Tl};var s,r;super(i,new class extends Gr{createParse(t,i,n){return new Al(e,t,i,n)}},[zo.of(((t,e)=>this.getIndent(t,e)))],t.name),this.topNode=function(t){let e=Sr.define({id:Cl.length,name:"Document",props:[So.add((()=>t))],top:!0});return Cl.push(e),e}(i),e=this,this.streamParser=n,this.stateAfter=new kr({perNode:!0}),this.tokenTable=t.tokenTable?new Bl(n.tokenTable):Pl}static define(t){return new bl(t)}getIndent(t,e){let i,n=Co(t.state),s=n.resolve(e);for(;s&&s.type!=this.topNode;)s=s.parent;if(!s)return null;let{overrideIndentation:r}=t.options;r&&(i=kl.get(t.state),null!=i&&i1e4)return null;for(;o=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 Or&&l=e.length)return e;s||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&&xl(t,n.tree,0-n.offset,i,r);if(o&&(e=Sl(t,n.tree,i+n.offset,o.pos+n.offset,!1)))return{state:o.state,tree:e}}return{state:t.streamParser.startState(n?Vo(n):4),tree:Or.empty}}(t,i,r,null==s?void 0:s.state);this.state=o,this.parsedPos=this.chunkStart=r+l.length;for(let t=0;t=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+=s=this.skipGapsTo(e,s,1);let t=this.chunk.length;i+=s=this.skipGapsTo(i,s,-1),n+=this.chunk.length-t}return this.chunk.push(t,e,i,n),s}parseLine(t){let{line:e,end:i}=this.nextLine(),n=0,{streamParser:s}=this.lang,r=new yl(e,t?t.state.tabSize:4,t?Vo(t.state):2);if(r.eol())s.blankLine(this.state,r.indentUnit);else for(;!r.eol();){let t=Ml(s.token,r,this.state);if(t&&(n=this.emitToken(this.lang.tokenTable.resolve(t),this.parsedPos+r.start,this.parsedPos+r.pos,4,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 Tl=Object.create(null),Cl=[Sr.none],Ol=new Ar(Cl),Dl=[],El=Object.create(null),Ll=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"]])Ll[t]=Rl(Tl,e);class Bl{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),Ll)}resolve(t){return t?this.table[t]||(this.table[t]=Rl(this.extra,t)):0}}const Pl=new Bl(Tl);function Nl(t,e){Dl.indexOf(t)>-1||(Dl.push(t),console.warn(e))}function Rl(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||bo[i];n?"function"==typeof n?e.length?e=e.map(n):Nl(i,`Modifier ${i} used at start of tag`):e.length?Nl(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:Nl(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=El[s];if(r)return r.id;let o=El[s]=Sr.define({id:Cl.length,name:n,props:[Zr({[n]:i})]});return Cl.push(o),o.id}function Il(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 Hl=Il(ql,0),zl=Il(_l,0),Wl=Il(((t,e)=>_l(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),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 Vl(t,e){let i=t.languageDataAt("commentTokens",e);return i.length?i[0]:{}}const Fl=50;function _l(t,e,i=e.selection.ranges){let n=i.map((t=>Vl(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-Fl,n),a=t.sliceDoc(s,s+Fl),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*Fl?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Fl),o=t.sliceDoc(s-Fl,s));let f=/^\s*/.exec(r)[0].length,d=/\s*$/.exec(o)[0].length,p=o.length-d-i.length;return r.slice(f,f+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+f+e.length,margin:/\s/.test(r.charAt(f+e.length))?1:0},close:{pos:s-d-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 jl=rt.define(),$l=rt.define(),Kl=R.define(),Gl=R.define({combine:t=>kt(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)})}),Ul=_.define({create:()=>ua.empty,update(t,e){let i=e.state.facet(Gl),n=e.annotation(jl);if(n){let s=e.docChanged?B.single(function(t){let e=0;return t.iterChangedRanges(((t,i)=>e=i)),e}(e.changes)):void 0,r=ea.fromTransaction(e,s),o=n.side,l=0==o?t.undone:t.done;return l=r?ia(l,l.length,i.minDepth,r):oa(l,e.startState.selection),new ua(0==o?n.rest:l,0==o?l:n.rest)}let s=e.annotation($l);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(ht.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=ea.fromTransaction(e),o=e.annotation(ht.time),l=e.annotation(ht.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 ua(t.done.map(ea.fromJSON),t.undone.map(ea.fromJSON))});function Jl(t={}){return[Ul,Gl.of(t),Es.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?Xl:"historyRedo"==t.inputType?Ql:null;return!!i&&(t.preventDefault(),i(e))}})]}function Yl(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(Ul,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const Xl=Yl(0,!1),Ql=Yl(1,!1),Zl=Yl(0,!0),ta=Yl(1,!0);class ea{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 ea(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 ea(t.changes&&A.fromJSON(t.changes),[],t.mapped&&S.fromJSON(t.mapped),t.startSelection&&B.fromJSON(t.startSelection),t.selectionsAfter.map(B.fromJSON))}static fromTransaction(t,e){let i=sa;for(let e of t.startState.facet(Kl)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new ea(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,sa)}static selection(t){return new ea(void 0,sa,void 0,void 0,t)}}function ia(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 na(t,e){return t.length?e.length?t.concat(e):t:e}const sa=[],ra=200;function oa(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-ra));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),ia(t,t.length-1,1e9,i.setSelAfter(n)))}return[ea.selection([e])]}function la(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 aa(t,e){if(!t.length)return t;let i=t.length,n=sa;for(;i;){let s=ha(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?[ea.selection(n)]:sa}function ha(t,e,i){let n=na(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):sa,i);if(!t.changes)return ea.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new ea(s,at.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const ca=/^(input\.type|delete)($|\.)/;class ua{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 ua(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||ca.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)?ia(r,r.length-1,n.minDepth,new ea(t.changes.compose(o.changes),na(t.effects,o.effects),o.mapped,o.startSelection,sa)):ia(r,r.length,n.minDepth,t),new ua(r,sa,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:sa;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty)).length)?this:new ua(oa(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new ua(aa(this.done,t),aa(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];if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:jl.of({side:t,rest:la(n)}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?sa:n.slice(0,n.length-1);return s.mapped&&(i=aa(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:jl.of({side:t,rest:i}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}ua.empty=new ua(sa,sa);const fa=[{key:"Mod-z",run:Xl,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ql,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ql,preventDefault:!0},{key:"Mod-u",run:Zl,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:ta,preventDefault:!0}];function da(t,e){return B.create(t.ranges.map(e),t.mainIndex)}function pa(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ga({state:t,dispatch:e},i){let n=da(t.selection,i);return!n.eq(t.selection)&&(e(pa(t,n)),!0)}function ma(t,e){return B.cursor(e?t.to:t.from)}function wa(t,e){return ga(t,(i=>i.empty?t.moveByChar(i,e):ma(i,e)))}function ya(t){return t.textDirectionAt(t.state.selection.main.head)==Bi.LTR}const va=t=>wa(t,!ya(t)),ka=t=>wa(t,ya(t));function ba(t,e){return ga(t,(i=>i.empty?t.moveByGroup(i,e):ma(i,e)))}function xa(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 Sa(t,e,i){let n,s,r=Co(t).resolveInner(e.head),o=i?kr.closedBy:kr.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;xa(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?gl(t,r.from,1):gl(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,B.cursor(s,i?-1:1)}function Aa(t,e){return ga(t,(i=>{if(!i.empty)return ma(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)}))}"undefined"!=typeof Intl&&Intl.Segmenter;const Ma=t=>Aa(t,!1),Ta=t=>Aa(t,!0);function Ca(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):ma(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.bottomOa(t,!1),Ea=t=>Oa(t,!0);function La(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=B.cursor(n.from+i))}return s}function Ba(t,e){let i=da(t.state.selection,(t=>{let i=e(t);return B.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)}));return!i.eq(t.state.selection)&&(t.dispatch(pa(t.state,i)),!0)}function Pa(t,e){return Ba(t,(i=>t.moveByChar(i,e)))}const Na=t=>Pa(t,!ya(t)),Ra=t=>Pa(t,ya(t));function Ia(t,e){return Ba(t,(i=>t.moveByGroup(i,e)))}function Ha(t,e){return Ba(t,(i=>t.moveVertically(i,e)))}const za=t=>Ha(t,!1),Wa=t=>Ha(t,!0);function Va(t,e){return Ba(t,(i=>t.moveVertically(i,e,Ca(t).height)))}const Fa=t=>Va(t,!1),_a=t=>Va(t,!0),qa=({state:t,dispatch:e})=>(e(pa(t,{anchor:0})),!0),ja=({state:t,dispatch:e})=>(e(pa(t,{anchor:t.doc.length})),!0),$a=({state:t,dispatch:e})=>(e(pa(t,{anchor:t.selection.main.anchor,head:0})),!0),Ka=({state:t,dispatch:e})=>(e(pa(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Ga(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 n=e(s);ns&&(i="delete.forward",n=Ua(t,n,!0)),s=Math.min(s,n),r=Math.max(r,n)}else s=Ua(t,s,!1),r=Ua(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:B.cursor(s)}}));return!s.changes.empty&&(t.dispatch(n.update(s,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?Es.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Ua(t,e,i){if(t instanceof Es)for(let n of t.state.facet(Es.atomicRanges).map((e=>e(t))))n.between(e,e,((t,n)=>{te&&(e=i?n:t)}));return e}const Ja=(t,e)=>Ga(t,(i=>{let n,s,{state:r}=t,o=r.doc.lineAt(i);if(!e&&i>o.from&&iJa(t,!1),Xa=t=>Ja(t,!0),Qa=(t,e)=>Ga(t,(i=>{let n=i,{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&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=d(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||(t=h),n=l}return n})),Za=t=>Qa(t,!1),th=t=>Ga(t,(e=>{let i=t.lineBlockAt(e).to;return e=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 ih(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of eh(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(B.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(B.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:B.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function nh(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of eh(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 sh=rh(!1);function rh(e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=i.changeByRange((n=>{let{from:s,to:r}=n,o=i.doc.lineAt(s),l=!e&&s==r&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=Co(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(kr.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}(i,s);e&&(s=r=(r<=o.to?o:i.doc.lineAt(r)).to);let a=new qo(i,{simulateBreak:s,simulateDoubleBreak:!!l}),h=_o(a,s);for(null==h&&(h=Ht(/^\s*/.exec(i.doc.lineAt(s).text)[0],i.tabSize));ro.from&&s{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:B.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}}))}const lh=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>ga(t,(e=>Sa(t.state,e,!ya(t)))),shift:t=>Ba(t,(e=>Sa(t.state,e,!ya(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>ga(t,(e=>Sa(t.state,e,ya(t)))),shift:t=>Ba(t,(e=>Sa(t.state,e,ya(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>ih(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>nh(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>ih(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>nh(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=B.create([i.main]):i.main.empty||(n=B.create([B.cursor(i.main.head)])),!!n&&(e(pa(t,n)),!0)}},{key:"Mod-Enter",run:rh(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=eh(t).map((({from:e,to:i})=>B.range(e,Math.min(i+1,t.doc.length))));return e(t.update({selection:B.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=da(t.selection,(e=>{var i;let n=Co(t).resolveInner(e.head,1);for(;!(n.from=e.to||n.to>e.to&&n.from<=e.from)&&(null===(i=n.parent)||void 0===i?void 0:i.parent);)n=n.parent;return B.range(n.to,n.from)}));return e(pa(t,i)),!0},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(oh(t,((e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Ht(n,t.tabSize),r=0,o=Fo(t,Math.max(0,s-Vo(t)));for(;r!t.readOnly&&(e(t.update(oh(t,((e,i)=>{i.push({from:e.from,insert:t.facet(Wo)})})),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new qo(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=oh(t,((e,s,r)=>{let o=_o(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=Fo(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(eh(e).map((({from:t,to:i})=>(t>0?t--:it.moveVertically(e,!0))).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,i){let n=!1,s=da(t.selection,(e=>{let s=gl(t,e.head,-1)||gl(t,e.head,1)||e.head>0&&gl(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Vl(t.state,i.from);return n.line?Hl(t):!!n.block&&Wl(t)}},{key:"Alt-A",run:zl}].concat([{key:"ArrowLeft",run:va,shift:Na,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>ba(t,!ya(t)),shift:t=>Ia(t,!ya(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>ga(t,(e=>La(t,e,!ya(t)))),shift:t=>Ba(t,(e=>La(t,e,!ya(t)))),preventDefault:!0},{key:"ArrowRight",run:ka,shift:Ra,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>ba(t,ya(t)),shift:t=>Ia(t,ya(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>ga(t,(e=>La(t,e,ya(t)))),shift:t=>Ba(t,(e=>La(t,e,ya(t)))),preventDefault:!0},{key:"ArrowUp",run:Ma,shift:za,preventDefault:!0},{mac:"Cmd-ArrowUp",run:qa,shift:$a},{mac:"Ctrl-ArrowUp",run:Da,shift:Fa},{key:"ArrowDown",run:Ta,shift:Wa,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ja,shift:Ka},{mac:"Ctrl-ArrowDown",run:Ea,shift:_a},{key:"PageUp",run:Da,shift:Fa},{key:"PageDown",run:Ea,shift:_a},{key:"Home",run:t=>ga(t,(e=>La(t,e,!1))),shift:t=>Ba(t,(e=>La(t,e,!1))),preventDefault:!0},{key:"Mod-Home",run:qa,shift:$a},{key:"End",run:t=>ga(t,(e=>La(t,e,!0))),shift:t=>Ba(t,(e=>La(t,e,!0))),preventDefault:!0},{key:"Mod-End",run:ja,shift:Ka},{key:"Enter",run:sh},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Ya,shift:Ya},{key:"Delete",run:Xa},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Za},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Qa(t,!0)},{mac:"Mod-Backspace",run:t=>Ga(t,(e=>{let i=t.lineBlockAt(e).from;return e>i?i:Math.max(0,e-1)}))},{mac:"Mod-Delete",run:th}].concat([{key:"Ctrl-b",run:va,shift:Na,preventDefault:!0},{key:"Ctrl-f",run:ka,shift:Ra},{key:"Ctrl-p",run:Ma,shift:za},{key:"Ctrl-n",run:Ta,shift:Wa},{key:"Ctrl-a",run:t=>ga(t,(e=>B.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>Ba(t,(e=>B.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>ga(t,(e=>B.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>Ba(t,(e=>B.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:Xa},{key:"Ctrl-h",run:Ya},{key:"Ctrl-k",run:th},{key:"Ctrl-Alt-h",run:Za},{key:"Ctrl-o",run:({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t.of(["",""])},range:B.cursor(e.from)})));return i(e.update(n,{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:d(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:d(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:B.cursor(r)}}));return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Ea}].map((t=>({mac:t.key,run:t.run,shift:t.shift})))));function ah(){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(;et.normalize("NFKD"):t=>t;class uh{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(ch(t)):ch,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 y(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=v(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=k(t);let n=this.normalize(e);for(let t=0,s=i;;t++){let r=n.charCodeAt(t),o=this.match(r,s);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=yh(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 mh(e,t.sliceString(e,i));return gh.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=yh(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=mh.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function yh(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}function vh(t){let e=ah("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))),f=B.cursor(u.from+Math.max(0,Math.min(h,u.length)));t.dispatch({effects:[kh.of(!1),Es.scrollIntoView(f.from,{y:"center"})],selection:f}),t.focus()}return{dom:ah("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:kh.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},ah("label",t.state.phrase("Go to line"),": ",e)," ",ah("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(ph.prototype[Symbol.iterator]=wh.prototype[Symbol.iterator]=function(){return this});const kh=at.define(),bh=_.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(kh)&&(t=i.value);return t},provide:t=>Js.from(t,(t=>t?vh:null))}),xh=Es.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Sh=R.define({combine:t=>kt(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Qh(t),scrollToMatch:t=>Es.scrollIntoView(t)})});class Ah{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,dh),!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 Lh(this):new Ch(this)}getCursor(t,e=0,i){let n=t.doc?t:vt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?Oh(this,n,e,i):Th(this,n,e,i)}}class Mh{constructor(t){this.spec=t}}function Th(t,e,i,n){return new uh(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=Th(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 Oh(t,e,i,n){return new ph(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(s=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(s(Dh(i.input,i.index))!=mt.Word||s(Eh(i.input,i.index))!=mt.Word)&&(s(Eh(i.input,i.index+i[0].length))!=mt.Word||s(Dh(i.input,i.index+i[0].length))!=mt.Word)):void 0},i,n);var s}function Dh(t,e){return t.slice(d(t,e,!1),e)}function Eh(t,e){return t.slice(e,d(t,e))}class Lh extends Mh{nextMatch(t,e,i){let n=Oh(this.spec,t,i,t.doc.length).next();return n.done&&(n=Oh(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=Oh(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)=>"$"==i?"$":"&"==i?t.match[0]:"0"!=i&&+i=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Oh(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 Bh=at.define(),Ph=at.define(),Nh=_.define({create:t=>new Rh(Kh(t).create(),null),update(t,e){for(let i of e.effects)i.is(Bh)?t=new Rh(i.value.create(),t.panel):i.is(Ph)&&(t=new Rh(t.query,i.value?$h:null));return t},provide:t=>Js.from(t,(t=>t.panel))});class Rh{constructor(t,e){this.query=t,this.panel=e}}const Ih=Ge.mark({class:"cm-searchMatch"}),Hh=Ge.mark({class:"cm-searchMatch cm-searchMatch-selected"}),zh=vi.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Nh))}update(t){let e=t.state.field(Nh);(e!=t.startState.field(Nh)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Ge.none;let{view:i}=this,n=new Tt;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?Hh:Ih)}))}return n.finish()}},{decorations:t=>t.decorations});function Wh(t){return e=>{let i=e.state.field(Nh,!1);return i&&i.query.spec.valid?t(e,i):Jh(e)}}const Vh=Wh(((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=B.single(n.from,n.to),r=t.state.facet(Sh);return t.dispatch({selection:s,effects:[ic(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),Uh(t),!0})),Fh=Wh(((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=B.single(s.from,s.to),o=t.state.facet(Sh);return t.dispatch({selection:r,effects:[ic(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),Uh(t),!0})),_h=Wh(((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length||(t.dispatch({selection:B.create(i.map((t=>B.range(t.from,t.to)))),userEvent:"select.search.matches"}),0))})),qh=Wh(((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=[],h=[];if(r.from==n&&r.to==s&&(l=i.toText(e.getReplacement(r)),a.push({from:r.from,to:r.to,insert:l}),r=e.nextMatch(i,r.from,r.to),h.push(Es.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+"."))),r){let e=0==a.length||a[0].from>=r.to?0:r.to-r.from-l.length;o=B.single(r.from-e,r.to-e),h.push(ic(t,r)),h.push(i.facet(Sh).scrollToMatch(o.main,t))}return t.dispatch({changes:a,selection:o,effects:h,userEvent:"input.replace"}),!0})),jh=Wh(((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:Es.announce.of(n),userEvent:"input.replace.all"}),!0}));function $h(t){return t.state.facet(Sh).createPanel(t)}function Kh(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(Sh);return new Ah({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 Gh(t){let e=$s(t,$h);return e&&e.dom.querySelector("[main-field]")}function Uh(t){let e=Gh(t);e&&e==t.root.activeElement&&e.select()}const Jh=t=>{let e=t.state.field(Nh,!1);if(e&&e.panel){let i=Gh(t);if(i&&i!=t.root.activeElement){let n=Kh(t.state,e.query.spec);n.valid&&t.dispatch({effects:Bh.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Ph.of(!0),e?Bh.of(Kh(t.state,e.query.spec)):at.appendConfig.of(sc)]});return!0},Yh=t=>{let e=t.state.field(Nh,!1);if(!e||!e.panel)return!1;let i=$s(t,$h);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Ph.of(!1)}),!0},Xh=[{key:"Mod-f",run:Jh,scope:"editor search-panel"},{key:"F3",run:Vh,shift:Fh,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Vh,shift:Fh,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Yh,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 uh(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(B.range(e.value.from,e.value.to))}return e(t.update({selection:B.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Alt-g",run:t=>{let e=$s(t,vh);if(!e){let i=[kh.of(!0)];null==t.state.field(bh,!1)&&i.push(at.appendConfig.of([bh,xh])),t.dispatch({effects:i}),e=$s(t,vh)}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=B.create(i.ranges.map((e=>t.wordAt(e.head)||B.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 uh(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 uh(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(B.range(s.from,s.to),!1),effects:Es.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class Qh{constructor(t){this.view=t;let e=this.query=t.state.field(Nh).query.spec;function i(t,e,i){return ah("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=ah("input",{value:e.search,placeholder:Zh(t,"Find"),"aria-label":Zh(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=ah("input",{value:e.replace,placeholder:Zh(t,"Replace"),"aria-label":Zh(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=ah("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=ah("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=ah("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=ah("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",(()=>Vh(t)),[Zh(t,"next")]),i("prev",(()=>Fh(t)),[Zh(t,"previous")]),i("select",(()=>_h(t)),[Zh(t,"all")]),ah("label",null,[this.caseField,Zh(t,"match case")]),ah("label",null,[this.reField,Zh(t,"regexp")]),ah("label",null,[this.wordField,Zh(t,"by word")]),...t.state.readOnly?[]:[ah("br"),this.replaceField,i("replace",(()=>qh(t)),[Zh(t,"replace")]),i("replaceAll",(()=>jh(t)),[Zh(t,"replace all")])],ah("button",{name:"close",onclick:()=>Yh(t),"aria-label":Zh(t,"close"),type:"button"},["×"])])}commit(){let t=new Ah({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:Bh.of(t)}))}keydown(t){var e,i;i=t,qs(Vs((e=this.view).state),i,e,"search-panel")?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Fh:Vh)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),qh(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Bh)&&!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(Sh).top}}function Zh(t,e){return t.state.phrase(e)}const tc=30,ec=/[\s\.,:;?!]/;function ic(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-tc),o=Math.min(s,i+tc),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-tc;t--)if(!ec.test(l[t-1])&&ec.test(l[t])){l=l.slice(0,t);break}return Es.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const nc=Es.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"}}),sc=[Nh,j.low(zh),nc];function rc(t){return rc="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},rc(t)}function oc(t){return function(t){if(Array.isArray(t))return lc(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return lc(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?lc(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function lc(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i0,n}var i,n;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&pc(t,e)}(e,t),i=e,(n=[{key:"setCodeMirrorPreference",value:function(t){this.useCodeMirror=t,fc(dc(e.prototype),"setCodeMirrorPreference",this).call(this,t)}},{key:"enableCodeMirror",value:function(){var t=this;if(!this.view){var e=this.$textarea.prop("selectionStart"),i=this.$textarea.prop("selectionEnd"),n=this.$textarea.scrollTop(),s=this.$textarea.is(":focus"),r=[].concat(oc(this.defaultExtensions),[this.langExtension,ul(),Jl(),Es.contentAttributes.of({spellcheck:"true"}),Es.domEventHandlers({blur:function(){return t.$textarea.triggerHandler("blur")},focus:function(){return t.$textarea.triggerHandler("focus")}}),Es.updateListener.of((function(e){e.docChanged&&"function"==typeof t.editRecoveryHandler&&t.editRecoveryHandler()})),Es.lineWrapping,zs.of([].concat(oc(lh),oc(Xh),oc(fa)))]);mw.hook("editRecovery.loadEnd").add((function(e){t.editRecoveryHandler=e.fieldChangeHandler})),this.initialize(r),this.view.scrollDOM.scrollTop=n,this.view.dispatch({selection:B.create([B.range(e,i)]),scrollIntoView:!0}),s&&this.view.focus(),mw.hook("ext.CodeMirror.switch").fire(!0,$(this.view.dom))}}},{key:"addCodeMirrorToWikiEditor",value:function(){var t=this,e=this.$textarea.data("wikiEditor-context"),i=e&&e.modules&&e.modules.toolbar;i&&(this.$textarea.wikiEditor("addToToolbar",{section:"main",groups:{codemirror:{tools:{CodeMirror:{label:mw.msg("codemirror-toggle-label"),type:"toggle",oouiIcon:"highlight",action:{type:"callback",execute:function(){return t.switchCodeMirror()}}}}}}}),i.$toolbar.find(".tool[rel=CodeMirror]").attr("id","mw-editbutton-codemirror"),this.useCodeMirror&&this.enableCodeMirror(),this.updateToolbarButton(),this.logUsage({editor:"wikitext",enabled:this.useCodeMirror,toggled:!1,edit_start_ts_ms:1e3*parseInt($('input[name="wpStarttime"]').val(),10)||0}))}},{key:"updateToolbarButton",value:function(){var t=$("#mw-editbutton-codemirror");t.toggleClass("mw-editbutton-codemirror-active",this.useCodeMirror),t.data("setActive")&&t.data("setActive")(this.useCodeMirror)}},{key:"switchCodeMirror",value:function(){if(this.view){this.setCodeMirrorPreference(!1);var t=this.view.scrollDOM.scrollTop,e=this.view.hasFocus,i=this.view.state.selection.ranges[0],n=i.from,s=i.to;$(this.view.dom).textSelection("unregister"),this.$textarea.textSelection("unregister"),this.$textarea.val(this.view.state.doc.toString()),this.view.destroy(),this.view=null,this.$textarea.show(),e&&this.$textarea.trigger("focus"),this.$textarea.prop("selectionStart",Math.min(n,s)).prop("selectionEnd",Math.max(s,n)),this.$textarea.scrollTop(t),mw.hook("ext.CodeMirror.switch").fire(!1,this.$textarea)}else this.enableCodeMirror(),this.setCodeMirrorPreference(!0);this.updateToolbarButton(),this.logUsage({editor:"wikitext",enabled:this.useCodeMirror,toggled:!0,edit_start_ts_ms:1e3*parseInt($('input[name="wpStarttime"]').val(),10)||0})}}])&&ac(i.prototype,n),Object.defineProperty(i,"prototype",{writable:!1}),e}(mr);function mc(t){return mc="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},mc(t)}function wc(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i~).,'])"),"i"),this.isBold=!1,this.wasBold=!1,this.isItalic=!1,this.wasItalic=!1,this.firstSingleLetterWord=null,this.firstMultiLetterWord=null,this.firstSpace=null,this.oldStyle=null,this.tokens=[],this.oldTokens=[],this.tokenTable=Mc.tokenTable,Object.keys(this.config.tags).forEach((function(t){return Mc.addTag(t)}))}var e,i;return e=t,i=[{key:"eatHtmlEntity",value:function(t,e){return(t.eat("#")?t.eat("x")?t.eatWhile(/[a-fA-F\d]/)&&t.eat(";"):t.eatWhile(/[\d]/)&&t.eat(";"):t.eatWhile(/[\w.\-:]/)&&t.eat(";"))?Mc.tags.htmlEntity:e}},{key:"makeStyle",value:function(t,e,i){return this.isBold&&(t+=" "+Mc.tags.strong),this.isItalic&&(t+=" "+Mc.tags.em),this.makeLocalStyle(t,e,i)}},{key:"makeLocalStyle",value:function(t,e,i){var n="";switch(e.nTemplate){case 0:break;case 1:n+="-template";break;case 2:n+="-template2";break;default:n+="-template3"}switch(e.nExt){case 0:break;case 1:n+="-ext";break;case 2:n+="-ext2";break;default:n+="-ext3"}return e.nLink>0&&(n+="-link"),""!==n&&(t="mw".concat(n,"-ground ").concat(t)),i&&e[i]--,t.trim()}},{key:"eatBlock",value:function(t,e,i){var n=this;return function(s,r){return s.skipTo(e)?(!1!==i&&s.match(e),r.tokenize=r.stack.pop()):s.skipToEnd(),n.makeLocalStyle(t,r)}}},{key:"eatEnd",value:function(t){var e=this;return function(i,n){return i.skipToEnd(),n.tokenize=n.stack.pop(),e.makeLocalStyle(t,n)}}},{key:"eatChar",value:function(t,e){var i=this;return function(n,s){return s.tokenize=s.stack.pop(),n.eat(t)?i.makeLocalStyle(e,s):i.makeLocalStyle(Mc.tags.error,s)}}},{key:"eatSectionHeader",value:function(t){var e=this;return function(i,n){return i.match(/^[^&<[{~]+/)?(i.eol()?(i.backUp(t),n.tokenize=e.eatEnd(Mc.tags.sectionHeader)):i.match(/^.*?=)/,!1)&&(i.backUp(t),n.tokenize=e.eatBlock(Mc.tags.sectionHeader,"\x3c!--",!1)),Mc.tags.section):e.eatWikiText(Mc.tags.section)(i,n)}}},{key:"inVariable",value:function(t,e){return t.match(/^[^{}|]+/)?this.makeLocalStyle(Mc.tags.templateVariableName,e):t.eat("|")?(e.tokenize=this.inVariableDefault.bind(this),this.makeLocalStyle(Mc.tags.templateVariableDelimiter,e)):t.match("}}}")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.templateVariableBracket,e)):t.match("{{{")?(e.stack.push(e.tokenize),this.makeLocalStyle(Mc.tags.templateVariableBracket,e)):(t.next(),this.makeLocalStyle(Mc.tags.templateVariableName,e))}},{key:"inVariableDefault",value:function(t,e){return t.match(/^[^{}[<&~]+/)?this.makeLocalStyle(Mc.tags.templateVariable,e):t.match("}}}")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.templateVariableBracket,e)):this.eatWikiText(Mc.tags.templateVariable)(t,e)}},{key:"inParserFunctionName",value:function(t,e){return t.match(/^#?[^:}{~]+/)?this.makeLocalStyle(Mc.tags.parserFunctionName,e):t.eat(":")?(e.tokenize=this.inParserFunctionArguments.bind(this),this.makeLocalStyle(Mc.tags.parserFunctionDelimiter,e)):t.match("}}")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.parserFunctionBracket,e,"nExt")):this.eatWikiText(Mc.tags.parserFunction)(t,e)}},{key:"inParserFunctionArguments",value:function(t,e){return t.match(/^[^|}{[<&~]+/)?this.makeLocalStyle(Mc.tags.parserFunction,e):t.eat("|")?this.makeLocalStyle(Mc.tags.parserFunctionDelimiter,e):t.match("}}")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.parserFunctionBracket,e,"nExt")):this.eatWikiText(Mc.tags.parserFunction)(t,e)}},{key:"eatTemplatePageName",value:function(t){var e=this;return function(i,n){return i.match(/^[\s\u00a0]*\|[\s\u00a0]*/)?(n.tokenize=e.eatTemplateArgument(!0),e.makeLocalStyle(Mc.tags.templateDelimiter,n)):i.match(/^[\s\u00a0]*\}\}/)?(n.tokenize=n.stack.pop(),e.makeLocalStyle(Mc.tags.templateBracket,n,"nTemplate")):i.match(/^[\s\u00a0]*/)?e.makeLocalStyle(Mc.tags.comment,n):t&&i.sol()?(n.nTemplate--,void(n.tokenize=n.stack.pop())):i.match(/^[\s\u00a0]*[^\s\u00a0|}<{&~]+/)?(n.tokenize=e.eatTemplatePageName(!0),e.makeLocalStyle(Mc.tags.templateName,n)):i.eatSpace()?(i.eol(),e.makeLocalStyle(Mc.tags.templateName,n)):e.eatWikiText(Mc.tags.templateName)(i,n)}}},{key:"eatTemplateArgument",value:function(t){var e=this;return function(i,n){return t&&i.eatWhile(/[^=|}{[<&~]/)?i.eat("=")?(n.tokenize=e.eatTemplateArgument(!1),e.makeLocalStyle(Mc.tags.templateArgumentName,n)):e.makeLocalStyle(Mc.tags.template,n):i.eatWhile(/[^|}{[<&~]/)?e.makeLocalStyle(Mc.tags.template,n):i.eat("|")?(n.tokenize=e.eatTemplateArgument(!0),e.makeLocalStyle(Mc.tags.templateDelimiter,n)):i.match("}}")?(n.tokenize=n.stack.pop(),e.makeLocalStyle(Mc.tags.templateBracket,n,"nTemplate")):e.eatWikiText(Mc.tags.template)(i,n)}}},{key:"eatExternalLinkProtocol",value:function(t){var e=this;return function(i,n){for(;t>0;)t--,i.next();return i.eol()?(n.nLink--,n.tokenize=n.stack.pop()):n.tokenize=e.inExternalLink.bind(e),e.makeLocalStyle(Mc.tags.extLinkProtocol,n)}}},{key:"inExternalLink",value:function(t,e){return t.sol()?(e.nLink--,void(e.tokenize=e.stack.pop())):t.match(/^[\s\u00a0]*\]/)?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.extLinkBracket,e,"nLink")):t.eatSpace()?(e.tokenize=this.inExternalLinkText.bind(this),this.makeStyle("",e)):t.match(/^[^\s\u00a0\]{&~']+/)||t.eatSpace()?("'"===t.peek()&&(t.match("''",!1)?e.tokenize=this.inExternalLinkText.bind(this):t.next()),this.makeStyle(Mc.tags.extLink,e)):this.eatWikiText(Mc.tags.extLink)(t,e)}},{key:"inExternalLinkText",value:function(t,e){return t.sol()?(e.nLink--,void(e.tokenize=e.stack.pop())):t.eat("]")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.extLinkBracket,e,"nLink")):t.match(/^[^'\]{&~<]+/)?this.makeStyle(Mc.tags.extLinkText,e):this.eatWikiText(Mc.tags.extLinkText)(t,e)}},{key:"inLink",value:function(t,e){return t.sol()?(e.nLink--,void(e.tokenize=e.stack.pop())):t.match(/^[\s\u00a0]*#[\s\u00a0]*/)?(e.tokenize=this.inLinkToSection.bind(this),this.makeLocalStyle(Mc.tags.link,e)):t.match(/^[\s\u00a0]*\|[\s\u00a0]*/)?(e.tokenize=this.eatLinkText(),this.makeLocalStyle(Mc.tags.linkDelimiter,e)):t.match(/^[\s\u00a0]*\]\]/)?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.linkBracket,e,"nLink")):t.match(/^[\s\u00a0]*[^\s\u00a0#|\]&~{]+/)||t.eatSpace()?this.makeStyle("".concat(Mc.tags.linkPageName," ").concat(Mc.tags.pageName),e):this.eatWikiText("".concat(Mc.tags.linkPageName," ").concat(Mc.tags.pageName))(t,e)}},{key:"inLinkToSection",value:function(t,e){return t.sol()?(e.nLink--,void(e.tokenize=e.stack.pop())):t.match(/^[^|\]&~{}]+/)?this.makeLocalStyle(Mc.tags.linkToSection,e):t.eat("|")?(e.tokenize=this.eatLinkText(),this.makeLocalStyle(Mc.tags.linkDelimiter,e)):t.match("]]")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.linkBracket,e,"nLink")):this.eatWikiText(Mc.tags.linkToSection)(t,e)}},{key:"eatLinkText",value:function(){var t,e,i=this;return function(n,s){var r;return n.match("]]")?(s.tokenize=s.stack.pop(),i.makeLocalStyle(Mc.tags.linkBracket,s,"nLink")):n.match("'''")?(t=!t,i.makeLocalStyle("".concat(Mc.tags.linkText," ").concat(Mc.tags.apostrophes),s)):n.match("''")?(e=!e,i.makeLocalStyle("".concat(Mc.tags.linkText," ").concat(Mc.tags.apostrophes),s)):(r=Mc.tags.linkText,t&&(r+=" "+Mc.tags.strong),e&&(r+=" "+Mc.tags.em),n.match(/^[^'\]{&~<]+/)?i.makeStyle(r,s):i.eatWikiText(r)(n,s))}}},{key:"eatTagName",value:function(t,e,i){var n=this;return function(s,r){for(var o="";t>0;)t--,o+=s.next();return s.eatSpace(),o=o.toLowerCase(),i?(e&&!Mc.implicitlyClosedHtmlTags[o]?r.tokenize=n.eatChar(">",Mc.tags.htmlTagBracket):r.tokenize=n.eatHtmlTagAttribute(o),n.makeLocalStyle(Mc.tags.htmlTagName,r)):(r.tokenize=e?n.eatChar(">","".concat(Mc.tags.extTagBracket," mw-ext-").concat(o)):n.eatExtTagAttribute(o),n.makeLocalStyle("".concat(Mc.tags.extTagName," mw-ext-").concat(o),r))}}},{key:"eatHtmlTagAttribute",value:function(t){var e=this;return function(i,n){return i.match(/^(?:"[^<">]*"|'[^<'>]*'|[^>/<{&~])+/)?e.makeLocalStyle(Mc.tags.htmlTagAttribute,n):i.eat(">")?(t in Mc.implicitlyClosedHtmlTags||n.inHtmlTag.push(t),n.tokenize=n.stack.pop(),e.makeLocalStyle(Mc.tags.htmlTagBracket,n)):i.match("/>")?(n.tokenize=n.stack.pop(),e.makeLocalStyle(Mc.tags.htmlTagBracket,n)):e.eatWikiText(Mc.tags.htmlTagAttribute)(i,n)}}},{key:"eatNowiki",value:function(){var t=this;return function(e){return e.match(/^[^&]+/)?"":(e.next(),t.eatHtmlEntity(e,""))}}},{key:"eatExtTagAttribute",value:function(t){var e=this;return function(i,n){if(i.match(/^(?:"[^">]*"|'[^'>]*'|[^>/<{&~])+/))return e.makeLocalStyle("".concat(Mc.tags.extTagAttribute," mw-ext-").concat(t),n);if(i.eat(">")){if(n.extName=t,"nowiki"===t||"pre"===t)n.extMode={startState:function(){},copyState:function(){},token:e.eatNowiki()};else if(t in e.config.tagModes){var s=e.config.tagModes[t];"mediawiki"!==s&&"text/mediawiki"!==s||(n.extMode=e.mediawiki,n.extState=n.extMode.startState())}return n.tokenize=e.eatExtTagArea(t),e.makeLocalStyle("".concat(Mc.tags.extTagBracket," mw-ext-").concat(t),n)}return i.match("/>")?(n.tokenize=n.stack.pop(),e.makeLocalStyle("".concat(Mc.tags.extTagBracket," mw-ext-").concat(t),n)):e.eatWikiText("".concat(Mc.tags.extTagAttribute," mw-ext-").concat(t))(i,n)}}},{key:"eatExtTagArea",value:function(t){var e=this;return function(i,n){var s,r=i.pos,o=new RegExp(""),"i").exec(r?i.string.slice(r):i.string),l=!1;if(o){if(0===o.index)return n.tokenize=e.eatExtCloseTag(t),n.extName=!1,!1!==n.extMode&&(n.extMode=!1,n.extState=!1),n.tokenize(i,n);s=o.index+r,l=i.string,i.string=l.slice(0,s)}return n.stack.push(n.tokenize),n.tokenize=e.eatExtTokens(l),n.tokenize(i,n)}}},{key:"eatExtCloseTag",value:function(t){var e=this;return function(i,n){return i.next(),i.next(),n.tokenize=e.eatTagName(t.length,!0,!1),e.makeLocalStyle("".concat(Mc.tags.extTagBracket," mw-ext-").concat(t),n)}}},{key:"eatExtTokens",value:function(t){var e=this;return function(i,n){var s;return!1===n.extMode?(s=Mc.tags.extTag,i.skipToEnd()):s="mw-tag-".concat(n.extName," ")+n.extMode.token(i,n.extState,!1===t),i.eol()&&(!1!==t&&(i.string=t),n.tokenize=n.stack.pop()),e.makeLocalStyle(s,n)}}},{key:"eatStartTable",value:function(t,e){return t.match("{|"),t.eatSpace(),e.tokenize=this.inTableDefinition.bind(this),Mc.tags.tableBracket}},{key:"inTableDefinition",value:function(t,e){return t.sol()?(e.tokenize=this.inTable.bind(this),this.inTable(t,e)):this.eatWikiText(Mc.tags.tableDefinition)(t,e)}},{key:"inTable",value:function(t,e){if(t.sol()){if(t.eatSpace(),t.eat("|"))return t.eat("-")?(t.eatSpace(),e.tokenize=this.inTableDefinition.bind(this),this.makeLocalStyle(Mc.tags.tableDelimiter,e)):t.eat("+")?(t.eatSpace(),e.tokenize=this.eatTableRow(!0,!1,!0),this.makeLocalStyle(Mc.tags.tableDelimiter,e)):t.eat("}")?(e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.tableBracket,e)):(t.eatSpace(),e.tokenize=this.eatTableRow(!0,!1),this.makeLocalStyle(Mc.tags.tableDelimiter,e));if(t.eat("!"))return t.eatSpace(),e.tokenize=this.eatTableRow(!0,!0),this.makeLocalStyle(Mc.tags.tableDelimiter,e)}return this.eatWikiText("")(t,e)}},{key:"eatTableRow",value:function(t,e,i){var n=this,s="";return i?s=Mc.tags.tableCaption:e&&(s=Mc.tags.strong),function(r,o){if(r.sol()){if(r.match(/^[\s\u00a0]*[|!]/,!1))return o.tokenize=n.inTable.bind(n),n.inTable(r,o)}else{if(r.match(/^[^'|{[<&~!]+/))return n.makeStyle(s,o);if(r.match("||")||e&&r.match("!!"))return n.isBold=!1,n.isItalic=!1,o.tokenize=n.eatTableRow(!0,e,i),n.makeLocalStyle(Mc.tags.tableDelimiter,o);if(t&&r.eat("|"))return o.tokenize=n.eatTableRow(!1,e,i),n.makeLocalStyle(Mc.tags.tableDelimiter,o)}return n.eatWikiText(s)(r,o)}}},{key:"eatFreeExternalLinkProtocol",value:function(t,e){return t.match(this.urlProtocols),e.tokenize=this.eatFreeExternalLink.bind(this),this.makeLocalStyle(Mc.tags.freeExtLinkProtocol,e)}},{key:"eatFreeExternalLink",value:function(t,e){if(t.eol());else if(t.match(/^[^\s\u00a0{[\]<>~).,']*/))if("~"===t.peek()){if(!t.match(/^~~~+/,!1))return t.match(/^~*/),this.makeLocalStyle(Mc.tags.freeExtLink,e)}else if("{"===t.peek()){if(!t.match("{{",!1))return t.next(),this.makeLocalStyle(Mc.tags.freeExtLink,e)}else if("'"===t.peek()){if(!t.match("''",!1))return t.next(),this.makeLocalStyle(Mc.tags.freeExtLink,e)}else if(t.match(/^[).,]+(?=[^\s\u00a0{[\]<>~).,])/))return this.makeLocalStyle(Mc.tags.freeExtLink,e);return e.tokenize=e.stack.pop(),this.makeLocalStyle(Mc.tags.freeExtLink,e)}},{key:"eatWikiText",value:function(t){var e=this;return function(i,n){var s,r,o,l,a,h,c;if(i.sol()){if(!i.match("//",!1)&&i.match(e.urlProtocols))return n.stack.push(n.tokenize),n.tokenize=e.eatFreeExternalLink.bind(e),e.makeLocalStyle(Mc.tags.freeExtLinkProtocol,n);switch(s=i.next()){case"-":if(i.match(/^---+/))return Mc.tags.hr;break;case"=":if(r=i.match(/^(={0,5})(.+?(=\1\s*)(.*\S).*?)?)$/))return i.backUp(r[2].length),n.stack.push(n.tokenize),n.tokenize=e.eatSectionHeader(r[3].length),Mc.tags.sectionHeader+" "+Mc.tags["sectionHeader".concat(r[1].length+1)];break;case"*":case"#":case";":return i.match(/^[*#;:]*/),Mc.tags.list;case":":return i.match(/^:*{\|/,!1)&&(n.stack.push(n.tokenize),n.tokenize=e.eatStartTable.bind(e)),i.match(/^[*#;:]*/),Mc.tags.indenting;case" ":if(!i.match(/^[\s\u00a0]*:*{\|/,!1))return Mc.tags.skipFormatting;if(i.eatSpace(),i.match(/^:+/))return n.stack.push(n.tokenize),n.tokenize=e.eatStartTable.bind(e),Mc.tags.indenting;i.eat("{");case"{":if(i.eat("|"))return i.eatSpace(),n.stack.push(n.tokenize),n.tokenize=e.inTableDefinition.bind(e),Mc.tags.tableBracket}}else s=i.next();switch(s){case"&":return e.makeStyle(e.eatHtmlEntity(i,t),n);case"'":if(i.match(/^'*(?=''''')/)||i.match(/^'''(?!')/,!1))break;if(i.match("''"))return e.firstSingleLetterWord||i.match("''",!1)||e.prepareItalicForCorrection(i),e.isBold=!e.isBold,e.makeLocalStyle(Mc.tags.apostrophesBold,n);if(i.eat("'"))return e.isItalic=!e.isItalic,e.makeLocalStyle(Mc.tags.apostrophesItalic,n);break;case"[":if(i.eat("[")){if(i.eatSpace(),/[^\]|[]/.test(i.peek()))return n.nLink++,n.stack.push(n.tokenize),n.tokenize=e.inLink.bind(e),e.makeLocalStyle(Mc.tags.linkBracket,n)}else if(o=i.match(e.urlProtocols))return n.nLink++,i.backUp(o[0].length),n.stack.push(n.tokenize),n.tokenize=e.eatExternalLinkProtocol(o[0].length),e.makeLocalStyle(Mc.tags.extLinkBracket,n);break;case"{":if(i.match(/^{{(?!{|[^{}]*}}(?!}))/))return i.eatSpace(),n.stack.push(n.tokenize),n.tokenize=e.inVariable.bind(e),e.makeLocalStyle(Mc.tags.templateVariableBracket,n);if(i.match(/^{(?!{(?!{))[\s\u00a0]*/))return"#"===i.peek()?(n.nExt++,n.stack.push(n.tokenize),n.tokenize=e.inParserFunctionName.bind(e),e.makeLocalStyle(Mc.tags.parserFunctionBracket,n)):!(l=i.match(/^([^\s\u00a0}[\]<{'|&:]+)(:|[\s\u00a0]*)(\}\}?)?(.)?/))||(i.backUp(l[0].length),":"!==l[2]&&void 0!==l[4]&&"}}"!==l[3]||!(l[1].toLowerCase()in e.config.functionSynonyms[0])&&!(l[1]in e.config.functionSynonyms[1]))?(n.nTemplate++,n.stack.push(n.tokenize),n.tokenize=e.eatTemplatePageName(!1),e.makeLocalStyle(Mc.tags.templateBracket,n)):(n.nExt++,n.stack.push(n.tokenize),n.tokenize=e.inParserFunctionName.bind(e),e.makeLocalStyle(Mc.tags.parserFunctionBracket,n));break;case"<":if(a=!!i.eat("/"),h=i.match(/^[^>/\s\u00a0.*,[\]{}$^+?|/\\'`~<=!@#%&()-]+/),i.match("!--"))return c=e.eatBlock(Mc.tags.comment,"--\x3e"),n.stack.push(n.tokenize),n.tokenize=c,c(i,n);if(h){if((h=h[0].toLowerCase())in e.config.tags)return!0===a?Mc.tags.error:(i.backUp(h.length),n.stack.push(n.tokenize),n.tokenize=e.eatTagName(h.length,a,!1),e.makeLocalStyle("".concat(Mc.tags.extTagBracket," mw-ext-").concat(h),n));if(h in Mc.permittedHtmlTags)return!0===a&&h!==n.inHtmlTag.pop()?(i.pos++,Mc.tags.error):!0===a&&h in Mc.implicitlyClosedHtmlTags?Mc.tags.error:(i.backUp(h.length),n.stack.push(n.tokenize),n.tokenize=e.eatTagName(h.length,a||h in Mc.implicitlyClosedHtmlTags,!0),e.makeLocalStyle(Mc.tags.htmlTagBracket,n));i.backUp(h.length)}break;case"~":if(i.match(/^~{2,4}/))return Mc.tags.signature;break;case"_":for(r=1;i.eat("_");)r++;if(r>2)return i.eol()||i.backUp(2),e.makeStyle(t,n);if(2===r&&(l=i.match(/^([^\s\u00a0>}[\]<{'|&:~]+?)__/))&&l[0])return"__"+l[0].toLowerCase()in e.config.doubleUnderscore[0]||"__"+l[0]in e.config.doubleUnderscore[1]?Mc.tags.doubleUnderscore:(i.eol()||i.backUp(2),e.makeStyle(t,n));break;default:if(/[\s\u00a0]/.test(s)&&(i.eatSpace(),i.match(e.urlProtocols,!1)&&!i.match("//")))return n.stack.push(n.tokenize),n.tokenize=e.eatFreeExternalLinkProtocol.bind(e),e.makeStyle(t,n)}return i.match(/^[^\s\u00a0_>}[\]<{'|&:~=]+/),e.makeStyle(t,n)}}},{key:"prepareItalicForCorrection",value:function(t){var e=t.pos,i=t.string.slice(0,e-3),n=i.slice(-1),s=i.slice(-2,-1);if(" "===n){if(this.firstMultiLetterWord||this.firstSpace)return;this.firstSpace=e}else if(" "===s)this.firstSingleLetterWord=e;else{if(this.firstMultiLetterWord)return;this.firstMultiLetterWord=e}this.wasBold=this.isBold,this.wasItalic=this.isItalic}},{key:"mediawiki",get:function(){var t=this;return{name:"mediawiki",startState:function(){return{tokenize:t.eatWikiText(""),stack:[],inHtmlTag:[],extName:!1,extMode:!1,extState:!1,nTemplate:0,nLink:0,nExt:0}},copyState:function(t){return{tokenize:t.tokenize,stack:t.stack.concat([]),inHtmlTag:t.inHtmlTag.concat([]),extName:t.extName,extMode:t.extMode,extState:!1!==t.extMode&&t.extMode.copyState(t.extState),nTemplate:t.nTemplate,nLink:t.nLink,nExt:t.nExt}},token:function(e,i){var n,s,r,o,l=[],a=[];if(t.oldTokens.length>0)return r=t.oldTokens.shift(),e.pos=r.pos,i=r.state,r.style;e.sol()&&(t.isBold=!1,t.isItalic=!1,t.firstSingleLetterWord=null,t.firstMultiLetterWord=null,t.firstSpace=null);do{if(n=i.tokenize(e,i),!(o=t.firstSingleLetterWord||t.firstMultiLetterWord||t.firstSpace))return t.oldStyle=n,n;o!==s&&(s=o,a.length>0&&(l=l.concat(a),a=[])),a.push({pos:e.pos,style:n,state:(i.extMode||t.mediawiki).copyState(i)})}while(!e.eol());if(t.isBold&&t.isItalic){if(t.isItalic=t.wasItalic,t.isBold=t.wasBold,t.firstSingleLetterWord=null,t.firstMultiLetterWord=null,t.firstSpace=null,!(l.length>0))return e.pos=a[0].pos-2,t.oldStyle;l[l.length-1].pos++,t.oldTokens=l}else t.oldTokens=l.concat(a);return r=t.oldTokens.shift(),e.pos=r.pos,i=r.state,r.style},blankLine:function(t){t.extMode&&t.extMode.blankLine&&t.extMode.blankLine(t.extState)},tokenTable:this.tokenTable}}}],i&&Cc(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();mw.loader.getState("ext.wikiEditor")&&mw.hook("wikiEditor.toolbarReady").add((function(t){new gc(t,function(){var t=new Dc((arguments.length>0&&void 0!==arguments[0]?arguments[0]:null)||mw.config.get("extCodeMirrorConfig")).mediawiki,e=bl.define(t),i=function(t,e){let i,n=[el];return t instanceof Yo&&(t.module&&n.push(Es.styleModule.of(t.module)),i=t.themeType),i?n.push(Xo.computeN([Es.darkTheme],(e=>e.facet(Es.darkTheme)==("dark"==i)?[t]:[]))):n.push(Xo.of(t)),n}(Yo.define(Mc.getTagStyles(t)));return new Ho(e,i)}()).addCodeMirrorToWikiEditor()}))})(); //# sourceMappingURL=main.js.map.json