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&&ot&&o&&(s+=i),tr&&(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=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=r&&e<=l){let h=o.replace(t-r,e-r,i),a=this.lines-o.lines+h.lines;if(h.lines>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;rt&&r&&(s+=i),to&&(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=e&&(h>i&&(l=l.slice(0,i-s)),s0?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;nn)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=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=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;et)return r+(t-s);r+=l}else{if(i!=K.Simple&&a>=t&&(i==K.TrackDel&&st||i==K.TrackBefore&&st))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=0&&s<=e&&l>=t)return se?"cover":!0;s=l}return!1}toString(){let t="";for(let e=0;e=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=0){e[s]=l,e[s+1]=o;let h=s>>1;for(;i.length0&&st(i,e,r.text),r.forward(c),l+=c}let a=t[o++];for(;l>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;od||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;fo&&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;sl&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)e.push(r[0],0);else{for(;i.length=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>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=0&&h=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.lenh||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>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;et.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;st?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;sr.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;in[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;ci===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>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[i]))r=n[i++],o=n[i++];else if(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"\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-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;ls.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;lo.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(;ln.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);ru||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=0){let f=e[h++];c.addInner(f.from,f.to,f.value)||a.push(f)}else l.rangeIndex==1&&l.chunkIndexthis.chunkEnd(l.chunkIndex)||rl.to||r=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;e0)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=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=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=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-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=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}};function 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=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)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-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),e)for(let h=0;h",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.top0&&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-p0&&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.lefte)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=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;sthis.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(i0&&(!o&&r.length&&c.merge(e,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(e2),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||et&&e.push(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=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||e0?i.length-1:0;s=i[r],!(t>0?r==0:r==i.length-1||s.top0?-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(n0?-1:1);return i&&i.tope.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:is&&e0;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;o0?h>=t:h>t)&&(t0)){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=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;r0&&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=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||e0;){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&&(t0),c=!h.isEditable&&(tn.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.toAc)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=e){if(l.level==i)return o;(r<0||(s!=0?s<0?l.frome: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=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;ol;){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;o1)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})=>lthis.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=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(;eo||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;cs)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;ee.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.head0&&e<=0)n=n.childNodes[t-1],t=ce(n);else if(n.nodeType==1&&t=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)|(t0;){let a=Q(s.text,o,!1);if(i(s.text.slice(a,o))!=h)break;o=a}for(;ln?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.topt.top+1}function Js(n,t){return tn.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;gB||o==B&&r>b)&&(i=u,s=m,r=b,o=B),b==0?e>m.bottom&&(!a||a.bottomm.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;le?c.top-e:e-c.bottom)-1;if(c.left-1<=t&&c.right+1>=t&&f=(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(fn.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(ph.bottom||(r<0?gs))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.frome.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()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=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 ln>=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=u1&&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{/[\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-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;h0}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--,lr*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&&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 tl))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.right.forEachLine(t,e,i,l,h,o);else{let a=this.lineAt(h,C.ByPos,i,s,r);t=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(ethis.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=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);t2*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=Jr)&&this.addLineDeco(s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new $(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.writtenToa.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;itypeof 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.headl.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.headthis.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(ah.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=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&ri.from&&l.push({from:i.from,to:r}),o=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=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;it){let r=[];s.frome&&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=eXt(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{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{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=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.froms.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(;r0&&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=o?r-e:0,l=r+(l-o),o=r):l=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-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{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;ei.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)||tthis.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=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{(!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={});