You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9 lines
163 KiB
9 lines
163 KiB
var In=Object.create;var Lt=Object.defineProperty,Hn=Object.defineProperties,Fn=Object.getOwnPropertyDescriptor,Wn=Object.getOwnPropertyDescriptors,zn=Object.getOwnPropertyNames,Mi=Object.getOwnPropertySymbols,qn=Object.getPrototypeOf,Di=Object.prototype.hasOwnProperty,Kn=Object.prototype.propertyIsEnumerable;var Oi=(n,t,e)=>t in n?Lt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Se=(n,t)=>{for(var e in t||(t={}))Di.call(t,e)&&Oi(n,e,t[e]);if(Mi)for(var e of Mi(t))Kn.call(t,e)&&Oi(n,e,t[e]);return n},ke=(n,t)=>Hn(n,Wn(t)),Ti=n=>Lt(n,"__esModule",{value:!0});var $n=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),jn=(n,t)=>{Ti(n);for(var e in t)Lt(n,e,{get:t[e],enumerable:!0})},Gn=(n,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of zn(t))!Di.call(n,i)&&i!=="default"&&Lt(n,i,{get:()=>t[i],enumerable:!(e=Fn(t,i))||e.enumerable});return n},Ri=n=>Gn(Ti(Lt(n!=null?In(qn(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var Ce=(n,t,e)=>new Promise((i,s)=>{var r=h=>{try{l(e.next(h))}catch(a){s(a)}},o=h=>{try{l(e.throw(h))}catch(a){s(a)}},l=h=>h.done?i(h.value):Promise.resolve(h.value).then(r,o);l((e=e.apply(n,t)).next())});var Ei=$n(Zt=>{"use strict";Object.defineProperty(Zt,"__esModule",{value:!0});require("obsidian");var Un=n=>{var t;return n?(t=n.plugins.plugins.dataview)===null||t===void 0?void 0:t.api:window.DataviewAPI},Jn=n=>n.plugins.enabledPlugins.has("dataview");Zt.getAPI=Un;Zt.isPluginEnabled=Jn});jn(exports,{default:()=>Ci});var Nn=Ri(Ei()),Et=Ri(require("obsidian"));var x=class{constructor(){}lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,1|2),this.decompose(e,this.length,s,1),G.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){let i=[];return this.decompose(t,e,i,0),G.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new yt(this),r=new yt(t);for(let o=e,l=e;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(t=1){return new yt(this,t)}iterRange(t,e=this.length){return new Ae(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new Me(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?x.empty:t.length<=32?new D(t):G.from(D.split(t,[]))}},D=class extends x{constructor(t,e=Xn(t)){super();this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((e?i:l)>=t)return new Bi(s,l,i,o);s=l+1,i++}}decompose(t,e,i,s){let r=t<=0&&e>=this.length?this:new D(Li(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(s&1){let o=i.pop(),l=Qt(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new D(l,o.length+r.length));else{let h=l.length>>1;i.push(new D(l.slice(0,h)),new D(l.slice(h)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof D))return super.replace(t,e,i);let s=Qt(this.text,Qt(i.text,Li(this.text,0,t)),e),r=this.length+i.length-(e-t);return s.length<=32?new D(s,r):G.from(D.split(s,[]),r)}sliceString(t,e=this.length,i=`
|
|
`){let s="";for(let r=0,o=0;r<=e&&o<this.text.length;o++){let l=this.text[o],h=r+l.length;r>t&&o&&(s+=i),t<h&&e>r&&(s+=l.slice(Math.max(0,t-r),e-r)),r=h+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,i.length==32&&(e.push(new D(i,s)),i=[],s=-1);return s>-1&&e.push(new D(i,s)),e}},G=class extends x{constructor(t,e){super();this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,h=i+o.lines-1;if((e?h:l)>=t)return o.lineInner(t,e,i,s);s=l+1,i=h+1}}decompose(t,e,i,s){for(let r=0,o=0;o<=e&&r<this.children.length;r++){let l=this.children[r],h=o+l.length;if(t<=h&&e>=o){let a=s&((o<=t?1:0)|(h>=e?2:0));o>=t&&h<=e&&!a?i.push(l):l.decompose(t-o,e-o,i,a)}o=h+1}}replace(t,e,i){if(i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(t>=r&&e<=l){let h=o.replace(t-r,e-r,i),a=this.lines-o.lines+h.lines;if(h.lines<a>>5-1&&h.lines>a>>5+1){let c=this.children.slice();return c[s]=h,new G(c,this.length-(e-t)+i.length)}return super.replace(r,l,h)}r=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
|
|
`){let s="";for(let r=0,o=0;r<this.children.length&&o<=e;r++){let l=this.children[r],h=o+l.length;o>t&&r&&(s+=i),t<h&&e>o&&(s+=l.sliceString(t-o,e-o,i)),o=h+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof G))return 0;let i=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 i;let h=this.children[s],a=t.children[r];if(h!=a)return i+h.scanIdentical(a,e);i+=h.length+1}}static from(t,e=t.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let u of t)i+=u.lines;if(i<32){let u=[];for(let p of t)p.flatten(u);return new D(u,e)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],h=0,a=-1,c=[];function f(u){let p;if(u.lines>r&&u instanceof G)for(let g of u.children)f(g);else u.lines>o&&(h>o||!h)?(d(),l.push(u)):u instanceof D&&h&&(p=c[c.length-1])instanceof D&&u.lines+p.lines<=32?(h+=u.lines,a+=u.length+1,c[c.length-1]=new D(p.text.concat(u.text),p.length+1+u.length)):(h+u.lines>s&&d(),h+=u.lines,a+=u.length+1,c.push(u))}function d(){h!=0&&(l.push(c.length==1?c[0]:G.from(c,a)),a=-1,h=c.length=0)}for(let u of t)f(u);return d(),l.length==1?l[0]:new G(l,e)}};x.empty=new D([""],0);function Xn(n){let t=-1;for(let e of n)t+=e.length+1;return t}function Qt(n,t,e=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],h=s+l.length;h>=e&&(h>i&&(l=l.slice(0,i-s)),s<e&&(l=l.slice(e-s)),o?(t[t.length-1]+=l,o=!1):t.push(l)),s=h+1}return t}function Li(n,t,e){return Qt(n,[""],t,e)}var yt=class{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof D?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof D?s.text.length:s.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
|
|
`,this;t--}else if(s instanceof D){let h=s.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,h.length>Math.max(0,t))return this.value=t==0?h:e>0?h.slice(t):h.slice(0,h.length-t),this;t-=h.length}else{let h=s.children[o+(e<0?-1:0)];t>h.length?(t-=h.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(e>0?1:(h instanceof D?h.text.length:h.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}},Ae=class{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new yt(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:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.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!=""}},Me=class{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol!="undefined"&&(x.prototype[Symbol.iterator]=function(){return this.iter()},yt.prototype[Symbol.iterator]=Ae.prototype[Symbol.iterator]=Me.prototype[Symbol.iterator]=function(){return this});var Bi=class{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}},wt="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(n=>n?parseInt(n,36):1);for(let n=1;n<wt.length;n++)wt[n]+=wt[n-1];function Yn(n){for(let t=1;t<wt.length;t+=2)if(wt[t]>n)return wt[t-1]<=n;return!1}function Pi(n){return n>=127462&&n<=127487}var Vi=8205;function Q(n,t,e=!0,i=!0){return(e?Ni:Zn)(n,t,i)}function Ni(n,t,e){if(t==n.length)return t;t&&Ii(n.charCodeAt(t))&&Hi(n.charCodeAt(t-1))&&t--;let i=_t(n,t);for(t+=De(i);t<n.length;){let s=_t(n,t);if(i==Vi||s==Vi||e&&Yn(s))t+=De(s),i=s;else if(Pi(s)){let r=0,o=t-2;for(;o>=0&&Pi(_t(n,o));)r++,o-=2;if(r%2==0)break;t+=2}else break}return t}function Zn(n,t,e){for(;t>0;){let i=Ni(n,t-2,e);if(i<t)return i;t--}return 0}function Ii(n){return n>=56320&&n<57344}function Hi(n){return n>=55296&&n<56320}function _t(n,t){let e=n.charCodeAt(t);if(!Hi(e)||t+1==n.length)return e;let i=n.charCodeAt(t+1);return Ii(i)?(e-55296<<10)+(i-56320)+65536:e}function De(n){return n<65536?1:2}var Oe=/\r\n?|\n/,K=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(K||(K={})),J=class{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let r=this.sections[e++],o=this.sections[e++];o<0?(t(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(t,e=!1){Te(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new J(t)}composeDesc(t){return this.empty?t:t.empty?this:Fi(this,t)}mapDesc(t,e=!1){return t.empty?this:Re(this,t,e)}mapPos(t,e=-1,i=K.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],a=s+l;if(h<0){if(a>t)return r+(t-s);r+=l}else{if(i!=K.Simple&&a>=t&&(i==K.TrackDel&&s<t&&a>t||i==K.TrackBefore&&s<t||i==K.TrackAfter&&a>t))return null;if(a>t||a==t&&e<0&&!l)return t==s||e<0?r:r+h;r+=h}s=a}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=e&&l>=t)return s<t&&l>e?"cover":!0;s=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new J(t)}static create(t){return new J(t)}},T=class extends J{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 Te(this,(e,i,s,r,o)=>t=t.replace(s,s+(i-e),o),!1),t}mapDesc(t,e=!1){return Re(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,r=0;s<e.length;s+=2){let o=e[s],l=e[s+1];if(l>=0){e[s]=l,e[s+1]=o;let h=s>>1;for(;i.length<h;)i.push(x.empty);i.push(o?t.slice(r,r+o):x.empty)}r+=o}return new T(e,i)}compose(t){return this.empty?t:t.empty?this:Fi(this,t,!0)}map(t,e=!1){return t.empty?this:Re(this,t,e,!0)}iterChanges(t,e=!1){Te(this,t,e)}get desc(){return J.create(this.sections)}filter(t){let e=[],i=[],s=[],r=new bt(this);t:for(let o=0,l=0;;){let h=o==t.length?1e9:t[o++];for(;l<h||l==h&&r.len==0;){if(r.done)break t;let c=Math.min(r.len,h-l);F(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;F(e,c,f),f>0&&st(i,e,r.text),r.forward(c),l+=c}let a=t[o++];for(;l<a;){if(r.done)break t;let c=Math.min(r.len,a-l);F(e,c,-1),F(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new T(e,i),filtered:J.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):s==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let s=[],r=[],o=0,l=null;function h(c=!1){if(!c&&!s.length)return;o<e&&F(s,e-o,-1);let f=new T(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function a(c){if(Array.isArray(c))for(let f of c)a(f);else if(c instanceof T){if(c.length!=e)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${e})`);h(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:d=f,insert:u}=c;if(f>d||f<0||d>e)throw new RangeError(`Invalid change range ${f} to ${d} (in doc of length ${e})`);let p=u?typeof u=="string"?x.of(u.split(i||Oe)):u:x.empty,g=p.length;if(f==d&&g==0)return;f<o&&h(),f>o&&F(s,f-o,-1),F(s,d-f,g),st(r,s,p),o=d}}return a(t),h(!l),l}static empty(t){return new T(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;s<t.length;s++){let r=t[s];if(typeof r=="number")e.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)e.push(r[0],0);else{for(;i.length<s;)i.push(x.empty);i[s]=x.of(r.slice(1)),e.push(r[0],i[s].length)}}}return new T(e,i)}static createSet(t,e){return new T(t,e)}};function F(n,t,e,i=!1){if(t==0&&e<=0)return;let s=n.length-2;s>=0&&e<=0&&e==n[s+1]?n[s]+=t:t==0&&n[s]==0?n[s+1]+=e:i?(n[s]+=t,n[s+1]+=e):n.push(t,e)}function st(n,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(e);else{for(;n.length<i;)n.push(x.empty);n.push(e)}}function Te(n,t,e){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],h=n.sections[o++];if(h<0)s+=l,r+=l;else{let a=s,c=r,f=x.empty;for(;a+=l,c+=h,h&&i&&(f=f.append(i[o-2>>1])),!(e||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],h=n.sections[o++];t(s,a,r,c,f),s=a,r=c}}}function Re(n,t,e,i=!1){let s=[],r=i?[]:null,o=new bt(n),l=new bt(t);for(let h=-1;;)if(o.ins==-1&&l.ins==-1){let a=Math.min(o.len,l.len);F(s,a,-1),o.forward(a),l.forward(a)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let a=l.len;for(F(s,l.ins,-1);a;){let c=Math.min(o.len,a);o.ins>=0&&h<o.i&&o.len<=c&&(F(s,0,o.ins),r&&st(r,s,o.text),h=o.i),o.forward(c),a-=c}l.next()}else if(o.ins>=0){let a=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);a+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;F(s,a,h<o.i?o.ins:0),r&&h<o.i&&st(r,s,o.text),h=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?T.createSet(s,r):J.create(s);throw new Error("Mismatched change set lengths")}}function Fi(n,t,e=!1){let i=[],s=e?[]:null,r=new bt(n),o=new bt(t);for(let l=!1;;){if(r.done&&o.done)return s?T.createSet(i,s):J.create(i);if(r.ins==0)F(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)F(i,0,o.ins,l),s&&st(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(r.len2,o.len),a=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;F(i,h,c,l),s&&c&&st(s,i,o.text)}else o.ins==-1?(F(i,r.off?0:r.len,h,l),s&&st(s,i,r.textBit(h))):(F(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&st(s,i,o.text));l=(r.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>a),r.forward2(h),o.forward(h)}}}}var bt=class{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?x.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?x.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}},nt=class{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let t=this.flags&3;return t==3?null:t}get goalColumn(){let t=this.flags>>5;return t==33554431?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new nt(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return w.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return w.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||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return w.range(t.anchor,t.head)}static create(t,e,i){return new nt(t,e,i)}},w=class{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:w.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;e<this.ranges.length;e++)if(!this.ranges[e].eq(t.ranges[e]))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new w([this.main],0)}addRange(t,e=!0){return w.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,w.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new w(t.ranges.map(e=>nt.fromJSON(e)),t.main)}static single(t,e=t){return new w([w.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let r=t[s];if(r.empty?r.from<=i:r.from<i)return w.normalized(t.slice(),e);i=r.to}return new w(t,e)}static cursor(t,e=0,i,s){return nt.create(t,t,(e==0?0:e<0?4:8)|(i==null?3:Math.min(2,i))|(s??33554431)<<5)}static range(t,e,i){let s=(i??33554431)<<5;return e<t?nt.create(e,t,16|s|8):nt.create(t,e,s|(e>t?4:0))}static normalized(t,e=0){let i=t[e];t.sort((s,r)=>s.from-r.from),e=t.indexOf(i);for(let s=1;s<t.length;s++){let r=t[s],o=t[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,h=Math.max(r.to,o.to);s<=e&&e--,t.splice(--s,2,r.anchor>r.head?w.range(h,l):w.range(l,h))}}return new w(t,e)}};function Wi(n,t){for(let e of n.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}var Ee=0,v=class{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=Ee++,this.default=t([]),this.extensions=typeof r=="function"?r(this):r}static define(t={}){return new v(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:Le),!!t.static,t.enables)}of(t){return new Bt([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Bt(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Bt(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}};function Le(n,t){return n==t||n.length==t.length&&n.every((e,i)=>e===t[i])}var Bt=class{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=Ee++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,o=t[r]>>1,l=this.type==2,h=!1,a=!1,c=[];for(let f of this.dependencies)f=="doc"?h=!0:f=="selection"?a=!0:(((e=t[f.id])!==null&&e!==void 0?e:1)&1)==0&&c.push(t[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,d){if(h&&d.docChanged||a&&(d.docChanged||d.selection)||Be(f,c)){let u=i(f);if(l?!zi(u,f.values[o],s):!s(u,f.values[o]))return f.values[o]=u,1}return 0},reconfigure:(f,d)=>{let u=i(f),p=d.config.address[r];if(p!=null){let g=ee(d,p);if(this.dependencies.every(m=>m instanceof v?d.facet(m)===f.facet(m):m instanceof rt?d.field(m,!1)==f.field(m,!1):!0)||(l?zi(u,g,s):s(u,g)))return f.values[o]=g,0}return f.values[o]=u,1}}}};function zi(n,t,e){if(n.length!=t.length)return!1;for(let i=0;i<n.length;i++)if(!e(n[i],t[i]))return!1;return!0}function Be(n,t){let e=!1;for(let i of t)It(n,i)&1&&(e=!0);return e}function Qn(n,t,e){let i=e.map(h=>n[h.id]),s=e.map(h=>h.type),r=i.filter(h=>!(h&1)),o=n[t.id]>>1;function l(h){let a=[];for(let c=0;c<i.length;c++){let f=ee(h,i[c]);if(s[c]==2)for(let d of f)a.push(d);else a.push(f)}return t.combine(a)}return{create(h){for(let a of i)It(h,a);return h.values[o]=l(h),1},update(h,a){if(!Be(h,r))return 0;let c=l(h);return t.compare(c,h.values[o])?0:(h.values[o]=c,1)},reconfigure(h,a){let c=Be(h,i),f=a.config.facets[t.id],d=a.facet(t);if(f&&!c&&Le(e,f))return h.values[o]=d,0;let u=l(h);return t.compare(u,d)?(h.values[o]=d,0):(h.values[o]=u,1)}}}var qi=v.define({static:!0}),rt=class{constructor(t,e,i,s,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(t){let e=new rt(Ee++,t.create,t.update,t.compare||((i,s)=>i===s),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(qi).find(i=>i.field==this);return((e==null?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,s)=>{let r=i.values[e],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[e]=o,1)},reconfigure:(i,s)=>s.config.address[this.id]!=null?(i.values[e]=s.field(this),0):(i.values[e]=this.create(i),1)}}init(t){return[this,qi.of({field:this,create:t})]}get extension(){return this}},vt={lowest:4,low:3,default:2,high:1,highest:0};function Pt(n){return t=>new Pe(t,n)}var Ki={highest:Pt(vt.highest),high:Pt(vt.high),default:Pt(vt.default),low:Pt(vt.low),lowest:Pt(vt.lowest)},Pe=class{constructor(t,e){this.inner=t,this.prec=e}},Vt=class{of(t){return new te(this,t)}reconfigure(t){return Vt.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}},te=class{constructor(t,e){this.compartment=t,this.inner=e}},Nt=class{constructor(t,e,i,s,r,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],r=Object.create(null),o=new Map;for(let d of _n(t,e,o))d instanceof rt?s.push(d):(r[d.facet.id]||(r[d.facet.id]=[])).push(d);let l=Object.create(null),h=[],a=[];for(let d of s)l[d.id]=a.length<<1,a.push(u=>d.slot(u));let c=i==null?void 0:i.config.facets;for(let d in r){let u=r[d],p=u[0].facet,g=c&&c[d]||[];if(u.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,Le(g,u))h.push(i.facet(p));else{let m=p.combine(u.map(b=>b.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of u)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=a.length<<1,a.push(b=>m.dynamicSlot(b)));l[p.id]=a.length<<1,a.push(m=>Qn(m,p,u))}}let f=a.map(d=>d(l));return new Nt(t,o,f,l,h,r)}};function _n(n,t,e){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let h=s.get(o);if(h!=null){if(h<=l)return;let a=i[h].indexOf(o);a>-1&&i[h].splice(a,1),o instanceof te&&e.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let a of o)r(a,l);else if(o instanceof te){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let a=t.get(o.compartment)||o.inner;e.set(o.compartment,a),r(a,l)}else if(o instanceof Pe)r(o.inner,o.prec);else if(o instanceof rt)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Bt)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,l);else{let a=o.extension;if(!a)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(a,l)}}return r(n,vt.default),i.reduce((o,l)=>o.concat(l))}function It(n,t){if(t&1)return 2;let e=t>>1,i=n.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[e]=4;let s=n.computeSlot(n,n.config.dynamicSlots[e]);return n.status[e]=2|s}function ee(n,t){return t&1?n.config.staticValues[t>>1]:n.values[t>>1]}var $i=v.define(),ji=v.define({combine:n=>n.some(t=>t),static:!0}),Gi=v.define({combine:n=>n.length?n[0]:void 0,static:!0}),Ui=v.define(),Ji=v.define(),Xi=v.define(),Yi=v.define({combine:n=>n.length?n[0]:!1}),xt=class{constructor(t,e){this.type=t,this.value=e}static define(){return new Zi}},Zi=class{of(t){return new xt(this,t)}},Qi=class{constructor(t){this.map=t}of(t){return new E(this,t)}},E=class{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new E(this.type,e)}is(t){return this.type==t}static define(t={}){return new Qi(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let r=s.map(e);r&&i.push(r)}return i}};E.reconfigure=E.define();E.appendConfig=E.define();var P=class{constructor(t,e,i,s,r,o){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Wi(i,e.newLength),r.some(l=>l.type==P.time)||(this.annotations=r.concat(P.time.of(Date.now())))}static create(t,e,i,s,r,o){return new P(t,e,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(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(P.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}};P.time=xt.define();P.userEvent=xt.define();P.addToHistory=xt.define();P.remote=xt.define();function tr(n,t){let e=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==t.length||t[s]>=n[i]))r=n[i++],o=n[i++];else if(s<t.length)r=t[s++],o=t[s++];else return e;!e.length||e[e.length-1]<r?e.push(r,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function _i(n,t,e){var i;let s,r,o;return e?(s=t.changes,r=T.empty(t.changes.length),o=n.changes.compose(t.changes)):(s=t.changes.map(n.changes),r=n.changes.mapDesc(t.changes,!0),o=n.changes.compose(s)),{changes:o,selection:t.selection?t.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:E.mapEffects(n.effects,s).concat(E.mapEffects(t.effects,r)),annotations:n.annotations.length?n.annotations.concat(t.annotations):t.annotations,scrollIntoView:n.scrollIntoView||t.scrollIntoView}}function Ve(n,t,e){let i=t.selection,s=St(t.annotations);return t.userEvent&&(s=s.concat(P.userEvent.of(t.userEvent))),{changes:t.changes instanceof T?t.changes:T.of(t.changes||[],e,n.facet(Gi)),selection:i&&(i instanceof w?i:w.single(i.anchor,i.head)),effects:St(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function ts(n,t,e){let i=Ve(n,t.length?t[0]:{},n.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let r=1;r<t.length;r++){t[r].filter===!1&&(e=!1);let o=!!t[r].sequential;i=_i(i,Ve(n,t[r],o?i.changes.newLength:n.doc.length),o)}let s=P.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return ir(e?er(s):s)}function er(n){let t=n.startState,e=!0;for(let s of t.facet(Ui)){let r=s(n);if(r===!1){e=!1;break}Array.isArray(r)&&(e=e===!0?r:tr(e,r))}if(e!==!0){let s,r;if(e===!1)r=n.changes.invertedDesc,s=T.empty(t.doc.length);else{let o=n.changes.filter(e);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=P.create(t,s,n.selection&&n.selection.map(r),E.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=t.facet(Ji);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof P?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof P?n=r[0]:n=ts(t,St(r),!1)}return n}function ir(n){let t=n.startState,e=t.facet(Xi),i=n;for(let s=e.length-1;s>=0;s--){let r=e[s](n);r&&Object.keys(r).length&&(i=_i(n,Ve(t,r,n.changes.newLength),!0))}return i==n?n:P.create(t,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}var sr=[];function St(n){return n==null?sr:Array.isArray(n)?n:[n]}var X=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(X||(X={})),nr=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Ne;try{Ne=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(n){}function rr(n){if(Ne)return Ne.test(n);for(let t=0;t<n.length;t++){let e=n[t];if(/\w/.test(e)||e>"\x80"&&(e.toUpperCase()!=e.toLowerCase()||nr.test(e)))return!0}return!1}function or(n){return t=>{if(!/\S/.test(t))return X.Space;if(rr(t))return X.Word;for(let e=0;e<n.length;e++)if(t.indexOf(n[e])>-1)return X.Word;return X.Other}}var S=class{constructor(t,e,i,s,r,o){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)It(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return It(this,i),ee(this,i)}update(...t){return ts(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:s}=e;for(let o of t.effects)o.is(Vt.reconfigure)?(e&&(s=new Map,e.compartments.forEach((l,h)=>s.set(h,l)),e=null),s.set(o.value.compartment,o.value.extension)):o.is(E.reconfigure)?(e=null,i=o.value):o.is(E.appendConfig)&&(e=null,i=St(i).concat(o.value));let r;e?r=t.startState.values.slice():(e=Nt.resolve(i,s,this),r=new S(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(l,h)=>h.reconfigure(l,this),null).values),new S(e,t.newDoc,t.newSelection,r,(o,l)=>l.update(o,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:w.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],o=St(i.effects);for(let l=1;l<e.ranges.length;l++){let h=t(e.ranges[l]),a=this.changes(h.changes),c=a.map(s);for(let d=0;d<l;d++)r[d]=r[d].map(c);let f=s.mapDesc(a,!0);r.push(h.range.map(f)),s=s.compose(c),o=E.mapEffects(o,c).concat(E.mapEffects(St(h.effects),f))}return{changes:s,selection:w.create(r,e.mainIndex),effects:o}}changes(t=[]){return t instanceof T?t:T.of(t,this.doc.length,this.facet(S.lineSeparator))}toText(t){return x.of(t.split(this.facet(S.lineSeparator)||Oe))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(It(this,e),ee(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof rt&&this.config.address[s.id]!=null&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(t,r)){let o=i[r],l=t[r];s.push(o.init(h=>o.spec.fromJSON(l,h)))}}return S.create({doc:t.doc,selection:w.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=Nt.resolve(t.extensions||[],new Map),i=t.doc instanceof x?t.doc:x.of((t.doc||"").split(e.staticFacet(S.lineSeparator)||Oe)),s=t.selection?t.selection instanceof w?t.selection:w.single(t.selection.anchor,t.selection.head):w.single(0);return Wi(s,i.length),e.staticFacet(ji)||(s=s.asSingle()),new S(e,i,s,e.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(S.tabSize)}get lineBreak(){return this.facet(S.lineSeparator)||`
|
|
`}get readOnly(){return this.facet(Yi)}phrase(t,...e){for(let i of this.facet(S.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>e.length?i:e[r-1]})),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet($i))for(let o of r(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&s.push(o[t]);return s}charCategorizer(t){return or(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let h=Q(e,o,!1);if(r(e.slice(h,o))!=X.Word)break;o=h}for(;l<s;){let h=Q(e,l);if(r(e.slice(l,h))!=X.Word)break;l=h}return o==l?null:w.range(o+i,l+i)}};S.allowMultipleSelections=ji;S.tabSize=v.define({combine:n=>n.length?n[0]:4});S.lineSeparator=Gi;S.readOnly=Yi;S.phrases=v.define({compare(n,t){let e=Object.keys(n),i=Object.keys(t);return e.length==i.length&&e.every(s=>n[s]==t[s])}});S.languageData=$i;S.changeFilter=Ui;S.transactionFilter=Ji;S.transactionExtender=Xi;Vt.reconfigure=E.define();var ot=class{eq(t){return this==t}range(t,e=t){return kt.create(t,e,this)}};ot.prototype.startSide=ot.prototype.endSide=0;ot.prototype.point=!1;ot.prototype.mapMode=K.TrackDel;var kt=class{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new kt(t,e,i)}};function Ie(n,t){return n.from-t.from||n.value.startSide-t.value.startSide}var ie=class{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let h=o+l>>1,a=r[h]-t||(i?this.value[h].endSide:this.value[h].startSide)-e;if(h==o)return a>=0?o:l;a>=0?l=h:o=h+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+t,this.to[r]+t,this.value[r])===!1)return!1}map(t,e){let i=[],s=[],r=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let a=this.value[h],c=this.from[h]+t,f=this.to[h]+t,d,u;if(c==f){let p=e.mapPos(c,a.startSide,a.mapMode);if(p==null||(d=u=p,a.startSide!=a.endSide&&(u=e.mapPos(c,a.endSide),u<d)))continue}else if(d=e.mapPos(c,a.startSide),u=e.mapPos(f,a.endSide),d>u||d==u&&a.startSide>0&&a.endSide<=0)continue;(u-d||a.endSide-a.startSide)<0||(o<0&&(o=d),a.point&&(l=Math.max(l,u-d)),i.push(a),s.push(d-o),r.push(u-o))}return{mapped:i.length?new ie(s,r,i,l):null,pos:o}}},O=class{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new O(t,e,i,s)}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:s=0,filterTo:r=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(Ie)),this.isEmpty)return e.length?O.of(e):this;let l=new He(this,null,-1).goto(0),h=0,a=[],c=new Ct;for(;l.value||h<e.length;)if(h<e.length&&(l.from-e[h].from||l.startSide-e[h].value.startSide)>=0){let f=e[h++];c.addInner(f.from,f.to,f.value)||a.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==e.length||this.chunkEnd(l.chunkIndex)<e[h].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||a.push(kt.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!a.length?O.empty:this.nextLayer.update({add:a,filter:o,filterFrom:s,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],a=t.touchesRange(l,l+h.length);if(a===!1)s=Math.max(s,h.maxPoint),e.push(h),i.push(t.mapPos(l));else if(a===!0){let{mapped:c,pos:f}=h.map(l,t);c&&(s=Math.max(s,c.maxPoint),e.push(c),i.push(f))}}let r=this.nextLayer.map(t);return e.length==0?r:new O(i,e,r||O.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(e>=r&&t<=r+o.length&&o.between(r,t-r,e-r,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return At.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return At.from(t).goto(e)}static compare(t,e,i,s,r=-1){let o=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),h=es(o,l,i),a=new Mt(o,h,r),c=new Mt(l,h,r);i.iterGaps((f,d,u)=>is(a,f,c,d,u,s)),i.empty&&i.length==0&&is(a,0,c,0,0,s)}static eq(t,e,i=0,s){s==null&&(s=1e9);let r=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0),o=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=es(r,o),h=new Mt(r,l,0).goto(i),a=new Mt(o,l,0).goto(i);for(;;){if(h.to!=a.to||!We(h.active,a.active)||h.point&&(!a.point||!h.point.eq(a.point)))return!1;if(h.to>s)return!0;h.next(),a.next()}}static spans(t,e,i,s,r=-1){let o=new Mt(t,null,r).goto(e),l=e,h=o.openStart;for(;;){let a=Math.min(o.to,i);if(o.point?(s.point(l,a,o.point,o.activeForPoint(o.to),h,o.pointRank),h=o.openEnd(a)+(o.to>a?1:0)):a>l&&(s.span(l,a,o.active,h),h=o.openEnd(a)),o.to>i)break;l=o.to,o.next()}return h}static of(t,e=!1){let i=new Ct;for(let s of t instanceof kt?[t]:e?lr(t):t)i.add(s.from,s.to,s.value);return i.finish()}};O.empty=new O([],[],null,-1);function lr(n){if(n.length>1)for(let t=n[0],e=1;e<n.length;e++){let i=n[e];if(Ie(t,i)>0)return n.slice().sort(Ie);t=i}return n}O.empty.nextLayer=O.empty;var Ct=class{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}finishChunk(t){this.chunks.push(new ie(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=[])}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Ct)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&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(O.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=O.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}};function es(n,t,e){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of t)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(e?e.mapPos(l):l)==r.chunkPos[o]&&!(e==null?void 0:e.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}var He=class{constructor(t,e,i,s=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<t||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}},At=class{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let r=0;r<t.length;r++)for(let o=t[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new He(o,e,i,r));return s.length==1?s[0]:new At(s)}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 i=this.heap.length>>1;i>=0;i--)Fe(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)Fe(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)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(),Fe(this.heap,0)}}};function Fe(n,t){for(let e=n[t];;){let i=(t<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),e.compare(s)<0)break;n[i]=e,n[t]=s,t=i}}var Mt=class{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=At.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){se(this.active,t),se(this.activeTo,t),se(this.activeRank,t),this.minActive=ss(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e<this.activeRank.length&&this.activeRank[e]<=r;)e++;ne(this.active,e,i),ne(this.activeTo,e,s),ne(this.activeRank,e,r),t&&ne(t,e,this.cursor.from),this.minActive=ss(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null,s=0;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>t){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&se(i,r)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let o=this.cursor.value;if(!o.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=o,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=o.endSide,this.cursor.from<t&&(s=1),this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){let r=0;for(;r<i.length&&i[r]<t;)r++;this.openStart=r+s}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[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 is(n,t,e,i,s,r){n.goto(t),e.goto(i);let o=i+s,l=i,h=i-t;for(;;){let a=n.to+h-e.to||n.endSide-e.endSide,c=a<0?n.to+h:e.to,f=Math.min(c,o);if(n.point||e.point?n.point&&e.point&&(n.point==e.point||n.point.eq(e.point))&&We(n.activeForPoint(n.to+h),e.activeForPoint(e.to))||r.comparePoint(l,f,n.point,e.point):f>l&&!We(n.active,e.active)&&r.compareRange(l,f,n.active,e.active),c>o)break;l=c,a<=0&&n.next(),a>=0&&e.next()}}function We(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!=t[e]&&!n[e].eq(t[e]))return!1;return!0}function se(n,t){for(let e=t,i=n.length-1;e<i;e++)n[e]=n[e+1];n.pop()}function ne(n,t,e){for(let i=n.length-1;i>=t;i--)n[i+1]=n[i];n[t]=e}function ss(n,t){let e=-1,i=1e9;for(let s=0;s<t.length;s++)(t[s]-i||n[s].endSide-n[e].endSide)<0&&(e=s,i=t[s]);return e}function ns(n,t,e,i){for(let s=0,r=0;;){if(r>=t)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?e-r%e:1,s=Q(n,s)}return i===!0?-1:n.length}var ze="\u037C",rs=typeof Symbol=="undefined"?"__"+ze:Symbol.for(ze),qe=typeof Symbol=="undefined"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),os=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:{},lt=class{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,a){let c=[],f=/^@(\w+)\b/.exec(o[0]),d=f&&f[1]=="keyframes";if(f&&l==null)return h.push(o[0]+";");for(let u in l){let p=l[u];if(/&/.test(u))r(u.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+u+") should be a primitive value.");r(s(u),p,c,d)}else p!=null&&c.push(u.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||d)&&h.push((i&&!f&&!a?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in t)r(s(o),t[o],this.rules)}getRules(){return this.rules.join(`
|
|
`)}static newName(){let t=os[rs]||1;return os[rs]=t+1,ze+t.toString(36)}static mount(t,e){(t[qe]||new ls(t)).mount(Array.isArray(e)?e:[e])}},re=null,ls=class{constructor(t){if(!t.head&&t.adoptedStyleSheets&&typeof CSSStyleSheet!="undefined"){if(re)return t.adoptedStyleSheets=[re.sheet].concat(t.adoptedStyleSheets),t[qe]=re;this.sheet=new CSSStyleSheet,t.adoptedStyleSheets=[this.sheet].concat(t.adoptedStyleSheets),re=this}else{this.styleTag=(t.ownerDocument||t).createElement("style");let e=t.head||t;e.insertBefore(this.styleTag,e.firstChild)}this.modules=[],t[qe]=this}mount(t){let e=this.sheet,i=0,s=0;for(let r=0;r<t.length;r++){let o=t[r],l=this.modules.indexOf(o);if(l<s&&l>-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),e)for(let h=0;h<o.rules.length;h++)e.insertRule(o.rules[h],i++)}else{for(;s<l;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(!e){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
|
|
`;this.styleTag.textContent=r}}};var ut={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",229:"q"},oe={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},hs=typeof navigator!="undefined"&&/Chrome\/(\d+)/.exec(navigator.userAgent),go=typeof navigator!="undefined"&&/Apple Computer/.test(navigator.vendor),hr=typeof navigator!="undefined"&&/Gecko\/\d+/.test(navigator.userAgent),as=typeof navigator!="undefined"&&/Mac/.test(navigator.platform),mo=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),yo=hs&&(as||+hs[1]<57)||hr&&as;for(R=0;R<10;R++)ut[48+R]=ut[96+R]=String(R);var R;for(R=1;R<=24;R++)ut[R+111]="F"+R;var R;for(R=65;R<=90;R++)ut[R]=String.fromCharCode(R+32),oe[R]=String.fromCharCode(R);var R;for(le in ut)oe.hasOwnProperty(le)||(oe[le]=ut[le]);var le;function he(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function Dt(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function ar(){let n=document.activeElement;for(;n&&n.shadowRoot;)n=n.shadowRoot.activeElement;return n}function Ke(n,t){if(!t.anchorNode)return!1;try{return Dt(n,t.anchorNode)}catch(e){return!1}}function Ht(n){return n.nodeType==3?Tt(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function ae(n,t,e,i){return e?cs(n,t,e,i,-1)||cs(n,t,e,i,1):!1}function $e(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function cs(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:ce(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=$e(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?ce(n):0}else return!1}}function ce(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}var fs={left:0,right:0,top:0,bottom:0};function fe(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function cr(n){return{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function fr(n,t,e,i,s,r,o,l){let h=n.ownerDocument,a=h.defaultView;for(let c=n;c;)if(c.nodeType==1){let f,d=c==h.body;if(d)f=cr(a);else{if(c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.parentNode;continue}let g=c.getBoundingClientRect();f={left:g.left,right:g.left+c.clientWidth,top:g.top,bottom:g.top+c.clientHeight}}let u=0,p=0;if(s=="nearest")t.top<f.top?(p=-(f.top-t.top+o),e>0&&t.bottom>f.bottom+p&&(p=t.bottom-f.bottom+p+o)):t.bottom>f.bottom&&(p=t.bottom-f.bottom+o,e<0&&t.top-p<f.top&&(p=-(f.top+p-t.top+o)));else{let g=t.bottom-t.top,m=f.bottom-f.top;p=(s=="center"&&g<=m?t.top+g/2-m/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-m+o)-f.top}if(i=="nearest"?t.left<f.left?(u=-(f.left-t.left+r),e>0&&t.right>f.right+u&&(u=t.right-f.right+u+r)):t.right>f.right&&(u=t.right-f.right+r,e<0&&t.left<f.left+u&&(u=-(f.left+u-t.left+r))):u=(i=="center"?t.left+(t.right-t.left)/2-(f.right-f.left)/2:i=="start"==l?t.left-r:t.right-(f.right-f.left)+r)-f.left,u||p)if(d)a.scrollBy(u,p);else{if(p){let g=c.scrollTop;c.scrollTop+=p,p=c.scrollTop-g}if(u){let g=c.scrollLeft;c.scrollLeft+=u,u=c.scrollLeft-g}t={left:t.left-u,top:t.top-p,right:t.right-u,bottom:t.bottom-p}}if(d)break;c=c.assignedSlot||c.parentNode,i=s="nearest"}else if(c.nodeType==11)c=c.host;else break}var us=class{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){this.set(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset)}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}},Ot=null;function ds(n){if(n.setActive)return n.setActive();if(Ot)return n.focus(Ot);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(Ot==null?{get preventScroll(){return Ot={preventScroll:!0},!0}}:void 0),!Ot){Ot=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],r=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}var ps;function Tt(n,t,e=t){let i=ps||(ps=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function Ft(n,t,e){let i={key:t,code:t,keyCode:e,which:e,cancelable:!0},s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let r=new KeyboardEvent("keyup",i);return r.synthetic=!0,n.dispatchEvent(r),s.defaultPrevented||r.defaultPrevented}function ur(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function gs(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}var V=class{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new V(t.parentNode,$e(t),e)}static after(t,e){return new V(t.parentNode,$e(t)+1,e)}},je=[],k=class{constructor(){this.parent=null,this.dom=null,this.dirty=2}get editorView(){if(!this.parent)throw new Error("Accessing view in orphan content view");return this.parent.editorView}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}coordsAt(t,e){return null}sync(t){if(this.dirty&2){let e=this.dom,i=null,s;for(let r of this.children){if(r.dirty){if(!r.dom&&(s=i?i.nextSibling:e.firstChild)){let o=k.get(s);(!o||!o.parent&&o.constructor==r.constructor)&&r.reuseDOM(s)}r.sync(t),r.dirty=0}if(s=i?i.nextSibling:e.firstChild,t&&!t.written&&t.node==e&&s!=r.dom&&(t.written=!0),r.dom.parentNode==e)for(;s&&s!=r.dom;)s=ms(s);else e.insertBefore(r.dom,s);i=r.dom}for(s=i?i.nextSibling:e.firstChild,s&&t&&t.node==e&&(t.written=!0);s;)s=ms(s)}else if(this.dirty&1)for(let e of this.children)e.dirty&&(e.sync(t),e.dirty=0)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=ce(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?s=-1:s=1),t=r}s<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!k.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,o=-1,l=-1;for(let h=0,a=i,c=i;h<this.children.length;h++){let f=this.children[h],d=a+f.length;if(a<t&&d>e)return f.domBoundsAround(t,e,a);if(d>=t&&s==-1&&(s=h,r=a),a>e&&f.dom.parentNode==this.dom){o=h,l=c;break}c=d,a=d+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(t=!1){this.dirty|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.dirty|=2),e.dirty&1)return;e.dirty|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.dirty&&this.markParentsDirty(!0))}setDOM(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=je){this.markDirty();for(let s=t;s<e;s++){let r=this.children[s];r.parent==this&&r.destroy()}this.children.splice(t,e-t,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Ge(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}merge(t,e,i,s,r,o){return!1}become(t){return!1}getSide(){return 0}destroy(){this.parent=null}};k.prototype.breakAfter=0;function ms(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}var Ge=class{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||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 ys(n,t,e,i,s,r,o,l,h){let{children:a}=n,c=a.length?a[t]:null,f=r.length?r[r.length-1]:null,d=f?f.breakAfter:o;if(!(t==i&&c&&!o&&!d&&r.length<2&&c.merge(e,s,r.length?f:null,e==0,l,h))){if(i<a.length){let u=a[i];u&&s<u.length?(t==i&&(u=u.split(s),s=0),!d&&f&&u.merge(0,s,f,!0,0,h)?r[r.length-1]=u:(s&&u.merge(0,s,null,!1,0,h),r.push(u))):(u==null?void 0:u.breakAfter)&&(f?f.breakAfter=1:o=1),i++}for(c&&(c.breakAfter=o,e>0&&(!o&&r.length&&c.merge(e,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(e<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(e,c.length,null,!1,l,0),t++));t<i&&r.length;)if(a[i-1].become(r[r.length-1]))i--,r.pop(),h=r.length?0:l;else if(a[t].become(r[0]))t++,r.shift(),l=r.length?0:h;else break;!r.length&&t&&i<a.length&&!a[t-1].breakAfter&&a[i].merge(0,0,a[t-1],!1,l,h)&&t--,(t<i||r.length)&&n.replaceChildren(t,i,r)}}function ws(n,t,e,i,s,r){let o=n.childCursor(),{i:l,off:h}=o.findPos(e,1),{i:a,off:c}=o.findPos(t,-1),f=t-e;for(let d of i)f+=d.length;n.length+=f,ys(n,a,c,l,h,i,0,s,r)}var j=typeof navigator!="undefined"?navigator:{userAgent:"",vendor:"",platform:""},Ue=typeof document!="undefined"?document:{documentElement:{style:{}}},Je=/Edge\/(\d+)/.exec(j.userAgent),bs=/MSIE \d/.test(j.userAgent),Xe=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(j.userAgent),ue=!!(bs||Xe||Je),vs=!ue&&/gecko\/(\d+)/i.test(j.userAgent),Ye=!ue&&/Chrome\/(\d+)/.exec(j.userAgent),xs="webkitFontSmoothing"in Ue.documentElement.style,Ss=!ue&&/Apple Computer/.test(j.vendor),ks=Ss&&(/Mobile\/\w+/.test(j.userAgent)||j.maxTouchPoints>2),y={mac:ks||/Mac/.test(j.platform),windows:/Win/.test(j.platform),linux:/Linux|X11/.test(j.platform),ie:ue,ie_version:bs?Ue.documentMode||6:Xe?+Xe[1]:Je?+Je[1]:0,gecko:vs,gecko_version:vs?+(/Firefox\/(\d+)/.exec(j.userAgent)||[0,0])[1]:0,chrome:!!Ye,chrome_version:Ye?+Ye[1]:0,ios:ks,android:/Android\b/.test(j.userAgent),webkit:xs,safari:Ss,webkit_version:xs?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:Ue.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"},dr=256,_=class extends k{constructor(t){super();this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return i&&(!(i instanceof _)||this.length-(e-t)+i.length>dr)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new _(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new V(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 Ze(this.dom,t,e)}},U=class extends k{constructor(t,e=[],i=0){super();this.mark=t,this.children=e,this.length=i;for(let s of e)s.setParent(this)}setAttrs(t){if(gs(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}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.dirty|=4|2)}sync(t){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t)}merge(t,e,i,s,r,o){return i&&(!(i instanceof U&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(ws(this,t,e,i?i.children:[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let l of this.children){let h=i+l.length;h>t&&e.push(i<t?l.split(t-i):l),s<0&&i>=t&&(s=r),i=h,r++}let o=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new U(this.mark,e,o)}domAtPos(t){return As(this.dom,this.children,t)}coordsAt(t,e){return Ds(this,t,e)}};function Ze(n,t,e){let i=n.nodeValue.length;t>i&&(t=i);let s=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?y.chrome||y.gecko||(t?(s--,o=1):r<i&&(r++,o=-1)):e<0?s--:r<i&&r++;let l=Tt(n,s,r).getClientRects();if(!l.length)return fs;let h=l[(o?o<0:e>=0)?0:l.length-1];return y.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?fe(h,o<0):h||null}var tt=class extends k{constructor(t,e,i){super();this.widget=t,this.length=e,this.side=i,this.prevWidget=null}static create(t,e,i){return new(t.customView||tt)(t,e,i)}split(t){let e=tt.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(t,e,i,s,r,o){return i&&(!(i instanceof tt)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t.length==this.length&&t instanceof tt&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.eq(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return x.empty;let t=this;for(;t.parent;)t=t.parent;let e=t.editorView,i=e&&e.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):x.empty}domAtPos(t){return t==0?V.before(this.dom):V.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.dom.getClientRects(),s=null;if(!i.length)return fs;for(let r=t>0?i.length-1:0;s=i[r],!(t>0?r==0:r==i.length-1||s.top<s.bottom);r+=t>0?-1:1);return t==0&&e>0||t==this.length&&e<=0?s:fe(s,t==0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},Qe=class extends tt{domAtPos(t){let{topView:e,text:i}=this.widget;return e?_e(t,0,e,i,(s,r)=>s.domAtPos(r),s=>new V(i,Math.min(s,i.nodeValue.length))):new V(i,Math.min(t,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(t,e){let{topView:i,text:s}=this.widget;return i?Cs(t,e,i,s):Math.min(e,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(t,e){let{topView:i,text:s}=this.widget;return i?_e(t,e,i,s,(r,o,l)=>r.coordsAt(o,l),(r,o)=>Ze(s,r,o)):Ze(s,t,e)}destroy(){var t;super.destroy(),(t=this.widget.topView)===null||t===void 0||t.destroy()}get isEditable(){return!0}};function _e(n,t,e,i,s,r){if(e instanceof U){for(let o of e.children){let l=Dt(o.dom,i),h=l?i.nodeValue.length:o.length;if(n<h||n==h&&o.getSide()<=0)return l?_e(n,t,o,i,s,r):s(o,n,t);n-=h}return s(e,e.length,-1)}else return e.dom==i?r(n,t):s(e,n,t)}function Cs(n,t,e,i){if(e instanceof U)for(let s of e.children){let r=0,o=Dt(s.dom,i);if(Dt(s.dom,n))return r+(o?Cs(n,t,s,i):s.localPosFromDOM(n,t));r+=o?i.nodeValue.length:s.length}else if(e.dom==i)return Math.min(t,i.nodeValue.length);return e.localPosFromDOM(n,t)}var dt=class extends k{constructor(t){super();this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof dt&&t.side==this.side}split(){return new dt(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return V.before(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){let e=this.dom.getBoundingClientRect(),i=pr(this,this.side>0?-1:1);return i&&i.top<e.bottom&&i.bottom>e.top?{left:e.left,right:e.right,top:i.top,bottom:i.bottom}:e}get overrideDOMText(){return x.empty}};_.prototype.children=tt.prototype.children=dt.prototype.children=je;function pr(n,t){let e=n.parent,i=e?e.children.indexOf(n):-1;for(;e&&i>=0;)if(t<0?i>0:i<e.children.length){let s=e.children[i+t];if(s instanceof _){let r=s.coordsAt(t<0?s.length:0,t);if(r)return r}i+=t}else if(e instanceof U&&e.parent)i=e.parent.children.indexOf(e)+(t<0?0:1),e=e.parent;else{let s=e.dom.lastChild;if(s&&s.nodeName=="BR")return s.getClientRects()[0];break}}function As(n,t,e){let i=0;for(let s=0;i<t.length;i++){let r=t[i],o=s+r.length;if(!(o==s&&r.getSide()<=0)){if(e>s&&e<o&&r.dom.parentNode==n)return r.domAtPos(e-s);if(e<=s)break;s=o}}for(;i>0;i--){let s=t[i-1].dom;if(s.parentNode==n)return V.after(s)}return new V(n,0)}function Ms(n,t,e){let i,{children:s}=n;e>0&&t instanceof U&&s.length&&(i=s[s.length-1])instanceof U&&i.mark.eq(t.mark)?Ms(i,t.children[0],e-1):(s.push(t),t.setParent(n)),n.length+=t.length}function Ds(n,t,e){for(let r=0,o=0;o<n.children.length;o++){let l=n.children[o],h=r+l.length,a;if((e<=0||h==n.length||l.getSide()>0?h>=t:h>t)&&(t<h||o+1==n.children.length||(a=n.children[o+1]).length||a.getSide()>0)){let c=0;if(h==r){if(l.getSide()<=0)continue;c=e=-l.getSide()}let f=l.coordsAt(Math.max(0,t-r),e);return c&&f?fe(f,e<0):f}r=h}let i=n.dom.lastChild;if(!i)return n.dom.getBoundingClientRect();let s=Ht(i);return s[s.length-1]||null}function ti(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}function ei(n,t){if(n==t)return!0;if(!n||!t)return!1;let e=Object.keys(n),i=Object.keys(t);if(e.length!=i.length)return!1;for(let s of e)if(i.indexOf(s)==-1||n[s]!==t[s])return!1;return!0}function ii(n,t,e){let i=null;if(t)for(let s in t)e&&s in e||n.removeAttribute(i=s);if(e)for(let s in e)t&&t[s]==e[s]||n.setAttribute(i=s,e[s]);return!!i}var Wt=class{eq(t){return!1}updateDOM(t){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}ignoreEvent(t){return!0}get customView(){return null}destroy(t){}},L=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(L||(L={})),N=class extends ot{constructor(t,e,i,s){super();this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new zt(t)}static widget(t){let e=t.side||0,i=!!t.block;return e+=i?e>0?3e8:-4e8:e>0?1e8:-1e8,new ht(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Os(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new ht(t,i,s,e,t.widget||null,!0)}static line(t){return new Rt(t)}static set(t,e=!1){return O.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};N.none=O.empty;var zt=class extends N{constructor(t){let{start:e,end:i}=Os(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){return this==t||t instanceof zt&&this.tagName==t.tagName&&this.class==t.class&&ei(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}};zt.prototype.point=!1;var Rt=class extends N{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Rt&&ei(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)}};Rt.prototype.mapMode=K.TrackBefore;Rt.prototype.point=!0;var ht=class extends N{constructor(t,e,i,s,r,o){super(e,i,r,t);this.block=s,this.isReplace=o,this.mapMode=s?e<=0?K.TrackBefore:K.TrackAfter:K.TrackDel}get type(){return this.startSide<this.endSide?L.WidgetRange:this.startSide<=0?L.WidgetBefore:L.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&this.widget.estimatedHeight>=5}eq(t){return t instanceof ht&&gr(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}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)}};ht.prototype.point=!0;function Os(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function gr(n,t){return n==t||!!(n&&t&&n.compare(t))}function si(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}var W=class extends k{constructor(){super(...arguments);this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,o){if(i){if(!(i instanceof W))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),ws(this,t,e,i?i.children:[],r,o),!0}split(t){let e=new W;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)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=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){ei(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Ms(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=ti(e,this.attrs||{})),i&&(this.attrs=ti({class:i},this.attrs||{}))}domAtPos(t){return As(this.dom,this.children,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.dirty|=4|2)}sync(t){var e;this.dom?this.dirty&4&&(gs(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(ii(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t);let i=this.dom.lastChild;for(;i&&k.get(i)instanceof U;)i=i.lastChild;if(!i||!this.length||i.nodeName!="BR"&&((e=k.get(i))===null||e===void 0?void 0:e.isEditable)==!1&&(!y.ios||!this.children.some(s=>s instanceof _))){let s=document.createElement("BR");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0;for(let e of this.children){if(!(e instanceof _))return null;let i=Ht(e.dom);if(i.length!=1)return null;t+=i[0].width}return{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length}}coordsAt(t,e){return Ds(this,t,e)}become(t){return!1}get type(){return L.Text}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],o=s+r.length;if(o>=e){if(r instanceof W)return r;if(o>e)break}s=o+r.breakAfter}return null}},at=class extends k{constructor(t,e,i){super();this.widget=t,this.length=e,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,o){return i&&(!(i instanceof at)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?V.before(this.dom):V.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new at(this.widget,e,this.type);return i.breakAfter=this.breakAfter,i}get children(){return je}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):x.empty}domBoundsAround(){return null}become(t){return t instanceof at&&t.type==this.type&&t.widget.constructor==this.widget.constructor?(t.widget.eq(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},de=class{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!t.breakAfter&&!(t instanceof at&&t.type==L.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new W),this.atCursorPos=!0),this.curLine}flushBuffer(t){this.pendingBuffer&&(this.curLine.append(pe(new dt(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer([]),this.curLine=null,this.content.push(t)}finish(t){t?this.pendingBuffer=0:this.flushBuffer([]),this.posCovered()||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,t--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(0,i)),this.getLine().append(pe(new _(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ht){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 l=e-t;if(i instanceof ht)if(i.block){let{type:h}=i;h==L.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new at(i.widget||new ni("div"),l,h))}else{let h=tt.create(i.widget||new ni("span"),l,i.startSide),a=this.atCursorPos&&!h.isEditable&&r<=s.length&&(t<e||i.startSide>0),c=!h.isEditable&&(t<e||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!a&&(this.pendingBuffer=0),this.flushBuffer(s),a&&(f.append(pe(new dt(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(pe(h,s),r),this.atCursorPos=c,this.pendingBuffer=c?t<e?1:2:0}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let o=new de(t,e,i,r);return o.openEnd=O.spans(s,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function pe(n,t){for(let e of t)n=new U(e,[n],n.length);return n}var ni=class extends Wt{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}},Ts=v.define(),Rs=v.define(),Es=v.define(),Ls=v.define(),ri=v.define(),Bs=v.define(),Ps=v.define({combine:n=>n.some(t=>t)}),qt=class{constructor(t,e="nearest",i="nearest",s=5,r=5){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r}map(t){return t.empty?this:new qt(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin)}},Vs=E.define({map:(n,t)=>n.map(t)});function pt(n,t,e){let i=n.facet(Ls);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}var ge=v.define({combine:n=>n.length?n[0]:!0}),mr=0,Kt=v.define(),$t=class{constructor(t,e,i,s){this.id=t,this.create=e,this.domEventHandlers=i,this.extension=s(this)}static define(t,e){let{eventHandlers:i,provide:s,decorations:r}=e||{};return new $t(mr++,t,i,o=>{let l=[Kt.of(o)];return r&&l.push(jt.of(h=>{let a=h.plugin(o);return a?r(a):N.none})),s&&l.push(s(o)),l})}static fromClass(t,e){return $t.define(i=>new t(i),e)}},me=class{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(pt(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(s){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){pt(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if((e=this.value)===null||e===void 0?void 0:e.destroy)try{this.value.destroy()}catch(i){pt(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},Ns=v.define(),Is=v.define(),jt=v.define(),Hs=v.define(),Fs=v.define(),Gt=v.define(),Y=class{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new Y(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 s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let h=s==t.length?null:t[s],a=o-l,c=h?h.fromB:1e9;for(;r<e.length&&e[r]<c;){let f=e[r],d=e[r+1],u=Math.max(l,f),p=Math.min(c,d);if(u<=p&&new Y(u+a,p+a,u,p).addToSet(i),d>c)break;r+=2}if(!h)return i;new Y(h.fromA,h.toA,h.fromB,h.toB).addToSet(i),o=h.toA,l=h.toB}}},Ut=class{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=T.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,l,h,a)=>s.push(new Y(o,l,h,a))),this.changedRanges=s;let r=t.hasFocus;r!=t.inputState.notifiedFocused&&(t.inputState.notifiedFocused=r,this.flags|=1)}static create(t,e,i){return new Ut(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&(8|2))>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},z=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(z||(z={})),oi=z.LTR,yr=z.RTL;function Ws(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}var wr=Ws("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),br=Ws("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),li=Object.create(null),Z=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);li[t]=e,li[e]=-t}function vr(n){return n<=247?wr[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?br[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8203||n==8204?256:1}var xr=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,gt=class{constructor(t,e,i){this.from=t,this.to=e,this.level=i}get dir(){return this.level%2?yr:oi}side(t,e){return this.dir==e==t?this.to:this.from}static find(t,e,i,s){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}},M=[];function Sr(n,t){let e=n.length,i=t==oi?1:2,s=t==oi?2:1;if(!n||i==1&&!xr.test(n))return zs(e);for(let o=0,l=i,h=i;o<e;o++){let a=vr(n.charCodeAt(o));a==512?a=l:a==8&&h==4&&(a=16),M[o]=a==4?2:a,a&7&&(h=a),l=a}for(let o=0,l=i,h=i;o<e;o++){let a=M[o];if(a==128)o<e-1&&l==M[o+1]&&l&24?a=M[o]=l:M[o]=256;else if(a==64){let c=o+1;for(;c<e&&M[c]==64;)c++;let f=o&&l==8||c<e&&M[c]==8?h==1?1:8:256;for(let d=o;d<c;d++)M[d]=f;o=c-1}else a==8&&h==1&&(M[o]=1);l=a,a&7&&(h=a)}for(let o=0,l=0,h=0,a,c,f;o<e;o++)if(c=li[a=n.charCodeAt(o)])if(c<0){for(let d=l-3;d>=0;d-=3)if(Z[d+1]==-c){let u=Z[d+2],p=u&2?i:u&4?u&1?s:i:0;p&&(M[o]=M[Z[d]]=p),l=d;break}}else{if(Z.length==189)break;Z[l++]=o,Z[l++]=a,Z[l++]=h}else if((f=M[o])==2||f==1){let d=f==i;h=d?0:1;for(let u=l-3;u>=0;u-=3){let p=Z[u+2];if(p&2)break;if(d)Z[u+2]|=2;else{if(p&4)break;Z[u+2]|=4}}}for(let o=0;o<e;o++)if(M[o]==256){let l=o+1;for(;l<e&&M[l]==256;)l++;let h=(o?M[o-1]:i)==1,a=(l<e?M[l]:i)==1,c=h==a?h?1:2:i;for(let f=o;f<l;f++)M[f]=c;o=l-1}let r=[];if(i==1)for(let o=0;o<e;){let l=o,h=M[o++]!=1;for(;o<e&&h==(M[o]!=1);)o++;if(h)for(let a=o;a>l;){let c=a,f=M[--a]!=2;for(;a>l&&f==(M[a-1]!=2);)a--;r.push(new gt(a,c,f?2:1))}else r.push(new gt(l,o,0))}else for(let o=0;o<e;){let l=o,h=M[o++]==2;for(;o<e&&h==(M[o]==2);)o++;r.push(new gt(l,o,h?1:2))}return r}function zs(n){return[new gt(0,n,0)]}var qs="";function kr(n,t,e,i,s){var r;let o=i.head-n.from,l=-1;if(o==0){if(!s||!n.length)return null;t[0].level!=e&&(o=t[0].side(!1,e),l=0)}else if(o==n.length){if(s)return null;let d=t[t.length-1];d.level!=e&&(o=d.side(!0,e),l=t.length-1)}l<0&&(l=gt.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let h=t[l];o==h.side(s,e)&&(h=t[l+=s?1:-1],o=h.side(!s,e));let a=s==(h.dir==e),c=Q(n.text,o,a);if(qs=n.text.slice(Math.min(o,c),Math.max(o,c)),c!=h.side(s,e))return w.cursor(c+n.from,a?-1:1,h.level);let f=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return!f&&h.level!=e?w.cursor(s?n.to:n.from,s?-1:1,e):f&&f.level<h.level?w.cursor(f.side(!s,e)+n.from,s?1:-1,f.level):w.cursor(c+n.from,s?-1:1,h.level)}var ct="\uFFFF",hi=class{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(S.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=ct}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s),this.readNode(s);let r=s.nextSibling;if(r==e)break;let o=k.get(s),l=k.get(r);(o&&l?o.breakAfter:(o?o.breakAfter:Ks(s))||Ks(r)&&(s.nodeName!="BR"||s.cmIgnore))&&this.lineBreak(),s=r}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,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==t&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=k.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&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)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+Math.min(e,i.offset))}};function Ks(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}var ai=class{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}},ci=class extends k{constructor(t){super();this.view=t,this.compositionDeco=N.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new W],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Y(0,0,0,t.state.doc.length)],0)}get root(){return this.view.root}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(t){let e=t.changedRanges;this.minWidth>0&&e.length&&(e.every(({fromA:o,toA:l})=>l<this.minWidthFrom||o>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=N.none:(t.transactions.length||this.dirty)&&(this.compositionDeco=Ar(this.view,t.changes)),(y.ie||y.chrome)&&!this.compositionDeco.size&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,s=this.updateDeco(),r=Dr(i,s,t.changes);return e=Y.extendWithRanges(e,r),this.dirty==0&&e.length==0?!1:(this.updateInner(e,t.startState.doc.length),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e);let{observer:i}=this.view;i.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=y.chrome||y.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(r),this.dirty=0,r&&(r.written||i.selectionRange.focusNode!=r.node)&&(this.forceSelection=!0),this.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.children)r instanceof at&&r.widget instanceof fi&&s.push(r.dom);i.updateGaps(s)}updateChildren(t,e){let i=this.childCursor(e);for(let s=t.length-1;;s--){let r=s>=0?t[s]:null;if(!r)break;let{fromA:o,toA:l,fromB:h,toB:a}=r,{content:c,breakAtStart:f,openStart:d,openEnd:u}=de.build(this.view.state.doc,h,a,this.decorations,this.dynamicDecorationMap),{i:p,off:g}=i.findPos(l,1),{i:m,off:b}=i.findPos(o,-1);ys(this,m,b,p,g,c,f,d,u)}}updateSelection(t=!1,e=!1){if((t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange(),!(e||this.mayControlSelection())||y.ios&&this.view.inputState.rapidCompositionStart)return;let i=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),o=s.empty?r:this.domAtPos(s.head);if(y.gecko&&s.empty&&Cr(r)){let h=document.createTextNode("");this.view.observer.ignore(()=>r.node.insertBefore(h,r.node.childNodes[r.offset]||null)),r=o=new V(h,0),i=!0}let l=this.view.observer.selectionRange;(i||!l.focusNode||!ae(r.node,r.offset,l.anchorNode,l.anchorOffset)||!ae(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{y.android&&y.chrome&&this.dom.contains(l.focusNode)&&Or(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let h=he(this.root);if(h)if(s.empty){if(y.gecko){let a=Mr(r.node,r.offset);if(a&&a!=(1|2)){let c=Gs(r.node,r.offset,a==1?1:-1);c&&(r=new V(c,a==1?0:c.nodeValue.length))}}h.collapse(r.node,r.offset),s.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=s.bidiLevel)}else if(h.extend)h.collapse(r.node,r.offset),h.extend(o.node,o.offset);else{let a=document.createRange();s.anchor>s.head&&([r,o]=[o,r]),a.setEnd(o.node,o.offset),a.setStart(r.node,r.offset),h.removeAllRanges(),h.addRange(a)}}),this.view.observer.setSelectionRange(r,o)),this.impreciseAnchor=r.precise?null:new V(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new V(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let t=this.view.state.selection.main,e=he(this.root);if(!e||!t.empty||!t.assoc||!e.modify)return;let i=W.find(this,t.head);if(!i)return;let s=i.posAtStart;if(t.head==s||t.head==s+i.length)return;let r=this.coordsAt(t.head,-1),o=this.coordsAt(t.head,1);if(!r||!o||r.bottom>o.top)return;let l=this.domAtPos(t.head+t.assoc);e.collapse(l.node,l.offset),e.modify("move",t.assoc<0?"forward":"backward","lineboundary")}mayControlSelection(){let t=this.root.activeElement;return t==this.dom||Ke(this.dom,this.view.observer.selectionRange)&&!(t&&this.dom.contains(t))}nearest(t){for(let e=t;e;){let i=k.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let s=this.children[e];if(i<s.length||s instanceof W)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){for(let i=this.length,s=this.children.length-1;;s--){let r=this.children[s],o=i-r.breakAfter-r.length;if(t>o||t==o&&r.type!=L.WidgetBefore&&r.type!=L.WidgetAfter&&(!s||e==2||this.children[s-1].breakAfter||this.children[s-1].type==L.WidgetBefore&&e>-2))return r.coordsAt(t-o,e);i=o}}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==z.LTR;for(let a=0,c=0;c<this.children.length;c++){let f=this.children[c],d=a+f.length;if(d>s)break;if(a>=i){let u=f.dom.getBoundingClientRect();if(e.push(u.height),o){let p=f.dom.lastChild,g=p?Ht(p):[];if(g.length){let m=g[g.length-1],b=h?m.right-u.left:u.right-m.left;b>l&&(l=b,this.minWidth=r,this.minWidthFrom=a,this.minWidthTo=d)}}}a=d+f.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?z.RTL:z.LTR}measureTextSize(){for(let s of this.children)if(s instanceof W){let r=s.measureTextSize();if(r)return r}let t=document.createElement("div"),e,i;return t.className="cm-line",t.style.width="99999px",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let s=Ht(t.firstChild)[0];e=t.getBoundingClientRect().height,i=s?s.width/27:7,t.remove()}),{lineHeight:e,charWidth:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Ge(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=e.lineBlockAt(o).bottom-e.lineBlockAt(i).top;t.push(N.replace({widget:new fi(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return N.set(t)}updateDeco(){let t=this.view.state.facet(jt).map((e,i)=>(this.dynamicDecorationMap[i]=typeof e=="function")?e(this.view):e);for(let e=t.length;e<t.length+3;e++)this.dynamicDecorationMap[e]=!1;return this.decorations=[...t,this.compositionDeco,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(t){let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=0,o=0,l=0,h=0;for(let c of this.view.state.facet(Fs).map(f=>f(this.view)))if(c){let{left:f,right:d,top:u,bottom:p}=c;f!=null&&(r=Math.max(r,f)),d!=null&&(o=Math.max(o,d)),u!=null&&(l=Math.max(l,u)),p!=null&&(h=Math.max(h,p))}let a={left:i.left-r,top:i.top-l,right:i.right+o,bottom:i.bottom+h};fr(this.view.scrollDOM,a,e.head<e.anchor?-1:1,t.x,t.y,t.xMargin,t.yMargin,this.view.textDirection==z.LTR)}};function Cr(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}var fi=class extends Wt{constructor(t){super();this.height=t}toDOM(){let t=document.createElement("div");return this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}};function $s(n){let t=n.observer.selectionRange,e=t.focusNode&&Gs(t.focusNode,t.focusOffset,0);if(!e)return null;let i=n.docView.nearest(e);if(!i)return null;if(i instanceof W){let s=e;for(;s.parentNode!=i.dom;)s=s.parentNode;let r=s.previousSibling;for(;r&&!k.get(r);)r=r.previousSibling;let o=r?k.get(r).posAtEnd:i.posAtStart;return{from:o,to:o,node:s,text:e}}else{for(;;){let{parent:r}=i;if(!r)return null;if(r instanceof W)break;i=r}let s=i.posAtStart;return{from:s,to:s+i.length,node:i.dom,text:e}}}function Ar(n,t){let e=$s(n);if(!e)return N.none;let{from:i,to:s,node:r,text:o}=e,l=t.mapPos(i,1),h=Math.max(l,t.mapPos(s,-1)),{state:a}=n,c=r.nodeType==3?r.nodeValue:new hi([],a).readRange(r.firstChild,null).text;if(h-l<c.length)if(a.doc.sliceString(l,Math.min(a.doc.length,l+c.length),ct)==c)h=l+c.length;else if(a.doc.sliceString(Math.max(0,h-c.length),h,ct)==c)l=h-c.length;else return N.none;else if(a.doc.sliceString(l,h,ct)!=c)return N.none;let f=k.get(r);return f instanceof Qe?f=f.widget.topView:f&&(f.parent=null),N.set(N.replace({widget:new js(r,o,f),inclusive:!0}).range(l,h))}var js=class extends Wt{constructor(t,e,i){super();this.top=t,this.text=e,this.topView=i}eq(t){return this.top==t.top&&this.text==t.text}toDOM(){return this.top}ignoreEvent(){return!1}get customView(){return Qe}};function Gs(n,t,e){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&t>0&&e<=0)n=n.childNodes[t-1],t=ce(n);else if(n.nodeType==1&&t<n.childNodes.length&&e>=0)n=n.childNodes[t],t=0;else return null}}function Mr(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}var Us=class{constructor(){this.changes=[]}compareRange(t,e){si(t,e,this.changes)}comparePoint(t,e){si(t,e,this.changes)}};function Dr(n,t,e){let i=new Us;return O.compare(n,t,e,i),i.changes}function Or(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Tr(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return w.cursor(t);r==0?e=1:r==s.length&&(e=-1);let o=r,l=r;e<0?o=Q(s.text,r,!1):l=Q(s.text,r);let h=i(s.text.slice(o,l));for(;o>0;){let a=Q(s.text,o,!1);if(i(s.text.slice(a,o))!=h)break;o=a}for(;l<s.length;){let a=Q(s.text,l);if(i(s.text.slice(l,a))!=h)break;l=a}return w.range(o+s.from,l+s.from)}function Rr(n,t){return t.left>n?t.left-n:Math.max(0,n-t.right)}function Er(n,t){return t.top>n?t.top-n:Math.max(0,n-t.bottom)}function ui(n,t){return n.top<t.bottom-1&&n.bottom>t.top+1}function Js(n,t){return t<n.top?{top:t,left:n.left,right:n.right,bottom:n.bottom}:n}function Xs(n,t){return t>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:t}:n}function di(n,t,e){let i,s,r,o,l,h,a,c;for(let u=n.firstChild;u;u=u.nextSibling){let p=Ht(u);for(let g=0;g<p.length;g++){let m=p[g];s&&ui(s,m)&&(m=Js(Xs(m,s.bottom),s.top));let b=Rr(t,m),B=Er(e,m);if(b==0&&B==0)return u.nodeType==3?Ys(u,t,e):di(u,t,e);(!i||o>B||o==B&&r>b)&&(i=u,s=m,r=b,o=B),b==0?e>m.bottom&&(!a||a.bottom<m.bottom)?(l=u,a=m):e<m.top&&(!c||c.top>m.top)&&(h=u,c=m):a&&ui(a,m)?a=Xs(a,m.bottom):c&&ui(c,m)&&(c=Js(c,m.top))}}if(a&&a.bottom>=e?(i=l,s=a):c&&c.top<=e&&(i=h,s=c),!i)return{node:n,offset:0};let f=Math.max(s.left,Math.min(s.right,t));if(i.nodeType==3)return Ys(i,f,e);if(!r&&i.contentEditable=="true")return di(i,f,e);let d=Array.prototype.indexOf.call(n.childNodes,i)+(t>=(s.left+s.right)/2?1:0);return{node:n,offset:d}}function Ys(n,t,e){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let h=Tt(n,l,l+1).getClientRects();for(let a=0;a<h.length;a++){let c=h[a];if(c.top==c.bottom)continue;o||(o=t-c.left);let f=(c.top>e?c.top-e:e-c.bottom)-1;if(c.left-1<=t&&c.right+1>=t&&f<r){let d=t>=(c.left+c.right)/2,u=d;if((y.chrome||y.gecko)&&Tt(n,l).getBoundingClientRect().left==c.right&&(u=!d),f<=0)return{node:n,offset:l+(u?1:0)};s=l+(u?1:0),r=f}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function Zs(n,{x:t,y:e},i,s=-1){var r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,h,{docHeight:a}=n.viewState,c=e-l;if(c<0)return 0;if(c>a)return n.state.doc.length;for(let b=n.defaultLineHeight/2,B=!1;h=n.elementAtHeight(c),h.type!=L.Text;)for(;c=s>0?h.bottom+b:h.top-b,!(c>=0&&c<=a);){if(B)return i?null:0;B=!0,s=-s}e=l+c;let f=h.from;if(f<n.viewport.from)return n.viewport.from==0?0:i?null:Qs(n,o,h,t,e);if(f>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:i?null:Qs(n,o,h,t,e);let d=n.dom.ownerDocument,u=n.root.elementFromPoint?n.root:d,p=u.elementFromPoint(t,e);p&&!n.contentDOM.contains(p)&&(p=null),p||(t=Math.max(o.left+1,Math.min(o.right-1,t)),p=u.elementFromPoint(t,e),p&&!n.contentDOM.contains(p)&&(p=null));let g,m=-1;if(p&&((r=n.docView.nearest(p))===null||r===void 0?void 0:r.isEditable)!=!1){if(d.caretPositionFromPoint){let b=d.caretPositionFromPoint(t,e);b&&({offsetNode:g,offset:m}=b)}else if(d.caretRangeFromPoint){let b=d.caretRangeFromPoint(t,e);b&&({startContainer:g,startOffset:m}=b,(y.safari&&Lr(g,m,t)||y.chrome&&Br(g,m,t))&&(g=void 0))}}if(!g||!n.docView.dom.contains(g)){let b=W.find(n.docView,f);if(!b)return c>h.top+h.height/2?h.to:h.from;({node:g,offset:m}=di(b.dom,t,e))}return n.docView.posFromDOM(g,m)}function Qs(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);n.lineWrapping&&e.height>n.defaultLineHeight*1.5&&(r+=Math.floor((s-e.top)/n.defaultLineHeight)*n.viewState.heightOracle.lineLength);let o=n.state.sliceDoc(e.from,e.to);return e.from+ns(o,r,n.state.tabSize)}function Lr(n,t,e){let i;if(n.nodeType!=3||t!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return Tt(n,i-1,i).getBoundingClientRect().left>e}function Br(n,t,e){if(t!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():Tt(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Pr(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=!i||!n.lineWrapping?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let h=n.dom.getBoundingClientRect(),a=n.textDirectionAt(s.from),c=n.posAtCoords({x:e==(a==z.LTR)?h.right-1:h.left+1,y:(r.top+r.bottom)/2});if(c!=null)return w.cursor(c,e?-1:1)}let o=W.find(n.docView,t.head),l=o?e?o.posAtEnd:o.posAtStart:e?s.to:s.from;return w.cursor(l,e?-1:1)}function _s(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=t,h=null;;){let a=kr(s,r,o,l,e),c=qs;if(!a){if(s.number==(e?n.state.doc.lines:1))return l;c=`
|
|
`,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),a=w.cursor(e?s.from:s.to)}if(h){if(!h(c))return l}else{if(!i)return a;h=i(c)}l=a}}function Vr(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let o=i(r);return s==X.Space&&(s=o),s==o}}function Nr(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return w.cursor(s,t.assoc);let o=t.goalColumn,l,h=n.contentDOM.getBoundingClientRect(),a=n.coordsAtPos(s),c=n.documentTop;if(a)o==null&&(o=a.left-h.left),l=r<0?a.top:a.bottom;else{let u=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(h.right-h.left,n.defaultCharacterWidth*(s-u.from))),l=(r<0?u.top:u.bottom)+c}let f=h.left+o,d=i??n.defaultLineHeight>>1;for(let u=0;;u+=10){let p=l+(d+u)*r,g=Zs(n,{x:f,y:p},!1,r);if(p<h.top||p>h.bottom||(r<0?g<s:g>s))return w.cursor(g,t.assoc,void 0,o)}}function pi(n,t,e){let i=n.state.facet(Hs).map(s=>s(n));for(;;){let s=!1;for(let r of i)r.between(e.from-1,e.from+1,(o,l,h)=>{e.from>o&&e.from<l&&(e=t.from>e.from?w.cursor(o,1):w.cursor(l,-1),s=!0)});if(!s)return e}}var tn=class{constructor(t){this.lastKeyCode=0,this.lastKeyTime=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.rapidCompositionStart=!1,this.mouseSelection=null;for(let e in I){let i=I[e];t.contentDOM.addEventListener(e,s=>{!nn(t,s)||this.ignoreDuringComposition(s)||e=="keydown"&&this.keydown(t,s)||(this.mustFlushObserver(s)&&t.observer.forceFlush(),this.runCustomHandlers(e,t,s)?s.preventDefault():i(t,s))}),this.registeredEvents.push(e)}y.chrome&&y.chrome_version>=102&&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,y.safari&&t.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}ensureHandlers(t,e){var i;let s;this.customHandlers=[];for(let r of e)if(s=(i=r.update(t).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let o in s)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),t.contentDOM.addEventListener(o,l=>{!nn(t,l)||this.runCustomHandlers(o,t,l)&&l.preventDefault()}))}}runCustomHandlers(t,e,i){for(let s of this.customHandlers){let r=s.handlers[t];if(r)try{if(r.call(s.plugin,i,e)||i.defaultPrevented)return!0}catch(o){pt(e.state,o)}}return!1}runScrollHandlers(t,e){for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,e,t)}catch(r){pt(t.state,r)}}}keydown(t,e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(y.android&&y.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return t.observer.delayAndroidKey(e.key,e.keyCode),!0;let i;return y.ios&&(i=en.find(s=>s.keyCode==e.keyCode))&&!(e.ctrlKey||e.altKey||e.metaKey)&&!e.synthetic?(this.pendingIOSKey=i,setTimeout(()=>this.flushIOSKey(t),250),!0):!1}flushIOSKey(t){let e=this.pendingIOSKey;return e?(this.pendingIOSKey=void 0,Ft(t.contentDOM,e.key,e.keyCode)):!1}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:y.safari&&Date.now()-this.compositionEndedAt<100?(this.compositionEndedAt=0,!0):!1:!1}mustFlushObserver(t){return t.type=="keydown"&&t.keyCode!=229||t.type=="compositionend"&&!y.ios}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()}},en=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Ir=[16,17,18,20,91,92,224,225],sn=class{constructor(t,e,i,s){this.view=t,this.style=i,this.mustSelect=s,this.lastEvent=e;let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(S.allowMultipleSelections)&&Hr(t,e),this.dragMove=Fr(t,e),this.dragging=Wr(t,e)&&gi(e)==1?null:!1,this.dragging===!1&&(e.preventDefault(),this.select(e))}move(t){if(t.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=t)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(t){let e=this.style.get(t,this.extend,this.multiple);(this.mustSelect||!e.eq(this.view.state.selection)||e.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:e,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(t){t.docChanged&&this.dragging&&(this.dragging=this.dragging.map(t.changes)),this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Hr(n,t){let e=n.state.facet(Ts);return e.length?e[0](t):y.mac?t.metaKey:t.ctrlKey}function Fr(n,t){let e=n.state.facet(Rs);return e.length?e[0](t):y.mac?!t.altKey:!t.ctrlKey}function Wr(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=he(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function nn(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=k.get(e))&&i.ignoreEvent(t))return!1;return!0}var I=Object.create(null),rn=y.ie&&y.ie_version<15||y.ios&&y.webkit_version<604;function zr(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),on(n,e.value)},50)}function on(n,t){let{state:e}=n,i,s=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(mi!=null&&e.selection.ranges.every(h=>h.empty)&&mi==r.toString()){let h=-1;i=e.changeByRange(a=>{let c=e.doc.lineAt(a.from);if(c.from==h)return{range:a};h=c.from;let f=e.toText((o?r.line(s++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:w.cursor(a.from+f.length)}})}else o?i=e.changeByRange(h=>{let a=r.line(s++);return{changes:{from:h.from,to:h.to,insert:a.text},range:w.cursor(h.from+a.length)}}):i=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}I.keydown=(n,t)=>{n.inputState.setSelectionOrigin("select"),t.keyCode==27?n.inputState.lastEscPress=Date.now():Ir.indexOf(t.keyCode)<0&&(n.inputState.lastEscPress=0)};var ln=0;I.touchstart=(n,t)=>{ln=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};I.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};I.mousedown=(n,t)=>{if(n.observer.flush(),ln>Date.now()-2e3&&gi(t)==1)return;let e=null;for(let i of n.state.facet(Es))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=$r(n,t)),e){let i=n.root.activeElement!=n.contentDOM;i&&n.observer.ignore(()=>ds(n.contentDOM)),n.inputState.startMouseSelection(new sn(n,t,e,i))}};function hn(n,t,e,i){if(i==1)return w.cursor(t,e);if(i==2)return Tr(n.state,t,e);{let s=W.find(n.docView,t),r=n.state.doc.lineAt(s?s.posAtEnd:t),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,w.range(o,l)}}var an=(n,t)=>n>=t.top&&n<=t.bottom,cn=(n,t,e)=>an(t,e)&&n>=e.left&&n<=e.right;function qr(n,t,e,i){let s=W.find(n.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&cn(e,i,o))return-1;let l=s.coordsAt(r,1);return l&&cn(e,i,l)?1:o&&an(i,o)?-1:1}function fn(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:qr(n,e,t.clientX,t.clientY)}}var Kr=y.ie&&y.ie_version<=11,un=null,dn=0,pn=0;function gi(n){if(!Kr)return n.detail;let t=un,e=pn;return un=n,pn=Date.now(),dn=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(dn+1)%3:1}function $r(n,t){let e=fn(n,t),i=gi(t),s=n.state.selection,r=e,o=t;return{update(l){l.docChanged&&(e&&(e.pos=l.changes.mapPos(e.pos)),s=s.map(l.changes),o=null)},get(l,h,a){let c;if(o&&l.clientX==o.clientX&&l.clientY==o.clientY?c=r:(c=r=fn(n,l),o=l),!c||!e)return s;let f=hn(n,c.pos,c.bias,i);if(e.pos!=c.pos&&!h){let d=hn(n,e.pos,e.bias,i),u=Math.min(d.from,f.from),p=Math.max(d.to,f.to);f=u<f.from?w.range(u,p):w.range(p,u)}return h?s.replaceRange(s.main.extend(f.from,f.to)):a&&s.ranges.length>1&&s.ranges.some(d=>d.eq(f))?jr(s,f):a?s.addRange(f):w.create([f])}}}function jr(n,t){for(let e=0;;e++)if(n.ranges[e].eq(t))return w.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}I.dragstart=(n,t)=>{let{selection:{main:e}}=n.state,{mouseSelection:i}=n.inputState;i&&(i.dragging=e),t.dataTransfer&&(t.dataTransfer.setData("Text",n.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove")};function gn(n,t,e,i){if(!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1);t.preventDefault();let{mouseSelection:r}=n.inputState,o=i&&r&&r.dragging&&r.dragMove?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:e},h=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:h,selection:{anchor:h.mapPos(s,-1),head:h.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}I.drop=(n,t)=>{if(!t.dataTransfer)return;if(n.state.readOnly)return t.preventDefault();let e=t.dataTransfer.files;if(e&&e.length){t.preventDefault();let i=Array(e.length),s=0,r=()=>{++s==e.length&&gn(n,t,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}}else gn(n,t,t.dataTransfer.getData("Text"),!0)};I.paste=(n,t)=>{if(n.state.readOnly)return t.preventDefault();n.observer.flush();let e=rn?null:t.clipboardData;e?(on(n,e.getData("text/plain")),t.preventDefault()):zr(n)};function Gr(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Ur(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:t.join(n.lineBreak),ranges:e,linewise:i}}var mi=null;I.copy=I.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=Ur(n.state);if(!e&&!s)return;mi=s?e:null;let r=rn?null:t.clipboardData;r?(t.preventDefault(),r.clearData(),r.setData("text/plain",e)):Gr(n,e),t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};function mn(n){setTimeout(()=>{n.hasFocus!=n.inputState.notifiedFocused&&n.update([])},10)}I.focus=mn;I.blur=n=>{n.observer.clearSelectionRange(),mn(n)};function yn(n,t){if(n.docView.compositionDeco.size){n.inputState.rapidCompositionStart=t;try{n.update([])}finally{n.inputState.rapidCompositionStart=!1}}}I.compositionstart=I.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0,n.docView.compositionDeco.size&&(n.observer.flush(),yn(n,!0)))};I.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionFirstChange=null,setTimeout(()=>{n.inputState.composing<0&&yn(n,!1)},50)};I.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};I.beforeinput=(n,t)=>{var e;let i;if(y.chrome&&y.android&&(i=en.find(s=>s.inputType==t.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}};var wn=["pre-wrap","normal","pre-line","break-spaces"],bn=class{constructor(){this.doc=x.empty,this.lineWrapping=!1,this.heightSamples={},this.lineHeight=14,this.charWidth=7,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.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 wn.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r){let o=wn.indexOf(t)>-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.lineLength=s,l){this.heightSamples={};for(let h=0;h<r.length;h++){let a=r[h];a<0?h++:this.heightSamples[Math.floor(a*10)]=!0}}return l}},vn=class{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}},et=class{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this.type=r}get to(){return this.from+this.length}get bottom(){return this.top+this.height}join(t){let e=(Array.isArray(this.type)?this.type:[this]).concat(Array.isArray(t.type)?t.type:[t]);return new et(this.from,this.length+t.length,this.top,this.height+t.height,e)}},C=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(C||(C={})),ye=.001,q=class{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&~2}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>ye&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return q.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this;for(let o=s.length-1;o>=0;o--){let{fromA:l,toA:h,fromB:a,toB:c}=s[o],f=r.lineAt(l,C.ByPosNoHeight,e,0,0),d=f.to>=h?f:r.lineAt(h,C.ByPosNoHeight,e,0,0);for(c+=d.to-h,h=d.to;o>0&&f.from<=s[o-1].toA;)l=s[o-1].fromA,a=s[o-1].fromB,o--,l<f.from&&(f=r.lineAt(l,C.ByPosNoHeight,e,0,0));a+=f.from-l,l=f.from;let u=we.build(i,t,a,c);r=r.replace(l,h,u)}return r.updateHeight(i,0)}static empty(){return new $(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new xn(q.of(t.slice(0,e)),o,q.of(t.slice(i)))}};q.prototype.size=1;var yi=class extends q{constructor(t,e,i){super(t,e);this.type=i}blockAt(t,e,i,s){return new et(s,this.length,i,this.height,this.type)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},$=class extends yi{constructor(t,e){super(t,e,L.Text);this.collapsed=0,this.widgetHeight=0}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof $||s instanceof H&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof H?s=new $(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):q.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},H=class extends q{constructor(t){super(t,0)}lines(t,e){let i=t.lineAt(e).number,s=t.lineAt(e+this.length).number;return{firstLine:i,lastLine:s,lineHeight:this.height/(s-i+1)}}blockAt(t,e,i,s){let{firstLine:r,lastLine:o,lineHeight:l}=this.lines(e,s),h=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:a,length:c}=e.line(r+h);return new et(a,c,i+l*h,l,L.Text)}lineAt(t,e,i,s,r){if(e==C.ByHeight)return this.blockAt(t,i,s,r);if(e==C.ByPosNoHeight){let{from:f,to:d}=i.lineAt(t);return new et(f,d-f,0,0,L.Text)}let{firstLine:o,lineHeight:l}=this.lines(i,r),{from:h,length:a,number:c}=i.lineAt(t);return new et(h,a,s+l*(c-o),l,L.Text)}forEachLine(t,e,i,s,r,o){let{firstLine:l,lineHeight:h}=this.lines(i,r);for(let a=Math.max(t,r),c=Math.min(r+this.length,e);a<=c;){let f=i.lineAt(a);a==t&&(s+=h*(f.number-l)),o(new et(f.from,f.length,s,h,L.Text)),s+=h,a=f.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof H?i[i.length-1]=new H(r.length+s):i.push(null,new H(s-1))}if(t>0){let r=i[0];r instanceof H?i[0]=new H(t+r.length):i.unshift(new H(t-1),null)}return q.of(i)}decomposeLeft(t,e){e.push(new H(t-1),null)}decomposeRight(t,e){e.push(null,new H(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),h=-1,a=t.heightChanged;for(s.from>e&&o.push(new H(s.from-e-1).updateHeight(t,e));l<=r&&s.more;){let f=t.doc.lineAt(l).length;o.length&&o.push(null);let d=s.heights[s.index++];h==-1?h=d:Math.abs(d-h)>=ye&&(h=-2);let u=new $(f,d);u.outdated=!1,o.push(u),l+=f+1}l<=r&&o.push(null,new H(r-l).updateHeight(t,l));let c=q.of(o);return t.heightChanged=a||h<0||Math.abs(c.height-this.height)>=ye||Math.abs(h-this.lines(t.doc,e).lineHeight)>=ye,c}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},xn=class extends q{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 this.flags&1}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,h=e==C.ByHeight?t<o:t<l,a=h?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let c=e==C.ByPosNoHeight?C.ByPosNoHeight:C.ByPos;return h?a.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(a)}forEachLine(t,e,i,s,r,o){let l=s+this.left.height,h=r+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,s,r,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let a=this.lineAt(h,C.ByPos,i,s,r);t<a.from&&this.left.forEachLine(t,a.from-1,i,s,r,o),a.to>=t&&a.from<=e&&o(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,l,h,o)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&Sn(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),Sn(r,l)}return q.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?q.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,s){let{left:r,right:o}=this,l=e+r.length+this.break,h=null;return s&&s.from<=e+r.length&&s.more?h=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?h=o=o.updateHeight(t,l,i,s):o.updateHeight(t,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Sn(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof H&&(i=n[t+1])instanceof H&&n.splice(t-1,3,new H(e.length+1+i.length))}var Jr=5,we=class{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 i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof $?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new $(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0;s<0&&(s=this.oracle.lineHeight);let r=e-t;i.block?this.addBlock(new yi(r,s,i.type)):(r||s>=Jr)&&this.addLineDeco(s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new $(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new H(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 $)return t;let e=new $(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine(),t.type==L.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,t.type!=L.WidgetBefore&&(this.covering=t)}addLineDeco(t,e){let i=this.ensureLine();i.length+=e,i.collapsed+=e,i.widgetHeight=Math.max(i.widgetHeight,t),this.writtenTo=this.pos=this.pos+e}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof $)&&!this.isCovered?this.nodes.push(new $(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof $&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new we(i,t);return O.spans(e,i,s,r,0),r.finish(i)}};function Xr(n,t,e){let i=new kn;return O.compare(n,t,e,i,0),i.changes}var kn=class{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&si(t,e,this.changes,5)}};function Yr(n,t){let e=n.getBoundingClientRect(),i=Math.max(0,e.left),s=Math.min(innerWidth,e.right),r=Math.max(0,e.top),o=Math.min(innerHeight,e.bottom),l=n.ownerDocument.body;for(let h=n.parentNode;h&&h!=l;)if(h.nodeType==1){let a=h,c=window.getComputedStyle(a);if((a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth)&&c.overflow!="visible"){let f=a.getBoundingClientRect();i=Math.max(i,f.left),s=Math.min(s,f.right),r=Math.max(r,f.top),o=Math.min(o,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?a.offsetParent:a.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:i-e.left,right:Math.max(i,s)-e.left,top:r-(e.top+t),bottom:Math.max(r,o)-(e.top+t)}}function Zr(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}var be=class{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<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t){return N.replace({widget:new Cn(this.size,t)}).range(this.from,this.to)}},Cn=class extends Wt{constructor(t,e){super();this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}},wi=class{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.heightOracle=new bn,this.scaler=Dn,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=z.RTL,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1,this.stateDeco=t.facet(jt).filter(e=>typeof e!="function"),this.heightMap=q.empty().applyChanges(this.stateDeco,x.empty,this.heightOracle.setDoc(t.doc),[new Y(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=N.set(this.lineGaps.map(e=>e.draw(!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);t.push(new Jt(r,o))}}this.viewports=t.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?Dn:new On(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,t=>{this.viewportLines.push(this.scaler.scale==1?t:Xt(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(jt).filter(a=>typeof a!="function");let s=t.changedRanges,r=Y.extendWithRanges(s,Xr(i,this.stateDeco,t?t.changes:T.empty(this.state.doc.length))),o=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(t.flags|=2);let l=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<l.from||e.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let h=!t.changes.empty||t.flags&2||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),h&&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&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?z.RTL:z.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=o||this.mustMeasureContent||this.contentDOMHeight!=e.clientHeight;this.contentDOMHeight=e.clientHeight,this.mustMeasureContent=!1;let h=0,a=0,c=parseInt(i.paddingTop)||0,f=parseInt(i.paddingBottom)||0;(this.paddingTop!=c||this.paddingBottom!=f)&&(this.paddingTop=c,this.paddingBottom=f,h|=8|2),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=8);let d=(this.printing?Zr:Yr)(e,this.paddingTop),u=d.top-this.pixelViewport.top,p=d.bottom-this.pixelViewport.bottom;this.pixelViewport=d;let g=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(g!=this.inView&&(this.inView=g,g&&(l=!0)),!this.inView)return 0;let m=e.clientWidth;if((this.contentDOMWidth!=m||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=m,this.editorHeight=t.scrollDOM.clientHeight,h|=8),l){let B=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(B)&&(o=!0),o||s.lineWrapping&&Math.abs(m-this.contentDOMWidth)>s.charWidth){let{lineHeight:it,charWidth:ft}=t.docView.measureTextSize();o=s.refresh(r,it,ft,m/ft,B),o&&(t.docView.minWidth=0,h|=8)}u>0&&p>0?a=Math.max(u,p):u<0&&p<0&&(a=Math.min(u,p)),s.heightChanged=!1;for(let it of this.viewports){let ft=it.from==this.viewport.from?B:t.docView.measureVisibleLineHeights(it);this.heightMap=this.heightMap.updateHeight(s,0,o,new vn(it.from,ft))}s.heightChanged&&(h|=2)}let b=!this.viewportIsAppropriate(this.viewport,a)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return b&&(this.viewport=this.getViewport(a,this.scrollTarget)),this.updateForViewport(),(h&2||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.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)),s=this.heightMap,r=this.state.doc,{visibleTop:o,visibleBottom:l}=this,h=new Jt(s.lineAt(o-i*1e3,C.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,C.ByHeight,r,0,0).to);if(e){let{head:a}=e.range;if(a<h.from||a>h.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(a,C.ByPos,r,0,0),d;e.y=="center"?d=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&a<h.from?d=f.top:d=f.bottom-c,h=new Jt(s.lineAt(d-1e3/2,C.ByHeight,r,0,0).from,s.lineAt(d+c+1e3/2,C.ByHeight,r,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new Jt(this.heightMap.lineAt(i,C.ByPos,this.state.doc,0,0).from,this.heightMap.lineAt(s,C.ByPos,this.state.doc,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,C.ByPos,this.state.doc,0,0),{bottom:r}=this.heightMap.lineAt(e,C.ByPos,this.state.doc,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new be(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t){let e=[];if(this.defaultTextDirection!=z.LTR)return e;for(let i of this.viewportLines){if(i.length<4e3)continue;let s=Qr(i.from,i.to,this.stateDeco);if(s.total<4e3)continue;let r,o;if(this.heightOracle.lineWrapping){let a=2e3/this.heightOracle.lineLength*this.heightOracle.lineHeight;r=ve(s,(this.visibleTop-i.top-a)/i.height),o=ve(s,(this.visibleBottom-i.top+a)/i.height)}else{let a=s.total*this.heightOracle.charWidth,c=2e3*this.heightOracle.charWidth;r=ve(s,(this.pixelViewport.left-c)/a),o=ve(s,(this.pixelViewport.right+c)/a)}let l=[];r>i.from&&l.push({from:i.from,to:r}),o<i.to&&l.push({from:o,to:i.to});let h=this.state.selection.main;h.from>=i.from&&h.from<=i.to&&Mn(l,h.from-10,h.from+10),!h.empty&&h.to>=i.from&&h.to<=i.to&&Mn(l,h.to-10,h.to+10);for(let{from:a,to:c}of l)c-a>1e3&&e.push(_r(t,f=>f.from>=i.from&&f.to<=i.to&&Math.abs(f.from-a)<1e3&&Math.abs(f.to-c)<1e3)||new be(a,c,this.gapSize(i,a,c,s)))}return e}gapSize(t,e,i,s){let r=An(s,i)-An(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){be.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=N.set(t.map(e=>e.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];O.spans(t,this.viewport.from,this.viewport.to,{span(s,r){e.push({from:s,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=e[r].from||s.to!=e[r].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)||Xt(this.heightMap.lineAt(t,C.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(t){return Xt(this.heightMap.lineAt(this.scaler.fromDOM(t),C.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(t){return Xt(this.heightMap.blockAt(this.scaler.fromDOM(t),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Jt=class{constructor(t,e){this.from=t,this.to=e}};function Qr(n,t,e){let i=[],s=n,r=0;return O.spans(e,n,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function ve({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:o}=t[s],l=o-r;if(i<=l)return r+i;i-=l}}function An(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function Mn(n,t,e){for(let i=0;i<n.length;i++){let s=n[i];if(s.from<e&&s.to>t){let r=[];s.from<t&&r.push({from:s.from,to:t}),s.to>e&&r.push({from:e,to:s.to}),n.splice(i,1,...r),i+=r.length-1}}}function _r(n,t){for(let e of n)if(t(e))return e}var Dn={toDOM(n){return n},fromDOM(n){return n},scale:1},On=class{constructor(t,e,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=e.lineAt(l,C.ByPos,t,0,0).top,c=e.lineAt(h,C.ByPos,t,0,0).bottom;return s+=c-a,{from:l,to:h,top:a,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}};function Xt(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new et(n.from,n.length,e,i-e,Array.isArray(n.type)?n.type.map(s=>Xt(s,t)):n.type)}var xe=v.define({combine:n=>n.join(" ")}),bi=v.define({combine:n=>n.indexOf(!0)>-1}),vi=lt.newName(),Tn=lt.newName(),Rn=lt.newName(),En={"&light":"."+Tn,"&dark":"."+Rn};function xi(n,t,e){return new lt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}var to=xi("."+vi,{"&.cm-editor":{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,minHeight:"100%",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 4px"},".cm-selectionLayer":{zIndex:-1,contain:"size style"},".cm-selectionBackground":{position:"absolute"},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{zIndex:100,contain:"size style",pointerEvents:"none"},"&.cm-focused .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":{position:"absolute",borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#f3f9ff"},"&dark .cm-activeLine":{backgroundColor:"#223039"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{display:"flex",height:"100%",boxSizing:"border-box",left: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",display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".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"}},En),eo={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Si=y.ie&&y.ie_version<=11,Ln=class{constructor(t,e,i){this.view=t,this.onChange=e,this.onScrollChanged=i,this.active=!1,this.selectionRange=new us,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(s=>{for(let r of s)this.queue.push(r);(y.ie&&y.ie_version<=11||y.ios&&t.composing)&&s.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),Si&&(this.onCharData=s=>{this.queue.push({target:s.target,type:"characterData",oldValue:s.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),window.addEventListener("resize",this.onResize=this.onResize.bind(this)),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{this.view.docView.lastUpdate<Date.now()-75&&this.onResize()}),this.resize.observe(t.scrollDOM)),window.addEventListener("beforeprint",this.onPrint=this.onPrint.bind(this)),this.start(),window.addEventListener("scroll",this.onScroll=this.onScroll.bind(this)),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(s=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),s.length>0&&s[s.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(s=>{s.length>0&&s[s.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange(),this.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}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){if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:e}=this,i=this.selectionRange;if(e.state.facet(ge)?e.root.activeElement!=this.dom:!Ke(e.dom,i))return;let s=i.anchorNode&&e.docView.nearest(i.anchorNode);s&&s.ignoreEvent(t)||((y.ie&&y.ie_version<=11||y.android&&y.chrome)&&!e.state.selection.main.empty&&i.focusNode&&ae(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1))}readSelectionRange(){let{root:t}=this.view,e=y.safari&&t.nodeType==11&&ar()==this.view.contentDOM&&io(this.view)||he(t);return!e||this.selectionRange.eq(e)?!1:(this.selectionRange.setRange(e),this.selectionChanged=!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,eo),Si&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){!this.active||(this.active=!1,this.observer.disconnect(),Si&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){this.delayedAndroidKey||requestAnimationFrame(()=>{let i=this.delayedAndroidKey;this.delayedAndroidKey=null,this.delayedFlush=-1,this.flush()||Ft(this.view.contentDOM,i.key,i.keyCode)}),(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e})}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=window.setTimeout(()=>{this.delayedFlush=-1,this.flush()},20))}forceFlush(){this.delayedFlush>=0&&(window.clearTimeout(this.delayedFlush),this.delayedFlush=-1,this.flush())}processRecords(){let t=this.queue;for(let r of this.observer.takeRecords())t.push(r);t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let o=this.readMutation(r);!o||(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return;t&&this.readSelectionRange();let{from:e,to:i,typeOver:s}=this.processRecords(),r=this.selectionChanged&&Ke(this.dom,this.selectionRange);if(e<0&&!r)return;this.selectionChanged=!1;let o=this.view.state,l=this.onChange(e,i,s);return this.view.state==o&&this.view.update([]),l}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.dirty|=4),t.type=="childList"){let i=Bn(e,t.previousSibling||t.target.previousSibling,-1),s=Bn(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resize)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);window.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),window.removeEventListener("beforeprint",this.onPrint),this.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout)}};function Bn(n,t,e){for(;t;){let i=k.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function io(n){let t=null;function e(h){h.preventDefault(),h.stopImmediatePropagation(),t=h.getTargetRanges()[0]}if(n.contentDOM.addEventListener("beforeinput",e,!0),document.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",e,!0),!t)return null;let i=t.startContainer,s=t.startOffset,r=t.endContainer,o=t.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return ae(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}function so(n,t,e,i){let s,r,o=n.state.selection.main;if(t>-1){let l=n.docView.domBoundsAround(t,e,0);if(!l||n.state.readOnly)return!1;let{from:h,to:a}=l,c=n.docView.impreciseHead||n.docView.impreciseAnchor?[]:ro(n),f=new hi(c,n.state);f.readRange(l.startDOM,l.endDOM);let d=o.from,u=null;(n.inputState.lastKeyCode===8&&n.inputState.lastKeyTime>Date.now()-100||y.android&&f.text.length<a-h)&&(d=o.to,u="end");let p=no(n.state.doc.sliceString(h,a,ct),f.text,d-h,u);p&&(y.chrome&&n.inputState.lastKeyCode==13&&p.toB==p.from+2&&f.text.slice(p.from,p.toB)==ct+ct&&p.toB--,s={from:h+p.from,to:h+p.toA,insert:x.of(f.text.slice(p.from,p.toB).split(ct))}),r=oo(c,h)}else if(n.hasFocus||!n.state.facet(ge)){let l=n.observer.selectionRange,{impreciseHead:h,impreciseAnchor:a}=n.docView,c=h&&h.node==l.focusNode&&h.offset==l.focusOffset||!Dt(n.contentDOM,l.focusNode)?n.state.selection.main.head:n.docView.posFromDOM(l.focusNode,l.focusOffset),f=a&&a.node==l.anchorNode&&a.offset==l.anchorOffset||!Dt(n.contentDOM,l.anchorNode)?n.state.selection.main.anchor:n.docView.posFromDOM(l.anchorNode,l.anchorOffset);(c!=o.head||f!=o.anchor)&&(r=w.single(f,c))}if(!s&&!r)return!1;if(!s&&i&&!o.empty&&r&&r.main.empty?s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,o.to)}:s&&s.from>=o.from&&s.to<=o.to&&(s.from!=o.from||s.to!=o.to)&&o.to-o.from-(s.to-s.from)<=4?s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,s.from).append(s.insert).append(n.state.doc.slice(s.to,o.to))}:(y.mac||y.android)&&s&&s.from==s.to&&s.from==o.head-1&&s.insert.toString()=="."&&(s={from:o.from,to:o.to,insert:x.of([" "])}),s){let l=n.state;if(y.ios&&n.inputState.flushIOSKey(n)||y.android&&(s.from==o.from&&s.to==o.to&&s.insert.length==1&&s.insert.lines==2&&Ft(n.contentDOM,"Enter",13)||s.from==o.from-1&&s.to==o.to&&s.insert.length==0&&Ft(n.contentDOM,"Backspace",8)||s.from==o.from&&s.to==o.to+1&&s.insert.length==0&&Ft(n.contentDOM,"Delete",46)))return!0;let h=s.insert.toString();if(n.state.facet(Bs).some(f=>f(n,s.from,s.to,h)))return!0;n.inputState.composing>=0&&n.inputState.composing++;let a;if(s.from>=o.from&&s.to<=o.to&&s.to-s.from>=(o.to-o.from)/3&&(!r||r.main.empty&&r.main.from==s.from+s.insert.length)&&n.inputState.composing<0){let f=o.from<s.from?l.sliceDoc(o.from,s.from):"",d=o.to>s.to?l.sliceDoc(s.to,o.to):"";a=l.replaceSelection(n.state.toText(f+s.insert.sliceString(0,void 0,n.state.lineBreak)+d))}else{let f=l.changes(s),d=r&&!l.selection.main.eq(r.main)&&r.main.to<=f.newLength?r.main:void 0;if(l.selection.ranges.length>1&&n.inputState.composing>=0&&s.to<=o.to&&s.to>=o.to-10){let u=n.state.sliceDoc(s.from,s.to),p=$s(n)||n.state.doc.lineAt(o.head),g=o.to-s.to,m=o.to-o.from;a=l.changeByRange(b=>{if(b.from==o.from&&b.to==o.to)return{changes:f,range:d||b.map(f)};let B=b.to-g,it=B-u.length;if(b.to-b.from!=m||n.state.sliceDoc(it,B)!=u||p&&b.to>=p.from&&b.from<=p.to)return{range:b};let ft=l.changes({from:it,to:B,insert:s.insert}),Ai=b.to-o.to;return{changes:ft,range:d?w.range(Math.max(0,d.anchor+Ai),Math.max(0,d.head+Ai)):b.map(ft)}})}else a={changes:f,selection:d&&l.selection.replaceRange(d)}}let c="input.type";return n.composing&&(c+=".compose",n.inputState.compositionFirstChange&&(c+=".start",n.inputState.compositionFirstChange=!1)),n.dispatch(a,{scrollIntoView:!0,userEvent:c}),!0}else if(r&&!r.main.eq(o)){let l=!1,h="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),h=n.inputState.lastSelectionOrigin),n.dispatch({selection:r,scrollIntoView:l,userEvent:h}),!0}else return!1}function no(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let o=n.length,l=t.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));e-=o+h-r}return o<r&&n.length<t.length?(r-=e<=r&&e>=o?r-e:0,l=r+(l-o),o=r):l<r&&(r-=e<=r&&e>=l?r-e:0,o=r+(o-l),l=r),{from:r,toA:o,toB:l}}function ro(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new ai(e,i)),(s!=e||r!=i)&&t.push(new ai(s,r))),t}function oo(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?w.single(e+t,i+t):null}var A=class{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: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=t.dispatch||(e=>this.update([e])),this.dispatch=this.dispatch.bind(this),this.root=t.root||ur(t.parent)||document,this.viewState=new wi(t.state||S.create(t)),this.plugins=this.state.facet(Kt).map(e=>new me(e));for(let e of this.plugins)e.update(this);this.observer=new Ln(this,(e,i,s)=>so(this,e,i,s),e=>{this.inputState.runScrollHandlers(this,e),this.observer.intersecting&&this.measure()}),this.inputState=new tn(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new ci(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),t.parent&&t.parent.appendChild(this.dom)}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}dispatch(...t){this._dispatch(t.length==1&&t[0]instanceof P?t[0]:this.state.update(...t))}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let l of t){if(l.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=l.state}if(this.destroyed){this.viewState.state=r;return}if(this.observer.clear(),r.facet(S.phrases)!=this.state.facet(S.phrases))return this.setState(r);s=Ut.create(this,r,t);let o=this.viewState.scrollTarget;try{this.updateState=2;for(let l of t){if(o&&(o=o.map(l.changes)),l.scrollIntoView){let{main:h}=l.state.selection;o=new qt(h.empty?h:w.cursor(h.head,h.head>h.anchor?-1:1))}for(let h of l.effects)h.is(Vs)&&(o=h.value)}this.viewState.update(s,o),this.bidiCache=Yt.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Gt)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(l=>l.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(xe)!=s.state.facet(xe)&&(this.viewState.mustMeasureContent=!0),(e||i||o||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let l of this.state.facet(ri))l(s)}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new wi(t),this.plugins=t.facet(Kt).map(i=>new me(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new ci(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(Kt),i=t.state.facet(Kt);if(e!=i){let s=[];for(let r of i){let o=e.indexOf(r);if(o<0)s.push(new me(r));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this)}measure(t=!0){if(this.destroyed)return;this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,t&&this.observer.flush();let e=null;try{for(let i=0;;i++){this.updateState=1;let s=this.viewport,r=this.viewState.measure(this);if(!r&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(i>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let o=[];r&4||([this.measureRequests,o]=[o,this.measureRequests]);let l=o.map(f=>{try{return f.read(this)}catch(d){return pt(this.state,d),Pn}}),h=Ut.create(this,this.state,[]),a=!1,c=!1;h.flags|=r,e?e.flags|=r:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),a=this.docView.update(h));for(let f=0;f<o.length;f++)if(l[f]!=Pn)try{let d=o[f];d.write&&d.write(l[f],this)}catch(d){pt(this.state,d)}if(this.viewState.scrollTarget&&(this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,c=!0),a&&this.docView.updateSelection(!0),this.viewport.from==s.from&&this.viewport.to==s.to&&!c&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let i of this.state.facet(ri))i(e)}get themeClasses(){return vi+" "+(this.state.facet(bi)?Rn:Tn)+" "+this.state.facet(xe)}updateAttrs(){let t=Vn(this,Ns,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(ge)?"true":"false",class:"cm-content",style:`${y.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Vn(this,Is,e);let i=this.observer.ignore(()=>{let s=ii(this.contentDOM,this.contentAttrs,e),r=ii(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(A.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Gt),lt.mount(this.root,this.styleModules.concat(to).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=requestAnimationFrame(()=>this.measure())),t){if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.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}}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 pi(this,t,_s(this,t,e,i))}moveByGroup(t,e){return pi(this,t,_s(this,t,e,i=>Vr(this,t.head,i)))}moveToLineBoundary(t,e,i=!0){return Pr(this,t,e,i)}moveVertically(t,e,i){return pi(this,t,Nr(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(),Zs(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 s=this.state.doc.lineAt(t),r=this.bidiSpans(s),o=r[gt.find(r,t-s.from,-1,e)];return fe(i,o.dir==z.LTR==e>0)}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(Ps)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>lo)return zs(t.length);let e=this.textDirectionAt(t.from);for(let s of this.bidiCache)if(s.from==t.from&&s.dir==e)return s.order;let i=Sr(t.text,e);return this.bidiCache.push(new Yt(t.from,t.to,e,i)),i}get hasFocus(){var t;return(document.hasFocus()||y.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{ds(this.contentDOM),this.docView.updateSelection()})}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Vs.of(new qt(typeof t=="number"?w.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}static domEventHandlers(t){return $t.define(()=>({}),{eventHandlers:t})}static theme(t,e){let i=lt.newName(),s=[xe.of(i),Gt.of(xi(`.${i}`,t))];return e&&e.dark&&s.push(bi.of(!0)),s}static baseTheme(t){return Ki.lowest(Gt.of(xi("."+vi,t,En)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&k.get(i)||k.get(t);return((e=s==null?void 0:s.rootView)===null||e===void 0?void 0:e.view)||null}};A.styleModule=Gt;A.inputHandler=Bs;A.perLineTextDirection=Ps;A.exceptionSink=Ls;A.updateListener=ri;A.editable=ge;A.mouseSelectionStyle=Es;A.dragMovesSelection=Rs;A.clickAddsSelectionRange=Ts;A.decorations=jt;A.atomicRanges=Hs;A.scrollMargins=Fs;A.darkTheme=bi;A.contentAttributes=Is;A.editorAttributes=Ns;A.lineWrapping=A.contentAttributes.of({class:"cm-lineWrapping"});A.announce=E.define();var lo=4096,Pn={},Yt=class{constructor(t,e,i,s){this.from=t,this.to=e,this.dir=i,this.order=s}static update(t,e){if(e.empty)return t;let i=[],s=t.length?t[t.length-1].dir:z.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new Yt(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.order))}return i}};function Vn(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&ti(o,e)}return e}var Ao=y.mac?"mac":y.windows?"win":y.linux?"linux":"key";var ho=!y.ios;var ao={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};ho&&(ao[".cm-line"].caretColor="transparent !important");var Mo=/x/.unicode!=null?"gu":"g";var Do=A.baseTheme({".cm-tooltip":{zIndex:100},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:`${7}px`,width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:`${7}px solid transparent`,borderRight:`${7}px solid transparent`},".cm-tooltip-above &":{bottom:`-${7}px`,"&:before":{borderTop:`${7}px solid #bbb`},"&:after":{borderTop:`${7}px solid #f5f5f5`,bottom:"1px"}},".cm-tooltip-below &":{top:`-${7}px`,"&:before":{borderBottom:`${7}px solid #bbb`},"&:after":{borderBottom:`${7}px solid #f5f5f5`,top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}});var mt=class extends ot{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};mt.prototype.elementClass="";mt.prototype.toDOM=void 0;mt.prototype.mapMode=K.TrackBefore;mt.prototype.startSide=mt.prototype.endSide=-1;mt.prototype.point=!0;var ki=class{constructor(){this.checkedRE=new RegExp(/^([\s>]*- \[)(x|X)(\] .*)$/),this.unCheckedRE=new RegExp(/^([\s>]*- \[)(.)(\] .*)$/)}check(t){return t.replace(this.unCheckedRE,"$1x$3")}uncheck(t){return t.replace(this.checkedRE,"$1 $3")}};var Ci=class extends Et.Plugin{onload(){return Ce(this,null,function*(){this.dvapi=(0,Nn.getAPI)(),this.TU=new ki,this.registerDomEvent(window,"click",t=>Ce(this,null,function*(){let e=t.target,i=this.app.workspace.getActiveViewOfType(Et.MarkdownView),s=e.nextElementSibling;console.debug("tgt",s,s==null?void 0:s.tagName);let r=o=>{let l=[];console.debug("items",o);for(let h=0;h<o.length;h++)console.log("ii",o[h]),l.push(o[h].querySelector("input[type='checkbox']")),r(o[h].children);return l};if(!(e.tagName.toLowerCase()!=="input"&&e.getAttr("type")!=="checkbox")){if((s==null?void 0:s.tagName.toLowerCase())==="ul"&&(s==null?void 0:s.classList.contains("contains-task-list"))){console.log("nessy",s,s.children);let o=r(s.children).flat(1/0);console.log("reee",o),o.forEach(l=>{(!e.checked&&l.checked||e.checked&&!l.checked)&&l.click()})}else if(e.tagName.toLowerCase()==="input"){let o=A.findFromDOM(document.body);console.debug("elif");let{editor:l}=o.state.field(Et.editorViewField),h=l.offsetToPos(o.posAtDOM(e)).line,a=this.app.workspace.getActiveFile(),f=this.dvapi.page(a.path).file.tasks.values.filter(g=>g.parent===h);console.debug("curious cat",f,this.recurseLivePreviewSubtasks(f).flat(1/0));let d=[];this.recurseLivePreviewSubtasks(f).flat(1/0).forEach(g=>{let{node:m}=o.domAtPos(g.end.offset),b=B=>{d.push(B),[].slice.call(B.children).forEach(b)};[].slice.call(m.children).forEach(b)});let p=d.filter(g=>g.matches("input[type='checkbox']"));p.forEach(g=>{let m=b=>{console.log("clik",b)};g.onclick=m,g.click(),console.log("check status",g.checked,e.checked),(!e.checked&&g.checked||e.checked&&!g.checked)&&g.click()}),console.debug("node",p),this.dvapi.index.touch(),this.app.workspace.trigger("dataview:refresh-views")}}}))})}recurseSubtasks(t){let e=[];function i(s){return e.push(s.children.map(i)),console.log("la",e,t),s.line}return t.map(s=>{e.push(s.line)}),t.map(i),e}recurseLivePreviewSubtasks(t){let e=[];function i(s){return e.push(s.children.map(i)),ke(Se({},s.position),{text:s.text})}return t.map(s=>{e.push(ke(Se({},s.position),{text:s.text}))}),t.map(i),console.debug("finalarr",e.flat(1/0)),e}onunload(){}};0&&(module.exports={});
|