@mokup/playground 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{d as Fo,u as Ho,o as Vo,r as ii,w as si,a as zo,c as Qi,b as _i,e as cn,f as un,g as Jt,t as qo,m as jo,h as $o}from"./playground.js";const xr=1024;let Ko=0,Gi=class{constructor(t,e){this.from=t,this.to=e}};class L{constructor(t={}){this.id=Ko++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=ht.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}}L.closedBy=new L({deserialize:r=>r.split(" ")});L.openedBy=new L({deserialize:r=>r.split(" ")});L.group=new L({deserialize:r=>r.split(" ")});L.isolate=new L({deserialize:r=>{if(r&&r!="rtl"&&r!="ltr"&&r!="auto")throw new RangeError("Invalid value for isolate: "+r);return r||"auto"}});L.contextHash=new L({perNode:!0});L.lookAhead=new L({perNode:!0});L.mounted=new L({perNode:!0});class Ne{constructor(t,e,i,s=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=s}static get(t){return t&&t.props&&t.props[L.mounted.id]}}const Qo=Object.create(null);class ht{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):Qo,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),s=new ht(t.name||"",e,t.id,i);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(s)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return s}prop(t){return this.props[t.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(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(L.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return i=>{for(let s=i.prop(L.group),n=-1;n<(s?s.length:0);n++){let o=e[n<0?i.name:s[n]];if(o)return o}}}}ht.none=new ht("",Object.create(null),0,8);class Ks{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let s=null;for(let n of t){let o=n(i);if(o){s||(s=Object.assign({},i.props));let l=o[1],h=o[0];h.combine&&h.id in s&&(l=h.combine(s[h.id],l)),s[h.id]=l}}e.push(s?new ht(i.name,s,i.id,i.flags):i)}return new Ks(e)}}const ni=new WeakMap,dn=new WeakMap;var U;(function(r){r[r.ExcludeBuffers=1]="ExcludeBuffers",r[r.IncludeAnonymous=2]="IncludeAnonymous",r[r.IgnoreMounts=4]="IgnoreMounts",r[r.IgnoreOverlays=8]="IgnoreOverlays",r[r.EnterBracketed=16]="EnterBracketed"})(U||(U={}));class Y{constructor(t,e,i,s,n){if(this.type=t,this.children=e,this.positions=i,this.length=s,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,l]of n)this.props[typeof o=="number"?o:o.id]=l}}toString(){let t=Ne.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let s=i.toString();s&&(e&&(e+=","),e+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new ds(this.topNode,t)}cursorAt(t,e=0,i=0){let s=ni.get(this)||this.topNode,n=new ds(s);return n.moveTo(t,e),ni.set(this,n._tree),n}get topNode(){return new mt(this,0,0,null)}resolve(t,e=0){let i=ze(ni.get(this)||this.topNode,t,e,!1);return ni.set(this,i),i}resolveInner(t,e=0){let i=ze(dn.get(this)||this.topNode,t,e,!0);return dn.set(this,i),i}resolveStack(t,e=0){return Uo(this,t,e)}iterate(t){let{enter:e,leave:i,from:s=0,to:n=this.length}=t,o=t.mode||0,l=(o&U.IncludeAnonymous)>0;for(let h=this.cursor(o|U.IncludeAnonymous);;){let a=!1;if(h.from<=n&&h.to>=s&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;a=!0}for(;a&&i&&(l||!h.type.isAnonymous)&&i(h),!h.nextSibling();){if(!h.parent())return;a=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Gs(ht.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,s)=>new Y(this.type,e,i,s,this.propValues),t.makeTree||((e,i,s)=>new Y(ht.none,e,i,s)))}static build(t){return Jo(t)}}Y.empty=new Y(ht.none,[],[],0);class Qs{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Qs(this.buffer,this.index)}}class $t{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return ht.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],s=this.set.types[e],n=s.name;if(/\W/.test(n)&&!s.isError&&(n=JSON.stringify(n)),t+=4,i==t)return n;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return n+"("+o.join(",")+")"}findChild(t,e,i,s,n){let{buffer:o}=this,l=-1;for(let h=t;h!=e&&!(yr(n,s,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(t,e,i){let s=this.buffer,n=new Uint16Array(e-t),o=0;for(let l=t,h=0;l<e;){n[h++]=s[l++],n[h++]=s[l++]-i;let a=n[h++]=s[l++]-i;n[h++]=s[l++]-t,o=Math.max(o,a)}return new $t(n,o,this.set)}}function yr(r,t,e,i){switch(r){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function ze(r,t,e,i){for(var s;r.from==r.to||(e<1?r.from>=t:r.from>t)||(e>-1?r.to<=t:r.to<t);){let o=!i&&r instanceof mt&&r.index<0?null:r.parent;if(!o)return r;r=o}let n=i?0:U.IgnoreOverlays;if(i)for(let o=r,l=o.parent;l;o=l,l=o.parent)o instanceof mt&&o.index<0&&((s=l.enter(t,e,n))===null||s===void 0?void 0:s.from)!=o.from&&(r=l);for(;;){let o=r.enter(t,e,n);if(!o)return r;r=o}}class wr{cursor(t=0){return new ds(this,t)}getChild(t,e=null,i=null){let s=pn(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return pn(this,t,e,i)}resolve(t,e=0){return ze(this,t,e,!1)}resolveInner(t,e=0){return ze(this,t,e,!0)}matchContext(t){return us(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let s=e.lastChild;if(!s||s.to!=e.to)break;s.type.isError&&s.from==s.to?(i=e,e=s.prevSibling):e=s}return i}get node(){return this}get next(){return this.parent}}class mt extends wr{constructor(t,e,i,s){super(),this._tree=t,this.from=e,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,s,n=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,a=e>0?l.length:-1;t!=a;t+=e){let f=l[t],c=h[t]+o.from,u;if(!(!(n&U.EnterBracketed&&f instanceof Y&&(u=Ne.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!yr(s,i,c,c+f.length))){if(f instanceof $t){if(n&U.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,e,i-c,s);if(d>-1)return new zt(new _o(o,f,t,c),null,d)}else if(n&U.IncludeAnonymous||!f.type.isAnonymous||_s(f)){let d;if(!(n&U.IgnoreMounts)&&(d=Ne.get(f))&&!d.overlay)return new mt(d.tree,c,t,o);let p=new mt(f,c,t,o);return n&U.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(e<0?f.children.length-1:0,e,i,s,n)}}}if(n&U.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let s;if(!(i&U.IgnoreOverlays)&&(s=Ne.get(this._tree))&&s.overlay){let n=t-this.from,o=i&U.EnterBracketed&&s.bracketed;for(let{from:l,to:h}of s.overlay)if((e>0||o?l<=n:l<n)&&(e<0||o?h>=n:h>n))return new mt(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function pn(r,t,e,i){let s=r.cursor(),n=[];if(!s.firstChild())return n;if(e!=null){for(let o=!1;!o;)if(o=s.type.is(e),!s.nextSibling())return n}for(;;){if(i!=null&&s.type.is(i))return n;if(s.type.is(t)&&n.push(s.node),!s.nextSibling())return i==null?n:[]}}function us(r,t,e=t.length-1){for(let i=r;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}class _o{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class zt extends wr{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return n<0?null:new zt(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&U.ExcludeBuffers)return null;let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new zt(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new zt(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new zt(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,n=i.buffer[this.index+3];if(n>s){let o=i.buffer[this.index+1];t.push(i.slice(s,n,o)),e.push(0)}return new Y(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function kr(r){if(!r.length)return null;let t=0,e=r[0];for(let n=1;n<r.length;n++){let o=r[n];(o.from>e.from||o.to<e.to)&&(e=o,t=n)}let i=e instanceof mt&&e.index<0?null:e.parent,s=r.slice();return i?s[t]=i:s.splice(t,1),new Go(s,e)}class Go{constructor(t,e){this.heads=t,this.node=e}get next(){return kr(this.heads)}}function Uo(r,t,e){let i=r.resolveInner(t,e),s=null;for(let n=i instanceof mt?i:i.context.parent;n;n=n.parent)if(n.index<0){let o=n.parent;(s||(s=[i])).push(o.resolve(t,e)),n=o}else{let o=Ne.get(n.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new mt(o.tree,o.overlay[0].from+n.from,-1,n);(s||(s=[i])).push(ze(l,t,e,!1))}}return s?kr(s):i}class ds{get name(){return this.type.name}constructor(t,e=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=e&~U.EnterBracketed,t instanceof mt)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return t?t instanceof mt?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,n=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&U.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&U.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&U.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(e.findChild(s,this.index,-1,0,4))}else{let s=e.buffer[this.index+3];if(s<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index<s.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(s.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:i}=s)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let n=e+t,o=t<0?-1:i._tree.children.length;n!=o;n+=t){let l=i._tree.children[n];if(this.mode&U.IncludeAnonymous||l instanceof $t||!l.type.isAnonymous||_s(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let s=this.index,n=this.stack.length;n>=0;){for(let o=t;o;o=o._parent)if(o.index==s){if(s==this.index)return o;e=o,i=n+1;break t}s=this.stack[--n]}for(let s=i;s<this.stack.length;s++)e=new zt(this.buffer,e,this.stack[s]);return this.bufferNode=new zt(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let s=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&e&&e(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(t){if(!this.buffer)return us(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let s=t.length-1,n=this.stack.length-1;s>=0;n--){if(n<0)return us(this._tree,t,s);let o=i[e.buffer[this.stack[n]]];if(!o.isAnonymous){if(t[s]&&t[s]!=o.name)return!1;s--}}return!0}}function _s(r){return r.children.some(t=>t instanceof $t||!t.type.isAnonymous||_s(t))}function Jo(r){var t;let{buffer:e,nodeSet:i,maxBufferLength:s=xr,reused:n=[],minRepeatType:o=i.types.length}=r,l=Array.isArray(e)?new Qs(e,e.length):e,h=i.types,a=0,f=0;function c(O,P,C,_,F,N){let{id:R,start:T,end:j,size:y}=l,S=f,I=a;if(y<0)if(l.next(),y==-1){let Rt=n[R];C.push(Rt),_.push(T-O);return}else if(y==-3){a=R;return}else if(y==-4){f=R;return}else throw new RangeError(`Unrecognized record size: ${y}`);let H=h[R],Q,G,he=T-O;if(j-T<=s&&(G=m(l.pos-P,F))){let Rt=new Uint16Array(G.size-G.skip),dt=l.pos-G.size,Ct=Rt.length;for(;l.pos>dt;)Ct=b(G.start,Rt,Ct);Q=new $t(Rt,j-G.start,i),he=G.start-O}else{let Rt=l.pos-y;l.next();let dt=[],Ct=[],Ut=R>=o?R:-1,ae=0,ei=j;for(;l.pos>Rt;)Ut>=0&&l.id==Ut&&l.size>=0?(l.end<=ei-s&&(p(dt,Ct,T,ae,l.end,ei,Ut,S,I),ae=dt.length,ei=l.end),l.next()):N>2500?u(T,Rt,dt,Ct):c(T,Rt,dt,Ct,Ut,N+1);if(Ut>=0&&ae>0&&ae<dt.length&&p(dt,Ct,T,ae,T,ei,Ut,S,I),dt.reverse(),Ct.reverse(),Ut>-1&&ae>0){let fn=d(H,I);Q=Gs(H,dt,Ct,0,dt.length,0,j-T,fn,fn)}else Q=g(H,dt,Ct,j-T,S-j,I)}C.push(Q),_.push(he)}function u(O,P,C,_){let F=[],N=0,R=-1;for(;l.pos>P;){let{id:T,start:j,end:y,size:S}=l;if(S>4)l.next();else{if(R>-1&&j<R)break;R<0&&(R=y-s),F.push(T,j,y),N++,l.next()}}if(N){let T=new Uint16Array(N*4),j=F[F.length-2];for(let y=F.length-3,S=0;y>=0;y-=3)T[S++]=F[y],T[S++]=F[y+1]-j,T[S++]=F[y+2]-j,T[S++]=S;C.push(new $t(T,F[2]-j,i)),_.push(j-O)}}function d(O,P){return(C,_,F)=>{let N=0,R=C.length-1,T,j;if(R>=0&&(T=C[R])instanceof Y){if(!R&&T.type==O&&T.length==F)return T;(j=T.prop(L.lookAhead))&&(N=_[R]+T.length+j)}return g(O,C,_,F,N,P)}}function p(O,P,C,_,F,N,R,T,j){let y=[],S=[];for(;O.length>_;)y.push(O.pop()),S.push(P.pop()+C-F);O.push(g(i.types[R],y,S,N-F,T-N,j)),P.push(F-C)}function g(O,P,C,_,F,N,R){if(N){let T=[L.contextHash,N];R=R?[T].concat(R):[T]}if(F>25){let T=[L.lookAhead,F];R=R?[T].concat(R):[T]}return new Y(O,P,C,_,R)}function m(O,P){let C=l.fork(),_=0,F=0,N=0,R=C.end-s,T={size:0,start:0,skip:0};t:for(let j=C.pos-O;C.pos>j;){let y=C.size;if(C.id==P&&y>=0){T.size=_,T.start=F,T.skip=N,N+=4,_+=4,C.next();continue}let S=C.pos-y;if(y<0||S<j||C.start<R)break;let I=C.id>=o?4:0,H=C.start;for(C.next();C.pos>S;){if(C.size<0)if(C.size==-3||C.size==-4)I+=4;else break t;else C.id>=o&&(I+=4);C.next()}F=H,_+=y,N+=I}return(P<0||_==O)&&(T.size=_,T.start=F,T.skip=N),T.size>4?T:void 0}function b(O,P,C){let{id:_,start:F,end:N,size:R}=l;if(l.next(),R>=0&&_<o){let T=C;if(R>4){let j=l.pos-(R-4);for(;l.pos>j;)C=b(O,P,C)}P[--C]=T,P[--C]=N-O,P[--C]=F-O,P[--C]=_}else R==-3?a=_:R==-4&&(f=_);return C}let A=[],M=[];for(;l.pos>0;)c(r.start||0,r.bufferStart||0,A,M,-1,0);let E=(t=r.length)!==null&&t!==void 0?t:A.length?M[0]+A[0].length:0;return new Y(h[r.topID],A.reverse(),M.reverse(),E)}const gn=new WeakMap;function yi(r,t){if(!r.isAnonymous||t instanceof $t||t.type!=r)return 1;let e=gn.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=r||!(i instanceof Y)){e=1;break}e+=yi(r,i)}gn.set(t,e)}return e}function Gs(r,t,e,i,s,n,o,l,h){let a=0;for(let p=i;p<s;p++)a+=yi(r,t[p]);let f=Math.ceil(a*1.5/8),c=[],u=[];function d(p,g,m,b,A){for(let M=m;M<b;){let E=M,O=g[M],P=yi(r,p[M]);for(M++;M<b;M++){let C=yi(r,p[M]);if(P+C>=f)break;P+=C}if(M==E+1){if(P>f){let C=p[E];d(C.children,C.positions,0,C.children.length,g[E]+A);continue}c.push(p[E])}else{let C=g[M-1]+p[M-1].length-O;c.push(Gs(r,p,g,E,M,O,C,null,h))}u.push(O+A-n)}}return d(t,e,i,s,0),(l||h)(c,u,o)}class ie{constructor(t,e,i,s,n=!1,o=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(n?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,e=[],i=!1){let s=[new ie(0,t.length,t,0,!1,i)];for(let n of e)n.to>t.length&&s.push(n);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],n=1,o=t.length?t[0]:null;for(let l=0,h=0,a=0;;l++){let f=l<e.length?e[l]:null,c=f?f.fromA:1e9;if(c-h>=i)for(;o&&o.from<c;){let u=o;if(h>=u.from||c<=u.to||a){let d=Math.max(u.from,h)-a,p=Math.min(u.to,c)-a;u=d>=p?null:new ie(d,p,u.tree,u.offset+a,l>0,!!f)}if(u&&s.push(u),o.to>c)break;o=n<t.length?t[n++]:null}if(!f)break;h=f.toA,a=f.toA-f.toB}return s}}class Sr{startParse(t,e,i){return typeof t=="string"&&(t=new Yo(t)),i=i?i.length?i.map(s=>new Gi(s.from,s.to)):[new Gi(0,0)]:[new Gi(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let n=s.advance();if(n)return n}}}class Yo{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new L({perNode:!0});var mn={};class Ci{constructor(t,e,i,s,n,o,l,h,a,f=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=s,this.pos=n,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let s=t.parser.context;return new Ci(t,[],e,i,i,0,[],0,s?new bn(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,s=t&65535,{parser:n}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=n.dynamicPrecedence(s);if(l&&(this.score+=l),i==0){this.pushState(n.getGoto(this.state,s,!0),this.reducePos),s<n.minRepeatTerm&&this.storeNode(s,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(s,this.reducePos);return}let h=this.stack.length-(i-1)*3-(t&262144?6:0),a=h?this.stack[h-2]:this.p.ranges[0].from,f=this.reducePos-a;f>=2e3&&!(!((e=this.p.parser.nodeSet.types[s])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=f):this.p.lastBigReductionSize<f&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=f));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(s<n.minRepeatTerm||t&131072){let d=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(s,a,d,u+4,!0)}if(t&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=n.getGoto(d,s,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(s,a)}storeNode(t,e,i,s=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(e==i)return;if(o.buffer[l-2]>=e){o.buffer[l-2]=i;return}}}if(!n||this.pos==i)this.buffer.push(t,e,i,s);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=s}}shift(t,e,i,s){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let n=t,{parser:o}=this.p;this.pos=s;let l=o.stateFlag(n,1);!l&&(s>i||e<=o.maxNode)&&(this.reducePos=s),this.pushState(n,l?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,s,4)}else this.pos=s,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,s,4)}apply(t,e,i,s){t&65536?this.reduce(t):this.shift(t,e,i,s)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let s=this.pos;this.reducePos=this.pos=s+t.length,this.pushState(e,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),s=t.bufferBase+e;for(;t&&s==t.bufferBase;)t=t.parent;return new Ci(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Xo(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let s=[];for(let n=0,o;n<e.length;n+=2)(o=e[n+1])!=this.state&&this.p.parser.hasAction(o,t)&&s.push(e[n],o);if(this.stack.length<120)for(let n=0;s.length<8&&n<e.length;n+=2){let o=e[n+1];s.some((l,h)=>h&1&&l==o)||s.push(e[n],o)}e=s}let i=[];for(let s=0;s<e.length&&i.length<4;s+=2){let n=e[s+1];if(n==this.state)continue;let o=this.split();o.pushState(n,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[s],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,s=e&65535,n=this.stack.length-i*3;if(n<0||t.getGoto(this.stack[n],s,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(s,n)=>{if(!e.includes(s))return e.push(s),t.allActions(s,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-n;if(l>1){let h=o&65535,a=this.stack.length-l*3;if(a>=0&&t.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,n+1);if(l!=null)return l}})};return i(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:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new bn(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class bn{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class Xo{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=s}}class Ai{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new Ai(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.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 Ai(this.stack,this.pos,this.index)}}function ri(r,t=Uint16Array){if(typeof r!="string")return r;let e=null;for(let i=0,s=0;i<r.length;){let n=0;for(;;){let o=r.charCodeAt(i++),l=!1;if(o==126){n=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),n+=h,l)break;n*=46}e?e[s++]=n:e=new t(n)}return e}class wi{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const xn=new wi;class Zo{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=xn,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,s=this.rangeIndex,n=this.pos+t;for(;n<i.from;){if(!s)return null;let o=this.ranges[--s];n-=i.from-o.to,i=o}for(;e<0?n>i.to:n>=i.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];n+=o.from-i.to,i=o}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,s;if(e>=0&&e<this.chunk.length)i=this.pos+t,s=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(i=n,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),s=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),s}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,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(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,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(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=xn,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let s of this.ranges){if(s.from>=e)break;s.to>t&&(i+=this.input.read(Math.max(s.from,t),Math.min(s.to,e)))}return i}}class ue{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;tl(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}ue.prototype.contextual=ue.prototype.fallback=ue.prototype.extend=!1;ue.prototype.fallback=ue.prototype.extend=!1;function tl(r,t,e,i,s,n){let o=0,l=1<<i,{dialect:h}=e.p.parser;t:for(;(l&r[o])!=0;){let a=r[o+1];for(let d=o+3;d<a;d+=2)if((r[d+1]&l)>0){let p=r[d];if(h.allows(p)&&(t.token.value==-1||t.token.value==p||el(p,t.token.value,s,n))){t.acceptToken(p);break}}let f=t.next,c=0,u=r[o+2];if(t.next<0&&u>c&&r[a+u*3-3]==65535){o=r[a+u*3-1];continue t}for(;c<u;){let d=c+u>>1,p=a+d+(d<<1),g=r[p],m=r[p+1]||65536;if(f<g)u=d;else if(f>=m)c=d+1;else{o=r[p+2],t.advance();continue t}}break}}function yn(r,t,e){for(let i=t,s;(s=r[i])!=65535;i++)if(s==e)return i-t;return-1}function el(r,t,e,i){let s=yn(e,i,t);return s<0||yn(e,i,r)<s}const at=typeof process<"u"&&mn&&/\bparse\b/.test(mn.LOG);let Ui=null;function wn(r,t,e){let i=r.cursor(U.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(r.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:r.length}}class il{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?wn(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?wn(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],s=this.index[e];if(s==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[s],o=this.start[e]+i.positions[s];if(o>t)return this.nextStart=o,null;if(n instanceof Y){if(o==t){if(o<this.safeFrom)return null;let l=o+n.length;if(l<=this.safeTo){let h=n.prop(L.lookAhead);if(!h||l+h<this.fragment.to)return n}}this.index[e]++,o+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+n.length}}}class sl{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new wi)}getActions(t){let e=0,i=null,{parser:s}=t.p,{tokenizers:n}=s,o=s.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let a=0;a<n.length;a++){if((1<<a&o)==0)continue;let f=n[a],c=this.tokens[a];if(!(i&&!f.fallback)&&((f.contextual||c.start!=t.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,f,t),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!f.extend&&(i=c,e>u))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!i&&t.pos==this.stream.end&&(i=new wi,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new wi,{pos:i,p:s}=t;return e.start=i,e.end=Math.min(i+1,s.stream.end),e.value=i==s.stream.end?s.parser.eofTerm:0,e}updateCachedToken(t,e,i){let s=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(s,t),i),t.value>-1){let{parser:n}=i.p;for(let o=0;o<n.specialized.length;o++)if(n.specialized[o]==t.value){let l=n.specializers[o](this.stream.read(t.start,t.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?t.value=l>>1:t.extended=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(s+1)}putAction(t,e,i,s){for(let n=0;n<s;n+=3)if(this.actions[n]==t)return s;return this.actions[s++]=t,this.actions[s++]=e,this.actions[s++]=i,s}addActions(t,e,i,s){let{state:n}=t,{parser:o}=t.p,{data:l}=o;for(let h=0;h<2;h++)for(let a=o.stateSlot(n,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=Et(l,a+2);else{s==0&&l[a+1]==2&&(s=this.putAction(Et(l,a+2),e,i,s));break}l[a]==e&&(s=this.putAction(Et(l,a+1),e,i,s))}return s}}class nl{constructor(t,e,i,s){this.parser=t,this.input=e,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Zo(e,s),this.tokens=new sl(t,this.stream),this.topTerm=t.top[1];let{from:n}=s[0];this.stacks=[Ci.start(this,t.top[0],n)],this.fragments=i.length&&this.stream.end-n>t.bufferLength*4?new il(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],s,n;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let l=t[o];for(;;){if(this.tokens.mainToken=null,l.pos>e)i.push(l);else{if(this.advanceStack(l,i,t))continue;{s||(s=[],n=[]),s.push(l);let h=this.tokens.getMainToken(l);n.push(h.value,h.end)}}break}}if(!i.length){let o=s&&ol(s);if(o)return at&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw at&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,n,i);if(o)return at&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let a=i[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue t}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let s=t.pos,{parser:n}=this,o=at?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,f=a?t.curContext.hash:0;for(let c=this.fragments.nodeAt(s);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?n.getGoto(t.state,c.type.id):-1;if(u>-1&&c.length&&(!a||(c.prop(L.contextHash)||0)==f))return t.useNode(c,u),at&&console.log(o+this.stackID(t)+` (via reuse of ${n.getName(c.type.id)})`),!0;if(!(c instanceof Y)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof Y&&c.positions[0]==0)c=d;else break}}let l=n.stateSlot(t.state,4);if(l>0)return t.reduce(l),at&&console.log(o+this.stackID(t)+` (via always-reduce ${n.getName(l&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],u=h[a++],d=a==h.length||!i,p=d?t:t.split(),g=this.tokens.mainToken;if(p.apply(f,c,g?g.start:p.pos,u),at&&console.log(o+this.stackID(p)+` (via ${(f&65536)==0?"shift":`reduce of ${n.getName(f&65535)}`} for ${n.getName(c)} @ ${s}${p==t?"":", split"})`),d)return!0;p.pos>s?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return kn(t,e),!0}}runRecovery(t,e,i){let s=null,n=!1;for(let o=0;o<t.length;o++){let l=t[o],h=e[o<<1],a=e[(o<<1)+1],f=at?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),at&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=f;for(let d=0;d<10&&c.forceReduce()&&(at&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)at&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))at&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),at&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),kn(l,i)):(!s||s.score<c.score)&&(s=c)}return s}stackToTree(t){return t.close(),Y.build({buffer:Ai.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Ui||(Ui=new WeakMap)).get(t);return e||Ui.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function kn(r,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==r.pos&&i.sameState(r)){t[e].score<r.score&&(t[e]=r);return}}t.push(r)}class rl{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}}class Oi extends Sr{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let i=Object.keys(t.topRules).map(l=>t.topRules[l][1]),s=[];for(let l=0;l<e.length;l++)s.push([]);function n(l,h,a){s[l].push([h,h.deserialize(String(a))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=L[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)n(f,h,l[a++]);else{let c=l[a+-f];for(let u=-f;u>0;u--)n(l[a++],h,c);a++}}}this.nodeSet=new Ks(e.map((l,h)=>ht.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:s[h],top:i.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=xr;let o=ri(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Sn),this.states=ri(t.states,Uint32Array),this.data=ri(t.stateData),this.goto=ri(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new ue(o,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let s=new nl(this,t,e,i);for(let n of this.wrappers)s=n(s,t,e,i);return s}getGoto(t,e,i=!1){let s=this.goto;if(e>=s[0])return-1;for(let n=s[e+1];;){let o=s[n++],l=o&1,h=s[n++];if(l&&i)return h;for(let a=n+(o>>1);n<a;n++)if(s[n]==t)return h;if(l)return-1}}hasAction(t,e){let i=this.data;for(let s=0;s<2;s++)for(let n=this.stateSlot(t,s?2:1),o;;n+=3){if((o=i[n])==65535)if(i[n+1]==1)o=i[n=Et(i,n+2)];else{if(i[n+1]==2)return Et(i,n+2);break}if(o==e||o==0)return Et(i,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),s=i?e(i):void 0;for(let n=this.stateSlot(t,1);s==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Et(this.data,n+2);else break;s=e(Et(this.data,n+1))}return s}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=Et(this.data,i+2);else break;if((this.data[i+2]&1)==0){let s=this.data[i+1];e.some((n,o)=>o&1&&n==s)||e.push(this.data[i],s)}}return e}configure(t){let e=Object.assign(Object.create(Oi.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let s=t.tokenizers.find(n=>n.from==i);return s?s.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,s)=>{let n=t.specializers.find(l=>l.from==i.external);if(!n)return i;let o=Object.assign(Object.assign({},i),{external:n.to});return e.specializers[s]=Sn(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let o=e.indexOf(n);o>=0&&(i[o]=!0)}let s=null;for(let n=0;n<e.length;n++)if(!i[n])for(let o=this.dialects[e[n]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new rl(t,i,s)}static deserialize(t){return new Oi(t)}}function Et(r,t){return r[t]|r[t+1]<<16}function ol(r){let t=null;for(let e of r){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function Sn(r){if(r.external){let t=r.extend?1:0;return(e,i)=>r.external(e,i)<<1|t}return r.get}let ll=0;class pt{constructor(t,e,i,s){this.name=t,this.set=e,this.base=i,this.modified=s,this.id=ll++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof pt&&(e=t),e?.base)throw new Error("Can not derive from a modified tag");let s=new pt(i,[],null,[]);if(s.set.push(s),e)for(let n of e.set)s.set.push(n);return s}static defineModifier(t){let e=new Mi(t);return i=>i.modified.indexOf(e)>-1?i:Mi.get(i.base||i,i.modified.concat(e).sort((s,n)=>s.id-n.id))}}let hl=0;class Mi{constructor(t){this.name=t,this.instances=[],this.id=hl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(l=>l.base==t&&al(e,l.modified));if(i)return i;let s=[],n=new pt(t.name,s,t,e);for(let l of e)l.instances.push(n);let o=fl(e);for(let l of t.set)if(!l.modified.length)for(let h of o)s.push(Mi.get(l,h));return n}}function al(r,t){return r.length==t.length&&r.every((e,i)=>e==t[i])}function fl(r){let t=[[]];for(let e=0;e<r.length;e++)for(let i=0,s=t.length;i<s;i++)t.push(t[i].concat(r[e]));return t.sort((e,i)=>i.length-e.length)}function vr(r){let t=Object.create(null);for(let e in r){let i=r[e];Array.isArray(i)||(i=[i]);for(let s of e.split(" "))if(s){let n=[],o=2,l=s;for(let c=0;;){if(l=="..."&&c>0&&c+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(n.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==s.length)break;let d=s[c++];if(c==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(c)}let h=n.length-1,a=n[h];if(!a)throw new RangeError("Invalid path: "+s);let f=new qe(i,o,h>0?n.slice(0,h):null);t[a]=f.sort(t[a])}}return Cr.add(t)}const Cr=new L({combine(r,t){let e,i,s;for(;r||t;){if(!r||t&&r.depth>=t.depth?(s=t,t=t.next):(s=r,r=r.next),e&&e.mode==s.mode&&!s.context&&!e.context)continue;let n=new qe(s.tags,s.mode,s.context);e?e.next=n:i=n,e=n}return i}});class qe{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}qe.empty=new qe([],2,null);function Ar(r,t){let e=Object.create(null);for(let n of r)if(!Array.isArray(n.tag))e[n.tag.id]=n.class;else for(let o of n.tag)e[o.id]=n.class;let{scope:i,all:s=null}=t||{};return{style:n=>{let o=s;for(let l of n)for(let h of l.set){let a=e[h.id];if(a){o=o?o+" "+a:a;break}}return o},scope:i}}function cl(r,t){let e=null;for(let i of r){let s=i.style(t);s&&(e=e?e+" "+s:s)}return e}function ul(r,t,e,i=0,s=r.length){let n=new dl(i,Array.isArray(t)?t:[t],e);n.highlightRange(r.cursor(),i,s,"",n.highlighters),n.flush(s)}class dl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,n){let{type:o,from:l,to:h}=t;if(l>=i||h<=e)return;o.isTop&&(n=this.highlighters.filter(d=>!d.scope||d.scope(o)));let a=s,f=pl(t)||qe.empty,c=cl(n,f.tags);if(c&&(a&&(a+=" "),a+=c,f.mode==1&&(s+=(s?" ":"")+c)),this.startSpan(Math.max(e,l),a),f.opaque)return;let u=t.tree&&t.tree.prop(L.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=t.firstChild();for(let m=0,b=l;;m++){let A=m<u.overlay.length?u.overlay[m]:null,M=A?A.from+l:h,E=Math.max(e,b),O=Math.min(i,M);if(E<O&&g)for(;t.from<O&&(this.highlightRange(t,E,O,s,n),this.startSpan(Math.min(O,t.to),a),!(t.to>=M||!t.nextSibling())););if(!A||M>i)break;b=A.to+l,b>e&&(this.highlightRange(d.cursor(),Math.max(e,A.from+l),Math.min(i,b),"",p),this.startSpan(Math.min(i,b),a))}g&&t.parent()}else if(t.firstChild()){u&&(s="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,n),this.startSpan(Math.min(i,t.to),a)}while(t.nextSibling());t.parent()}}}function pl(r){let t=r.type.prop(Cr);for(;t&&t.context&&!r.matchContext(t.context);)t=t.next;return t||null}const w=pt.define,oi=w(),Ht=w(),vn=w(Ht),Cn=w(Ht),Vt=w(),li=w(Vt),Ji=w(Vt),Tt=w(),Yt=w(Tt),At=w(),Ot=w(),ps=w(),Me=w(ps),hi=w(),x={comment:oi,lineComment:w(oi),blockComment:w(oi),docComment:w(oi),name:Ht,variableName:w(Ht),typeName:vn,tagName:w(vn),propertyName:Cn,attributeName:w(Cn),className:w(Ht),labelName:w(Ht),namespace:w(Ht),macroName:w(Ht),literal:Vt,string:li,docString:w(li),character:w(li),attributeValue:w(li),number:Ji,integer:w(Ji),float:w(Ji),bool:w(Vt),regexp:w(Vt),escape:w(Vt),color:w(Vt),url:w(Vt),keyword:At,self:w(At),null:w(At),atom:w(At),unit:w(At),modifier:w(At),operatorKeyword:w(At),controlKeyword:w(At),definitionKeyword:w(At),moduleKeyword:w(At),operator:Ot,derefOperator:w(Ot),arithmeticOperator:w(Ot),logicOperator:w(Ot),bitwiseOperator:w(Ot),compareOperator:w(Ot),updateOperator:w(Ot),definitionOperator:w(Ot),typeOperator:w(Ot),controlOperator:w(Ot),punctuation:ps,separator:w(ps),bracket:Me,angleBracket:w(Me),squareBracket:w(Me),paren:w(Me),brace:w(Me),content:Tt,heading:Yt,heading1:w(Yt),heading2:w(Yt),heading3:w(Yt),heading4:w(Yt),heading5:w(Yt),heading6:w(Yt),contentSeparator:w(Tt),list:w(Tt),quote:w(Tt),emphasis:w(Tt),strong:w(Tt),link:w(Tt),monospace:w(Tt),strikethrough:w(Tt),inserted:w(),deleted:w(),changed:w(),invalid:w(),meta:hi,documentMeta:w(hi),annotation:w(hi),processingInstruction:w(hi),definition:pt.defineModifier("definition"),constant:pt.defineModifier("constant"),function:pt.defineModifier("function"),standard:pt.defineModifier("standard"),local:pt.defineModifier("local"),special:pt.defineModifier("special")};for(let r in x){let t=x[r];t instanceof pt&&(t.name=r)}Ar([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);const gl=vr({String:x.string,Number:x.number,"True False":x.bool,PropertyName:x.propertyName,Null:x.null,", :":x.separator,"[ ]":x.squareBracket,"{ }":x.brace}),ml=Oi.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[gl],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0});let gs=[],Or=[];(()=>{let r="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<r.length;t++)(t%2?Or:gs).push(e=e+r[t])})();function bl(r){if(r<768)return!1;for(let t=0,e=gs.length;;){let i=t+e>>1;if(r<gs[i])e=i;else if(r>=Or[i])t=i+1;else return!0;if(t==e)return!1}}function An(r){return r>=127462&&r<=127487}const On=8205;function xl(r,t,e=!0,i=!0){return(e?Mr:yl)(r,t,i)}function Mr(r,t,e){if(t==r.length)return t;t&&Tr(r.charCodeAt(t))&&Pr(r.charCodeAt(t-1))&&t--;let i=Yi(r,t);for(t+=Mn(i);t<r.length;){let s=Yi(r,t);if(i==On||s==On||e&&bl(s))t+=Mn(s),i=s;else if(An(s)){let n=0,o=t-2;for(;o>=0&&An(Yi(r,o));)n++,o-=2;if(n%2==0)break;t+=2}else break}return t}function yl(r,t,e){for(;t>0;){let i=Mr(r,t-2,e);if(i<t)return i;t--}return 0}function Yi(r,t){let e=r.charCodeAt(t);if(!Pr(e)||t+1==r.length)return e;let i=r.charCodeAt(t+1);return Tr(i)?(e-55296<<10)+(i-56320)+65536:e}function Tr(r){return r>=56320&&r<57344}function Pr(r){return r>=55296&&r<56320}function Mn(r){return r<65536?1:2}class W{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=be(this,t,e);let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),Pt.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=be(this,t,e);let i=[];return this.decompose(t,e,i,0),Pt.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new Ie(this),n=new Ie(t);for(let o=e,l=e;;){if(s.next(o),n.next(o),o=0,s.lineBreak!=n.lineBreak||s.done!=n.done||s.value!=n.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(t=1){return new Ie(this,t)}iterRange(t,e=this.length){return new Dr(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new Br(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?W.empty:t.length<=32?new J(t):Pt.from(J.split(t,[]))}}class J extends W{constructor(t,e=wl(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let n=0;;n++){let o=this.text[n],l=s+o.length;if((e?i:l)>=t)return new kl(s,l,i,o);s=l+1,i++}}decompose(t,e,i,s){let n=t<=0&&e>=this.length?this:new J(Tn(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(s&1){let o=i.pop(),l=ki(n.text,o.text.slice(),0,n.length);if(l.length<=32)i.push(new J(l,o.length+n.length));else{let h=l.length>>1;i.push(new J(l.slice(0,h)),new J(l.slice(h)))}}else i.push(n)}replace(t,e,i){if(!(i instanceof J))return super.replace(t,e,i);[t,e]=be(this,t,e);let s=ki(this.text,ki(i.text,Tn(this.text,0,t)),e),n=this.length+i.length-(e-t);return s.length<=32?new J(s,n):Pt.from(J.split(s,[]),n)}sliceString(t,e=this.length,i=`
|
|
1
|
+
import{d as Fo,u as Ho,o as Vo,r as ii,w as si,a as zo,c as fn,b as cn,e as qo,f as Qi,g as jo,h as Jt,t as un,v as $o,m as Ko,i as Qo}from"./playground.js";const xr=1024;let Go=0,Gi=class{constructor(t,e){this.from=t,this.to=e}};class L{constructor(t={}){this.id=Go++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=ht.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}}L.closedBy=new L({deserialize:r=>r.split(" ")});L.openedBy=new L({deserialize:r=>r.split(" ")});L.group=new L({deserialize:r=>r.split(" ")});L.isolate=new L({deserialize:r=>{if(r&&r!="rtl"&&r!="ltr"&&r!="auto")throw new RangeError("Invalid value for isolate: "+r);return r||"auto"}});L.contextHash=new L({perNode:!0});L.lookAhead=new L({perNode:!0});L.mounted=new L({perNode:!0});class Ne{constructor(t,e,i,s=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=s}static get(t){return t&&t.props&&t.props[L.mounted.id]}}const Uo=Object.create(null);class ht{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):Uo,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),s=new ht(t.name||"",e,t.id,i);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(s)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return s}prop(t){return this.props[t.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(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(L.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return i=>{for(let s=i.prop(L.group),n=-1;n<(s?s.length:0);n++){let o=e[n<0?i.name:s[n]];if(o)return o}}}}ht.none=new ht("",Object.create(null),0,8);class $s{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let s=null;for(let n of t){let o=n(i);if(o){s||(s=Object.assign({},i.props));let l=o[1],h=o[0];h.combine&&h.id in s&&(l=h.combine(s[h.id],l)),s[h.id]=l}}e.push(s?new ht(i.name,s,i.id,i.flags):i)}return new $s(e)}}const ni=new WeakMap,dn=new WeakMap;var _;(function(r){r[r.ExcludeBuffers=1]="ExcludeBuffers",r[r.IncludeAnonymous=2]="IncludeAnonymous",r[r.IgnoreMounts=4]="IgnoreMounts",r[r.IgnoreOverlays=8]="IgnoreOverlays",r[r.EnterBracketed=16]="EnterBracketed"})(_||(_={}));class Y{constructor(t,e,i,s,n){if(this.type=t,this.children=e,this.positions=i,this.length=s,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,l]of n)this.props[typeof o=="number"?o:o.id]=l}}toString(){let t=Ne.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let s=i.toString();s&&(e&&(e+=","),e+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new us(this.topNode,t)}cursorAt(t,e=0,i=0){let s=ni.get(this)||this.topNode,n=new us(s);return n.moveTo(t,e),ni.set(this,n._tree),n}get topNode(){return new mt(this,0,0,null)}resolve(t,e=0){let i=ze(ni.get(this)||this.topNode,t,e,!1);return ni.set(this,i),i}resolveInner(t,e=0){let i=ze(dn.get(this)||this.topNode,t,e,!0);return dn.set(this,i),i}resolveStack(t,e=0){return Yo(this,t,e)}iterate(t){let{enter:e,leave:i,from:s=0,to:n=this.length}=t,o=t.mode||0,l=(o&_.IncludeAnonymous)>0;for(let h=this.cursor(o|_.IncludeAnonymous);;){let a=!1;if(h.from<=n&&h.to>=s&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;a=!0}for(;a&&i&&(l||!h.type.isAnonymous)&&i(h),!h.nextSibling();){if(!h.parent())return;a=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Gs(ht.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,s)=>new Y(this.type,e,i,s,this.propValues),t.makeTree||((e,i,s)=>new Y(ht.none,e,i,s)))}static build(t){return Xo(t)}}Y.empty=new Y(ht.none,[],[],0);class Ks{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Ks(this.buffer,this.index)}}class $t{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return ht.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],s=this.set.types[e],n=s.name;if(/\W/.test(n)&&!s.isError&&(n=JSON.stringify(n)),t+=4,i==t)return n;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return n+"("+o.join(",")+")"}findChild(t,e,i,s,n){let{buffer:o}=this,l=-1;for(let h=t;h!=e&&!(yr(n,s,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(t,e,i){let s=this.buffer,n=new Uint16Array(e-t),o=0;for(let l=t,h=0;l<e;){n[h++]=s[l++],n[h++]=s[l++]-i;let a=n[h++]=s[l++]-i;n[h++]=s[l++]-t,o=Math.max(o,a)}return new $t(n,o,this.set)}}function yr(r,t,e,i){switch(r){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function ze(r,t,e,i){for(var s;r.from==r.to||(e<1?r.from>=t:r.from>t)||(e>-1?r.to<=t:r.to<t);){let o=!i&&r instanceof mt&&r.index<0?null:r.parent;if(!o)return r;r=o}let n=i?0:_.IgnoreOverlays;if(i)for(let o=r,l=o.parent;l;o=l,l=o.parent)o instanceof mt&&o.index<0&&((s=l.enter(t,e,n))===null||s===void 0?void 0:s.from)!=o.from&&(r=l);for(;;){let o=r.enter(t,e,n);if(!o)return r;r=o}}class wr{cursor(t=0){return new us(this,t)}getChild(t,e=null,i=null){let s=pn(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return pn(this,t,e,i)}resolve(t,e=0){return ze(this,t,e,!1)}resolveInner(t,e=0){return ze(this,t,e,!0)}matchContext(t){return cs(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let s=e.lastChild;if(!s||s.to!=e.to)break;s.type.isError&&s.from==s.to?(i=e,e=s.prevSibling):e=s}return i}get node(){return this}get next(){return this.parent}}class mt extends wr{constructor(t,e,i,s){super(),this._tree=t,this.from=e,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,s,n=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,a=e>0?l.length:-1;t!=a;t+=e){let f=l[t],c=h[t]+o.from,u;if(!(!(n&_.EnterBracketed&&f instanceof Y&&(u=Ne.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!yr(s,i,c,c+f.length))){if(f instanceof $t){if(n&_.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,e,i-c,s);if(d>-1)return new zt(new _o(o,f,t,c),null,d)}else if(n&_.IncludeAnonymous||!f.type.isAnonymous||Qs(f)){let d;if(!(n&_.IgnoreMounts)&&(d=Ne.get(f))&&!d.overlay)return new mt(d.tree,c,t,o);let p=new mt(f,c,t,o);return n&_.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(e<0?f.children.length-1:0,e,i,s,n)}}}if(n&_.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let s;if(!(i&_.IgnoreOverlays)&&(s=Ne.get(this._tree))&&s.overlay){let n=t-this.from,o=i&_.EnterBracketed&&s.bracketed;for(let{from:l,to:h}of s.overlay)if((e>0||o?l<=n:l<n)&&(e<0||o?h>=n:h>n))return new mt(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function pn(r,t,e,i){let s=r.cursor(),n=[];if(!s.firstChild())return n;if(e!=null){for(let o=!1;!o;)if(o=s.type.is(e),!s.nextSibling())return n}for(;;){if(i!=null&&s.type.is(i))return n;if(s.type.is(t)&&n.push(s.node),!s.nextSibling())return i==null?n:[]}}function cs(r,t,e=t.length-1){for(let i=r;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}class _o{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class zt extends wr{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return n<0?null:new zt(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&_.ExcludeBuffers)return null;let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new zt(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new zt(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new zt(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,n=i.buffer[this.index+3];if(n>s){let o=i.buffer[this.index+1];t.push(i.slice(s,n,o)),e.push(0)}return new Y(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function kr(r){if(!r.length)return null;let t=0,e=r[0];for(let n=1;n<r.length;n++){let o=r[n];(o.from>e.from||o.to<e.to)&&(e=o,t=n)}let i=e instanceof mt&&e.index<0?null:e.parent,s=r.slice();return i?s[t]=i:s.splice(t,1),new Jo(s,e)}class Jo{constructor(t,e){this.heads=t,this.node=e}get next(){return kr(this.heads)}}function Yo(r,t,e){let i=r.resolveInner(t,e),s=null;for(let n=i instanceof mt?i:i.context.parent;n;n=n.parent)if(n.index<0){let o=n.parent;(s||(s=[i])).push(o.resolve(t,e)),n=o}else{let o=Ne.get(n.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new mt(o.tree,o.overlay[0].from+n.from,-1,n);(s||(s=[i])).push(ze(l,t,e,!1))}}return s?kr(s):i}class us{get name(){return this.type.name}constructor(t,e=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=e&~_.EnterBracketed,t instanceof mt)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return t?t instanceof mt?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,n=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&_.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&_.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&_.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(e.findChild(s,this.index,-1,0,4))}else{let s=e.buffer[this.index+3];if(s<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index<s.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(s.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:i}=s)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let n=e+t,o=t<0?-1:i._tree.children.length;n!=o;n+=t){let l=i._tree.children[n];if(this.mode&_.IncludeAnonymous||l instanceof $t||!l.type.isAnonymous||Qs(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let s=this.index,n=this.stack.length;n>=0;){for(let o=t;o;o=o._parent)if(o.index==s){if(s==this.index)return o;e=o,i=n+1;break t}s=this.stack[--n]}for(let s=i;s<this.stack.length;s++)e=new zt(this.buffer,e,this.stack[s]);return this.bufferNode=new zt(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let s=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&e&&e(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(t){if(!this.buffer)return cs(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let s=t.length-1,n=this.stack.length-1;s>=0;n--){if(n<0)return cs(this._tree,t,s);let o=i[e.buffer[this.stack[n]]];if(!o.isAnonymous){if(t[s]&&t[s]!=o.name)return!1;s--}}return!0}}function Qs(r){return r.children.some(t=>t instanceof $t||!t.type.isAnonymous||Qs(t))}function Xo(r){var t;let{buffer:e,nodeSet:i,maxBufferLength:s=xr,reused:n=[],minRepeatType:o=i.types.length}=r,l=Array.isArray(e)?new Ks(e,e.length):e,h=i.types,a=0,f=0;function c(O,P,C,G,F,N){let{id:R,start:T,end:j,size:y}=l,S=f,I=a;if(y<0)if(l.next(),y==-1){let Rt=n[R];C.push(Rt),G.push(T-O);return}else if(y==-3){a=R;return}else if(y==-4){f=R;return}else throw new RangeError(`Unrecognized record size: ${y}`);let H=h[R],Q,U,he=T-O;if(j-T<=s&&(U=m(l.pos-P,F))){let Rt=new Uint16Array(U.size-U.skip),dt=l.pos-U.size,Ct=Rt.length;for(;l.pos>dt;)Ct=b(U.start,Rt,Ct);Q=new $t(Rt,j-U.start,i),he=U.start-O}else{let Rt=l.pos-y;l.next();let dt=[],Ct=[],_t=R>=o?R:-1,ae=0,ei=j;for(;l.pos>Rt;)_t>=0&&l.id==_t&&l.size>=0?(l.end<=ei-s&&(p(dt,Ct,T,ae,l.end,ei,_t,S,I),ae=dt.length,ei=l.end),l.next()):N>2500?u(T,Rt,dt,Ct):c(T,Rt,dt,Ct,_t,N+1);if(_t>=0&&ae>0&&ae<dt.length&&p(dt,Ct,T,ae,T,ei,_t,S,I),dt.reverse(),Ct.reverse(),_t>-1&&ae>0){let an=d(H,I);Q=Gs(H,dt,Ct,0,dt.length,0,j-T,an,an)}else Q=g(H,dt,Ct,j-T,S-j,I)}C.push(Q),G.push(he)}function u(O,P,C,G){let F=[],N=0,R=-1;for(;l.pos>P;){let{id:T,start:j,end:y,size:S}=l;if(S>4)l.next();else{if(R>-1&&j<R)break;R<0&&(R=y-s),F.push(T,j,y),N++,l.next()}}if(N){let T=new Uint16Array(N*4),j=F[F.length-2];for(let y=F.length-3,S=0;y>=0;y-=3)T[S++]=F[y],T[S++]=F[y+1]-j,T[S++]=F[y+2]-j,T[S++]=S;C.push(new $t(T,F[2]-j,i)),G.push(j-O)}}function d(O,P){return(C,G,F)=>{let N=0,R=C.length-1,T,j;if(R>=0&&(T=C[R])instanceof Y){if(!R&&T.type==O&&T.length==F)return T;(j=T.prop(L.lookAhead))&&(N=G[R]+T.length+j)}return g(O,C,G,F,N,P)}}function p(O,P,C,G,F,N,R,T,j){let y=[],S=[];for(;O.length>G;)y.push(O.pop()),S.push(P.pop()+C-F);O.push(g(i.types[R],y,S,N-F,T-N,j)),P.push(F-C)}function g(O,P,C,G,F,N,R){if(N){let T=[L.contextHash,N];R=R?[T].concat(R):[T]}if(F>25){let T=[L.lookAhead,F];R=R?[T].concat(R):[T]}return new Y(O,P,C,G,R)}function m(O,P){let C=l.fork(),G=0,F=0,N=0,R=C.end-s,T={size:0,start:0,skip:0};t:for(let j=C.pos-O;C.pos>j;){let y=C.size;if(C.id==P&&y>=0){T.size=G,T.start=F,T.skip=N,N+=4,G+=4,C.next();continue}let S=C.pos-y;if(y<0||S<j||C.start<R)break;let I=C.id>=o?4:0,H=C.start;for(C.next();C.pos>S;){if(C.size<0)if(C.size==-3||C.size==-4)I+=4;else break t;else C.id>=o&&(I+=4);C.next()}F=H,G+=y,N+=I}return(P<0||G==O)&&(T.size=G,T.start=F,T.skip=N),T.size>4?T:void 0}function b(O,P,C){let{id:G,start:F,end:N,size:R}=l;if(l.next(),R>=0&&G<o){let T=C;if(R>4){let j=l.pos-(R-4);for(;l.pos>j;)C=b(O,P,C)}P[--C]=T,P[--C]=N-O,P[--C]=F-O,P[--C]=G}else R==-3?a=G:R==-4&&(f=G);return C}let A=[],M=[];for(;l.pos>0;)c(r.start||0,r.bufferStart||0,A,M,-1,0);let E=(t=r.length)!==null&&t!==void 0?t:A.length?M[0]+A[0].length:0;return new Y(h[r.topID],A.reverse(),M.reverse(),E)}const gn=new WeakMap;function yi(r,t){if(!r.isAnonymous||t instanceof $t||t.type!=r)return 1;let e=gn.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=r||!(i instanceof Y)){e=1;break}e+=yi(r,i)}gn.set(t,e)}return e}function Gs(r,t,e,i,s,n,o,l,h){let a=0;for(let p=i;p<s;p++)a+=yi(r,t[p]);let f=Math.ceil(a*1.5/8),c=[],u=[];function d(p,g,m,b,A){for(let M=m;M<b;){let E=M,O=g[M],P=yi(r,p[M]);for(M++;M<b;M++){let C=yi(r,p[M]);if(P+C>=f)break;P+=C}if(M==E+1){if(P>f){let C=p[E];d(C.children,C.positions,0,C.children.length,g[E]+A);continue}c.push(p[E])}else{let C=g[M-1]+p[M-1].length-O;c.push(Gs(r,p,g,E,M,O,C,null,h))}u.push(O+A-n)}}return d(t,e,i,s,0),(l||h)(c,u,o)}class ie{constructor(t,e,i,s,n=!1,o=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(n?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,e=[],i=!1){let s=[new ie(0,t.length,t,0,!1,i)];for(let n of e)n.to>t.length&&s.push(n);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],n=1,o=t.length?t[0]:null;for(let l=0,h=0,a=0;;l++){let f=l<e.length?e[l]:null,c=f?f.fromA:1e9;if(c-h>=i)for(;o&&o.from<c;){let u=o;if(h>=u.from||c<=u.to||a){let d=Math.max(u.from,h)-a,p=Math.min(u.to,c)-a;u=d>=p?null:new ie(d,p,u.tree,u.offset+a,l>0,!!f)}if(u&&s.push(u),o.to>c)break;o=n<t.length?t[n++]:null}if(!f)break;h=f.toA,a=f.toA-f.toB}return s}}class Sr{startParse(t,e,i){return typeof t=="string"&&(t=new Zo(t)),i=i?i.length?i.map(s=>new Gi(s.from,s.to)):[new Gi(0,0)]:[new Gi(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let n=s.advance();if(n)return n}}}class Zo{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new L({perNode:!0});var mn={};class Ci{constructor(t,e,i,s,n,o,l,h,a,f=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=s,this.pos=n,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let s=t.parser.context;return new Ci(t,[],e,i,i,0,[],0,s?new bn(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,s=t&65535,{parser:n}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=n.dynamicPrecedence(s);if(l&&(this.score+=l),i==0){this.pushState(n.getGoto(this.state,s,!0),this.reducePos),s<n.minRepeatTerm&&this.storeNode(s,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(s,this.reducePos);return}let h=this.stack.length-(i-1)*3-(t&262144?6:0),a=h?this.stack[h-2]:this.p.ranges[0].from,f=this.reducePos-a;f>=2e3&&!(!((e=this.p.parser.nodeSet.types[s])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=f):this.p.lastBigReductionSize<f&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=f));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(s<n.minRepeatTerm||t&131072){let d=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(s,a,d,u+4,!0)}if(t&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=n.getGoto(d,s,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(s,a)}storeNode(t,e,i,s=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(e==i)return;if(o.buffer[l-2]>=e){o.buffer[l-2]=i;return}}}if(!n||this.pos==i)this.buffer.push(t,e,i,s);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=s}}shift(t,e,i,s){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let n=t,{parser:o}=this.p;this.pos=s;let l=o.stateFlag(n,1);!l&&(s>i||e<=o.maxNode)&&(this.reducePos=s),this.pushState(n,l?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,s,4)}else this.pos=s,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,s,4)}apply(t,e,i,s){t&65536?this.reduce(t):this.shift(t,e,i,s)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let s=this.pos;this.reducePos=this.pos=s+t.length,this.pushState(e,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),s=t.bufferBase+e;for(;t&&s==t.bufferBase;)t=t.parent;return new Ci(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new tl(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let s=[];for(let n=0,o;n<e.length;n+=2)(o=e[n+1])!=this.state&&this.p.parser.hasAction(o,t)&&s.push(e[n],o);if(this.stack.length<120)for(let n=0;s.length<8&&n<e.length;n+=2){let o=e[n+1];s.some((l,h)=>h&1&&l==o)||s.push(e[n],o)}e=s}let i=[];for(let s=0;s<e.length&&i.length<4;s+=2){let n=e[s+1];if(n==this.state)continue;let o=this.split();o.pushState(n,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[s],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,s=e&65535,n=this.stack.length-i*3;if(n<0||t.getGoto(this.stack[n],s,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(s,n)=>{if(!e.includes(s))return e.push(s),t.allActions(s,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-n;if(l>1){let h=o&65535,a=this.stack.length-l*3;if(a>=0&&t.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,n+1);if(l!=null)return l}})};return i(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:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new bn(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class bn{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class tl{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=s}}class Ai{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new Ai(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.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 Ai(this.stack,this.pos,this.index)}}function ri(r,t=Uint16Array){if(typeof r!="string")return r;let e=null;for(let i=0,s=0;i<r.length;){let n=0;for(;;){let o=r.charCodeAt(i++),l=!1;if(o==126){n=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),n+=h,l)break;n*=46}e?e[s++]=n:e=new t(n)}return e}class wi{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const xn=new wi;class el{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=xn,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,s=this.rangeIndex,n=this.pos+t;for(;n<i.from;){if(!s)return null;let o=this.ranges[--s];n-=i.from-o.to,i=o}for(;e<0?n>i.to:n>=i.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];n+=o.from-i.to,i=o}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,s;if(e>=0&&e<this.chunk.length)i=this.pos+t,s=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(i=n,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),s=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),s}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,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(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,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(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=xn,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let s of this.ranges){if(s.from>=e)break;s.to>t&&(i+=this.input.read(Math.max(s.from,t),Math.min(s.to,e)))}return i}}class ue{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;il(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}ue.prototype.contextual=ue.prototype.fallback=ue.prototype.extend=!1;ue.prototype.fallback=ue.prototype.extend=!1;function il(r,t,e,i,s,n){let o=0,l=1<<i,{dialect:h}=e.p.parser;t:for(;(l&r[o])!=0;){let a=r[o+1];for(let d=o+3;d<a;d+=2)if((r[d+1]&l)>0){let p=r[d];if(h.allows(p)&&(t.token.value==-1||t.token.value==p||sl(p,t.token.value,s,n))){t.acceptToken(p);break}}let f=t.next,c=0,u=r[o+2];if(t.next<0&&u>c&&r[a+u*3-3]==65535){o=r[a+u*3-1];continue t}for(;c<u;){let d=c+u>>1,p=a+d+(d<<1),g=r[p],m=r[p+1]||65536;if(f<g)u=d;else if(f>=m)c=d+1;else{o=r[p+2],t.advance();continue t}}break}}function yn(r,t,e){for(let i=t,s;(s=r[i])!=65535;i++)if(s==e)return i-t;return-1}function sl(r,t,e,i){let s=yn(e,i,t);return s<0||yn(e,i,r)<s}const at=typeof process<"u"&&mn&&/\bparse\b/.test(mn.LOG);let Ui=null;function wn(r,t,e){let i=r.cursor(_.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(r.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:r.length}}class nl{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?wn(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?wn(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],s=this.index[e];if(s==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[s],o=this.start[e]+i.positions[s];if(o>t)return this.nextStart=o,null;if(n instanceof Y){if(o==t){if(o<this.safeFrom)return null;let l=o+n.length;if(l<=this.safeTo){let h=n.prop(L.lookAhead);if(!h||l+h<this.fragment.to)return n}}this.index[e]++,o+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+n.length}}}class rl{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new wi)}getActions(t){let e=0,i=null,{parser:s}=t.p,{tokenizers:n}=s,o=s.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let a=0;a<n.length;a++){if((1<<a&o)==0)continue;let f=n[a],c=this.tokens[a];if(!(i&&!f.fallback)&&((f.contextual||c.start!=t.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,f,t),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!f.extend&&(i=c,e>u))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!i&&t.pos==this.stream.end&&(i=new wi,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new wi,{pos:i,p:s}=t;return e.start=i,e.end=Math.min(i+1,s.stream.end),e.value=i==s.stream.end?s.parser.eofTerm:0,e}updateCachedToken(t,e,i){let s=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(s,t),i),t.value>-1){let{parser:n}=i.p;for(let o=0;o<n.specialized.length;o++)if(n.specialized[o]==t.value){let l=n.specializers[o](this.stream.read(t.start,t.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?t.value=l>>1:t.extended=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(s+1)}putAction(t,e,i,s){for(let n=0;n<s;n+=3)if(this.actions[n]==t)return s;return this.actions[s++]=t,this.actions[s++]=e,this.actions[s++]=i,s}addActions(t,e,i,s){let{state:n}=t,{parser:o}=t.p,{data:l}=o;for(let h=0;h<2;h++)for(let a=o.stateSlot(n,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=Et(l,a+2);else{s==0&&l[a+1]==2&&(s=this.putAction(Et(l,a+2),e,i,s));break}l[a]==e&&(s=this.putAction(Et(l,a+1),e,i,s))}return s}}class ol{constructor(t,e,i,s){this.parser=t,this.input=e,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new el(e,s),this.tokens=new rl(t,this.stream),this.topTerm=t.top[1];let{from:n}=s[0];this.stacks=[Ci.start(this,t.top[0],n)],this.fragments=i.length&&this.stream.end-n>t.bufferLength*4?new nl(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],s,n;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let l=t[o];for(;;){if(this.tokens.mainToken=null,l.pos>e)i.push(l);else{if(this.advanceStack(l,i,t))continue;{s||(s=[],n=[]),s.push(l);let h=this.tokens.getMainToken(l);n.push(h.value,h.end)}}break}}if(!i.length){let o=s&&hl(s);if(o)return at&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw at&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,n,i);if(o)return at&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let a=i[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue t}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let s=t.pos,{parser:n}=this,o=at?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,f=a?t.curContext.hash:0;for(let c=this.fragments.nodeAt(s);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?n.getGoto(t.state,c.type.id):-1;if(u>-1&&c.length&&(!a||(c.prop(L.contextHash)||0)==f))return t.useNode(c,u),at&&console.log(o+this.stackID(t)+` (via reuse of ${n.getName(c.type.id)})`),!0;if(!(c instanceof Y)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof Y&&c.positions[0]==0)c=d;else break}}let l=n.stateSlot(t.state,4);if(l>0)return t.reduce(l),at&&console.log(o+this.stackID(t)+` (via always-reduce ${n.getName(l&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],u=h[a++],d=a==h.length||!i,p=d?t:t.split(),g=this.tokens.mainToken;if(p.apply(f,c,g?g.start:p.pos,u),at&&console.log(o+this.stackID(p)+` (via ${(f&65536)==0?"shift":`reduce of ${n.getName(f&65535)}`} for ${n.getName(c)} @ ${s}${p==t?"":", split"})`),d)return!0;p.pos>s?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return kn(t,e),!0}}runRecovery(t,e,i){let s=null,n=!1;for(let o=0;o<t.length;o++){let l=t[o],h=e[o<<1],a=e[(o<<1)+1],f=at?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),at&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=f;for(let d=0;d<10&&c.forceReduce()&&(at&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)at&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))at&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),at&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),kn(l,i)):(!s||s.score<c.score)&&(s=c)}return s}stackToTree(t){return t.close(),Y.build({buffer:Ai.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Ui||(Ui=new WeakMap)).get(t);return e||Ui.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function kn(r,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==r.pos&&i.sameState(r)){t[e].score<r.score&&(t[e]=r);return}}t.push(r)}class ll{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}}class Oi extends Sr{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let i=Object.keys(t.topRules).map(l=>t.topRules[l][1]),s=[];for(let l=0;l<e.length;l++)s.push([]);function n(l,h,a){s[l].push([h,h.deserialize(String(a))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=L[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)n(f,h,l[a++]);else{let c=l[a+-f];for(let u=-f;u>0;u--)n(l[a++],h,c);a++}}}this.nodeSet=new $s(e.map((l,h)=>ht.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:s[h],top:i.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=xr;let o=ri(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Sn),this.states=ri(t.states,Uint32Array),this.data=ri(t.stateData),this.goto=ri(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new ue(o,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let s=new ol(this,t,e,i);for(let n of this.wrappers)s=n(s,t,e,i);return s}getGoto(t,e,i=!1){let s=this.goto;if(e>=s[0])return-1;for(let n=s[e+1];;){let o=s[n++],l=o&1,h=s[n++];if(l&&i)return h;for(let a=n+(o>>1);n<a;n++)if(s[n]==t)return h;if(l)return-1}}hasAction(t,e){let i=this.data;for(let s=0;s<2;s++)for(let n=this.stateSlot(t,s?2:1),o;;n+=3){if((o=i[n])==65535)if(i[n+1]==1)o=i[n=Et(i,n+2)];else{if(i[n+1]==2)return Et(i,n+2);break}if(o==e||o==0)return Et(i,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),s=i?e(i):void 0;for(let n=this.stateSlot(t,1);s==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=Et(this.data,n+2);else break;s=e(Et(this.data,n+1))}return s}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=Et(this.data,i+2);else break;if((this.data[i+2]&1)==0){let s=this.data[i+1];e.some((n,o)=>o&1&&n==s)||e.push(this.data[i],s)}}return e}configure(t){let e=Object.assign(Object.create(Oi.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let s=t.tokenizers.find(n=>n.from==i);return s?s.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,s)=>{let n=t.specializers.find(l=>l.from==i.external);if(!n)return i;let o=Object.assign(Object.assign({},i),{external:n.to});return e.specializers[s]=Sn(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let o=e.indexOf(n);o>=0&&(i[o]=!0)}let s=null;for(let n=0;n<e.length;n++)if(!i[n])for(let o=this.dialects[e[n]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new ll(t,i,s)}static deserialize(t){return new Oi(t)}}function Et(r,t){return r[t]|r[t+1]<<16}function hl(r){let t=null;for(let e of r){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function Sn(r){if(r.external){let t=r.extend?1:0;return(e,i)=>r.external(e,i)<<1|t}return r.get}let al=0;class pt{constructor(t,e,i,s){this.name=t,this.set=e,this.base=i,this.modified=s,this.id=al++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof pt&&(e=t),e?.base)throw new Error("Can not derive from a modified tag");let s=new pt(i,[],null,[]);if(s.set.push(s),e)for(let n of e.set)s.set.push(n);return s}static defineModifier(t){let e=new Mi(t);return i=>i.modified.indexOf(e)>-1?i:Mi.get(i.base||i,i.modified.concat(e).sort((s,n)=>s.id-n.id))}}let fl=0;class Mi{constructor(t){this.name=t,this.instances=[],this.id=fl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(l=>l.base==t&&cl(e,l.modified));if(i)return i;let s=[],n=new pt(t.name,s,t,e);for(let l of e)l.instances.push(n);let o=ul(e);for(let l of t.set)if(!l.modified.length)for(let h of o)s.push(Mi.get(l,h));return n}}function cl(r,t){return r.length==t.length&&r.every((e,i)=>e==t[i])}function ul(r){let t=[[]];for(let e=0;e<r.length;e++)for(let i=0,s=t.length;i<s;i++)t.push(t[i].concat(r[e]));return t.sort((e,i)=>i.length-e.length)}function vr(r){let t=Object.create(null);for(let e in r){let i=r[e];Array.isArray(i)||(i=[i]);for(let s of e.split(" "))if(s){let n=[],o=2,l=s;for(let c=0;;){if(l=="..."&&c>0&&c+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(n.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==s.length)break;let d=s[c++];if(c==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(c)}let h=n.length-1,a=n[h];if(!a)throw new RangeError("Invalid path: "+s);let f=new qe(i,o,h>0?n.slice(0,h):null);t[a]=f.sort(t[a])}}return Cr.add(t)}const Cr=new L({combine(r,t){let e,i,s;for(;r||t;){if(!r||t&&r.depth>=t.depth?(s=t,t=t.next):(s=r,r=r.next),e&&e.mode==s.mode&&!s.context&&!e.context)continue;let n=new qe(s.tags,s.mode,s.context);e?e.next=n:i=n,e=n}return i}});class qe{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}qe.empty=new qe([],2,null);function Ar(r,t){let e=Object.create(null);for(let n of r)if(!Array.isArray(n.tag))e[n.tag.id]=n.class;else for(let o of n.tag)e[o.id]=n.class;let{scope:i,all:s=null}=t||{};return{style:n=>{let o=s;for(let l of n)for(let h of l.set){let a=e[h.id];if(a){o=o?o+" "+a:a;break}}return o},scope:i}}function dl(r,t){let e=null;for(let i of r){let s=i.style(t);s&&(e=e?e+" "+s:s)}return e}function pl(r,t,e,i=0,s=r.length){let n=new gl(i,Array.isArray(t)?t:[t],e);n.highlightRange(r.cursor(),i,s,"",n.highlighters),n.flush(s)}class gl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,n){let{type:o,from:l,to:h}=t;if(l>=i||h<=e)return;o.isTop&&(n=this.highlighters.filter(d=>!d.scope||d.scope(o)));let a=s,f=ml(t)||qe.empty,c=dl(n,f.tags);if(c&&(a&&(a+=" "),a+=c,f.mode==1&&(s+=(s?" ":"")+c)),this.startSpan(Math.max(e,l),a),f.opaque)return;let u=t.tree&&t.tree.prop(L.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=t.firstChild();for(let m=0,b=l;;m++){let A=m<u.overlay.length?u.overlay[m]:null,M=A?A.from+l:h,E=Math.max(e,b),O=Math.min(i,M);if(E<O&&g)for(;t.from<O&&(this.highlightRange(t,E,O,s,n),this.startSpan(Math.min(O,t.to),a),!(t.to>=M||!t.nextSibling())););if(!A||M>i)break;b=A.to+l,b>e&&(this.highlightRange(d.cursor(),Math.max(e,A.from+l),Math.min(i,b),"",p),this.startSpan(Math.min(i,b),a))}g&&t.parent()}else if(t.firstChild()){u&&(s="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,n),this.startSpan(Math.min(i,t.to),a)}while(t.nextSibling());t.parent()}}}function ml(r){let t=r.type.prop(Cr);for(;t&&t.context&&!r.matchContext(t.context);)t=t.next;return t||null}const w=pt.define,oi=w(),Ht=w(),vn=w(Ht),Cn=w(Ht),Vt=w(),li=w(Vt),_i=w(Vt),Tt=w(),Yt=w(Tt),At=w(),Ot=w(),ds=w(),Me=w(ds),hi=w(),x={comment:oi,lineComment:w(oi),blockComment:w(oi),docComment:w(oi),name:Ht,variableName:w(Ht),typeName:vn,tagName:w(vn),propertyName:Cn,attributeName:w(Cn),className:w(Ht),labelName:w(Ht),namespace:w(Ht),macroName:w(Ht),literal:Vt,string:li,docString:w(li),character:w(li),attributeValue:w(li),number:_i,integer:w(_i),float:w(_i),bool:w(Vt),regexp:w(Vt),escape:w(Vt),color:w(Vt),url:w(Vt),keyword:At,self:w(At),null:w(At),atom:w(At),unit:w(At),modifier:w(At),operatorKeyword:w(At),controlKeyword:w(At),definitionKeyword:w(At),moduleKeyword:w(At),operator:Ot,derefOperator:w(Ot),arithmeticOperator:w(Ot),logicOperator:w(Ot),bitwiseOperator:w(Ot),compareOperator:w(Ot),updateOperator:w(Ot),definitionOperator:w(Ot),typeOperator:w(Ot),controlOperator:w(Ot),punctuation:ds,separator:w(ds),bracket:Me,angleBracket:w(Me),squareBracket:w(Me),paren:w(Me),brace:w(Me),content:Tt,heading:Yt,heading1:w(Yt),heading2:w(Yt),heading3:w(Yt),heading4:w(Yt),heading5:w(Yt),heading6:w(Yt),contentSeparator:w(Tt),list:w(Tt),quote:w(Tt),emphasis:w(Tt),strong:w(Tt),link:w(Tt),monospace:w(Tt),strikethrough:w(Tt),inserted:w(),deleted:w(),changed:w(),invalid:w(),meta:hi,documentMeta:w(hi),annotation:w(hi),processingInstruction:w(hi),definition:pt.defineModifier("definition"),constant:pt.defineModifier("constant"),function:pt.defineModifier("function"),standard:pt.defineModifier("standard"),local:pt.defineModifier("local"),special:pt.defineModifier("special")};for(let r in x){let t=x[r];t instanceof pt&&(t.name=r)}Ar([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);const bl=vr({String:x.string,Number:x.number,"True False":x.bool,PropertyName:x.propertyName,Null:x.null,", :":x.separator,"[ ]":x.squareBracket,"{ }":x.brace}),xl=Oi.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[bl],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0});let ps=[],Or=[];(()=>{let r="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<r.length;t++)(t%2?Or:ps).push(e=e+r[t])})();function yl(r){if(r<768)return!1;for(let t=0,e=ps.length;;){let i=t+e>>1;if(r<ps[i])e=i;else if(r>=Or[i])t=i+1;else return!0;if(t==e)return!1}}function An(r){return r>=127462&&r<=127487}const On=8205;function wl(r,t,e=!0,i=!0){return(e?Mr:kl)(r,t,i)}function Mr(r,t,e){if(t==r.length)return t;t&&Tr(r.charCodeAt(t))&&Pr(r.charCodeAt(t-1))&&t--;let i=Ji(r,t);for(t+=Mn(i);t<r.length;){let s=Ji(r,t);if(i==On||s==On||e&&yl(s))t+=Mn(s),i=s;else if(An(s)){let n=0,o=t-2;for(;o>=0&&An(Ji(r,o));)n++,o-=2;if(n%2==0)break;t+=2}else break}return t}function kl(r,t,e){for(;t>0;){let i=Mr(r,t-2,e);if(i<t)return i;t--}return 0}function Ji(r,t){let e=r.charCodeAt(t);if(!Pr(e)||t+1==r.length)return e;let i=r.charCodeAt(t+1);return Tr(i)?(e-55296<<10)+(i-56320)+65536:e}function Tr(r){return r>=56320&&r<57344}function Pr(r){return r>=55296&&r<56320}function Mn(r){return r<65536?1:2}class W{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=be(this,t,e);let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),Pt.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=be(this,t,e);let i=[];return this.decompose(t,e,i,0),Pt.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new Ie(this),n=new Ie(t);for(let o=e,l=e;;){if(s.next(o),n.next(o),o=0,s.lineBreak!=n.lineBreak||s.done!=n.done||s.value!=n.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(t=1){return new Ie(this,t)}iterRange(t,e=this.length){return new Dr(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new Br(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?W.empty:t.length<=32?new J(t):Pt.from(J.split(t,[]))}}class J extends W{constructor(t,e=Sl(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let n=0;;n++){let o=this.text[n],l=s+o.length;if((e?i:l)>=t)return new vl(s,l,i,o);s=l+1,i++}}decompose(t,e,i,s){let n=t<=0&&e>=this.length?this:new J(Tn(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(s&1){let o=i.pop(),l=ki(n.text,o.text.slice(),0,n.length);if(l.length<=32)i.push(new J(l,o.length+n.length));else{let h=l.length>>1;i.push(new J(l.slice(0,h)),new J(l.slice(h)))}}else i.push(n)}replace(t,e,i){if(!(i instanceof J))return super.replace(t,e,i);[t,e]=be(this,t,e);let s=ki(this.text,ki(i.text,Tn(this.text,0,t)),e),n=this.length+i.length-(e-t);return s.length<=32?new J(s,n):Pt.from(J.split(s,[]),n)}sliceString(t,e=this.length,i=`
|
|
2
2
|
`){[t,e]=be(this,t,e);let s="";for(let n=0,o=0;n<=e&&o<this.text.length;o++){let l=this.text[o],h=n+l.length;n>t&&o&&(s+=i),t<h&&e>n&&(s+=l.slice(Math.max(0,t-n),e-n)),n=h+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],s=-1;for(let n of t)i.push(n),s+=n.length+1,i.length==32&&(e.push(new J(i,s)),i=[],s=-1);return s>-1&&e.push(new J(i,s)),e}}class Pt extends W{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,s){for(let n=0;;n++){let o=this.children[n],l=s+o.length,h=i+o.lines-1;if((e?h:l)>=t)return o.lineInner(t,e,i,s);s=l+1,i=h+1}}decompose(t,e,i,s){for(let n=0,o=0;o<=e&&n<this.children.length;n++){let l=this.children[n],h=o+l.length;if(t<=h&&e>=o){let a=s&((o<=t?1:0)|(h>=e?2:0));o>=t&&h<=e&&!a?i.push(l):l.decompose(t-o,e-o,i,a)}o=h+1}}replace(t,e,i){if([t,e]=be(this,t,e),i.lines<this.lines)for(let s=0,n=0;s<this.children.length;s++){let o=this.children[s],l=n+o.length;if(t>=n&&e<=l){let h=o.replace(t-n,e-n,i),a=this.lines-o.lines+h.lines;if(h.lines<a>>4&&h.lines>a>>6){let f=this.children.slice();return f[s]=h,new Pt(f,this.length-(e-t)+i.length)}return super.replace(n,l,h)}n=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
|
|
3
|
-
`){[t,e]=be(this,t,e);let s="";for(let n=0,o=0;n<this.children.length&&o<=e;n++){let l=this.children[n],h=o+l.length;o>t&&n&&(s+=i),t<h&&e>o&&(s+=l.sliceString(t-o,e-o,i)),o=h+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Pt))return 0;let i=0,[s,n,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,n+=e){if(s==o||n==l)return i;let h=this.children[s],a=t.children[n];if(h!=a)return i+h.scanIdentical(a,e);i+=h.length+1}}static from(t,e=t.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new J(d,e)}let s=Math.max(32,i>>5),n=s<<1,o=s>>1,l=[],h=0,a=-1,f=[];function c(d){let p;if(d.lines>n&&d instanceof Pt)for(let g of d.children)c(g);else d.lines>o&&(h>o||!h)?(u(),l.push(d)):d instanceof J&&h&&(p=f[f.length-1])instanceof J&&d.lines+p.lines<=32?(h+=d.lines,a+=d.length+1,f[f.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(h+d.lines>s&&u(),h+=d.lines,a+=d.length+1,f.push(d))}function u(){h!=0&&(l.push(f.length==1?f[0]:Pt.from(f,a)),a=-1,h=f.length=0)}for(let d of t)c(d);return u(),l.length==1?l[0]:new Pt(l,e)}}W.empty=new J([""],0);function
|
|
4
|
-
`,this;t--}else if(s instanceof J){let h=s.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,h.length>Math.max(0,t))return this.value=t==0?h:e>0?h.slice(t):h.slice(0,h.length-t),this;t-=h.length}else{let h=s.children[o+(e<0?-1:0)];t>h.length?(t-=h.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(e>0?1:(h instanceof J?h.text.length:h.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class Dr{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new Ie(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Br{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(W.prototype[Symbol.iterator]=function(){return this.iter()},Ie.prototype[Symbol.iterator]=Dr.prototype[Symbol.iterator]=Br.prototype[Symbol.iterator]=function(){return this});class kl{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}function be(r,t,e){return t=Math.max(0,Math.min(r.length,t)),[t,Math.max(t,Math.min(r.length,e))]}function wt(r,t,e=!0,i=!0){return xl(r,t,e,i)}const ms=/\r\n?|\n/;var ct=(function(r){return r[r.Simple=0]="Simple",r[r.TrackDel=1]="TrackDel",r[r.TrackBefore=2]="TrackBefore",r[r.TrackAfter=3]="TrackAfter",r})(ct||(ct={}));class Wt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let n=this.sections[e++],o=this.sections[e++];o<0?(t(i,s,n),s+=n):s+=o,i+=n}}iterChangedRanges(t,e=!1){bs(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new Wt(t)}composeDesc(t){return this.empty?t:t.empty?this:Rr(this,t)}mapDesc(t,e=!1){return t.empty?this:xs(this,t,e)}mapPos(t,e=-1,i=ct.Simple){let s=0,n=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],a=s+l;if(h<0){if(a>t)return n+(t-s);n+=l}else{if(i!=ct.Simple&&a>=t&&(i==ct.TrackDel&&s<t&&a>t||i==ct.TrackBefore&&s<t||i==ct.TrackAfter&&a>t))return null;if(a>t||a==t&&e<0&&!l)return t==s||e<0?n:n+h;n+=h}s=a}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return n}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let n=this.sections[i++],o=this.sections[i++],l=s+n;if(o>=0&&s<=e&&l>=t)return s<t&&l>e?"cover":!0;s=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Wt(t)}static create(t){return new Wt(t)}}class et extends Wt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return bs(this,(e,i,s,n,o)=>t=t.replace(s,s+(i-e),o),!1),t}mapDesc(t,e=!1){return xs(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,n=0;s<e.length;s+=2){let o=e[s],l=e[s+1];if(l>=0){e[s]=l,e[s+1]=o;let h=s>>1;for(;i.length<h;)i.push(W.empty);i.push(o?t.slice(n,n+o):W.empty)}n+=o}return new et(e,i)}compose(t){return this.empty?t:t.empty?this:Rr(this,t,!0)}map(t,e=!1){return t.empty?this:xs(this,t,e,!0)}iterChanges(t,e=!1){bs(this,t,e)}get desc(){return Wt.create(this.sections)}filter(t){let e=[],i=[],s=[],n=new je(this);t:for(let o=0,l=0;;){let h=o==t.length?1e9:t[o++];for(;l<h||l==h&&n.len==0;){if(n.done)break t;let f=Math.min(n.len,h-l);nt(s,f,-1);let c=n.ins==-1?-1:n.off==0?n.ins:0;nt(e,f,c),c>0&&qt(i,e,n.text),n.forward(f),l+=f}let a=t[o++];for(;l<a;){if(n.done)break t;let f=Math.min(n.len,a-l);nt(e,f,-1),nt(s,f,n.ins==-1?-1:n.off==0?n.ins:0),n.forward(f),l+=f}}return{changes:new et(e,i),filtered:Wt.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):s==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let s=[],n=[],o=0,l=null;function h(f=!1){if(!f&&!s.length)return;o<e&&nt(s,e-o,-1);let c=new et(s,n);l=l?l.compose(c.map(l)):c,s=[],n=[],o=0}function a(f){if(Array.isArray(f))for(let c of f)a(c);else if(f instanceof et){if(f.length!=e)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${e})`);h(),l=l?l.compose(f.map(l)):f}else{let{from:c,to:u=c,insert:d}=f;if(c>u||c<0||u>e)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?W.of(d.split(i||ms)):d:W.empty,g=p.length;if(c==u&&g==0)return;c<o&&h(),c>o&&nt(s,c-o,-1),nt(s,u-c,g),qt(n,s,p),o=u}}return a(t),h(!l),l}static empty(t){return new et(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;s<t.length;s++){let n=t[s];if(typeof n=="number")e.push(n,-1);else{if(!Array.isArray(n)||typeof n[0]!="number"||n.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(n.length==1)e.push(n[0],0);else{for(;i.length<s;)i.push(W.empty);i[s]=W.of(n.slice(1)),e.push(n[0],i[s].length)}}}return new et(e,i)}static createSet(t,e){return new et(t,e)}}function nt(r,t,e,i=!1){if(t==0&&e<=0)return;let s=r.length-2;s>=0&&e<=0&&e==r[s+1]?r[s]+=t:s>=0&&t==0&&r[s]==0?r[s+1]+=e:i?(r[s]+=t,r[s+1]+=e):r.push(t,e)}function qt(r,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<r.length)r[r.length-1]=r[r.length-1].append(e);else{for(;r.length<i;)r.push(W.empty);r.push(e)}}function bs(r,t,e){let i=r.inserted;for(let s=0,n=0,o=0;o<r.sections.length;){let l=r.sections[o++],h=r.sections[o++];if(h<0)s+=l,n+=l;else{let a=s,f=n,c=W.empty;for(;a+=l,f+=h,h&&i&&(c=c.append(i[o-2>>1])),!(e||o==r.sections.length||r.sections[o+1]<0);)l=r.sections[o++],h=r.sections[o++];t(s,a,n,f,c),s=a,n=f}}}function xs(r,t,e,i=!1){let s=[],n=i?[]:null,o=new je(r),l=new je(t);for(let h=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let a=Math.min(o.len,l.len);nt(s,a,-1),o.forward(a),l.forward(a)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let a=l.len;for(nt(s,l.ins,-1);a;){let f=Math.min(o.len,a);o.ins>=0&&h<o.i&&o.len<=f&&(nt(s,0,o.ins),n&&qt(n,s,o.text),h=o.i),o.forward(f),a-=f}l.next()}else if(o.ins>=0){let a=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);a+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.len<f)f-=l.len,l.next();else break;nt(s,a,h<o.i?o.ins:0),n&&h<o.i&&qt(n,s,o.text),h=o.i,o.forward(o.len-f)}else{if(o.done&&l.done)return n?et.createSet(s,n):Wt.create(s);throw new Error("Mismatched change set lengths")}}}function Rr(r,t,e=!1){let i=[],s=e?[]:null,n=new je(r),o=new je(t);for(let l=!1;;){if(n.done&&o.done)return s?et.createSet(i,s):Wt.create(i);if(n.ins==0)nt(i,n.len,0,l),n.next();else if(o.len==0&&!o.done)nt(i,0,o.ins,l),s&&qt(s,i,o.text),o.next();else{if(n.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(n.len2,o.len),a=i.length;if(n.ins==-1){let f=o.ins==-1?-1:o.off?0:o.ins;nt(i,h,f,l),s&&f&&qt(s,i,o.text)}else o.ins==-1?(nt(i,n.off?0:n.len,h,l),s&&qt(s,i,n.textBit(h))):(nt(i,n.off?0:n.len,o.off?0:o.ins,l),s&&!o.off&&qt(s,i,o.text));l=(n.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>a),n.forward2(h),o.forward(h)}}}}class je{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?W.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?W.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class te{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}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 t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new te(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return k.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return k.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&this.goalColumn==t.goalColumn&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return k.range(t.anchor,t.head)}static create(t,e,i){return new te(t,e,i)}}class k{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:k.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new k([this.main],0)}addRange(t,e=!0){return k.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,k.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new k(t.ranges.map(e=>te.fromJSON(e)),t.main)}static single(t,e=t){return new k([k.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let n=t[s];if(n.empty?n.from<=i:n.from<i)return k.normalized(t.slice(),e);i=n.to}return new k(t,e)}static cursor(t,e=0,i,s){return te.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(t,e,i,s){let n=(i??16777215)<<6|(s==null?7:Math.min(6,s));return e<t?te.create(e,t,48|n):te.create(t,e,(e>t?8:0)|n)}static normalized(t,e=0){let i=t[e];t.sort((s,n)=>s.from-n.from),e=t.indexOf(i);for(let s=1;s<t.length;s++){let n=t[s],o=t[s-1];if(n.empty?n.from<=o.to:n.from<o.to){let l=o.from,h=Math.max(n.to,o.to);s<=e&&e--,t.splice(--s,2,n.anchor>n.head?k.range(h,l):k.range(l,h))}}return new k(t,e)}}function Er(r,t){for(let e of r.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let Us=0;class D{constructor(t,e,i,s,n){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=Us++,this.default=t([]),this.extensions=typeof n=="function"?n(this):n}get reader(){return this}static define(t={}){return new D(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:Js),!!t.static,t.enables)}of(t){return new Si([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Si(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Si(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function Js(r,t){return r==t||r.length==t.length&&r.every((e,i)=>e===t[i])}class Si{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=Us++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,n=this.id,o=t[n]>>1,l=this.type==2,h=!1,a=!1,f=[];for(let c of this.dependencies)c=="doc"?h=!0:c=="selection"?a=!0:(((e=t[c.id])!==null&&e!==void 0?e:1)&1)==0&&f.push(t[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(h&&u.docChanged||a&&(u.docChanged||u.selection)||ys(c,f)){let d=i(c);if(l?!Pn(d,c.values[o],s):!s(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[n];if(p!=null){let g=Pi(u,p);if(this.dependencies.every(m=>m instanceof D?u.facet(m)===c.facet(m):m instanceof Gt?u.field(m,!1)==c.field(m,!1):!0)||(l?Pn(d=i(c),g,s):s(d=i(c),g)))return c.values[o]=g,0}else d=i(c);return c.values[o]=d,1}}}}function Pn(r,t,e){if(r.length!=t.length)return!1;for(let i=0;i<r.length;i++)if(!e(r[i],t[i]))return!1;return!0}function ys(r,t){let e=!1;for(let i of t)Le(r,i)&1&&(e=!0);return e}function Sl(r,t,e){let i=e.map(h=>r[h.id]),s=e.map(h=>h.type),n=i.filter(h=>!(h&1)),o=r[t.id]>>1;function l(h){let a=[];for(let f=0;f<i.length;f++){let c=Pi(h,i[f]);if(s[f]==2)for(let u of c)a.push(u);else a.push(c)}return t.combine(a)}return{create(h){for(let a of i)Le(h,a);return h.values[o]=l(h),1},update(h,a){if(!ys(h,n))return 0;let f=l(h);return t.compare(f,h.values[o])?0:(h.values[o]=f,1)},reconfigure(h,a){let f=ys(h,i),c=a.config.facets[t.id],u=a.facet(t);if(c&&!f&&Js(e,c))return h.values[o]=u,0;let d=l(h);return t.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const ai=D.define({static:!0});class Gt{constructor(t,e,i,s,n){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=n,this.provides=void 0}static define(t){let e=new Gt(Us++,t.create,t.update,t.compare||((i,s)=>i===s),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(ai).find(i=>i.field==this);return(e?.create||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,s)=>{let n=i.values[e],o=this.updateF(n,s);return this.compareF(n,o)?0:(i.values[e]=o,1)},reconfigure:(i,s)=>{let n=i.facet(ai),o=s.facet(ai),l;return(l=n.find(h=>h.field==this))&&l!=o.find(h=>h.field==this)?(i.values[e]=l.create(i),1):s.config.address[this.id]!=null?(i.values[e]=s.field(this),0):(i.values[e]=this.create(i),1)}}}init(t){return[this,ai.of({field:this,create:t})]}get extension(){return this}}const Zt={lowest:4,low:3,default:2,high:1,highest:0};function Te(r){return t=>new Ir(t,r)}const Nr={highest:Te(Zt.highest),high:Te(Zt.high),default:Te(Zt.default),low:Te(Zt.low),lowest:Te(Zt.lowest)};class Ir{constructor(t,e){this.inner=t,this.prec=e}}class se{of(t){return new ws(this,t)}reconfigure(t){return se.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class ws{constructor(t,e){this.compartment=t,this.inner=e}}class Ti{constructor(t,e,i,s,n,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=n,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],n=Object.create(null),o=new Map;for(let u of vl(t,e,o))u instanceof Gt?s.push(u):(n[u.facet.id]||(n[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],a=[];for(let u of s)l[u.id]=a.length<<1,a.push(d=>u.slot(d));let f=i?.config.facets;for(let u in n){let d=n[u],p=d[0].facet,g=f&&f[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,Js(g,d))h.push(i.facet(p));else{let m=p.combine(d.map(b=>b.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=a.length<<1,a.push(b=>m.dynamicSlot(b)));l[p.id]=a.length<<1,a.push(m=>Sl(m,p,d))}}let c=a.map(u=>u(l));return new Ti(t,o,c,l,h,n)}}function vl(r,t,e){let i=[[],[],[],[],[]],s=new Map;function n(o,l){let h=s.get(o);if(h!=null){if(h<=l)return;let a=i[h].indexOf(o);a>-1&&i[h].splice(a,1),o instanceof ws&&e.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let a of o)n(a,l);else if(o instanceof ws){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let a=t.get(o.compartment)||o.inner;e.set(o.compartment,a),n(a,l)}else if(o instanceof Ir)n(o.inner,o.prec);else if(o instanceof Gt)i[l].push(o),o.provides&&n(o.provides,l);else if(o instanceof Si)i[l].push(o),o.facet.extensions&&n(o.facet.extensions,Zt.default);else{let a=o.extension;if(!a)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(a,l)}}return n(r,Zt.default),i.reduce((o,l)=>o.concat(l))}function Le(r,t){if(t&1)return 2;let e=t>>1,i=r.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;r.status[e]=4;let s=r.computeSlot(r,r.config.dynamicSlots[e]);return r.status[e]=2|s}function Pi(r,t){return t&1?r.config.staticValues[t>>1]:r.values[t>>1]}const Lr=D.define(),ks=D.define({combine:r=>r.some(t=>t),static:!0}),Wr=D.define({combine:r=>r.length?r[0]:void 0,static:!0}),Fr=D.define(),Hr=D.define(),Vr=D.define(),zr=D.define({combine:r=>r.length?r[0]:!1});class Oe{constructor(t,e){this.type=t,this.value=e}static define(){return new Cl}}class Cl{of(t){return new Oe(this,t)}}class Al{constructor(t){this.map=t}of(t){return new X(this,t)}}class X{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new X(this.type,e)}is(t){return this.type==t}static define(t={}){return new Al(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let n=s.map(e);n&&i.push(n)}return i}}X.reconfigure=X.define();X.appendConfig=X.define();class rt{constructor(t,e,i,s,n,o){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=n,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Er(i,e.newLength),n.some(l=>l.type==rt.time)||(this.annotations=n.concat(rt.time.of(Date.now())))}static create(t,e,i,s,n,o){return new rt(t,e,i,s,n,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(rt.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}rt.time=Oe.define();rt.userEvent=Oe.define();rt.addToHistory=Oe.define();rt.remote=Oe.define();function Ol(r,t){let e=[];for(let i=0,s=0;;){let n,o;if(i<r.length&&(s==t.length||t[s]>=r[i]))n=r[i++],o=r[i++];else if(s<t.length)n=t[s++],o=t[s++];else return e;!e.length||e[e.length-1]<n?e.push(n,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function qr(r,t,e){var i;let s,n,o;return e?(s=t.changes,n=et.empty(t.changes.length),o=r.changes.compose(t.changes)):(s=t.changes.map(r.changes),n=r.changes.mapDesc(t.changes,!0),o=r.changes.compose(s)),{changes:o,selection:t.selection?t.selection.map(n):(i=r.selection)===null||i===void 0?void 0:i.map(s),effects:X.mapEffects(r.effects,s).concat(X.mapEffects(t.effects,n)),annotations:r.annotations.length?r.annotations.concat(t.annotations):t.annotations,scrollIntoView:r.scrollIntoView||t.scrollIntoView}}function Ss(r,t,e){let i=t.selection,s=de(t.annotations);return t.userEvent&&(s=s.concat(rt.userEvent.of(t.userEvent))),{changes:t.changes instanceof et?t.changes:et.of(t.changes||[],e,r.facet(Wr)),selection:i&&(i instanceof k?i:k.single(i.anchor,i.head)),effects:de(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function jr(r,t,e){let i=Ss(r,t.length?t[0]:{},r.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let n=1;n<t.length;n++){t[n].filter===!1&&(e=!1);let o=!!t[n].sequential;i=qr(i,Ss(r,t[n],o?i.changes.newLength:r.doc.length),o)}let s=rt.create(r,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Tl(e?Ml(s):s)}function Ml(r){let t=r.startState,e=!0;for(let s of t.facet(Fr)){let n=s(r);if(n===!1){e=!1;break}Array.isArray(n)&&(e=e===!0?n:Ol(e,n))}if(e!==!0){let s,n;if(e===!1)n=r.changes.invertedDesc,s=et.empty(t.doc.length);else{let o=r.changes.filter(e);s=o.changes,n=o.filtered.mapDesc(o.changes).invertedDesc}r=rt.create(t,s,r.selection&&r.selection.map(n),X.mapEffects(r.effects,n),r.annotations,r.scrollIntoView)}let i=t.facet(Hr);for(let s=i.length-1;s>=0;s--){let n=i[s](r);n instanceof rt?r=n:Array.isArray(n)&&n.length==1&&n[0]instanceof rt?r=n[0]:r=jr(t,de(n),!1)}return r}function Tl(r){let t=r.startState,e=t.facet(Vr),i=r;for(let s=e.length-1;s>=0;s--){let n=e[s](r);n&&Object.keys(n).length&&(i=qr(i,Ss(t,n,r.changes.newLength),!0))}return i==r?r:rt.create(t,r.changes,r.selection,i.effects,i.annotations,i.scrollIntoView)}const Pl=[];function de(r){return r==null?Pl:Array.isArray(r)?r:[r]}var It=(function(r){return r[r.Word=0]="Word",r[r.Space=1]="Space",r[r.Other=2]="Other",r})(It||(It={}));const Dl=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let vs;try{vs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Bl(r){if(vs)return vs.test(r);for(let t=0;t<r.length;t++){let e=r[t];if(/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||Dl.test(e)))return!0}return!1}function Rl(r){return t=>{if(!/\S/.test(t))return It.Space;if(Bl(t))return It.Word;for(let e=0;e<r.length;e++)if(t.indexOf(r[e])>-1)return It.Word;return It.Other}}class V{constructor(t,e,i,s,n,o){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=n,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Le(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return Le(this,i),Pi(this,i)}update(...t){return jr(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:s}=e;for(let l of t.effects)l.is(se.reconfigure)?(e&&(s=new Map,e.compartments.forEach((h,a)=>s.set(a,h)),e=null),s.set(l.value.compartment,l.value.extension)):l.is(X.reconfigure)?(e=null,i=l.value):l.is(X.appendConfig)&&(e=null,i=de(i).concat(l.value));let n;e?n=t.startState.values.slice():(e=Ti.resolve(i,s,this),n=new V(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(h,a)=>a.reconfigure(h,this),null).values);let o=t.startState.facet(ks)?t.newSelection:t.newSelection.asSingle();new V(e,t.newDoc,o,n,(l,h)=>h.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:k.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),n=[i.range],o=de(i.effects);for(let l=1;l<e.ranges.length;l++){let h=t(e.ranges[l]),a=this.changes(h.changes),f=a.map(s);for(let u=0;u<l;u++)n[u]=n[u].map(f);let c=s.mapDesc(a,!0);n.push(h.range.map(c)),s=s.compose(f),o=X.mapEffects(o,f).concat(X.mapEffects(de(h.effects),c))}return{changes:s,selection:k.create(n,e.mainIndex),effects:o}}changes(t=[]){return t instanceof et?t:et.of(t,this.doc.length,this.facet(V.lineSeparator))}toText(t){return W.of(t.split(this.facet(V.lineSeparator)||ms))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(Le(this,e),Pi(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof Gt&&this.config.address[s.id]!=null&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let n in i)if(Object.prototype.hasOwnProperty.call(t,n)){let o=i[n],l=t[n];s.push(o.init(h=>o.spec.fromJSON(l,h)))}}return V.create({doc:t.doc,selection:k.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=Ti.resolve(t.extensions||[],new Map),i=t.doc instanceof W?t.doc:W.of((t.doc||"").split(e.staticFacet(V.lineSeparator)||ms)),s=t.selection?t.selection instanceof k?t.selection:k.single(t.selection.anchor,t.selection.head):k.single(0);return Er(s,i.length),e.staticFacet(ks)||(s=s.asSingle()),new V(e,i,s,e.dynamicSlots.map(()=>null),(n,o)=>o.create(n),null)}get tabSize(){return this.facet(V.tabSize)}get lineBreak(){return this.facet(V.lineSeparator)||`
|
|
5
|
-
`}get readOnly(){return this.facet(zr)}phrase(t,...e){for(let i of this.facet(V.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let n=+(s||1);return!n||n>e.length?i:e[n-1]})),t}languageDataAt(t,e,i=-1){let s=[];for(let n of this.facet(Lr))for(let o of n(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&s.push(o[t]);return s}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return Rl(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),n=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let h=wt(e,o,!1);if(n(e.slice(h,o))!=It.Word)break;o=h}for(;l<s;){let h=wt(e,l);if(n(e.slice(l,h))!=It.Word)break;l=h}return o==l?null:k.range(o+i,l+i)}}V.allowMultipleSelections=ks;V.tabSize=D.define({combine:r=>r.length?r[0]:4});V.lineSeparator=Wr;V.readOnly=zr;V.phrases=D.define({compare(r,t){let e=Object.keys(r),i=Object.keys(t);return e.length==i.length&&e.every(s=>r[s]==t[s])}});V.languageData=Lr;V.changeFilter=Fr;V.transactionFilter=Hr;V.transactionExtender=Vr;se.reconfigure=X.define();class ne{eq(t){return this==t}range(t,e=t){return $e.create(t,e,this)}}ne.prototype.startSide=ne.prototype.endSide=0;ne.prototype.point=!1;ne.prototype.mapMode=ct.TrackDel;function Ys(r,t){return r==t||r.constructor==t.constructor&&r.eq(t)}class $e{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new $e(t,e,i)}}function Cs(r,t){return r.from-t.from||r.value.startSide-t.value.startSide}class Xs{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let n=i?this.to:this.from;for(let o=s,l=n.length;;){if(o==l)return o;let h=o+l>>1,a=n[h]-t||(i?this.value[h].endSide:this.value[h].startSide)-e;if(h==o)return a>=0?o:l;a>=0?l=h:o=h+1}}between(t,e,i,s){for(let n=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,n);n<o;n++)if(s(this.from[n]+t,this.to[n]+t,this.value[n])===!1)return!1}map(t,e){let i=[],s=[],n=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let a=this.value[h],f=this.from[h]+t,c=this.to[h]+t,u,d;if(f==c){let p=e.mapPos(f,a.startSide,a.mapMode);if(p==null||(u=d=p,a.startSide!=a.endSide&&(d=e.mapPos(f,a.endSide),d<u)))continue}else if(u=e.mapPos(f,a.startSide),d=e.mapPos(c,a.endSide),u>d||u==d&&a.startSide>0&&a.endSide<=0)continue;(d-u||a.endSide-a.startSide)<0||(o<0&&(o=u),a.point&&(l=Math.max(l,d-u)),i.push(a),s.push(u-o),n.push(d-o))}return{mapped:i.length?new Xs(s,n,i,l):null,pos:o}}}class z{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new z(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:n=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(Cs)),this.isEmpty)return e.length?z.of(e):this;let l=new $r(this,null,-1).goto(0),h=0,a=[],f=new Ke;for(;l.value||h<e.length;)if(h<e.length&&(l.from-e[h].from||l.startSide-e[h].value.startSide)>=0){let c=e[h++];f.addInner(c.from,c.to,c.value)||a.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==e.length||this.chunkEnd(l.chunkIndex)<e[h].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||n<this.chunkPos[l.chunkIndex])&&f.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||n<l.from||o(l.from,l.to,l.value))&&(f.addInner(l.from,l.to,l.value)||a.push($e.create(l.from,l.to,l.value))),l.next());return f.finishInner(this.nextLayer.isEmpty&&!a.length?z.empty:this.nextLayer.update({add:a,filter:o,filterFrom:s,filterTo:n}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],a=t.touchesRange(l,l+h.length);if(a===!1)s=Math.max(s,h.maxPoint),e.push(h),i.push(t.mapPos(l));else if(a===!0){let{mapped:f,pos:c}=h.map(l,t);f&&(s=Math.max(s,f.maxPoint),e.push(f),i.push(c))}}let n=this.nextLayer.map(t);return e.length==0?n:new z(i,e,n||z.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let n=this.chunkPos[s],o=this.chunk[s];if(e>=n&&t<=n+o.length&&o.between(n,t-n,e-n,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return Qe.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Qe.from(t).goto(e)}static compare(t,e,i,s,n=-1){let o=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=n),l=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=n),h=Dn(o,l,i),a=new Pe(o,h,n),f=new Pe(l,h,n);i.iterGaps((c,u,d)=>Bn(a,c,f,u,d,s)),i.empty&&i.length==0&&Bn(a,0,f,0,0,s)}static eq(t,e,i=0,s){s==null&&(s=999999999);let n=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0),o=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0);if(n.length!=o.length)return!1;if(!n.length)return!0;let l=Dn(n,o),h=new Pe(n,l,0).goto(i),a=new Pe(o,l,0).goto(i);for(;;){if(h.to!=a.to||!As(h.active,a.active)||h.point&&(!a.point||!Ys(h.point,a.point)))return!1;if(h.to>s)return!0;h.next(),a.next()}}static spans(t,e,i,s,n=-1){let o=new Pe(t,null,n).goto(e),l=e,h=o.openStart;for(;;){let a=Math.min(o.to,i);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFrom<e?f.length+1:o.point.startSide<0?f.length:Math.min(f.length,h);s.point(l,a,o.point,f,c,o.pointRank),h=Math.min(o.openEnd(a),f.length)}else a>l&&(s.span(l,a,o.active,h),h=o.openEnd(a));if(o.to>i)return h+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(t,e=!1){let i=new Ke;for(let s of t instanceof $e?[t]:e?El(t):t)i.add(s.from,s.to,s.value);return i.finish()}static join(t){if(!t.length)return z.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let s=t[i];s!=z.empty;s=s.nextLayer)e=new z(s.chunkPos,s.chunk,e,Math.max(s.maxPoint,e.maxPoint));return e}}z.empty=new z([],[],null,-1);function El(r){if(r.length>1)for(let t=r[0],e=1;e<r.length;e++){let i=r[e];if(Cs(t,i)>0)return r.slice().sort(Cs);t=i}return r}z.empty.nextLayer=z.empty;class Ke{finishChunk(t){this.chunks.push(new Xs(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Ke)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(z.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=z.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Dn(r,t,e){let i=new Map;for(let n of r)for(let o=0;o<n.chunk.length;o++)n.chunk[o].maxPoint<=0&&i.set(n.chunk[o],n.chunkPos[o]);let s=new Set;for(let n of t)for(let o=0;o<n.chunk.length;o++){let l=i.get(n.chunk[o]);l!=null&&(e?e.mapPos(l):l)==n.chunkPos[o]&&!e?.touchesRange(l,l+n.chunk[o].length)&&s.add(n.chunk[o])}return s}class $r{constructor(t,e,i,s=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<t||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class Qe{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let n=0;n<t.length;n++)for(let o=t[n];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new $r(o,e,i,n));return s.length==1?s[0]:new Qe(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)Xi(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)Xi(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Xi(this.heap,0)}}}function Xi(r,t){for(let e=r[t];;){let i=(t<<1)+1;if(i>=r.length)break;let s=r[i];if(i+1<r.length&&s.compare(r[i+1])>=0&&(s=r[i+1],i++),e.compare(s)<0)break;r[i]=e,r[t]=s,t=i}}class Pe{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Qe.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){fi(this.active,t),fi(this.activeTo,t),fi(this.activeRank,t),this.minActive=Rn(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:n}=this.cursor;for(;e<this.activeRank.length&&(n-this.activeRank[e]||s-this.activeTo[e])>0;)e++;ci(this.active,e,i),ci(this.activeTo,e,s),ci(this.activeRank,e,n),t&&ci(t,e,this.cursor.from),this.minActive=Rn(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>t){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&fi(i,s)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let n=this.cursor.value;if(!n.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=n,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=n.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<t;s--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function Bn(r,t,e,i,s,n){r.goto(t),e.goto(i);let o=i+s,l=i,h=i-t,a=!!n.boundChange;for(let f=!1;;){let c=r.to+h-e.to,u=c||r.endSide-e.endSide,d=u<0?r.to+h:e.to,p=Math.min(d,o);if(r.point||e.point?(r.point&&e.point&&Ys(r.point,e.point)&&As(r.activeForPoint(r.to),e.activeForPoint(e.to))||n.comparePoint(l,p,r.point,e.point),f=!1):(f&&n.boundChange(l),p>l&&!As(r.active,e.active)&&n.compareRange(l,p,r.active,e.active),a&&p<o&&(c||r.openEnd(d)!=e.openEnd(d))&&(f=!0)),d>o)break;l=d,u<=0&&r.next(),u>=0&&e.next()}}function As(r,t){if(r.length!=t.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!=t[e]&&!Ys(r[e],t[e]))return!1;return!0}function fi(r,t){for(let e=t,i=r.length-1;e<i;e++)r[e]=r[e+1];r.pop()}function ci(r,t,e){for(let i=r.length-1;i>=t;i--)r[i+1]=r[i];r[t]=e}function Rn(r,t){let e=-1,i=1e9;for(let s=0;s<t.length;s++)(t[s]-i||r[s].endSide-r[e].endSide)<0&&(e=s,i=t[s]);return e}function Nl(r,t,e,i){for(let s=0,n=0;;){if(n>=t)return s;if(s==r.length)break;n+=r.charCodeAt(s)==9?e-n%e:1,s=wt(r,s)}return r.length}const Os="ͼ",En=typeof Symbol>"u"?"__"+Os:Symbol.for(Os),Ms=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Nn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Kt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function n(o,l,h,a){let f=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))n(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");n(s(d),p,f,u)}else p!=null&&f.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(f.length||u)&&h.push((i&&!c&&!a?o.map(i):o).join(", ")+" {"+f.join(" ")+"}")}for(let o in t)n(s(o),t[o],this.rules)}getRules(){return this.rules.join(`
|
|
6
|
-
`)}static newName(){let t=Nn[En]||1;return Nn[En]=t+1,
|
|
7
|
-
`;this.styleTag.textContent=o;let l=e.head||e;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var xe={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ts={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'};for(var st=0;st<10;st++)xe[48+st]=xe[96+st]=String(st);for(var st=1;st<=24;st++)xe[st+111]="F"+st;for(var st=65;st<=90;st++)xe[st]=String.fromCharCode(st+32),Ts[st]=String.fromCharCode(st);for(var Zi in xe)Ts.hasOwnProperty(Zi)||(Ts[Zi]=xe[Zi]);let ut=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ps=typeof document<"u"?document:{documentElement:{style:{}}};const Ds=/Edge\/(\d+)/.exec(ut.userAgent),Kr=/MSIE \d/.test(ut.userAgent),Bs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ut.userAgent),Vi=!!(Kr||Bs||Ds),Ln=!Vi&&/gecko\/(\d+)/i.test(ut.userAgent),ts=!Vi&&/Chrome\/(\d+)/.exec(ut.userAgent),Ll="webkitFontSmoothing"in Ps.documentElement.style,Rs=!Vi&&/Apple Computer/.test(ut.vendor),Wn=Rs&&(/Mobile\/\w+/.test(ut.userAgent)||ut.maxTouchPoints>2);var v={mac:Wn||/Mac/.test(ut.platform),ie:Vi,ie_version:Kr?Ps.documentMode||6:Bs?+Bs[1]:Ds?+Ds[1]:0,gecko:Ln,gecko_version:Ln?+(/Firefox\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,chrome:!!ts,chrome_version:ts?+ts[1]:0,ios:Wn,android:/Android\b/.test(ut.userAgent),webkit_version:Ll?+(/\bAppleWebKit\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,safari:Rs,safari_version:Rs?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ut.userAgent)||[0,0])[1]:0,tabSize:Ps.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Zs(r,t){for(let e in r)e=="class"&&t.class?t.class+=" "+r.class:e=="style"&&t.style?t.style+=";"+r.style:t[e]=r[e];return t}const Di=Object.create(null);function tn(r,t,e){if(r==t)return!0;r||(r=Di),t||(t=Di);let i=Object.keys(r),s=Object.keys(t);if(i.length-0!=s.length-0)return!1;for(let n of i)if(n!=e&&(s.indexOf(n)==-1||r[n]!==t[n]))return!1;return!0}function Wl(r,t){for(let e=r.attributes.length-1;e>=0;e--){let i=r.attributes[e].name;t[i]==null&&r.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?r.style.cssText=i:r.getAttribute(e)!=i&&r.setAttribute(e,i)}}function Fn(r,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?r.style.cssText="":r.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?r.style.cssText=e[s]:r.setAttribute(s,e[s]));return i}function Fl(r){let t=Object.create(null);for(let e=0;e<r.attributes.length;e++){let i=r.attributes[e];t[i.name]=i.value}return t}class Ye{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var bt=(function(r){return r[r.Text=0]="Text",r[r.WidgetBefore=1]="WidgetBefore",r[r.WidgetAfter=2]="WidgetAfter",r[r.WidgetRange=3]="WidgetRange",r})(bt||(bt={}));class K extends ne{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Xe(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new re(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:n,end:o}=Qr(t,e);i=(n?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new re(t,i,s,e,t.widget||null,!0)}static line(t){return new Ze(t)}static set(t,e=!1){return z.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}K.none=z.empty;class Xe extends K{constructor(t){let{start:e,end:i}=Qr(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?Zs(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||Di}eq(t){return this==t||t instanceof Xe&&this.tagName==t.tagName&&tn(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Xe.prototype.point=!1;class Ze extends K{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Ze&&this.spec.class==t.spec.class&&tn(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Ze.prototype.mapMode=ct.TrackBefore;Ze.prototype.point=!0;class re extends K{constructor(t,e,i,s,n,o){super(e,i,n,t),this.block=s,this.isReplace=o,this.mapMode=s?e<=0?ct.TrackBefore:ct.TrackAfter:ct.TrackDel}get type(){return this.startSide!=this.endSide?bt.WidgetRange:this.startSide<=0?bt.WidgetBefore:bt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof re&&Hl(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}re.prototype.point=!0;function Qr(r,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=r;return e==null&&(e=r.inclusive),i==null&&(i=r.inclusive),{start:e??t,end:i??t}}function Hl(r,t){return r==t||!!(r&&t&&r.compare(t))}function pe(r,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=r?e[s]=Math.max(e[s],t):e.push(r,t)}class _e extends ne{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof _e&&this.tagName==t.tagName&&tn(this.attributes,t.attributes)}static create(t){return new _e(t.tagName,t.attributes||Di)}static set(t,e=!1){return z.of(t,e)}}_e.prototype.startSide=_e.prototype.endSide=-1;function ye(r){let t;return r.nodeType==11?t=r.getSelection?r:r.ownerDocument:t=r,t.getSelection()}function Es(r,t){return t?r==t||r.contains(t.nodeType!=1?t.parentNode:t):!1}function We(r,t){if(!t.anchorNode)return!1;try{return Es(r,t.anchorNode)}catch{return!1}}function Fe(r){return r.nodeType==3?Ue(r,0,r.nodeValue.length).getClientRects():r.nodeType==1?r.getClientRects():[]}function He(r,t,e,i){return e?Hn(r,t,e,i,-1)||Hn(r,t,e,i,1):!1}function Qt(r){for(var t=0;;t++)if(r=r.previousSibling,!r)return t}function Bi(r){return r.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(r.nodeName)}function Hn(r,t,e,i,s){for(;;){if(r==e&&t==i)return!0;if(t==(s<0?0:Ft(r))){if(r.nodeName=="DIV")return!1;let n=r.parentNode;if(!n||n.nodeType!=1)return!1;t=Qt(r)+(s<0?0:1),r=n}else if(r.nodeType==1){if(r=r.childNodes[t+(s<0?-1:0)],r.nodeType==1&&r.contentEditable=="false")return!1;t=s<0?Ft(r):0}else return!1}}function Ft(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Ge(r,t){let e=t?r.left:r.right;return{left:e,right:e,top:r.top,bottom:r.bottom}}function Vl(r){let t=r.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:r.innerWidth,top:0,bottom:r.innerHeight}}function _r(r,t){let e=t.width/r.offsetWidth,i=t.height/r.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-r.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-r.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function zl(r,t,e,i,s,n,o,l){let h=r.ownerDocument,a=h.defaultView||window;for(let f=r,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==h.body,p=1,g=1;if(d)u=Vl(a);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let A=f.getBoundingClientRect();({scaleX:p,scaleY:g}=_r(f,A)),u={left:A.left,right:A.left+f.clientWidth*p,top:A.top,bottom:A.top+f.clientHeight*g}}let m=0,b=0;if(s=="nearest")t.top<u.top?(b=t.top-(u.top+o),e>0&&t.bottom>u.bottom+b&&(b=t.bottom-u.bottom+o)):t.bottom>u.bottom&&(b=t.bottom-u.bottom+o,e<0&&t.top-b<u.top&&(b=t.top-(u.top+o)));else{let A=t.bottom-t.top,M=u.bottom-u.top;b=(s=="center"&&A<=M?t.top+A/2-M/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-M+o)-u.top}if(i=="nearest"?t.left<u.left?(m=t.left-(u.left+n),e>0&&t.right>u.right+m&&(m=t.right-u.right+n)):t.right>u.right&&(m=t.right-u.right+n,e<0&&t.left<u.left+m&&(m=t.left-(u.left+n))):m=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-n:t.right-(u.right-u.left)+n)-u.left,m||b)if(d)a.scrollBy(m,b);else{let A=0,M=0;if(b){let E=f.scrollTop;f.scrollTop+=b/g,M=(f.scrollTop-E)*g}if(m){let E=f.scrollLeft;f.scrollLeft+=m/p,A=(f.scrollLeft-E)*p}t={left:t.left-A,top:t.top-M,right:t.right-A,bottom:t.bottom-M},A&&Math.abs(A-m)<1&&(i="nearest"),M&&Math.abs(M-b)<1&&(s="nearest")}if(d)break;(t.top<u.top||t.bottom>u.bottom||t.left<u.left||t.right>u.right)&&(t={left:Math.max(t.left,u.left),right:Math.min(t.right,u.right),top:Math.max(t.top,u.top),bottom:Math.min(t.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function ql(r){let t=r.ownerDocument,e,i;for(let s=r.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}class jl{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Ft(e):0),i,Math.min(t.focusOffset,i?Ft(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let Xt=null;v.safari&&v.safari_version>=26&&(Xt=!1);function Gr(r){if(r.setActive)return r.setActive();if(Xt)return r.focus(Xt);let t=[];for(let e=r;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(r.focus(Xt==null?{get preventScroll(){return Xt={preventScroll:!0},!0}}:void 0),!Xt){Xt=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],n=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=n&&(i.scrollLeft=n)}}}let Vn;function Ue(r,t,e=t){let i=Vn||(Vn=document.createRange());return i.setEnd(r,e),i.setStart(r,t),i}function ge(r,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let n=new KeyboardEvent("keydown",s);n.synthetic=!0,r.dispatchEvent(n);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,r.dispatchEvent(o),n.defaultPrevented||o.defaultPrevented}function $l(r){for(;r;){if(r&&(r.nodeType==9||r.nodeType==11&&r.host))return r;r=r.assignedSlot||r.parentNode}return null}function Kl(r,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Ft(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=Ft(e))}else{if(e==r)return!0;i=Qt(e),e=e.parentNode}}function Ur(r){return r.scrollTop>Math.max(1,r.scrollHeight-r.clientHeight-4)}function Jr(r,t){for(let e=r,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Ft(e)}else if(e.parentNode&&!Bi(e))i=Qt(e),e=e.parentNode;else return null}}function Yr(r,t){for(let e=r,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Bi(e))i=Qt(e)+1,e=e.parentNode;else return null}}class kt{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new kt(t.parentNode,Qt(t),e)}static after(t,e){return new kt(t.parentNode,Qt(t)+1,e)}}var tt=(function(r){return r[r.LTR=0]="LTR",r[r.RTL=1]="RTL",r})(tt||(tt={}));const oe=tt.LTR,en=tt.RTL;function Xr(r){let t=[];for(let e=0;e<r.length;e++)t.push(1<<+r[e]);return t}const Ql=Xr("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),_l=Xr("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ns=Object.create(null),Mt=[];for(let r of["()","[]","{}"]){let t=r.charCodeAt(0),e=r.charCodeAt(1);Ns[t]=e,Ns[e]=-t}function Zr(r){return r<=247?Ql[r]:1424<=r&&r<=1524?2:1536<=r&&r<=1785?_l[r-1536]:1774<=r&&r<=2220?4:8192<=r&&r<=8204?256:64336<=r&&r<=65023?4:1}const Gl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Lt{get dir(){return this.level%2?en:oe}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let n=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(n<0||(s!=0?s<0?l.from<e:l.to>e:t[n].level>l.level))&&(n=o)}}if(n<0)throw new RangeError("Index out of range");return n}}function to(r,t){if(r.length!=t.length)return!1;for(let e=0;e<r.length;e++){let i=r[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!to(i.inner,s.inner))return!1}return!0}const q=[];function Ul(r,t,e,i,s){for(let n=0;n<=i.length;n++){let o=n?i[n-1].to:t,l=n<i.length?i[n].from:e,h=n?256:s;for(let a=o,f=h,c=h;a<l;a++){let u=Zr(r.charCodeAt(a));u==512?u=f:u==8&&c==4&&(u=16),q[a]=u==4?2:u,u&7&&(c=u),f=u}for(let a=o,f=h,c=h;a<l;a++){let u=q[a];if(u==128)a<l-1&&f==q[a+1]&&f&24?u=q[a]=f:q[a]=256;else if(u==64){let d=a+1;for(;d<l&&q[d]==64;)d++;let p=a&&f==8||d<e&&q[d]==8?c==1?1:8:256;for(let g=a;g<d;g++)q[g]=p;a=d-1}else u==8&&c==1&&(q[a]=1);f=u,u&7&&(c=u)}}}function Jl(r,t,e,i,s){let n=s==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let a=o?i[o-1].to:t,f=o<i.length?i[o].from:e;for(let c=a,u,d,p;c<f;c++)if(d=Ns[u=r.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(Mt[g+1]==-d){let m=Mt[g+2],b=m&2?s:m&4?m&1?n:s:0;b&&(q[c]=q[Mt[g]]=b),l=g;break}}else{if(Mt.length==189)break;Mt[l++]=c,Mt[l++]=u,Mt[l++]=h}else if((p=q[c])==2||p==1){let g=p==s;h=g?0:1;for(let m=l-3;m>=0;m-=3){let b=Mt[m+2];if(b&2)break;if(g)Mt[m+2]|=2;else{if(b&4)break;Mt[m+2]|=4}}}}}function Yl(r,t,e,i){for(let s=0,n=i;s<=e.length;s++){let o=s?e[s-1].to:r,l=s<e.length?e[s].from:t;for(let h=o;h<l;){let a=q[h];if(a==256){let f=h+1;for(;;)if(f==l){if(s==e.length)break;f=e[s++].to,l=s<e.length?e[s].from:t}else if(q[f]==256)f++;else break;let c=n==1,u=(f<t?q[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,g=s,m=g?e[g-1].to:r;p>h;)p==m&&(p=e[--g].from,m=g?e[g-1].to:r),q[--p]=d;h=f}else n=a,h++}}}function Is(r,t,e,i,s,n,o){let l=i%2?2:1;if(i%2==s%2)for(let h=t,a=0;h<e;){let f=!0,c=!1;if(a==n.length||h<n[a].from){let g=q[h];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;t:for(;;)if(a<n.length&&p==n[a].from){if(c)break t;let g=n[a];if(!f)for(let m=g.to,b=a+1;;){if(m==e)break t;if(b<n.length&&n[b].from==m)m=n[b++].to;else{if(q[m]==l)break t;break}}if(a++,u)u.push(g);else{g.from>h&&o.push(new Lt(h,g.from,d));let m=g.direction==oe!=!(d%2);Ls(r,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==e||(f?q[p]!=l:q[p]==l))break;p++}u?Is(r,h,p,i+1,s,u,o):h<p&&o.push(new Lt(h,p,d)),h=p}else for(let h=e,a=n.length;h>t;){let f=!0,c=!1;if(!a||h>n[a-1].to){let g=q[h-1];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;t:for(;;)if(a&&p==n[a-1].to){if(c)break t;let g=n[--a];if(!f)for(let m=g.from,b=a;;){if(m==t)break t;if(b&&n[b-1].to==m)m=n[--b].from;else{if(q[m-1]==l)break t;break}}if(u)u.push(g);else{g.to<h&&o.push(new Lt(g.to,h,d));let m=g.direction==oe!=!(d%2);Ls(r,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==t||(f?q[p-1]!=l:q[p-1]==l))break;p--}u?Is(r,p,h,i+1,s,u,o):p<h&&o.push(new Lt(p,h,d)),h=p}}function Ls(r,t,e,i,s,n,o){let l=t%2?2:1;Ul(r,s,n,i,l),Jl(r,s,n,i,l),Yl(s,n,i,l),Is(r,s,n,t,e,i,o)}function Xl(r,t,e){if(!r)return[new Lt(0,0,t==en?1:0)];if(t==oe&&!e.length&&!Gl.test(r))return eo(r.length);if(e.length)for(;r.length>q.length;)q[q.length]=256;let i=[],s=t==oe?0:1;return Ls(r,s,s,e,0,r.length,i),i}function eo(r){return[new Lt(0,r,0)]}let io="";function Zl(r,t,e,i,s){var n;let o=i.head-r.from,l=Lt.find(t,o,(n=i.bidiLevel)!==null&&n!==void 0?n:-1,i.assoc),h=t[l],a=h.side(s,e);if(o==a){let u=l+=s?1:-1;if(u<0||u>=t.length)return null;h=t[l=u],o=h.side(!s,e),a=h.side(s,e)}let f=wt(r.text,o,h.forward(s,e));(f<h.from||f>h.to)&&(f=a),io=r.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return c&&f==a&&c.level+(s?0:1)<h.level?k.cursor(c.side(!s,e)+r.from,c.forward(s,e)?1:-1,c.level):k.cursor(f+r.from,h.forward(s,e)?-1:1,h.level)}function th(r,t,e){for(let i=t;i<e;i++){let s=Zr(r.charCodeAt(i));if(s==1)return oe;if(s==2||s==4)return en}return oe}const so=D.define(),no=D.define(),ro=D.define(),oo=D.define(),Ws=D.define(),lo=D.define(),ho=D.define(),sn=D.define(),nn=D.define(),ao=D.define({combine:r=>r.some(t=>t)}),eh=D.define({combine:r=>r.some(t=>t)}),fo=D.define();class me{constructor(t,e="nearest",i="nearest",s=5,n=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=n,this.isSnapshot=o}map(t){return t.empty?this:new me(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 me(k.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const ui=X.define({map:(r,t)=>r.map(t)}),co=X.define();function Bt(r,t,e){let i=r.facet(oo);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}const Nt=D.define({combine:r=>r.length?r[0]:!0});let ih=0;const fe=D.define({combine(r){return r.filter((t,e)=>{for(let i=0;i<e;i++)if(r[i].plugin==t.plugin)return!1;return!0})}});class _t{constructor(t,e,i,s,n){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=n(this),this.extension=this.baseExtensions.concat(fe.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(fe.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:n,decorations:o}=e||{};return new _t(ih++,t,i,s,l=>{let h=[];return o&&h.push(zi.of(a=>{let f=a.plugin(l);return f?o(f):K.none})),n&&h.push(n(l)),h})}static fromClass(t,e){return _t.define((i,s)=>new t(i,s),e)}}class es{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Bt(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Bt(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Bt(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const uo=D.define(),rn=D.define(),zi=D.define(),po=D.define(),on=D.define(),ti=D.define(),go=D.define();function zn(r,t){let e=r.state.facet(go);if(!e.length)return e;let i=e.map(n=>n instanceof Function?n(r):n),s=[];return z.spans(i,t.from,t.to,{point(){},span(n,o,l,h){let a=n-t.from,f=o-t.from,c=s;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=th(t.text,a,f)),h>0&&c.length&&(p=c[c.length-1]).to==a&&p.direction==d)p.to=f,c=p.inner;else{let g={from:a,to:f,direction:d,inner:[]};c.push(g),c=g.inner}}}}),s}const mo=D.define();function bo(r){let t=0,e=0,i=0,s=0;for(let n of r.state.facet(mo)){let o=n(r);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Be=D.define();class gt{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new gt(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,n=0,o=0;;){let l=s<t.length?t[s].fromB:1e9,h=n<e.length?e[n]:1e9,a=Math.min(l,h);if(a==1e9)break;let f=a+o,c=a,u=f;for(;;)if(n<e.length&&e[n]<=c){let d=e[n+1];n+=2,c=Math.max(c,d);for(let p=s;p<t.length&&t[p].fromB<=c;p++)o=t[p].toA-t[p].toB;u=Math.max(u,d+o)}else if(s<t.length&&t[s].fromB<=c){let d=t[s++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new gt(f,u,a,c))}return i}}class Ri{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.empty(this.startState.doc.length);for(let n of i)this.changes=this.changes.compose(n.changes);let s=[];this.changes.iterChangedRanges((n,o,l,h)=>s.push(new gt(n,o,l,h))),this.changedRanges=s}static create(t,e,i){return new Ri(t,e,i)}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(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const sh=[];class Z{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return sh}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&Wl(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=Qt(this.dom),s=this.length?t>0:e>0;return new kt(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof ji)return t;return null}static get(t){return t.cmTile}}class qi extends Z{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s,n=t?.node==e?t:null,o=0;for(let l of this.children){if(l.sync(t),o+=l.length+l.breakAfter,s=i?i.nextSibling:e.firstChild,n&&s!=l.dom&&(n.written=!0),l.dom.parentNode==e)for(;s&&s!=l.dom;)s=qn(s);else e.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:e.firstChild,n&&s&&(n.written=!0);s;)s=qn(s);this.length=o}}function qn(r){let t=r.nextSibling;return r.parentNode.removeChild(r),t}class ji extends qi{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=Z.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,n=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&n++,s=e.pop()}else{let o=i.children[s++];if(o instanceof jt)e.push(s),i=o,s=0;else{let l=n+o.length,h=t(o,n);if(h!==void 0)return h;n=l+o.breakAfter}}}resolveBlock(t,e){let i,s=-1,n,o=-1;if(this.blockTiles((l,h)=>{let a=h+l.length;if(t>=h&&t<=a){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(h<t||t==a&&(e<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=t-h),(a>t||t==h&&(e>1?l.length:l.covers(-1)))&&(!n||!l.isWidget()&&n.isWidget())&&(n=l,o=t-h)}}),!i&&!n)throw new Error("No tile at position "+t);return i&&e<0||!n?{tile:i,offset:s}:{tile:n,offset:o}}}class jt extends qi{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new jt(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class we extends qi{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new we(e||document.createElement("div"),t);return(!e||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,n=-1,o=null,l=-1;function h(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],g=d+p.length;g>=c&&(p.isComposite()?h(p,c-d):(!o||o.isHidden&&(e>0||i&&rh(o,p)))&&(g>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(s=p,n=c-d)),d=g}}h(this,t);let a=(e<0?s:o)||s||o;return a?{tile:a,offset:a==s?n:l}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):nh(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:s,offset:n}=i;if(this.dom.contains(s.dom))return s.isText()?new kt(s.dom,Math.min(s.dom.nodeValue.length,n)):s.domPosFor(n,s.flags&16?1:s.flags&32?-1:e);let o=i.tile.parent,l=!1;for(let h of o.children){if(l)return new kt(h.dom,0);h==i.tile&&(l=!0)}}return new kt(this.dom,0)}}function nh(r){let t=r.dom.lastChild;if(!t)return r.dom.getBoundingClientRect();let e=Fe(t);return e[e.length-1]||null}function rh(r,t){let e=r.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}class lt extends qi{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new lt(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class ee extends Z{constructor(t,e){super(t,e.length),this.text=e}sync(t){this.flags&2||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,n=t,o=0;t==0&&e<0||t==i&&e>=0?v.chrome||v.gecko||(t?(s--,o=1):n<i&&(n++,o=-1)):e<0?s--:n<i&&n++;let l=Ue(this.dom,s,n).getClientRects();if(!l.length)return null;let h=l[(o?o<0:e>=0)?0:l.length-1];return v.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?Ge(h,o<0):h||null}static of(t,e){let i=new ee(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class le extends Z{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return Ge(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let n=this.dom.getClientRects(),o=null;if(!n.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let h=l?n.length-1:0;o=n[h],!(t>0?h==0:h==n.length-1||o.top<o.bottom);h+=l?-1:1);return Ge(o,!l)}}get overrideDOMText(){if(!this.length)return W.empty;let{root:t}=this;if(!t)return W.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,n){return n||(n=t.toDOM(e),t.editable||(n.contentEditable="false")),new le(n,i,t,s)}}class Ei extends Z{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return W.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class oh{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:n,beforeBreak:o,parents:l}=this;for(;t||e>0;)if(s.isComposite())if(o){if(!t)break;i&&i.break(),t--,o=!1}else if(n==s.children.length){if(!t&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:n}=l.pop(),n++}else{let h=s.children[n],a=h.breakAfter;(e>0?h.length<=t:h.length<t)&&(!i||i.skip(h,0,h.length)!==!1||!h.isComposite)?(o=!!a,n++,t-=h.length):(l.push({tile:s,index:n}),s=h,n=0,i&&h.isComposite()&&i.enter(h))}else if(n==s.length)o=!!s.breakAfter,{tile:s,index:n}=l.pop(),n++;else if(t){let h=Math.min(t,s.length-n);i&&i.skip(s,n,n+h),t-=h,n+=h}else break;return this.tile=s,this.index=n,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class lh{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class hh{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var n;this.flushBuffer();let o=this.ensureMarks(e,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+t.length<512){this.cache.reused.set(l,2);let h=o.children[o.children.length-1]=new ee(l.dom,l.text+t);h.parent=o}else o.append(s||ee.of(t,(n=this.cache.find(ee))===null||n===void 0?void 0:n.dom));this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?is(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let l=e.marks.length-1;l>=0;l--){let h=e.marks[l],a=s.lastChild;if(a instanceof lt&&a.mark.eq(h.mark))a.dom!=h.dom&&a.setDOM(is(h.dom)),s=a;else{if(this.cache.reused.get(h)){let c=Z.get(h.dom);c&&c.setDOM(is(h.dom))}let f=lt.of(h.mark,h.dom);s.append(f),s=f}this.cache.reused.set(h,2)}let n=Z.get(t.text);n&&this.cache.reused.set(n,2);let o=new ee(t.text,t.text.nodeValue);o.flags|=8,s.append(o)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);s||this.flushBuffer();let n=this.ensureMarks(e,i);!s&&!(t.flags&16)&&n.append(this.getBuffer(1)),n.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=xo);let s=we.start(t,e||((i=this.cache.find(we))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let n=t.length-1;n>=0;n--){let o=t[n],l;if(e>0&&(l=s.lastChild)&&l instanceof lt&&l.mark.eq(o))s=l,e--;else{let h=lt.of(o,(i=this.cache.find(lt,a=>a.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(h),s=h,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!jn(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(v.ios&&jn(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(ss,0,32)||new le(ss.toDOM(),0,ss,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new lh(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof jt&&s.wrapper.eq(i.wrapper))e=s;else{let n=jt.of(i.wrapper,(t=this.cache.find(jt,o=>o.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(n),e=n}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(Ei,void 0,1);return i&&(i.flags=e),i||new Ei(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class ah{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:s,lineBreak:n,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(t,s.length);return n?null:s.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const Ni=[le,we,ee,lt,Ei,jt,ji];for(let r=0;r<Ni.length;r++)Ni[r].bucket=r;class fh{constructor(t){this.view=t,this.buckets=Ni.map(()=>[]),this.index=Ni.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,n=this.buckets[s],o=this.index[s];for(let l=n.length-1;l>=0;l--){let h=(l+o)%n.length,a=n[h];if((!e||e(a))&&!this.reused.has(a))return n.splice(h,1),h<o&&this.index[s]--,this.reused.set(a,i),a}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let n=0,o=0;;n++){if(n==s.length){if(o)return null;o=1,n=0}let l=s[n];if(!this.reused.has(l)&&(o==0?l.widget.compare(t):l.widget.constructor==t.constructor&&t.updateDOM(l.dom,this.view)))return s.splice(n,1),n<this.index[0]&&this.index[0]--,l.widget==t&&l.length==e&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new le(l.dom,e,t,l.flags&-498|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class ch{constructor(t,e,i,s,n){this.view=t,this.decorations=s,this.disallowBlockEffectsFor=n,this.openWidget=!1,this.openMarks=0,this.cache=new fh(t),this.text=new ah(t.state.doc),this.builder=new hh(this.cache,new ji(t,t.contentDOM),z.iter(i)),this.cache.reused.set(e,2),this.old=new oh(e),this.reuseWalker={skip:(o,l,h)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,n=0,o=0;;){let l=o<t.length?t[o++]:null,h=l?l.fromA:this.old.root.length;if(h>s){let a=h-s;this.preserve(a,!o,!l),s=h,n+=a}if(!l)break;e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.forward(l.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(n,e.range.fromB),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,l.toA),this.emit(e.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(n,l.toB)),n=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=ph(this.old),n=this.openMarks;this.old.advance(t,i?1:-1,{skip:(o,l,h)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(h-l);else{let a=h>0||l<o.length?le.of(o.widget,this.view,h-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,s,n),n=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&h==o.length?this.builder.addText(o.text,s,n,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,h),s,n)),n=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Ei)this.cache.add(o);else if(o instanceof lt)this.builder.ensureLine(null),this.builder.addMark(o,s,n),this.cache.reused.set(o,1),n=s.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof lt&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=n=0):o instanceof lt&&(s.shift(),n=Math.min(n,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,s=this.builder,n=0,o=z.spans(this.decorations,t,e,{point:(l,h,a,f,c,u)=>{if(a instanceof re){if(this.disallowBlockEffectsFor[u]){if(a.block)throw new RangeError("Block decorations may not be specified via plugins");if(h>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(n=f.length,c>f.length)s.continueWidget(h-l);else{let d=a.widget||(a.block?ke.block:ke.inline),p=uh(a),g=this.cache.findWidget(d,h-l,p)||le.of(d,this.view,h-l,p);a.block?(a.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(g)):(s.ensureLine(i),s.addInlineWidget(g,f,c))}i=null}else i=dh(i,a);h>l&&this.text.skip(h-l)},span:(l,h,a,f)=>{for(let c=l;c<h;){let u=this.text.next(Math.min(512,h-c));u==null?(s.addLineStartIfNotCovered(i),s.addBreak(),c++):(s.ensureLine(i),s.addText(u,a,c==l?f:a.length),c+=u.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=o>n,this.openMarks=o}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let n=Z.get(s);if(s==this.view.contentDOM)break;n instanceof lt?e.push(n):n?.isLine()?i=n:s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new we(s,xo):e.push(lt.of(new Xe({tagName:s.nodeName.toLowerCase(),attributes:Fl(s)}),s))}return{line:i,marks:e}}}function jn(r,t){let e=i=>{for(let s of i.children)if((t?s.isText():s.length)||e(s))return!0;return!1};return e(r)}function uh(r){let t=r.isReplace?(r.startSide<0?64:0)|(r.endSide>0?128:0):r.startSide>0?32:16;return r.block&&(t|=256),t}const xo={class:"cm-line"};function dh(r,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(r||(r={class:"cm-line"}),e&&Zs(e,r),i&&(r.class+=" "+i)),r}function ph(r){let t=[];for(let e=r.parents.length;e>1;e--){let i=e==r.parents.length?r.tile:r.parents[e].tile;i instanceof lt&&t.push(i.mark)}return t}function is(r){let t=Z.get(r);return t&&t.setDOM(r.cloneNode()),r}class ke extends Ye{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}ke.inline=new ke("span");ke.block=new ke("div");const ss=new class extends Ye{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class $n{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=K.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new ji(t,t.contentDOM),this.updateInner([new gt(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!vh(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let n=s>-1?mh(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new gt(f,c,t.changes.mapPos(f,-1),t.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=n?{from:n.range.fromB,to:n.range.toB}:null,(v.ie||v.chrome)&&!n&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let h=yh(o,this.decorations,t.changes);h.length&&(i=gt.extendWithRanges(i,h));let a=kh(l,this.blockWrappers,t.changes);return a.length&&(i=gt.extendWithRanges(i,a)),n&&!i.some(f=>f.fromA<=n.range.fromA&&f.toA>=n.range.toA)&&(i=n.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,n),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let o=this.tile,l=new ch(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(t,e),Fs(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=v.chrome||v.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),n&&(n.written||i.selectionRange.focusNode!=n.node||!this.tile.dom.contains(n.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let n of this.tile.children)n.isWidget()&&n.widget instanceof ns&&s.push(n.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(co)&&(this.editContextFormatting=i.value)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,n=s==i,o=!n&&!(this.view.state.facet(Nt)||i.tabIndex>-1)&&We(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(n||e||o))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,a,f;if(h.empty?f=a=this.inlineDOMNearPos(h.anchor,h.assoc||1):(f=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),a=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),v.gecko&&h.empty&&!this.hasComposition&&gh(a)){let u=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(u,a.node.childNodes[a.offset]||null)),a=f=new kt(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!He(a.node,a.offset,c.anchorNode,c.anchorOffset)||!He(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,h))&&(this.view.observer.ignore(()=>{v.android&&v.chrome&&i.contains(c.focusNode)&&Sh(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=ye(this.view.root);if(u)if(h.empty){if(v.gecko){let d=bh(a.node,a.offset);if(d&&d!=3){let p=(d==1?Jr:Yr)(a.node,a.offset);p&&(a=new kt(p.node,p.offset))}}u.collapse(a.node,a.offset),h.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=h.bidiLevel)}else if(u.extend){u.collapse(a.node,a.offset);try{u.extend(f.node,f.offset)}catch{}}else{let d=document.createRange();h.anchor>h.head&&([a,f]=[f,a]),d.setEnd(f.node,f.offset),d.setStart(a.node,a.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new kt(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new kt(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&He(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ye(t.root),{anchorNode:s,anchorOffset:n}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=this.lineAt(e.head,e.assoc);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let h=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!h||!a||h.bottom>a.top)return;let f=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(f.node,f.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(s,n)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let n;if(t==i.dom)n=i.dom.childNodes[e];else{let o=Ft(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?o=-1:o=1),t=l}o<0?n=t:n=t.nextSibling}if(n==i.dom.firstChild)return s;for(;n&&!Z.get(n);)n=n.nextSibling;if(!n)return s+i.length;for(let o=0,l=s;;o++){let h=i.children[o];if(h.dom==n)return l;l+=h.length+h.breakAfter}}else return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,n=!1,o,l=-1,h=!1;return this.tile.blockTiles((a,f)=>{if(a.isWidget()){if(a.flags&32&&f>=t)return!0;a.flags&16&&(n=!0)}else{let c=f+a.length;if(f<=t&&(i=a,s=t-f,n=c<t),c>=t&&!o&&(o=a,l=t-f,h=f>t),f>t&&o)return!0}}),!i&&!o?this.domAtPos(t,e):(n&&o?i=null:h&&i&&(o=null),i&&e<0||!o?i.domIn(s,e):o.domIn(l,e))}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof ns?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function s(n,o){if(n.isComposite())for(let l of n.children){if(l.length>=o){let h=s(l,o);if(h)return h}if(o-=l.length,o<0)break}else if(n.isText()&&o<n.length){let l=wt(n.text,o);if(l==o)return null;let h=Ue(n.dom,o,l).getClientRects();for(let a=0;a<h.length;a++){let f=h[a];if(a==h.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return s(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,n=this.view.contentDOM.clientWidth,o=n>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==tt.LTR,a=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>s);p++){let g=c.children[p],m=u+g.length,b=g.dom.getBoundingClientRect(),{height:A}=b;if(d&&!p&&(a+=b.top-d.top),g instanceof jt)m>i&&f(g,u,b);else if(u>=i&&(a>0&&e.push(-a),e.push(A+a),a=0,o)){let M=g.dom.lastChild,E=M?Fe(M):[];if(E.length){let O=E[E.length-1],P=h?O.right-b.left:b.right-O.left;P>l&&(l=P,this.minWidth=n,this.minWidthFrom=u,this.minWidthTo=m)}}d&&p==c.children.length-1&&(a+=d.bottom-b.bottom),u=m+g.breakAfter}};return f(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?tt.RTL:tt.LTR}measureTextSize(){let t=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,h;for(let a of o.children){if(!a.isText()||/[^ -~]/.test(a.text))return;let f=Fe(a.dom);if(f.length!=1)return;l+=f[0].width,h=f[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:h}}});if(t)return t;let e=document.createElement("div"),i,s,n;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.tile.dom.appendChild(e);let o=Fe(e.firstChild)[0];i=e.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,n=o&&o.height?o.height:i,e.remove()}),{lineHeight:i,charWidth:s,textHeight:n}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let n=s==e.viewports.length?null:e.viewports[s],o=n?n.from-1:this.view.state.doc.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(K.replace({widget:new ns(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!n)break;i=n.to+1}return K.set(t)}updateDeco(){let t=1,e=this.view.state.facet(zi).map(n=>(this.dynamicDecorationMap[t++]=typeof n=="function")?n(this.view):n),i=!1,s=this.view.state.facet(on).map((n,o)=>{let l=typeof n=="function";return l&&(i=!0),l?n(this.view):n});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(z.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(po).map(n=>typeof n=="function"?n(this.view):n)}scrollIntoView(t){if(t.isSnapshot){let a=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=a.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let a of this.view.state.facet(fo))try{if(a(this.view,t.range,t))return!0}catch(f){Bt(this.view.state,f,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let n=bo(this.view),o={left:i.left-n.left,top:i.top-n.top,right:i.right+n.right,bottom:i.bottom+n.bottom},{offsetWidth:l,offsetHeight:h}=this.view.scrollDOM;zl(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,h),-h),this.view.textDirection==tt.LTR)}lineHasWidget(t){let e=i=>i.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Fs(this.tile)}}function Fs(r,t){let e=t?.get(r);if(e!=1){e==null&&r.destroy();for(let i of r.children)Fs(i,t)}}function gh(r){return r.node.nodeType==1&&r.node.firstChild&&(r.offset==0||r.node.childNodes[r.offset-1].contentEditable=="false")&&(r.offset==r.node.childNodes.length||r.node.childNodes[r.offset].contentEditable=="false")}function yo(r,t){let e=r.observer.selectionRange;if(!e.focusNode)return null;let i=Jr(e.focusNode,e.focusOffset),s=Yr(e.focusNode,e.focusOffset),n=i||s;if(s&&i&&s.node!=i.node){let l=Z.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)n=s;else if(r.docView.lastCompositionAfterCursor){let h=Z.get(i.node);!h||h.isText()&&h.text!=i.node.nodeValue||(n=s)}}if(r.docView.lastCompositionAfterCursor=n!=i,!n)return null;let o=t-n.offset;return{from:o,to:o+n.node.nodeValue.length,node:n.node}}function mh(r,t,e){let i=yo(r,e);if(!i)return null;let{node:s,from:n,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||r.state.doc.sliceString(i.from,i.to)!=l)return null;let h=t.invertedDesc;return{range:new gt(h.mapPos(n),h.mapPos(o),n,o),text:s}}function bh(r,t){return r.nodeType!=1?0:(t&&r.childNodes[t-1].contentEditable=="false"?1:0)|(t<r.childNodes.length&&r.childNodes[t].contentEditable=="false"?2:0)}let xh=class{constructor(){this.changes=[]}compareRange(t,e){pe(t,e,this.changes)}comparePoint(t,e){pe(t,e,this.changes)}boundChange(t){pe(t,t,this.changes)}};function yh(r,t,e){let i=new xh;return z.compare(r,t,e,i),i.changes}class wh{constructor(){this.changes=[]}compareRange(t,e){pe(t,e,this.changes)}comparePoint(){}boundChange(t){pe(t,t,this.changes)}}function kh(r,t,e){let i=new wh;return z.compare(r,t,e,i),i.changes}function Sh(r,t){for(let e=r;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function vh(r,t){let e=!1;return t&&r.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}class ns extends Ye{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Ch(r,t,e=1){let i=r.charCategorizer(t),s=r.doc.lineAt(t),n=t-s.from;if(s.length==0)return k.cursor(t);n==0?e=1:n==s.length&&(e=-1);let o=n,l=n;e<0?o=wt(s.text,n,!1):l=wt(s.text,n);let h=i(s.text.slice(o,l));for(;o>0;){let a=wt(s.text,o,!1);if(i(s.text.slice(a,o))!=h)break;o=a}for(;l<s.length;){let a=wt(s.text,l);if(i(s.text.slice(l,a))!=h)break;l=a}return k.range(o+s.from,l+s.from)}function Ah(r,t,e,i,s){let n=Math.round((i-t.left)*r.defaultCharacterWidth);if(r.lineWrapping&&e.height>r.defaultLineHeight*1.5){let l=r.viewState.heightOracle.textHeight,h=Math.floor((s-e.top-(r.defaultLineHeight-l)*.5)/l);n+=h*r.viewState.heightOracle.lineLength}let o=r.state.sliceDoc(e.from,e.to);return e.from+Nl(o,n,r.state.tabSize)}function Oh(r,t,e){let i=r.lineBlockAt(t);if(Array.isArray(i.type)){let s;for(let n of i.type){if(n.from>t)break;if(!(n.to<t)){if(n.from<t&&n.to>t)return n;(!s||n.type==bt.Text&&(s.type!=n.type||(e<0?n.from<t:n.to>t)))&&(s=n)}}return s||i}return i}function Mh(r,t,e,i){let s=Oh(r,t.head,t.assoc||-1),n=!i||s.type!=bt.Text||!(r.lineWrapping||s.widgetLineBreaks)?null:r.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(n){let o=r.dom.getBoundingClientRect(),l=r.textDirectionAt(s.from),h=r.posAtCoords({x:e==(l==tt.LTR)?o.right-1:o.left+1,y:(n.top+n.bottom)/2});if(h!=null)return k.cursor(h,e?-1:1)}return k.cursor(e?s.to:s.from,e?-1:1)}function Kn(r,t,e,i){let s=r.state.doc.lineAt(t.head),n=r.bidiSpans(s),o=r.textDirectionAt(s.from);for(let l=t,h=null;;){let a=Zl(s,n,o,l,e),f=io;if(!a){if(s.number==(e?r.state.doc.lines:1))return l;f=`
|
|
8
|
-
`,s=r.state.doc.line(s.number+(e?1:-1)),n=r.bidiSpans(s),a=r.visualLineSide(s,!e)}if(h){if(!h(f))return l}else{if(!i)return a;h=i(f)}l=a}}function
|
|
9
|
-
`&&r.lineWrapping&&(i&&(i=k.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:W.of([" "])}),e)return ln(r,e,i,n);if(i&&!Ii(i,s)){let o=!1,l="select";return r.inputState.lastSelectionTime>Date.now()-50&&(r.inputState.lastSelectionOrigin=="select"&&(o=!0),l=r.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=wo(r.state.facet(ti).map(h=>h(r)),i))),r.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function ln(r,t,e,i=-1){if(v.ios&&r.inputState.flushIOSKey(t))return!0;let s=r.state.selection.main;if(v.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&r.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&ge(r.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&ge(r.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&ge(r.contentDOM,"Delete",46)))return!0;let n=t.insert.toString();r.inputState.composing>=0&&r.inputState.composing++;let o,l=()=>o||(o=Nh(r,t,e));return r.state.facet(lo).some(h=>h(r,t.from,t.to,n,l))||r.dispatch(l()),!0}function Nh(r,t,e){let i,s=r.state,n=s.selection.main,o=-1;if(t.from==t.to&&t.from<n.from||t.from>n.to){let h=t.from<n.from?-1:1,a=h<0?n.from:n.to,f=Ve(s.facet(ti).map(c=>c(r)),a,h);t.from==f&&(o=f)}if(o>-1)i={changes:t,selection:k.cursor(t.from+t.insert.length,-1)};else if(t.from>=n.from&&t.to<=n.to&&t.to-t.from>=(n.to-n.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&r.inputState.composing<0){let h=n.from<t.from?s.sliceDoc(n.from,t.from):"",a=n.to>t.to?s.sliceDoc(t.to,n.to):"";i=s.replaceSelection(r.state.toText(h+t.insert.sliceString(0,void 0,r.state.lineBreak)+a))}else{let h=s.changes(t),a=e&&e.main.to<=h.newLength?e.main:void 0;if(s.selection.ranges.length>1&&(r.inputState.composing>=0||r.inputState.compositionPendingChange)&&t.to<=n.to+10&&t.to>=n.to-10){let f=r.state.sliceDoc(t.from,t.to),c,u=e&&yo(r,e.main.head);if(u){let p=t.insert.length-(t.to-t.from);c={from:u.from,to:u.to-p}}else c=r.state.doc.lineAt(n.head);let d=n.to-t.to;i=s.changeByRange(p=>{if(p.from==n.from&&p.to==n.to)return{changes:h,range:a||p.map(h)};let g=p.to-d,m=g-f.length;if(r.state.sliceDoc(m,g)!=f||g>=c.from&&m<=c.to)return{range:p};let b=s.changes({from:m,to:g,insert:t.insert}),A=p.to-n.to;return{changes:b,range:a?k.range(Math.max(0,a.anchor+A),Math.max(0,a.head+A)):p.map(b)}})}else i={changes:h,selection:a&&s.selection.replaceRange(a)}}let l="input.type";return(r.composing||r.inputState.compositionPendingChange&&r.inputState.compositionEndedAt>Date.now()-50)&&(r.inputState.compositionPendingChange=!1,l+=".compose",r.inputState.compositionFirstChange&&(l+=".start",r.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Co(r,t,e,i){let s=Math.min(r.length,t.length),n=0;for(;n<s&&r.charCodeAt(n)==t.charCodeAt(n);)n++;if(n==s&&r.length==t.length)return null;let o=r.length,l=t.length;for(;o>0&&l>0&&r.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,n-Math.min(o,l));e-=o+h-n}if(o<n&&r.length<t.length){let h=e<=n&&e>=o?n-e:0;n-=h,l=n+(l-o),o=n}else if(l<n){let h=e<=n&&e>=l?n-e:0;n-=h,o=n+(o-l),l=n}return{from:n,toA:o,toB:l}}function Ih(r){let t=[];if(r.root.activeElement!=r.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:n}=r.observer.selectionRange;return e&&(t.push(new _n(e,i)),(s!=e||n!=i)&&t.push(new _n(s,n))),t}function Lh(r,t){if(r.length==0)return null;let e=r[0].pos,i=r.length==2?r[1].pos:e;return e>-1&&i>-1?k.single(e+t,i+t):null}function Ii(r,t){return t.head==r.main.head&&t.anchor==r.main.anchor}class Wh{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,v.safari&&t.contentDOM.addEventListener("input",()=>null),v.gecko&&Zh(t.contentDOM.ownerDocument)}handleEvent(t){!Qh(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Fh(t),i=this.handlers,s=this.view.contentDOM;for(let n in e)if(n!="scroll"){let o=!e[n].handlers.length,l=i[n];l&&o!=!l.handlers.length&&(s.removeEventListener(n,this.handleEvent),l=null),l||s.addEventListener(n,this.handleEvent,{passive:o})}for(let n in i)n!="scroll"&&!e[n]&&s.removeEventListener(n,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Vh.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),v.android&&v.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return v.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Ao.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||Hh.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,ge(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return!/^key/.test(t.type)||t.synthetic?!1:this.composing>0?!0:v.safari&&!v.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Gn(r,t){return(e,i)=>{try{return t.call(r,i,e)}catch(s){Bt(e.state,s)}}}function Fh(r){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of r){let s=i.spec,n=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(n)for(let l in n){let h=n[l];h&&e(l).handlers.push(Gn(i.value,h))}if(o)for(let l in o){let h=o[l];h&&e(l).observers.push(Gn(i.value,h))}}for(let i in vt)e(i).handlers.push(vt[i]);for(let i in xt)e(i).observers.push(xt[i]);return t}const Ao=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Hh="dthko",Vh=[16,17,18,20,91,92,224,225],di=6;function pi(r){return Math.max(0,r)*.7+8}function zh(r,t){return Math.max(Math.abs(r.clientX-t.clientX),Math.abs(r.clientY-t.clientY))}class qh{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=ql(t.contentDOM),this.atoms=t.state.facet(ti).map(o=>o(t));let n=t.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(V.allowMultipleSelections)&&jh(t,e),this.dragging=Kh(t,e)&&To(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&zh(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,n=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:n,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=bo(this.view);t.clientX-h.left<=s+di?e=-pi(s-t.clientX):t.clientX+h.right>=o-di&&(e=pi(t.clientX-o)),t.clientY-h.top<=n+di?i=-pi(n-t.clientY):t.clientY+h.bottom>=l-di&&(i=pi(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=wo(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function jh(r,t){let e=r.state.facet(so);return e.length?e[0](t):v.mac?t.metaKey:t.ctrlKey}function $h(r,t){let e=r.state.facet(no);return e.length?e[0](t):v.mac?!t.altKey:!t.ctrlKey}function Kh(r,t){let{main:e}=r.state.selection;if(e.empty)return!1;let i=ye(r.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let n=0;n<s.length;n++){let o=s[n];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Qh(r,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=r.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=Z.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}const vt=Object.create(null),xt=Object.create(null),Oo=v.ie&&v.ie_version<15||v.ios&&v.webkit_version<604;function _h(r){let t=r.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{r.focus(),e.remove(),Mo(r,e.value)},50)}function $i(r,t,e){for(let i of r.facet(t))e=i(e,r);return e}function Mo(r,t){t=$i(r.state,sn,t);let{state:e}=r,i,s=1,n=e.toText(t),o=n.lines==e.selection.ranges.length;if(Vs!=null&&e.selection.ranges.every(h=>h.empty)&&Vs==n.toString()){let h=-1;i=e.changeByRange(a=>{let f=e.doc.lineAt(a.from);if(f.from==h)return{range:a};h=f.from;let c=e.toText((o?n.line(s++).text:t)+e.lineBreak);return{changes:{from:f.from,insert:c},range:k.cursor(a.from+c.length)}})}else o?i=e.changeByRange(h=>{let a=n.line(s++);return{changes:{from:h.from,to:h.to,insert:a.text},range:k.cursor(h.from+a.length)}}):i=e.replaceSelection(n);r.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}xt.scroll=r=>{r.inputState.lastScrollTop=r.scrollDOM.scrollTop,r.inputState.lastScrollLeft=r.scrollDOM.scrollLeft};vt.keydown=(r,t)=>(r.inputState.setSelectionOrigin("select"),t.keyCode==27&&r.inputState.tabFocusMode!=0&&(r.inputState.tabFocusMode=Date.now()+2e3),!1);xt.touchstart=(r,t)=>{r.inputState.lastTouchTime=Date.now(),r.inputState.setSelectionOrigin("select.pointer")};xt.touchmove=r=>{r.inputState.setSelectionOrigin("select.pointer")};vt.mousedown=(r,t)=>{if(r.observer.flush(),r.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of r.state.facet(ro))if(e=i(r,t),e)break;if(!e&&t.button==0&&(e=Uh(r,t)),e){let i=!r.hasFocus;r.inputState.startMouseSelection(new qh(r,t,e,i)),i&&r.observer.ignore(()=>{Gr(r.contentDOM);let n=r.root.activeElement;n&&!n.contains(r.contentDOM)&&n.blur()});let s=r.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}else r.inputState.setSelectionOrigin("select.pointer");return!1};function Un(r,t,e,i){if(i==1)return k.cursor(t,e);if(i==2)return Ch(r.state,t,e);{let s=r.docView.lineAt(t,e),n=r.state.doc.lineAt(s?s.posAtEnd:t),o=s?s.posAtStart:n.from,l=s?s.posAtEnd:n.to;return l<r.state.doc.length&&l==n.to&&l++,k.range(o,l)}}const Gh=v.ie&&v.ie_version<=11;let Jn=null,Yn=0,Xn=0;function To(r){if(!Gh)return r.detail;let t=Jn,e=Xn;return Jn=r,Xn=Date.now(),Yn=!t||e>Date.now()-400&&Math.abs(t.clientX-r.clientX)<2&&Math.abs(t.clientY-r.clientY)<2?(Yn+1)%3:1}function Uh(r,t){let e=r.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=To(t),s=r.state.selection;return{update(n){n.docChanged&&(e.pos=n.changes.mapPos(e.pos),s=s.map(n.changes))},get(n,o,l){let h=r.posAndSideAtCoords({x:n.clientX,y:n.clientY},!1),a,f=Un(r,h.pos,h.assoc,i);if(e.pos!=h.pos&&!o){let c=Un(r,e.pos,e.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?k.range(u,d):k.range(d,u)}return o?s.replaceRange(s.main.extend(f.from,f.to)):l&&i==1&&s.ranges.length>1&&(a=Jh(s,h.pos))?a:l?s.addRange(f):k.create([f])}}}function Jh(r,t){for(let e=0;e<r.ranges.length;e++){let{from:i,to:s}=r.ranges[e];if(i<=t&&s>=t)return k.create(r.ranges.slice(0,e).concat(r.ranges.slice(e+1)),r.mainIndex==e?0:r.mainIndex-(r.mainIndex>e?1:0))}return null}vt.dragstart=(r,t)=>{let{selection:{main:e}}=r.state;if(t.target.draggable){let s=r.docView.tile.nearest(t.target);if(s&&s.isWidget()){let n=s.posAtStart,o=n+s.length;(n>=e.to||o<=e.from)&&(e=k.range(n,o))}}let{inputState:i}=r;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",$i(r.state,nn,r.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};vt.dragend=r=>(r.inputState.draggedContent=null,!1);function Zn(r,t,e,i){if(e=$i(r.state,sn,e),!e)return;let s=r.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:n}=r.inputState,o=i&&n&&$h(r,t)?{from:n.from,to:n.to}:null,l={from:s,insert:e},h=r.state.changes(o?[o,l]:l);r.focus(),r.dispatch({changes:h,selection:{anchor:h.mapPos(s,-1),head:h.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),r.inputState.draggedContent=null}vt.drop=(r,t)=>{if(!t.dataTransfer)return!1;if(r.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,n=()=>{++s==e.length&&Zn(r,t,i.filter(o=>o!=null).join(r.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=n,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),n()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Zn(r,t,i,!0),!0}return!1};vt.paste=(r,t)=>{if(r.state.readOnly)return!0;r.observer.flush();let e=Oo?null:t.clipboardData;return e?(Mo(r,e.getData("text/plain")||e.getData("text/uri-list")),!0):(_h(r),!1)};function Yh(r,t){let e=r.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),r.focus()},50)}function Xh(r){let t=[],e=[],i=!1;for(let s of r.selection.ranges)s.empty||(t.push(r.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:n}of r.selection.ranges){let o=r.doc.lineAt(n);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(r.doc.length,o.to+1)})),s=o.number}i=!0}return{text:$i(r,nn,t.join(r.lineBreak)),ranges:e,linewise:i}}let Vs=null;vt.copy=vt.cut=(r,t)=>{let e=ye(r.root);if(e&&!We(r.contentDOM,e))return!1;let{text:i,ranges:s,linewise:n}=Xh(r.state);if(!i&&!n)return!1;Vs=n?i:null,t.type=="cut"&&!r.state.readOnly&&r.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"});let o=Oo?null:t.clipboardData;return o?(o.clearData(),o.setData("text/plain",i),!0):(Yh(r,i),!1)};const Po=Oe.define();function Do(r,t){let e=[];for(let i of r.facet(ho)){let s=i(r,t);s&&e.push(s)}return e.length?r.update({effects:e,annotations:Po.of(!0)}):null}function Bo(r){setTimeout(()=>{let t=r.hasFocus;if(t!=r.inputState.notifiedFocused){let e=Do(r.state,t);e?r.dispatch(e):r.update([])}},10)}xt.focus=r=>{r.inputState.lastFocusTime=Date.now(),!r.scrollDOM.scrollTop&&(r.inputState.lastScrollTop||r.inputState.lastScrollLeft)&&(r.scrollDOM.scrollTop=r.inputState.lastScrollTop,r.scrollDOM.scrollLeft=r.inputState.lastScrollLeft),Bo(r)};xt.blur=r=>{r.observer.clearSelectionRange(),Bo(r)};xt.compositionstart=xt.compositionupdate=r=>{r.observer.editContext||(r.inputState.compositionFirstChange==null&&(r.inputState.compositionFirstChange=!0),r.inputState.composing<0&&(r.inputState.composing=0))};xt.compositionend=r=>{r.observer.editContext||(r.inputState.composing=-1,r.inputState.compositionEndedAt=Date.now(),r.inputState.compositionPendingKey=!0,r.inputState.compositionPendingChange=r.observer.pendingRecords().length>0,r.inputState.compositionFirstChange=null,v.chrome&&v.android?r.observer.flushSoon():r.inputState.compositionPendingChange?Promise.resolve().then(()=>r.observer.flush()):setTimeout(()=>{r.inputState.composing<0&&r.docView.hasComposition&&r.update([])},50))};xt.contextmenu=r=>{r.inputState.lastContextMenu=Date.now()};vt.beforeinput=(r,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(r.inputState.insertingText=t.data,r.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&r.observer.editContext){let n=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(n&&o.length){let l=o[0],h=r.posAtDOM(l.startContainer,l.startOffset),a=r.posAtDOM(l.endContainer,l.endOffset);return ln(r,{from:h,to:a,insert:r.state.toText(n)},null),!0}}let s;if(v.chrome&&v.android&&(s=Ao.find(n=>n.inputType==t.inputType))&&(r.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let n=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>n+10&&r.hasFocus&&(r.contentDOM.blur(),r.focus())},100)}return v.ios&&t.inputType=="deleteContentForward"&&r.observer.flushSoon(),v.safari&&t.inputType=="insertText"&&r.inputState.composing>=0&&setTimeout(()=>xt.compositionend(r,t),20),!1};const tr=new Set;function Zh(r){tr.has(r)||(tr.add(r),r.addEventListener("copy",()=>{}),r.addEventListener("cut",()=>{}))}const er=["pre-wrap","normal","pre-line","break-spaces"];let Se=!1;function ir(){Se=!1}class ta{constructor(t){this.lineWrapping=t,this.doc=W.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return er.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,n,o){let l=er.indexOf(t)>-1,h=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=n,h){this.heightSamples={};for(let a=0;a<o.length;a++){let f=o[a];f<0?a++:this.heightSamples[Math.floor(f*10)]=!0}}return h}}class ea{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class yt{constructor(t,e,i,s,n){this.from=t,this.length=e,this.top=i,this.height=s,this._content=n}get type(){return typeof this._content=="number"?bt.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof re?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new yt(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var $=(function(r){return r[r.ByPos=0]="ByPos",r[r.ByHeight=1]="ByHeight",r[r.ByPosNoHeight=2]="ByPosNoHeight",r})($||($={}));const vi=.001;class ot{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>vi&&(Se=!0),this.height=t)}replace(t,e,i){return ot.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let n=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:h,toA:a,fromB:f,toB:c}=s[l],u=n.lineAt(h,$.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=a?u:n.lineAt(a,$.ByPosNoHeight,i,0,0);for(c+=d.to-a,a=d.to;l>0&&u.from<=s[l-1].toA;)h=s[l-1].fromA,f=s[l-1].fromB,l--,h<u.from&&(u=n.lineAt(h,$.ByPosNoHeight,i,0,0));f+=u.from-h,h=u.from;let p=hn.build(i.setDoc(o),t,f,c);n=Li(n,n.replace(h,a,p))}return n.updateHeight(i,0)}static empty(){return new ft(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,n=0;for(;;)if(e==i)if(s>n*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(n>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,n-=l.size}else break;else if(s<n){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(n+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new sa(ot.of(t.slice(0,e)),o,ot.of(t.slice(i)))}}function Li(r,t){return r==t?r:(r.constructor!=t.constructor&&(Se=!0),t)}ot.prototype.size=1;const ia=K.replace({});class Ro extends ot{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new yt(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new yt(s,0,i,this.spaceAbove,ia):this.mainBlock(i,s)}lineAt(t,e,i,s,n){let o=this.mainBlock(s,n);return this.spaceAbove?this.blockAt(0,i,s,n).join(o):o}forEachLine(t,e,i,s,n,o){t<=n+this.length&&e>=n&&o(this.lineAt(0,$.ByPos,i,s,n))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class ft extends Ro{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new yt(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof ft||s instanceof it&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof it?s=new ft(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):ot.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class it extends ot{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,n=s-i+1,o,l=0;if(t.lineWrapping){let h=Math.min(this.height,t.lineHeight*n);o=h/n,this.length>n+1&&(l=(this.height-h)/(this.length-n-1))}else o=this.height/n;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(t,e,i,s){let{firstLine:n,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(e,s);if(e.lineWrapping){let a=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),f=e.doc.lineAt(a),c=l+f.length*h,u=Math.max(i,t-c/2);return new yt(f.from,f.length,u,c,0)}else{let a=Math.max(0,Math.min(o-n,Math.floor((t-i)/l))),{from:f,length:c}=e.doc.line(n+a);return new yt(f,c,i+l*a,l,0)}}lineAt(t,e,i,s,n){if(e==$.ByHeight)return this.blockAt(t,i,s,n);if(e==$.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new yt(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,n),a=i.doc.lineAt(t),f=l+a.length*h,c=a.number-o,u=s+l*c+h*(a.from-n-c);return new yt(a.from,a.length,Math.max(s,Math.min(u,s+this.height-f)),f,0)}forEachLine(t,e,i,s,n,o){t=Math.max(t,n),e=Math.min(e,n+this.length);let{firstLine:l,perLine:h,perChar:a}=this.heightMetrics(i,n);for(let f=t,c=s;f<=e;){let u=i.doc.lineAt(f);if(f==t){let p=u.number-l;c+=h*p+a*(t-n-p)}let d=h+a*u.length;o(new yt(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let n=i[i.length-1];n instanceof it?i[i.length-1]=new it(n.length+s):i.push(null,new it(s-1))}if(t>0){let n=i[0];n instanceof it?i[0]=new it(t+n.length):i.unshift(new it(t-1),null)}return ot.of(i)}decomposeLeft(t,e){e.push(new it(t-1),null)}decomposeRight(t,e){e.push(null,new it(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let n=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),h=-1;for(s.from>e&&o.push(new it(s.from-e-1).updateHeight(t,e));l<=n&&s.more;){let f=t.doc.lineAt(l).length;o.length&&o.push(null);let c=s.heights[s.index++],u=0;c<0&&(u=-c,c=s.heights[s.index++]),h==-1?h=c:Math.abs(c-h)>=vi&&(h=-2);let d=new ft(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=n&&o.push(null,new it(n-l).updateHeight(t,l));let a=ot.of(o);return(h<0||Math.abs(a.height-this.height)>=vi||Math.abs(h-this.heightMetrics(t,e).perLine)>=vi)&&(Se=!0),Li(this,a)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class sa extends ot{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let n=i+this.left.height;return t<n?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,n,s+this.left.length+this.break)}lineAt(t,e,i,s,n){let o=s+this.left.height,l=n+this.left.length+this.break,h=e==$.ByHeight?t<o:t<l,a=h?this.left.lineAt(t,e,i,s,n):this.right.lineAt(t,e,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let f=e==$.ByPosNoHeight?$.ByPosNoHeight:$.ByPos;return h?a.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,s,n).join(a)}forEachLine(t,e,i,s,n,o){let l=s+this.left.height,h=n+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,s,n,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let a=this.lineAt(h,$.ByPos,i,s,n);t<a.from&&this.left.forEachLine(t,a.from-1,i,s,n,o),a.to>=t&&a.from<=e&&o(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,l,h,o)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let n=[];t>0&&this.decomposeLeft(t,n);let o=n.length;for(let l of i)n.push(l);if(t>0&&sr(n,o-1),e<this.length){let l=n.length;this.decomposeRight(e,n),sr(n,l)}return ot.of(n)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?ot.of(this.break?[t,null,e]:[t,e]):(this.left=Li(this.left,t),this.right=Li(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:n,right:o}=this,l=e+n.length+this.break,h=null;return s&&s.from<=e+n.length&&s.more?h=n=n.updateHeight(t,e,i,s):n.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?h=o=o.updateHeight(t,l,i,s):o.updateHeight(t,l,i),h?this.balanced(n,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function sr(r,t){let e,i;r[t]==null&&(e=r[t-1])instanceof it&&(i=r[t+1])instanceof it&&r.splice(t-1,3,new it(e.length+1+i.length))}const na=5;class hn{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof ft?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new ft(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,n=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new Ro(o,s,i)):(o||n||s>=na)&&this.addLineDeco(s,n,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new ft(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new it(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof ft)return t;let e=new ft(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof ft)&&!this.isCovered?this.nodes.push(new ft(0,-1,0)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof ft&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let n=new hn(i,t);return z.spans(e,i,s,n,0),n.finish(i)}}function ra(r,t,e){let i=new oa;return z.compare(r,t,e,i,0),i.changes}class oa{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&pe(t,e,this.changes,5)}}function la(r,t){let e=r.getBoundingClientRect(),i=r.ownerDocument,s=i.defaultView||window,n=Math.max(0,e.left),o=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),h=Math.min(s.innerHeight,e.bottom);for(let a=r.parentNode;a&&a!=i.body;)if(a.nodeType==1){let f=a,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();n=Math.max(n,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(a==r.parentNode?s.innerHeight:h,u.bottom)}a=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(a.nodeType==11)a=a.host;else break;return{left:n-e.left,right:Math.max(n,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,h)-(e.top+t)}}function ha(r){let t=r.getBoundingClientRect(),e=r.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function aa(r,t){let e=r.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class os{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],n=e[i];if(s.from!=n.from||s.to!=n.to||s.size!=n.size)return!1}return!0}draw(t,e){return K.replace({widget:new fa(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class fa extends Ye{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class nr{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=rr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=tt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(rn).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new ta(e),this.stateDeco=or(t),this.heightMap=ot.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle.setDoc(t.doc),[new gt(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=K.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:n,to:o})=>s>=n&&s<=o)){let{from:n,to:o}=this.lineBlockAt(s);t.push(new gi(n,o))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?rr:new an(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Ee(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=or(this.state);let s=t.changedRanges,n=gt.extendWithRanges(s,ra(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ir(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),n),(this.heightMap.height!=o||Se)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let h=n.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<h.from||e.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let a=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,t.flags|=this.updateForViewport(),(a||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(eh)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,n=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?tt.RTL:tt.LTR;let o=this.heightOracle.mustRefreshForWrapping(n)||this.mustMeasureContent,l=e.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let a=0,f=0;if(l.width&&l.height){let{scaleX:E,scaleY:O}=_r(e,l);(E>.005&&Math.abs(this.scaleX-E)>.005||O>.005&&Math.abs(this.scaleY-O)>.005)&&(this.scaleX=E,this.scaleY=O,a|=16,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Ur(t.scrollDOM);let p=(this.printing?aa:la)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(h=!0)),!this.inView&&!this.scrollTarget&&!ha(t.dom))return 0;let A=l.width;if((this.contentDOMWidth!=A||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),h){let E=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(E)&&(o=!0),o||s.lineWrapping&&Math.abs(A-this.contentDOMWidth)>s.charWidth){let{lineHeight:O,charWidth:P,textHeight:C}=t.docView.measureTextSize();o=O>0&&s.refresh(n,O,P,C,Math.max(5,A/P),E),o&&(t.docView.minWidth=0,a|=16)}g>0&&m>0?f=Math.max(g,m):g<0&&m<0&&(f=Math.min(g,m)),ir();for(let O of this.viewports){let P=O.from==this.viewport.from?E:t.docView.measureVisibleLineHeights(O);this.heightMap=(o?ot.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle,[new gt(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new ea(O.from,P))}Se&&(a|=2)}let M=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return M&&(a&2&&(a|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),a|=this.updateForViewport()),(a&2||M)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,n=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new gi(s.lineAt(o-i*1e3,$.ByHeight,n,0,0).from,s.lineAt(l+(1-i)*1e3,$.ByHeight,n,0,0).to);if(e){let{head:a}=e.range;if(a<h.from||a>h.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=s.lineAt(a,$.ByPos,n,0,0),u;e.y=="center"?u=(c.top+c.bottom)/2-f/2:e.y=="start"||e.y=="nearest"&&a<h.from?u=c.top:u=c.bottom-f,h=new gi(s.lineAt(u-1e3/2,$.ByHeight,n,0,0).from,s.lineAt(u+f+1e3/2,$.ByHeight,n,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new gi(this.heightMap.lineAt(i,$.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,$.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),{bottom:n}=this.heightMap.lineAt(e,$.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||n>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&n<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new os(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,n=s>>1,o=s<<1;if(this.defaultTextDirection!=tt.LTR&&!i)return[];let l=[],h=(f,c,u,d)=>{if(c-f<n)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let b of g)if(b>f&&b<c){h(f,b-10,u,d),h(b+10,c,u,d);return}let m=ua(t,b=>b.from>=u.from&&b.to<=u.to&&Math.abs(b.from-f)<n&&Math.abs(b.to-c)<n&&!g.some(A=>b.from<A&&b.to>A));if(!m){if(c<u.to&&e&&i&&e.visibleRanges.some(M=>M.from<=c&&M.to>=c)){let M=e.moveToLineBoundary(k.cursor(c),!1,!0).head;M>f&&(c=M)}let b=this.gapSize(u,f,c,d),A=i||b<2e6?b:2e6;m=new os(f,c,b,A)}l.push(m)},a=f=>{if(f.length<o||f.type!=bt.Text)return;let c=ca(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,b;if(u!=null){let A=bi(c,u),M=((this.visibleBottom-this.visibleTop)/2+g)/f.height;m=A-M,b=A+M}else m=(this.visibleTop-f.top-g)/f.height,b=(this.visibleBottom-f.top+g)/f.height;d=mi(c,m),p=mi(c,b)}else{let g=c.total*this.heightOracle.charWidth,m=s*this.heightOracle.charWidth,b=0;if(g>2e6)for(let P of t)P.from>=f.from&&P.from<f.to&&P.size!=P.displaySize&&P.from*this.heightOracle.charWidth+b<this.pixelViewport.left&&(b=P.size-P.displaySize);let A=this.pixelViewport.left+b,M=this.pixelViewport.right+b,E,O;if(u!=null){let P=bi(c,u),C=((M-A)/2+m)/g;E=P-C,O=P+C}else E=(A-m)/g,O=(M+m)/g;d=mi(c,E),p=mi(c,O)}d>f.from&&h(f.from,d,f,c),p<f.to&&h(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(a):a(f);return l}gapSize(t,e,i,s){let n=bi(s,i)-bi(s,e);return this.heightOracle.lineWrapping?t.height*n:s.total*this.heightOracle.charWidth*n}updateLineGaps(t){os.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=K.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];z.spans(e,this.viewport.from,this.viewport.to,{span(n,o){i.push({from:n,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let n=0;n<i.length&&!(s&8);n++){let o=this.visibleRanges[n],l=i[n];(o.from!=l.from||o.to!=l.to)&&(s|=4,t&&t.mapPos(o.from,-1)==l.from&&t.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Ee(this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Ee(this.heightMap.lineAt(this.scaler.fromDOM(t),$.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Ee(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class gi{constructor(t,e){this.from=t,this.to=e}}function ca(r,t,e){let i=[],s=r,n=0;return z.spans(e,r,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),n+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),n+=t-s),{total:n,ranges:i}}function mi({total:r,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(r*e);for(let s=0;;s++){let{from:n,to:o}=t[s],l=o-n;if(i<=l)return n+i;i-=l}}function bi(r,t){let e=0;for(let{from:i,to:s}of r.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/r.total}function ua(r,t){for(let e of r)if(t(e))return e}const rr={toDOM(r){return r},fromDOM(r){return r},scale:1,eq(r){return r==this}};function or(r){let t=r.facet(zi).filter(i=>typeof i!="function"),e=r.facet(on).filter(i=>typeof i!="function");return e.length&&t.push(z.join(e)),t}class an{constructor(t,e,i){let s=0,n=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=e.lineAt(l,$.ByPos,t,0,0).top,f=e.lineAt(h,$.ByPos,t,0,0).bottom;return s+=f-a,{from:l,to:h,top:a,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=o+(l.top-n)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),n=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let n=e<this.viewports.length?this.viewports[e]:null;if(!n||t<n.top)return s+(t-i)*this.scale;if(t<=n.bottom)return n.domTop+(t-n.top);i=n.bottom,s=n.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let n=e<this.viewports.length?this.viewports[e]:null;if(!n||t<n.domTop)return i+(t-s)/this.scale;if(t<=n.domBottom)return n.top+(t-n.domTop);i=n.bottom,s=n.domBottom}}eq(t){return t instanceof an?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Ee(r,t){if(t.scale==1)return r;let e=t.toDOM(r.top),i=t.toDOM(r.bottom);return new yt(r.from,r.length,e,i-e,Array.isArray(r._content)?r._content.map(s=>Ee(s,t)):r._content)}const xi=D.define({combine:r=>r.join(" ")}),zs=D.define({combine:r=>r.indexOf(!0)>-1}),qs=Kt.newName(),Eo=Kt.newName(),No=Kt.newName(),Io={"&light":"."+Eo,"&dark":"."+No};function js(r,t,e){return new Kt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return r;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):r+" "+i}})}const da=js("."+qs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,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"}},Io),pa={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},ls=v.ie&&v.ie_version<=11;class ga{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new jl,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(v.ie&&v.ie_version<=11||v.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&v.android&&t.constructor.EDIT_CONTEXT!==!1&&!(v.chrome&&v.chrome_version<126)&&(this.editContext=new ba(t),t.state.facet(Nt)&&(t.contentDOM.editContext=this.editContext.editContext)),ls&&(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),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{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()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(Nt)?i.root.activeElement!=this.dom:!We(this.dom,s))return;let n=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(n&&n.isWidget()&&n.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(v.ie&&v.ie_version<=11||v.android&&v.chrome)&&!i.state.selection.main.empty&&s.focusNode&&He(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ye(t.root);if(!e)return!1;let i=v.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&ma(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=We(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&Kl(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,pa),ls&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),ls&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let n=this.delayedAndroidKey;n&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=n.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&n.force&&ge(this.dom,n.key,n.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let n of t){let o=this.readMutation(n);o&&(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&We(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let n=new Eh(this.view,t,e,i);return this.view.docView.domChanged={newSel:n.newSel?n.newSel.main:null},n}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=vo(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Ii(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=lr(e,t.previousSibling||t.target.previousSibling,-1),s=lr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Nt)!=t.state.facet(Nt)&&(t.view.contentDOM.editContext=t.state.facet(Nt)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function lr(r,t,e){for(;t;){let i=Z.get(t);if(i&&i.parent==r)return i;let s=t.parentNode;t=s!=r.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function hr(r,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,n=t.endOffset,o=r.docView.domAtPos(r.state.selection.main.anchor,1);return He(o.node,o.offset,s,n)&&([e,i,s,n]=[s,n,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:n}}function ma(r,t){if(t.getComposedRanges){let s=t.getComposedRanges(r.root)[0];if(s)return hr(r,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return r.contentDOM.addEventListener("beforeinput",i,!0),r.dom.ownerDocument.execCommand("indent"),r.contentDOM.removeEventListener("beforeinput",i,!0),e?hr(r,e):null}class ba{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:n,head:o}=s,l=this.toEditorPos(i.updateRangeStart),h=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let a=h-l>i.text.length;l==this.from&&n<this.from?l=n:h==this.to&&n>this.to&&(h=n);let f=Co(t.state.sliceDoc(l,h),i.text,(a?s.from:s.to)-l,a?"end":null);if(!f){let u=k.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Ii(u,s)||t.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:W.of(i.text.slice(f.from,f.toB).split(`
|
|
10
|
-
`))};if((v.mac||v.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:h,insert:W.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!t.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);ln(t,c,k.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),c.from<c.to&&!c.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],n=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let h=t.coordsForChar(o);n=h&&new DOMRect(h.left,h.top,h.right-h.left,h.bottom-h.top)||n||new DOMRect,s.push(n)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let n of i.getTextFormats()){let o=n.underlineStyle,l=n.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let h=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);if(h<a){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(K.mark({attributes:{style:f}}).range(h,a))}}}t.dispatch({effects:co.of(K.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=ye(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((n,o,l,h,a)=>{if(i)return;let f=a.length-(o-n);if(s&&o>=s.to)if(s.from==n&&s.to==o&&s.insert.eq(a)){s=this.pendingContextChange=null,e+=f,this.to+=f;return}else s=null,this.revertPending(t.state);if(n+=e,o+=e,o<=this.from)this.from+=f,this.to+=f;else if(n<this.to){if(n<this.from||o>this.to||this.to-this.from+a.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(n),this.toContextPos(o),a.toString()),this.to+=f}e+=f}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class B{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(n=>i(n,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||$l(t.parent)||document,this.viewState=new nr(t.state||V.create(t)),t.scrollTo&&t.scrollTo.is(ui)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(fe).map(s=>new es(s));for(let s of this.plugins)s.update(this);this.observer=new ga(this),this.inputState=new Wh(this),this.inputState.ensureHandlers(this.plugins),this.docView=new $n(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=!0,this.requestMeasure()})}dispatch(...t){let e=t.length==1&&t[0]instanceof rt?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,n=this.state;for(let u of t){if(u.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=u.state}if(this.destroyed){this.viewState.state=n;return}let o=this.hasFocus,l=0,h=null;t.some(u=>u.annotation(Po))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=Do(n,o),h||(l=1));let a=this.observer.delayedAndroidKey,f=null;if(a?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(f=null)):this.observer.clear(),n.facet(V.phrases)!=this.state.facet(V.phrases))return this.setState(n);s=Ri.create(this,n,t),s.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new me(d.empty?d:k.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(ui)&&(c=d.value.clip(this.state))}this.viewState.update(s,c),this.bidiCache=Wi.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Be)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(xi)!=s.state.facet(xi)&&(this.viewState.mustMeasureContent=!0),(e||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(Ws))try{u(s)}catch(d){Bt(this.state,d,"update listener")}(h||f)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),f&&!vo(this,f)&&a.force&&ge(this.contentDOM,a.key,a.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new nr(t),this.plugins=t.facet(fe).map(i=>new es(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new $n(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(fe),i=t.state.facet(fe);if(e!=i){let s=[];for(let n of i){let o=e.indexOf(n);if(o<0)s.push(new es(n));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let n of this.plugins)n.mustUpdate!=t&&n.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Bt(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:n,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Ur(i))n=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);n=d.from,o=d.top}this.updateState=1;let h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let a=[];h&4||([this.measureRequests,a]=[a,this.measureRequests]);let f=a.map(d=>{try{return d.read(this)}catch(p){return Bt(this.state,p),ar}}),c=Ri.create(this,this.state,[]),u=!1;c.flags|=h,e?e.flags|=h:e=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<a.length;d++)if(f[d]!=ar)try{let p=a[d];p.write&&p.write(f[d],this)}catch(p){Bt(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(n<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(n).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Ws))l(e)}get themeClasses(){return qs+" "+(this.state.facet(zs)?No:Eo)+" "+this.state.facet(xi)}updateAttrs(){let t=fr(this,uo,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Nt)?"true":"false",class:"cm-content",style:`${v.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),fr(this,rn,e);let i=this.observer.ignore(()=>{let s=Fn(this.contentDOM,this.contentAttrs,e),n=Fn(this.dom,this.editorAttrs,t);return s||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(B.announce)){e&&(this.announceDOM.textContent=""),e=!1;let n=this.announceDOM.appendChild(document.createElement("div"));n.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Be);let t=this.state.facet(B.cspNonce);Kt.mount(this.root,this.styleModules.concat(da).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return rs(this,t,Kn(this,t,e,i))}moveByGroup(t,e){return rs(this,t,Kn(this,t,e,i=>Th(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),n=i[e?i.length-1:0];return k.cursor(n.side(e,s)+t.from,n.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return Mh(this,t,e,i)}moveVertically(t,e,i){return rs(this,t,Ph(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=Hs(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Hs(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),n=this.bidiSpans(s),o=n[Lt.find(n,t-s.from,-1,e)];return Ge(i,o.dir==tt.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(ao)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>xa)return eo(t.length);let e=this.textDirectionAt(t.from),i;for(let n of this.bidiCache)if(n.from==t.from&&n.dir==e&&(n.fresh||to(n.isolates,i=zn(this,t))))return n.order;i||(i=zn(this,t));let s=Xl(t.text,e,i);return this.bidiCache.push(new Wi(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||v.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Gr(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return ui.of(new me(typeof t=="number"?k.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return ui.of(new me(k.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return _t.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return _t.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Kt.newName(),s=[xi.of(i),Be.of(js(`.${i}`,t))];return e&&e.dark&&s.push(zs.of(!0)),s}static baseTheme(t){return Nr.lowest(Be.of(js("."+qs,t,Io)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Z.get(i)||Z.get(t);return((e=s?.root)===null||e===void 0?void 0:e.view)||null}}B.styleModule=Be;B.inputHandler=lo;B.clipboardInputFilter=sn;B.clipboardOutputFilter=nn;B.scrollHandler=fo;B.focusChangeEffect=ho;B.perLineTextDirection=ao;B.exceptionSink=oo;B.updateListener=Ws;B.editable=Nt;B.mouseSelectionStyle=ro;B.dragMovesSelection=no;B.clickAddsSelectionRange=so;B.decorations=zi;B.blockWrappers=po;B.outerDecorations=on;B.atomicRanges=ti;B.bidiIsolatedRanges=go;B.scrollMargins=mo;B.darkTheme=zs;B.cspNonce=D.define({combine:r=>r.length?r[0]:""});B.contentAttributes=rn;B.editorAttributes=uo;B.lineWrapping=B.contentAttributes.of({class:"cm-lineWrapping"});B.announce=X.define();const xa=4096,ar={};class Wi{constructor(t,e,i,s,n,o){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=n,this.order=o}static update(t,e){if(e.empty&&!t.some(n=>n.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:tt.LTR;for(let n=Math.max(0,t.length-10);n<t.length;n++){let o=t[n];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new Wi(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function fr(r,t,e){for(let i=r.state.facet(t),s=i.length-1;s>=0;s--){let n=i[s],o=typeof n=="function"?n(r):n;o&&Zs(o,e)}return e}class ya extends Ye{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?Fe(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Ge(e[0],i.direction!="rtl"),n=parseInt(i.lineHeight);return s.bottom-s.top>n*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+n}:s}ignoreEvent(){return!1}}function cr(r){let t=_t.fromClass(class{constructor(e){this.view=e,this.placeholder=r?K.set([K.widget({widget:new ya(r),side:1}).range(0)]):K.none}get decorations(){return this.view.state.doc.length?K.none:this.placeholder}},{decorations:e=>e.decorations});return typeof r=="string"?[t,B.contentAttributes.of({"aria-placeholder":r})]:t}class ve extends ne{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}ve.prototype.elementClass="";ve.prototype.toDOM=void 0;ve.prototype.mapMode=ct.TrackBefore;ve.prototype.startSide=ve.prototype.endSide=-1;ve.prototype.point=!0;var hs;const ce=new L;function wa(r){return D.define({combine:r?t=>t.concat(r):void 0})}const ka=new L;class St{constructor(t,e,i=[],s=""){this.data=t,this.name=s,V.prototype.hasOwnProperty("tree")||Object.defineProperty(V.prototype,"tree",{get(){return Je(this)}}),this.parser=e,this.extension=[Ae.of(this),V.languageData.of((n,o,l)=>{let h=ur(n,o,l),a=h.type.prop(ce);if(!a)return[];let f=n.facet(a),c=h.type.prop(ka);if(c){let u=h.resolve(o-h.from,l);for(let d of c)if(d.test(u,n)){let p=n.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(t,e,i=-1){return ur(t,e,i).type.prop(ce)==this.data}findRegions(t){let e=t.facet(Ae);if(e?.data==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(n,o)=>{if(n.prop(ce)==this.data){i.push({from:o,to:o+n.length});return}let l=n.prop(L.mounted);if(l){if(l.tree.prop(ce)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+n.length});return}else if(l.overlay){let h=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<n.children.length;h++){let a=n.children[h];a instanceof Y&&s(a,n.positions[h]+o)}};return s(Je(t),0),i}get allowsNesting(){return!0}}St.setState=X.define();function ur(r,t,e){let i=r.facet(Ae),s=Je(r).topNode;if(!i||i.allowsNesting)for(let n=s;n;n=n.enter(t,e,U.ExcludeBuffers|U.EnterBracketed))n.type.isTop&&(s=n);return s}class Fi extends St{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=wa(t.languageData);return new Fi(e,t.parser.configure({props:[ce.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new Fi(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Je(r){let t=r.field(St.state,!1);return t?t.tree:Y.empty}class Sa{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let De=null;class Hi{constructor(t,e,i=[],s,n,o,l,h){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=n,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Hi(t,e,[],Y.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Sa(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=Y.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(ie.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(ie.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=De;De=this;try{return t()}finally{De=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=dr(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:n,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let h=[];if(t.iterChangedRanges((a,f,c,u)=>h.push({fromA:a,toA:f,fromB:c,toB:u})),i=ie.applyChanges(i,h),s=Y.empty,n=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let a of this.skipped){let f=t.mapPos(a.from,1),c=t.mapPos(a.to,-1);f<c&&l.push({from:f,to:c})}}}return new Hi(this.parser,e,i,s,n,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:n}=this.skipped[i];s<t.to&&n>t.from&&(this.fragments=dr(this.fragments,s,n),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Sr{createParse(e,i,s){let n=s[0].from,o=s[s.length-1].to;return{parsedPos:n,advance(){let h=De;if(h){for(let a of s)h.tempSkipped.push(a);t&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,t]):t)}return this.parsedPos=o,new Y(ht.none,[],[],o-n)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return De}}function dr(r,t,e){return ie.applyChanges(r,[{fromA:t,toA:e,fromB:t,toB:e}])}class Ce{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ce(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Hi.create(t.facet(Ae).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ce(i)}}St.state=Gt.define({create:Ce.init,update(r,t){for(let e of t.effects)if(e.is(St.setState))return e.value;return t.startState.facet(Ae)!=t.state.facet(Ae)?Ce.init(t.state):r.apply(t)}});let Lo=r=>{let t=setTimeout(()=>r(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Lo=r=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(r,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const as=typeof navigator<"u"&&(!((hs=navigator.scheduling)===null||hs===void 0)&&hs.isInputPending)?()=>navigator.scheduling.isInputPending():null,va=_t.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(St.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(St.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=Lo(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,n=i.field(St.state);if(n.tree==n.context.tree&&n.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!as?Math.max(25,t.timeRemaining()-5):1e9),l=n.context.treeLen<s&&i.doc.length>s+1e3,h=n.context.work(()=>as&&as()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-e,(h||this.chunkBudget<=0)&&(n.context.takeTree(),this.view.dispatch({effects:St.setState.of(new Ce(n.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(n.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Bt(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ae=D.define({combine(r){return r.length?r[0]:null},enables:r=>[St.state,va,B.contentAttributes.compute([r],t=>{let e=t.facet(r);return e&&e.name?{"data-language":e.name}:{}})]});class Ca{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Aa=new L;function pr({except:r,units:t=1}={}){return e=>{let i=r&&r.test(e.textAfter);return e.baseIndent+(i?0:t*e.unit)}}const Oa=new L;function Ma(r){let t=r.firstChild,e=r.lastChild;return t&&t.to<e.from?{from:t.to,to:e.type.isError?r.to:e.from}:null}class Ki{constructor(t,e){this.specs=t;let i;function s(l){let h=Kt.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const n=typeof e.all=="string"?e.all:e.all?s(e.all):void 0,o=e.scope;this.scope=o instanceof St?l=>l.prop(ce)==o.data:o?l=>l==o:void 0,this.style=Ar(t.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:n}).style,this.module=i?new Kt(i):null,this.themeType=e.themeType}static define(t,e){return new Ki(t,e||{})}}const $s=D.define(),Wo=D.define({combine(r){return r.length?[r[0]]:null}});function fs(r){let t=r.facet($s);return t.length?t:r.facet(Wo)}function Ta(r,t){let e=[Da],i;return r instanceof Ki&&(r.module&&e.push(B.styleModule.of(r.module)),i=r.themeType),t?.fallback?e.push(Wo.of(r)):i?e.push($s.computeN([B.darkTheme],s=>s.facet(B.darkTheme)==(i=="dark")?[r]:[])):e.push($s.of(r)),e}class Pa{constructor(t){this.markCache=Object.create(null),this.tree=Je(t.state),this.decorations=this.buildDeco(t,fs(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Je(t.state),i=fs(t.state),s=i!=fs(t.startState),{viewport:n}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<n.to&&!s&&e.type==this.tree.type&&o>=n.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=n.to)}buildDeco(t,e){if(!e||!this.tree.length)return K.none;let i=new Ke;for(let{from:s,to:n}of t.visibleRanges)ul(this.tree,e,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=K.mark({class:h})))},s,n);return i.finish()}}const Da=Nr.high(_t.fromClass(Pa,{decorations:r=>r.decorations})),Ba=Ki.define([{tag:x.meta,color:"#404740"},{tag:x.link,textDecoration:"underline"},{tag:x.heading,textDecoration:"underline",fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strong,fontWeight:"bold"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.keyword,color:"#708"},{tag:[x.atom,x.bool,x.url,x.contentSeparator,x.labelName],color:"#219"},{tag:[x.literal,x.inserted],color:"#164"},{tag:[x.string,x.deleted],color:"#a11"},{tag:[x.regexp,x.escape,x.special(x.string)],color:"#e40"},{tag:x.definition(x.variableName),color:"#00f"},{tag:x.local(x.variableName),color:"#30a"},{tag:[x.typeName,x.namespace],color:"#085"},{tag:x.className,color:"#167"},{tag:[x.special(x.variableName),x.macroName],color:"#256"},{tag:x.definition(x.propertyName),color:"#00c"},{tag:x.comment,color:"#940"},{tag:x.invalid,color:"#f00"}]),Ra=Object.create(null),gr=[ht.none],mr=[],br=Object.create(null),Ea=Object.create(null);for(let[r,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Ea[r]=Na(Ra,t);function cs(r,t){mr.indexOf(r)>-1||(mr.push(r),console.warn(t))}function Na(r,t){let e=[];for(let l of t.split(" ")){let h=[];for(let a of l.split(".")){let f=r[a]||x[a];f?typeof f=="function"?h.length?h=h.map(f):cs(a,`Modifier ${a} used at start of tag`):h.length?cs(a,`Tag ${a} used as modifier`):h=Array.isArray(f)?f:[f]:cs(a,`Unknown highlighting tag ${a}`)}for(let a of h)e.push(a)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),s=i+" "+e.map(l=>l.id),n=br[s];if(n)return n.id;let o=br[s]=ht.define({id:gr.length,name:i,props:[vr({[i]:e})]});return gr.push(o),o.id}tt.RTL,tt.LTR;const Ia=Fi.define({name:"json",parser:ml.configure({props:[Aa.add({Object:pr({except:/^\s*\}/}),Array:pr({except:/^\s*\]/})}),Oa.add({"Object Array":Ma})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function La(){return new Ca(Ia)}const Wa={key:0,class:"flex items-center justify-end border-b px-2 py-1 border-pg-border bg-pg-surface-soft"},Fa={key:1,class:"border-t px-2 py-1 text-[0.68rem] border-pg-danger-border bg-pg-danger-bg text-pg-danger-text","aria-live":"polite"},Ha=Fo({__name:"UiCodeEditor",props:{modelValue:{},placeholder:{default:""},rows:{default:4},language:{default:"text"},disabled:{type:Boolean,default:!1},showJsonFormat:{type:Boolean,default:!0}},emits:["update:modelValue"],setup(r,{emit:t}){const e=r,i=t,s=Ho(),n=ii(null),o=ii(null),l=ii(!1),h=ii(null),a=new se,f=new se,c=new se,u=X.define(),d=Gt.define({create(){return K.none},update(y,S){for(const I of S.effects)if(I.is(u)){const H=I.value;if(H===null)return K.none;const Q=Math.min(Math.max(H,0),Math.max(S.state.doc.length-1,0)),G=S.state.doc.lineAt(Q);return K.set([K.line({class:"pg-cm-error-line"}).range(G.from)])}return y.map(S.changes)},provide:y=>B.decorations.from(y)}),p=Jt(()=>e.language==="json"),g=Jt(()=>p.value&&e.showJsonFormat&&!e.disabled),m=Jt(()=>!!h.value&&p.value),b=Jt(()=>{const y=h.value;return y?typeof y.line=="number"&&typeof y.column=="number"?`${y.message} (Ln ${y.line}, Col ${y.column})`:y.message:""}),A=Jt(()=>$o("overflow-hidden rounded-lg border border-pg-border bg-pg-surface-strong text-pg-text transition focus-within:border-pg-accent",m.value?"border-pg-danger-border":"",e.disabled?"cursor-not-allowed opacity-80":"",s.class)),M=Jt(()=>({minHeight:`${(Math.max(2,e.rows)*1.45+1.2).toFixed(2)}rem`,...s.style})),E=Jt(()=>{const{class:y,style:S,...I}=s;return I});function O(y){return y==="json"?La():[]}function P(y,S){if(y<=0)return{from:0,to:0};const I=Math.max(0,Math.min(S,y-1)),H=I,Q=Math.min(I+1,y);return{from:H,to:Q}}function C(y,S){let I=1,H=1;const Q=Math.max(0,Math.min(S,y.length));for(let G=0;G<Q;G+=1)y[G]===`
|
|
11
|
-
`?(I+=1,H=1):H+=1;return{line:I,column:H}}function
|
|
3
|
+
`){[t,e]=be(this,t,e);let s="";for(let n=0,o=0;n<this.children.length&&o<=e;n++){let l=this.children[n],h=o+l.length;o>t&&n&&(s+=i),t<h&&e>o&&(s+=l.sliceString(t-o,e-o,i)),o=h+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Pt))return 0;let i=0,[s,n,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,n+=e){if(s==o||n==l)return i;let h=this.children[s],a=t.children[n];if(h!=a)return i+h.scanIdentical(a,e);i+=h.length+1}}static from(t,e=t.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new J(d,e)}let s=Math.max(32,i>>5),n=s<<1,o=s>>1,l=[],h=0,a=-1,f=[];function c(d){let p;if(d.lines>n&&d instanceof Pt)for(let g of d.children)c(g);else d.lines>o&&(h>o||!h)?(u(),l.push(d)):d instanceof J&&h&&(p=f[f.length-1])instanceof J&&d.lines+p.lines<=32?(h+=d.lines,a+=d.length+1,f[f.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(h+d.lines>s&&u(),h+=d.lines,a+=d.length+1,f.push(d))}function u(){h!=0&&(l.push(f.length==1?f[0]:Pt.from(f,a)),a=-1,h=f.length=0)}for(let d of t)c(d);return u(),l.length==1?l[0]:new Pt(l,e)}}W.empty=new J([""],0);function Sl(r){let t=-1;for(let e of r)t+=e.length+1;return t}function ki(r,t,e=0,i=1e9){for(let s=0,n=0,o=!0;n<r.length&&s<=i;n++){let l=r[n],h=s+l.length;h>=e&&(h>i&&(l=l.slice(0,i-s)),s<e&&(l=l.slice(e-s)),o?(t[t.length-1]+=l,o=!1):t.push(l)),s=h+1}return t}function Tn(r,t,e){return ki(r,[""],t,e)}class Ie{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof J?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],n=this.offsets[i],o=n>>1,l=s instanceof J?s.text.length:s.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((n&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
|
|
4
|
+
`,this;t--}else if(s instanceof J){let h=s.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,h.length>Math.max(0,t))return this.value=t==0?h:e>0?h.slice(t):h.slice(0,h.length-t),this;t-=h.length}else{let h=s.children[o+(e<0?-1:0)];t>h.length?(t-=h.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(e>0?1:(h instanceof J?h.text.length:h.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class Dr{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new Ie(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Br{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(W.prototype[Symbol.iterator]=function(){return this.iter()},Ie.prototype[Symbol.iterator]=Dr.prototype[Symbol.iterator]=Br.prototype[Symbol.iterator]=function(){return this});class vl{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}function be(r,t,e){return t=Math.max(0,Math.min(r.length,t)),[t,Math.max(t,Math.min(r.length,e))]}function wt(r,t,e=!0,i=!0){return wl(r,t,e,i)}const gs=/\r\n?|\n/;var ct=(function(r){return r[r.Simple=0]="Simple",r[r.TrackDel=1]="TrackDel",r[r.TrackBefore=2]="TrackBefore",r[r.TrackAfter=3]="TrackAfter",r})(ct||(ct={}));class Wt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let n=this.sections[e++],o=this.sections[e++];o<0?(t(i,s,n),s+=n):s+=o,i+=n}}iterChangedRanges(t,e=!1){ms(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new Wt(t)}composeDesc(t){return this.empty?t:t.empty?this:Rr(this,t)}mapDesc(t,e=!1){return t.empty?this:bs(this,t,e)}mapPos(t,e=-1,i=ct.Simple){let s=0,n=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],a=s+l;if(h<0){if(a>t)return n+(t-s);n+=l}else{if(i!=ct.Simple&&a>=t&&(i==ct.TrackDel&&s<t&&a>t||i==ct.TrackBefore&&s<t||i==ct.TrackAfter&&a>t))return null;if(a>t||a==t&&e<0&&!l)return t==s||e<0?n:n+h;n+=h}s=a}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return n}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let n=this.sections[i++],o=this.sections[i++],l=s+n;if(o>=0&&s<=e&&l>=t)return s<t&&l>e?"cover":!0;s=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Wt(t)}static create(t){return new Wt(t)}}class et extends Wt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return ms(this,(e,i,s,n,o)=>t=t.replace(s,s+(i-e),o),!1),t}mapDesc(t,e=!1){return bs(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,n=0;s<e.length;s+=2){let o=e[s],l=e[s+1];if(l>=0){e[s]=l,e[s+1]=o;let h=s>>1;for(;i.length<h;)i.push(W.empty);i.push(o?t.slice(n,n+o):W.empty)}n+=o}return new et(e,i)}compose(t){return this.empty?t:t.empty?this:Rr(this,t,!0)}map(t,e=!1){return t.empty?this:bs(this,t,e,!0)}iterChanges(t,e=!1){ms(this,t,e)}get desc(){return Wt.create(this.sections)}filter(t){let e=[],i=[],s=[],n=new je(this);t:for(let o=0,l=0;;){let h=o==t.length?1e9:t[o++];for(;l<h||l==h&&n.len==0;){if(n.done)break t;let f=Math.min(n.len,h-l);nt(s,f,-1);let c=n.ins==-1?-1:n.off==0?n.ins:0;nt(e,f,c),c>0&&qt(i,e,n.text),n.forward(f),l+=f}let a=t[o++];for(;l<a;){if(n.done)break t;let f=Math.min(n.len,a-l);nt(e,f,-1),nt(s,f,n.ins==-1?-1:n.off==0?n.ins:0),n.forward(f),l+=f}}return{changes:new et(e,i),filtered:Wt.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):s==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let s=[],n=[],o=0,l=null;function h(f=!1){if(!f&&!s.length)return;o<e&&nt(s,e-o,-1);let c=new et(s,n);l=l?l.compose(c.map(l)):c,s=[],n=[],o=0}function a(f){if(Array.isArray(f))for(let c of f)a(c);else if(f instanceof et){if(f.length!=e)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${e})`);h(),l=l?l.compose(f.map(l)):f}else{let{from:c,to:u=c,insert:d}=f;if(c>u||c<0||u>e)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?W.of(d.split(i||gs)):d:W.empty,g=p.length;if(c==u&&g==0)return;c<o&&h(),c>o&&nt(s,c-o,-1),nt(s,u-c,g),qt(n,s,p),o=u}}return a(t),h(!l),l}static empty(t){return new et(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;s<t.length;s++){let n=t[s];if(typeof n=="number")e.push(n,-1);else{if(!Array.isArray(n)||typeof n[0]!="number"||n.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(n.length==1)e.push(n[0],0);else{for(;i.length<s;)i.push(W.empty);i[s]=W.of(n.slice(1)),e.push(n[0],i[s].length)}}}return new et(e,i)}static createSet(t,e){return new et(t,e)}}function nt(r,t,e,i=!1){if(t==0&&e<=0)return;let s=r.length-2;s>=0&&e<=0&&e==r[s+1]?r[s]+=t:s>=0&&t==0&&r[s]==0?r[s+1]+=e:i?(r[s]+=t,r[s+1]+=e):r.push(t,e)}function qt(r,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<r.length)r[r.length-1]=r[r.length-1].append(e);else{for(;r.length<i;)r.push(W.empty);r.push(e)}}function ms(r,t,e){let i=r.inserted;for(let s=0,n=0,o=0;o<r.sections.length;){let l=r.sections[o++],h=r.sections[o++];if(h<0)s+=l,n+=l;else{let a=s,f=n,c=W.empty;for(;a+=l,f+=h,h&&i&&(c=c.append(i[o-2>>1])),!(e||o==r.sections.length||r.sections[o+1]<0);)l=r.sections[o++],h=r.sections[o++];t(s,a,n,f,c),s=a,n=f}}}function bs(r,t,e,i=!1){let s=[],n=i?[]:null,o=new je(r),l=new je(t);for(let h=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let a=Math.min(o.len,l.len);nt(s,a,-1),o.forward(a),l.forward(a)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let a=l.len;for(nt(s,l.ins,-1);a;){let f=Math.min(o.len,a);o.ins>=0&&h<o.i&&o.len<=f&&(nt(s,0,o.ins),n&&qt(n,s,o.text),h=o.i),o.forward(f),a-=f}l.next()}else if(o.ins>=0){let a=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);a+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.len<f)f-=l.len,l.next();else break;nt(s,a,h<o.i?o.ins:0),n&&h<o.i&&qt(n,s,o.text),h=o.i,o.forward(o.len-f)}else{if(o.done&&l.done)return n?et.createSet(s,n):Wt.create(s);throw new Error("Mismatched change set lengths")}}}function Rr(r,t,e=!1){let i=[],s=e?[]:null,n=new je(r),o=new je(t);for(let l=!1;;){if(n.done&&o.done)return s?et.createSet(i,s):Wt.create(i);if(n.ins==0)nt(i,n.len,0,l),n.next();else if(o.len==0&&!o.done)nt(i,0,o.ins,l),s&&qt(s,i,o.text),o.next();else{if(n.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(n.len2,o.len),a=i.length;if(n.ins==-1){let f=o.ins==-1?-1:o.off?0:o.ins;nt(i,h,f,l),s&&f&&qt(s,i,o.text)}else o.ins==-1?(nt(i,n.off?0:n.len,h,l),s&&qt(s,i,n.textBit(h))):(nt(i,n.off?0:n.len,o.off?0:o.ins,l),s&&!o.off&&qt(s,i,o.text));l=(n.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>a),n.forward2(h),o.forward(h)}}}}class je{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?W.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?W.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class te{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}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 t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new te(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return k.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return k.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&this.goalColumn==t.goalColumn&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return k.range(t.anchor,t.head)}static create(t,e,i){return new te(t,e,i)}}class k{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:k.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new k([this.main],0)}addRange(t,e=!0){return k.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,k.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new k(t.ranges.map(e=>te.fromJSON(e)),t.main)}static single(t,e=t){return new k([k.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let n=t[s];if(n.empty?n.from<=i:n.from<i)return k.normalized(t.slice(),e);i=n.to}return new k(t,e)}static cursor(t,e=0,i,s){return te.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(t,e,i,s){let n=(i??16777215)<<6|(s==null?7:Math.min(6,s));return e<t?te.create(e,t,48|n):te.create(t,e,(e>t?8:0)|n)}static normalized(t,e=0){let i=t[e];t.sort((s,n)=>s.from-n.from),e=t.indexOf(i);for(let s=1;s<t.length;s++){let n=t[s],o=t[s-1];if(n.empty?n.from<=o.to:n.from<o.to){let l=o.from,h=Math.max(n.to,o.to);s<=e&&e--,t.splice(--s,2,n.anchor>n.head?k.range(h,l):k.range(l,h))}}return new k(t,e)}}function Er(r,t){for(let e of r.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let Us=0;class D{constructor(t,e,i,s,n){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=Us++,this.default=t([]),this.extensions=typeof n=="function"?n(this):n}get reader(){return this}static define(t={}){return new D(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:_s),!!t.static,t.enables)}of(t){return new Si([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Si(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Si(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function _s(r,t){return r==t||r.length==t.length&&r.every((e,i)=>e===t[i])}class Si{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=Us++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,n=this.id,o=t[n]>>1,l=this.type==2,h=!1,a=!1,f=[];for(let c of this.dependencies)c=="doc"?h=!0:c=="selection"?a=!0:(((e=t[c.id])!==null&&e!==void 0?e:1)&1)==0&&f.push(t[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(h&&u.docChanged||a&&(u.docChanged||u.selection)||xs(c,f)){let d=i(c);if(l?!Pn(d,c.values[o],s):!s(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[n];if(p!=null){let g=Pi(u,p);if(this.dependencies.every(m=>m instanceof D?u.facet(m)===c.facet(m):m instanceof Ut?u.field(m,!1)==c.field(m,!1):!0)||(l?Pn(d=i(c),g,s):s(d=i(c),g)))return c.values[o]=g,0}else d=i(c);return c.values[o]=d,1}}}}function Pn(r,t,e){if(r.length!=t.length)return!1;for(let i=0;i<r.length;i++)if(!e(r[i],t[i]))return!1;return!0}function xs(r,t){let e=!1;for(let i of t)Le(r,i)&1&&(e=!0);return e}function Cl(r,t,e){let i=e.map(h=>r[h.id]),s=e.map(h=>h.type),n=i.filter(h=>!(h&1)),o=r[t.id]>>1;function l(h){let a=[];for(let f=0;f<i.length;f++){let c=Pi(h,i[f]);if(s[f]==2)for(let u of c)a.push(u);else a.push(c)}return t.combine(a)}return{create(h){for(let a of i)Le(h,a);return h.values[o]=l(h),1},update(h,a){if(!xs(h,n))return 0;let f=l(h);return t.compare(f,h.values[o])?0:(h.values[o]=f,1)},reconfigure(h,a){let f=xs(h,i),c=a.config.facets[t.id],u=a.facet(t);if(c&&!f&&_s(e,c))return h.values[o]=u,0;let d=l(h);return t.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const ai=D.define({static:!0});class Ut{constructor(t,e,i,s,n){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=n,this.provides=void 0}static define(t){let e=new Ut(Us++,t.create,t.update,t.compare||((i,s)=>i===s),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(ai).find(i=>i.field==this);return(e?.create||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,s)=>{let n=i.values[e],o=this.updateF(n,s);return this.compareF(n,o)?0:(i.values[e]=o,1)},reconfigure:(i,s)=>{let n=i.facet(ai),o=s.facet(ai),l;return(l=n.find(h=>h.field==this))&&l!=o.find(h=>h.field==this)?(i.values[e]=l.create(i),1):s.config.address[this.id]!=null?(i.values[e]=s.field(this),0):(i.values[e]=this.create(i),1)}}}init(t){return[this,ai.of({field:this,create:t})]}get extension(){return this}}const Zt={lowest:4,low:3,default:2,high:1,highest:0};function Te(r){return t=>new Ir(t,r)}const Nr={highest:Te(Zt.highest),high:Te(Zt.high),default:Te(Zt.default),low:Te(Zt.low),lowest:Te(Zt.lowest)};class Ir{constructor(t,e){this.inner=t,this.prec=e}}class se{of(t){return new ys(this,t)}reconfigure(t){return se.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class ys{constructor(t,e){this.compartment=t,this.inner=e}}class Ti{constructor(t,e,i,s,n,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=n,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],n=Object.create(null),o=new Map;for(let u of Al(t,e,o))u instanceof Ut?s.push(u):(n[u.facet.id]||(n[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],a=[];for(let u of s)l[u.id]=a.length<<1,a.push(d=>u.slot(d));let f=i?.config.facets;for(let u in n){let d=n[u],p=d[0].facet,g=f&&f[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,_s(g,d))h.push(i.facet(p));else{let m=p.combine(d.map(b=>b.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=a.length<<1,a.push(b=>m.dynamicSlot(b)));l[p.id]=a.length<<1,a.push(m=>Cl(m,p,d))}}let c=a.map(u=>u(l));return new Ti(t,o,c,l,h,n)}}function Al(r,t,e){let i=[[],[],[],[],[]],s=new Map;function n(o,l){let h=s.get(o);if(h!=null){if(h<=l)return;let a=i[h].indexOf(o);a>-1&&i[h].splice(a,1),o instanceof ys&&e.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let a of o)n(a,l);else if(o instanceof ys){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let a=t.get(o.compartment)||o.inner;e.set(o.compartment,a),n(a,l)}else if(o instanceof Ir)n(o.inner,o.prec);else if(o instanceof Ut)i[l].push(o),o.provides&&n(o.provides,l);else if(o instanceof Si)i[l].push(o),o.facet.extensions&&n(o.facet.extensions,Zt.default);else{let a=o.extension;if(!a)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(a,l)}}return n(r,Zt.default),i.reduce((o,l)=>o.concat(l))}function Le(r,t){if(t&1)return 2;let e=t>>1,i=r.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;r.status[e]=4;let s=r.computeSlot(r,r.config.dynamicSlots[e]);return r.status[e]=2|s}function Pi(r,t){return t&1?r.config.staticValues[t>>1]:r.values[t>>1]}const Lr=D.define(),ws=D.define({combine:r=>r.some(t=>t),static:!0}),Wr=D.define({combine:r=>r.length?r[0]:void 0,static:!0}),Fr=D.define(),Hr=D.define(),Vr=D.define(),zr=D.define({combine:r=>r.length?r[0]:!1});class Oe{constructor(t,e){this.type=t,this.value=e}static define(){return new Ol}}class Ol{of(t){return new Oe(this,t)}}class Ml{constructor(t){this.map=t}of(t){return new X(this,t)}}class X{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new X(this.type,e)}is(t){return this.type==t}static define(t={}){return new Ml(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let n=s.map(e);n&&i.push(n)}return i}}X.reconfigure=X.define();X.appendConfig=X.define();class rt{constructor(t,e,i,s,n,o){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=n,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Er(i,e.newLength),n.some(l=>l.type==rt.time)||(this.annotations=n.concat(rt.time.of(Date.now())))}static create(t,e,i,s,n,o){return new rt(t,e,i,s,n,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(rt.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}rt.time=Oe.define();rt.userEvent=Oe.define();rt.addToHistory=Oe.define();rt.remote=Oe.define();function Tl(r,t){let e=[];for(let i=0,s=0;;){let n,o;if(i<r.length&&(s==t.length||t[s]>=r[i]))n=r[i++],o=r[i++];else if(s<t.length)n=t[s++],o=t[s++];else return e;!e.length||e[e.length-1]<n?e.push(n,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function qr(r,t,e){var i;let s,n,o;return e?(s=t.changes,n=et.empty(t.changes.length),o=r.changes.compose(t.changes)):(s=t.changes.map(r.changes),n=r.changes.mapDesc(t.changes,!0),o=r.changes.compose(s)),{changes:o,selection:t.selection?t.selection.map(n):(i=r.selection)===null||i===void 0?void 0:i.map(s),effects:X.mapEffects(r.effects,s).concat(X.mapEffects(t.effects,n)),annotations:r.annotations.length?r.annotations.concat(t.annotations):t.annotations,scrollIntoView:r.scrollIntoView||t.scrollIntoView}}function ks(r,t,e){let i=t.selection,s=de(t.annotations);return t.userEvent&&(s=s.concat(rt.userEvent.of(t.userEvent))),{changes:t.changes instanceof et?t.changes:et.of(t.changes||[],e,r.facet(Wr)),selection:i&&(i instanceof k?i:k.single(i.anchor,i.head)),effects:de(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function jr(r,t,e){let i=ks(r,t.length?t[0]:{},r.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let n=1;n<t.length;n++){t[n].filter===!1&&(e=!1);let o=!!t[n].sequential;i=qr(i,ks(r,t[n],o?i.changes.newLength:r.doc.length),o)}let s=rt.create(r,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Dl(e?Pl(s):s)}function Pl(r){let t=r.startState,e=!0;for(let s of t.facet(Fr)){let n=s(r);if(n===!1){e=!1;break}Array.isArray(n)&&(e=e===!0?n:Tl(e,n))}if(e!==!0){let s,n;if(e===!1)n=r.changes.invertedDesc,s=et.empty(t.doc.length);else{let o=r.changes.filter(e);s=o.changes,n=o.filtered.mapDesc(o.changes).invertedDesc}r=rt.create(t,s,r.selection&&r.selection.map(n),X.mapEffects(r.effects,n),r.annotations,r.scrollIntoView)}let i=t.facet(Hr);for(let s=i.length-1;s>=0;s--){let n=i[s](r);n instanceof rt?r=n:Array.isArray(n)&&n.length==1&&n[0]instanceof rt?r=n[0]:r=jr(t,de(n),!1)}return r}function Dl(r){let t=r.startState,e=t.facet(Vr),i=r;for(let s=e.length-1;s>=0;s--){let n=e[s](r);n&&Object.keys(n).length&&(i=qr(i,ks(t,n,r.changes.newLength),!0))}return i==r?r:rt.create(t,r.changes,r.selection,i.effects,i.annotations,i.scrollIntoView)}const Bl=[];function de(r){return r==null?Bl:Array.isArray(r)?r:[r]}var It=(function(r){return r[r.Word=0]="Word",r[r.Space=1]="Space",r[r.Other=2]="Other",r})(It||(It={}));const Rl=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Ss;try{Ss=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function El(r){if(Ss)return Ss.test(r);for(let t=0;t<r.length;t++){let e=r[t];if(/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||Rl.test(e)))return!0}return!1}function Nl(r){return t=>{if(!/\S/.test(t))return It.Space;if(El(t))return It.Word;for(let e=0;e<r.length;e++)if(t.indexOf(r[e])>-1)return It.Word;return It.Other}}class V{constructor(t,e,i,s,n,o){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=n,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Le(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return Le(this,i),Pi(this,i)}update(...t){return jr(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:s}=e;for(let l of t.effects)l.is(se.reconfigure)?(e&&(s=new Map,e.compartments.forEach((h,a)=>s.set(a,h)),e=null),s.set(l.value.compartment,l.value.extension)):l.is(X.reconfigure)?(e=null,i=l.value):l.is(X.appendConfig)&&(e=null,i=de(i).concat(l.value));let n;e?n=t.startState.values.slice():(e=Ti.resolve(i,s,this),n=new V(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(h,a)=>a.reconfigure(h,this),null).values);let o=t.startState.facet(ws)?t.newSelection:t.newSelection.asSingle();new V(e,t.newDoc,o,n,(l,h)=>h.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:k.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),n=[i.range],o=de(i.effects);for(let l=1;l<e.ranges.length;l++){let h=t(e.ranges[l]),a=this.changes(h.changes),f=a.map(s);for(let u=0;u<l;u++)n[u]=n[u].map(f);let c=s.mapDesc(a,!0);n.push(h.range.map(c)),s=s.compose(f),o=X.mapEffects(o,f).concat(X.mapEffects(de(h.effects),c))}return{changes:s,selection:k.create(n,e.mainIndex),effects:o}}changes(t=[]){return t instanceof et?t:et.of(t,this.doc.length,this.facet(V.lineSeparator))}toText(t){return W.of(t.split(this.facet(V.lineSeparator)||gs))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(Le(this,e),Pi(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof Ut&&this.config.address[s.id]!=null&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let n in i)if(Object.prototype.hasOwnProperty.call(t,n)){let o=i[n],l=t[n];s.push(o.init(h=>o.spec.fromJSON(l,h)))}}return V.create({doc:t.doc,selection:k.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=Ti.resolve(t.extensions||[],new Map),i=t.doc instanceof W?t.doc:W.of((t.doc||"").split(e.staticFacet(V.lineSeparator)||gs)),s=t.selection?t.selection instanceof k?t.selection:k.single(t.selection.anchor,t.selection.head):k.single(0);return Er(s,i.length),e.staticFacet(ws)||(s=s.asSingle()),new V(e,i,s,e.dynamicSlots.map(()=>null),(n,o)=>o.create(n),null)}get tabSize(){return this.facet(V.tabSize)}get lineBreak(){return this.facet(V.lineSeparator)||`
|
|
5
|
+
`}get readOnly(){return this.facet(zr)}phrase(t,...e){for(let i of this.facet(V.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let n=+(s||1);return!n||n>e.length?i:e[n-1]})),t}languageDataAt(t,e,i=-1){let s=[];for(let n of this.facet(Lr))for(let o of n(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&s.push(o[t]);return s}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return Nl(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),n=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let h=wt(e,o,!1);if(n(e.slice(h,o))!=It.Word)break;o=h}for(;l<s;){let h=wt(e,l);if(n(e.slice(l,h))!=It.Word)break;l=h}return o==l?null:k.range(o+i,l+i)}}V.allowMultipleSelections=ws;V.tabSize=D.define({combine:r=>r.length?r[0]:4});V.lineSeparator=Wr;V.readOnly=zr;V.phrases=D.define({compare(r,t){let e=Object.keys(r),i=Object.keys(t);return e.length==i.length&&e.every(s=>r[s]==t[s])}});V.languageData=Lr;V.changeFilter=Fr;V.transactionFilter=Hr;V.transactionExtender=Vr;se.reconfigure=X.define();class ne{eq(t){return this==t}range(t,e=t){return $e.create(t,e,this)}}ne.prototype.startSide=ne.prototype.endSide=0;ne.prototype.point=!1;ne.prototype.mapMode=ct.TrackDel;function Js(r,t){return r==t||r.constructor==t.constructor&&r.eq(t)}class $e{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new $e(t,e,i)}}function vs(r,t){return r.from-t.from||r.value.startSide-t.value.startSide}class Ys{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let n=i?this.to:this.from;for(let o=s,l=n.length;;){if(o==l)return o;let h=o+l>>1,a=n[h]-t||(i?this.value[h].endSide:this.value[h].startSide)-e;if(h==o)return a>=0?o:l;a>=0?l=h:o=h+1}}between(t,e,i,s){for(let n=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,n);n<o;n++)if(s(this.from[n]+t,this.to[n]+t,this.value[n])===!1)return!1}map(t,e){let i=[],s=[],n=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let a=this.value[h],f=this.from[h]+t,c=this.to[h]+t,u,d;if(f==c){let p=e.mapPos(f,a.startSide,a.mapMode);if(p==null||(u=d=p,a.startSide!=a.endSide&&(d=e.mapPos(f,a.endSide),d<u)))continue}else if(u=e.mapPos(f,a.startSide),d=e.mapPos(c,a.endSide),u>d||u==d&&a.startSide>0&&a.endSide<=0)continue;(d-u||a.endSide-a.startSide)<0||(o<0&&(o=u),a.point&&(l=Math.max(l,d-u)),i.push(a),s.push(u-o),n.push(d-o))}return{mapped:i.length?new Ys(s,n,i,l):null,pos:o}}}class z{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new z(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:n=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(vs)),this.isEmpty)return e.length?z.of(e):this;let l=new $r(this,null,-1).goto(0),h=0,a=[],f=new Ke;for(;l.value||h<e.length;)if(h<e.length&&(l.from-e[h].from||l.startSide-e[h].value.startSide)>=0){let c=e[h++];f.addInner(c.from,c.to,c.value)||a.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==e.length||this.chunkEnd(l.chunkIndex)<e[h].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||n<this.chunkPos[l.chunkIndex])&&f.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||n<l.from||o(l.from,l.to,l.value))&&(f.addInner(l.from,l.to,l.value)||a.push($e.create(l.from,l.to,l.value))),l.next());return f.finishInner(this.nextLayer.isEmpty&&!a.length?z.empty:this.nextLayer.update({add:a,filter:o,filterFrom:s,filterTo:n}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],a=t.touchesRange(l,l+h.length);if(a===!1)s=Math.max(s,h.maxPoint),e.push(h),i.push(t.mapPos(l));else if(a===!0){let{mapped:f,pos:c}=h.map(l,t);f&&(s=Math.max(s,f.maxPoint),e.push(f),i.push(c))}}let n=this.nextLayer.map(t);return e.length==0?n:new z(i,e,n||z.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let n=this.chunkPos[s],o=this.chunk[s];if(e>=n&&t<=n+o.length&&o.between(n,t-n,e-n,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return Qe.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Qe.from(t).goto(e)}static compare(t,e,i,s,n=-1){let o=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=n),l=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=n),h=Dn(o,l,i),a=new Pe(o,h,n),f=new Pe(l,h,n);i.iterGaps((c,u,d)=>Bn(a,c,f,u,d,s)),i.empty&&i.length==0&&Bn(a,0,f,0,0,s)}static eq(t,e,i=0,s){s==null&&(s=999999999);let n=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0),o=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0);if(n.length!=o.length)return!1;if(!n.length)return!0;let l=Dn(n,o),h=new Pe(n,l,0).goto(i),a=new Pe(o,l,0).goto(i);for(;;){if(h.to!=a.to||!Cs(h.active,a.active)||h.point&&(!a.point||!Js(h.point,a.point)))return!1;if(h.to>s)return!0;h.next(),a.next()}}static spans(t,e,i,s,n=-1){let o=new Pe(t,null,n).goto(e),l=e,h=o.openStart;for(;;){let a=Math.min(o.to,i);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFrom<e?f.length+1:o.point.startSide<0?f.length:Math.min(f.length,h);s.point(l,a,o.point,f,c,o.pointRank),h=Math.min(o.openEnd(a),f.length)}else a>l&&(s.span(l,a,o.active,h),h=o.openEnd(a));if(o.to>i)return h+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(t,e=!1){let i=new Ke;for(let s of t instanceof $e?[t]:e?Il(t):t)i.add(s.from,s.to,s.value);return i.finish()}static join(t){if(!t.length)return z.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let s=t[i];s!=z.empty;s=s.nextLayer)e=new z(s.chunkPos,s.chunk,e,Math.max(s.maxPoint,e.maxPoint));return e}}z.empty=new z([],[],null,-1);function Il(r){if(r.length>1)for(let t=r[0],e=1;e<r.length;e++){let i=r[e];if(vs(t,i)>0)return r.slice().sort(vs);t=i}return r}z.empty.nextLayer=z.empty;class Ke{finishChunk(t){this.chunks.push(new Ys(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Ke)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(z.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=z.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Dn(r,t,e){let i=new Map;for(let n of r)for(let o=0;o<n.chunk.length;o++)n.chunk[o].maxPoint<=0&&i.set(n.chunk[o],n.chunkPos[o]);let s=new Set;for(let n of t)for(let o=0;o<n.chunk.length;o++){let l=i.get(n.chunk[o]);l!=null&&(e?e.mapPos(l):l)==n.chunkPos[o]&&!e?.touchesRange(l,l+n.chunk[o].length)&&s.add(n.chunk[o])}return s}class $r{constructor(t,e,i,s=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<t||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class Qe{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let n=0;n<t.length;n++)for(let o=t[n];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new $r(o,e,i,n));return s.length==1?s[0]:new Qe(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)Yi(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)Yi(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Yi(this.heap,0)}}}function Yi(r,t){for(let e=r[t];;){let i=(t<<1)+1;if(i>=r.length)break;let s=r[i];if(i+1<r.length&&s.compare(r[i+1])>=0&&(s=r[i+1],i++),e.compare(s)<0)break;r[i]=e,r[t]=s,t=i}}class Pe{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Qe.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){fi(this.active,t),fi(this.activeTo,t),fi(this.activeRank,t),this.minActive=Rn(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:n}=this.cursor;for(;e<this.activeRank.length&&(n-this.activeRank[e]||s-this.activeTo[e])>0;)e++;ci(this.active,e,i),ci(this.activeTo,e,s),ci(this.activeRank,e,n),t&&ci(t,e,this.cursor.from),this.minActive=Rn(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>t){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&fi(i,s)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let n=this.cursor.value;if(!n.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=n,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=n.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<t;s--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function Bn(r,t,e,i,s,n){r.goto(t),e.goto(i);let o=i+s,l=i,h=i-t,a=!!n.boundChange;for(let f=!1;;){let c=r.to+h-e.to,u=c||r.endSide-e.endSide,d=u<0?r.to+h:e.to,p=Math.min(d,o);if(r.point||e.point?(r.point&&e.point&&Js(r.point,e.point)&&Cs(r.activeForPoint(r.to),e.activeForPoint(e.to))||n.comparePoint(l,p,r.point,e.point),f=!1):(f&&n.boundChange(l),p>l&&!Cs(r.active,e.active)&&n.compareRange(l,p,r.active,e.active),a&&p<o&&(c||r.openEnd(d)!=e.openEnd(d))&&(f=!0)),d>o)break;l=d,u<=0&&r.next(),u>=0&&e.next()}}function Cs(r,t){if(r.length!=t.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!=t[e]&&!Js(r[e],t[e]))return!1;return!0}function fi(r,t){for(let e=t,i=r.length-1;e<i;e++)r[e]=r[e+1];r.pop()}function ci(r,t,e){for(let i=r.length-1;i>=t;i--)r[i+1]=r[i];r[t]=e}function Rn(r,t){let e=-1,i=1e9;for(let s=0;s<t.length;s++)(t[s]-i||r[s].endSide-r[e].endSide)<0&&(e=s,i=t[s]);return e}function Ll(r,t,e,i){for(let s=0,n=0;;){if(n>=t)return s;if(s==r.length)break;n+=r.charCodeAt(s)==9?e-n%e:1,s=wt(r,s)}return r.length}const As="ͼ",En=typeof Symbol>"u"?"__"+As:Symbol.for(As),Os=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Nn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Kt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function n(o,l,h,a){let f=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))n(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");n(s(d),p,f,u)}else p!=null&&f.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(f.length||u)&&h.push((i&&!c&&!a?o.map(i):o).join(", ")+" {"+f.join(" ")+"}")}for(let o in t)n(s(o),t[o],this.rules)}getRules(){return this.rules.join(`
|
|
6
|
+
`)}static newName(){let t=Nn[En]||1;return Nn[En]=t+1,As+t.toString(36)}static mount(t,e,i){let s=t[Os],n=i&&i.nonce;s?n&&s.setNonce(n):s=new Wl(t,n),s.mount(Array.isArray(e)?e:[e],t)}}let In=new Map;class Wl{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let n=In.get(i);if(n)return t[Os]=n;this.sheet=new s.CSSStyleSheet,In.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Os]=this}mount(t,e){let i=this.sheet,s=0,n=0;for(let o=0;o<t.length;o++){let l=t[o],h=this.modules.indexOf(l);if(h<n&&h>-1&&(this.modules.splice(h,1),n--,h=-1),h==-1){if(this.modules.splice(n++,0,l),i)for(let a=0;a<l.rules.length;a++)i.insertRule(l.rules[a],s++)}else{for(;n<h;)s+=this.modules[n++].rules.length;s+=l.rules.length,n++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let o="";for(let h=0;h<this.modules.length;h++)o+=this.modules[h].getRules()+`
|
|
7
|
+
`;this.styleTag.textContent=o;let l=e.head||e;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var xe={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ms={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'};for(var st=0;st<10;st++)xe[48+st]=xe[96+st]=String(st);for(var st=1;st<=24;st++)xe[st+111]="F"+st;for(var st=65;st<=90;st++)xe[st]=String.fromCharCode(st+32),Ms[st]=String.fromCharCode(st);for(var Xi in xe)Ms.hasOwnProperty(Xi)||(Ms[Xi]=xe[Xi]);let ut=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ts=typeof document<"u"?document:{documentElement:{style:{}}};const Ps=/Edge\/(\d+)/.exec(ut.userAgent),Kr=/MSIE \d/.test(ut.userAgent),Ds=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ut.userAgent),Vi=!!(Kr||Ds||Ps),Ln=!Vi&&/gecko\/(\d+)/i.test(ut.userAgent),Zi=!Vi&&/Chrome\/(\d+)/.exec(ut.userAgent),Fl="webkitFontSmoothing"in Ts.documentElement.style,Bs=!Vi&&/Apple Computer/.test(ut.vendor),Wn=Bs&&(/Mobile\/\w+/.test(ut.userAgent)||ut.maxTouchPoints>2);var v={mac:Wn||/Mac/.test(ut.platform),ie:Vi,ie_version:Kr?Ts.documentMode||6:Ds?+Ds[1]:Ps?+Ps[1]:0,gecko:Ln,gecko_version:Ln?+(/Firefox\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,chrome:!!Zi,chrome_version:Zi?+Zi[1]:0,ios:Wn,android:/Android\b/.test(ut.userAgent),webkit_version:Fl?+(/\bAppleWebKit\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,safari:Bs,safari_version:Bs?+(/\bVersion\/(\d+(\.\d+)?)/.exec(ut.userAgent)||[0,0])[1]:0,tabSize:Ts.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Xs(r,t){for(let e in r)e=="class"&&t.class?t.class+=" "+r.class:e=="style"&&t.style?t.style+=";"+r.style:t[e]=r[e];return t}const Di=Object.create(null);function Zs(r,t,e){if(r==t)return!0;r||(r=Di),t||(t=Di);let i=Object.keys(r),s=Object.keys(t);if(i.length-0!=s.length-0)return!1;for(let n of i)if(n!=e&&(s.indexOf(n)==-1||r[n]!==t[n]))return!1;return!0}function Hl(r,t){for(let e=r.attributes.length-1;e>=0;e--){let i=r.attributes[e].name;t[i]==null&&r.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?r.style.cssText=i:r.getAttribute(e)!=i&&r.setAttribute(e,i)}}function Fn(r,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?r.style.cssText="":r.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?r.style.cssText=e[s]:r.setAttribute(s,e[s]));return i}function Vl(r){let t=Object.create(null);for(let e=0;e<r.attributes.length;e++){let i=r.attributes[e];t[i.name]=i.value}return t}class Ye{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var bt=(function(r){return r[r.Text=0]="Text",r[r.WidgetBefore=1]="WidgetBefore",r[r.WidgetAfter=2]="WidgetAfter",r[r.WidgetRange=3]="WidgetRange",r})(bt||(bt={}));class K extends ne{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Xe(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new re(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:n,end:o}=Qr(t,e);i=(n?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new re(t,i,s,e,t.widget||null,!0)}static line(t){return new Ze(t)}static set(t,e=!1){return z.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}K.none=z.empty;class Xe extends K{constructor(t){let{start:e,end:i}=Qr(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?Xs(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||Di}eq(t){return this==t||t instanceof Xe&&this.tagName==t.tagName&&Zs(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Xe.prototype.point=!1;class Ze extends K{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Ze&&this.spec.class==t.spec.class&&Zs(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Ze.prototype.mapMode=ct.TrackBefore;Ze.prototype.point=!0;class re extends K{constructor(t,e,i,s,n,o){super(e,i,n,t),this.block=s,this.isReplace=o,this.mapMode=s?e<=0?ct.TrackBefore:ct.TrackAfter:ct.TrackDel}get type(){return this.startSide!=this.endSide?bt.WidgetRange:this.startSide<=0?bt.WidgetBefore:bt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof re&&zl(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}re.prototype.point=!0;function Qr(r,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=r;return e==null&&(e=r.inclusive),i==null&&(i=r.inclusive),{start:e??t,end:i??t}}function zl(r,t){return r==t||!!(r&&t&&r.compare(t))}function pe(r,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=r?e[s]=Math.max(e[s],t):e.push(r,t)}class Ge extends ne{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof Ge&&this.tagName==t.tagName&&Zs(this.attributes,t.attributes)}static create(t){return new Ge(t.tagName,t.attributes||Di)}static set(t,e=!1){return z.of(t,e)}}Ge.prototype.startSide=Ge.prototype.endSide=-1;function ye(r){let t;return r.nodeType==11?t=r.getSelection?r:r.ownerDocument:t=r,t.getSelection()}function Rs(r,t){return t?r==t||r.contains(t.nodeType!=1?t.parentNode:t):!1}function We(r,t){if(!t.anchorNode)return!1;try{return Rs(r,t.anchorNode)}catch{return!1}}function Fe(r){return r.nodeType==3?_e(r,0,r.nodeValue.length).getClientRects():r.nodeType==1?r.getClientRects():[]}function He(r,t,e,i){return e?Hn(r,t,e,i,-1)||Hn(r,t,e,i,1):!1}function Qt(r){for(var t=0;;t++)if(r=r.previousSibling,!r)return t}function Bi(r){return r.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(r.nodeName)}function Hn(r,t,e,i,s){for(;;){if(r==e&&t==i)return!0;if(t==(s<0?0:Ft(r))){if(r.nodeName=="DIV")return!1;let n=r.parentNode;if(!n||n.nodeType!=1)return!1;t=Qt(r)+(s<0?0:1),r=n}else if(r.nodeType==1){if(r=r.childNodes[t+(s<0?-1:0)],r.nodeType==1&&r.contentEditable=="false")return!1;t=s<0?Ft(r):0}else return!1}}function Ft(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Ue(r,t){let e=t?r.left:r.right;return{left:e,right:e,top:r.top,bottom:r.bottom}}function ql(r){let t=r.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:r.innerWidth,top:0,bottom:r.innerHeight}}function Gr(r,t){let e=t.width/r.offsetWidth,i=t.height/r.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-r.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-r.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function jl(r,t,e,i,s,n,o,l){let h=r.ownerDocument,a=h.defaultView||window;for(let f=r,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==h.body,p=1,g=1;if(d)u=ql(a);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let A=f.getBoundingClientRect();({scaleX:p,scaleY:g}=Gr(f,A)),u={left:A.left,right:A.left+f.clientWidth*p,top:A.top,bottom:A.top+f.clientHeight*g}}let m=0,b=0;if(s=="nearest")t.top<u.top?(b=t.top-(u.top+o),e>0&&t.bottom>u.bottom+b&&(b=t.bottom-u.bottom+o)):t.bottom>u.bottom&&(b=t.bottom-u.bottom+o,e<0&&t.top-b<u.top&&(b=t.top-(u.top+o)));else{let A=t.bottom-t.top,M=u.bottom-u.top;b=(s=="center"&&A<=M?t.top+A/2-M/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-M+o)-u.top}if(i=="nearest"?t.left<u.left?(m=t.left-(u.left+n),e>0&&t.right>u.right+m&&(m=t.right-u.right+n)):t.right>u.right&&(m=t.right-u.right+n,e<0&&t.left<u.left+m&&(m=t.left-(u.left+n))):m=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-n:t.right-(u.right-u.left)+n)-u.left,m||b)if(d)a.scrollBy(m,b);else{let A=0,M=0;if(b){let E=f.scrollTop;f.scrollTop+=b/g,M=(f.scrollTop-E)*g}if(m){let E=f.scrollLeft;f.scrollLeft+=m/p,A=(f.scrollLeft-E)*p}t={left:t.left-A,top:t.top-M,right:t.right-A,bottom:t.bottom-M},A&&Math.abs(A-m)<1&&(i="nearest"),M&&Math.abs(M-b)<1&&(s="nearest")}if(d)break;(t.top<u.top||t.bottom>u.bottom||t.left<u.left||t.right>u.right)&&(t={left:Math.max(t.left,u.left),right:Math.min(t.right,u.right),top:Math.max(t.top,u.top),bottom:Math.min(t.bottom,u.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function $l(r){let t=r.ownerDocument,e,i;for(let s=r.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}class Kl{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Ft(e):0),i,Math.min(t.focusOffset,i?Ft(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let Xt=null;v.safari&&v.safari_version>=26&&(Xt=!1);function Ur(r){if(r.setActive)return r.setActive();if(Xt)return r.focus(Xt);let t=[];for(let e=r;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(r.focus(Xt==null?{get preventScroll(){return Xt={preventScroll:!0},!0}}:void 0),!Xt){Xt=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],n=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=n&&(i.scrollLeft=n)}}}let Vn;function _e(r,t,e=t){let i=Vn||(Vn=document.createRange());return i.setEnd(r,e),i.setStart(r,t),i}function ge(r,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let n=new KeyboardEvent("keydown",s);n.synthetic=!0,r.dispatchEvent(n);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,r.dispatchEvent(o),n.defaultPrevented||o.defaultPrevented}function Ql(r){for(;r;){if(r&&(r.nodeType==9||r.nodeType==11&&r.host))return r;r=r.assignedSlot||r.parentNode}return null}function Gl(r,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Ft(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=Ft(e))}else{if(e==r)return!0;i=Qt(e),e=e.parentNode}}function _r(r){return r.scrollTop>Math.max(1,r.scrollHeight-r.clientHeight-4)}function Jr(r,t){for(let e=r,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Ft(e)}else if(e.parentNode&&!Bi(e))i=Qt(e),e=e.parentNode;else return null}}function Yr(r,t){for(let e=r,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Bi(e))i=Qt(e)+1,e=e.parentNode;else return null}}class kt{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new kt(t.parentNode,Qt(t),e)}static after(t,e){return new kt(t.parentNode,Qt(t)+1,e)}}var tt=(function(r){return r[r.LTR=0]="LTR",r[r.RTL=1]="RTL",r})(tt||(tt={}));const oe=tt.LTR,tn=tt.RTL;function Xr(r){let t=[];for(let e=0;e<r.length;e++)t.push(1<<+r[e]);return t}const Ul=Xr("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),_l=Xr("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Es=Object.create(null),Mt=[];for(let r of["()","[]","{}"]){let t=r.charCodeAt(0),e=r.charCodeAt(1);Es[t]=e,Es[e]=-t}function Zr(r){return r<=247?Ul[r]:1424<=r&&r<=1524?2:1536<=r&&r<=1785?_l[r-1536]:1774<=r&&r<=2220?4:8192<=r&&r<=8204?256:64336<=r&&r<=65023?4:1}const Jl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Lt{get dir(){return this.level%2?tn:oe}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let n=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(n<0||(s!=0?s<0?l.from<e:l.to>e:t[n].level>l.level))&&(n=o)}}if(n<0)throw new RangeError("Index out of range");return n}}function to(r,t){if(r.length!=t.length)return!1;for(let e=0;e<r.length;e++){let i=r[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!to(i.inner,s.inner))return!1}return!0}const q=[];function Yl(r,t,e,i,s){for(let n=0;n<=i.length;n++){let o=n?i[n-1].to:t,l=n<i.length?i[n].from:e,h=n?256:s;for(let a=o,f=h,c=h;a<l;a++){let u=Zr(r.charCodeAt(a));u==512?u=f:u==8&&c==4&&(u=16),q[a]=u==4?2:u,u&7&&(c=u),f=u}for(let a=o,f=h,c=h;a<l;a++){let u=q[a];if(u==128)a<l-1&&f==q[a+1]&&f&24?u=q[a]=f:q[a]=256;else if(u==64){let d=a+1;for(;d<l&&q[d]==64;)d++;let p=a&&f==8||d<e&&q[d]==8?c==1?1:8:256;for(let g=a;g<d;g++)q[g]=p;a=d-1}else u==8&&c==1&&(q[a]=1);f=u,u&7&&(c=u)}}}function Xl(r,t,e,i,s){let n=s==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let a=o?i[o-1].to:t,f=o<i.length?i[o].from:e;for(let c=a,u,d,p;c<f;c++)if(d=Es[u=r.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(Mt[g+1]==-d){let m=Mt[g+2],b=m&2?s:m&4?m&1?n:s:0;b&&(q[c]=q[Mt[g]]=b),l=g;break}}else{if(Mt.length==189)break;Mt[l++]=c,Mt[l++]=u,Mt[l++]=h}else if((p=q[c])==2||p==1){let g=p==s;h=g?0:1;for(let m=l-3;m>=0;m-=3){let b=Mt[m+2];if(b&2)break;if(g)Mt[m+2]|=2;else{if(b&4)break;Mt[m+2]|=4}}}}}function Zl(r,t,e,i){for(let s=0,n=i;s<=e.length;s++){let o=s?e[s-1].to:r,l=s<e.length?e[s].from:t;for(let h=o;h<l;){let a=q[h];if(a==256){let f=h+1;for(;;)if(f==l){if(s==e.length)break;f=e[s++].to,l=s<e.length?e[s].from:t}else if(q[f]==256)f++;else break;let c=n==1,u=(f<t?q[f]:i)==1,d=c==u?c?1:2:i;for(let p=f,g=s,m=g?e[g-1].to:r;p>h;)p==m&&(p=e[--g].from,m=g?e[g-1].to:r),q[--p]=d;h=f}else n=a,h++}}}function Ns(r,t,e,i,s,n,o){let l=i%2?2:1;if(i%2==s%2)for(let h=t,a=0;h<e;){let f=!0,c=!1;if(a==n.length||h<n[a].from){let g=q[h];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;t:for(;;)if(a<n.length&&p==n[a].from){if(c)break t;let g=n[a];if(!f)for(let m=g.to,b=a+1;;){if(m==e)break t;if(b<n.length&&n[b].from==m)m=n[b++].to;else{if(q[m]==l)break t;break}}if(a++,u)u.push(g);else{g.from>h&&o.push(new Lt(h,g.from,d));let m=g.direction==oe!=!(d%2);Is(r,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==e||(f?q[p]!=l:q[p]==l))break;p++}u?Ns(r,h,p,i+1,s,u,o):h<p&&o.push(new Lt(h,p,d)),h=p}else for(let h=e,a=n.length;h>t;){let f=!0,c=!1;if(!a||h>n[a-1].to){let g=q[h-1];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=h;t:for(;;)if(a&&p==n[a-1].to){if(c)break t;let g=n[--a];if(!f)for(let m=g.from,b=a;;){if(m==t)break t;if(b&&n[b-1].to==m)m=n[--b].from;else{if(q[m-1]==l)break t;break}}if(u)u.push(g);else{g.to<h&&o.push(new Lt(g.to,h,d));let m=g.direction==oe!=!(d%2);Is(r,m?i+1:i,s,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==t||(f?q[p-1]!=l:q[p-1]==l))break;p--}u?Ns(r,p,h,i+1,s,u,o):p<h&&o.push(new Lt(p,h,d)),h=p}}function Is(r,t,e,i,s,n,o){let l=t%2?2:1;Yl(r,s,n,i,l),Xl(r,s,n,i,l),Zl(s,n,i,l),Ns(r,s,n,t,e,i,o)}function th(r,t,e){if(!r)return[new Lt(0,0,t==tn?1:0)];if(t==oe&&!e.length&&!Jl.test(r))return eo(r.length);if(e.length)for(;r.length>q.length;)q[q.length]=256;let i=[],s=t==oe?0:1;return Is(r,s,s,e,0,r.length,i),i}function eo(r){return[new Lt(0,r,0)]}let io="";function eh(r,t,e,i,s){var n;let o=i.head-r.from,l=Lt.find(t,o,(n=i.bidiLevel)!==null&&n!==void 0?n:-1,i.assoc),h=t[l],a=h.side(s,e);if(o==a){let u=l+=s?1:-1;if(u<0||u>=t.length)return null;h=t[l=u],o=h.side(!s,e),a=h.side(s,e)}let f=wt(r.text,o,h.forward(s,e));(f<h.from||f>h.to)&&(f=a),io=r.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return c&&f==a&&c.level+(s?0:1)<h.level?k.cursor(c.side(!s,e)+r.from,c.forward(s,e)?1:-1,c.level):k.cursor(f+r.from,h.forward(s,e)?-1:1,h.level)}function ih(r,t,e){for(let i=t;i<e;i++){let s=Zr(r.charCodeAt(i));if(s==1)return oe;if(s==2||s==4)return tn}return oe}const so=D.define(),no=D.define(),ro=D.define(),oo=D.define(),Ls=D.define(),lo=D.define(),ho=D.define(),en=D.define(),sn=D.define(),ao=D.define({combine:r=>r.some(t=>t)}),sh=D.define({combine:r=>r.some(t=>t)}),fo=D.define();class me{constructor(t,e="nearest",i="nearest",s=5,n=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=n,this.isSnapshot=o}map(t){return t.empty?this:new me(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 me(k.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const ui=X.define({map:(r,t)=>r.map(t)}),co=X.define();function Bt(r,t,e){let i=r.facet(oo);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}const Nt=D.define({combine:r=>r.length?r[0]:!0});let nh=0;const fe=D.define({combine(r){return r.filter((t,e)=>{for(let i=0;i<e;i++)if(r[i].plugin==t.plugin)return!1;return!0})}});class Gt{constructor(t,e,i,s,n){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=n(this),this.extension=this.baseExtensions.concat(fe.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(fe.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:n,decorations:o}=e||{};return new Gt(nh++,t,i,s,l=>{let h=[];return o&&h.push(zi.of(a=>{let f=a.plugin(l);return f?o(f):K.none})),n&&h.push(n(l)),h})}static fromClass(t,e){return Gt.define((i,s)=>new t(i,s),e)}}class ts{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Bt(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Bt(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Bt(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const uo=D.define(),nn=D.define(),zi=D.define(),po=D.define(),rn=D.define(),ti=D.define(),go=D.define();function zn(r,t){let e=r.state.facet(go);if(!e.length)return e;let i=e.map(n=>n instanceof Function?n(r):n),s=[];return z.spans(i,t.from,t.to,{point(){},span(n,o,l,h){let a=n-t.from,f=o-t.from,c=s;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=ih(t.text,a,f)),h>0&&c.length&&(p=c[c.length-1]).to==a&&p.direction==d)p.to=f,c=p.inner;else{let g={from:a,to:f,direction:d,inner:[]};c.push(g),c=g.inner}}}}),s}const mo=D.define();function bo(r){let t=0,e=0,i=0,s=0;for(let n of r.state.facet(mo)){let o=n(r);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Be=D.define();class gt{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new gt(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,n=0,o=0;;){let l=s<t.length?t[s].fromB:1e9,h=n<e.length?e[n]:1e9,a=Math.min(l,h);if(a==1e9)break;let f=a+o,c=a,u=f;for(;;)if(n<e.length&&e[n]<=c){let d=e[n+1];n+=2,c=Math.max(c,d);for(let p=s;p<t.length&&t[p].fromB<=c;p++)o=t[p].toA-t[p].toB;u=Math.max(u,d+o)}else if(s<t.length&&t[s].fromB<=c){let d=t[s++];c=Math.max(c,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new gt(f,u,a,c))}return i}}class Ri{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.empty(this.startState.doc.length);for(let n of i)this.changes=this.changes.compose(n.changes);let s=[];this.changes.iterChangedRanges((n,o,l,h)=>s.push(new gt(n,o,l,h))),this.changedRanges=s}static create(t,e,i){return new Ri(t,e,i)}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(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const rh=[];class Z{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return rh}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&Hl(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=Qt(this.dom),s=this.length?t>0:e>0;return new kt(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof ji)return t;return null}static get(t){return t.cmTile}}class qi extends Z{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s,n=t?.node==e?t:null,o=0;for(let l of this.children){if(l.sync(t),o+=l.length+l.breakAfter,s=i?i.nextSibling:e.firstChild,n&&s!=l.dom&&(n.written=!0),l.dom.parentNode==e)for(;s&&s!=l.dom;)s=qn(s);else e.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:e.firstChild,n&&s&&(n.written=!0);s;)s=qn(s);this.length=o}}function qn(r){let t=r.nextSibling;return r.parentNode.removeChild(r),t}class ji extends qi{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=Z.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,n=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&n++,s=e.pop()}else{let o=i.children[s++];if(o instanceof jt)e.push(s),i=o,s=0;else{let l=n+o.length,h=t(o,n);if(h!==void 0)return h;n=l+o.breakAfter}}}resolveBlock(t,e){let i,s=-1,n,o=-1;if(this.blockTiles((l,h)=>{let a=h+l.length;if(t>=h&&t<=a){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(h<t||t==a&&(e<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=t-h),(a>t||t==h&&(e>1?l.length:l.covers(-1)))&&(!n||!l.isWidget()&&n.isWidget())&&(n=l,o=t-h)}}),!i&&!n)throw new Error("No tile at position "+t);return i&&e<0||!n?{tile:i,offset:s}:{tile:n,offset:o}}}class jt extends qi{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new jt(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class we extends qi{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new we(e||document.createElement("div"),t);return(!e||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,n=-1,o=null,l=-1;function h(f,c){for(let u=0,d=0;u<f.children.length&&d<=c;u++){let p=f.children[u],g=d+p.length;g>=c&&(p.isComposite()?h(p,c-d):(!o||o.isHidden&&(e>0||i&&lh(o,p)))&&(g>c||p.flags&32)?(o=p,l=c-d):(d<c||p.flags&16&&!p.isHidden)&&(s=p,n=c-d)),d=g}}h(this,t);let a=(e<0?s:o)||s||o;return a?{tile:a,offset:a==s?n:l}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):oh(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:s,offset:n}=i;if(this.dom.contains(s.dom))return s.isText()?new kt(s.dom,Math.min(s.dom.nodeValue.length,n)):s.domPosFor(n,s.flags&16?1:s.flags&32?-1:e);let o=i.tile.parent,l=!1;for(let h of o.children){if(l)return new kt(h.dom,0);h==i.tile&&(l=!0)}}return new kt(this.dom,0)}}function oh(r){let t=r.dom.lastChild;if(!t)return r.dom.getBoundingClientRect();let e=Fe(t);return e[e.length-1]||null}function lh(r,t){let e=r.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}class lt extends qi{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new lt(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class ee extends Z{constructor(t,e){super(t,e.length),this.text=e}sync(t){this.flags&2||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,n=t,o=0;t==0&&e<0||t==i&&e>=0?v.chrome||v.gecko||(t?(s--,o=1):n<i&&(n++,o=-1)):e<0?s--:n<i&&n++;let l=_e(this.dom,s,n).getClientRects();if(!l.length)return null;let h=l[(o?o<0:e>=0)?0:l.length-1];return v.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?Ue(h,o<0):h||null}static of(t,e){let i=new ee(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class le extends Z{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return Ue(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let n=this.dom.getClientRects(),o=null;if(!n.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let h=l?n.length-1:0;o=n[h],!(t>0?h==0:h==n.length-1||o.top<o.bottom);h+=l?-1:1);return Ue(o,!l)}}get overrideDOMText(){if(!this.length)return W.empty;let{root:t}=this;if(!t)return W.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,n){return n||(n=t.toDOM(e),t.editable||(n.contentEditable="false")),new le(n,i,t,s)}}class Ei extends Z{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return W.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class hh{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:n,beforeBreak:o,parents:l}=this;for(;t||e>0;)if(s.isComposite())if(o){if(!t)break;i&&i.break(),t--,o=!1}else if(n==s.children.length){if(!t&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:n}=l.pop(),n++}else{let h=s.children[n],a=h.breakAfter;(e>0?h.length<=t:h.length<t)&&(!i||i.skip(h,0,h.length)!==!1||!h.isComposite)?(o=!!a,n++,t-=h.length):(l.push({tile:s,index:n}),s=h,n=0,i&&h.isComposite()&&i.enter(h))}else if(n==s.length)o=!!s.breakAfter,{tile:s,index:n}=l.pop(),n++;else if(t){let h=Math.min(t,s.length-n);i&&i.skip(s,n,n+h),t-=h,n+=h}else break;return this.tile=s,this.index=n,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class ah{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class fh{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var n;this.flushBuffer();let o=this.ensureMarks(e,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+t.length<512){this.cache.reused.set(l,2);let h=o.children[o.children.length-1]=new ee(l.dom,l.text+t);h.parent=o}else o.append(s||ee.of(t,(n=this.cache.find(ee))===null||n===void 0?void 0:n.dom));this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?es(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let l=e.marks.length-1;l>=0;l--){let h=e.marks[l],a=s.lastChild;if(a instanceof lt&&a.mark.eq(h.mark))a.dom!=h.dom&&a.setDOM(es(h.dom)),s=a;else{if(this.cache.reused.get(h)){let c=Z.get(h.dom);c&&c.setDOM(es(h.dom))}let f=lt.of(h.mark,h.dom);s.append(f),s=f}this.cache.reused.set(h,2)}let n=Z.get(t.text);n&&this.cache.reused.set(n,2);let o=new ee(t.text,t.text.nodeValue);o.flags|=8,s.append(o)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);s||this.flushBuffer();let n=this.ensureMarks(e,i);!s&&!(t.flags&16)&&n.append(this.getBuffer(1)),n.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=xo);let s=we.start(t,e||((i=this.cache.find(we))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let n=t.length-1;n>=0;n--){let o=t[n],l;if(e>0&&(l=s.lastChild)&&l instanceof lt&&l.mark.eq(o))s=l,e--;else{let h=lt.of(o,(i=this.cache.find(lt,a=>a.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(h),s=h,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!jn(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(v.ios&&jn(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(is,0,32)||new le(is.toDOM(),0,is,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new ah(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof jt&&s.wrapper.eq(i.wrapper))e=s;else{let n=jt.of(i.wrapper,(t=this.cache.find(jt,o=>o.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(n),e=n}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(Ei,void 0,1);return i&&(i.flags=e),i||new Ei(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class ch{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:s,lineBreak:n,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(t,s.length);return n?null:s.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const Ni=[le,we,ee,lt,Ei,jt,ji];for(let r=0;r<Ni.length;r++)Ni[r].bucket=r;class uh{constructor(t){this.view=t,this.buckets=Ni.map(()=>[]),this.index=Ni.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,n=this.buckets[s],o=this.index[s];for(let l=n.length-1;l>=0;l--){let h=(l+o)%n.length,a=n[h];if((!e||e(a))&&!this.reused.has(a))return n.splice(h,1),h<o&&this.index[s]--,this.reused.set(a,i),a}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let n=0,o=0;;n++){if(n==s.length){if(o)return null;o=1,n=0}let l=s[n];if(!this.reused.has(l)&&(o==0?l.widget.compare(t):l.widget.constructor==t.constructor&&t.updateDOM(l.dom,this.view)))return s.splice(n,1),n<this.index[0]&&this.index[0]--,l.widget==t&&l.length==e&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new le(l.dom,e,t,l.flags&-498|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class dh{constructor(t,e,i,s,n){this.view=t,this.decorations=s,this.disallowBlockEffectsFor=n,this.openWidget=!1,this.openMarks=0,this.cache=new uh(t),this.text=new ch(t.state.doc),this.builder=new fh(this.cache,new ji(t,t.contentDOM),z.iter(i)),this.cache.reused.set(e,2),this.old=new hh(e),this.reuseWalker={skip:(o,l,h)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,n=0,o=0;;){let l=o<t.length?t[o++]:null,h=l?l.fromA:this.old.root.length;if(h>s){let a=h-s;this.preserve(a,!o,!l),s=h,n+=a}if(!l)break;e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.forward(l.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(n,e.range.fromB),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,l.toA),this.emit(e.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(n,l.toB)),n=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=mh(this.old),n=this.openMarks;this.old.advance(t,i?1:-1,{skip:(o,l,h)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(h-l);else{let a=h>0||l<o.length?le.of(o.widget,this.view,h-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,s,n),n=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&h==o.length?this.builder.addText(o.text,s,n,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,h),s,n)),n=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Ei)this.cache.add(o);else if(o instanceof lt)this.builder.ensureLine(null),this.builder.addMark(o,s,n),this.cache.reused.set(o,1),n=s.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof lt&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=n=0):o instanceof lt&&(s.shift(),n=Math.min(n,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,s=this.builder,n=0,o=z.spans(this.decorations,t,e,{point:(l,h,a,f,c,u)=>{if(a instanceof re){if(this.disallowBlockEffectsFor[u]){if(a.block)throw new RangeError("Block decorations may not be specified via plugins");if(h>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(n=f.length,c>f.length)s.continueWidget(h-l);else{let d=a.widget||(a.block?ke.block:ke.inline),p=ph(a),g=this.cache.findWidget(d,h-l,p)||le.of(d,this.view,h-l,p);a.block?(a.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(g)):(s.ensureLine(i),s.addInlineWidget(g,f,c))}i=null}else i=gh(i,a);h>l&&this.text.skip(h-l)},span:(l,h,a,f)=>{for(let c=l;c<h;){let u=this.text.next(Math.min(512,h-c));u==null?(s.addLineStartIfNotCovered(i),s.addBreak(),c++):(s.ensureLine(i),s.addText(u,a,c==l?f:a.length),c+=u.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=o>n,this.openMarks=o}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let n=Z.get(s);if(s==this.view.contentDOM)break;n instanceof lt?e.push(n):n?.isLine()?i=n:s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new we(s,xo):e.push(lt.of(new Xe({tagName:s.nodeName.toLowerCase(),attributes:Vl(s)}),s))}return{line:i,marks:e}}}function jn(r,t){let e=i=>{for(let s of i.children)if((t?s.isText():s.length)||e(s))return!0;return!1};return e(r)}function ph(r){let t=r.isReplace?(r.startSide<0?64:0)|(r.endSide>0?128:0):r.startSide>0?32:16;return r.block&&(t|=256),t}const xo={class:"cm-line"};function gh(r,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(r||(r={class:"cm-line"}),e&&Xs(e,r),i&&(r.class+=" "+i)),r}function mh(r){let t=[];for(let e=r.parents.length;e>1;e--){let i=e==r.parents.length?r.tile:r.parents[e].tile;i instanceof lt&&t.push(i.mark)}return t}function es(r){let t=Z.get(r);return t&&t.setDOM(r.cloneNode()),r}class ke extends Ye{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}ke.inline=new ke("span");ke.block=new ke("div");const is=new class extends Ye{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class $n{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=K.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new ji(t,t.contentDOM),this.updateInner([new gt(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!Ah(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let n=s>-1?xh(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:c}=this.hasComposition;i=new gt(f,c,t.changes.mapPos(f,-1),t.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=n?{from:n.range.fromB,to:n.range.toB}:null,(v.ie||v.chrome)&&!n&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let h=kh(o,this.decorations,t.changes);h.length&&(i=gt.extendWithRanges(i,h));let a=vh(l,this.blockWrappers,t.changes);return a.length&&(i=gt.extendWithRanges(i,a)),n&&!i.some(f=>f.fromA<=n.range.fromA&&f.toA>=n.range.toA)&&(i=n.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,n),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let o=this.tile,l=new dh(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(t,e),Ws(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=v.chrome||v.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),n&&(n.written||i.selectionRange.focusNode!=n.node||!this.tile.dom.contains(n.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let n of this.tile.children)n.isWidget()&&n.widget instanceof ss&&s.push(n.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(co)&&(this.editContextFormatting=i.value)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,n=s==i,o=!n&&!(this.view.state.facet(Nt)||i.tabIndex>-1)&&We(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(n||e||o))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,a,f;if(h.empty?f=a=this.inlineDOMNearPos(h.anchor,h.assoc||1):(f=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),a=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),v.gecko&&h.empty&&!this.hasComposition&&bh(a)){let u=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(u,a.node.childNodes[a.offset]||null)),a=f=new kt(u,0),l=!0}let c=this.view.observer.selectionRange;(l||!c.focusNode||(!He(a.node,a.offset,c.anchorNode,c.anchorOffset)||!He(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,h))&&(this.view.observer.ignore(()=>{v.android&&v.chrome&&i.contains(c.focusNode)&&Ch(c.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=ye(this.view.root);if(u)if(h.empty){if(v.gecko){let d=yh(a.node,a.offset);if(d&&d!=3){let p=(d==1?Jr:Yr)(a.node,a.offset);p&&(a=new kt(p.node,p.offset))}}u.collapse(a.node,a.offset),h.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=h.bidiLevel)}else if(u.extend){u.collapse(a.node,a.offset);try{u.extend(f.node,f.offset)}catch{}}else{let d=document.createRange();h.anchor>h.head&&([a,f]=[f,a]),d.setEnd(f.node,f.offset),d.setStart(a.node,a.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new kt(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new kt(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&He(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ye(t.root),{anchorNode:s,anchorOffset:n}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=this.lineAt(e.head,e.assoc);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let h=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!h||!a||h.bottom>a.top)return;let f=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(f.node,f.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(s,n)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let n;if(t==i.dom)n=i.dom.childNodes[e];else{let o=Ft(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?o=-1:o=1),t=l}o<0?n=t:n=t.nextSibling}if(n==i.dom.firstChild)return s;for(;n&&!Z.get(n);)n=n.nextSibling;if(!n)return s+i.length;for(let o=0,l=s;;o++){let h=i.children[o];if(h.dom==n)return l;l+=h.length+h.breakAfter}}else return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,n=!1,o,l=-1,h=!1;return this.tile.blockTiles((a,f)=>{if(a.isWidget()){if(a.flags&32&&f>=t)return!0;a.flags&16&&(n=!0)}else{let c=f+a.length;if(f<=t&&(i=a,s=t-f,n=c<t),c>=t&&!o&&(o=a,l=t-f,h=f>t),f>t&&o)return!0}}),!i&&!o?this.domAtPos(t,e):(n&&o?i=null:h&&i&&(o=null),i&&e<0||!o?i.domIn(s,e):o.domIn(l,e))}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof ss?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function s(n,o){if(n.isComposite())for(let l of n.children){if(l.length>=o){let h=s(l,o);if(h)return h}if(o-=l.length,o<0)break}else if(n.isText()&&o<n.length){let l=wt(n.text,o);if(l==o)return null;let h=_e(n.dom,o,l).getClientRects();for(let a=0;a<h.length;a++){let f=h[a];if(a==h.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return s(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,n=this.view.contentDOM.clientWidth,o=n>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==tt.LTR,a=0,f=(c,u,d)=>{for(let p=0;p<c.children.length&&!(u>s);p++){let g=c.children[p],m=u+g.length,b=g.dom.getBoundingClientRect(),{height:A}=b;if(d&&!p&&(a+=b.top-d.top),g instanceof jt)m>i&&f(g,u,b);else if(u>=i&&(a>0&&e.push(-a),e.push(A+a),a=0,o)){let M=g.dom.lastChild,E=M?Fe(M):[];if(E.length){let O=E[E.length-1],P=h?O.right-b.left:b.right-O.left;P>l&&(l=P,this.minWidth=n,this.minWidthFrom=u,this.minWidthTo=m)}}d&&p==c.children.length-1&&(a+=d.bottom-b.bottom),u=m+g.breakAfter}};return f(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?tt.RTL:tt.LTR}measureTextSize(){let t=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,h;for(let a of o.children){if(!a.isText()||/[^ -~]/.test(a.text))return;let f=Fe(a.dom);if(f.length!=1)return;l+=f[0].width,h=f[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:h}}});if(t)return t;let e=document.createElement("div"),i,s,n;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.tile.dom.appendChild(e);let o=Fe(e.firstChild)[0];i=e.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,n=o&&o.height?o.height:i,e.remove()}),{lineHeight:i,charWidth:s,textHeight:n}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let n=s==e.viewports.length?null:e.viewports[s],o=n?n.from-1:this.view.state.doc.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(K.replace({widget:new ss(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!n)break;i=n.to+1}return K.set(t)}updateDeco(){let t=1,e=this.view.state.facet(zi).map(n=>(this.dynamicDecorationMap[t++]=typeof n=="function")?n(this.view):n),i=!1,s=this.view.state.facet(rn).map((n,o)=>{let l=typeof n=="function";return l&&(i=!0),l?n(this.view):n});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(z.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(po).map(n=>typeof n=="function"?n(this.view):n)}scrollIntoView(t){if(t.isSnapshot){let a=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=a.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let a of this.view.state.facet(fo))try{if(a(this.view,t.range,t))return!0}catch(f){Bt(this.view.state,f,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let n=bo(this.view),o={left:i.left-n.left,top:i.top-n.top,right:i.right+n.right,bottom:i.bottom+n.bottom},{offsetWidth:l,offsetHeight:h}=this.view.scrollDOM;jl(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,h),-h),this.view.textDirection==tt.LTR)}lineHasWidget(t){let e=i=>i.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Ws(this.tile)}}function Ws(r,t){let e=t?.get(r);if(e!=1){e==null&&r.destroy();for(let i of r.children)Ws(i,t)}}function bh(r){return r.node.nodeType==1&&r.node.firstChild&&(r.offset==0||r.node.childNodes[r.offset-1].contentEditable=="false")&&(r.offset==r.node.childNodes.length||r.node.childNodes[r.offset].contentEditable=="false")}function yo(r,t){let e=r.observer.selectionRange;if(!e.focusNode)return null;let i=Jr(e.focusNode,e.focusOffset),s=Yr(e.focusNode,e.focusOffset),n=i||s;if(s&&i&&s.node!=i.node){let l=Z.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)n=s;else if(r.docView.lastCompositionAfterCursor){let h=Z.get(i.node);!h||h.isText()&&h.text!=i.node.nodeValue||(n=s)}}if(r.docView.lastCompositionAfterCursor=n!=i,!n)return null;let o=t-n.offset;return{from:o,to:o+n.node.nodeValue.length,node:n.node}}function xh(r,t,e){let i=yo(r,e);if(!i)return null;let{node:s,from:n,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||r.state.doc.sliceString(i.from,i.to)!=l)return null;let h=t.invertedDesc;return{range:new gt(h.mapPos(n),h.mapPos(o),n,o),text:s}}function yh(r,t){return r.nodeType!=1?0:(t&&r.childNodes[t-1].contentEditable=="false"?1:0)|(t<r.childNodes.length&&r.childNodes[t].contentEditable=="false"?2:0)}let wh=class{constructor(){this.changes=[]}compareRange(t,e){pe(t,e,this.changes)}comparePoint(t,e){pe(t,e,this.changes)}boundChange(t){pe(t,t,this.changes)}};function kh(r,t,e){let i=new wh;return z.compare(r,t,e,i),i.changes}class Sh{constructor(){this.changes=[]}compareRange(t,e){pe(t,e,this.changes)}comparePoint(){}boundChange(t){pe(t,t,this.changes)}}function vh(r,t,e){let i=new Sh;return z.compare(r,t,e,i),i.changes}function Ch(r,t){for(let e=r;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Ah(r,t){let e=!1;return t&&r.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}class ss extends Ye{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Oh(r,t,e=1){let i=r.charCategorizer(t),s=r.doc.lineAt(t),n=t-s.from;if(s.length==0)return k.cursor(t);n==0?e=1:n==s.length&&(e=-1);let o=n,l=n;e<0?o=wt(s.text,n,!1):l=wt(s.text,n);let h=i(s.text.slice(o,l));for(;o>0;){let a=wt(s.text,o,!1);if(i(s.text.slice(a,o))!=h)break;o=a}for(;l<s.length;){let a=wt(s.text,l);if(i(s.text.slice(l,a))!=h)break;l=a}return k.range(o+s.from,l+s.from)}function Mh(r,t,e,i,s){let n=Math.round((i-t.left)*r.defaultCharacterWidth);if(r.lineWrapping&&e.height>r.defaultLineHeight*1.5){let l=r.viewState.heightOracle.textHeight,h=Math.floor((s-e.top-(r.defaultLineHeight-l)*.5)/l);n+=h*r.viewState.heightOracle.lineLength}let o=r.state.sliceDoc(e.from,e.to);return e.from+Ll(o,n,r.state.tabSize)}function Th(r,t,e){let i=r.lineBlockAt(t);if(Array.isArray(i.type)){let s;for(let n of i.type){if(n.from>t)break;if(!(n.to<t)){if(n.from<t&&n.to>t)return n;(!s||n.type==bt.Text&&(s.type!=n.type||(e<0?n.from<t:n.to>t)))&&(s=n)}}return s||i}return i}function Ph(r,t,e,i){let s=Th(r,t.head,t.assoc||-1),n=!i||s.type!=bt.Text||!(r.lineWrapping||s.widgetLineBreaks)?null:r.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(n){let o=r.dom.getBoundingClientRect(),l=r.textDirectionAt(s.from),h=r.posAtCoords({x:e==(l==tt.LTR)?o.right-1:o.left+1,y:(n.top+n.bottom)/2});if(h!=null)return k.cursor(h,e?-1:1)}return k.cursor(e?s.to:s.from,e?-1:1)}function Kn(r,t,e,i){let s=r.state.doc.lineAt(t.head),n=r.bidiSpans(s),o=r.textDirectionAt(s.from);for(let l=t,h=null;;){let a=eh(s,n,o,l,e),f=io;if(!a){if(s.number==(e?r.state.doc.lines:1))return l;f=`
|
|
8
|
+
`,s=r.state.doc.line(s.number+(e?1:-1)),n=r.bidiSpans(s),a=r.visualLineSide(s,!e)}if(h){if(!h(f))return l}else{if(!i)return a;h=i(f)}l=a}}function Dh(r,t,e){let i=r.state.charCategorizer(t),s=i(e);return n=>{let o=i(n);return s==It.Space&&(s=o),s==o}}function Bh(r,t,e,i){let s=t.head,n=e?1:-1;if(s==(e?r.state.doc.length:0))return k.cursor(s,t.assoc);let o=t.goalColumn,l,h=r.contentDOM.getBoundingClientRect(),a=r.coordsAtPos(s,(t.empty?t.assoc:0)||(e?1:-1)),f=r.documentTop;if(a)o==null&&(o=a.left-h.left),l=n<0?a.top:a.bottom;else{let p=r.viewState.lineBlockAt(s);o==null&&(o=Math.min(h.right-h.left,r.defaultCharacterWidth*(s-p.from))),l=(n<0?p.top:p.bottom)+f}let c=h.left+o,u=i??r.viewState.heightOracle.textHeight>>1,d=Fs(r,{x:c,y:l+u*n},!1,n);return k.cursor(d.pos,d.assoc,void 0,o)}function Ve(r,t,e){for(;;){let i=0;for(let s of r)s.between(t-1,t+1,(n,o,l)=>{if(t>n&&t<o){let h=i||e||(t-n<o-t?-1:1);t=h<0?n:o,i=h}});if(!i)return t}}function wo(r,t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],n=null;if(s.empty){let o=Ve(r,s.from,0);o!=s.from&&(n=k.cursor(o,-1))}else{let o=Ve(r,s.from,-1),l=Ve(r,s.to,1);(o!=s.from||l!=s.to)&&(n=k.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}n&&(e||(e=t.ranges.slice()),e[i]=n)}return e?k.create(e,t.mainIndex):t}function ns(r,t,e){let i=Ve(r.state.facet(ti).map(s=>s(r)),e.from,t.head>e.from?-1:1);return i==e.from?e:k.cursor(i,i<e.from?1:-1)}class Dt{constructor(t,e){this.pos=t,this.assoc=e}}function Fs(r,t,e,i){let s=r.contentDOM.getBoundingClientRect(),n=s.top+r.viewState.paddingTop,{x:o,y:l}=t,h=l-n,a;for(;;){if(h<0)return new Dt(0,1);if(h>r.viewState.docHeight)return new Dt(r.state.doc.length,-1);if(a=r.elementAtHeight(h),i==null)break;if(a.type==bt.Text){if(i<0?a.to<r.viewport.from:a.from>r.viewport.to)break;let u=r.docView.coordsAt(i<0?a.from:a.to,i>0?-1:1);if(u&&(i<0?u.top<=h+n:u.bottom>=h+n))break}let c=r.viewState.heightOracle.textHeight/2;h=i>0?a.bottom+c:a.top-c}if(r.viewport.from>=a.to||r.viewport.to<=a.from){if(e)return null;if(a.type==bt.Text){let c=Mh(r,s,a,o,l);return new Dt(c,c==a.from?1:-1)}}if(a.type!=bt.Text)return h<(a.top+a.bottom)/2?new Dt(a.from,1):new Dt(a.to,-1);let f=r.docView.lineAt(a.from,2);return(!f||f.length!=a.length)&&(f=r.docView.lineAt(a.from,-2)),ko(r,f,a.from,o,l)}function ko(r,t,e,i,s){let n=-1,o=null,l=1e9,h=1e9,a=s,f=s,c=(u,d)=>{for(let p=0;p<u.length;p++){let g=u[p];if(g.top==g.bottom)continue;let m=g.left>i?g.left-i:g.right<i?i-g.right:0,b=g.top>s?g.top-s:g.bottom<s?s-g.bottom:0;g.top<=f&&g.bottom>=a&&(a=Math.min(g.top,a),f=Math.max(g.bottom,f),b=0),(n<0||(b-h||m-l)<0)&&(n>=0&&h&&l<m&&o.top<=f-2&&o.bottom>=a+2?h=0:(n=d,l=m,h=b,o=g))}};if(t.isText()){for(let d=0;d<t.length;){let p=wt(t.text,d);if(c(_e(t.dom,d,p).getClientRects(),d),!l&&!h)break;d=p}return i>(o.left+o.right)/2==(Qn(r,n+e)==tt.LTR)?new Dt(e+wt(t.text,n),-1):new Dt(e+n,1)}else{if(!t.length)return new Dt(e,1);for(let g=0;g<t.children.length;g++){let m=t.children[g];if(m.flags&48)continue;let b=(m.dom.nodeType==1?m.dom:_e(m.dom,0,m.length)).getClientRects();if(c(b,g),!l&&!h)break}let u=t.children[n],d=t.posBefore(u,e);return u.isComposite()||u.isText()?ko(r,u,d,Math.max(o.left,Math.min(o.right,i)),s):i>(o.left+o.right)/2==(Qn(r,n+e)==tt.LTR)?new Dt(d+u.length,-1):new Dt(d,1)}}function Qn(r,t){let e=r.state.doc.lineAt(t);return r.bidiSpans(e)[Lt.find(r.bidiSpans(e),t-e.from,-1,1)].dir}const Re="";class Rh{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(V.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Re}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let n=this.text.length;this.readNode(s);let o=Z.get(s),l=s.nextSibling;if(l==e){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let h=Z.get(l);(o&&h?o.breakAfter:(o?o.breakAfter:Bi(s))||Bi(l)&&(s.nodeName!="BR"||o?.isWidget())&&this.text.length>n)&&!Nh(l,e)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let n=-1,o=1,l;if(this.lineSeparator?(n=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(e))&&(n=l.index,o=l[0].length),this.append(e.slice(i,n<0?e.length:n)),n<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==t&&h.pos>this.text.length&&(h.pos-=o-1);i=n+o}}readNode(t){let e=Z.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Eh(t,i.node,i.offset)?e:0))}}function Eh(r,t,e){for(;;){if(!t||e<Ft(t))return!1;if(t==r)return!0;e=Qt(t)+1,t=t.parentNode}}function Nh(r,t){let e;for(;!(r==t||!r);r=r.nextSibling){let i=Z.get(r);if(!i?.isWidget())return!1;i&&(e||(e=[])).push(i)}if(e)for(let i of e){let s=i.overrideDOMText;if(s?.length)return!1}return!0}class Gn{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class Ih{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:n,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=So(t.docView.tile,e,i,0))){let l=n||o?[]:Wh(t),h=new Rh(l,t);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=Fh(l,this.bounds.from)}else{let l=t.observer.selectionRange,h=n&&n.node==l.focusNode&&n.offset==l.focusOffset||!Rs(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),a=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Rs(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),f=t.viewport;if((v.ios||v.chrome)&&t.state.selection.main.empty&&h!=a&&(f.from>0||f.to<t.state.doc.length)){let c=Math.min(h,a),u=Math.max(h,a),d=f.from-c,p=f.to-u;(d==0||d==1||c==0)&&(p==0||p==-1||u==t.state.doc.length)&&(h=0,a=t.state.doc.length)}t.inputState.composing>-1&&t.state.selection.ranges.length>1?this.newSel=t.state.selection.replaceRange(k.range(a,h)):this.newSel=k.single(a,h)}}}function So(r,t,e,i){if(r.isComposite()){let s=-1,n=-1,o=-1,l=-1;for(let h=0,a=i,f=i;h<r.children.length;h++){let c=r.children[h],u=a+c.length;if(a<t&&u>e)return So(c,t,e,a);if(u>=t&&s==-1&&(s=h,n=a),a>e&&c.dom.parentNode==r.dom){o=h,l=f;break}f=u,a=u+c.breakAfter}return{from:n,to:l<0?i+r.length:l,startDOM:(s?r.children[s-1].dom.nextSibling:null)||r.dom.firstChild,endDOM:o<r.children.length&&o>=0?r.children[o].dom:null}}else return r.isText()?{from:i,to:i+r.length,startDOM:r.dom,endDOM:r.dom.nextSibling}:null}function vo(r,t){let e,{newSel:i}=t,s=r.state.selection.main,n=r.inputState.lastKeyTime>Date.now()-100?r.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,h=s.from,a=null;(n===8||v.android&&t.text.length<l-o)&&(h=s.to,a="end");let f=Co(r.state.doc.sliceString(o,l,Re),t.text,h-o,a);f&&(v.chrome&&n==13&&f.toB==f.from+2&&t.text.slice(f.from,f.toB)==Re+Re&&f.toB--,e={from:o+f.from,to:o+f.toA,insert:W.of(t.text.slice(f.from,f.toB).split(Re))})}else i&&(!r.hasFocus&&r.state.facet(Nt)||Ii(i,s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:r.state.doc.slice(s.from,s.to)}:(v.mac||v.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&r.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=k.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:W.of([e.insert.toString().replace("."," ")])}):e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:r.state.doc.slice(s.from,e.from).append(e.insert).append(r.state.doc.slice(e.to,s.to))}:r.state.doc.lineAt(s.from).to<s.to&&r.docView.lineHasWidget(s.to)&&r.inputState.insertingTextAt>Date.now()-50?e={from:s.from,to:s.to,insert:r.state.toText(r.inputState.insertingText)}:v.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
|
|
9
|
+
`&&r.lineWrapping&&(i&&(i=k.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:W.of([" "])}),e)return on(r,e,i,n);if(i&&!Ii(i,s)){let o=!1,l="select";return r.inputState.lastSelectionTime>Date.now()-50&&(r.inputState.lastSelectionOrigin=="select"&&(o=!0),l=r.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=wo(r.state.facet(ti).map(h=>h(r)),i))),r.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function on(r,t,e,i=-1){if(v.ios&&r.inputState.flushIOSKey(t))return!0;let s=r.state.selection.main;if(v.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&r.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&ge(r.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&ge(r.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&ge(r.contentDOM,"Delete",46)))return!0;let n=t.insert.toString();r.inputState.composing>=0&&r.inputState.composing++;let o,l=()=>o||(o=Lh(r,t,e));return r.state.facet(lo).some(h=>h(r,t.from,t.to,n,l))||r.dispatch(l()),!0}function Lh(r,t,e){let i,s=r.state,n=s.selection.main,o=-1;if(t.from==t.to&&t.from<n.from||t.from>n.to){let h=t.from<n.from?-1:1,a=h<0?n.from:n.to,f=Ve(s.facet(ti).map(c=>c(r)),a,h);t.from==f&&(o=f)}if(o>-1)i={changes:t,selection:k.cursor(t.from+t.insert.length,-1)};else if(t.from>=n.from&&t.to<=n.to&&t.to-t.from>=(n.to-n.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&r.inputState.composing<0){let h=n.from<t.from?s.sliceDoc(n.from,t.from):"",a=n.to>t.to?s.sliceDoc(t.to,n.to):"";i=s.replaceSelection(r.state.toText(h+t.insert.sliceString(0,void 0,r.state.lineBreak)+a))}else{let h=s.changes(t),a=e&&e.main.to<=h.newLength?e.main:void 0;if(s.selection.ranges.length>1&&(r.inputState.composing>=0||r.inputState.compositionPendingChange)&&t.to<=n.to+10&&t.to>=n.to-10){let f=r.state.sliceDoc(t.from,t.to),c,u=e&&yo(r,e.main.head);if(u){let p=t.insert.length-(t.to-t.from);c={from:u.from,to:u.to-p}}else c=r.state.doc.lineAt(n.head);let d=n.to-t.to;i=s.changeByRange(p=>{if(p.from==n.from&&p.to==n.to)return{changes:h,range:a||p.map(h)};let g=p.to-d,m=g-f.length;if(r.state.sliceDoc(m,g)!=f||g>=c.from&&m<=c.to)return{range:p};let b=s.changes({from:m,to:g,insert:t.insert}),A=p.to-n.to;return{changes:b,range:a?k.range(Math.max(0,a.anchor+A),Math.max(0,a.head+A)):p.map(b)}})}else i={changes:h,selection:a&&s.selection.replaceRange(a)}}let l="input.type";return(r.composing||r.inputState.compositionPendingChange&&r.inputState.compositionEndedAt>Date.now()-50)&&(r.inputState.compositionPendingChange=!1,l+=".compose",r.inputState.compositionFirstChange&&(l+=".start",r.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Co(r,t,e,i){let s=Math.min(r.length,t.length),n=0;for(;n<s&&r.charCodeAt(n)==t.charCodeAt(n);)n++;if(n==s&&r.length==t.length)return null;let o=r.length,l=t.length;for(;o>0&&l>0&&r.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,n-Math.min(o,l));e-=o+h-n}if(o<n&&r.length<t.length){let h=e<=n&&e>=o?n-e:0;n-=h,l=n+(l-o),o=n}else if(l<n){let h=e<=n&&e>=l?n-e:0;n-=h,o=n+(o-l),l=n}return{from:n,toA:o,toB:l}}function Wh(r){let t=[];if(r.root.activeElement!=r.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:n}=r.observer.selectionRange;return e&&(t.push(new Gn(e,i)),(s!=e||n!=i)&&t.push(new Gn(s,n))),t}function Fh(r,t){if(r.length==0)return null;let e=r[0].pos,i=r.length==2?r[1].pos:e;return e>-1&&i>-1?k.single(e+t,i+t):null}function Ii(r,t){return t.head==r.main.head&&t.anchor==r.main.anchor}class Hh{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,v.safari&&t.contentDOM.addEventListener("input",()=>null),v.gecko&&ea(t.contentDOM.ownerDocument)}handleEvent(t){!Uh(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Vh(t),i=this.handlers,s=this.view.contentDOM;for(let n in e)if(n!="scroll"){let o=!e[n].handlers.length,l=i[n];l&&o!=!l.handlers.length&&(s.removeEventListener(n,this.handleEvent),l=null),l||s.addEventListener(n,this.handleEvent,{passive:o})}for(let n in i)n!="scroll"&&!e[n]&&s.removeEventListener(n,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&qh.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),v.android&&v.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return v.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Ao.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||zh.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,ge(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return!/^key/.test(t.type)||t.synthetic?!1:this.composing>0?!0:v.safari&&!v.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Un(r,t){return(e,i)=>{try{return t.call(r,i,e)}catch(s){Bt(e.state,s)}}}function Vh(r){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of r){let s=i.spec,n=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(n)for(let l in n){let h=n[l];h&&e(l).handlers.push(Un(i.value,h))}if(o)for(let l in o){let h=o[l];h&&e(l).observers.push(Un(i.value,h))}}for(let i in vt)e(i).handlers.push(vt[i]);for(let i in xt)e(i).observers.push(xt[i]);return t}const Ao=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],zh="dthko",qh=[16,17,18,20,91,92,224,225],di=6;function pi(r){return Math.max(0,r)*.7+8}function jh(r,t){return Math.max(Math.abs(r.clientX-t.clientX),Math.abs(r.clientY-t.clientY))}class $h{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=$l(t.contentDOM),this.atoms=t.state.facet(ti).map(o=>o(t));let n=t.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(V.allowMultipleSelections)&&Kh(t,e),this.dragging=Gh(t,e)&&To(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&jh(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,n=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:n,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=bo(this.view);t.clientX-h.left<=s+di?e=-pi(s-t.clientX):t.clientX+h.right>=o-di&&(e=pi(t.clientX-o)),t.clientY-h.top<=n+di?i=-pi(n-t.clientY):t.clientY+h.bottom>=l-di&&(i=pi(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=wo(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Kh(r,t){let e=r.state.facet(so);return e.length?e[0](t):v.mac?t.metaKey:t.ctrlKey}function Qh(r,t){let e=r.state.facet(no);return e.length?e[0](t):v.mac?!t.altKey:!t.ctrlKey}function Gh(r,t){let{main:e}=r.state.selection;if(e.empty)return!1;let i=ye(r.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let n=0;n<s.length;n++){let o=s[n];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Uh(r,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=r.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=Z.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}const vt=Object.create(null),xt=Object.create(null),Oo=v.ie&&v.ie_version<15||v.ios&&v.webkit_version<604;function _h(r){let t=r.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{r.focus(),e.remove(),Mo(r,e.value)},50)}function $i(r,t,e){for(let i of r.facet(t))e=i(e,r);return e}function Mo(r,t){t=$i(r.state,en,t);let{state:e}=r,i,s=1,n=e.toText(t),o=n.lines==e.selection.ranges.length;if(Hs!=null&&e.selection.ranges.every(h=>h.empty)&&Hs==n.toString()){let h=-1;i=e.changeByRange(a=>{let f=e.doc.lineAt(a.from);if(f.from==h)return{range:a};h=f.from;let c=e.toText((o?n.line(s++).text:t)+e.lineBreak);return{changes:{from:f.from,insert:c},range:k.cursor(a.from+c.length)}})}else o?i=e.changeByRange(h=>{let a=n.line(s++);return{changes:{from:h.from,to:h.to,insert:a.text},range:k.cursor(h.from+a.length)}}):i=e.replaceSelection(n);r.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}xt.scroll=r=>{r.inputState.lastScrollTop=r.scrollDOM.scrollTop,r.inputState.lastScrollLeft=r.scrollDOM.scrollLeft};vt.keydown=(r,t)=>(r.inputState.setSelectionOrigin("select"),t.keyCode==27&&r.inputState.tabFocusMode!=0&&(r.inputState.tabFocusMode=Date.now()+2e3),!1);xt.touchstart=(r,t)=>{r.inputState.lastTouchTime=Date.now(),r.inputState.setSelectionOrigin("select.pointer")};xt.touchmove=r=>{r.inputState.setSelectionOrigin("select.pointer")};vt.mousedown=(r,t)=>{if(r.observer.flush(),r.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of r.state.facet(ro))if(e=i(r,t),e)break;if(!e&&t.button==0&&(e=Yh(r,t)),e){let i=!r.hasFocus;r.inputState.startMouseSelection(new $h(r,t,e,i)),i&&r.observer.ignore(()=>{Ur(r.contentDOM);let n=r.root.activeElement;n&&!n.contains(r.contentDOM)&&n.blur()});let s=r.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}else r.inputState.setSelectionOrigin("select.pointer");return!1};function _n(r,t,e,i){if(i==1)return k.cursor(t,e);if(i==2)return Oh(r.state,t,e);{let s=r.docView.lineAt(t,e),n=r.state.doc.lineAt(s?s.posAtEnd:t),o=s?s.posAtStart:n.from,l=s?s.posAtEnd:n.to;return l<r.state.doc.length&&l==n.to&&l++,k.range(o,l)}}const Jh=v.ie&&v.ie_version<=11;let Jn=null,Yn=0,Xn=0;function To(r){if(!Jh)return r.detail;let t=Jn,e=Xn;return Jn=r,Xn=Date.now(),Yn=!t||e>Date.now()-400&&Math.abs(t.clientX-r.clientX)<2&&Math.abs(t.clientY-r.clientY)<2?(Yn+1)%3:1}function Yh(r,t){let e=r.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=To(t),s=r.state.selection;return{update(n){n.docChanged&&(e.pos=n.changes.mapPos(e.pos),s=s.map(n.changes))},get(n,o,l){let h=r.posAndSideAtCoords({x:n.clientX,y:n.clientY},!1),a,f=_n(r,h.pos,h.assoc,i);if(e.pos!=h.pos&&!o){let c=_n(r,e.pos,e.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u<f.from?k.range(u,d):k.range(d,u)}return o?s.replaceRange(s.main.extend(f.from,f.to)):l&&i==1&&s.ranges.length>1&&(a=Xh(s,h.pos))?a:l?s.addRange(f):k.create([f])}}}function Xh(r,t){for(let e=0;e<r.ranges.length;e++){let{from:i,to:s}=r.ranges[e];if(i<=t&&s>=t)return k.create(r.ranges.slice(0,e).concat(r.ranges.slice(e+1)),r.mainIndex==e?0:r.mainIndex-(r.mainIndex>e?1:0))}return null}vt.dragstart=(r,t)=>{let{selection:{main:e}}=r.state;if(t.target.draggable){let s=r.docView.tile.nearest(t.target);if(s&&s.isWidget()){let n=s.posAtStart,o=n+s.length;(n>=e.to||o<=e.from)&&(e=k.range(n,o))}}let{inputState:i}=r;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",$i(r.state,sn,r.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};vt.dragend=r=>(r.inputState.draggedContent=null,!1);function Zn(r,t,e,i){if(e=$i(r.state,en,e),!e)return;let s=r.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:n}=r.inputState,o=i&&n&&Qh(r,t)?{from:n.from,to:n.to}:null,l={from:s,insert:e},h=r.state.changes(o?[o,l]:l);r.focus(),r.dispatch({changes:h,selection:{anchor:h.mapPos(s,-1),head:h.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),r.inputState.draggedContent=null}vt.drop=(r,t)=>{if(!t.dataTransfer)return!1;if(r.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,n=()=>{++s==e.length&&Zn(r,t,i.filter(o=>o!=null).join(r.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=n,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),n()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Zn(r,t,i,!0),!0}return!1};vt.paste=(r,t)=>{if(r.state.readOnly)return!0;r.observer.flush();let e=Oo?null:t.clipboardData;return e?(Mo(r,e.getData("text/plain")||e.getData("text/uri-list")),!0):(_h(r),!1)};function Zh(r,t){let e=r.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),r.focus()},50)}function ta(r){let t=[],e=[],i=!1;for(let s of r.selection.ranges)s.empty||(t.push(r.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:n}of r.selection.ranges){let o=r.doc.lineAt(n);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(r.doc.length,o.to+1)})),s=o.number}i=!0}return{text:$i(r,sn,t.join(r.lineBreak)),ranges:e,linewise:i}}let Hs=null;vt.copy=vt.cut=(r,t)=>{let e=ye(r.root);if(e&&!We(r.contentDOM,e))return!1;let{text:i,ranges:s,linewise:n}=ta(r.state);if(!i&&!n)return!1;Hs=n?i:null,t.type=="cut"&&!r.state.readOnly&&r.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"});let o=Oo?null:t.clipboardData;return o?(o.clearData(),o.setData("text/plain",i),!0):(Zh(r,i),!1)};const Po=Oe.define();function Do(r,t){let e=[];for(let i of r.facet(ho)){let s=i(r,t);s&&e.push(s)}return e.length?r.update({effects:e,annotations:Po.of(!0)}):null}function Bo(r){setTimeout(()=>{let t=r.hasFocus;if(t!=r.inputState.notifiedFocused){let e=Do(r.state,t);e?r.dispatch(e):r.update([])}},10)}xt.focus=r=>{r.inputState.lastFocusTime=Date.now(),!r.scrollDOM.scrollTop&&(r.inputState.lastScrollTop||r.inputState.lastScrollLeft)&&(r.scrollDOM.scrollTop=r.inputState.lastScrollTop,r.scrollDOM.scrollLeft=r.inputState.lastScrollLeft),Bo(r)};xt.blur=r=>{r.observer.clearSelectionRange(),Bo(r)};xt.compositionstart=xt.compositionupdate=r=>{r.observer.editContext||(r.inputState.compositionFirstChange==null&&(r.inputState.compositionFirstChange=!0),r.inputState.composing<0&&(r.inputState.composing=0))};xt.compositionend=r=>{r.observer.editContext||(r.inputState.composing=-1,r.inputState.compositionEndedAt=Date.now(),r.inputState.compositionPendingKey=!0,r.inputState.compositionPendingChange=r.observer.pendingRecords().length>0,r.inputState.compositionFirstChange=null,v.chrome&&v.android?r.observer.flushSoon():r.inputState.compositionPendingChange?Promise.resolve().then(()=>r.observer.flush()):setTimeout(()=>{r.inputState.composing<0&&r.docView.hasComposition&&r.update([])},50))};xt.contextmenu=r=>{r.inputState.lastContextMenu=Date.now()};vt.beforeinput=(r,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(r.inputState.insertingText=t.data,r.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&r.observer.editContext){let n=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(n&&o.length){let l=o[0],h=r.posAtDOM(l.startContainer,l.startOffset),a=r.posAtDOM(l.endContainer,l.endOffset);return on(r,{from:h,to:a,insert:r.state.toText(n)},null),!0}}let s;if(v.chrome&&v.android&&(s=Ao.find(n=>n.inputType==t.inputType))&&(r.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let n=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>n+10&&r.hasFocus&&(r.contentDOM.blur(),r.focus())},100)}return v.ios&&t.inputType=="deleteContentForward"&&r.observer.flushSoon(),v.safari&&t.inputType=="insertText"&&r.inputState.composing>=0&&setTimeout(()=>xt.compositionend(r,t),20),!1};const tr=new Set;function ea(r){tr.has(r)||(tr.add(r),r.addEventListener("copy",()=>{}),r.addEventListener("cut",()=>{}))}const er=["pre-wrap","normal","pre-line","break-spaces"];let Se=!1;function ir(){Se=!1}class ia{constructor(t){this.lineWrapping=t,this.doc=W.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return er.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,n,o){let l=er.indexOf(t)>-1,h=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=n,h){this.heightSamples={};for(let a=0;a<o.length;a++){let f=o[a];f<0?a++:this.heightSamples[Math.floor(f*10)]=!0}}return h}}class sa{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class yt{constructor(t,e,i,s,n){this.from=t,this.length=e,this.top=i,this.height=s,this._content=n}get type(){return typeof this._content=="number"?bt.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof re?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new yt(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var $=(function(r){return r[r.ByPos=0]="ByPos",r[r.ByHeight=1]="ByHeight",r[r.ByPosNoHeight=2]="ByPosNoHeight",r})($||($={}));const vi=.001;class ot{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>vi&&(Se=!0),this.height=t)}replace(t,e,i){return ot.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let n=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:h,toA:a,fromB:f,toB:c}=s[l],u=n.lineAt(h,$.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=a?u:n.lineAt(a,$.ByPosNoHeight,i,0,0);for(c+=d.to-a,a=d.to;l>0&&u.from<=s[l-1].toA;)h=s[l-1].fromA,f=s[l-1].fromB,l--,h<u.from&&(u=n.lineAt(h,$.ByPosNoHeight,i,0,0));f+=u.from-h,h=u.from;let p=ln.build(i.setDoc(o),t,f,c);n=Li(n,n.replace(h,a,p))}return n.updateHeight(i,0)}static empty(){return new ft(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,n=0;for(;;)if(e==i)if(s>n*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(n>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,n-=l.size}else break;else if(s<n){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(n+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new ra(ot.of(t.slice(0,e)),o,ot.of(t.slice(i)))}}function Li(r,t){return r==t?r:(r.constructor!=t.constructor&&(Se=!0),t)}ot.prototype.size=1;const na=K.replace({});class Ro extends ot{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new yt(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new yt(s,0,i,this.spaceAbove,na):this.mainBlock(i,s)}lineAt(t,e,i,s,n){let o=this.mainBlock(s,n);return this.spaceAbove?this.blockAt(0,i,s,n).join(o):o}forEachLine(t,e,i,s,n,o){t<=n+this.length&&e>=n&&o(this.lineAt(0,$.ByPos,i,s,n))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class ft extends Ro{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new yt(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof ft||s instanceof it&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof it?s=new ft(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):ot.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class it extends ot{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,n=s-i+1,o,l=0;if(t.lineWrapping){let h=Math.min(this.height,t.lineHeight*n);o=h/n,this.length>n+1&&(l=(this.height-h)/(this.length-n-1))}else o=this.height/n;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(t,e,i,s){let{firstLine:n,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(e,s);if(e.lineWrapping){let a=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),f=e.doc.lineAt(a),c=l+f.length*h,u=Math.max(i,t-c/2);return new yt(f.from,f.length,u,c,0)}else{let a=Math.max(0,Math.min(o-n,Math.floor((t-i)/l))),{from:f,length:c}=e.doc.line(n+a);return new yt(f,c,i+l*a,l,0)}}lineAt(t,e,i,s,n){if(e==$.ByHeight)return this.blockAt(t,i,s,n);if(e==$.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new yt(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,n),a=i.doc.lineAt(t),f=l+a.length*h,c=a.number-o,u=s+l*c+h*(a.from-n-c);return new yt(a.from,a.length,Math.max(s,Math.min(u,s+this.height-f)),f,0)}forEachLine(t,e,i,s,n,o){t=Math.max(t,n),e=Math.min(e,n+this.length);let{firstLine:l,perLine:h,perChar:a}=this.heightMetrics(i,n);for(let f=t,c=s;f<=e;){let u=i.doc.lineAt(f);if(f==t){let p=u.number-l;c+=h*p+a*(t-n-p)}let d=h+a*u.length;o(new yt(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let n=i[i.length-1];n instanceof it?i[i.length-1]=new it(n.length+s):i.push(null,new it(s-1))}if(t>0){let n=i[0];n instanceof it?i[0]=new it(t+n.length):i.unshift(new it(t-1),null)}return ot.of(i)}decomposeLeft(t,e){e.push(new it(t-1),null)}decomposeRight(t,e){e.push(null,new it(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let n=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),h=-1;for(s.from>e&&o.push(new it(s.from-e-1).updateHeight(t,e));l<=n&&s.more;){let f=t.doc.lineAt(l).length;o.length&&o.push(null);let c=s.heights[s.index++],u=0;c<0&&(u=-c,c=s.heights[s.index++]),h==-1?h=c:Math.abs(c-h)>=vi&&(h=-2);let d=new ft(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=n&&o.push(null,new it(n-l).updateHeight(t,l));let a=ot.of(o);return(h<0||Math.abs(a.height-this.height)>=vi||Math.abs(h-this.heightMetrics(t,e).perLine)>=vi)&&(Se=!0),Li(this,a)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class ra extends ot{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let n=i+this.left.height;return t<n?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,n,s+this.left.length+this.break)}lineAt(t,e,i,s,n){let o=s+this.left.height,l=n+this.left.length+this.break,h=e==$.ByHeight?t<o:t<l,a=h?this.left.lineAt(t,e,i,s,n):this.right.lineAt(t,e,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let f=e==$.ByPosNoHeight?$.ByPosNoHeight:$.ByPos;return h?a.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,s,n).join(a)}forEachLine(t,e,i,s,n,o){let l=s+this.left.height,h=n+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,s,n,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let a=this.lineAt(h,$.ByPos,i,s,n);t<a.from&&this.left.forEachLine(t,a.from-1,i,s,n,o),a.to>=t&&a.from<=e&&o(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,l,h,o)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let n=[];t>0&&this.decomposeLeft(t,n);let o=n.length;for(let l of i)n.push(l);if(t>0&&sr(n,o-1),e<this.length){let l=n.length;this.decomposeRight(e,n),sr(n,l)}return ot.of(n)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?ot.of(this.break?[t,null,e]:[t,e]):(this.left=Li(this.left,t),this.right=Li(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:n,right:o}=this,l=e+n.length+this.break,h=null;return s&&s.from<=e+n.length&&s.more?h=n=n.updateHeight(t,e,i,s):n.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?h=o=o.updateHeight(t,l,i,s):o.updateHeight(t,l,i),h?this.balanced(n,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function sr(r,t){let e,i;r[t]==null&&(e=r[t-1])instanceof it&&(i=r[t+1])instanceof it&&r.splice(t-1,3,new it(e.length+1+i.length))}const oa=5;class ln{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof ft?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new ft(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,n=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new Ro(o,s,i)):(o||n||s>=oa)&&this.addLineDeco(s,n,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new ft(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new it(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof ft)return t;let e=new ft(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof ft)&&!this.isCovered?this.nodes.push(new ft(0,-1,0)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof ft&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let n=new ln(i,t);return z.spans(e,i,s,n,0),n.finish(i)}}function la(r,t,e){let i=new ha;return z.compare(r,t,e,i,0),i.changes}class ha{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&pe(t,e,this.changes,5)}}function aa(r,t){let e=r.getBoundingClientRect(),i=r.ownerDocument,s=i.defaultView||window,n=Math.max(0,e.left),o=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),h=Math.min(s.innerHeight,e.bottom);for(let a=r.parentNode;a&&a!=i.body;)if(a.nodeType==1){let f=a,c=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();n=Math.max(n,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(a==r.parentNode?s.innerHeight:h,u.bottom)}a=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(a.nodeType==11)a=a.host;else break;return{left:n-e.left,right:Math.max(n,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,h)-(e.top+t)}}function fa(r){let t=r.getBoundingClientRect(),e=r.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function ca(r,t){let e=r.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class rs{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],n=e[i];if(s.from!=n.from||s.to!=n.to||s.size!=n.size)return!1}return!0}draw(t,e){return K.replace({widget:new ua(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class ua extends Ye{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class nr{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=rr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=tt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(nn).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new ia(e),this.stateDeco=or(t),this.heightMap=ot.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle.setDoc(t.doc),[new gt(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=K.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:n,to:o})=>s>=n&&s<=o)){let{from:n,to:o}=this.lineBlockAt(s);t.push(new gi(n,o))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?rr:new hn(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Ee(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=or(this.state);let s=t.changedRanges,n=gt.extendWithRanges(s,la(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ir(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),n),(this.heightMap.height!=o||Se)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let h=n.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<h.from||e.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let a=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,t.flags|=this.updateForViewport(),(a||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(sh)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,n=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?tt.RTL:tt.LTR;let o=this.heightOracle.mustRefreshForWrapping(n)||this.mustMeasureContent,l=e.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let a=0,f=0;if(l.width&&l.height){let{scaleX:E,scaleY:O}=Gr(e,l);(E>.005&&Math.abs(this.scaleX-E)>.005||O>.005&&Math.abs(this.scaleY-O)>.005)&&(this.scaleX=E,this.scaleY=O,a|=16,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=_r(t.scrollDOM);let p=(this.printing?ca:aa)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(h=!0)),!this.inView&&!this.scrollTarget&&!fa(t.dom))return 0;let A=l.width;if((this.contentDOMWidth!=A||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),h){let E=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(E)&&(o=!0),o||s.lineWrapping&&Math.abs(A-this.contentDOMWidth)>s.charWidth){let{lineHeight:O,charWidth:P,textHeight:C}=t.docView.measureTextSize();o=O>0&&s.refresh(n,O,P,C,Math.max(5,A/P),E),o&&(t.docView.minWidth=0,a|=16)}g>0&&m>0?f=Math.max(g,m):g<0&&m<0&&(f=Math.min(g,m)),ir();for(let O of this.viewports){let P=O.from==this.viewport.from?E:t.docView.measureVisibleLineHeights(O);this.heightMap=(o?ot.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle,[new gt(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new sa(O.from,P))}Se&&(a|=2)}let M=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return M&&(a&2&&(a|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),a|=this.updateForViewport()),(a&2||M)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,n=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new gi(s.lineAt(o-i*1e3,$.ByHeight,n,0,0).from,s.lineAt(l+(1-i)*1e3,$.ByHeight,n,0,0).to);if(e){let{head:a}=e.range;if(a<h.from||a>h.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=s.lineAt(a,$.ByPos,n,0,0),u;e.y=="center"?u=(c.top+c.bottom)/2-f/2:e.y=="start"||e.y=="nearest"&&a<h.from?u=c.top:u=c.bottom-f,h=new gi(s.lineAt(u-1e3/2,$.ByHeight,n,0,0).from,s.lineAt(u+f+1e3/2,$.ByHeight,n,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new gi(this.heightMap.lineAt(i,$.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,$.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),{bottom:n}=this.heightMap.lineAt(e,$.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||n>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&n<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new rs(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,n=s>>1,o=s<<1;if(this.defaultTextDirection!=tt.LTR&&!i)return[];let l=[],h=(f,c,u,d)=>{if(c-f<n)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let b of g)if(b>f&&b<c){h(f,b-10,u,d),h(b+10,c,u,d);return}let m=pa(t,b=>b.from>=u.from&&b.to<=u.to&&Math.abs(b.from-f)<n&&Math.abs(b.to-c)<n&&!g.some(A=>b.from<A&&b.to>A));if(!m){if(c<u.to&&e&&i&&e.visibleRanges.some(M=>M.from<=c&&M.to>=c)){let M=e.moveToLineBoundary(k.cursor(c),!1,!0).head;M>f&&(c=M)}let b=this.gapSize(u,f,c,d),A=i||b<2e6?b:2e6;m=new rs(f,c,b,A)}l.push(m)},a=f=>{if(f.length<o||f.type!=bt.Text)return;let c=da(f.from,f.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,b;if(u!=null){let A=bi(c,u),M=((this.visibleBottom-this.visibleTop)/2+g)/f.height;m=A-M,b=A+M}else m=(this.visibleTop-f.top-g)/f.height,b=(this.visibleBottom-f.top+g)/f.height;d=mi(c,m),p=mi(c,b)}else{let g=c.total*this.heightOracle.charWidth,m=s*this.heightOracle.charWidth,b=0;if(g>2e6)for(let P of t)P.from>=f.from&&P.from<f.to&&P.size!=P.displaySize&&P.from*this.heightOracle.charWidth+b<this.pixelViewport.left&&(b=P.size-P.displaySize);let A=this.pixelViewport.left+b,M=this.pixelViewport.right+b,E,O;if(u!=null){let P=bi(c,u),C=((M-A)/2+m)/g;E=P-C,O=P+C}else E=(A-m)/g,O=(M+m)/g;d=mi(c,E),p=mi(c,O)}d>f.from&&h(f.from,d,f,c),p<f.to&&h(p,f.to,f,c)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(a):a(f);return l}gapSize(t,e,i,s){let n=bi(s,i)-bi(s,e);return this.heightOracle.lineWrapping?t.height*n:s.total*this.heightOracle.charWidth*n}updateLineGaps(t){rs.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=K.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];z.spans(e,this.viewport.from,this.viewport.to,{span(n,o){i.push({from:n,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let n=0;n<i.length&&!(s&8);n++){let o=this.visibleRanges[n],l=i[n];(o.from!=l.from||o.to!=l.to)&&(s|=4,t&&t.mapPos(o.from,-1)==l.from&&t.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Ee(this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Ee(this.heightMap.lineAt(this.scaler.fromDOM(t),$.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Ee(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class gi{constructor(t,e){this.from=t,this.to=e}}function da(r,t,e){let i=[],s=r,n=0;return z.spans(e,r,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),n+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),n+=t-s),{total:n,ranges:i}}function mi({total:r,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(r*e);for(let s=0;;s++){let{from:n,to:o}=t[s],l=o-n;if(i<=l)return n+i;i-=l}}function bi(r,t){let e=0;for(let{from:i,to:s}of r.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/r.total}function pa(r,t){for(let e of r)if(t(e))return e}const rr={toDOM(r){return r},fromDOM(r){return r},scale:1,eq(r){return r==this}};function or(r){let t=r.facet(zi).filter(i=>typeof i!="function"),e=r.facet(rn).filter(i=>typeof i!="function");return e.length&&t.push(z.join(e)),t}class hn{constructor(t,e,i){let s=0,n=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=e.lineAt(l,$.ByPos,t,0,0).top,f=e.lineAt(h,$.ByPos,t,0,0).bottom;return s+=f-a,{from:l,to:h,top:a,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=o+(l.top-n)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),n=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let n=e<this.viewports.length?this.viewports[e]:null;if(!n||t<n.top)return s+(t-i)*this.scale;if(t<=n.bottom)return n.domTop+(t-n.top);i=n.bottom,s=n.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let n=e<this.viewports.length?this.viewports[e]:null;if(!n||t<n.domTop)return i+(t-s)/this.scale;if(t<=n.domBottom)return n.top+(t-n.domTop);i=n.bottom,s=n.domBottom}}eq(t){return t instanceof hn?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Ee(r,t){if(t.scale==1)return r;let e=t.toDOM(r.top),i=t.toDOM(r.bottom);return new yt(r.from,r.length,e,i-e,Array.isArray(r._content)?r._content.map(s=>Ee(s,t)):r._content)}const xi=D.define({combine:r=>r.join(" ")}),Vs=D.define({combine:r=>r.indexOf(!0)>-1}),zs=Kt.newName(),Eo=Kt.newName(),No=Kt.newName(),Io={"&light":"."+Eo,"&dark":"."+No};function qs(r,t,e){return new Kt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return r;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):r+" "+i}})}const ga=qs("."+zs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,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"}},Io),ma={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},os=v.ie&&v.ie_version<=11;class ba{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new Kl,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(v.ie&&v.ie_version<=11||v.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&v.android&&t.constructor.EDIT_CONTEXT!==!1&&!(v.chrome&&v.chrome_version<126)&&(this.editContext=new ya(t),t.state.facet(Nt)&&(t.contentDOM.editContext=this.editContext.editContext)),os&&(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),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{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()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(Nt)?i.root.activeElement!=this.dom:!We(this.dom,s))return;let n=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(n&&n.isWidget()&&n.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(v.ie&&v.ie_version<=11||v.android&&v.chrome)&&!i.state.selection.main.empty&&s.focusNode&&He(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ye(t.root);if(!e)return!1;let i=v.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&xa(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=We(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&Gl(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,ma),os&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),os&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let n=this.delayedAndroidKey;n&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=n.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&n.force&&ge(this.dom,n.key,n.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let n of t){let o=this.readMutation(n);o&&(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&We(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let n=new Ih(this.view,t,e,i);return this.view.docView.domChanged={newSel:n.newSel?n.newSel.main:null},n}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=vo(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Ii(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=lr(e,t.previousSibling||t.target.previousSibling,-1),s=lr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Nt)!=t.state.facet(Nt)&&(t.view.contentDOM.editContext=t.state.facet(Nt)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function lr(r,t,e){for(;t;){let i=Z.get(t);if(i&&i.parent==r)return i;let s=t.parentNode;t=s!=r.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function hr(r,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,n=t.endOffset,o=r.docView.domAtPos(r.state.selection.main.anchor,1);return He(o.node,o.offset,s,n)&&([e,i,s,n]=[s,n,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:n}}function xa(r,t){if(t.getComposedRanges){let s=t.getComposedRanges(r.root)[0];if(s)return hr(r,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return r.contentDOM.addEventListener("beforeinput",i,!0),r.dom.ownerDocument.execCommand("indent"),r.contentDOM.removeEventListener("beforeinput",i,!0),e?hr(r,e):null}class ya{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:n,head:o}=s,l=this.toEditorPos(i.updateRangeStart),h=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let a=h-l>i.text.length;l==this.from&&n<this.from?l=n:h==this.to&&n>this.to&&(h=n);let f=Co(t.state.sliceDoc(l,h),i.text,(a?s.from:s.to)-l,a?"end":null);if(!f){let u=k.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Ii(u,s)||t.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:W.of(i.text.slice(f.from,f.toB).split(`
|
|
10
|
+
`))};if((v.mac||v.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:h,insert:W.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!t.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);on(t,c,k.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),c.from<c.to&&!c.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],n=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let h=t.coordsForChar(o);n=h&&new DOMRect(h.left,h.top,h.right-h.left,h.bottom-h.top)||n||new DOMRect,s.push(n)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let n of i.getTextFormats()){let o=n.underlineStyle,l=n.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let h=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);if(h<a){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(K.mark({attributes:{style:f}}).range(h,a))}}}t.dispatch({effects:co.of(K.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=ye(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((n,o,l,h,a)=>{if(i)return;let f=a.length-(o-n);if(s&&o>=s.to)if(s.from==n&&s.to==o&&s.insert.eq(a)){s=this.pendingContextChange=null,e+=f,this.to+=f;return}else s=null,this.revertPending(t.state);if(n+=e,o+=e,o<=this.from)this.from+=f,this.to+=f;else if(n<this.to){if(n<this.from||o>this.to||this.to-this.from+a.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(n),this.toContextPos(o),a.toString()),this.to+=f}e+=f}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class B{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(n=>i(n,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Ql(t.parent)||document,this.viewState=new nr(t.state||V.create(t)),t.scrollTo&&t.scrollTo.is(ui)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(fe).map(s=>new ts(s));for(let s of this.plugins)s.update(this);this.observer=new ba(this),this.inputState=new Hh(this),this.inputState.ensureHandlers(this.plugins),this.docView=new $n(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=!0,this.requestMeasure()})}dispatch(...t){let e=t.length==1&&t[0]instanceof rt?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,n=this.state;for(let u of t){if(u.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=u.state}if(this.destroyed){this.viewState.state=n;return}let o=this.hasFocus,l=0,h=null;t.some(u=>u.annotation(Po))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=Do(n,o),h||(l=1));let a=this.observer.delayedAndroidKey,f=null;if(a?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(f=null)):this.observer.clear(),n.facet(V.phrases)!=this.state.facet(V.phrases))return this.setState(n);s=Ri.create(this,n,t),s.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new me(d.empty?d:k.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(ui)&&(c=d.value.clip(this.state))}this.viewState.update(s,c),this.bidiCache=Wi.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Be)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(xi)!=s.state.facet(xi)&&(this.viewState.mustMeasureContent=!0),(e||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(Ls))try{u(s)}catch(d){Bt(this.state,d,"update listener")}(h||f)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),f&&!vo(this,f)&&a.force&&ge(this.contentDOM,a.key,a.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new nr(t),this.plugins=t.facet(fe).map(i=>new ts(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new $n(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(fe),i=t.state.facet(fe);if(e!=i){let s=[];for(let n of i){let o=e.indexOf(n);if(o<0)s.push(new ts(n));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let n of this.plugins)n.mustUpdate!=t&&n.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Bt(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:n,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(_r(i))n=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);n=d.from,o=d.top}this.updateState=1;let h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let a=[];h&4||([this.measureRequests,a]=[a,this.measureRequests]);let f=a.map(d=>{try{return d.read(this)}catch(p){return Bt(this.state,p),ar}}),c=Ri.create(this,this.state,[]),u=!1;c.flags|=h,e?e.flags|=h:e=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<a.length;d++)if(f[d]!=ar)try{let p=a[d];p.write&&p.write(f[d],this)}catch(p){Bt(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(n<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(n).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Ls))l(e)}get themeClasses(){return zs+" "+(this.state.facet(Vs)?No:Eo)+" "+this.state.facet(xi)}updateAttrs(){let t=fr(this,uo,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Nt)?"true":"false",class:"cm-content",style:`${v.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),fr(this,nn,e);let i=this.observer.ignore(()=>{let s=Fn(this.contentDOM,this.contentAttrs,e),n=Fn(this.dom,this.editorAttrs,t);return s||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(B.announce)){e&&(this.announceDOM.textContent=""),e=!1;let n=this.announceDOM.appendChild(document.createElement("div"));n.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Be);let t=this.state.facet(B.cspNonce);Kt.mount(this.root,this.styleModules.concat(ga).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return ns(this,t,Kn(this,t,e,i))}moveByGroup(t,e){return ns(this,t,Kn(this,t,e,i=>Dh(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),n=i[e?i.length-1:0];return k.cursor(n.side(e,s)+t.from,n.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return Ph(this,t,e,i)}moveVertically(t,e,i){return ns(this,t,Bh(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=Fs(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Fs(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),n=this.bidiSpans(s),o=n[Lt.find(n,t-s.from,-1,e)];return Ue(i,o.dir==tt.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(ao)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>wa)return eo(t.length);let e=this.textDirectionAt(t.from),i;for(let n of this.bidiCache)if(n.from==t.from&&n.dir==e&&(n.fresh||to(n.isolates,i=zn(this,t))))return n.order;i||(i=zn(this,t));let s=th(t.text,e,i);return this.bidiCache.push(new Wi(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||v.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ur(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return ui.of(new me(typeof t=="number"?k.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return ui.of(new me(k.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return Gt.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return Gt.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Kt.newName(),s=[xi.of(i),Be.of(qs(`.${i}`,t))];return e&&e.dark&&s.push(Vs.of(!0)),s}static baseTheme(t){return Nr.lowest(Be.of(qs("."+zs,t,Io)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Z.get(i)||Z.get(t);return((e=s?.root)===null||e===void 0?void 0:e.view)||null}}B.styleModule=Be;B.inputHandler=lo;B.clipboardInputFilter=en;B.clipboardOutputFilter=sn;B.scrollHandler=fo;B.focusChangeEffect=ho;B.perLineTextDirection=ao;B.exceptionSink=oo;B.updateListener=Ls;B.editable=Nt;B.mouseSelectionStyle=ro;B.dragMovesSelection=no;B.clickAddsSelectionRange=so;B.decorations=zi;B.blockWrappers=po;B.outerDecorations=rn;B.atomicRanges=ti;B.bidiIsolatedRanges=go;B.scrollMargins=mo;B.darkTheme=Vs;B.cspNonce=D.define({combine:r=>r.length?r[0]:""});B.contentAttributes=nn;B.editorAttributes=uo;B.lineWrapping=B.contentAttributes.of({class:"cm-lineWrapping"});B.announce=X.define();const wa=4096,ar={};class Wi{constructor(t,e,i,s,n,o){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=n,this.order=o}static update(t,e){if(e.empty&&!t.some(n=>n.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:tt.LTR;for(let n=Math.max(0,t.length-10);n<t.length;n++){let o=t[n];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new Wi(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function fr(r,t,e){for(let i=r.state.facet(t),s=i.length-1;s>=0;s--){let n=i[s],o=typeof n=="function"?n(r):n;o&&Xs(o,e)}return e}class ka extends Ye{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?Fe(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Ue(e[0],i.direction!="rtl"),n=parseInt(i.lineHeight);return s.bottom-s.top>n*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+n}:s}ignoreEvent(){return!1}}function cr(r){let t=Gt.fromClass(class{constructor(e){this.view=e,this.placeholder=r?K.set([K.widget({widget:new ka(r),side:1}).range(0)]):K.none}get decorations(){return this.view.state.doc.length?K.none:this.placeholder}},{decorations:e=>e.decorations});return typeof r=="string"?[t,B.contentAttributes.of({"aria-placeholder":r})]:t}class ve extends ne{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}ve.prototype.elementClass="";ve.prototype.toDOM=void 0;ve.prototype.mapMode=ct.TrackBefore;ve.prototype.startSide=ve.prototype.endSide=-1;ve.prototype.point=!0;var ls;const ce=new L;function Sa(r){return D.define({combine:r?t=>t.concat(r):void 0})}const va=new L;class St{constructor(t,e,i=[],s=""){this.data=t,this.name=s,V.prototype.hasOwnProperty("tree")||Object.defineProperty(V.prototype,"tree",{get(){return Je(this)}}),this.parser=e,this.extension=[Ae.of(this),V.languageData.of((n,o,l)=>{let h=ur(n,o,l),a=h.type.prop(ce);if(!a)return[];let f=n.facet(a),c=h.type.prop(va);if(c){let u=h.resolve(o-h.from,l);for(let d of c)if(d.test(u,n)){let p=n.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(t,e,i=-1){return ur(t,e,i).type.prop(ce)==this.data}findRegions(t){let e=t.facet(Ae);if(e?.data==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(n,o)=>{if(n.prop(ce)==this.data){i.push({from:o,to:o+n.length});return}let l=n.prop(L.mounted);if(l){if(l.tree.prop(ce)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+n.length});return}else if(l.overlay){let h=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<n.children.length;h++){let a=n.children[h];a instanceof Y&&s(a,n.positions[h]+o)}};return s(Je(t),0),i}get allowsNesting(){return!0}}St.setState=X.define();function ur(r,t,e){let i=r.facet(Ae),s=Je(r).topNode;if(!i||i.allowsNesting)for(let n=s;n;n=n.enter(t,e,_.ExcludeBuffers|_.EnterBracketed))n.type.isTop&&(s=n);return s}class Fi extends St{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=Sa(t.languageData);return new Fi(e,t.parser.configure({props:[ce.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new Fi(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Je(r){let t=r.field(St.state,!1);return t?t.tree:Y.empty}class Ca{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let De=null;class Hi{constructor(t,e,i=[],s,n,o,l,h){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=n,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Hi(t,e,[],Y.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Ca(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=Y.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(ie.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(ie.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=De;De=this;try{return t()}finally{De=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=dr(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:n,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let h=[];if(t.iterChangedRanges((a,f,c,u)=>h.push({fromA:a,toA:f,fromB:c,toB:u})),i=ie.applyChanges(i,h),s=Y.empty,n=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let a of this.skipped){let f=t.mapPos(a.from,1),c=t.mapPos(a.to,-1);f<c&&l.push({from:f,to:c})}}}return new Hi(this.parser,e,i,s,n,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:n}=this.skipped[i];s<t.to&&n>t.from&&(this.fragments=dr(this.fragments,s,n),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Sr{createParse(e,i,s){let n=s[0].from,o=s[s.length-1].to;return{parsedPos:n,advance(){let h=De;if(h){for(let a of s)h.tempSkipped.push(a);t&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,t]):t)}return this.parsedPos=o,new Y(ht.none,[],[],o-n)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return De}}function dr(r,t,e){return ie.applyChanges(r,[{fromA:t,toA:e,fromB:t,toB:e}])}class Ce{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ce(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Hi.create(t.facet(Ae).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ce(i)}}St.state=Ut.define({create:Ce.init,update(r,t){for(let e of t.effects)if(e.is(St.setState))return e.value;return t.startState.facet(Ae)!=t.state.facet(Ae)?Ce.init(t.state):r.apply(t)}});let Lo=r=>{let t=setTimeout(()=>r(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Lo=r=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(r,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const hs=typeof navigator<"u"&&(!((ls=navigator.scheduling)===null||ls===void 0)&&ls.isInputPending)?()=>navigator.scheduling.isInputPending():null,Aa=Gt.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(St.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(St.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=Lo(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,n=i.field(St.state);if(n.tree==n.context.tree&&n.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!hs?Math.max(25,t.timeRemaining()-5):1e9),l=n.context.treeLen<s&&i.doc.length>s+1e3,h=n.context.work(()=>hs&&hs()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-e,(h||this.chunkBudget<=0)&&(n.context.takeTree(),this.view.dispatch({effects:St.setState.of(new Ce(n.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(n.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Bt(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ae=D.define({combine(r){return r.length?r[0]:null},enables:r=>[St.state,Aa,B.contentAttributes.compute([r],t=>{let e=t.facet(r);return e&&e.name?{"data-language":e.name}:{}})]});class Oa{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Ma=new L;function pr({except:r,units:t=1}={}){return e=>{let i=r&&r.test(e.textAfter);return e.baseIndent+(i?0:t*e.unit)}}const Ta=new L;function Pa(r){let t=r.firstChild,e=r.lastChild;return t&&t.to<e.from?{from:t.to,to:e.type.isError?r.to:e.from}:null}class Ki{constructor(t,e){this.specs=t;let i;function s(l){let h=Kt.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const n=typeof e.all=="string"?e.all:e.all?s(e.all):void 0,o=e.scope;this.scope=o instanceof St?l=>l.prop(ce)==o.data:o?l=>l==o:void 0,this.style=Ar(t.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:n}).style,this.module=i?new Kt(i):null,this.themeType=e.themeType}static define(t,e){return new Ki(t,e||{})}}const js=D.define(),Wo=D.define({combine(r){return r.length?[r[0]]:null}});function as(r){let t=r.facet(js);return t.length?t:r.facet(Wo)}function Da(r,t){let e=[Ra],i;return r instanceof Ki&&(r.module&&e.push(B.styleModule.of(r.module)),i=r.themeType),t?.fallback?e.push(Wo.of(r)):i?e.push(js.computeN([B.darkTheme],s=>s.facet(B.darkTheme)==(i=="dark")?[r]:[])):e.push(js.of(r)),e}class Ba{constructor(t){this.markCache=Object.create(null),this.tree=Je(t.state),this.decorations=this.buildDeco(t,as(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Je(t.state),i=as(t.state),s=i!=as(t.startState),{viewport:n}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<n.to&&!s&&e.type==this.tree.type&&o>=n.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=n.to)}buildDeco(t,e){if(!e||!this.tree.length)return K.none;let i=new Ke;for(let{from:s,to:n}of t.visibleRanges)pl(this.tree,e,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=K.mark({class:h})))},s,n);return i.finish()}}const Ra=Nr.high(Gt.fromClass(Ba,{decorations:r=>r.decorations})),Ea=Ki.define([{tag:x.meta,color:"#404740"},{tag:x.link,textDecoration:"underline"},{tag:x.heading,textDecoration:"underline",fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strong,fontWeight:"bold"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.keyword,color:"#708"},{tag:[x.atom,x.bool,x.url,x.contentSeparator,x.labelName],color:"#219"},{tag:[x.literal,x.inserted],color:"#164"},{tag:[x.string,x.deleted],color:"#a11"},{tag:[x.regexp,x.escape,x.special(x.string)],color:"#e40"},{tag:x.definition(x.variableName),color:"#00f"},{tag:x.local(x.variableName),color:"#30a"},{tag:[x.typeName,x.namespace],color:"#085"},{tag:x.className,color:"#167"},{tag:[x.special(x.variableName),x.macroName],color:"#256"},{tag:x.definition(x.propertyName),color:"#00c"},{tag:x.comment,color:"#940"},{tag:x.invalid,color:"#f00"}]),Na=Object.create(null),gr=[ht.none],mr=[],br=Object.create(null),Ia=Object.create(null);for(let[r,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Ia[r]=La(Na,t);function fs(r,t){mr.indexOf(r)>-1||(mr.push(r),console.warn(t))}function La(r,t){let e=[];for(let l of t.split(" ")){let h=[];for(let a of l.split(".")){let f=r[a]||x[a];f?typeof f=="function"?h.length?h=h.map(f):fs(a,`Modifier ${a} used at start of tag`):h.length?fs(a,`Tag ${a} used as modifier`):h=Array.isArray(f)?f:[f]:fs(a,`Unknown highlighting tag ${a}`)}for(let a of h)e.push(a)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),s=i+" "+e.map(l=>l.id),n=br[s];if(n)return n.id;let o=br[s]=ht.define({id:gr.length,name:i,props:[vr({[i]:e})]});return gr.push(o),o.id}tt.RTL,tt.LTR;const Wa=Fi.define({name:"json",parser:xl.configure({props:[Ma.add({Object:pr({except:/^\s*\}/}),Array:pr({except:/^\s*\]/})}),Ta.add({"Object Array":Pa})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Fa(){return new Oa(Wa)}const Ha={key:0,class:"flex items-center border-b px-2 py-1 border-pg-border bg-pg-surface-soft"},Va=Fo({inheritAttrs:!1,__name:"UiCodeEditor",props:{modelValue:{},placeholder:{default:""},rows:{default:4},language:{default:"text"},disabled:{type:Boolean,default:!1},showJsonFormat:{type:Boolean,default:!0},formatLabel:{default:"Format JSON"}},emits:["update:modelValue"],setup(r,{emit:t}){const e=r,i=t,s=Ho(),n=ii(null),o=ii(null),l=ii(!1),h=ii(null),a=new se,f=new se,c=new se,u=X.define(),d=Ut.define({create(){return K.none},update(y,S){for(const I of S.effects)if(I.is(u)){const H=I.value;if(H===null)return K.none;const Q=Math.min(Math.max(H,0),Math.max(S.state.doc.length-1,0)),U=S.state.doc.lineAt(Q);return K.set([K.line({class:"pg-cm-error-line"}).range(U.from)])}return y.map(S.changes)},provide:y=>B.decorations.from(y)}),p=Jt(()=>e.language==="json"),g=Jt(()=>p.value&&e.showJsonFormat&&!e.disabled),m=Jt(()=>!!h.value&&p.value),b=Jt(()=>{const y=h.value;return y?typeof y.line=="number"&&typeof y.column=="number"?`${y.message} (Ln ${y.line}, Col ${y.column})`:y.message:""}),A=Jt(()=>Qo("flex flex-col overflow-hidden rounded border border-pg-border bg-pg-surface-strong text-pg-text transition focus-within:border-pg-accent",m.value?"border-pg-danger-border":"",e.disabled?"cursor-not-allowed opacity-80":"",s.class)),M=Jt(()=>({minHeight:`${(Math.max(2,e.rows)*1.45+1.2).toFixed(2)}rem`,...s.style})),E=Jt(()=>{const{class:y,style:S,...I}=s;return I});function O(y){return y==="json"?Fa():[]}function P(y,S){if(y<=0)return{from:0,to:0};const I=Math.max(0,Math.min(S,y-1)),H=I,Q=Math.min(I+1,y);return{from:H,to:Q}}function C(y,S){let I=1,H=1;const Q=Math.max(0,Math.min(S,y.length));for(let U=0;U<Q;U+=1)y[U]===`
|
|
11
|
+
`?(I+=1,H=1):H+=1;return{line:I,column:H}}function G(y,S){const I=y.match(/position\s+(\d+)/i);if(I){const H=Number(I[1]);if(Number.isFinite(H))return Math.max(0,H)}return/end of json input/i.test(y)?Math.max(S.length-1,0):null}function F(y,S){const I=S instanceof Error?S.message:String(S),H=G(I,y);if(H===null)return{message:I,index:null,line:null,column:null};const{line:Q,column:U}=C(y,H);return{message:I,index:H,line:Q,column:U}}function N(y){const S=o.value;S&&S.dispatch({effects:u.of(y)})}function R(y,S={}){if(!p.value||!y.trim())return h.value=null,N(null),!0;try{return JSON.parse(y),h.value=null,N(null),!0}catch(H){const Q=F(y,H);if(h.value=Q,N(Q.index),S.focusError&&typeof Q.index=="number"){const U=o.value;if(U){const he=P(U.state.doc.length,Q.index);U.dispatch({selection:k.range(he.from,he.to),effects:B.scrollIntoView(he.from,{y:"center"})})}}return!1}}function T(){if(!g.value)return;const y=o.value;if(!y)return;const S=y.state.doc.toString();if(!S.trim()){h.value=null,N(null);return}try{const H=JSON.parse(S),Q=JSON.stringify(H,null,2),U=y.state.doc.toString();if(Q===U){h.value=null,N(null);return}l.value=!0,y.dispatch({changes:{from:0,to:U.length,insert:Q},selection:k.cursor(Q.length)}),l.value=!1,i("update:modelValue",Q),h.value=null,N(null)}catch(H){const Q=F(S,H);h.value=Q,N(Q.index),R(S,{focusError:!0})}}function j(){return V.create({doc:e.modelValue,extensions:[Da(Ea,{fallback:!0}),d,B.lineWrapping,a.of(O(e.language)),f.of(e.placeholder?cr(e.placeholder):[]),c.of(B.editable.of(!e.disabled)),B.updateListener.of(y=>{if(!y.docChanged||l.value)return;const S=y.state.doc.toString();i("update:modelValue",S),queueMicrotask(()=>R(S))})]})}return Vo(()=>{n.value&&(o.value=new B({state:j(),parent:n.value}),R(e.modelValue))}),si(()=>e.modelValue,y=>{const S=o.value;if(!S)return;const I=S.state.doc.toString();if(I===y)return;l.value=!0;const H=Math.min(S.state.selection.main.anchor,y.length);S.dispatch({changes:{from:0,to:I.length,insert:y},selection:k.cursor(H)}),l.value=!1,R(y)}),si(()=>e.language,y=>{const S=o.value;S&&(S.dispatch({effects:a.reconfigure(O(y))}),R(S.state.doc.toString()))}),si(()=>e.placeholder,y=>{const S=o.value;S&&S.dispatch({effects:f.reconfigure(y?cr(y):[])})}),si(()=>e.disabled,y=>{const S=o.value;S&&S.dispatch({effects:c.reconfigure(B.editable.of(!y))})}),zo(()=>{o.value?.destroy(),o.value=null}),(y,S)=>(cn(),fn("div",Ko(E.value,{class:A.value,style:M.value}),[g.value?(cn(),fn("div",Ha,[Qi("button",{class:"rounded border px-2 py-1 text-[0.62rem] font-medium uppercase tracking-[0.16em] transition border-pg-border bg-pg-surface-card text-pg-text-muted hover:text-pg-text-soft",type:"button",onClick:T},un(e.formatLabel),1)])):qo("",!0),Qi("div",{ref_key:"host",ref:n,class:"min-h-0 flex-1"},null,512),jo(Qi("div",{class:"border-t px-2 py-1 text-[0.68rem] border-pg-danger-border bg-pg-danger-bg text-pg-danger-text","aria-live":"polite"},un(b.value),513),[[$o,m.value]])],16))}}),za=(r,t)=>{const e=r.__vccOpts||r;for(const[i,s]of t)e[i]=s;return e},Qa=za(Va,[["__scopeId","data-v-8c8f1e2e"]]);export{Qa as default};
|