import{t as e}from"./rolldown-runtime.BB3S47xo.mjs";import{B as t,H as n,V as r}from"./react.UZZKdtaS.mjs";import{I as i,Z as a}from"./framer.Ypvh2MRC.mjs";var o,s,c,l=e((()=>{a(),i.loadFonts([`CUSTOM;Alliance No.2 Regular`]),o=[{explicitInter:!0,fonts:[{family:`Alliance No.2 Regular`,source:`custom`,url:`/assets/fonts/5ULuFZzV6apka2S9h7VtMoWQeI-18c5433196.woff2`}]}],s=[`.framer-pDFiI .framer-styles-preset-bo0tsp:not(.rich-text-wrapper), .framer-pDFiI .framer-styles-preset-bo0tsp.rich-text-wrapper h1 { --framer-font-family: "Alliance No.2 Regular", "Alliance No.2 Regular Placeholder", sans-serif; --framer-font-open-type-features: normal; --framer-font-size: 64px; --framer-font-style: normal; --framer-font-variation-axes: normal; --framer-font-weight: 400; --framer-letter-spacing: -0.03em; --framer-line-height: 1.2em; --framer-paragraph-spacing: 80px; --framer-text-alignment: start; --framer-text-color: var(--token-28d21c18-0fa7-4a39-8727-636fc79ae338, #ffffff); --framer-text-decoration: none; --framer-text-stroke-color: initial; --framer-text-stroke-width: initial; --framer-text-transform: none; --framer-text-wrap: balance; }`,`@media (max-width: 1439px) and (min-width: 1180px) { .framer-pDFiI .framer-styles-preset-bo0tsp:not(.rich-text-wrapper), .framer-pDFiI .framer-styles-preset-bo0tsp.rich-text-wrapper h1 { --framer-font-family: "Alliance No.2 Regular", "Alliance No.2 Regular Placeholder", sans-serif; --framer-font-open-type-features: normal; --framer-font-size: 54px; --framer-font-style: normal; --framer-font-variation-axes: normal; --framer-font-weight: 400; --framer-letter-spacing: -0.03em; --framer-line-height: 1.2em; --framer-paragraph-spacing: 60px; --framer-text-alignment: start; --framer-text-color: var(--token-28d21c18-0fa7-4a39-8727-636fc79ae338, #ffffff); --framer-text-decoration: none; --framer-text-stroke-color: initial; --framer-text-stroke-width: initial; --framer-text-transform: none; --framer-text-wrap: balance; } }`,`@media (max-width: 1179px) and (min-width: 0px) { .framer-pDFiI .framer-styles-preset-bo0tsp:not(.rich-text-wrapper), .framer-pDFiI .framer-styles-preset-bo0tsp.rich-text-wrapper h1 { --framer-font-family: "Alliance No.2 Regular", "Alliance No.2 Regular Placeholder", sans-serif; --framer-font-open-type-features: normal; --framer-font-size: 44px; --framer-font-style: normal; --framer-font-variation-axes: normal; --framer-font-weight: 400; --framer-letter-spacing: -0.03em; --framer-line-height: 1.2em; --framer-paragraph-spacing: 80px; --framer-text-alignment: start; --framer-text-color: var(--token-28d21c18-0fa7-4a39-8727-636fc79ae338, #ffffff); --framer-text-decoration: none; --framer-text-stroke-color: initial; --framer-text-stroke-width: initial; --framer-text-transform: none; --framer-text-wrap: balance; } }`],c=`framer-pDFiI`}));function u(e,t){return{description:`Gravvitor impulsa empresas con branding estratégico, marketing digital e inteligencia artificial. Fortalece tu marca, optimiza tu presencia online y acelera el crecimiento de tu negocio.`,favicon:`/assets/images/b8xMZv1rXh8Wa4fsqpujFIPPZU-33d056a622.png`,robots:`max-image-preview:large`,socialImage:`/assets/images/baUBxGCXCzX4JfPR9VV3CGNC4bA-2ab22c8228.jpg`,title:`Gravvitor - Publicidad y Capacitación para la Empresa`}}var d=e((()=>{}));function f(e,t,n,r){switch(e){case-2:return n=t&&nt;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function p(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}function g(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;rn.from||i.to=t){let o=new w(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(p(o,t,n,!1))}}return i?g(i):r}function ee(e){return e.children.some(e=>e instanceof ye||!e.type.isAnonymous||ee(e))}function te(e){let{buffer:t,nodeSet:n,maxBufferLength:r=de,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new ve(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,ee,te,ne){let{id:ie,start:v,end:ae,size:oe}=o,se=l,ce=c;for(;oe<0;)if(o.next(),oe==-1){let t=i[ie];_.push(t),ee.push(v-e);return}else if(oe==-3){c=ie;return}else if(oe==-4){l=ie;return}else throw RangeError(`Unrecognized record size: ${oe}`);let le=s[ie],ue,de,fe=v-e;if(ae-v<=r&&(de=h(o.pos-t,te))){let t=new Uint16Array(de.size-de.skip),r=o.pos-de.size,i=t.length;for(;o.pos>r;)i=g(de.start,t,i);ue=new ye(t,ae-de.start,n),fe=de.start-e}else{let e=o.pos-oe;o.next();let t=[],n=[],i=ie>=a?ie:-1,s=0,c=ae;for(;o.pos>e;)i>=0&&o.id==i&&o.size>=0?(o.end<=c-r&&(p(t,n,v,s,o.end,c,i,se,ce),s=t.length,c=o.end),o.next()):ne>2500?d(v,e,t,n):u(v,e,t,n,i,ne+1);if(i>=0&&s>0&&s-1&&s>0){let e=f(le,ce);ue=re(le,t,n,0,t.length,0,ae-v,e,e)}else ue=m(le,t,n,ae-v,se-ae,ce)}_.push(ue),ee.push(fe)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new ye(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof C){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(b.lookAhead))&&(a=r[o]+s.length+c)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[b.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[b.lookAhead,i];o=o?[e].concat(o):[e]}return new C(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0)if(n.size==-3)d+=4;else break scan;else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],ee=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,ee,-1,0);let te=e.length??(_.length?ee[0]+_[0].length:0);return new C(s[e.topID],_.reverse(),ee.reverse(),te)}function ne(e,t){if(!e.isAnonymous||t instanceof ye||t.type!=e)return 1;let n=Te.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof C)){n=1;break}n+=ne(e,r)}Te.set(t,n)}return n}function re(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(re(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}function ie(e){return(t,n,r,i)=>new Ne(t,e,n,r,i)}function v(e){if(!e.length||e.some(e=>e.from>=e.to))throw RangeError(`Invalid inner parse ranges given: `+JSON.stringify(e))}function ae(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function oe(e,t,n,r,i,a){if(t=s)break;e.to<=o||(n||(r=n=t.slice()),e.froms&&n.splice(a+1,0,new y(s,e.to))):e.to>s?n[a--]=new y(s,e.to):n.splice(a--,1))}}return r}function le(e,t,n,r){let i=0,a=0,o=!1,s=!1,c=-1e9,l=[];for(;;){let u=i==e.length?1e9:o?e[i].to:e[i].from,d=a==t.length?1e9:s?t[a].to:t[a].from;if(o!=s){let e=Math.max(c,n),t=Math.min(u,d,r);enew y(e.from+r,e.to+r)),s,c);for(let t=0,r=s;;t++){let s=t==o.length,l=s?c:o[t].from;if(l>r&&n.push(new De(r,l,i.tree,-e,a.from>=r||a.openStart,a.to<=l||a.openEnd)),s)break;r=o[t].to}}else n.push(new De(s,c,i.tree,-e,a.from>=e||a.openStart,a.to<=o||a.openEnd))}return n}var de,fe,y,b,pe,me,x,he,ge,_e,S,C,ve,ye,be,w,xe,Se,Ce,we,Te,Ee,De,Oe,ke,Ae,je,Me,Ne,Pe,Fe,Ie=e((()=>{de=1024,fe=0,y=class{constructor(e,t){this.from=e,this.to=t}},b=class{add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=x.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}constructor(e={}){this.id=fe++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)})}},b.closedBy=new b({deserialize:e=>e.split(` `)}),b.openedBy=new b({deserialize:e=>e.split(` `)}),b.group=new b({deserialize:e=>e.split(` `)}),b.isolate=new b({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),b.contextHash=new b({perNode:!0}),b.lookAhead=new b({perNode:!0}),b.mounted=new b({perNode:!0}),pe=class{static get(e){return e&&e.props&&e.props[b.mounted.id]}constructor(e,t,n){this.tree=e,this.overlay=t,this.parser=n}},me=Object.create(null),x=class e{static define(t){let n=t.props&&t.props.length?Object.create(null):me,r=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e==`string`){if(this.name==e)return!0;let t=this.prop(b.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(b.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}},x.none=new x(``,Object.create(null),0,8),he=class e{extend(...t){let n=[];for(let e of this.types){let r=null;for(let n of t){let t=n(e);t&&(r||=Object.assign({},e.props),r[t[0].id]=t[1])}n.push(r?new x(e.name,r,e.id,e.flags):e)}return new e(n)}constructor(e){this.types=e;for(let t=0;t0;for(let e=this.cursor(a|S.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(t={}){return this.children.length<=8?this:re(x.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(x.none,t,n,r)))}static build(e){return te(e)}constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}},C.empty=new C(x.none,[],[],0),ve=class e{get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new e(this.buffer,this.index)}constructor(e,t){this.buffer=e,this.index=t}},ye=class e{get type(){return x.none}toString(){let e=[];for(let t=0;t0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from;if(f(i,r,u,u+l.length)){if(l instanceof ye){if(a&S.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new Se(new xe(o,l,t,u),null,e)}else if(a&S.IncludeAnonymous||!l.type.isAnonymous||ee(l)){let s;if(!(a&S.IgnoreMounts)&&(s=pe.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&S.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i)}}}if(a&S.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(t,n,r=0){let i;if(!(r&S.IgnoreOverlays)&&(i=pe.get(this._tree))&&i.overlay){let r=t-this.from;for(let{from:t,to:a}of i.overlay)if((n>0?t<=r:t=r:a>r))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}},xe=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},Se=class e extends be{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(t,n,r=0){if(r&S.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new C(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}},Ce=class{get next(){return g(this.heads)}constructor(e,t){this.heads=e,this.node=t}},we=class{get name(){return this.type.name}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof w?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&S.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&S.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&S.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&S.IncludeAnonymous||e instanceof ye||!e.type.isAnonymous||ee(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e=0;i--){if(i<0)return h(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof w)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}},Te=new WeakMap,Ee=class{setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof Se?this.setBuffer(e.context.buffer,e.index,t):e instanceof w&&this.map.set(e.tree,t)}get(e){return e instanceof Se?this.getBuffer(e.context.buffer,e.index):e instanceof w?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}constructor(){this.map=new WeakMap}},De=class e{get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new e(0,t.length,t,0,!1,r)];for(let e of n)e.to>t.length&&i.push(e);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let s=0,c=0,l=0;;s++){let u=s=r)for(;o&&o.from=n.from||d<=n.to||l){let t=Math.max(n.from,c)-l,r=Math.min(n.to,d)-l;n=t>=r?null:new e(t,r,n.tree,n.offset+l,s>0,!!u)}if(n&&i.push(n),o.to>d)break;o=anew y(e.from,e.to)):[new y(0,0)]:[new y(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}},ke=class{get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}constructor(e){this.string=e}},Ae=class{constructor(e,t,n,r,i){this.parser=e,this.parse=t,this.overlay=n,this.target=r,this.from=i}},je=class{constructor(e,t,n,r,i,a,o){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=i,this.target=a,this.prev=o,this.depth=0,this.ranges=[]}},Me=new b({perNode:!0}),Ne=class{advance(){if(this.baseParse){let e=this.baseParse.advance();if(!e)return null;if(this.baseParse=null,this.baseTree=e,this.startInner(),this.stoppedAt!=null)for(let e of this.inner)e.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let e=this.baseTree;return this.stoppedAt!=null&&(e=new C(e.type,e.children,e.positions,e.length,e.propValues.concat([[Me,this.stoppedAt]]))),e}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[b.mounted.id]=new pe(t,e.overlay,e.parser),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t=this.stoppedAt)o=!1;else if(e.hasNode(r)){if(t){let e=t.mounts.find(e=>e.frag.from<=r.from&&e.frag.to>=r.to&&e.mount.overlay);if(e)for(let n of e.mount.overlay){let i=n.from+e.pos,a=n.to+e.pos;i>=r.from&&a<=r.to&&!t.ranges.some(e=>e.fromi)&&t.ranges.push({from:i,to:a})}}o=!1}else if(n&&(a=ae(n.ranges,r.from,r.to)))o=a!=2;else if(!r.type.isAnonymous&&(i=this.nest(r,this.input))&&(r.fromnew y(e.from-r.from,e.to-r.from)):null,r.tree,e.length?e[0].from:r.from)),i.overlay?e.length&&(n={ranges:e,depth:0,prev:n}):o=!1}}else if(t&&(s=t.predicate(r))&&(s===!0&&(s=new y(r.from,r.to)),s.from=0&&t.ranges[e].to==s.from?t.ranges[e]={from:t.ranges[e].from,to:s.to}:t.ranges.push(s)}if(o&&r.firstChild())t&&t.depth++,n&&n.depth++;else for(;!r.nextSibling();){if(!r.parent())break scan;if(t&&!--t.depth){let e=ce(this.ranges,t.ranges);e.length&&(v(e),this.inner.splice(t.index,0,new Ae(t.parser,t.parser.startParse(this.input,ue(t.mounts,e),e),t.ranges.map(e=>new y(e.from-t.start,e.to-t.start)),t.target,e[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}constructor(e,t,n,r,i){this.nest=t,this.input=n,this.fragments=r,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}},Pe=class{moveTo(e){let{cursor:t}=this,n=e-this.offset;for(;!this.done&&t.from=e&&t.enter(n,1,S.IgnoreOverlays|S.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof C)t=t.children[0];else break}return!1}constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(S.IncludeAnonymous|S.IgnoreMounts)}},Fe=class{hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=e.tree.prop(Me)??e.to,this.inner=new Pe(e.tree,-e.offset)}}findMounts(e,t){let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let e=this.inner.cursor.node;e;e=e.parent){let r=e.tree?.prop(b.mounted);if(r&&r.parser==t)for(let t=this.fragI;t=e.to)break;i.tree==this.curFrag.tree&&n.push({frag:i,pos:e.from-i.offset,mount:r})}}}return n}constructor(e){if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let t=this.curFrag=e[0];this.curTo=t.tree.prop(Me)??t.to,this.inner=new Pe(t.tree,-t.offset)}else this.curFrag=this.inner=null}}}));function Le(e,t=Uint16Array){if(typeof e!=`string`)return e;let n=null;for(let r=0,i=0;r=92&&t--,t>=34&&t--;let i=t-32;if(i>=46&&(i-=46,n=!0),a+=i,n)break;a*=46}n?n[i++]=a:n=new t(a)}return n}function Re(e,t,n,r,i,a){let o=0,s=1<0){let n=e[r];if(c.allows(n)&&(t.token.value==-1||t.token.value==n||Be(n,t.token.value,i,a))){t.acceptToken(n);break}}let r=t.next,l=0,u=e[o+2];if(t.next<0&&u>l&&e[n+u*3-3]==65535&&e[n+u*3-3]==65535){o=e[n+u*3-1];continue scan}for(;l>1,a=n+i+(i<<1),s=e[a],c=e[a+1]||65536;if(r=c)l=i+1;else{o=e[a+2],t.advance();continue scan}}break}}function ze(e,t,n){for(let r=t,i;(i=e[r])!=65535;r++)if(i==n)return r-t;return-1}function Be(e,t,n,r){let i=ze(n,r,t);return i<0||ze(n,r,e)t)&&!r.type.isError)return n<0?Math.max(0,Math.min(r.to-1,t-25)):Math.min(e.length,Math.max(r.from+1,t+25));if(n<0?r.prevSibling():r.nextSibling())break;if(!r.parent())return n<0?0:e.length}}function He(e,t){for(let n=0;ne)&&n.p.parser.stateFlag(n.state,2)&&(!t||t.scoree.external(n,r)<<1|t}return e.get}var Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,nt,T,rt,it,at,ot,st,ct,lt,ut,dt,ft,pt=e((()=>{Ie(),Ke=class e{toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?`!`+this.score:``}`}static start(t,n,r=0){let i=t.parser.context;return new e(t,[],n,r,r,0,[],0,i?new qe(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){let t=e>>19,n=e&65535,{parser:r}=this.p,i=r.dynamicPrecedence(n);if(i&&(this.score+=i),t==0){this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n=2e3&&!this.p.parser.nodeSet.types[n]?.isAnonymous&&(o==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=s):this.p.lastBigReductionSizea;)this.stack.pop();this.reduceContext(n,o)}storeNode(e,t,n,r=4,i=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]0&&e.buffer[r-4]==0&&e.buffer[r-1]>-1){if(t==n)return;if(e.buffer[r-2]>=t){e.buffer[r-2]=n;return}}}if(!i||this.pos==n)this.buffer.push(e,t,n,r);else{let i=this.buffer.length;if(i>0&&this.buffer[i-4]!=0)for(;i>0&&this.buffer[i-2]>n;)this.buffer[i]=this.buffer[i-4],this.buffer[i+1]=this.buffer[i-3],this.buffer[i+2]=this.buffer[i-2],this.buffer[i+3]=this.buffer[i-1],i-=4,r>4&&(r-=4);this.buffer[i]=e,this.buffer[i+1]=t,this.buffer[i+2]=n,this.buffer[i+3]=r}}shift(e,t,n){let r=this.pos;if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=n,this.shiftContext(t,r),t<=this.p.parser.maxNode&&this.buffer.push(t,r,n,4);else{let i=e,{parser:a}=this.p;(n>this.pos||t<=a.maxNode)&&(this.pos=n,a.stateFlag(i,1)||(this.reducePos=n)),this.pushState(i,r),this.shiftContext(t,r),t<=a.maxNode&&this.buffer.push(t,r,n,4)}}apply(e,t,n){e&65536?this.reduce(e):this.shift(e,t,n)}useNode(e,t){let n=this.p.reused.length-1;(n<0||this.p.reused[n]!=e)&&(this.p.reused.push(e),n++);let r=this.pos;this.reducePos=this.pos=r+e.length,this.pushState(t,r),this.buffer.push(n,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let t=this,n=t.buffer.length;for(;n>0&&t.buffer[n-2]>t.reducePos;)n-=4;let r=t.buffer.slice(n),i=t.bufferBase+n;for(;t&&i==t.bufferBase;)t=t.parent;return new e(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,r,i,this.curContext,this.lookAhead,t)}recoverByDelete(e,t){let n=e<=this.p.parser.maxNode;n&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,n?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Ye(this);;){let n=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(n==0)return!1;if(!(n&65536))return!0;t.reduce(n)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,i;rt&1&&e==r)||n.push(t[e],r)}t=n}let n=[];for(let e=0;e>19,r=t&65535,i=this.stack.length-n*3;if(i<0||e.getGoto(this.stack[i],r,!1)<0){let e=this.findForcedReduction();if(e==null)return!1;t=e}this.storeNode(0,this.reducePos,this.reducePos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],n=(r,i)=>{if(!t.includes(r))return t.push(r),e.allActions(r,t=>{if(!(t&393216))if(t&65536){let n=(t>>19)-i;if(n>1){let r=t&65535,i=this.stack.length-n*3;if(i>=0&&e.getGoto(this.stack[i],r,!1)>=0)return n<<19|65536|r}}else{let e=n(t,i+1);if(e!=null)return e}})};return n(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;tthis.lookAhead&&(this.emitLookAhead(),this.lookAhead=e)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}constructor(e,t,n,r,i,a,o,s,c,l=0,u){this.p=e,this.stack=t,this.state=n,this.reducePos=r,this.pos=i,this.score=a,this.buffer=o,this.bufferBase=s,this.curContext=c,this.lookAhead=l,this.parent=u}},qe=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},(function(e){e[e.Insert=200]=`Insert`,e[e.Delete=190]=`Delete`,e[e.Reduce=100]=`Reduce`,e[e.MaxNext=4]=`MaxNext`,e[e.MaxInsertStackDepth=300]=`MaxInsertStackDepth`,e[e.DampenInsertStackDepth=120]=`DampenInsertStackDepth`,e[e.MinBigReduction=2e3]=`MinBigReduction`})(Je||={}),Ye=class{reduce(e){let t=e&65535,n=e>>19;n==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(n-1)*3,this.state=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0)}constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}},Xe=class e{static create(t,n=t.bufferBase+t.buffer.length){return new e(t,n,n-t.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new e(this.stack,this.pos,this.index)}constructor(e,t,n){this.stack=e,this.pos=t,this.index=n,this.buffer=e.buffer,this.index==0&&this.maybeNext()}},Ze=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},Qe=new Ze,$e=class{resolveOffset(e,t){let n=this.range,r=this.rangeIndex,i=this.pos+e;for(;in.to:i>=n.to;){if(r==this.ranges.length-1)return null;let e=this.ranges[++r];i+=e.from-n.to,n=e}return i}clipPos(e){if(e>=this.range.from&&ee)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,n,r;if(t>=0&&t=this.chunk2Pos&&nt.to&&(this.chunk2=this.chunk2.slice(0,t.to-n)),r=this.chunk2.charCodeAt(0)}}return n>=this.token.lookAhead&&(this.token.lookAhead=n+1),r}acceptToken(e,t=0){let n=t?this.resolveOffset(t,-1):this.pos;if(n==null||n=this.chunk2Pos&&this.posthis.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk=``,this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=Qe,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let n=``;for(let r of this.ranges){if(r.from>=t)break;r.to>e&&(n+=this.input.read(Math.max(r.from,e),Math.min(r.to,t)))}return n}constructor(e,t){this.input=e,this.ranges=t,this.chunk=``,this.chunkOff=0,this.chunk2=``,this.chunk2Pos=0,this.next=-1,this.token=Qe,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}},et=class{token(e,t){let{parser:n}=t.p;Re(this.data,e,t,this.id,n.data,n.tokenPrecTable)}constructor(e,t){this.data=e,this.id=t}},et.prototype.contextual=et.prototype.fallback=et.prototype.extend=!1,tt=class{token(e,t){let n=e.pos,r=0;for(;Re(this.data,e,t,0,this.data,this.precTable),!(e.token.value>-1);){if(this.elseToken==null)return;if(e.next<0)break;e.advance(),e.reset(e.pos,e.token),r++}r&&(e.reset(n,e.token),e.acceptToken(this.elseToken,r))}constructor(e,t,n){this.precTable=t,this.elseToken=n,this.data=typeof e==`string`?Le(e):e}},tt.prototype.contextual=et.prototype.fallback=et.prototype.extend=!1,nt=class{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}},T=typeof process<`u`&&process.env&&/\bparse\b/.test(process.env.LOG),rt=null,(function(e){e[e.Margin=25]=`Margin`})(it||={}),at=class{nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Ve(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Ve(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(ee)return this.nextStart=a,null;if(i instanceof C){if(a==e){if(a=Math.max(this.safeFrom,e)&&(this.trees.push(i),this.start.push(a),this.index.push(0))}else this.index[t]++,this.nextStart=a+i.length}}constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}},ot=class{getActions(e){let t=0,n=null,{parser:r}=e.p,{tokenizers:i}=r,a=r.stateSlot(e.state,3),o=e.curContext?e.curContext.hash:0,s=0;for(let r=0;rl.end+25&&(s=Math.max(l.lookAhead,s)),l.value!=0)){let r=t;if(l.extended>-1&&(t=this.addActions(e,l.extended,l.end,t)),t=this.addActions(e,l.value,l.end,t),!c.extend&&(n=l,t>r))break}}for(;this.actions.length>t;)this.actions.pop();return s&&e.setLookAhead(s),!n&&e.pos==this.stream.end&&(n=new Ze,n.value=e.p.parser.eofTerm,n.start=n.end=e.pos,t=this.addActions(e,n.value,n.end,t)),this.mainToken=n,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Ze,{pos:n,p:r}=e;return t.start=n,t.end=Math.min(n+1,r.stream.end),t.value=n==r.stream.end?r.parser.eofTerm:0,t}updateCachedToken(e,t,n){let r=this.stream.clipPos(n.pos);if(t.token(this.stream.reset(r,e),n),e.value>-1){let{parser:t}=n.p;for(let r=0;r=0&&n.p.parser.dialect.allows(i>>1)){i&1?e.extended=i>>1:e.value=i>>1;break}}}else e.value=0,e.end=this.stream.clipPos(r+1)}putAction(e,t,n,r){for(let t=0;tnew Ze)}},(function(e){e[e.Distance=5]=`Distance`,e[e.MaxRemainingPerStep=3]=`MaxRemainingPerStep`,e[e.MinBufferLengthPrune=500]=`MinBufferLengthPrune`,e[e.ForceReduceLimit=10]=`ForceReduceLimit`,e[e.CutDepth=15e3]=`CutDepth`,e[e.CutTo=9e3]=`CutTo`,e[e.MaxLeftAssociativeReductionCount=300]=`MaxLeftAssociativeReductionCount`,e[e.MaxStackCount=12]=`MaxStackCount`})(st||={}),ct=class{get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,n=this.stacks=[],r,i;if(this.bigReductionCount>300&&e.length==1){let[t]=e;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let a=0;at)n.push(o);else if(this.advanceStack(o,n,e))continue;else{r||(r=[],i=[]),r.push(o);let e=this.tokens.getMainToken(o);i.push(e.value,e.end)}break}}if(!n.length){let e=r&&We(r);if(e)return this.stackToTree(e);if(this.parser.strict)throw T&&r&&console.log(`Stuck with token `+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):`none`)),SyntaxError(`No parse at `+t);this.recovering||=5}if(this.recovering&&r){let e=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,i,n);if(e)return this.stackToTree(e.forceAll())}if(this.recovering){let e=this.recovering==1?1:this.recovering*3;if(n.length>e)for(n.sort((e,t)=>t.score-e.score);n.length>e;)n.pop();n.some(e=>e.reducePos>t)&&this.recovering--}else if(n.length>1){outer:for(let e=0;e500&&i.buffer.length>500)if((t.score-i.score||t.buffer.length-i.buffer.length)>0)n.splice(r--,1);else{n.splice(e--,1);continue outer}}}n.length>12&&n.splice(12,n.length-12)}this.minStackPos=n[0].pos;for(let e=1;e `:``;if(this.stoppedAt!=null&&r>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let t=e.curContext&&e.curContext.tracker.strict,n=t?e.curContext.hash:0;for(let o=this.fragments.nodeAt(r);o;){let r=this.parser.nodeSet.types[o.type.id]==o.type?i.getGoto(e.state,o.type.id):-1;if(r>-1&&o.length&&(!t||(o.prop(b.contextHash)||0)==n))return e.useNode(o,r),T&&console.log(a+this.stackID(e)+` (via reuse of ${i.getName(o.type.id)})`),!0;if(!(o instanceof C)||o.children.length==0||o.positions[0]>0)break;let s=o.children[0];if(s instanceof C&&o.positions[0]==0)o=s;else break}}let o=i.stateSlot(e.state,4);if(o>0)return e.reduce(o),T&&console.log(a+this.stackID(e)+` (via always-reduce ${i.getName(o&65535)})`),!0;if(e.stack.length>=15e3)for(;e.stack.length>9e3&&e.forceReduce(););let s=this.tokens.getActions(e);for(let o=0;or?t.push(f):n.push(f)}return!1}advanceFully(e,t){let n=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>n)return He(e,t),!0}}runRecovery(e,t,n){let r=null,i=!1;for(let a=0;a `:``;if(o.deadEnd&&(i||(i=!0,o.restart(),T&&console.log(l+this.stackID(o)+` (restarted)`),this.advanceFully(o,n))))continue;let u=o.split(),d=l;for(let e=0;u.forceReduce()&&e<10&&(T&&console.log(d+this.stackID(u)+` (via force-reduce)`),!this.advanceFully(u,n));e++)T&&(d=this.stackID(u)+` -> `);for(let e of o.recoverByInsert(s))T&&console.log(l+this.stackID(e)+` (via recover-insert)`),this.advanceFully(e,n);this.stream.end>o.pos?(c==o.pos&&(c++,s=0),o.recoverByDelete(s,c),T&&console.log(l+this.stackID(o)+` (via recover-delete ${this.parser.getName(s)})`),He(o,n)):(!r||r.scoree.bufferLength*4?new at(n,e.nodeSet):null}},lt=class{allows(e){return!this.disabled||this.disabled[e]==0}constructor(e,t,n){this.source=e,this.flags=t,this.disabled=n}},ut=e=>e,dt=class{constructor(e){this.start=e.start,this.shift=e.shift||ut,this.reduce=e.reduce||ut,this.reuse=e.reuse||ut,this.hash=e.hash||(()=>0),this.strict=e.strict!==!1}},ft=class e extends Oe{createParse(e,t,n){let r=new ct(this,e,t,n);for(let i of this.wrappers)r=i(r,e,t,n);return r}getGoto(e,t,n=!1){let r=this.goto;if(t>=r[0])return-1;for(let i=r[t+1];;){let t=r[i++],a=t&1,o=r[i++];if(a&&n)return o;for(let n=i+(t>>1);i0}validAction(e,t){return!!this.allActions(e,e=>e==t?!0:null)}allActions(e,t){let n=this.stateSlot(e,4),r=n?t(n):void 0;for(let n=this.stateSlot(e,1);r==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Ue(this.data,n+2);else break;r=t(Ue(this.data,n+1))}return r}nextStates(e){let t=[];for(let n=this.stateSlot(e,1);;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Ue(this.data,n+2);else break;if(!(this.data[n+2]&1)){let e=this.data[n+1];t.some((t,n)=>n&1&&t==e)||t.push(this.data[n],e)}}return t}configure(t){let n=Object.assign(Object.create(e.prototype),this);if(t.props&&(n.nodeSet=this.nodeSet.extend(...t.props)),t.top){let e=this.topRules[t.top];if(!e)throw RangeError(`Invalid top rule name ${t.top}`);n.top=e}return t.tokenizers&&(n.tokenizers=this.tokenizers.map(e=>{let n=t.tokenizers.find(t=>t.from==e);return n?n.to:e})),t.specializers&&(n.specializers=this.specializers.slice(),n.specializerSpecs=this.specializerSpecs.map((e,r)=>{let i=t.specializers.find(t=>t.from==e.external);if(!i)return e;let a=Object.assign(Object.assign({},e),{external:i.to});return n.specializers[r]=Ge(a),a})),t.contextTracker&&(n.context=t.contextTracker),t.dialect&&(n.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(n.strict=t.strict),t.wrap&&(n.wrappers=n.wrappers.concat(t.wrap)),t.bufferLength!=null&&(n.bufferLength=t.bufferLength),n}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),n=t.map(()=>!1);if(e)for(let r of e.split(` `)){let e=t.indexOf(r);e>=0&&(n[e]=!0)}let r=null;for(let e=0;ee.topRules[t][1]),r=[];for(let e=0;e=0)i(r,e,t[n++]);else{let a=t[n+-r];for(let o=-r;o>0;o--)i(t[n++],e,a);n++}}}this.nodeSet=new he(t.map((t,i)=>x.define({name:i>=this.minRepeatTerm?void 0:t,id:i,props:r[i],top:n.indexOf(i)>-1,error:i==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(i)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=de;let a=Le(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let e=0;etypeof e==`number`?new et(a,e):e),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}}}));function mt(e,t){return e.length==t.length&&e.every((e,n)=>e==t[n])}function ht(e){let t=[[]];for(let n=0;nt.length-e.length)}function gt(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(` `))if(e){let n=[],i=2,a=e;for(let t=0;;){if(a==`...`&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!r)throw RangeError(`Invalid path: `+e);if(n.push(r[0]==`*`?``:r[0][0]==`"`?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let o=e[t++];if(t==e.length&&o==`!`){i=0;break}if(o!=`/`)throw RangeError(`Invalid path: `+e);a=e.slice(t)}let o=n.length-1,s=n[o];if(!s)throw RangeError(`Invalid path: `+e);t[s]=new Et(r,i,o>0?n.slice(0,o):null).sort(t[s])}}return Tt.add(t)}function _t(e,t){let n=Object.create(null);for(let t of e)if(!Array.isArray(t.tag))n[t.tag.id]=t.class;else for(let e of t.tag)n[e.id]=t.class;let{scope:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+` `+r:r;break}}return t},scope:r}}function vt(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+` `+e:e)}return n}function yt(e,t,n,r=0,i=e.length){let a=new Dt(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,``,a.highlighters),a.flush(i)}function bt(e){let t=e.type.prop(Tt);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}var xt,St,Ct,wt,Tt,Et,Dt,E,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt,Rt,zt,Bt,Vt,D,Ht=e((()=>{Ie(),xt=0,St=class e{static define(t){if(t?.base)throw Error(`Can not derive from a modified tag`);let n=new e([],null,[]);if(n.set.push(n),t)for(let e of t.set)n.set.push(e);return n}static defineModifier(){let e=new wt;return t=>t.modified.indexOf(e)>-1?t:wt.get(t.base||t,t.modified.concat(e).sort((e,t)=>e.id-t.id))}constructor(e,t,n){this.set=e,this.base=t,this.modified=n,this.id=xt++}},Ct=0,wt=class e{static get(t,n){if(!n.length)return t;let r=n[0].instances.find(e=>e.base==t&&mt(n,e.modified));if(r)return r;let i=[],a=new St(i,t,n);for(let e of n)e.instances.push(a);let o=ht(n);for(let n of t.set)if(!n.modified.length)for(let t of o)i.push(e.get(n,t));return a}constructor(){this.instances=[],this.id=Ct++}},Tt=new b,Et=class{get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depththis.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,i){let{type:a,from:o,to:s}=e;if(o>=n||s<=t)return;a.isTop&&(i=this.highlighters.filter(e=>!e.scope||e.scope(a)));let c=r,l=bt(e)||Et.empty,u=vt(i,l.tags);if(u&&(c&&(c+=` `),c+=u,l.mode==1&&(r+=(r?` `:``)+u)),this.startSpan(Math.max(t,o),c),l.opaque)return;let d=e.tree&&e.tree.prop(b.mounted);if(d&&d.overlay){let a=e.node.enter(d.overlay[0].from+o,1),l=this.highlighters.filter(e=>!e.scope||e.scope(d.tree.type)),u=e.firstChild();for(let f=0,p=o;;f++){let m=f=h||!e.nextSibling())););if(!m||h>n)break;p=m.to+o,p>t&&(this.highlightRange(a.cursor(),Math.max(t,m.from+o),Math.min(n,p),``,l),this.startSpan(Math.min(n,p),c))}u&&e.parent()}else if(e.firstChild()){d&&(r=``);do{if(e.to<=t)continue;if(e.from>=n)break;this.highlightRange(e,t,n,r,i),this.startSpan(Math.min(n,e.to),c)}while(e.nextSibling());e.parent()}}constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=``}},E=St.define,Ot=E(),kt=E(),At=E(kt),jt=E(kt),Mt=E(),Nt=E(Mt),Pt=E(Mt),Ft=E(),It=E(Ft),Lt=E(),Rt=E(),zt=E(),Bt=E(zt),Vt=E(),D={comment:Ot,lineComment:E(Ot),blockComment:E(Ot),docComment:E(Ot),name:kt,variableName:E(kt),typeName:At,tagName:E(At),propertyName:jt,attributeName:E(jt),className:E(kt),labelName:E(kt),namespace:E(kt),macroName:E(kt),literal:Mt,string:Nt,docString:E(Nt),character:E(Nt),attributeValue:E(Nt),number:Pt,integer:E(Pt),float:E(Pt),bool:E(Mt),regexp:E(Mt),escape:E(Mt),color:E(Mt),url:E(Mt),keyword:Lt,self:E(Lt),null:E(Lt),atom:E(Lt),unit:E(Lt),modifier:E(Lt),operatorKeyword:E(Lt),controlKeyword:E(Lt),definitionKeyword:E(Lt),moduleKeyword:E(Lt),operator:Rt,derefOperator:E(Rt),arithmeticOperator:E(Rt),logicOperator:E(Rt),bitwiseOperator:E(Rt),compareOperator:E(Rt),updateOperator:E(Rt),definitionOperator:E(Rt),typeOperator:E(Rt),controlOperator:E(Rt),punctuation:zt,separator:E(zt),bracket:Bt,angleBracket:E(Bt),squareBracket:E(Bt),paren:E(Bt),brace:E(Bt),content:Ft,heading:It,heading1:E(It),heading2:E(It),heading3:E(It),heading4:E(It),heading5:E(It),heading6:E(It),contentSeparator:E(Ft),list:E(Ft),quote:E(Ft),emphasis:E(Ft),strong:E(Ft),link:E(Ft),monospace:E(Ft),strikethrough:E(Ft),inserted:E(),deleted:E(),changed:E(),invalid:E(),meta:Vt,documentMeta:E(Vt),annotation:E(Vt),processingInstruction:E(Vt),definition:St.defineModifier(),constant:St.defineModifier(),function:St.defineModifier(),standard:St.defineModifier(),local:St.defineModifier(),special:St.defineModifier()},_t([{tag:D.link,class:`tok-link`},{tag:D.heading,class:`tok-heading`},{tag:D.emphasis,class:`tok-emphasis`},{tag:D.strong,class:`tok-strong`},{tag:D.keyword,class:`tok-keyword`},{tag:D.atom,class:`tok-atom`},{tag:D.bool,class:`tok-bool`},{tag:D.url,class:`tok-url`},{tag:D.labelName,class:`tok-labelName`},{tag:D.inserted,class:`tok-inserted`},{tag:D.deleted,class:`tok-deleted`},{tag:D.literal,class:`tok-literal`},{tag:D.string,class:`tok-string`},{tag:D.number,class:`tok-number`},{tag:[D.regexp,D.escape,D.special(D.string)],class:`tok-string2`},{tag:D.variableName,class:`tok-variableName`},{tag:D.local(D.variableName),class:`tok-variableName tok-local`},{tag:D.definition(D.variableName),class:`tok-variableName tok-definition`},{tag:D.special(D.variableName),class:`tok-variableName2`},{tag:D.definition(D.propertyName),class:`tok-propertyName tok-definition`},{tag:D.typeName,class:`tok-typeName`},{tag:D.namespace,class:`tok-namespace`},{tag:D.className,class:`tok-className`},{tag:D.macroName,class:`tok-macroName`},{tag:D.propertyName,class:`tok-propertyName`},{tag:D.operator,class:`tok-operator`},{tag:D.comment,class:`tok-comment`},{tag:D.meta,class:`tok-meta`},{tag:D.invalid,class:`tok-invalid`},{tag:D.punctuation,class:`tok-punctuation`}])}));function Ut(e){if(e<768)return!1;for(let t=0,n=Un.length;;){let r=t+n>>1;if(e=Wn[r])t=r+1;else return!0;if(t==n)return!1}}function Wt(e){return e>=127462&&e<=127487}function Gt(e,t,n=!0,r=!0){return(n?Kt:qt)(e,t,r)}function Kt(e,t,n){if(t==e.length)return t;t&&Yt(e.charCodeAt(t))&&Xt(e.charCodeAt(t-1))&&t--;let r=Jt(e,t);for(t+=Zt(r);t=0&&Wt(Jt(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function qt(e,t,n){for(;t>0;){let r=Kt(e,t-2,n);if(r=56320&&e<57344}function Xt(e){return e>=55296&&e<56320}function Zt(e){return e<65536?1:2}function Qt(e){let t=-1;for(let n of e)t+=n.length+1;return t}function $t(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a=n&&(c>r&&(s=s.slice(0,r-i)),i=56320&&e<57344}function an(e){return e>=55296&&e<56320}function on(e,t){let n=e.charCodeAt(t);if(!an(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return rn(r)?(n-55296<<10)+(r-56320)+65536:n}function sn(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function cn(e){return e<65536?1:2}function O(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function ln(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function dn(e,t,n,r=!1){let i=[],a=r?[]:null,o=new $n(e),s=new $n(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);O(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len=0&&e=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.lent||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}function pn(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}function mn(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}function hn(e,t,n){if(e.length!=t.length)return!1;for(let r=0;re[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;tnew sr(t,e)}function yn(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof lr&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof lr){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof sr)a(e.inner,e.prec);else if(e instanceof ir)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof nr)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,ar.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,ar.default),r.reduce((e,t)=>e.concat(t))}function bn(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function xn(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}function Sn(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r=e[r]))a=e[r++],o=e[r++];else if(i=0;n--){let i=r[n](e);e=i instanceof I?i:Array.isArray(i)&&i.length==1&&i[0]instanceof I?i[0]:Tn(t,On(i),!1)}return e}function Dn(e){let t=e.startState,n=t.facet(gr),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Cn(r,wn(t,a,e.changes.newLength),!0))}return r==e?e:I.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}function On(e){return e==null?xr:Array.isArray(e)?e:[e]}function kn(e){if(wr)return wr.test(e);for(let t=0;t`€`&&(n.toUpperCase()!=n.toLowerCase()||Cr.test(n)))return!0}return!1}function An(e){return t=>{if(!/\S/.test(t))return Sr.Space;if(kn(t))return Sr.Word;for(let n=0;n-1)return Sr.Word;return Sr.Other}}function jn(e,t,n={}){let r={};for(let t of e)for(let e of Object.keys(t)){let i=t[e],a=r[e];if(a===void 0)r[e]=i;else if(!(a===i||i===void 0))if(Object.hasOwnProperty.call(n,e))r[e]=n[e](a,i);else throw Error(`Config merge conflict for field `+e)}for(let e in t)r[e]===void 0&&(r[e]=t[e]);return r}function Mn(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}function Nn(e){if(e.length>1)for(let t=e[0],n=1;n0)return e.slice().sort(Mn);t=r}return e}function Pn(e,t,n){let r=new Map;for(let t of e)for(let e=0;e=e.length)break;let i=e[r];if(r+1=0&&(i=e[r+1],r++),n.compare(i)<0)break;e[r]=n,e[t]=i,t=r}}function In(e,t,n,r,i,a){e.goto(t),n.goto(r);let o=r+i,s=r,c=r-t;for(;;){let t=e.to+c-n.to,r=t||e.endSide-n.endSide,i=r<0?e.to+c:n.to,l=Math.min(i,o);if(e.point||n.point?e.point&&n.point&&(e.point==n.point||e.point.eq(n.point))&&Ln(e.activeForPoint(e.to),n.activeForPoint(n.to))||a.comparePoint(s,l,e.point,n.point):l>s&&!Ln(e.active,n.active)&&a.compareRange(s,l,e.active,n.active),i>o)break;(t||e.openEnd!=n.openEnd)&&a.boundChange&&a.boundChange(i),s=i,r<=0&&e.next(),r>=0&&n.next()}}function Ln(e,t){if(e.length!=t.length)return!1;for(let n=0;n=t;n--)e[n+1]=e[n];e[t]=n}function Bn(e,t){let n=-1,r=1e9;for(let i=0;i=t)return r;if(r==e.length)break;i+=e.charCodeAt(r)==9?n-i%n:1,r=nn(e,r)}return r===!0?-1:e.length}var Un,Wn,Gn,k,A,Kn,qn,Jn,Yn,Xn,Zn,j,Qn,M,$n,er,N,tr,P,nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,F,I,xr,Sr,Cr,wr,L,Tr,Er,Dr,R,Or,kr,Ar,jr,Mr=e((()=>{Un=[],Wn=[],(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;tthis.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=tn(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Kn.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=tn(this,e,t);let n=[];return this.decompose(e,t,n,0),Kn.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new qn(this),i=new qn(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new qn(this,e)}iterRange(e,t=this.length){return new Jn(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Yn(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new A(t):Kn.from(A.split(t,[]))}constructor(){}},A=class e extends k{get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new Xn(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(en(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=$t(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=tn(this,t,n);let i=$t(this.text,$t(r.text,en(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Kn.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=` `){[e,t]=tn(this,e,t);let r=``;for(let i=0,a=0;i<=t&&ae&&a&&(r+=n),ei&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}constructor(e,t=Qt(e)){super(),this.text=e,this.length=t}},Kn=class e extends k{lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i=a){let i=r&((a<=e?1:0)|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=tn(this,t,n),r.lines=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=` `){[e,t]=tn(this,e,t);let r=``;for(let i=0,a=0;ie&&i&&(r+=n),ea&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new A(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof A&&c&&(n=u[u.length-1])instanceof A&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new A(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}},k.empty=new A([``],0),qn=class{nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof A?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=` `,this;e--}else if(r instanceof A){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof A?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof A?e.text.length:e.children.length)<<1]}},Jn=class{nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new qn(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}},Yn=class{next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}},typeof Symbol<`u`&&(k.prototype[Symbol.iterator]=function(){return this.iter()},qn.prototype[Symbol.iterator]=Jn.prototype[Symbol.iterator]=Yn.prototype[Symbol.iterator]=function(){return this}),Xn=class{get length(){return this.to-this.from}constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}},Zn=/\r\n?|\n/,j=function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e}(j||={}),Qn=class e{get length(){let e=0;for(let t=0;te)return i+(e-r);i+=o}else{if(n!=j.Simple&&c>=e&&(n==j.TrackDel&&re||n==j.TrackBefore&&re))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n=0&&r<=t&&o>=e)return rt?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}constructor(e){this.sections=e}},M=class e extends Qn{apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return un(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return dn(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length0&&ln(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;os||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?k.of(l.split(r||Zn)):l:k.empty,d=u.length;if(e==s&&d==0)return;eo&&O(i,e-o,-1),O(i,s-e,d),ln(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;et&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length>1;return t>=e.length?k.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?k.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}constructor(e){this.set=e,this.i=0,this.next()}},er=class e{get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return N.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return N.range(this.anchor,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return N.range(e.anchor,e.head)}static create(t,n,r){return new e(t,n,r)}constructor(e,t,n){this.from=e,this.to=t,this.flags=n}},N=class e{map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;ne.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>er.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;ie?8:0)|i)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;ri.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}constructor(e,t){this.ranges=e,this.mainIndex=t}},tr=0,P=class e{get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:mn),!!t.static,t.enables)}of(e){return new nr([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new nr(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new nr(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=tr++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}},nr=class{dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||gn(e,c)){let r=t(e);if(a?!hn(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=xn(o,c);if(this.dependencies.every(t=>t instanceof P?o.facet(t)===e.facet(t):t instanceof ir?o.field(t,!1)==e.field(t,!1):!0)||(a?hn(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=tr++}},rr=P.define({static:!0}),ir=class e{static define(t){let n=new e(tr++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(rr).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(rr),i=n.facet(rr),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,rr.of({field:this,create:e})]}get extension(){return this}constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}},ar={lowest:4,low:3,default:2,high:1,highest:0},or={highest:vn(ar.highest),high:vn(ar.high),default:vn(ar.default),low:vn(ar.low),lowest:vn(ar.lowest)},sr=class{constructor(e,t){this.inner=e,this.prec=t}},cr=class e{of(e){return new lr(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},lr=class{constructor(e,t){this.compartment=e,this.inner=t}},ur=class e{staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of yn(t,n,o))e instanceof ir?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0))if(s[n.id]=c.length<<1|1,mn(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>_n(e,n,t))}}return new e(t,o,l.map(e=>e(s)),s,c,a)}constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.lengthe.some(e=>e),static:!0}),pr=P.define({combine:e=>e.length?e[0]:void 0,static:!0}),mr=P.define(),hr=P.define(),gr=P.define(),_r=P.define({combine:e=>e.length?e[0]:!1}),vr=class{static define(){return new yr}constructor(e,t){this.type=e,this.value=t}},yr=class{of(e){return new vr(this,e)}},br=class{of(e){return new F(this,e)}constructor(e){this.map=e}},F=class e{map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new br(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}constructor(e,t){this.type=e,this.value=t}},F.reconfigure=F.define(),F.appendConfig=F.define(),I=class e{static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&pn(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}},I.time=vr.define(),I.userEvent=vr.define(),I.addToHistory=vr.define(),I.remote=vr.define(),xr=[],Sr=function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e}(Sr||={}),Cr=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;try{wr=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}L=class e{field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return bn(this,n),xn(this,n)}update(...e){return Tn(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(cr.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(F.reconfigure)?(n=null,r=e.value):e.is(F.appendConfig)&&(n=null,r=On(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=ur.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(fr)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:N.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=On(n.effects);for(let n=1;nn.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:N.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=ur.resolve(t.extensions||[],new Map),r=t.doc instanceof k?t.doc:k.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||Zn)),i=t.selection?t.selection instanceof N?t.selection:N.single(t.selection.anchor,t.selection.head):N.single(0);return pn(i,r.length),n.staticFacet(fr)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||` `}get readOnly(){return this.facet(_r)}phrase(t,...n){for(let n of this.facet(e.phrases))if(Object.prototype.hasOwnProperty.call(n,t)){t=n[t];break}return n.length&&(t=t.replace(/\$(\$|\d*)/g,(e,t)=>{if(t==`$`)return`$`;let r=+(t||1);return!r||r>n.length?e:n[r-1]})),t}languageDataAt(e,t,n=-1){let r=[];for(let i of this.facet(dr))for(let a of i(this,t,n))Object.prototype.hasOwnProperty.call(a,e)&&r.push(a[e]);return r}charCategorizer(e){return An(this.languageDataAt(`wordChars`,e).join(``))}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),i=this.charCategorizer(e),a=e-n,o=e-n;for(;a>0;){let e=nn(t,a,!1);if(i(t.slice(e,a))!=Sr.Word)break;a=e}for(;oe.length?e[0]:4}),L.lineSeparator=pr,L.readOnly=_r,L.phrases=P.define({compare(e,t){let n=Object.keys(e),r=Object.keys(t);return n.length==r.length&&n.every(n=>e[n]==t[n])}}),L.languageData=dr,L.changeFilter=mr,L.transactionFilter=hr,L.transactionExtender=gr,cr.reconfigure=F.define(),Tr=class{eq(e){return this==e}range(e,t=e){return Er.create(e,t,this)}},Tr.prototype.startSide=Tr.prototype.endSide=0,Tr.prototype.point=!1,Tr.prototype.mapMode=j.TrackDel,Er=class e{static create(t,n,r){return new e(t,n,r)}constructor(e,t,n){this.from=e,this.to=t,this.value=n}},Dr=class e{get length(){return this.to[this.to.length-1]}findIndex(e,t,n,r=0){let i=n?this.to:this.from;for(let a=r,o=i.length;;){if(a==o)return a;let r=a+o>>1,s=i[r]-e||(n?this.value[r].endSide:this.value[r].startSide)-t;if(r==a)return s>=0?a:o;s>=0?o=r:a=r+1}}between(e,t,n,r){for(let i=this.findIndex(t,-1e9,!0),a=this.findIndex(n,1e9,!1,i);if||d==f&&c.startSide>0&&c.endSide<=0)continue;(f-d||c.endSide-c.startSide)<0||(o<0&&(o=d),c.point&&(s=Math.max(s,f-d)),r.push(c),i.push(d-o),a.push(f-o))}return{mapped:r.length?new e(i,a,r,s):null,pos:o}}constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}},R=class e{static create(t,n,r,i){return new e(t,n,r,i)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(t){let{add:n=[],sort:r=!1,filterFrom:i=0,filterTo:a=this.length}=t,o=t.filter;if(n.length==0&&!o)return this;if(r&&(n=n.slice().sort(Mn)),this.isEmpty)return n.length?e.of(n):this;let s=new kr(this,null,-1).goto(0),c=0,l=[],u=new Or;for(;s.value||c=0){let e=n[c++];u.addInner(e.from,e.to,e.value)||l.push(e)}else s.rangeIndex==1&&s.chunkIndexthis.chunkEnd(s.chunkIndex)||as.to||a=i&&e<=i+a.length&&a.between(i,e-i,t-i,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Ar.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ar.from(e).goto(t)}static compare(e,t,n,r,i=-1){let a=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),o=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),s=Pn(a,o,n),c=new jr(a,s,i),l=new jr(o,s,i);n.iterGaps((e,t,n)=>In(c,e,l,t,n,r)),n.empty&&n.length==0&&In(c,0,l,0,0,r)}static eq(e,t,n=0,r){r??=999999999;let i=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),a=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(i.length!=a.length)return!1;if(!i.length)return!0;let o=Pn(i,a),s=new jr(i,o,0).goto(n),c=new jr(a,o,0).goto(n);for(;;){if(s.to!=c.to||!Ln(s.active,c.active)||s.point&&(!c.point||!s.point.eq(c.point)))return!1;if(s.to>r)return!0;s.next(),c.next()}}static spans(e,t,n,r,i=-1){let a=new jr(e,null,i).goto(t),o=t,s=a.openStart;for(;;){let e=Math.min(a.to,n);if(a.point){let n=a.activeForPoint(a.to),i=a.pointFromo&&(r.span(o,e,a.active,s),s=a.openEnd(e));if(a.to>n)return s+(a.point&&a.to>n?1:0);o=a.to,a.next()}}static of(e,t=!1){let n=new Or;for(let r of e instanceof Er?[e]:t?Nn(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(t){if(!t.length)return e.empty;let n=t[t.length-1];for(let r=t.length-2;r>=0;r--)for(let i=t[r];i!=e.empty;i=i.nextLayer)n=new e(i.chunkPos,i.chunk,n,Math.max(i.maxPoint,n.maxPoint));return n}constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}},R.empty=new R([],[],null,-1),R.empty.nextLayer=R.empty,Or=class e{finishChunk(e){this.chunks.push(new Dr(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}add(t,n,r){this.addInner(t,n,r)||(this.nextLayer||=new e).add(t,n,r)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(R.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=R.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}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}},kr=class{get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=r&&i.push(new kr(a,n,r,e));return i.length==1?i[0]:new e(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)Fn(this.heap,e);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)Fn(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Fn(this.heap,0)}}constructor(e){this.heap=e}},jr=class{goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Rn(this.active,e),Rn(this.activeTo,e),Rn(this.activeRank,e),this.minActive=Bn(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:i}=this.cursor;for(;t0;)t++;zn(this.active,t,n),zn(this.activeTo,t,r),zn(this.activeRank,t,i),e&&zn(e,t,this.cursor.from),this.minActive=Bn(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&Rn(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let e=this.cursor.value;if(!e.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from=0&&n[t]=0&&!(this.activeRank[n]e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}constructor(e,t,n){this.minPoint=n,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=Ar.from(e,t,n)}}}));function Nr(e){var t=!(ko&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||Ao&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Oo:Do)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}function Pr(e){let t;return t=e.nodeType==11?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function Fr(e,t){return t?e==t||e.contains(t.nodeType==1?t:t.parentNode):!1}function Ir(e,t){if(!t.anchorNode)return!1;try{return Fr(e,t.anchorNode)}catch{return!1}}function Lr(e){return e.nodeType==3?Yr(e,0,e.nodeValue.length).getClientRects():e.nodeType==1?e.getClientRects():[]}function Rr(e,t,n,r){return n?Vr(e,t,n,r,-1)||Vr(e,t,n,r,1):!1}function zr(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t}function Br(e){return e.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function Vr(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Hr(e))){if(e.nodeName==`DIV`)return!1;let n=e.parentNode;if(!n||n.nodeType!=1)return!1;t=zr(e)+(i<0?0:1),e=n}else if(e.nodeType==1){if(e=e.childNodes[t+(i<0?-1:0)],e.nodeType==1&&e.contentEditable==`false`)return!1;t=i<0?Hr(e):0}else return!1}}function Hr(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Ur(e,t){let n=t?e.left:e.right;return{left:n,right:n,top:e.top,bottom:e.bottom}}function Wr(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function Gr(e,t){let n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.width-e.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(t.height-e.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function Kr(e,t,r,i,a,o,s,c){let l=e.ownerDocument,u=l.defaultView||n;for(let n=e,d=!1;n&&!d;)if(n.nodeType==1){let e,f=n==l.body,p=1,m=1;if(f)e=Wr(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(n).position)&&(d=!0),n.scrollHeight<=n.clientHeight&&n.scrollWidth<=n.clientWidth){n=n.assignedSlot||n.parentNode;continue}let t=n.getBoundingClientRect();({scaleX:p,scaleY:m}=Gr(n,t)),e={left:t.left,right:t.left+n.clientWidth*p,top:t.top,bottom:t.top+n.clientHeight*m}}let h=0,g=0;if(a==`nearest`)t.top0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+s)):t.bottom>e.bottom&&(g=t.bottom-e.bottom+s,r<0&&t.top-g0&&t.right>e.right+h&&(h=t.right-e.right+o)):t.right>e.right&&(h=t.right-e.right+o,r<0&&t.lefte.bottom||t.lefte.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),n=n.assignedSlot||n.parentNode}else if(n.nodeType==11)n=n.host;else break}function qr(e){let t=e.ownerDocument,n,r;for(let i=e.parentNode;i&&!(i==t.body||n&&r);)if(i.nodeType==1)!r&&i.scrollHeight>i.clientHeight&&(r=i),!n&&i.scrollWidth>i.clientWidth&&(n=i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;return{x:n,y:r}}function Jr(e){if(e.setActive)return e.setActive();if(No)return e.focus(No);let t=[];for(let n=e;n&&(t.push(n,n.scrollTop,n.scrollLeft),n!=n.ownerDocument);n=n.parentNode);if(e.focus(No==null?{get preventScroll(){return No={preventScroll:!0},!0}}:void 0),!No){No=!1;for(let e=0;eMath.max(1,e.scrollHeight-e.clientHeight-4)}function ti(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r>0)return{node:n,offset:r};else if(n.nodeType==1&&r>0){if(n.contentEditable==`false`)return null;n=n.childNodes[r-1],r=Hr(n)}else if(n.parentNode&&!Br(n))r=zr(n),n=n.parentNode;else return null}function ni(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r0&&(!o&&a.length&&u.merge(n,u.length,a[0],!1,s,0)?u.breakAfter=a.shift().breakAfter:(nr&&(t=r);let i=t,a=t,o=0;t==0&&n<0||t==r&&n>=0?U.chrome||U.gecko||(t?(i--,o=1):a=0)?0:s.length-1];return U.safari&&!o&&c.width==0&&(c=Array.prototype.find.call(s,e=>e.width)||c),o?Ur(c,o<0):c||null}function si(e,t){let n=e.dom,{children:r}=e,i=0;for(let e=0;ie&&t0;e--){let t=r[e-1];if(t.dom.parentNode==n)return t.domAtPos(t.length)}for(let e=i;e0&&t instanceof Yo&&i.length&&(r=i[i.length-1])instanceof Yo&&r.mark.eq(t.mark)?ci(r,t.children[0],n-1):(i.push(t),t.setParent(e)),e.length+=t.length}function li(e,t,n){let r=null,i=-1,a=null,o=-1;function s(e,t){for(let c=0,l=0;c=t&&(u.children.length?s(u,t-l):(!a||a.isHidden&&(n>0||di(a,u)))&&(d>t||l==d&&u.getSide()>0)?(a=u,o=t-l):(l-1?1:0)!=i.length-(n&&i.indexOf(n)>-1?1:0))return!1;for(let a of r)if(a!=n&&(i.indexOf(a)==-1||e[a]!==t[a]))return!1;return!0}function mi(e,t,n){let r=!1;if(t)for(let i in t)n&&i in n||(r=!0,i==`style`?e.style.cssText=``:e.removeAttribute(i));if(n)for(let i in n)t&&t[i]==n[i]||(r=!0,i==`style`?e.style.cssText=n[i]:e.setAttribute(i,n[i]));return r}function hi(e){let t=Object.create(null);for(let n=0;n=0&&n[i]+r>=e?n[i]=Math.max(n[i],t):n.push(e,t)}function yi(e,t){for(let n of t)e=new Yo(n,[e],e.length);return e}function bi(e){let t=[];for(let n=0;n=0;e-=3)if(fs[e+1]==-r){let n=fs[e+2],r=n&2?i:n&4?n&1?a:i:0;r&&(J[t]=J[fs[e]]=r),s=e;break}}else if(fs.length==189)break;else fs[s++]=t,fs[s++]=n,fs[s++]=c;else if((o=J[t])==2||o==1){let e=o==i;c=e?0:1;for(let t=s-3;t>=0;t-=3){let n=fs[t+2];if(n&2)break;if(e)fs[t+2]|=2;else{if(n&4)break;fs[t+2]|=4}}}}}function Ti(e,t,n,r){for(let i=0,a=r;i<=n.length;i++){let o=i?n[i-1].to:e,s=ic;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),J[--t]=u;c=o}else a=o,c++}}}function Ei(e,t,n,r,i,a,o){let s=r%2?2:1;if(r%2==i%2)for(let c=t,l=0;cc&&o.push(new ms(c,m.from,f)),Di(e,m.direction==ss==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?J[p]!=s:J[p]==s))break;else p++;d?Ei(e,c,p,r+1,i,d,o):ct;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=J[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;run:for(;;)if(l&&p==a[l-1].to){if(u)break run;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break run;if(n&&a[n-1].to==e)e=a[--n].from;else if(J[e-1]==s)break run;else break}d?d.push(m):(m.toJ.length;)J[J.length]=256;let r=[],i=t==ss?0:1;return Di(e,i,i,n,0,e.length,r),r}function ki(e){return[new ms(0,e,0)]}function Ai(e,t,n,r,i){let a=r.head-e.from,o=ms.find(t,a,r.bidiLevel??-1,r.assoc),s=t[o],c=s.side(i,n);if(a==c){let e=o+=i?1:-1;if(e<0||e>=t.length)return null;s=t[o=e],a=s.side(!i,n),c=s.side(i,n)}let l=nn(e.text,a,s.forward(i,n));(ls.to)&&(l=c),hs=e.text.slice(Math.min(a,l),Math.max(a,l));let u=o==(i?t.length-1:0)?null:t[o+(i?1:-1)];return u&&l==c&&u.level+(i?0:1)t instanceof Function?t(e):t),i=[];return R.spans(r,t.from,t.to,{point(){},span(e,n,r,a){let o=e-t.from,s=n-t.from,c=i;for(let e=r.length-1;e>=0;e--,a--){let n=r[e].spec.bidiIsolate,i;if(n??=ji(t.text,o,s),a>0&&c.length&&(i=c[c.length-1]).to==o&&i.direction==n)i.to=s,c=i.inner;else{let e={from:o,to:s,direction:n,inner:[]};c.push(e),c=e.inner}}}}),i}function Pi(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(Hs)){let o=a(e);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(n=Math.max(n,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(i=Math.max(i,o.bottom)))}return{left:t,right:n,top:r,bottom:i}}function Fi(e){return e.node.nodeType==1&&e.node.firstChild&&(e.offset==0||e.node.childNodes[e.offset-1].contentEditable==`false`)&&(e.offset==e.node.childNodes.length||e.node.childNodes[e.offset].contentEditable==`false`)}function Ii(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=ti(n.focusNode,n.focusOffset),i=ni(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=V.get(i.node);if(!t||t instanceof Jo&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=V.get(r.node);!e||e instanceof Jo&&e.text!=r.node.nodeValue||(a=i)}}if(e.docView.lastCompositionAfterCursor=a!=r,!a)return null;let o=t-a.offset;return{from:o,to:o+a.node.nodeValue.length,node:a.node}}function Li(e,t,n){let r=Ii(e,n);if(!r)return null;let{node:i,from:a,to:o}=r,s=i.nodeValue;if(/[\n\r]/.test(s)||e.state.doc.sliceString(r.from,r.to)!=s)return null;let c=t.invertedDesc,l=new Ws(c.mapPos(a),c.mapPos(o),a,o),u=[];for(let t=i.parentNode;;t=t.parentNode){let n=V.get(t);if(n instanceof Yo)u.push({node:t,deco:n.mark});else if(n instanceof K||t.nodeName==`DIV`&&t.parentNode==e.contentDOM)return{range:l,text:i,marks:u,line:t};else if(t!=e.contentDOM)u.push({node:t,deco:new es({inclusive:!0,attributes:hi(t),tagName:t.tagName.toLowerCase()})});else return null}}function Ri(e,t){return e.nodeType==1?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t{et.from&&(n=!0)}),n}function Hi(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return N.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=nn(i.text,a,!1):s=nn(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=nn(i.text,o,!1);if(r(i.text.slice(e,o))!=c)break;o=e}for(;se?t.left-e:Math.max(0,e-t.right)}function Wi(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function Gi(e,t){return e.topt.top+1}function Ki(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function Ji(e,t,n){let r,i,a,o,s=!1,c,l,u,d;for(let f=e.firstChild;f;f=f.nextSibling){let e=Lr(f);for(let p=0;pg||o==g&&a>h){r=f,i=m,a=h,o=g;let c=g?n0?p0)}h==0?n>m.bottom&&(!u||u.bottomm.top)&&(l=f,d=m):u&&Gi(u,m)?u=qi(u,m.bottom):d&&Gi(d,m)&&(d=Ki(d,m.top))}}if(u&&u.bottom>=n?(r=c,i=u):d&&d.top<=n&&(r=l,i=d),!r)return{node:e,offset:0};let f=Math.max(i.left,Math.min(i.right,t));return r.nodeType==3?Yi(r,f,n):s&&r.contentEditable!=`false`?Ji(r,f,n):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,r)+(t>=(i.left+i.right)/2?1:0)}}function Yi(e,t,n){let r=e.nodeValue.length,i=-1,a=1e9,o=0;for(let s=0;sn?l.top-n:n-l.bottom)-1;if(l.left-1<=t&&l.right+1>=t&&u=(l.left+l.right)/2,r=n;if((U.chrome||U.gecko)&&Yr(e,s).getBoundingClientRect().left==l.right&&(r=!n),u<=0)return{node:e,offset:s+(r?1:0)};i=s+(r?1:0),a=u}}}return{node:e,offset:i>-1?i:o>0?e.nodeValue.length:0}}function Xi(e,t,n,r=-1){let i=e.contentDOM.getBoundingClientRect(),a=i.top+e.viewState.paddingTop,o,{docHeight:s}=e.viewState,{x:c,y:l}=t,u=l-a;if(u<0)return 0;if(u>s)return e.state.doc.length;for(let t=e.viewState.heightOracle.textHeight/2,i=!1;o=e.elementAtHeight(u),o.type!=W.Text;)for(;u=r>0?o.bottom+t:o.top-t,!(u>=0&&u<=s);){if(i)return n?null:0;i=!0,r=-r}l=a+u;let d=o.from;if(de.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:n?null:Zi(e,i,o,c,l);let f=e.dom.ownerDocument,p=e.root.elementFromPoint?e.root:f,m=p.elementFromPoint(c,l);m&&!e.contentDOM.contains(m)&&(m=null),m||(c=Math.max(i.left+1,Math.min(i.right-1,c)),m=p.elementFromPoint(c,l),m&&!e.contentDOM.contains(m)&&(m=null));let h,g=-1;if(m&&e.docView.nearest(m)?.isEditable!=0){if(f.caretPositionFromPoint){let e=f.caretPositionFromPoint(c,l);e&&({offsetNode:h,offset:g}=e)}else if(f.caretRangeFromPoint){let t=f.caretRangeFromPoint(c,l);t&&({startContainer:h,startOffset:g}=t,(!e.contentDOM.contains(h)||U.safari&&Qi(h,g,c)||U.chrome&&$i(h,g,c))&&(h=void 0))}h&&(g=Math.min(Hr(h),g))}if(!h||!e.docView.dom.contains(h)){let t=K.find(e.docView,d);if(!t)return u>o.top+o.height/2?o.to:o.from;({node:h,offset:g}=Ji(t.dom,c,l))}let _=e.docView.nearest(h);if(!_)return null;if(_.isWidget&&_.dom?.nodeType==1){let e=_.dom.getBoundingClientRect();return t.ye.defaultLineHeight*1.5){let t=e.viewState.heightOracle.textHeight,r=Math.floor((i-n.top-(e.defaultLineHeight-t)*.5)/t);a+=r*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(n.from,n.to);return n.from+Hn(o,a,e.state.tabSize)}function Qi(e,t,n){let r;if(e.nodeType!=3||t!=(r=e.nodeValue.length))return!1;for(let t=e.nextSibling;t;t=t.nextSibling)if(t.nodeType!=1||t.nodeName!=`BR`)return!1;return Yr(e,r-1,r).getBoundingClientRect().left>n}function $i(e,t,n){if(t!=0)return!1;for(let t=e;;){let e=t.parentNode;if(!e||e.nodeType!=1||e.firstChild!=t)return!1;if(e.classList.contains(`cm-line`))break;t=e}return n-(e.nodeType==1?e.getBoundingClientRect():Yr(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect()).left>5}function ea(e,t){let n=e.lineBlockAt(t);if(Array.isArray(n.type)){for(let e of n.type)if(e.to>t||e.to==t&&(e.to==n.to||e.type==W.Text))return e}return n}function ta(e,t,n,r){let i=ea(e,t.head),a=!r||i.type!=W.Text||!(e.lineWrapping||i.widgetLineBreaks)?null:e.coordsAtPos(t.assoc<0&&t.head>i.from?t.head-1:t.head);if(a){let t=e.dom.getBoundingClientRect(),r=e.textDirectionAt(i.from),o=e.posAtCoords({x:n==(r==q.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o!=null)return N.cursor(o,n?-1:1)}return N.cursor(n?i.to:i.from,n?-1:1)}function na(e,t,n,r){let i=e.state.doc.lineAt(t.head),a=e.bidiSpans(i),o=e.textDirectionAt(i.from);for(let s=t,c=null;;){let t=Ai(i,a,o,s,n),l=hs;if(!t){if(i.number==(n?e.state.doc.lines:1))return s;l=` `,i=e.state.doc.line(i.number+(n?1:-1)),a=e.bidiSpans(i),t=e.visualLineSide(i,!n)}if(c){if(!c(l))return s}else{if(!r)return t;c=r(l)}s=t}}function ra(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==Sr.Space&&(i=t),i==t}}function ia(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return N.cursor(i,t.assoc);let o=t.goalColumn,s,c=e.contentDOM.getBoundingClientRect(),l=e.coordsAtPos(i,t.assoc||-1),u=e.documentTop;if(l)o??=l.left-c.left,s=a<0?l.top:l.bottom;else{let t=e.viewState.lineBlockAt(i);o??=Math.min(c.right-c.left,e.defaultCharacterWidth*(i-t.from)),s=(a<0?t.top:t.bottom)+u}let d=c.left+o,f=r??e.viewState.heightOracle.textHeight>>1;for(let t=0;;t+=10){let n=s+(f+t)*a,r=Xi(e,{x:d,y:n},!1,a);if(nc.bottom||(a<0?ri)){let t=e.docView.coordsForChar(r),i=!t||n{if(t>e&&tt(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:N.cursor(r,rDate.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:r,to:o}=t.bounds,s=i.from,c=null;(a===8||U.android&&t.text.length=i.from&&n.to<=i.to&&(n.from!=i.from||n.to!=i.to)&&i.to-i.from-(n.to-n.from)<=4?n={from:i.from,to:i.to,insert:e.state.doc.slice(i.from,n.from).append(n.insert).append(e.state.doc.slice(n.to,i.to))}:U.chrome&&n&&n.from==n.to&&n.from==i.head&&n.insert.toString()==` `&&e.lineWrapping&&(r&&=N.single(r.main.anchor-1,r.main.head-1),n={from:i.from,to:i.to,insert:k.of([` `])}),n)return la(e,n,r,a);if(r&&!r.main.eq(i)){let t=!1,n=`select`;return e.inputState.lastSelectionTime>Date.now()-50&&(e.inputState.lastSelectionOrigin==`select`&&(t=!0),n=e.inputState.lastSelectionOrigin),e.dispatch({selection:r,scrollIntoView:t,userEvent:n}),!0}else return!1}function la(e,t,n,r=-1){if(U.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(U.android&&(t.to==i.to&&(t.from==i.from||t.from==i.from-1&&e.state.sliceDoc(t.from,i.from)==` `)&&t.insert.length==1&&t.insert.lines==2&&Xr(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.lengthi.head)&&Xr(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&Xr(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=ua(e,t,n);return e.state.facet(xs).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function ua(e,t,n){let r,i=e.state,a=i.selection.main;if(t.from>=a.from&&t.to<=a.to&&t.to-t.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=a.fromt.to?i.sliceDoc(t.to,a.to):``;r=i.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=i.changes(t),s=n&&n.main.to<=o.newLength?n.main:void 0;if(i.selection.ranges.length>1&&e.inputState.composing>=0&&t.to<=a.to&&t.to>=a.to-10){let c=e.state.sliceDoc(t.from,t.to),l,u=n&&Ii(e,n.main.head);if(u){let e=t.insert.length-(t.to-t.from);l={from:u.from,to:u.to-e}}else l=e.state.doc.lineAt(a.head);let d=a.to-t.to,f=a.to-a.from;r=i.changeByRange(n=>{if(n.from==a.from&&n.to==a.to)return{changes:o,range:s||n.map(o)};let r=n.to-d,u=r-c.length;if(n.to-n.from!=f||e.state.sliceDoc(u,r)!=c||n.to>=l.from&&n.from<=l.to)return{range:n};let p=i.changes({from:u,to:r,insert:t.insert}),m=n.to-a.to;return{changes:p,range:s?N.range(Math.max(0,s.anchor+m),Math.max(0,s.head+m)):n.map(p)}})}else r={changes:o,selection:s&&i.selection.replaceRange(s)}}let o=`input.type`;return(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,o+=`.compose`,e.inputState.compositionFirstChange&&(o+=`.start`,e.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:o,scrollIntoView:!0})}function da(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a0&&s>0&&e.charCodeAt(o-1)==t.charCodeAt(s-1);)o--,s--;if(r==`end`){let e=Math.max(0,a-Math.min(o,s));n-=o+e-a}if(o=o?a-n:0;a-=e,s=a+(s-o),o=a}else if(s=s?a-n:0;a-=e,o=a+(o-s),s=a}return{from:a,toA:o,toB:s}}function fa(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=e.observer.selectionRange;return n&&(t.push(new Xs(n,r)),(i!=n||a!=r)&&t.push(new Xs(i,a))),t}function pa(e,t){if(e.length==0)return null;let n=e[0].pos,r=e.length==2?e[1].pos:n;return n>-1&&r>-1?N.single(n+t,r+t):null}function ma(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){Mi(n.state,e)}}}function ha(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec;if(e&&e.domEventHandlers)for(let r in e.domEventHandlers){let i=e.domEventHandlers[r];i&&n(r).handlers.push(ma(t.value,i))}if(e&&e.domEventObservers)for(let r in e.domEventObservers){let i=e.domEventObservers[r];i&&n(r).observers.push(ma(t.value,i))}}for(let e in Y)n(e).handlers.push(Y[e]);for(let e in X)n(e).observers.push(X[e]);return t}function ga(e){return Math.max(0,e)*.7+8}function _a(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}function va(e,t){let n=e.state.facet(gs);return n.length?n[0](t):U.mac?t.metaKey:t.ctrlKey}function ya(e,t){let n=e.state.facet(_s);return n.length?n[0](t):U.mac?!t.altKey:!t.ctrlKey}function ba(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=Pr(e.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}function xa(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target,r;n!=e.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=V.get(n))&&r.ignoreEvent(t))return!1;return!0}function Sa(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement(`textarea`));n.style.cssText=`position: fixed; left: -10000px; top: 10px`,n.focus(),setTimeout(()=>{e.focus(),n.remove(),wa(e,n.value)},50)}function Ca(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function wa(e,t){t=Ca(e.state,Cs,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(uc!=null&&n.selection.ranges.every(e=>e.empty)&&uc==a.toString()){let e=-1;r=n.changeByRange(r=>{let s=n.doc.lineAt(r.from);if(s.from==e)return{range:r};e=s.from;let c=n.toText((o?a.line(i++).text:t)+n.lineBreak);return{changes:{from:s.from,insert:c},range:N.cursor(r.from+c.length)}})}else r=o?n.changeByRange(e=>{let t=a.line(i++);return{changes:{from:e.from,to:e.to,insert:t.text},range:N.cursor(e.from+t.length)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}function Ta(e,t,n,r){if(r==1)return N.cursor(t,n);if(r==2)return Hi(e.state,t,n);{let n=K.find(e.docView,t),r=e.state.doc.lineAt(n?n.posAtEnd:t),i=n?n.posAtStart:r.from,a=n?n.posAtEnd:r.to;return a=r?-1:1}function Da(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:n,bias:Ea(e,n,t.clientX,t.clientY)}}function Oa(e){if(!oc)return e.detail;let t=sc,n=lc;return sc=e,lc=Date.now(),cc=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(cc+1)%3:1}function ka(e,t){let n=Da(e,t),r=Oa(t),i=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),i=i.map(e.changes))},get(t,a,o){let s=Da(e,t),c,l=Ta(e,s.pos,s.bias,r);if(n.pos!=s.pos&&!a){let t=Ta(e,n.pos,n.bias,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i1&&(c=Aa(i,s.pos))?c:o?i.addRange(l):N.create([l])}}}function Aa(e,t){for(let n=0;n=t)return N.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-(e.mainIndex>n?1:0))}return null}function ja(e,t,n,r){if(n=Ca(e.state,Cs,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&ya(e,t)?{from:a.from,to:a.to}:null,s={from:i,insert:n},c=e.state.changes(o?[o,s]:s);e.focus(),e.dispatch({changes:c,selection:{anchor:c.mapPos(i,-1),head:c.mapPos(i,1)},userEvent:o?`move.drop`:`input.drop`}),e.inputState.draggedContent=null}function Ma(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement(`textarea`));r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),e.focus()},50)}function Na(e){let t=[],n=[],r=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),n.push(r));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let a=e.doc.lineAt(r);a.number>i&&(t.push(a.text),n.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),i=a.number}r=!0}return{text:Ca(e,ws,t.join(e.lineBreak)),ranges:n,linewise:r}}function Pa(e,t){let n=[];for(let r of e.facet(Ss)){let i=r(e,t);i&&n.push(i)}return n?e.update({effects:n,annotations:dc.of(!0)}):null}function Fa(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=Pa(e.state,t);n?e.dispatch(n):e.update([])}},10)}function Ia(e){fc.has(e)||(fc.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}function La(){mc=!1}function Ra(e,t){return e==t?e:(e.constructor!=t.constructor&&(mc=!0),t)}function za(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof Sc&&(r=e[t+1])instanceof Sc&&e.splice(t-1,3,new Sc(n.length+1+r.length))}function Ba(e,t,n){let r=new Ec;return R.compare(e,t,n,r,0),r.changes}function Va(e,t){let r=e.getBoundingClientRect(),i=e.ownerDocument,a=i.defaultView||n,o=Math.max(0,r.left),s=Math.min(a.innerWidth,r.right),c=Math.max(0,r.top),l=Math.min(a.innerHeight,r.bottom);for(let t=e.parentNode;t&&t!=i.body;)if(t.nodeType==1){let r=t,i=n.getComputedStyle(r);if((r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&i.overflow!=`visible`){let n=r.getBoundingClientRect();o=Math.max(o,n.left),s=Math.min(s,n.right),c=Math.max(c,n.top),l=Math.min(t==e.parentNode?a.innerHeight:l,n.bottom)}t=i.position==`absolute`||i.position==`fixed`?r.offsetParent:r.parentNode}else if(t.nodeType==11)t=t.host;else break;return{left:o-r.left,right:Math.max(o,s)-r.left,top:c-(r.top+t),bottom:Math.max(c,l)-(r.top+t)}}function Ha(e){let t=e.getBoundingClientRect(),r=e.ownerDocument.defaultView||n;return t.left0&&t.top0}function Ua(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}function Wa(e,t,n){let r=[],i=e,a=0;return R.spans(n,e,t,{span(){},point(e,t){e>i&&(r.push({from:i,to:e}),a+=e-i),i=t}},20),i=1)return t[t.length-1].to;let r=Math.floor(e*n);for(let e=0;;e++){let{from:n,to:i}=t[e],a=i-n;if(r<=a)return n+r;r-=a}}function Ka(e,t){let n=0;for(let{from:r,to:i}of e.ranges){if(t<=i){n+=t-r;break}n+=i-r}return n/e.total}function qa(e,t){for(let n of e)if(t(n))return n}function Ja(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new _c(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>Ja(e,t)):e._content)}function Ya(e,t,n){return new wo(t,{finish(t){return/&/.test(t)?t.replace(/&\w*/,t=>{if(t==`&`)return e;if(!n||!n[t])throw RangeError(`Unsupported selector: ${t}`);return n[t]}):e+` `+t}})}function Xa(e,t,n){for(;t;){let r=V.get(t);if(r&&r.parent==e)return r;let i=t.parentNode;t=i==e.dom?n>0?t.nextSibling:t.previousSibling:i}return null}function Za(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.docView.domAtPos(e.state.selection.main.anchor);return Rr(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Qa(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Za(e,n)}let n=null;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.contentDOM.addEventListener(`beforeinput`,r,!0),e.dom.ownerDocument.execCommand(`indent`),e.contentDOM.removeEventListener(`beforeinput`,r,!0),n?Za(e,n):null}function $a(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let t=r[i],a=typeof t==`function`?t(e):t;a&&fi(a,n)}return n}function eo(e,t){let n=e.split(/-(?!$)/),r=n[n.length-1];r==`Space`&&(r=` `);let i,a,o,s;for(let e=0;ee.concat(t),[]))),n}function ro(e,t=qc){let n=Object.create(null),r=Object.create(null),i=(e,t)=>{let n=r[e];if(n==null)r[e]=t;else if(n!=t)throw Error(`Key binding `+e+` is used both as a regular binding and as a multi-stroke prefix`)},a=(e,r,a,o,s)=>{let c=n[e]||(n[e]=Object.create(null)),l=r.split(/ (?!$)/).map(e=>eo(e,t));for(let t=1;t{let r=Zc={view:t,prefix:n,scope:e};return setTimeout(()=>{Zc==r&&(Zc=null)},Qc),!0}]})}let u=l.join(` `);i(u,!1);let d=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(c._any?.run)?.slice()||[]});a&&d.run.push(a),o&&(d.preventDefault=!0),s&&(d.stopPropagation=!0)};for(let r of e){let e=r.scope?r.scope.split(` `):[`editor`];if(r.any)for(let t of e){let e=n[t]||(n[t]=Object.create(null));e._any||={preventDefault:!1,stopPropagation:!1,run:[]};let{any:i}=r;for(let t in e)e[t].run.push(e=>i(e,$c))}let i=r[t]||r.key;if(i)for(let t of e)a(t,i,r.run,r.preventDefault,r.stopPropagation),r.shift&&a(t,`Shift-`+i,r.shift,r.preventDefault,r.stopPropagation)}return n}function io(e,t,n,r){$c=t;let i=Nr(t),a=cn(on(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;Zc&&Zc.view==n&&Zc.scope==r&&(o=Zc.prefix+` `,tc.indexOf(t.keyCode)<0&&(c=!0,Zc=null));let u=new Set,d=e=>{if(e){for(let t of e.run)if(!u.has(t)&&(u.add(t),t(n)))return e.stopPropagation&&(l=!0),!0;e.preventDefault&&(e.stopPropagation&&(l=!0),c=!0)}return!1},f=e[r],p,m;return f&&(d(f[o+to(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(U.windows&&t.ctrlKey&&t.altKey)&&(p=Do[t.keyCode])&&p!=i?(d(f[o+to(p,t,!0)])||t.shiftKey&&(m=Oo[t.keyCode])!=i&&m!=p&&d(f[o+to(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+to(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),$c=null,s}function ao(e,t,n,r,i){t.lastIndex=0;for(let a=e.iterRange(n,r),o=n,s;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;s=t.exec(a.value);)i(o+s.index,s)}function oo(e,t){let n=e.visibleRanges;if(n.length==1&&n[0].from==e.viewport.from&&n[0].to==e.viewport.to)return n;let r=[];for(let{from:i,to:a}of n)i=Math.max(e.state.doc.lineAt(i).from,i-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),r.length&&r[r.length-1].to>=i?r[r.length-1].to=a:r.push({from:i,to:a});return r}function so(){if(il==null&&typeof document<`u`&&document.body){let e=document.body.style;il=(e.tabSize??e.MozTabSize)!=null}return il||!1}function co(e={}){return[al.of(e),lo()]}function lo(){return ol||=Ps.fromClass(class{makeDecorator(e){return new el({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:i}=n.state,a=on(t[0],0);if(a==9){let e=i.lineAt(r),t=n.state.tabSize,a=Vn(e.text,t,r-e.from);return G.replace({widget:new ll((t-a%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=G.replace({widget:new cl(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(al);e.startState.facet(al)==t?this.decorations=this.decorator.updateDeco(e,this.decorations):(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view))}constructor(e){this.view=e,this.decorations=G.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(al)),this.decorations=this.decorator.createDeco(e)}},{decorations:e=>e.decorations})}function uo(e){return e>=32?sl:e==10?`␤`:String.fromCharCode(9216+e)}function fo(){return dl}function po(e){let t=[_l];return e&&e.fixed===!1&&t.push(gl.of(!0)),t}function mo(e){return Array.isArray(e)?e:[e]}function ho(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}function go(e,t){if(e.length!=t.length)return!1;for(let n=0;n{for(t(),Mr(),bo=`ͼ`,xo=typeof Symbol>`u`?`__`+bo:Symbol.for(bo),So=typeof Symbol>`u`?`__styleSet`+Math.floor(Math.random()*1e8):Symbol(`styleSet`),Co=typeof globalThis<`u`?globalThis:n===void 0?{}:n,wo=class{getRules(){return this.rules.join(` `)}static newName(){let e=Co[xo]||1;return Co[xo]=e+1,bo+e.toString(36)}static mount(e,t,n){let r=e[So],i=n&&n.nonce;r?i&&r.setNonce(i):r=new Eo(e,i),r.mount(Array.isArray(t)?t:[t],e)}constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(e,t,a,o){let s=[],c=/^@(\w+)\b/.exec(e[0]),l=c&&c[1]==`keyframes`;if(c&&t==null)return a.push(e[0]+`;`);for(let n in t){let o=t[n];if(/&/.test(n))i(n.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,a);else if(o&&typeof o==`object`){if(!c)throw RangeError(`The value of a property (`+n+`) should be a primitive value.`);i(r(n),o,s,l)}else o!=null&&s.push(n.replace(/_.*/,``).replace(/[A-Z]/g,e=>`-`+e.toLowerCase())+`: `+o+`;`)}(s.length||l)&&a.push((n&&!c&&!o?e.map(n):e).join(`, `)+` {`+s.join(` `)+`}`)}for(let t in e)i(r(t),e[t],this.rules)}},To=new Map,Eo=class{mount(e,t){let n=this.sheet,r=0,i=0;for(let t=0;t-1&&(this.modules.splice(o,1),i--,o=-1),o==-1){if(this.modules.splice(i++,0,a),n)for(let e=0;e`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},ko=r!==void 0&&/Mac/.test(r.platform),Ao=r!==void 0&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(r.userAgent),z=0;z<10;z++)Do[48+z]=Do[96+z]=String(z);for(z=1;z<=24;z++)Do[z+111]=`F`+z;for(z=65;z<=90;z++)Do[z]=String.fromCharCode(z+32),Oo[z]=String.fromCharCode(z);for(jo in Do)Oo.hasOwnProperty(jo)||(Oo[jo]=Do[jo]);Mo=class{eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?Hr(t):0),n,Math.min(e.focusOffset,n?Hr(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}},No=null,B=class e{static before(t,n){return new e(t.parentNode,zr(t),n)}static after(t,n){return new e(t.parentNode,zr(t)+1,n)}constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}},Fo=[],V=class e{get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let n of this.children){if(n==e)return t;t+=n.length+n.breakAfter}throw RangeError(`Invalid child in posBefore`)}posAfter(e){return this.posBefore(e)+e.length}sync(t,n){if(this.flags&2){let r=this.dom,i=null,a;for(let o of this.children){if(o.flags&7){if(!o.dom&&(a=i?i.nextSibling:r.firstChild)){let t=e.get(a);(!t||!t.parent&&t.canReuseDOM(o))&&o.reuseDOM(a)}o.sync(t,n),o.flags&=-8}if(a=i?i.nextSibling:r.firstChild,n&&!n.written&&n.node==r&&a!=o.dom&&(n.written=!0),o.dom.parentNode==r)for(;a&&a!=o.dom;)a=ri(a);else r.insertBefore(o.dom,a);i=o.dom}for(a=i?i.nextSibling:r.firstChild,a&&n&&n.node==r&&(n.written=!0);a;)a=ri(a)}else if(this.flags&1)for(let e of this.children)e.flags&7&&(e.sync(t,n),e.flags&=-8)}reuseDOM(e){}localPosFromDOM(t,n){let r;if(t==this.dom)r=this.dom.childNodes[n];else{let e=Hr(t)==0?0:n==0?-1:1;for(;;){let n=t.parentNode;if(n==this.dom)break;e==0&&n.firstChild!=n.lastChild&&(e=t==n.firstChild?-1:1),t=n}r=e<0?t:t.nextSibling}if(r==this.dom.firstChild)return 0;for(;r&&!e.get(r);)r=r.nextSibling;if(!r)return this.length;for(let e=0,t=0;;e++){let n=this.children[e];if(n.dom==r)return t;t+=n.length+n.breakAfter}}domBoundsAround(e,t,n=0){let r=-1,i=-1,a=-1,o=-1;for(let s=0,c=n,l=n;st)return n.domBoundsAround(e,t,c);if(u>=e&&r==-1&&(r=s,i=c),c>t&&n.dom.parentNode==this.dom){a=s,o=l;break}l=u,c=u+n.breakAfter}return{from:i,to:o<0?n+this.length:o,startDOM:(r?this.children[r-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:a=0?this.children[a].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,n=Fo){this.markDirty();for(let r=e;rthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let n=this.children[--this.i];this.pos-=n.length+n.breakAfter}}constructor(e,t,n){this.children=e,this.pos=t,this.i=n,this.off=0}},H=r===void 0?{userAgent:``,vendor:``,platform:``}:r,Lo=typeof document<`u`?document:{documentElement:{style:{}}},Ro=/Edge\/(\d+)/.exec(H.userAgent),zo=/MSIE \d/.test(H.userAgent),Bo=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(H.userAgent),Vo=!!(zo||Bo||Ro),Ho=!Vo&&/gecko\/(\d+)/i.test(H.userAgent),Uo=!Vo&&/Chrome\/(\d+)/.exec(H.userAgent),Wo=`webkitFontSmoothing`in Lo.documentElement.style,Go=!Vo&&/Apple Computer/.test(H.vendor),Ko=Go&&(/Mobile\/\w+/.test(H.userAgent)||H.maxTouchPoints>2),U={mac:Ko||/Mac/.test(H.platform),windows:/Win/.test(H.platform),linux:/Linux|X11/.test(H.platform),ie:Vo,ie_version:zo?Lo.documentMode||6:Bo?+Bo[1]:Ro?+Ro[1]:0,gecko:Ho,gecko_version:Ho?+(/Firefox\/(\d+)/.exec(H.userAgent)||[0,0])[1]:0,chrome:!!Uo,chrome_version:Uo?+Uo[1]:0,ios:Ko,android:/Android\b/.test(H.userAgent),webkit:Wo,safari:Go,webkit_version:Wo?+(/\bAppleWebKit\/(\d+)/.exec(H.userAgent)||[0,0])[1]:0,tabSize:Lo.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`},qo=256,Jo=class e extends V{get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(t,n,r){return this.flags&8||r&&(!(r instanceof e)||this.length-(n-t)+r.length>qo||r.flags&8)?!1:(this.text=this.text.slice(0,t)+(r?r.text:``)+this.text.slice(n),this.markDirty(),!0)}split(t){let n=new e(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),n.flags|=this.flags&8,n}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new B(this.dom,e)}domBoundsAround(e,t,n){return{from:n,to:n+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return oi(this.dom,e,t)}constructor(e){super(),this.text=e}},Yo=class e extends V{setAttrs(e){if(Qr(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(t,n,r,i,a,o){return r&&(!(r instanceof e&&r.mark.eq(this.mark))||t&&a<=0||nt&&n.push(r=t&&(i=a),r=o,a++}let o=this.length-t;return this.length=t,i>-1&&(this.children.length=i,this.markDirty()),new e(this.mark,n,o)}domAtPos(e){return si(this,e)}coordsAt(e,t){return li(this,e,t)}constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let e of t)e.setParent(this)}},Xo=class e extends V{static create(t,n,r){return new e(t,n,r)}split(t){let n=e.create(this.widget,this.length-t,this.side);return this.length-=t,n}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable=`false`))}getSide(){return this.side}merge(t,n,r,i,a,o){return r&&(!(r instanceof e)||!this.widget.compare(r.widget)||t>0&&a<=0||n0)?B.before(this.dom):B.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;let r=this.dom.getClientRects(),i=null;if(!r.length)return null;let a=this.side?this.side<0:e>0;for(let t=a?r.length-1:0;i=r[t],!(e>0?t==0:t==r.length-1||i.top0?B.before(this.dom):B.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return k.empty}get isHidden(){return!0}constructor(e){super(),this.side=e}},Jo.prototype.children=Xo.prototype.children=Zo.prototype.children=Fo,Qo=Object.create(null),$o=class{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},W=function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e}(W||={}),G=class extends Tr{get heightRelevant(){return!1}static mark(e){return new es(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ns(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:i,end:a}=gi(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new ns(e,n,r,t,e.widget||null,!0)}static line(e){return new ts(e)}static set(e,t=!1){return R.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}},G.none=R.empty,es=class e extends G{eq(t){return this==t||t instanceof e&&this.tagName==t.tagName&&(this.class||this.attrs?.class)==(t.class||t.attrs?.class)&&pi(this.attrs,t.attrs,`class`)}range(e,t=e){if(e>=t)throw RangeError(`Mark decorations may not be empty`);return super.range(e,t)}constructor(e){let{start:t,end:n}=gi(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||`span`,this.class=e.class||``,this.attrs=e.attributes||null}},es.prototype.point=!1,ts=class e extends G{eq(t){return t instanceof e&&this.spec.class==t.spec.class&&pi(this.spec.attributes,t.spec.attributes)}range(e,t=e){if(t!=e)throw RangeError(`Line decoration ranges must be zero-length`);return super.range(e,t)}constructor(e){super(-2e8,-2e8,null,e)}},ts.prototype.mapMode=j.TrackBefore,ts.prototype.point=!0,ns=class e extends G{get type(){return this.startSide==this.endSide?this.startSide<=0?W.WidgetBefore:W.WidgetAfter:W.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&_i(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw RangeError(`Invalid range for replacement decoration`);if(!this.isReplace&&t!=e)throw RangeError(`Widget decorations can only have zero-length ranges`);return super.range(e,t)}constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?j.TrackBefore:j.TrackAfter:j.TrackDel}},ns.prototype.point=!0,K=class e extends V{merge(t,n,r,i,a,o){if(r){if(!(r instanceof e))return!1;this.dom||r.transferDOM(this)}return i&&this.setDeco(r?r.attrs:null),ai(this,t,n,r?r.children.slice():[],a,o),!0}split(t){let n=new e;if(n.breakAfter=this.breakAfter,this.length==0)return n;let{i:r,off:i}=this.childPos(t);i&&(n.append(this.children[r].split(i),0),this.children[r].merge(i,this.children[r].length,null,!1,0,0),r++);for(let e=r;e0&&this.children[r-1].length==0;)this.children[--r].destroy();return this.children.length=r,this.markDirty(),this.length=t,n}transferDOM(e){this.dom&&=(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,null)}setDeco(e){pi(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){ci(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=fi(t,this.attrs||{})),n&&(this.attrs=fi({class:n},this.attrs||{}))}domAtPos(e){return si(this,e)}reuseDOM(e){e.nodeName==`DIV`&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&(Qr(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&&(mi(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add(`cm-line`),this.prevAttrs=void 0),super.sync(e,t);let n=this.dom.lastChild;for(;n&&V.get(n)instanceof Yo;)n=n.lastChild;if(!n||!this.length||n.nodeName!=`BR`&&V.get(n)?.isEditable==0&&(!U.ios||!this.children.some(e=>e instanceof Jo))){let e=document.createElement(`BR`);e.cmIgnore=!0,this.dom.appendChild(e)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let n of this.children){if(!(n instanceof Jo)||/[^ -~]/.test(n.text))return null;let r=Lr(n.dom);if(r.length!=1)return null;e+=r[0].width,t=r[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let n=li(this,e,t);if(!this.children.length&&n&&this.parent){let{heightOracle:e}=this.parent.view.viewState,t=n.bottom-n.top;if(Math.abs(t-e.lineHeight)<2&&e.textHeight=n){if(a instanceof e)return a;if(o>n)break}i=o+a.breakAfter}return null}constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}},rs=class e extends V{merge(t,n,r,i,a,o){return r&&(!(r instanceof e)||!this.widget.compare(r.widget)||t>0&&a<=0||n0}constructor(e,t,n){super(),this.widget=e,this.length=t,this.deco=n,this.breakAfter=0,this.prevWidget=null}},is=class extends $o{toDOM(){let e=document.createElement(`div`);return e.className=`cm-gap`,this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+`px`,!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}constructor(e){super(),this.height=e}},as=class e{posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof rs&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new K),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&=(this.curLine.append(yi(new Zo(-1),e),e.length),0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof rs)&&this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:t,lineBreak:n,done:r}=this.cursor.next(this.skip);if(this.skip=0,r)throw Error(`Ran out of text content when drawing inline views`);if(n){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=t,this.textOff=0}let r=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(yi(new Jo(this.text.slice(this.textOff,this.textOff+r)),t),n),this.atCursorPos=!0,this.textOff+=r,e-=r,n=0}}span(e,t,n,r){this.buildText(t-e,n,r),this.pos=t,this.openStart<0&&(this.openStart=r)}point(e,t,n,r,i,a){if(this.disallowBlockEffectsFor[a]&&n instanceof ns){if(n.block)throw RangeError(`Block decorations may not be specified via plugins`);if(t>this.doc.lineAt(this.pos).to)throw RangeError(`Decorations that replace line breaks may not be specified via plugins`)}let o=t-e;if(n instanceof ns)if(n.block)n.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new rs(n.widget||os.block,o,n));else{let a=Xo.create(n.widget||os.inline,o,o?0:n.startSide),s=this.atCursorPos&&!a.isEditable&&i<=r.length&&(e0),c=!a.isEditable&&(er.length||n.startSide<=0),l=this.getLine();this.pendingBuffer==2&&!s&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(r),s&&(l.append(yi(new Zo(1),r),i),i=r.length+Math.max(0,i-r.length)),l.append(yi(a,r),i),this.atCursorPos=c,this.pendingBuffer=c?er.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=r.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(n);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text=``,this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=i)}static build(t,n,r,i,a){let o=new e(t,n,r,a);return o.openEnd=R.spans(i,n,r,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}constructor(e,t,n,r){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=r,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text=``,this.textOff=0,this.cursor=e.iter(),this.skip=t}},os=class extends $o{eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}constructor(e){super(),this.tag=e}},os.inline=new os(`span`),os.block=new os(`div`),q=function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e}(q||={}),ss=q.LTR,cs=q.RTL,ls=bi(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),us=bi(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),ds=Object.create(null),fs=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);ds[t]=n,ds[n]=-t}ps=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,ms=class{get dir(){return this.level%2?cs:ss}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let i=-1;for(let a=0;a=t){if(o.level==n)return a;(i<0||(r==0?e[i].level>o.level:r<0?o.fromt))&&(i=a)}}if(i<0)throw RangeError(`Index out of range`);return i}constructor(e,t,n){this.from=e,this.to=t,this.level=n}},J=[],hs=``,gs=P.define(),_s=P.define(),vs=P.define(),ys=P.define(),bs=P.define(),xs=P.define(),Ss=P.define(),Cs=P.define(),ws=P.define(),Ts=P.define({combine:e=>e.some(e=>e)}),Es=P.define({combine:e=>e.some(e=>e)}),Ds=P.define(),Os=class e{map(t){return t.empty?this:new e(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new e(N.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}constructor(e,t=`nearest`,n=`nearest`,r=5,i=5,a=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=a}},ks=F.define({map:(e,t)=>e.map(t)}),As=F.define(),js=P.define({combine:e=>e.length?e[0]:!0}),Ms=0,Ns=P.define(),Ps=class e{static define(t,n){let{eventHandlers:r,eventObservers:i,provide:a,decorations:o}=n||{};return new e(Ms++,t,r,i,e=>{let t=[Ns.of(e)];return o&&t.push(Rs.of(t=>{let n=t.plugin(e);return n?o(n):G.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define(e=>new t(e),n)}constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.extension=i(this)}},Fs=class{update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(Mi(e.state,t,`CodeMirror plugin crashed`),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){Mi(e.state,t,`CodeMirror plugin crashed`),this.deactivate()}return this}destroy(e){if(this.value?.destroy)try{this.value.destroy()}catch(t){Mi(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}},Is=P.define(),Ls=P.define(),Rs=P.define(),zs=P.define(),Bs=P.define(),Vs=P.define(),Hs=P.define(),Us=P.define(),Ws=class e{join(t){return new e(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(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toAu)break;a+=2}if(!c)return r;new e(c.fromA,c.toA,c.fromB,c.toB).addToSet(r),o=c.toA,s=c.toB}}constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}},Gs=class e{static create(t,n,r){return new e(t,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=M.empty(this.startState.doc.length);for(let e of n)this.changes=this.changes.compose(e.changes);let r=[];this.changes.iterChangedRanges((e,t,n,i)=>r.push(new Ws(e,t,n,i))),this.changedRanges=r}},Ks=class extends V{get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:e,toA:t})=>tthis.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(this.domChanged?.newSel?n=this.domChanged.newSel.head:!Vi(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Li(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:n,to:r}=this.hasComposition;t=new Ws(n,r,e.changes.mapPos(n,-1),e.changes.mapPos(r,1)).addToSet(t.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(U.ie||U.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,a=zi(i,this.updateDeco(),e.changes);return t=Ws.extendWithRanges(t,a),!(this.flags&7)&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:r}=this.view;r.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+`px`,this.dom.style.flexBasis=this.minWidth?this.minWidth+`px`:``;let e=U.chrome||U.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.flags&=-8,e&&(e.written||r.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=``}),this.markedForComposition.forEach(e=>e.flags&=-9);let i=[];if(this.view.viewport.from||this.view.viewport.to=0?r[e]:null;if(!t)break;let{fromA:a,toA:o,fromB:s,toB:c}=t,l,u,d,f;if(n&&n.range.fromBs){let e=as.build(this.view.state.doc,s,n.range.fromB,this.decorations,this.dynamicDecorationMap),t=as.build(this.view.state.doc,n.range.toB,c,this.decorations,this.dynamicDecorationMap);u=e.breakAtStart,d=e.openStart,f=t.openEnd;let r=this.compositionView(n);t.breakAtStart?r.breakAfter=1:t.content.length&&r.merge(r.length,r.length,t.content[0],!1,t.openStart,0)&&(r.breakAfter=t.content[0].breakAfter,t.content.shift()),e.content.length&&r.merge(0,0,e.content[e.content.length-1],!0,0,e.openEnd)&&e.content.pop(),l=e.content.concat(r).concat(t.content)}else ({content:l,breakAtStart:u,openStart:d,openEnd:f}=as.build(this.view.state.doc,s,c,this.decorations,this.dynamicDecorationMap));let{i:p,off:m}=i.findPos(o,1),{i:h,off:g}=i.findPos(a,-1);ii(this,h,g,p,m,l,u,d,f)}n&&this.fixCompositionDOM(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(As)&&(this.editContextFormatting=e.value)}compositionView(e){let t=new Jo(e.text.nodeValue);t.flags|=8;for(let{deco:n}of e.marks)t=new Yo(n,[t],t.length);let n=new K;return n.append(t,0),n}fixCompositionDOM(e){let t=(e,t)=>{t.flags|=8|(t.children.some(e=>e.flags&7)?1:0),this.markedForComposition.add(t);let n=V.get(e);n&&n!=t&&(n.dom=null),t.setDOM(e)},n=this.childPos(e.range.fromB,1),r=this.children[n.i];t(e.line,r);for(let i=e.marks.length-1;i>=-1;i--)n=r.childPos(n.off,1),r=r.children[n.i],t(i>=0?e.marks[i].node:e.text,r)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let n=this.view.root.activeElement,r=n==this.dom,i=!r&&!(this.view.state.facet(js)||this.dom.tabIndex>-1)&&Ir(this.dom,this.view.observer.selectionRange)&&!(n&&this.dom.contains(n));if(!(r||t||i))return;let a=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,s=this.moveToLine(this.domAtPos(o.anchor)),c=o.empty?s:this.moveToLine(this.domAtPos(o.head));if(U.gecko&&o.empty&&!this.hasComposition&&Fi(s)){let e=document.createTextNode(``);this.view.observer.ignore(()=>s.node.insertBefore(e,s.node.childNodes[s.offset]||null)),s=c=new B(e,0),a=!0}let l=this.view.observer.selectionRange;(a||!l.focusNode||(!Rr(s.node,s.offset,l.anchorNode,l.anchorOffset)||!Rr(c.node,c.offset,l.focusNode,l.focusOffset))&&!this.suppressWidgetCursorChange(l,o))&&(this.view.observer.ignore(()=>{U.android&&U.chrome&&this.dom.contains(l.focusNode)&&Bi(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let e=Pr(this.view.root);if(e)if(o.empty){if(U.gecko){let e=Ri(s.node,s.offset);if(e&&e!=3){let t=(e==1?ti:ni)(s.node,s.offset);t&&(s=new B(t.node,t.offset))}}e.collapse(s.node,s.offset),o.bidiLevel!=null&&e.caretBidiLevel!==void 0&&(e.caretBidiLevel=o.bidiLevel)}else if(e.extend){e.collapse(s.node,s.offset);try{e.extend(c.node,c.offset)}catch{}}else{let t=document.createRange();o.anchor>o.head&&([s,c]=[c,s]),t.setEnd(c.node,c.offset),t.setStart(s.node,s.offset),e.removeAllRanges(),e.addRange(t)}i&&this.view.root.activeElement==this.dom&&(this.dom.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(s,c)),this.impreciseAnchor=s.precise?null:new B(l.anchorNode,l.anchorOffset),this.impreciseHead=c.precise?null:new B(l.focusNode,l.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Rr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=Pr(e.root),{anchorNode:r,anchorOffset:i}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let a=K.find(this,t.head);if(!a)return;let o=a.posAtStart;if(t.head==o||t.head==o+a.length)return;let s=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!s||!c||s.bottom>c.top)return;let l=this.domAtPos(t.head+t.assoc);n.collapse(l.node,l.offset),n.modify(`move`,t.assoc<0?`forward`:`backward`,`lineboundary`),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&n.collapse(r,i)}moveToLine(e){let t=this.dom,n;if(e.node!=t)return e;for(let r=e.offset;!n&&r=0;r--){let e=V.get(t.childNodes[r]);e instanceof K&&(n=e.domAtPos(e.length))}return n?new B(n.node,n.offset,!0):e}nearest(e){for(let t=e;t;){let e=V.get(t);if(e&&e.rootView==this)return e;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw RangeError(`Trying to find position for a DOM position outside of the document`);return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t=0;a--){let o=this.children[a],s=i-o.breakAfter,c=s-o.length;if(se||o.covers(1))&&(!n||o instanceof K&&!(n instanceof K&&t>=0)))n=o,r=c;else if(n&&c==e&&s==e&&o instanceof rs&&Math.abs(t)<2){if(o.deco.startSide<0)break;a&&(n=null)}i=c}return n?n.coordsAt(e-r,t):null}coordsForChar(e){let{i:t,off:n}=this.childPos(e,1),r=this.children[t];if(!(r instanceof K))return null;for(;r.children.length;){let{i:e,off:t}=r.childPos(n,1);for(;;e++){if(e==r.children.length)return null;if((r=r.children[e]).length)break}n=t}if(!(r instanceof Jo))return null;let i=nn(r.text,n);if(i==n)return null;let a=Yr(r.dom,n,i).getClientRects();for(let e=0;eMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,s=this.view.textDirection==q.LTR;for(let e=0,c=0;cr)break;if(e>=n){let n=l.dom.getBoundingClientRect();if(t.push(n.height),a){let t=l.dom.lastChild,r=t?Lr(t):[];if(r.length){let t=r[r.length-1],a=s?t.right-n.left:n.right-t.left;a>o&&(o=a,this.minWidth=i,this.minWidthFrom=e,this.minWidthTo=u)}}}e=u+l.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction==`rtl`?q.RTL:q.LTR}measureTextSize(){for(let e of this.children)if(e instanceof K){let t=e.measureTextSize();if(t)return t}let e=document.createElement(`div`),t,n,r;return e.className=`cm-line`,e.style.width=`99999px`,e.style.position=`absolute`,e.textContent=`abc def ghi jkl mno pqr stu`,this.view.observer.ignore(()=>{this.dom.appendChild(e);let i=Lr(e.firstChild)[0];t=e.getBoundingClientRect().height,n=i?i.width/27:7,r=i?i.height:t,e.remove()}),{lineHeight:t,charWidth:n,textHeight:r}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Io(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let i=r==t.viewports.length?null:t.viewports[r],a=i?i.from-1:this.length;if(a>n){let r=(t.lineBlockAt(a).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(G.replace({widget:new is(r),block:!0,inclusive:!0,isBlockGap:!0}).range(n,a))}if(!i)break;n=i.to+1}return G.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Rs).map(t=>(this.dynamicDecorationMap[e++]=typeof t==`function`)?t(this.view):t),n=!1,r=this.view.state.facet(zs).map((e,t)=>{let r=typeof e==`function`;return r&&(n=!0),r?e(this.view):e});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(R.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];et.anchor?-1:1),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let i=Pi(this.view),a={left:n.left-i.left,top:n.top-i.top,right:n.right+i.right,bottom:n.bottom+i.bottom},{offsetWidth:o,offsetHeight:s}=this.view.scrollDOM;Kr(this.view.scrollDOM,a,t.heade)&&this.lineBreak(),r=i}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let i=-1,a=1,o;if(this.lineSeparator?(i=t.indexOf(this.lineSeparator,n),a=this.lineSeparator.length):(o=r.exec(t))&&(i=o.index,a=o[0].length),this.append(t.slice(n,i<0?t.length:i)),i<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);n=i+a}}readNode(e){if(e.cmIgnore)return;let t=V.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let e=n.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName==`BR`?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(sa(e,n.node,n.offset)?t:0))}constructor(e,t){this.points=e,this.text=``,this.lineSeparator=t.facet(L.lineSeparator)}},Xs=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},Zs=class{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text=``,this.domChanged=t>-1;let{impreciseHead:i,impreciseAnchor:a}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let t=i||a?[]:fa(e),n=new Ys(t,e.state);n.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=n.text,this.newSel=pa(t,this.bounds.from)}else{let t=e.observer.selectionRange,n=i&&i.node==t.focusNode&&i.offset==t.focusOffset||!Fr(e.contentDOM,t.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),r=a&&a.node==t.anchorNode&&a.offset==t.anchorOffset||!Fr(e.contentDOM,t.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),o=e.viewport;if((U.ios||U.chrome)&&e.state.selection.main.empty&&n!=r&&(o.from>0||o.tothis.runHandlers(e.type,e)))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let e of n.observers)e(this.view,t);for(let e of n.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=ha(e),n=this.handlers,r=this.view.contentDOM;for(let e in t)if(e!=`scroll`){let i=!t[e].handlers.length,a=n[e];a&&i!=!a.handlers.length&&(r.removeEventListener(e,this.handleEvent),a=null),a||r.addEventListener(e,this.handleEvent,{passive:i})}for(let e in n)e!=`scroll`&&!t[e]&&r.removeEventListener(e,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&tc.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),U.android&&U.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return U.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=$s.find(t=>t.keyCode==e.keyCode))&&!e.ctrlKey||ec.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key==`Enter`&&e&&e.from0?!0:U.safari&&!U.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,U.safari&&e.contentDOM.addEventListener(`input`,()=>null),U.gecko&&Ia(e.contentDOM.ownerDocument)}},$s=[{key:`Backspace`,keyCode:8,inputType:`deleteContentBackward`},{key:`Enter`,keyCode:13,inputType:`insertParagraph`},{key:`Enter`,keyCode:13,inputType:`insertLineBreak`},{key:`Delete`,keyCode:46,inputType:`deleteContentForward`}],ec=`dthko`,tc=[16,17,18,20,91,92,224,225],nc=6,rc=class{start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&_a(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,i=0,a=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:i,bottom:o}=this.scrollParents.y.getBoundingClientRect());let s=Pi(this.view);e.clientX-s.left<=r+nc?t=-ga(r-e.clientX):e.clientX+s.right>=a-nc&&(t=ga(e.clientX-a)),e.clientY-s.top<=i+nc?n=-ga(i-e.clientY):e.clientY+s.bottom>=o-nc&&(n=ga(e.clientY-o)),this.setScrollSpeed(t,n)}up(e){this.dragging??this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener(`mousemove`,this.move),e.removeEventListener(`mouseup`,this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let n=0;ne.isUserEvent(`input.type`))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=qr(e.contentDOM),this.atoms=e.state.facet(Bs).map(t=>t(e));let i=e.contentDOM.ownerDocument;i.addEventListener(`mousemove`,this.move=this.move.bind(this)),i.addEventListener(`mouseup`,this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(L.allowMultipleSelections)&&va(e,t),this.dragging=ba(e,t)&&Oa(t)==1?null:!1}},Y=Object.create(null),X=Object.create(null),ic=U.ie&&U.ie_version<15||U.ios&&U.webkit_version<604,X.scroll=e=>{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},Y.keydown=(e,t)=>(e.inputState.setSelectionOrigin(`select`),t.keyCode==27&&e.inputState.tabFocusMode!=0&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),X.touchstart=(e,t)=>{e.inputState.lastTouchTime=Date.now(),e.inputState.setSelectionOrigin(`select.pointer`)},X.touchmove=e=>{e.inputState.setSelectionOrigin(`select.pointer`)},Y.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of e.state.facet(vs))if(n=r(e,t),n)break;if(!n&&t.button==0&&(n=ka(e,t)),n){let r=!e.hasFocus;e.inputState.startMouseSelection(new rc(e,t,n,r)),r&&e.observer.ignore(()=>{Jr(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let i=e.inputState.mouseSelection;if(i)return i.start(t),i.dragging===!1}return!1},ac=(e,t,n)=>t>=n.top&&t<=n.bottom&&e>=n.left&&e<=n.right,oc=U.ie&&U.ie_version<=11,sc=null,cc=0,lc=0,Y.dragstart=(e,t)=>{let{selection:{main:n}}=e.state;if(t.target.draggable){let r=e.docView.nearest(t.target);if(r&&r.isWidget){let e=r.posAtStart,t=e+r.length;(e>=n.to||t<=n.from)&&(n=N.range(e,t))}}let{inputState:r}=e;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,t.dataTransfer&&(t.dataTransfer.setData(`Text`,Ca(e.state,ws,e.state.sliceDoc(n.from,n.to))),t.dataTransfer.effectAllowed=`copyMove`),!1},Y.dragend=e=>(e.inputState.draggedContent=null,!1),Y.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let n=t.dataTransfer.files;if(n&&n.length){let r=Array(n.length),i=0,a=()=>{++i==n.length&&ja(e,t,r.filter(e=>e!=null).join(e.state.lineBreak),!1)};for(let e=0;e{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(r[e]=t.result),a()},t.readAsText(n[e])}return!0}else{let n=t.dataTransfer.getData(`Text`);if(n)return ja(e,t,n,!0),!0}return!1},Y.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let n=ic?null:t.clipboardData;return n?(wa(e,n.getData(`text/plain`)||n.getData(`text/uri-list`)),!0):(Sa(e),!1)},uc=null,Y.copy=Y.cut=(e,t)=>{let{text:n,ranges:r,linewise:i}=Na(e.state);if(!n&&!i)return!1;uc=i?n:null,t.type==`cut`&&!e.state.readOnly&&e.dispatch({changes:r,scrollIntoView:!0,userEvent:`delete.cut`});let a=ic?null:t.clipboardData;return a?(a.clearData(),a.setData(`text/plain`,n),!0):(Ma(e,n),!1)},dc=vr.define(),X.focus=e=>{e.inputState.lastFocusTime=Date.now(),!e.scrollDOM.scrollTop&&(e.inputState.lastScrollTop||e.inputState.lastScrollLeft)&&(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),Fa(e)},X.blur=e=>{e.observer.clearSelectionRange(),Fa(e)},X.compositionstart=X.compositionupdate=e=>{e.observer.editContext||(e.inputState.compositionFirstChange??(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},X.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,U.chrome&&U.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},X.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},Y.beforeinput=(e,t)=>{if(t.inputType==`insertReplacementText`&&e.observer.editContext){let n=t.dataTransfer?.getData(`text/plain`),r=t.getTargetRanges();if(n&&r.length){let t=r[0];return la(e,{from:e.posAtDOM(t.startContainer,t.startOffset),to:e.posAtDOM(t.endContainer,t.endOffset),insert:e.state.toText(n)},null),!0}}let r;if(U.chrome&&U.android&&(r=$s.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(r.key,r.keyCode),r.key==`Backspace`||r.key==`Delete`)){let t=n.visualViewport?.height||0;setTimeout(()=>{(n.visualViewport?.height||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return U.ios&&t.inputType==`deleteContentForward`&&e.observer.flushSoon(),U.safari&&t.inputType==`insertText`&&e.inputState.composing>=0&&setTimeout(()=>X.compositionend(e,t),20),!1},fc=new Set,pc=[`pre-wrap`,`normal`,`pre-line`,`break-spaces`],mc=!1,hc=class{heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return pc.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n-1,s=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=i,s){this.heightSamples={};for(let e=0;e0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>vc&&(mc=!0),this.height=e)}replace(t,n,r){return e.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let i=this,a=n.doc;for(let o=r.length-1;o>=0;o--){let{fromA:s,toA:c,fromB:l,toB:u}=r[o],d=i.lineAt(s,Z.ByPosNoHeight,n.setDoc(t),0,0),f=d.to>=c?d:i.lineAt(c,Z.ByPosNoHeight,n,0,0);for(u+=f.to-c,c=f.to;o>0&&d.from<=r[o-1].toA;)s=r[o-1].fromA,l=r[o-1].fromB,o--,sa*2){let e=t[n-1];e.break?t.splice(--n,1,e.left,null,e.right):t.splice(--n,1,e.left,e.right),r+=1+e.break,i-=e.size}else if(a>i*2){let e=t[r];e.break?t.splice(r,1,e.left,null,e.right):t.splice(r,1,e.left,e.right),r+=2+e.break,a-=e.size}else break;else if(i=i&&a(this.blockAt(0,n,r,i))}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setHeight(r.heights[r.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}constructor(e,t,n){super(e,t),this.deco=n}},xc=class e extends bc{blockAt(e,t,n,r){return new _c(r,this.length,n,this.height,this.breaks)}replace(t,n,r){let i=r[0];return r.length==1&&(i instanceof e||i instanceof Sc&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof Sc?i=new e(i.length,this.height):i.height=this.height,this.outdated||(i.outdated=!1),i):yc.of(r)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setHeight(r.heights[r.index++]):(n||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:``}${this.widgetHeight?`:`+this.widgetHeight:``})`}constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}},Sc=class e extends yc{heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,i=r-n+1,a,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*i);a=t/i,this.length>i+1&&(o=(this.height-t)/(this.length-i-1))}else a=this.height/i;return{firstLine:n,lastLine:r,perLine:a,perChar:o}}blockAt(e,t,n,r){let{firstLine:i,lastLine:a,perLine:o,perChar:s}=this.heightMetrics(t,r);if(t.lineWrapping){let i=r+(e0){let t=r[r.length-1];t instanceof e?r[r.length-1]=new e(t.length+i):r.push(null,new e(i-1))}if(t>0){let n=r[0];n instanceof e?r[0]=new e(t+n.length):r.unshift(new e(t-1),null)}return yc.of(r)}decomposeLeft(t,n){n.push(new e(t-1),null)}decomposeRight(t,n){n.push(null,new e(this.length-t-1))}updateHeight(t,n=0,r=!1,i){let a=n+this.length;if(i&&i.from<=n+this.length&&i.more){let r=[],o=Math.max(n,i.from),s=-1;for(i.from>n&&r.push(new e(i.from-n-1).updateHeight(t,n));o<=a&&i.more;){let e=t.doc.lineAt(o).length;r.length&&r.push(null);let n=i.heights[i.index++];s==-1?s=n:Math.abs(n-s)>=vc&&(s=-2);let a=new xc(e,n);a.outdated=!1,r.push(a),o+=e+1}o<=a&&r.push(null,new e(a-o).updateHeight(t,o));let c=yc.of(r);return(s<0||Math.abs(c.height-this.height)>=vc||Math.abs(s-this.heightMetrics(t,n).perLine)>=vc)&&(mc=!0),Ra(this,c)}else (r||this.outdated)&&(this.setHeight(t.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}constructor(e){super(e,0)}},Cc=class extends yc{get break(){return this.flags&1}blockAt(e,t,n,r){let i=n+this.left.height;return eo))return c;let l=t==Z.ByPosNoHeight?Z.ByPosNoHeight:Z.ByPos;return s?c.join(this.right.lineAt(o,l,n,a,o)):this.left.lineAt(o,l,n,r,i).join(c)}forEachLine(e,t,n,r,i,a){let o=r+this.left.height,s=i+this.left.length+this.break;if(this.break)e=s&&this.right.forEachLine(e,t,n,o,s,a);else{let c=this.lineAt(s,Z.ByPos,n,r,i);e=e&&c.from<=t&&a(c),t>c.to&&this.right.forEachLine(c.to+1,t,n,o,s,a)}}replace(e,t,n){let r=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let i=[];e>0&&this.decomposeLeft(e,i);let a=i.length;for(let e of n)i.push(e);if(e>0&&za(i,a-1),t=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e2*t.size||t.size>2*e.size?yc.of(this.break?[e,null,t]:[e,t]):(this.left=Ra(this.left,e),this.right=Ra(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:i,right:a}=this,o=t+i.length+this.break,s=null;return r&&r.from<=t+i.length&&r.more?s=i=i.updateHeight(e,t,n,r):i.updateHeight(e,t,n),r&&r.from<=o+a.length&&r.more?s=a=a.updateHeight(e,o,n,r):a.updateHeight(e,o,n),s?this.balanced(i,a):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?` `:`-`)+this.right}constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}},wc=5,Tc=class e{get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof xc?n.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new xc(e-this.pos,-1)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e=wc)&&this.addLineDeco(r,i,a)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new xc(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let n=new Sc(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof xc)return e;let t=new xc(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos+=e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos+=n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof xc)&&!this.isCovered?this.nodes.push(new xc(0,-1)):(this.writtenTor>=e&&r<=t)){let{from:t,to:n}=this.lineBlockAt(r);e.push(new Ac(t,n))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?jc:new Mc(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Ja(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(Rs).filter(e=>typeof e!=`function`);let r=e.changedRanges,i=Ws.extendWithRanges(r,Ba(n,this.stateDeco,e?e.changes:M.empty(this.state.doc.length))),a=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);La(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),i),(this.heightMap.height!=a||mc)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let s=i.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heads.to)||!this.viewportIsAppropriate(s))&&(s=this.getViewport(0,t));let c=s.from!=this.viewport.from||s.to!=this.viewport.to;this.viewport=s,e.flags|=this.updateForViewport(),(c||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Es)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,r=n.getComputedStyle(t),i=this.heightOracle,a=r.whiteSpace;this.defaultTextDirection=r.direction==`rtl`?q.RTL:q.LTR;let o=this.heightOracle.mustRefreshForWrapping(a),s=t.getBoundingClientRect(),c=o||this.mustMeasureContent||this.contentDOMHeight!=s.height;this.contentDOMHeight=s.height,this.mustMeasureContent=!1;let l=0,u=0;if(s.width&&s.height){let{scaleX:e,scaleY:n}=Gr(t,s);(e>.005&&Math.abs(this.scaleX-e)>.005||n>.005&&Math.abs(this.scaleY-n)>.005)&&(this.scaleX=e,this.scaleY=n,l|=16,o=c=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,l|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(i.lineWrapping&&(c=!0),this.editorWidth=e.scrollDOM.clientWidth,l|=16);let p=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=p&&(this.scrollAnchorHeight=-1,this.scrollTop=p),this.scrolledToBottom=ei(e.scrollDOM);let m=(this.printing?Ua:Va)(t,this.paddingTop),h=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let _=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(_!=this.inView&&(this.inView=_,_&&(c=!0)),!this.inView&&!this.scrollTarget&&!Ha(e.dom))return 0;let ee=s.width;if((this.contentDOMWidth!=ee||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=s.width,this.editorHeight=e.scrollDOM.clientHeight,l|=16),c){let t=e.docView.measureVisibleLineHeights(this.viewport);if(i.mustRefreshForHeights(t)&&(o=!0),o||i.lineWrapping&&Math.abs(ee-this.contentDOMWidth)>i.charWidth){let{lineHeight:n,charWidth:r,textHeight:s}=e.docView.measureTextSize();o=n>0&&i.refresh(a,n,r,s,ee/r,t),o&&(e.docView.minWidth=0,l|=16)}h>0&&g>0?u=Math.max(h,g):h<0&&g<0&&(u=Math.min(h,g)),La();for(let n of this.viewports){let r=n.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(n);this.heightMap=(o?yc.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle,[new Ws(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(i,0,o,new gc(n.from,r))}mc&&(l|=2)}let te=!this.viewportIsAppropriate(this.viewport,u)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return te&&(l&2&&(l|=this.updateScaler()),this.viewport=this.getViewport(u,this.scrollTarget),l|=this.updateForViewport()),(l&2||te)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),l|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),l}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,i=this.heightOracle,{visibleTop:a,visibleBottom:o}=this,s=new Ac(r.lineAt(a-n*1e3,Z.ByHeight,i,0,0).from,r.lineAt(o+(1-n)*1e3,Z.ByHeight,i,0,0).to);if(t){let{head:e}=t.range;if(es.to){let n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=r.lineAt(e,Z.ByPos,i,0,0),o;o=t.y==`center`?(a.top+a.bottom)/2-n/2:t.y==`start`||t.y==`nearest`&&e=o+Math.max(10,Math.min(n,250)))&&r>a-2*1e3&&i>1,a=r<<1;if(this.defaultTextDirection!=q.LTR&&!n)return[];let o=[],s=(r,a,c,l)=>{if(a-rr&&ee.from>=c.from&&e.to<=c.to&&Math.abs(e.from-r)e.fromt));if(!f){if(ae.from<=a&&e.to>=a)){let e=t.moveToLineBoundary(N.cursor(a),!1,!0).head;e>r&&(a=e)}let e=this.gapSize(c,r,a,l);f=new Dc(r,a,e,n||e<2e6?e:2e6)}o.push(f)},c=t=>{if(t.length2e6)for(let n of e)n.from>=t.from&&n.fromt.from&&s(t.from,c,t,i),le.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];R.spans(t,this.viewport.from,this.viewport.to,{span(e,t){n.push({from:e,to:t})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let t=0;t=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Ja(this.heightMap.lineAt(e,Z.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Ja(this.heightMap.lineAt(this.scaler.fromDOM(e),Z.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Ja(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}constructor(e){this.state=e,this.pixelViewport={left:0,right:n.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=jc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=q.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1,this.heightOracle=new hc(e.facet(Ls).some(e=>typeof e!=`function`&&e.class==`cm-lineWrapping`)),this.stateDeco=e.facet(Rs).filter(e=>typeof e!=`function`),this.heightMap=yc.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle.setDoc(e.doc),[new Ws(0,0,0,e.doc.length)]);for(let e=0;e<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());e++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=G.set(this.lineGaps.map(e=>e.draw(this,!1))),this.computeVisibleRanges()}},Ac=class{constructor(e,t){this.from=e,this.to=t}},jc={toDOM(e){return e},fromDOM(e){return e},scale:1,eq(e){return e==this}},Mc=class e{toDOM(e){for(let t=0,n=0,r=0;;t++){let i=te.from==t.viewports[n].from&&e.to==t.viewports[n].to):!1}constructor(e,t,n){let r=0,i=0,a=0;this.viewports=n.map(({from:n,to:i})=>{let a=t.lineAt(n,Z.ByPos,e,0,0).top,o=t.lineAt(i,Z.ByPos,e,0,0).bottom;return r+=o-a,{from:n,to:i,top:a,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let e of this.viewports)e.domTop=a+(e.top-i)*this.scale,a=e.domBottom=e.domTop+(e.bottom-e.top),i=e.bottom}},Nc=P.define({combine:e=>e.join(` `)}),Pc=P.define({combine:e=>e.indexOf(!0)>-1}),Fc=wo.newName(),Ic=wo.newName(),Lc=wo.newName(),Rc={"&light":`.`+Ic,"&dark":`.`+Lc},zc=Ya(`.`+Fc,{"&":{position:`relative !important`,boxSizing:`border-box`,"&.cm-focused":{outline:`1px dotted #212121`},display:`flex !important`,flexDirection:`column`},".cm-scroller":{display:`flex !important`,alignItems:`flex-start !important`,fontFamily:`monospace`,lineHeight:1.4,height:`100%`,overflowX:`auto`,position:`relative`,zIndex:0,overflowAnchor:`none`},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:`block`,whiteSpace:`pre`,wordWrap:`normal`,boxSizing:`border-box`,minHeight:`100%`,padding:`4px 0`,outline:`none`,"&[contenteditable=true]":{WebkitUserModify:`read-write-plaintext-only`}},".cm-lineWrapping":{whiteSpace_fallback:`pre-wrap`,whiteSpace:`break-spaces`,wordBreak:`break-word`,overflowWrap:`anywhere`,flexShrink:1},"&light .cm-content":{caretColor:`black`},"&dark .cm-content":{caretColor:`white`},".cm-line":{display:`block`,padding:`0 2px 0 6px`},".cm-layer":{position:`absolute`,left:0,top:0,contain:`size style`,"& > *":{position:`absolute`}},"&light .cm-selectionBackground":{background:`#d9d9d9`},"&dark .cm-selectionBackground":{background:`#222`},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#d7d4f0`},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#233`},".cm-cursorLayer":{pointerEvents:`none`},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:`steps(1) cm-blink 1.2s infinite`},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:`1.2px solid black`,marginLeft:`-0.6px`,pointerEvents:`none`},".cm-cursor":{display:`none`},"&dark .cm-cursor":{borderLeftColor:`#ddd`},".cm-dropCursor":{position:`absolute`},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:`block`},".cm-iso":{unicodeBidi:`isolate`},".cm-announced":{position:`fixed`,top:`-10000px`},"@media print":{".cm-announced":{display:`none`}},"&light .cm-activeLine":{backgroundColor:`#cceeff44`},"&dark .cm-activeLine":{backgroundColor:`#99eeff33`},"&light .cm-specialChar":{color:`red`},"&dark .cm-specialChar":{color:`#f78`},".cm-gutters":{flexShrink:0,display:`flex`,height:`100%`,boxSizing:`border-box`,insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:`#f5f5f5`,color:`#6c6c6c`,borderRight:`1px solid #ddd`},"&dark .cm-gutters":{backgroundColor:`#333338`,color:`#ccc`},".cm-gutter":{display:`flex !important`,flexDirection:`column`,flexShrink:0,boxSizing:`border-box`,minHeight:`100%`,overflow:`hidden`},".cm-gutterElement":{boxSizing:`border-box`},".cm-lineNumbers .cm-gutterElement":{padding:`0 3px 0 5px`,minWidth:`20px`,textAlign:`right`,whiteSpace:`nowrap`},"&light .cm-activeLineGutter":{backgroundColor:`#e2f2ff`},"&dark .cm-activeLineGutter":{backgroundColor:`#222227`},".cm-panels":{boxSizing:`border-box`,position:`sticky`,left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:`#f5f5f5`,color:`black`},"&light .cm-panels-top":{borderBottom:`1px solid #ddd`},"&light .cm-panels-bottom":{borderTop:`1px solid #ddd`},"&dark .cm-panels":{backgroundColor:`#333338`,color:`white`},".cm-tab":{display:`inline-block`,overflow:`hidden`,verticalAlign:`bottom`},".cm-widgetBuffer":{verticalAlign:`text-top`,height:`1em`,width:0,display:`inline`},".cm-placeholder":{color:`#888`,display:`inline-block`,verticalAlign:`top`,userSelect:`none`},".cm-highlightSpace":{backgroundImage:`radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)`,backgroundPosition:`center`},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,backgroundSize:`auto 100%`,backgroundPosition:`right 90%`,backgroundRepeat:`no-repeat`},".cm-trailingSpace":{backgroundColor:`#ff332255`},".cm-button":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,padding:`.2em 1em`,borderRadius:`1px`},"&light .cm-button":{backgroundImage:`linear-gradient(#eff1f5, #d9d9df)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#b4b4b4, #d0d3d6)`}},"&dark .cm-button":{backgroundImage:`linear-gradient(#393939, #111)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#111, #333)`}},".cm-textfield":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,border:`1px solid silver`,padding:`.2em .5em`},"&light .cm-textfield":{backgroundColor:`white`},"&dark .cm-textfield":{border:`1px solid #555`,backgroundColor:`inherit`}},Rc),Bc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Vc=U.ie&&U.ie_version<=11,Hc=class{onScrollChanged(e){this.view.inputState.runHandlers(`scroll`,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type==`change`||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(js)?n.root.activeElement!=this.dom:!Ir(this.dom,r))return;let i=r.anchorNode&&n.docView.nearest(r.anchorNode);if(i&&i.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(U.ie&&U.ie_version<=11||U.android&&U.chrome)&&!n.state.selection.main.empty&&r.focusNode&&Rr(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Pr(e.root);if(!t)return!1;let n=U.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Qa(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=Ir(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&Xr(this.dom,e.key,e.keyCode))})),(!this.delayedAndroidKey||e==`Enter`)&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let i of e){let e=this.readMutation(i);e&&(e.typeOver&&(r=!0),t==-1?{from:t,to:n}=e:(t=Math.min(e.from,t),n=Math.max(e.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&Ir(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let i=new Zs(this.view,e,t,n);return this.view.docView.domChanged={newSel:i.newSel?i.newSel.main:null},i}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let n=this.view.state,r=ca(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),r}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type==`attributes`),e.type==`attributes`&&(t.flags|=4),e.type==`childList`){let n=Xa(t,e.previousSibling||e.target.previousSibling,-1),r=Xa(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else if(e.type==`characterData`)return{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue};else return null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener(`resize`,this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener(`change`,this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener(`beforeprint`,this.onPrint),e.addEventListener(`scroll`,this.onScroll),e.document.addEventListener(`selectionchange`,this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener(`scroll`,this.onScroll),e.removeEventListener(`resize`,this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener(`change`,this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener(`beforeprint`,this.onPrint),e.document.removeEventListener(`selectionchange`,this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(js)!=e.state.facet(js)&&(e.view.contentDOM.editContext=e.state.facet(js)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)==null||e.disconnect(),(t=this.gapIntersection)==null||t.disconnect(),(n=this.resizeScroll)==null||n.disconnect();for(let e of this.scrollTargets)e.removeEventListener(`scroll`,this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Mo,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let e of t)this.queue.push(e);(U.ie&&U.ie_version<=11||U.ios&&e.composing)&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),n.EditContext&&e.constructor.EDIT_CONTEXT!==!1&&!(U.chrome&&U.chrome_version<126)&&(this.editContext=new Uc(e),e.state.facet(js)&&(e.contentDOM.editContext=this.editContext.editContext)),Vc&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),n.matchMedia&&(this.printQuery=n.matchMedia(`print`)),typeof ResizeObserver==`function`&&(this.resizeScroll=new ResizeObserver(()=>{this.view.docView?.lastUpdate{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent(`Event`)))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent(`Event`))},{})),this.listenForScroll(),this.readSelectionRange()}},Uc=class{applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((i,a,o,s,c)=>{if(n)return;let l=c.length-(a-i);if(r&&a>=r.to)if(r.from==i&&r.to==a&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=l,this.to+=l;return}else r=null,this.revertPending(e.state);if(i+=t,a+=t,a<=this.from)this.from+=l,this.to+=l;else if(ithis.to||this.to-this.from+c.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(a),c.toString()),this.to+=l}t+=l}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(e=>!e.isUserEvent(`input.type`)&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new n.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});for(let n in this.handlers.textupdate=t=>{let n=e.state.selection.main,{anchor:r,head:i}=n,a=this.toEditorPos(t.updateRangeStart),o=this.toEditorPos(t.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:t.updateRangeStart,editorBase:a,drifted:!1});let s={from:a,to:o,insert:k.of(t.text.split(` `))};if(s.from==this.from&&rthis.to&&(s.to=r),s.from==s.to&&!s.insert.length){let r=N.single(this.toEditorPos(t.selectionStart),this.toEditorPos(t.selectionEnd));r.main.eq(n)||e.dispatch({selection:r,userEvent:`select`});return}if((U.mac||U.android)&&s.from==i-1&&/^\. ?$/.test(t.text)&&e.contentDOM.getAttribute(`autocorrect`)==`off`&&(s={from:a,to:o,insert:k.of([t.text.replace(`.`,` `)])}),this.pendingContextChange=s,!e.state.readOnly){let n=this.to-this.from+(s.to-s.from+s.insert.length);la(e,s,N.single(this.toEditorPos(t.selectionStart,n),this.toEditorPos(t.selectionEnd,n)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state))},this.handlers.characterboundsupdate=n=>{let r=[],i=null;for(let t=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);t{let n=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,r=e.underlineThickness;if(t!=`None`&&r!=`None`){let i=this.toEditorPos(e.rangeStart),a=this.toEditorPos(e.rangeEnd);if(i{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:t}=this.composing;this.composing=null,t&&this.reset(e.state)}},this.handlers)t.addEventListener(n,this.handlers[n]);this.measureReq={read:e=>{this.editContext.updateControlBounds(e.contentDOM.getBoundingClientRect());let t=Pr(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}},Q=class e{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||n}dispatch(...e){let t=e.length==1&&e[0]instanceof I?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw Error(`Calls to EditorView.update are not allowed while an update is in progress`);let t=!1,n=!1,r,i=this.state;for(let t of e){if(t.startState!=i)throw RangeError(`Trying to update state with a transaction that doesn't start from the previous state.`);i=t.state}if(this.destroyed){this.viewState.state=i;return}let a=this.hasFocus,o=0,s=null;e.some(e=>e.annotation(dc))?(this.inputState.notifiedFocused=a,o=1):a!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=a,s=Pa(i,a),s||(o=1));let c=this.observer.delayedAndroidKey,l=null;if(c?(this.observer.clearDelayedAndroidKey(),l=this.observer.readChange(),(l&&!this.state.doc.eq(i.doc)||!this.state.selection.eq(i.selection))&&(l=null)):this.observer.clear(),i.facet(L.phrases)!=this.state.facet(L.phrases))return this.setState(i);r=Gs.create(this,i,e),r.flags|=o;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let t of e){if(u&&=u.map(t.changes),t.scrollIntoView){let{main:e}=t.state.selection;u=new Os(e.empty?e:N.cursor(e.head,e.head>e.anchor?-1:1))}for(let e of t.effects)e.is(ks)&&(u=e.value.clip(this.state))}this.viewState.update(r,u),this.bidiCache=Kc.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Us)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(e=>e.isUserEvent(`select.pointer`)))}finally{this.updateState=0}if(r.startState.facet(Nc)!=r.state.facet(Nc)&&(this.viewState.mustMeasureContent=!0),(t||n||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let e of this.state.facet(bs))try{e(r)}catch(e){Mi(this.state,e,`update listener`)}(s||l)&&Promise.resolve().then(()=>{s&&this.state==s.startState&&this.dispatch(s),l&&!ca(this,l)&&c.force&&Xr(this.contentDOM,c.key,c.keyCode)})}setState(e){if(this.updateState!=0)throw Error(`Calls to EditorView.setState are not allowed while an update is in progress`);if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new kc(e),this.plugins=e.facet(Ns).map(e=>new Fs(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new Ks(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ns),n=e.state.facet(Ns);if(t!=n){let r=[];for(let i of n){let n=t.indexOf(i);if(n<0)r.push(new Fs(i));else{let t=this.plugins[n];t.mustUpdate=e,r.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.scrollDOM,r=n.scrollTop*this.scaleY,{scrollAnchorPos:i,scrollAnchorHeight:a}=this.viewState;Math.abs(r-this.viewState.scrollTop)>1&&(a=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(a<0)if(ei(n))i=-1,a=this.viewState.heightMap.height;else{let e=this.viewState.scrollAnchorAt(r);i=e.from,a=e.top}this.updateState=1;let o=this.viewState.measure(this);if(!o&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(e>5){console.warn(this.measureRequests.length?`Measure loop restarted more than 5 times`:`Viewport failed to stabilize`);break}let s=[];o&4||([this.measureRequests,s]=[s,this.measureRequests]);let c=s.map(e=>{try{return e.read(this)}catch(e){return Mi(this.state,e),Gc}}),l=Gs.create(this,this.state,[]),u=!1;l.flags|=o,t?t.flags|=o:t=l,this.updateState=2,l.empty||(this.updatePlugins(l),this.inputState.update(l),this.updateAttrs(),u=this.docView.update(l),u&&this.docViewUpdate());for(let e=0;e1||e<-1){r+=e,n.scrollTop=r/this.scaleY,a=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(bs))e(t)}get themeClasses(){return Fc+` `+(this.state.facet(Pc)?Lc:Ic)+` `+this.state.facet(Nc)}updateAttrs(){let e=$a(this,Is,{class:`cm-editor`+(this.hasFocus?` cm-focused `:` `)+this.themeClasses}),t={spellcheck:`false`,autocorrect:`off`,autocapitalize:`off`,writingsuggestions:`false`,translate:`no`,contenteditable:this.state.facet(js)?`true`:`false`,class:`cm-content`,style:`${U.tabSize}: ${this.state.tabSize}`,role:`textbox`,"aria-multiline":`true`};this.state.readOnly&&(t[`aria-readonly`]=`true`),$a(this,Ls,t);let n=this.observer.ignore(()=>{let n=mi(this.contentDOM,this.contentAttrs,t),r=mi(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(t){let n=!0;for(let r of t)for(let t of r.effects)if(t.is(e.announce)){n&&(this.announceDOM.textContent=``),n=!1;let e=this.announceDOM.appendChild(document.createElement(`div`));e.textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(Us);let t=this.state.facet(e.cspNonce);wo.mount(this.root,this.styleModules.concat(zc).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw Error(`Reading the editor layout isn't allowed during an update`);this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;tt.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return oa(this,e,na(this,e,t,n))}moveByGroup(e,t){return oa(this,e,na(this,e,t,t=>ra(this,e.head,t)))}visualLineSide(e,t){let n=this.bidiSpans(e),r=this.textDirectionAt(e.from),i=n[t?n.length-1:0];return N.cursor(i.side(t,r)+e.from,i.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,n=!0){return ta(this,e,t,n)}moveVertically(e,t,n){return oa(this,e,ia(this,e,t,n))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Xi(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.docView.coordsAt(e,t);if(!n||n.left==n.right)return n;let r=this.state.doc.lineAt(e),i=this.bidiSpans(r),a=i[ms.find(i,e-r.from,-1,t)];return Ur(n,a.dir==q.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Ts)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Wc)return ki(e.length);let t=this.textDirectionAt(e.from),n;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Si(r.isolates,n=Ni(this,e))))return r.order;n||=Ni(this,e);let r=Oi(e.text,t,n);return this.bidiCache.push(new Kc(e.from,e.to,t,n,!0,r)),r}get hasFocus(){return(this.dom.ownerDocument.hasFocus()||U.safari&&this.inputState?.lastContextMenu>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Jr(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||n),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return ks.of(new Os(typeof e==`number`?N.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return ks.of(new Os(N.cursor(n.from),`start`,`start`,n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e==`boolean`?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Ps.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Ps.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=wo.newName(),r=[Nc.of(n),Us.of(Ya(`.${n}`,e))];return t&&t.dark&&r.push(Pc.of(!0)),r}static baseTheme(e){return or.lowest(Us.of(Ya(`.`+Fc,e,Rc)))}static findFromDOM(e){let t=e.querySelector(`.cm-content`);return(t&&V.get(t)||V.get(e))?.rootView?.view||null}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement(`div`),this.scrollDOM=document.createElement(`div`),this.scrollDOM.tabIndex=-1,this.scrollDOM.className=`cm-scroller`,this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement(`div`),this.announceDOM.className=`cm-announced`,this.announceDOM.setAttribute(`aria-live`,`polite`),this.dom=document.createElement(`div`),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(e=>e.forEach(e=>t(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Zr(e.parent)||document,this.viewState=new kc(e.state||L.create(e)),e.scrollTo&&e.scrollTo.is(ks)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ns).map(e=>new Fs(e));for(let e of this.plugins)e.update(this);this.observer=new Hc(this),this.inputState=new Qs(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ks(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),document.fonts?.ready&&document.fonts.ready.then(()=>this.requestMeasure())}},Q.styleModule=Us,Q.inputHandler=xs,Q.clipboardInputFilter=Cs,Q.clipboardOutputFilter=ws,Q.scrollHandler=Ds,Q.focusChangeEffect=Ss,Q.perLineTextDirection=Ts,Q.exceptionSink=ys,Q.updateListener=bs,Q.editable=js,Q.mouseSelectionStyle=vs,Q.dragMovesSelection=_s,Q.clickAddsSelectionRange=gs,Q.decorations=Rs,Q.outerDecorations=zs,Q.atomicRanges=Bs,Q.bidiIsolatedRanges=Vs,Q.scrollMargins=Hs,Q.darkTheme=Pc,Q.cspNonce=P.define({combine:e=>e.length?e[0]:``}),Q.contentAttributes=Ls,Q.editorAttributes=Is,Q.lineWrapping=Q.contentAttributes.of({class:`cm-lineWrapping`}),Q.announce=F.define(),Wc=4096,Gc={},Kc=class e{static update(t,n){if(n.empty&&!t.some(e=>e.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:q.LTR;for(let a=Math.max(0,t.length-10);athis.addMatch(r,e,t,n));return t.finish()}updateDeco(e,t){let n=1e9,r=-1;return e.docChanged&&e.changes.iterChanges((t,i,a,o)=>{o>=e.view.viewport.from&&a<=e.view.viewport.to&&(n=Math.min(a,n),r=Math.max(o,r))}),e.viewportMoved||r-n>1e3?this.createDeco(e.view):r>-1?this.updateRange(e.view,t.map(e.changes),n,r):t}updateRange(e,t,n,r){for(let i of e.visibleRanges){let a=Math.max(i.from,n),o=Math.min(i.to,r);if(o>a){let n=e.state.doc.lineAt(a),r=n.ton.from;a--)if(this.boundary.test(n.text[a-1-n.from])){s=a;break}for(;ol.push(n.range(e,t));if(n==r)for(this.regexp.lastIndex=s-n.from;(u=this.regexp.exec(n.text))&&u.indexthis.addMatch(n,e,t,d));t=t.update({filterFrom:s,filterTo:c,filter:(e,t)=>ec,add:l})}}return t}constructor(e){let{regexp:t,decoration:n,decorate:r,boundary:i,maxLength:a=1e3}=e;if(!t.global)throw RangeError(`The regular expression given to MatchDecorator should have its 'g' flag set`);if(this.regexp=t,r)this.addMatch=(e,t,n,i)=>r(i,n,n+e[0].length,e,t);else if(typeof n==`function`)this.addMatch=(e,t,r,i)=>{let a=n(e,t,r);a&&i(r,r+e[0].length,a)};else if(n)this.addMatch=(e,t,r,i)=>i(r,r+e[0].length,n);else throw RangeError(`Either 'decorate' or 'decoration' should be provided to MatchDecorator`);this.boundary=i,this.maxLength=a}},tl=/x/.unicode==null?`g`:`gu`,nl=RegExp(`[\0-\b --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩-]`,tl),rl={0:`null`,7:`bell`,8:`backspace`,10:`newline`,11:`vertical tab`,13:`carriage return`,27:`escape`,8203:`zero width space`,8204:`zero width non-joiner`,8205:`zero width joiner`,8206:`left-to-right mark`,8207:`right-to-left mark`,8232:`line separator`,8237:`left-to-right override`,8238:`right-to-left override`,8294:`left-to-right isolate`,8295:`right-to-left isolate`,8297:`pop directional isolate`,8233:`paragraph separator`,65279:`zero width no-break space`,65532:`object replacement`},il=null,al=P.define({combine(e){let t=jn(e,{render:null,specialChars:nl,addSpecialChars:null});return(t.replaceTabs=!so())&&(t.specialChars=RegExp(` |`+t.specialChars.source,tl)),t.addSpecialChars&&(t.specialChars=RegExp(t.specialChars.source+`|`+t.addSpecialChars.source,tl)),t}}),ol=null,sl=`•`,cl=class extends $o{eq(e){return e.code==this.code}toDOM(e){let t=uo(this.code),n=e.state.phrase(`Control character`)+` `+(rl[this.code]||`0x`+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let i=document.createElement(`span`);return i.textContent=t,i.title=n,i.setAttribute(`aria-label`,n),i.className=`cm-specialChar`,i}ignoreEvent(){return!1}constructor(e,t){super(),this.options=e,this.code=t}},ll=class extends $o{eq(e){return e.width==this.width}toDOM(){let e=document.createElement(`span`);return e.textContent=` `,e.className=`cm-tab`,e.style.width=this.width+`px`,e}ignoreEvent(){return!1}constructor(e){super(),this.width=e}},ul=G.line({class:`cm-activeLine`}),dl=Ps.fromClass(class{update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,n=[];for(let r of e.state.selection.ranges){let i=e.lineBlockAt(r.head);i.from>t&&(n.push(ul.range(i.from)),t=i.from)}return G.set(n)}constructor(e){this.decorations=this.getDeco(e)}},{decorations:e=>e.decorations}),fl=class extends Tr{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}},fl.prototype.elementClass=``,fl.prototype.toDOM=void 0,fl.prototype.mapMode=j.TrackBefore,fl.prototype.startSide=fl.prototype.endSide=-1,fl.prototype.point=!0,pl=P.define(),ml=P.define(),hl=P.define(),gl=P.define({combine:e=>e.some(e=>e)}),_l=Ps.fromClass(class{update(e){if(this.updateGutters(e)){let t=this.prevViewport,n=e.view.viewport,r=Math.min(t.to,n.to)-Math.max(t.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}e.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+`px`),this.view.state.facet(gl)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?`sticky`:``),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&this.dom.remove();let n=R.iter(this.view.state.facet(pl),this.view.viewport.from),r=[],i=this.gutters.map(e=>new vl(e,this.view.viewport,-this.view.documentPadding.top));for(let e of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(e.type)){let t=!0;for(let a of e.type)if(a.type==W.Text&&t){ho(n,r,a.from);for(let e of i)e.line(this.view,a,r);t=!1}else if(a.widget)for(let e of i)e.widget(this.view,a)}else if(e.type==W.Text){ho(n,r,e.from);for(let t of i)t.line(this.view,e,r)}else if(e.widget)for(let t of i)t.widget(this.view,e);for(let e of i)e.finish();e&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(e){let t=e.startState.facet(hl),n=e.state.facet(hl),r=e.docChanged||e.heightChanged||e.viewportChanged||!R.eq(e.startState.facet(pl),e.state.facet(pl),e.view.viewport.from,e.view.viewport.to);if(t==n)for(let t of this.gutters)t.update(e)&&(r=!0);else{r=!0;let i=[];for(let r of n){let n=t.indexOf(r);n<0?i.push(new yl(this.view,r)):(this.gutters[n].update(e),i.push(this.gutters[n]))}for(let e of this.gutters)e.dom.remove(),i.indexOf(e)<0&&e.destroy();for(let e of i)this.dom.appendChild(e.dom);this.gutters=i}return r}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove()}constructor(e){this.view=e,this.prevViewport=e.viewport,this.dom=document.createElement(`div`),this.dom.className=`cm-gutters`,this.dom.setAttribute(`aria-hidden`,`true`),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+`px`,this.gutters=e.state.facet(hl).map(t=>new yl(e,t));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!e.state.facet(gl),this.fixed&&(this.dom.style.position=`sticky`),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}},{provide:e=>Q.scrollMargins.of(t=>{let n=t.plugin(e);return!n||n.gutters.length==0||!n.fixed?null:t.textDirection==q.LTR?{left:n.dom.offsetWidth*t.scaleX}:{right:n.dom.offsetWidth*t.scaleX}})}),vl=class{addElement(e,t,n){let{gutter:r}=this,i=(t.top-this.height)/e.scaleY,a=t.height/e.scaleY;if(this.i==r.elements.length){let t=new bl(e,a,i,n);r.elements.push(t),r.dom.appendChild(t.dom)}else r.elements[this.i].update(e,a,i,n);this.height=t.bottom,this.i++}line(e,t,n){let r=[];ho(this.cursor,r,t.from),n.length&&(r=r.concat(n));let i=this.gutter.config.lineMarker(e,t,r);i&&r.unshift(i);let a=this.gutter;r.length==0&&!a.config.renderEmptyElements||this.addElement(e,t,r)}widget(e,t){let n=this.gutter.config.widgetMarker(e,t.widget,t),r=n?[n]:null;for(let n of e.state.facet(ml)){let i=n(e,t.widget,t);i&&(r||=[]).push(i)}r&&this.addElement(e,t,r)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}constructor(e,t,n){this.gutter=e,this.height=n,this.i=0,this.cursor=R.iter(e.markers,t.from)}},yl=class{update(e){let t=this.markers;if(this.markers=mo(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let t=this.config.updateSpacer(this.spacer.markers[0],e);t!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[t])}let n=e.view.viewport;return!R.eq(this.markers,t,n.from,n.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}constructor(e,t){for(let n in this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement(`div`),this.dom.className=`cm-gutter`+(this.config.class?` `+this.config.class:``),t.domEventHandlers)this.dom.addEventListener(n,r=>{let i=r.target,a;if(i!=this.dom&&this.dom.contains(i)){for(;i.parentNode!=this.dom;)i=i.parentNode;let e=i.getBoundingClientRect();a=(e.top+e.bottom)/2}else a=r.clientY;let o=e.lineBlockAtHeight(a-e.documentTop);t.domEventHandlers[n](e,o,r)&&r.preventDefault()});this.markers=mo(t.markers(e)),t.initialSpacer&&(this.spacer=new bl(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+=`visibility: hidden; pointer-events: none`)}},bl=class{update(e,t,n,r){this.height!=t&&(this.height=t,this.dom.style.height=t+`px`),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+`px`:``),go(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let n=`cm-gutterElement`,r=this.dom.firstChild;for(let i=0,a=0;;){let o=a,s=ir(e,t,n)||i(e,t,n):i}return n}})}}),wl=class extends fl{eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}constructor(e){super(),this.number=e}},Tl=hl.compute([Cl],e=>({class:`cm-lineNumbers`,renderEmptyElements:!1,markers(e){return e.state.facet(xl)},lineMarker(e,t,n){return n.some(e=>e.toDOM)?null:new wl(_o(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,n)=>{for(let r of e.state.facet(Sl)){let i=r(e,t,n);if(i)return i}return null},lineMarkerChange:e=>e.startState.facet(Cl)!=e.state.facet(Cl),initialSpacer(e){return new wl(_o(e,yo(e.state.doc.lines)))},updateSpacer(e,t){let n=_o(t.view,yo(t.view.state.doc.lines));return n==e.number?e:new wl(n)},domEventHandlers:e.facet(Cl).domEventHandlers}))}));function Dl(e){return P.define({combine:e?t=>t.concat(e):void 0})}function Ol(e,t,n){let r=e.facet(Du),i=kl(e).topNode;if(!r||r.allowsNesting)for(let e=i;e;e=e.enter(t,n,S.ExcludeBuffers))e.type.isTop&&(i=e);return i}function kl(e){let t=e.field($.state,!1);return t?t.tree:C.empty}function Al(e,t,n){return De.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}function jl(e){let t=e.facet(ju);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function Ml(e,t){let n=``,r=e.tabSize,i=e.facet(ju)[0];if(i==` `){for(;t>=r;)n+=` `,t-=r;i=` `}for(let e=0;e-1;return e=>Hl(e,!0,1,void 0,n&&!Fl(e)?t.from:void 0)}return e.parent==null?Rl:null}function Ll(e,t,n){for(;e;e=e.parent){let r=Il(e);if(r)return r(Pu.create(n,t,e))}return null}function Rl(){return 0}function zl(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function Bl(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=i==null||i<=a.from?a.to:Math.min(a.to,i);for(let e=n.to;;){let i=t.childAfter(e);if(!i||i==r)return null;if(!i.type.isSkipped)return i.fromHl(r,t,n,e)}function Hl(e,t,n,r,i){let a=e.textAfter,o=a.match(/^\s*/)[0].length,s=r&&a.slice(o,o+r.length)==r||i==e.pos+o,c=t?Bl(e):null;return c?s?e.column(c.from):e.column(c.to):e.baseIndent+(s?0:e.unit*n)}function Ul({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}function Wl(e){let t=e.firstChild,n=e.lastChild;return t&&t.tot.facet(Q.darkTheme)==(r==`dark`)?[e]:[])):n.push(zu.of(e)),n}function ql(e){let t=[],n=e.matched?qu:Ju;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}function Jl(e={}){return[Ku.of(e),Yu]}function Yl(e,t,n){let r=e.prop(t<0?b.openedBy:b.closedBy);if(r)return r;if(e.name.length==1){let r=n.indexOf(e.name);if(r>-1&&r%2==(t<0?1:0))return[n[r+t]]}return null}function Xl(e){let t=e.type.prop(Xu);return t?t(e.node):e}function Zl(e,t,n,r={}){let i=r.maxScanDistance||Wu,a=r.brackets||Gu,o=kl(e),s=o.resolveInner(t,n);for(let r=s;r;r=r.parent){let i=Yl(r.type,n,a);if(i&&r.from0?t>=o.from&&to.from&&t<=o.to))return Ql(e,t,n,r,o,i,a)}}return $l(e,t,n,o,s.type,i,a)}function Ql(e,t,n,r,i,a,o){let s=r.parent,c={from:i.from,to:i.to},l=0,u=s?.cursor();if(u&&(n<0?u.childBefore(r.from):u.childAfter(r.to)))do if(n<0?u.to<=r.from:u.from>=r.to){if(l==0&&a.indexOf(u.type.name)>-1&&u.from0)return null;let l={from:n<0?t-1:t,to:n>0?t+1:t},u=e.doc.iterRange(t,n>0?e.doc.length:0),d=0;for(let e=0;!u.next().done&&e<=a;){let a=u.value;n<0&&(e+=a.length);let s=t+e*n;for(let e=n>0?0:a.length-1,t=n>0?a.length:-1;e!=t;e+=n){let t=o.indexOf(a[e]);if(!(t<0||r.resolveInner(s+e,1).type!=i))if(t%2==0==n>0)d++;else if(d==1)return{start:l,end:{from:s+e,to:s+e+1},matched:t>>1==c>>1};else d--}n>0&&(e+=a.length)}return u.done?{start:l,matched:!1}:null}function eu(e,t,n,r=0,i=0){t??(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));let a=i;for(let i=r;i{}),startState:e.startState||(()=>!0),copyState:e.copyState||nu,indent:e.indent||(()=>null),languageData:e.languageData||{},tokenTable:e.tokenTable||td}}function nu(e){if(typeof e!=`object`)return e;let t={};for(let n in e){let r=e[n];t[n]=r instanceof Array?r.slice():r}return t}function ru(e,t,n,r,i){let a=n>=r&&n+t.length<=i&&t.prop(e.stateAfter);if(a)return{state:e.streamParser.copyState(a),pos:n+t.length};for(let a=t.children.length-1;a>=0;a--){let o=t.children[a],s=n+t.positions[a],c=o instanceof C&&s=t.length)return t;!i&&t.type==e.topNode&&(i=!0);for(let a=t.children.length-1;a>=0;a--){let o=t.positions[a],s=t.children[a],c;if(on&&ru(e,r.tree,0-r.offset,n,i),o;if(a&&(o=iu(e,r.tree,n+r.offset,a.pos+r.offset,!1)))return{state:a.state,tree:o}}return{state:e.streamParser.startState(r?jl(r):4),tree:C.empty}}function ou(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let r=e(t,n);if(t.pos>t.start)return r}throw Error(`Stream parser failed to advance stream.`)}function su(e,t){id.indexOf(e)>-1||(id.push(e),console.warn(t))}function cu(e,t){let n=null;for(let r of t.split(`.`)){let t=e[r]||D[r];t?typeof t==`function`?n?n=t(n):su(r,`Modifier ${r} used at start of tag`):n?su(r,`Tag ${r} used as modifier`):n=t:su(r,`Unknown highlighting tag ${r}`)}if(!n)return 0;let r=t.replace(/ /g,`_`),i=x.define({id:nd.length,name:r,props:[gt({[r]:n})]});return nd.push(i),i.id}function lu(e){let t=x.define({id:nd.length,name:`Document`,props:[_u.add(()=>e)]});return nd.push(t),t}var uu,du,fu,pu,mu,hu,gu,_u,vu,$,yu,bu,xu,Su,Cu,wu,Tu,Eu,Du,Ou,ku,Au,ju,Mu,Nu,Pu,Fu,Iu,Lu,Ru,zu,Bu,Vu,Hu,Uu,Wu,Gu,Ku,qu,Ju,Yu,Xu,Zu,Qu,$u,ed,td,nd,rd,id,ad,od,sd,cd=e((()=>{t(),Ie(),Mr(),El(),Ht(),uu=`ͼ`,du=typeof Symbol>`u`?`__`+uu:Symbol.for(uu),fu=typeof Symbol>`u`?`__styleSet`+Math.floor(Math.random()*1e8):Symbol(`styleSet`),pu=typeof globalThis<`u`?globalThis:n===void 0?{}:n,mu=class{getRules(){return this.rules.join(` `)}static newName(){let e=pu[du]||1;return pu[du]=e+1,uu+e.toString(36)}static mount(e,t,n){let r=e[fu],i=n&&n.nonce;r?i&&r.setNonce(i):r=new gu(e,i),r.mount(Array.isArray(t)?t:[t],e)}constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(e,t,a,o){let s=[],c=/^@(\w+)\b/.exec(e[0]),l=c&&c[1]==`keyframes`;if(c&&t==null)return a.push(e[0]+`;`);for(let n in t){let o=t[n];if(/&/.test(n))i(n.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,a);else if(o&&typeof o==`object`){if(!c)throw RangeError(`The value of a property (`+n+`) should be a primitive value.`);i(r(n),o,s,l)}else o!=null&&s.push(n.replace(/_.*/,``).replace(/[A-Z]/g,e=>`-`+e.toLowerCase())+`: `+o+`;`)}(s.length||l)&&a.push((n&&!c&&!o?e.map(n):e).join(`, `)+` {`+s.join(` `)+`}`)}for(let t in e)i(r(t),e[t],this.rules)}},hu=new Map,gu=class{mount(e,t){let n=this.sheet,r=0,i=0;for(let t=0;t-1&&(this.modules.splice(o,1),i--,o=-1),o==-1){if(this.modules.splice(i++,0,a),n)for(let e=0;e{if(e.prop(_u)==this.data){n.push({from:t,to:t+e.length});return}let i=e.prop(b.mounted);if(i){if(i.tree.prop(_u)==this.data){if(i.overlay)for(let e of i.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}else if(i.overlay){let e=n.length;if(r(i.tree,i.overlay[0].from+t),n.length>e)return}}for(let n=0;n{let r=Ol(e,t,n),i=r.type.prop(_u);if(!i)return[];let a=e.facet(i),o=r.type.prop(vu);if(o){let i=r.resolve(t-r.from,n);for(let t of o)if(t.test(i,e)){let n=e.facet(t.facet);return t.type==`replace`?n:n.concat(a)}}return a})].concat(n)}},$.setState=F.define(),yu=class e extends ${static define(t){let n=Dl(t.languageData);return new e(n,t.parser.configure({props:[_u.add(e=>e.isTop?n:void 0)]}),t.name)}configure(t,n){return new e(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}constructor(e,t,n){super(e,t,[],n),this.parser=t}},bu=class{get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}constructor(e){this.doc=e,this.cursorPos=0,this.string=``,this.cursor=e.iter()}},xu=null,Su=class e{static create(t,n,r){return new e(t,n,[],C.empty,0,r,[],null)}startParse(){return this.parser.startParse(new bu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=C.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{if(typeof e==`number`){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||=this.startParse(),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(De.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=xu;xu=this;try{return e()}finally{xu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Al(e,t.from,t.to);return e}changes(t,n){let{fragments:r,tree:i,treeLen:a,viewport:o,skipped:s}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,n,r,i)=>e.push({fromA:t,toA:n,fromB:r,toB:i})),r=De.applyChanges(r,e),i=C.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){s=[];for(let e of this.skipped){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);ne.from&&(this.fragments=Al(this.fragments,n,r),this.skipped.splice(t--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&=(this.takeTree(),null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Oe{createParse(t,n,r){let i=r[0].from,a=r[r.length-1].to;return{parsedPos:i,advance(){let t=xu;if(t){for(let e of r)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=a,new C(x.none,[],[],a-i)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return xu}constructor(e,t,n=[],r,i,a,o,s){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=i,this.viewport=a,this.skipped=o,this.scheduleOn=s,this.parse=null,this.tempSkipped=[]}},Cu=class e{apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new e(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=Su.create(t.facet(Du).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new e(r)}constructor(e){this.context=e,this.tree=e.tree}},$.state=ir.define({create:Cu.init,update(e,t){for(let e of t.effects)if(e.is($.setState))return e.value;return t.startState.facet(Du)==t.state.facet(Du)?e.apply(t):Cu.init(t.state)}}),wu=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)},typeof requestIdleCallback<`u`&&(wu=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)}),Tu=r!==void 0&&r.scheduling?.isInputPending?()=>r.scheduling.isInputPending():null,Eu=Ps.fromClass(class{update(e){let t=this.view.state.field($.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field($.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=wu(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndr+1e3,s=i.context.work(()=>Tu&&Tu()||Date.now()>a,r+(o?0:1e5));this.chunkBudget-=Date.now()-t,(s||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:$.setState.of(new Cu(i.context))})),this.chunkBudget>0&&!(s&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&=(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Mi(this.view.state,e)).then(()=>this.workScheduled--),null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}},{eventHandlers:{focus(){this.scheduleWork()}}}),Du=P.define({combine(e){return e.length?e[0]:null},enables:e=>[$.state,Eu,Q.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]}),Ou=class{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}},ku=class e{load(){return this.loading||=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e})}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw RangeError(`Must pass either 'load' or 'support' to LanguageDescription.of`);n=()=>Promise.resolve(r)}return new e(t.name,(t.alias||[]).concat(t.name).map(e=>e.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let n=/\.([^.]+)$/.exec(t);if(n){for(let t of e)if(t.extensions.indexOf(n[1])>-1)return t}return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(e=>e==t))return n;if(n)for(let n of e)for(let e of n.alias){let r=t.indexOf(e);if(r>-1&&(e.length>2||!/\w/.test(t[r-1])&&!/\w/.test(t[r+e.length])))return n}return null}constructor(e,t,n,r,i,a=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=i,this.support=a,this.loading=null}},Au=P.define(),ju=P.define({combine:e=>{if(!e.length)return` `;let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw Error(`Invalid indent unit: `+JSON.stringify(e[0]));return t}}),Mu=class{lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:i}=this.options;return r!=null&&r>=n.from&&r<=n.to?i&&r==e?{text:``,from:e}:(t<0?r-1&&(i+=a-this.countColumn(n,n.search(/\S|$/))),i}countColumn(e,t=e.length){return Vn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.options.overrideIndentation;if(i){let e=i(r);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}constructor(e,t={}){this.state=e,this.options=t,this.unit=jl(e)}},Nu=new b,Pu=class e extends Mu{static create(t,n,r){return new e(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(zl(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){let e=this.node.parent;return e?Ll(e,this.pos,this.base):0}constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.node=n}},Fu=e=>e.baseIndent,Iu=P.define(),Lu=new b,Ru=class e{static define(t,n){return new e(t,n||{})}constructor(e,t){this.specs=e;let n;function r(e){let t=mu.newName();return(n||=Object.create(null))[`.`+t]=e,t}let i=typeof t.all==`string`?t.all:t.all?r(t.all):void 0,a=t.scope;this.scope=a instanceof $?e=>e.prop(_u)==a.data:a?e=>e==a:void 0,this.style=_t(e.map(e=>({tag:e.tag,class:e.class||r(Object.assign({},e,{tag:null}))})),{all:i}).style,this.module=n?new mu(n):null,this.themeType=t.themeType}},zu=P.define(),Bu=P.define({combine(e){return e.length?[e[0]]:null}}),Vu=class{update(e){let t=kl(e.state),n=Gl(e.state),r=n!=Gl(e.startState);t.length{n.add(e,t,this.markCache[r]||(this.markCache[r]=G.mark({class:r})))},r,i);return n.finish()}constructor(e){this.markCache=Object.create(null),this.tree=kl(e.state),this.decorations=this.buildDeco(e,Gl(e.state))}},Hu=or.high(Ps.fromClass(Vu,{decorations:e=>e.decorations})),D.meta,D.link,D.heading,D.emphasis,D.strong,D.strikethrough,D.keyword,D.atom,D.bool,D.url,D.contentSeparator,D.labelName,D.literal,D.inserted,D.string,D.deleted,D.regexp,D.escape,D.string,D.variableName,D.variableName,D.typeName,D.namespace,D.className,D.variableName,D.macroName,D.propertyName,D.comment,D.invalid,Uu=Q.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:`#328c8252`},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:`#bb555544`}}),Wu=1e4,Gu=`()[]{}`,Ku=P.define({combine(e){return jn(e,{afterCursor:!0,brackets:Gu,maxScanDistance:Wu,renderMatch:ql})}}),qu=G.mark({class:`cm-matchingBracket`}),Ju=G.mark({class:`cm-nonmatchingBracket`}),Yu=[ir.define({create(){return G.none},update(e,t){if(!t.docChanged&&!t.selection)return e;let n=[],r=t.state.facet(Ku);for(let e of t.state.selection.ranges){if(!e.empty)continue;let i=Zl(t.state,e.head,-1,r)||e.head>0&&Zl(t.state,e.head-1,1,r)||r.afterCursor&&(Zl(t.state,e.head,1,r)||e.headQ.decorations.from(e)}),Uu],Xu=new b,Zu=class{eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPosn?e.toLowerCase():e;return r(this.string.substr(this.pos,e.length))==r(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}constructor(e,t,n,r){this.string=e,this.tabSize=t,this.indentUnit=n,this.overrideIndent=r,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}},Qu=new WeakMap,$u=class e extends ${static define(t){return new e(t)}getIndent(e,t){let n=kl(e.state),r=n.resolve(t);for(;r&&r.type!=this.topNode;)r=r.parent;if(!r)return null;let i,{overrideIndentation:a}=e.options;a&&(i=Qu.get(e.state),i!=null&&i1e4)return null;for(;sthis.getIndent(e,t))],e.name),this.topNode=lu(t),r=this,this.streamParser=n,this.stateAfter=new b({perNode:!0}),this.tokenTable=e.tokenTable?new od(n.tokenTable):sd}},ed=class{advance(){let e=Su.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),n=Math.min(t,this.chunkStart+2048);for(e&&(n=Math.min(n,e.viewport.to));this.parsedPos=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==` `&&(t=``);else{let e=t.indexOf(` `);e>-1&&(t=t.slice(0,e))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),n=e+t.length;for(let e=this.rangeIndex;;){let r=this.ranges[e].to;if(r>=n||(t=t.slice(0,r-(n-t.length)),e++,e==this.ranges.length))break;let i=this.ranges[e].from,a=this.lineAfter(i);t+=a,n=i+a.length}return{line:t,end:n}}skipGapsTo(e,t,n){for(;;){let r=this.ranges[this.rangeIndex].to,i=e+t;if(n>0?r>i:r>=i)break;let a=this.ranges[++this.rangeIndex].from;t+=a-r}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){i=this.skipGapsTo(t,i,1),t+=i;let e=this.chunk.length;i=this.skipGapsTo(n,i,-1),n+=i,r+=this.chunk.length-e}return this.chunk.push(e,t,n,r),i}parseLine(e){let{line:t,end:n}=this.nextLine(),r=0,{streamParser:i}=this.lang,a=new Zu(t,e?e.state.tabSize:4,e?jl(e.state):2);if(a.eol())i.blankLine(this.state,a.indentUnit);else for(;!a.eol();){let e=ou(i.token,a,this.state);if(e&&(r=this.emitToken(this.lang.tokenTable.resolve(e),this.parsedPos+a.start,this.parsedPos+a.pos,4,r)),a.start>1e4)break}this.parsedPos=n,this.moveRangeIndex(),this.parsedPos