var Gy=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function pf(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function Yy(n){if(Object.prototype.hasOwnProperty.call(n,"__esModule"))return n;var e=n.default;if(typeof e=="function"){var t=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(i){var s=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return n[i]}})}),t}var ws={exports:{}},ui={};/**
 * @license React
 * react-jsx-runtime.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Oo;function mf(){if(Oo)return ui;Oo=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(i,s,r){var o=null;if(r!==void 0&&(o=""+r),s.key!==void 0&&(o=""+s.key),"key"in s){r={};for(var l in s)l!=="key"&&(r[l]=s[l])}else r=s;return s=r.ref,{$$typeof:n,type:i,key:o,ref:s!==void 0?s:null,props:r}}return ui.Fragment=e,ui.jsx=t,ui.jsxs=t,ui}var Do;function gf(){return Do||(Do=1,ws.exports=mf()),ws.exports}var yf=gf(),vs={exports:{}},V={};/**
 * @license React
 * react.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Eo;function bf(){if(Eo)return V;Eo=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),r=Symbol.for("react.consumer"),o=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),a=Symbol.for("react.suspense"),h=Symbol.for("react.memo"),c=Symbol.for("react.lazy"),f=Symbol.for("react.activity"),u=Symbol.iterator;function d(g){return g===null||typeof g!="object"?null:(g=u&&g[u]||g["@@iterator"],typeof g=="function"?g:null)}var p={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},m=Object.assign,y={};function b(g,k,I){this.props=g,this.context=k,this.refs=y,this.updater=I||p}b.prototype.isReactComponent={},b.prototype.setState=function(g,k){if(typeof g!="object"&&typeof g!="function"&&g!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,g,k,"setState")},b.prototype.forceUpdate=function(g){this.updater.enqueueForceUpdate(this,g,"forceUpdate")};function A(){}A.prototype=b.prototype;function S(g,k,I){this.props=g,this.context=k,this.refs=y,this.updater=I||p}var O=S.prototype=new A;O.constructor=S,m(O,b.prototype),O.isPureReactComponent=!0;var C=Array.isArray;function M(){}var v={H:null,A:null,T:null,S:null},W=Object.prototype.hasOwnProperty;function R(g,k,I){var N=I.ref;return{$$typeof:n,type:g,key:k,ref:N!==void 0?N:null,props:I}}function _(g,k){return R(g.type,k,g.props)}function H(g){return typeof g=="object"&&g!==null&&g.$$typeof===n}function L(g){var k={"=":"=0",":":"=2"};return"$"+g.replace(/[=:]/g,function(I){return k[I]})}var F=/\/+/g;function z(g,k){return typeof g=="object"&&g!==null&&g.key!=null?L(""+g.key):k.toString(36)}function Y(g){switch(g.status){case"fulfilled":return g.value;case"rejected":throw g.reason;default:switch(typeof g.status=="string"?g.then(M,M):(g.status="pending",g.then(function(k){g.status==="pending"&&(g.status="fulfilled",g.value=k)},function(k){g.status==="pending"&&(g.status="rejected",g.reason=k)})),g.status){case"fulfilled":return g.value;case"rejected":throw g.reason}}throw g}function ie(g,k,I,N,$){var G=typeof g;(G==="undefined"||G==="boolean")&&(g=null);var Q=!1;if(g===null)Q=!0;else switch(G){case"bigint":case"string":case"number":Q=!0;break;case"object":switch(g.$$typeof){case n:case e:Q=!0;break;case c:return Q=g._init,ie(Q(g._payload),k,I,N,$)}}if(Q)return $=$(g),Q=N===""?"."+z(g,0):N,C($)?(I="",Q!=null&&(I=Q.replace(F,"$&/")+"/"),ie($,k,I,"",function(df){return df})):$!=null&&(H($)&&($=_($,I+($.key==null||g&&g.key===$.key?"":(""+$.key).replace(F,"$&/")+"/")+Q)),k.push($)),1;Q=0;var Xe=N===""?".":N+":";if(C(g))for(var Oe=0;Oe<g.length;Oe++)N=g[Oe],G=Xe+z(N,Oe),Q+=ie(N,k,I,G,$);else if(Oe=d(g),typeof Oe=="function")for(g=Oe.call(g),Oe=0;!(N=g.next()).done;)N=N.value,G=Xe+z(N,Oe++),Q+=ie(N,k,I,G,$);else if(G==="object"){if(typeof g.then=="function")return ie(Y(g),k,I,N,$);throw k=String(g),Error("Objects are not valid as a React child (found: "+(k==="[object Object]"?"object with keys {"+Object.keys(g).join(", ")+"}":k)+"). If you meant to render a collection of children, use an array instead.")}return Q}function re(g,k,I){if(g==null)return g;var N=[],$=0;return ie(g,N,"","",function(G){return k.call(I,G,$++)}),N}function pe(g){if(g._status===-1){var k=g._result;k=k(),k.then(function(I){(g._status===0||g._status===-1)&&(g._status=1,g._result=I)},function(I){(g._status===0||g._status===-1)&&(g._status=2,g._result=I)}),g._status===-1&&(g._status=0,g._result=k)}if(g._status===1)return g._result.default;throw g._result}var X=typeof reportError=="function"?reportError:function(g){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var k=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof g=="object"&&g!==null&&typeof g.message=="string"?String(g.message):String(g),error:g});if(!window.dispatchEvent(k))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",g);return}console.error(g)},oe={map:re,forEach:function(g,k,I){re(g,function(){k.apply(this,arguments)},I)},count:function(g){var k=0;return re(g,function(){k++}),k},toArray:function(g){return re(g,function(k){return k})||[]},only:function(g){if(!H(g))throw Error("React.Children.only expected to receive a single React element child.");return g}};return V.Activity=f,V.Children=oe,V.Component=b,V.Fragment=t,V.Profiler=s,V.PureComponent=S,V.StrictMode=i,V.Suspense=a,V.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=v,V.__COMPILER_RUNTIME={__proto__:null,c:function(g){return v.H.useMemoCache(g)}},V.cache=function(g){return function(){return g.apply(null,arguments)}},V.cacheSignal=function(){return null},V.cloneElement=function(g,k,I){if(g==null)throw Error("The argument must be a React element, but you passed "+g+".");var N=m({},g.props),$=g.key;if(k!=null)for(G in k.key!==void 0&&($=""+k.key),k)!W.call(k,G)||G==="key"||G==="__self"||G==="__source"||G==="ref"&&k.ref===void 0||(N[G]=k[G]);var G=arguments.length-2;if(G===1)N.children=I;else if(1<G){for(var Q=Array(G),Xe=0;Xe<G;Xe++)Q[Xe]=arguments[Xe+2];N.children=Q}return R(g.type,$,N)},V.createContext=function(g){return g={$$typeof:o,_currentValue:g,_currentValue2:g,_threadCount:0,Provider:null,Consumer:null},g.Provider=g,g.Consumer={$$typeof:r,_context:g},g},V.createElement=function(g,k,I){var N,$={},G=null;if(k!=null)for(N in k.key!==void 0&&(G=""+k.key),k)W.call(k,N)&&N!=="key"&&N!=="__self"&&N!=="__source"&&($[N]=k[N]);var Q=arguments.length-2;if(Q===1)$.children=I;else if(1<Q){for(var Xe=Array(Q),Oe=0;Oe<Q;Oe++)Xe[Oe]=arguments[Oe+2];$.children=Xe}if(g&&g.defaultProps)for(N in Q=g.defaultProps,Q)$[N]===void 0&&($[N]=Q[N]);return R(g,G,$)},V.createRef=function(){return{current:null}},V.forwardRef=function(g){return{$$typeof:l,render:g}},V.isValidElement=H,V.lazy=function(g){return{$$typeof:c,_payload:{_status:-1,_result:g},_init:pe}},V.memo=function(g,k){return{$$typeof:h,type:g,compare:k===void 0?null:k}},V.startTransition=function(g){var k=v.T,I={};v.T=I;try{var N=g(),$=v.S;$!==null&&$(I,N),typeof N=="object"&&N!==null&&typeof N.then=="function"&&N.then(M,X)}catch(G){X(G)}finally{k!==null&&I.types!==null&&(k.types=I.types),v.T=k}},V.unstable_useCacheRefresh=function(){return v.H.useCacheRefresh()},V.use=function(g){return v.H.use(g)},V.useActionState=function(g,k,I){return v.H.useActionState(g,k,I)},V.useCallback=function(g,k){return v.H.useCallback(g,k)},V.useContext=function(g){return v.H.useContext(g)},V.useDebugValue=function(){},V.useDeferredValue=function(g,k){return v.H.useDeferredValue(g,k)},V.useEffect=function(g,k){return v.H.useEffect(g,k)},V.useEffectEvent=function(g){return v.H.useEffectEvent(g)},V.useId=function(){return v.H.useId()},V.useImperativeHandle=function(g,k,I){return v.H.useImperativeHandle(g,k,I)},V.useInsertionEffect=function(g,k){return v.H.useInsertionEffect(g,k)},V.useLayoutEffect=function(g,k){return v.H.useLayoutEffect(g,k)},V.useMemo=function(g,k){return v.H.useMemo(g,k)},V.useOptimistic=function(g,k){return v.H.useOptimistic(g,k)},V.useReducer=function(g,k,I){return v.H.useReducer(g,k,I)},V.useRef=function(g){return v.H.useRef(g)},V.useState=function(g){return v.H.useState(g)},V.useSyncExternalStore=function(g,k,I){return v.H.useSyncExternalStore(g,k,I)},V.useTransition=function(){return v.H.useTransition()},V.version="19.2.0",V}var Bo;function xf(){return Bo||(Bo=1,vs.exports=bf()),vs.exports}var ve=xf();const Jy=pf(ve);function Qs(){return Qs=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var i in t)({}).hasOwnProperty.call(t,i)&&(n[i]=t[i])}return n},Qs.apply(null,arguments)}function wf(n,e){if(n==null)return{};var t={};for(var i in n)if({}.hasOwnProperty.call(n,i)){if(e.indexOf(i)!==-1)continue;t[i]=n[i]}return t}let Zs=[],va=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?va:Zs).push(t=t+n[e])})();function vf(n){if(n<768)return!1;for(let e=0,t=Zs.length;;){let i=e+t>>1;if(n<Zs[i])t=i;else if(n>=va[i])e=i+1;else return!0;if(e==t)return!1}}function Ro(n){return n>=127462&&n<=127487}const Lo=8205;function kf(n,e,t=!0,i=!0){return(t?ka:Sf)(n,e,i)}function ka(n,e,t){if(e==n.length)return e;e&&Sa(n.charCodeAt(e))&&Ca(n.charCodeAt(e-1))&&e--;let i=ks(n,e);for(e+=Po(i);e<n.length;){let s=ks(n,e);if(i==Lo||s==Lo||t&&vf(s))e+=Po(s),i=s;else if(Ro(s)){let r=0,o=e-2;for(;o>=0&&Ro(ks(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Sf(n,e,t){for(;e>0;){let i=ka(n,e-2,t);if(i<e)return i;e--}return 0}function ks(n,e){let t=n.charCodeAt(e);if(!Ca(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Sa(i)?(t-55296<<10)+(i-56320)+65536:t}function Sa(n){return n>=56320&&n<57344}function Ca(n){return n>=55296&&n<56320}function Po(n){return n<65536?1:2}class J{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=ti(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),it.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ti(this,e,t);let i=[];return this.decompose(e,t,i,0),it.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new ki(this),r=new ki(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new ki(this,e)}iterRange(e,t=this.length){return new Aa(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Ma(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?J.empty:e.length<=32?new le(e):it.from(le.split(e,[]))}}class le extends J{constructor(e,t=Cf(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new Af(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new le(Io(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=Tn(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new le(l,o.length+r.length));else{let a=l.length>>1;i.push(new le(l.slice(0,a)),new le(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof le))return super.replace(e,t,i);[e,t]=ti(this,e,t);let s=Tn(this.text,Tn(i.text,Io(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new le(s,r):it.from(le.split(s,[]),r)}sliceString(e,t=this.length,i=`
`){[e,t]=ti(this,e,t);let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new le(i,s)),i=[],s=-1);return s>-1&&t.push(new le(i,s)),t}}class it extends J{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=ti(this,e,t),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[s]=a,new it(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
`){[e,t]=ti(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof it))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new le(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof it)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof le&&a&&(p=c[c.length-1])instanceof le&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new le(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:it.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new it(l,t)}}J.empty=new le([""],0);function Cf(n){let e=-1;for(let t of n)e+=t.length+1;return e}function Tn(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function Io(n,e,t){return Tn(n,[""],e,t)}class ki{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof le?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof le?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
`,this;e--}else if(s instanceof le){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof le?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Aa{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ki(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Ma{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(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"&&(J.prototype[Symbol.iterator]=function(){return this.iter()},ki.prototype[Symbol.iterator]=Aa.prototype[Symbol.iterator]=Ma.prototype[Symbol.iterator]=function(){return this});class Af{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}function ti(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function fe(n,e,t=!0,i=!0){return kf(n,e,t,i)}function Mf(n){return n>=56320&&n<57344}function Tf(n){return n>=55296&&n<56320}function De(n,e){let t=n.charCodeAt(e);if(!Tf(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Mf(i)?(t-55296<<10)+(i-56320)+65536:t}function Gr(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function nt(n){return n<65536?1:2}const er=/\r\n?|\n/;var Me=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(Me||(Me={}));class lt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){tr(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new lt(e)}composeDesc(e){return this.empty?e:e.empty?this:Ta(this,e)}mapDesc(e,t=!1){return e.empty?this:ir(this,e,t)}mapPos(e,t=-1,i=Me.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=Me.Simple&&h>=e&&(i==Me.TrackDel&&s<e&&h>e||i==Me.TrackBefore&&s<e||i==Me.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new lt(e)}static create(e){return new lt(e)}}class ce extends lt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return tr(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return ir(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(J.empty);i.push(o?e.slice(r,r+o):J.empty)}r+=o}return new ce(t,i)}compose(e){return this.empty?e:e.empty?this:Ta(this,e,!0)}map(e,t=!1){return e.empty?this:ir(this,e,t,!0)}iterChanges(e,t=!1){tr(this,e,t)}get desc(){return lt.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new Ei(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);ke(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;ke(t,c,f),f>0&&xt(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);ke(t,c,-1),ke(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new ce(t,i),filtered:lt.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&ke(s,t-o,-1);let f=new ce(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof ce){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?J.of(d.split(i||er)):d:J.empty,m=p.length;if(f==u&&m==0)return;f<o&&a(),f>o&&ke(s,f-o,-1),ke(s,u-f,m),xt(r,s,p),o=u}}return h(e),a(!l),l}static empty(e){return new ce(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(J.empty);i[s]=J.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new ce(t,i)}static createSet(e,t){return new ce(e,t)}}function ke(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:s>=0&&e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function xt(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(J.empty);n.push(t)}}function tr(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,f=J.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,f),s=h,r=c}}}function ir(n,e,t,i=!1){let s=[],r=i?[]:null,o=new Ei(n),l=new Ei(e);for(let a=-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 h=Math.min(o.len,l.len);ke(s,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(ke(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(ke(s,0,o.ins),r&&xt(r,s,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;ke(s,h,a<o.i?o.ins:0),r&&a<o.i&&xt(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?ce.createSet(s,r):lt.create(s);throw new Error("Mismatched change set lengths")}}}function Ta(n,e,t=!1){let i=[],s=t?[]:null,r=new Ei(n),o=new Ei(e);for(let l=!1;;){if(r.done&&o.done)return s?ce.createSet(i,s):lt.create(i);if(r.ins==0)ke(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)ke(i,0,o.ins,l),s&&xt(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;ke(i,a,c,l),s&&c&&xt(s,i,o.text)}else o.ins==-1?(ke(i,r.off?0:r.len,a,l),s&&xt(s,i,r.textBit(a))):(ke(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&xt(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class Ei{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[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:e}=this.set,t=this.i-2>>1;return t>=e.length?J.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?J.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class Pt{constructor(e,t,i){this.from=e,this.to=t,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 e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new Pt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return w.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return w.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return w.range(e.anchor,e.head)}static create(e,t,i){return new Pt(e,t,i)}}class w{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:w.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new w([this.main],0)}addRange(e,t=!0){return w.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,w.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new w(e.ranges.map(t=>Pt.fromJSON(t)),e.main)}static single(e,t=e){return new w([w.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return w.normalized(e.slice(),t);i=r.to}return new w(e,t)}static cursor(e,t=0,i,s){return Pt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return t<e?Pt.create(t,e,48|r):Pt.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?w.range(a,l):w.range(l,a))}}return new w(e,t)}}function Oa(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Yr=0;class B{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Yr++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new B(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Jr),!!e.static,e.enables)}of(e){return new On([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new On(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new On(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Jr(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class On{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Yr++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||nr(f,c)){let d=i(f);if(l?!No(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let m=Wn(u,p);if(this.dependencies.every(y=>y instanceof B?u.facet(y)===f.facet(y):y instanceof we?u.field(y,!1)==f.field(y,!1):!0)||(l?No(d=i(f),m,s):s(d=i(f),m)))return f.values[o]=m,0}else d=i(f);return f.values[o]=d,1}}}}function No(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function nr(n,e){let t=!1;for(let i of e)Si(n,i)&1&&(t=!0);return t}function Of(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=Wn(a,i[c]);if(s[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)Si(a,h);return a.values[o]=l(a),1},update(a,h){if(!nr(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=nr(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&Jr(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const sn=B.define({static:!0});class we{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new we(Yr++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(sn).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>{let r=i.facet(sn),o=s.facet(sn),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,sn.of({field:this,create:e})]}get extension(){return this}}const Rt={lowest:4,low:3,default:2,high:1,highest:0};function di(n){return e=>new Da(e,n)}const qt={highest:di(Rt.highest),high:di(Rt.high),default:di(Rt.default),low:di(Rt.low),lowest:di(Rt.lowest)};class Da{constructor(e,t){this.inner=e,this.prec=t}}class rs{of(e){return new sr(this,e)}reconfigure(e){return rs.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class sr{constructor(e,t){this.compartment=e,this.inner=t}}class Nn{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let u of Df(e,t,o))u instanceof we?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of s)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,m=c&&c[u]||[];if(d.every(y=>y.type==0))if(l[p.id]=a.length<<1|1,Jr(m,d))a.push(i.facet(p));else{let y=p.combine(d.map(b=>b.value));a.push(i&&p.compare(y,i.facet(p))?i.facet(p):y)}else{for(let y of d)y.type==0?(l[y.id]=a.length<<1|1,a.push(y.value)):(l[y.id]=h.length<<1,h.push(b=>y.dynamicSlot(b)));l[p.id]=h.length<<1,h.push(y=>Of(y,p,d))}}let f=h.map(u=>u(l));return new Nn(e,o,f,l,a,r)}}function Df(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof sr&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof sr){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof Da)r(o.inner,o.prec);else if(o instanceof we)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof On)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,Rt.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(h,l)}}return r(n,Rt.default),i.reduce((o,l)=>o.concat(l))}function Si(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Wn(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const Ea=B.define(),rr=B.define({combine:n=>n.some(e=>e),static:!0}),Ba=B.define({combine:n=>n.length?n[0]:void 0,static:!0}),Ra=B.define(),La=B.define(),Pa=B.define(),Ia=B.define({combine:n=>n.length?n[0]:!1});class at{constructor(e,t){this.type=e,this.value=t}static define(){return new Ef}}class Ef{of(e){return new at(this,e)}}class Bf{constructor(e){this.map=e}of(e){return new q(this,e)}}class q{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new q(this.type,t)}is(e){return this.type==e}static define(e={}){return new Bf(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}q.reconfigure=q.define();q.appendConfig=q.define();class ue{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Oa(i,t.newLength),r.some(l=>l.type==ue.time)||(this.annotations=r.concat(ue.time.of(Date.now())))}static create(e,t,i,s,r,o){return new ue(e,t,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(ue.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}ue.time=at.define();ue.userEvent=at.define();ue.addToHistory=at.define();ue.remote=at.define();function Rf(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Na(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=ce.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:q.mapEffects(n.effects,s).concat(q.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function or(n,e,t){let i=e.selection,s=Yt(e.annotations);return e.userEvent&&(s=s.concat(ue.userEvent.of(e.userEvent))),{changes:e.changes instanceof ce?e.changes:ce.of(e.changes||[],t,n.facet(Ba)),selection:i&&(i instanceof w?i:w.single(i.anchor,i.head)),effects:Yt(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function Wa(n,e,t){let i=or(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Na(i,or(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=ue.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Pf(t?Lf(s):s)}function Lf(n){let e=n.startState,t=!0;for(let s of e.facet(Ra)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:Rf(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=ce.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=ue.create(e,s,n.selection&&n.selection.map(r),q.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(La);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof ue?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof ue?n=r[0]:n=Wa(e,Yt(r),!1)}return n}function Pf(n){let e=n.startState,t=e.facet(Pa),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=Na(i,or(e,r,n.changes.newLength),!0))}return i==n?n:ue.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const If=[];function Yt(n){return n==null?If:Array.isArray(n)?n:[n]}var se=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(se||(se={}));const Nf=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let lr;try{lr=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Wf(n){if(lr)return lr.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||Nf.test(t)))return!0}return!1}function Hf(n){return e=>{if(!/\S/.test(e))return se.Space;if(Wf(e))return se.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return se.Word;return se.Other}}class K{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Si(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return Si(this,i),Wn(this,i)}update(...e){return Wa(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(rs.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,h)=>s.set(h,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(q.reconfigure)?(t=null,i=l.value):l.is(q.appendConfig)&&(t=null,i=Yt(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=Nn.resolve(i,s,this),r=new K(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(rr)?e.newSelection:e.newSelection.asSingle();new K(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:w.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=Yt(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=s.mapDesc(h,!0);r.push(a.range.map(f)),s=s.compose(c),o=q.mapEffects(o,c).concat(q.mapEffects(Yt(a.effects),f))}return{changes:s,selection:w.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ce?e:ce.of(e,this.doc.length,this.facet(K.lineSeparator))}toText(e){return J.of(e.split(this.facet(K.lineSeparator)||er))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Si(this,t),Wn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof we&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return K.create({doc:e.doc,selection:w.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=Nn.resolve(e.extensions||[],new Map),i=e.doc instanceof J?e.doc:J.of((e.doc||"").split(t.staticFacet(K.lineSeparator)||er)),s=e.selection?e.selection instanceof w?e.selection:w.single(e.selection.anchor,e.selection.head):w.single(0);return Oa(s,i.length),t.staticFacet(rr)||(s=s.asSingle()),new K(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(K.tabSize)}get lineBreak(){return this.facet(K.lineSeparator)||`
`}get readOnly(){return this.facet(Ia)}phrase(e,...t){for(let i of this.facet(K.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(Ea))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return Hf(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=fe(t,o,!1);if(r(t.slice(a,o))!=se.Word)break;o=a}for(;l<s;){let a=fe(t,l);if(r(t.slice(l,a))!=se.Word)break;l=a}return o==l?null:w.range(o+i,l+i)}}K.allowMultipleSelections=rr;K.tabSize=B.define({combine:n=>n.length?n[0]:4});K.lineSeparator=Ba;K.readOnly=Ia;K.phrases=B.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(s=>n[s]==e[s])}});K.languageData=Ea;K.changeFilter=Ra;K.transactionFilter=La;K.transactionExtender=Pa;rs.reconfigure=q.define();function ht(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}class St{eq(e){return this==e}range(e,t=e){return ar.create(e,t,this)}}St.prototype.startSide=St.prototype.endSide=0;St.prototype.point=!1;St.prototype.mapMode=Me.TrackDel;function Xr(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let ar=class Ha{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Ha(e,t,i)}};function hr(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Qr{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,f=this.to[a]+e,u,d;if(c==f){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<u)))continue}else if(u=t.mapPos(c,h.startSide),d=t.mapPos(f,h.endSide),u>d||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),i.push(h),s.push(u-o),r.push(d-o))}return{mapped:i.length?new Qr(s,r,i,l):null,pos:o}}}class j{constructor(e,t,i,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}static create(e,t,i,s){return new j(e,t,i,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(hr)),this.isEmpty)return t.length?j.of(t):this;let l=new Fa(this,null,-1).goto(0),a=0,h=[],c=new dt;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||h.push(ar.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?j.empty:this.nextLayer.update({add:h,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:f}=a.map(l,e);c&&(s=Math.max(s,c.maxPoint),t.push(c),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new j(i,t,r||j.empty,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return Bi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Bi.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=Wo(o,l,i),h=new pi(o,a,r),c=new pi(l,a,r);i.iterGaps((f,u,d)=>Ho(h,f,c,u,d,s)),i.empty&&i.length==0&&Ho(h,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=999999999);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Wo(r,o),a=new pi(r,l,0).goto(i),h=new pi(o,l,0).goto(i);for(;;){if(a.to!=h.to||!cr(a.active,h.active)||a.point&&(!h.point||!Xr(a.point,h.point)))return!1;if(a.to>s)return!0;a.next(),h.next()}}static spans(e,t,i,s,r=-1){let o=new pi(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,a);s.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(s.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new dt;for(let s of e instanceof ar?[e]:t?Ff(e):e)i.add(s.from,s.to,s.value);return i.finish()}static join(e){if(!e.length)return j.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let s=e[i];s!=j.empty;s=s.nextLayer)t=new j(s.chunkPos,s.chunk,t,Math.max(s.maxPoint,t.maxPoint));return t}}j.empty=new j([],[],null,-1);function Ff(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(hr(e,i)>0)return n.slice().sort(hr);e=i}return n}j.empty.nextLayer=j.empty;class dt{finishChunk(e){this.chunks.push(new Qr(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}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(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new dt)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-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=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(j.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=j.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Wo(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}class Fa{constructor(e,t,i,s=0){this.layer=e,this.skip=t,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(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,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)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==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=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Bi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new Fa(o,t,i,r));return s.length==1?s[0]:new Bi(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)Ss(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)Ss(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Ss(this.heap,0)}}}function Ss(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}class pi{constructor(e,t,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=Bi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){rn(this.active,e),rn(this.activeTo,e),rn(this.activeRank,e),this.minActive=Fo(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||s-this.activeTo[t])>0;)t++;on(this.active,t,i),on(this.activeTo,t,s),on(this.activeRank,t,r),e&&on(e,t,this.cursor.from),this.minActive=Fo(this.active,this.activeTo)}next(){let e=this.to,t=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]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&rn(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.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]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function Ho(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e,h=!!r.boundChange;for(let c=!1;;){let f=n.to+a-t.to,u=f||n.endSide-t.endSide,d=u<0?n.to+a:t.to,p=Math.min(d,o);if(n.point||t.point?(n.point&&t.point&&Xr(n.point,t.point)&&cr(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,p,n.point,t.point),c=!1):(c&&r.boundChange(l),p>l&&!cr(n.active,t.active)&&r.compareRange(l,p,n.active,t.active),h&&p<o&&(f||n.openEnd(d)!=t.openEnd(d))&&(c=!0)),d>o)break;l=d,u<=0&&n.next(),u>=0&&t.next()}}function cr(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!Xr(n[t],e[t]))return!1;return!0}function rn(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function on(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function Fo(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}function hi(n,e,t=n.length){let i=0;for(let s=0;s<t&&s<n.length;)n.charCodeAt(s)==9?(i+=e-i%e,s++):(i++,s=fe(n,s));return i}function fr(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=fe(n,s)}return i===!0?-1:n.length}const ur="ͼ",Vo=typeof Symbol>"u"?"__"+ur:Symbol.for(ur),dr=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),zo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Ct{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(y=>m.replace(/&/,y))).reduce((m,y)=>m.concat(y)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((i&&!f&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let e=zo[Vo]||1;return zo[Vo]=e+1,ur+e.toString(36)}static mount(e,t,i){let s=e[dr],r=i&&i.nonce;s?r&&s.setNonce(r):s=new Vf(e,r),s.mount(Array.isArray(t)?t:[t],e)}}let qo=new Map;class Vf{constructor(e,t){let i=e.ownerDocument||e,s=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&s.CSSStyleSheet){let r=qo.get(i);if(r)return e[dr]=r;this.sheet=new s.CSSStyleSheet,qo.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[dr]=this}mount(e,t){let i=this.sheet,s=0,r=0;for(let o=0;o<e.length;o++){let l=e[o],a=this.modules.indexOf(l);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let h=0;h<l.rules.length;h++)i.insertRule(l.rules[h],s++)}else{for(;r<a;)s+=this.modules[r++].rules.length;s+=l.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+`
`;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var At={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:"'"},Ri={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},zf=typeof navigator<"u"&&/Mac/.test(navigator.platform),qf=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ye=0;ye<10;ye++)At[48+ye]=At[96+ye]=String(ye);for(var ye=1;ye<=24;ye++)At[ye+111]="F"+ye;for(var ye=65;ye<=90;ye++)At[ye]=String.fromCharCode(ye+32),Ri[ye]=String.fromCharCode(ye);for(var Cs in At)Ri.hasOwnProperty(Cs)||(Ri[Cs]=At[Cs]);function _f(n){var e=zf&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||qf&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Ri:At)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function Z(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}e++}for(;e<arguments.length;e++)Va(n,arguments[e]);return n}function Va(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)Va(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}let Ae=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},pr=typeof document<"u"?document:{documentElement:{style:{}}};const mr=/Edge\/(\d+)/.exec(Ae.userAgent),za=/MSIE \d/.test(Ae.userAgent),gr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ae.userAgent),os=!!(za||gr||mr),_o=!os&&/gecko\/(\d+)/i.test(Ae.userAgent),As=!os&&/Chrome\/(\d+)/.exec(Ae.userAgent),$f="webkitFontSmoothing"in pr.documentElement.style,yr=!os&&/Apple Computer/.test(Ae.vendor),$o=yr&&(/Mobile\/\w+/.test(Ae.userAgent)||Ae.maxTouchPoints>2);var E={mac:$o||/Mac/.test(Ae.platform),windows:/Win/.test(Ae.platform),linux:/Linux|X11/.test(Ae.platform),ie:os,ie_version:za?pr.documentMode||6:gr?+gr[1]:mr?+mr[1]:0,gecko:_o,gecko_version:_o?+(/Firefox\/(\d+)/.exec(Ae.userAgent)||[0,0])[1]:0,chrome:!!As,chrome_version:As?+As[1]:0,ios:$o,android:/Android\b/.test(Ae.userAgent),webkit_version:$f?+(/\bAppleWebKit\/(\d+)/.exec(Ae.userAgent)||[0,0])[1]:0,safari:yr,safari_version:yr?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Ae.userAgent)||[0,0])[1]:0,tabSize:pr.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Zr(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const Hn=Object.create(null);function eo(n,e,t){if(n==e)return!0;n||(n=Hn),e||(e=Hn);let i=Object.keys(n),s=Object.keys(e);if(i.length-0!=s.length-0)return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function jf(n,e){for(let t=n.attributes.length-1;t>=0;t--){let i=n.attributes[t].name;e[i]==null&&n.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?n.style.cssText=i:n.getAttribute(t)!=i&&n.setAttribute(t,i)}}function jo(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function Kf(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class ct{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var xe=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(xe||(xe={}));class P extends St{constructor(e,t,i,s){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new Yi(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Ft(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=qa(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new Ft(e,i,s,t,e.widget||null,!0)}static line(e){return new Ji(e)}static set(e,t=!1){return j.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}P.none=j.empty;class Yi extends P{constructor(e){let{start:t,end:i}=qa(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Zr(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Hn}eq(e){return this==e||e instanceof Yi&&this.tagName==e.tagName&&eo(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Yi.prototype.point=!1;class Ji extends P{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ji&&this.spec.class==e.spec.class&&eo(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Ji.prototype.mapMode=Me.TrackBefore;Ji.prototype.point=!0;class Ft extends P{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?Me.TrackBefore:Me.TrackAfter:Me.TrackDel}get type(){return this.startSide!=this.endSide?xe.WidgetRange:this.startSide<=0?xe.WidgetBefore:xe.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof Ft&&Uf(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}Ft.prototype.point=!0;function qa(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function Uf(n,e){return n==e||!!(n&&e&&n.compare(e))}function Jt(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}class Li extends St{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof Li&&this.tagName==e.tagName&&eo(this.attributes,e.attributes)}static create(e){return new Li(e.tagName,e.attributes||Hn)}static set(e,t=!1){return j.of(e,t)}}Li.prototype.startSide=Li.prototype.endSide=-1;function Pi(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function br(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function Dn(n,e){if(!e.anchorNode)return!1;try{return br(n,e.anchorNode)}catch{return!1}}function Ci(n){return n.nodeType==3?Ni(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Ai(n,e,t,i){return t?Ko(n,e,t,i,-1)||Ko(n,e,t,i,1):!1}function Mt(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Fn(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Ko(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:pt(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=Mt(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?pt(n):0}else return!1}}function pt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ii(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Gf(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function _a(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Yf(n,e,t,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==a.body,p=1,m=1;if(d)u=Gf(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let A=c.getBoundingClientRect();({scaleX:p,scaleY:m}=_a(c,A)),u={left:A.left,right:A.left+c.clientWidth*p,top:A.top,bottom:A.top+c.clientHeight*m}}let y=0,b=0;if(s=="nearest")e.top<u.top?(b=e.top-(u.top+o),t>0&&e.bottom>u.bottom+b&&(b=e.bottom-u.bottom+o)):e.bottom>u.bottom&&(b=e.bottom-u.bottom+o,t<0&&e.top-b<u.top&&(b=e.top-(u.top+o)));else{let A=e.bottom-e.top,S=u.bottom-u.top;b=(s=="center"&&A<=S?e.top+A/2-S/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-S+o)-u.top}if(i=="nearest"?e.left<u.left?(y=e.left-(u.left+r),t>0&&e.right>u.right+y&&(y=e.right-u.right+r)):e.right>u.right&&(y=e.right-u.right+r,t<0&&e.left<u.left+y&&(y=e.left-(u.left+r))):y=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,y||b)if(d)h.scrollBy(y,b);else{let A=0,S=0;if(b){let O=c.scrollTop;c.scrollTop+=b/m,S=(c.scrollTop-O)*m}if(y){let O=c.scrollLeft;c.scrollLeft+=y/p,A=(c.scrollLeft-O)*p}e={left:e.left-A,top:e.top-S,right:e.right-A,bottom:e.bottom-S},A&&Math.abs(A-y)<1&&(i="nearest"),S&&Math.abs(S-b)<1&&(s="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Jf(n){let e=n.ownerDocument,t,i;for(let s=n.parentNode;s&&!(s==e.body||t&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!t&&s.scrollWidth>s.clientWidth&&(t=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:t,y:i}}class Xf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?pt(t):0),i,Math.min(e.focusOffset,i?pt(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let Bt=null;E.safari&&E.safari_version>=26&&(Bt=!1);function $a(n){if(n.setActive)return n.setActive();if(Bt)return n.focus(Bt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Bt==null?{get preventScroll(){return Bt={preventScroll:!0},!0}}:void 0),!Bt){Bt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Uo;function Ni(n,e,t=e){let i=Uo||(Uo=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function Xt(n,e,t,i){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Qf(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function Zf(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,pt(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=pt(t))}else{if(t==n)return!0;i=Mt(t),t=t.parentNode}}function ja(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Ka(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=pt(t)}else if(t.parentNode&&!Fn(t))i=Mt(t),t=t.parentNode;else return null}}function Ua(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Fn(t))i=Mt(t)+1,t=t.parentNode;else return null}}class Ke{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Ke(e.parentNode,Mt(e),t)}static after(e,t){return new Ke(e.parentNode,Mt(e)+1,t)}}var te=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(te||(te={}));const Vt=te.LTR,to=te.RTL;function Ga(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const eu=Ga("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),tu=Ga("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),xr=Object.create(null),Qe=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);xr[e]=t,xr[t]=-e}function Ya(n){return n<=247?eu[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?tu[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const iu=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ut{get dir(){return this.level%2?to:Vt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ja(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!Ja(i.inner,s.inner))return!1}return!0}const ee=[];function nu(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let h=o,c=a,f=a;h<l;h++){let u=Ya(n.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),ee[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=ee[h];if(u==128)h<l-1&&c==ee[h+1]&&c&24?u=ee[h]=c:ee[h]=256;else if(u==64){let d=h+1;for(;d<l&&ee[d]==64;)d++;let p=h&&c==8||d<t&&ee[d]==8?f==1?1:8:256;for(let m=h;m<d;m++)ee[m]=p;h=d-1}else u==8&&f==1&&(ee[h]=1);c=u,u&7&&(f=u)}}}function su(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,c=o<i.length?i[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=xr[u=n.charCodeAt(f)])if(d<0){for(let m=l-3;m>=0;m-=3)if(Qe[m+1]==-d){let y=Qe[m+2],b=y&2?s:y&4?y&1?r:s:0;b&&(ee[f]=ee[Qe[m]]=b),l=m;break}}else{if(Qe.length==189)break;Qe[l++]=f,Qe[l++]=u,Qe[l++]=a}else if((p=ee[f])==2||p==1){let m=p==s;a=m?0:1;for(let y=l-3;y>=0;y-=3){let b=Qe[y+2];if(b&2)break;if(m)Qe[y+2]|=2;else{if(b&4)break;Qe[y+2]|=4}}}}}function ru(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let h=ee[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==t.length)break;c=t[s++].to,l=s<t.length?t[s].from:e}else if(ee[c]==256)c++;else break;let f=r==1,u=(c<e?ee[c]:i)==1,d=f==u?f?1:2:i;for(let p=c,m=s,y=m?t[m-1].to:n;p>a;)p==y&&(p=t[--m].from,y=m?t[m-1].to:n),ee[--p]=d;a=c}else r=h,a++}}}function wr(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let m=ee[a];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(f)break e;let m=r[h];if(!c)for(let y=m.to,b=h+1;;){if(y==t)break e;if(b<r.length&&r[b].from==y)y=r[b++].to;else{if(ee[y]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new ut(a,m.from,d));let y=m.direction==Vt!=!(d%2);vr(n,y?i+1:i,s,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?ee[p]!=l:ee[p]==l))break;p++}u?wr(n,a,p,i+1,s,u,o):a<p&&o.push(new ut(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let c=!0,f=!1;if(!h||a>r[h-1].to){let m=ee[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(f)break e;let m=r[--h];if(!c)for(let y=m.from,b=h;;){if(y==e)break e;if(b&&r[b-1].to==y)y=r[--b].from;else{if(ee[y-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new ut(m.to,a,d));let y=m.direction==Vt!=!(d%2);vr(n,y?i+1:i,s,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?ee[p-1]!=l:ee[p-1]==l))break;p--}u?wr(n,p,a,i+1,s,u,o):p<a&&o.push(new ut(p,a,d)),a=p}}function vr(n,e,t,i,s,r,o){let l=e%2?2:1;nu(n,s,r,i,l),su(n,s,r,i,l),ru(s,r,i,l),wr(n,s,r,e,t,i,o)}function ou(n,e,t){if(!n)return[new ut(0,0,e==to?1:0)];if(e==Vt&&!t.length&&!iu.test(n))return Xa(n.length);if(t.length)for(;n.length>ee.length;)ee[ee.length]=256;let i=[],s=e==Vt?0:1;return vr(n,s,s,t,0,n.length,i),i}function Xa(n){return[new ut(0,n,0)]}let Qa="";function lu(n,e,t,i,s){var r;let o=i.head-n.from,l=ut.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],h=a.side(s,t);if(o==h){let u=l+=s?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!s,t),h=a.side(s,t)}let c=fe(n.text,o,a.forward(s,t));(c<a.from||c>a.to)&&(c=h),Qa=n.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?w.cursor(f.side(!s,t)+n.from,f.forward(s,t)?1:-1,f.level):w.cursor(c+n.from,a.forward(s,t)?-1:1,a.level)}function au(n,e,t){for(let i=e;i<t;i++){let s=Ya(n.charCodeAt(i));if(s==1)return Vt;if(s==2||s==4)return to}return Vt}const Za=B.define(),eh=B.define(),th=B.define(),ih=B.define(),kr=B.define(),nh=B.define(),sh=B.define(),io=B.define(),no=B.define(),rh=B.define({combine:n=>n.some(e=>e)}),oh=B.define({combine:n=>n.some(e=>e)}),lh=B.define();class Qt{constructor(e,t="nearest",i="nearest",s=5,r=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Qt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Qt(w.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const ln=q.define({map:(n,e)=>n.map(e)}),ah=q.define();function Re(n,e,t){let i=n.facet(ih);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const ft=B.define({combine:n=>n.length?n[0]:!0});let hu=0;const jt=B.define({combine(n){return n.filter((e,t)=>{for(let i=0;i<t;i++)if(n[i].plugin==e.plugin)return!1;return!0})}});class he{constructor(e,t,i,s,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(jt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(jt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=t||{};return new he(hu++,e,i,s,l=>{let a=[];return o&&a.push(Wi.of(h=>{let c=h.plugin(l);return c?o(c):P.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return he.define((i,s)=>new e(i,s),t)}}class Ms{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(Re(t.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(e,this.spec.arg)}catch(t){Re(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){Re(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const hh=B.define(),so=B.define(),Wi=B.define(),ch=B.define(),fh=B.define(),Xi=B.define(),uh=B.define();function Go(n,e){let t=n.state.facet(uh);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(n):r),s=[];return j.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,c=o-e.from,f=s;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=au(e.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),s}const dh=B.define();function ro(n){let e=0,t=0,i=0,s=0;for(let r of n.state.facet(dh)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const bi=B.define();class Fe{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Fe(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0;;){let l=s<e.length?e[s].fromB:1e9,a=r<t.length?t[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,f=h,u=c;for(;;)if(r<t.length&&t[r]<=f){let d=t[r+1];r+=2,f=Math.max(f,d);for(let p=s;p<e.length&&e[p].fromB<=f;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(s<e.length&&e[s].fromB<=f){let d=e[s++];f=Math.max(f,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new Fe(c,u,h,f))}return i}}class Vn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=ce.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Fe(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new Vn(e,t,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(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const cu=[];class de{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return cu}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&jf(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let s of this.children){if(s==e)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=Mt(this.dom),s=this.length?e>0:t>0;return new Ke(this.parent.dom,i+(s?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof as)return e;return null}static get(e){return e.cmTile}}class ls extends de{constructor(e){super(e,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(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,s,r=(e==null?void 0:e.node)==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,s=i?i.nextSibling:t.firstChild,r&&s!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;s&&s!=l.dom;)s=Yo(s);else t.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:t.firstChild,r&&s&&(r.written=!0);s;)s=Yo(s);this.length=o}}function Yo(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class as extends ls{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=de.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,s=0,r=0;;)if(s==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,s=t.pop()}else{let o=i.children[s++];if(o instanceof vt)t.push(s),i=o,s=0;else{let l=r+o.length,a=e(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(e,t){let i,s=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=e-a),(h>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-a)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:s}:{tile:r,offset:o}}}class vt extends ls{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new vt(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class ii extends ls{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let s=new ii(t||document.createElement("div"),e);return(!t||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(e,t,i){let s=null,r=-1,o=null,l=-1;function a(c,f){for(let u=0,d=0;u<c.children.length&&d<=f;u++){let p=c.children[u],m=d+p.length;m>=f&&(p.isComposite()?a(p,f-d):(!o||o.isHidden&&(t>0||i&&uu(o,p)))&&(m>f||p.flags&32)?(o=p,l=f-d):(d<f||p.flags&16&&!p.isHidden)&&(s=p,r=f-d)),d=m}}a(this,e);let h=(t<0?s:o)||s||o;return h?{tile:h,offset:h==s?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):fu(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:s,offset:r}=i;if(this.dom.contains(s.dom))return s.isText()?new Ke(s.dom,Math.min(s.dom.nodeValue.length,r)):s.domPosFor(r,s.flags&16?1:s.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new Ke(a.dom,0);a==i.tile&&(l=!0)}}return new Ke(this.dom,0)}}function fu(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Ci(e);return t[t.length-1]||null}function uu(n,e){let t=n.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class Be extends ls{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new Be(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class It extends de{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?E.chrome||E.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=Ni(this.dom,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return E.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Ii(a,o<0):a||null}static of(e,t){let i=new It(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class ni extends de{constructor(e,t,i,s){super(e,t,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let s=this.widget.coordsAt(this.dom,e,t);if(s)return s;if(i)return Ii(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?r.length-1:0;o=r[a],!(e>0?a==0:a==r.length-1||o.top<o.bottom);a+=l?-1:1);return Ii(o,!l)}}get overrideDOMText(){if(!this.length)return J.empty;let{root:e}=this;if(!e)return J.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,s,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new ni(r,i,e,s)}}class zn extends de{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!1}get overrideDOMText(){return J.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class du{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:s,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(s.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==s.children.length){if(!e&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++}else{let a=s.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,e-=a.length):(l.push({tile:s,index:r}),s=a,r=0,i&&a.isComposite()&&i.enter(a))}else if(r==s.length)o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++;else if(e){let a=Math.min(e,s.length-r);i&&i.skip(s,r,r+a),e-=a,r+=a}else break;return this.tile=s,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class pu{constructor(e,t,i,s){this.from=e,this.to=t,this.wrapper=i,this.rank=s}}class mu{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,s){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new It(l.dom,l.text+e);a.parent=o}else o.append(s||It.of(e,(r=this.cache.find(It))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Ts(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let s=i;for(let o=t.marks.length-1;o>=0;o--){let l=t.marks[o],a=s.lastChild;if(a instanceof Be&&a.mark.eq(l.mark))a.dom!=l.dom&&a.setDOM(Ts(l.dom)),s=a;else{if(this.cache.reused.get(l)){let c=de.get(l.dom);c&&c.setDOM(Ts(l.dom))}let h=Be.of(l.mark,l.dom);s.append(h),s=h}this.cache.reused.set(l,2)}let r=new It(e.text,e.text.nodeValue);r.flags|=8,s.append(r)}addInlineWidget(e,t,i){let s=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);s||this.flushBuffer();let r=this.ensureMarks(t,i);!s&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=ph);let s=ii.start(e,t||((i=this.cache.find(ii))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let s=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=s.lastChild)&&l instanceof Be&&l.mark.eq(o))s=l,t--;else{let a=Be.of(o,(i=this.cache.find(Be,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,t=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Jo(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(E.ios&&Jo(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Os,0,32)||new ni(Os.toDOM(),0,Os,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new pu(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let s=t.lastChild;if(i.from<this.pos&&s instanceof vt&&s.wrapper.eq(i.wrapper))t=s;else{let r=vt.of(i.wrapper,(e=this.cache.find(vt,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(zn,void 0,1);return i&&(i.flags=t),i||new zn(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class gu{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:s,lineBreak:r,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(e,s.length);return r?null:s.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const qn=[ni,ii,It,Be,zn,vt,as];for(let n=0;n<qn.length;n++)qn[n].bucket=n;class yu{constructor(e){this.view=e,this.buckets=qn.map(()=>[]),this.index=qn.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let s=e.bucket,r=this.buckets[s],o=this.index[s];for(let l=r.length-1;l>=0;l--){let a=(l+o)%r.length,h=r[a];if((!t||t(h))&&!this.reused.has(h))return r.splice(a,1),a<o&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(e,t,i){let s=this.buckets[0];if(s.length)for(let r=0,o=0;;r++){if(r==s.length){if(o)return null;o=1,r=0}let l=s[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view)))return s.splice(r,1),r<this.index[0]&&this.index[0]--,this.reused.set(l,1),l.length=t,l.flags=l.flags&-498|i,l}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}}class bu{constructor(e,t,i,s,r){this.view=e,this.decorations=s,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new yu(e),this.text=new gu(e.state.doc),this.builder=new mu(this.cache,new as(e,e.contentDOM),j.iter(i)),this.cache.reused.set(t,2),this.old=new du(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let s=0,r=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!o,!l),s=a,r+=h}if(!l)break;this.forward(l.fromA,l.toA),t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.emit(r,t.range.fromB),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.emit(t.range.toB,l.toB)):this.emit(r,l.toB),r=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let s=vu(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?ni.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,r),r=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length?this.builder.addText(o.text,s,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),s,r)),r=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof zn)this.cache.add(o);else if(o instanceof Be)this.builder.ensureLine(null),this.builder.addMark(o,s,r),this.cache.reused.set(o,1),r=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 Be&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=r=0):o instanceof Be&&(s.shift(),r=Math.min(r,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,s=this.builder,r=0,o=j.spans(this.decorations,e,t,{point:(l,a,h,c,f,u)=>{if(h instanceof Ft){if(this.disallowBlockEffectsFor[u]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,f>c.length)s.continueWidget(a-l);else{let d=h.widget||(h.block?si.block:si.inline),p=xu(h),m=this.cache.findWidget(d,a-l,p)||ni.of(d,this.view,a-l,p);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(m)):(s.ensureLine(i),s.addInlineWidget(m,c,f))}i=null}else i=wu(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let u=this.text.next(Math.min(512,a-f));u==null?(s.addLineStartIfNotCovered(i),s.addBreak(),f++):(s.ensureLine(i),s.addText(u,h,c),f+=u.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t){t-e<=10?this.old.advance(t-e,1,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,1,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let s=e.parentNode;;s=s.parentNode){let r=de.get(s);if(s==this.view.contentDOM)break;r instanceof Be?t.push(r):r!=null&&r.isLine()?i=r:s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new ii(s,ph):t.push(Be.of(new Yi({tagName:s.nodeName.toLowerCase(),attributes:Kf(s)}),s))}return{line:i,marks:t}}}function Jo(n,e){let t=i=>{for(let s of i.children)if((e?s.isText():s.length)||t(s))return!0;return!1};return t(n)}function xu(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const ph={class:"cm-line"};function wu(n,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(n||(n={class:"cm-line"}),t&&Zr(t,n),i&&(n.class+=" "+i)),n}function vu(n){let e=[];for(let t=n.parents.length;t>1;t--){let i=t==n.parents.length?n.tile:n.parents[t].tile;i instanceof Be&&e.push(i.mark)}return e}function Ts(n){let e=de.get(n);return e&&e.setDOM(n.cloneNode()),n}class si extends ct{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}si.inline=new si("span");si.block=new si("div");const Os=new class extends ct{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Xo{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=P.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 as(e,e.contentDOM),this.updateInner([new Fe(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!Eu(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?Su(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new Fe(c,f,e.changes.mapPos(c,-1),e.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(E.ie||E.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=Mu(o,this.decorations,e.changes);a.length&&(i=Fe.extendWithRanges(i,a));let h=Ou(l,this.blockWrappers,e.changes);return h.length&&(i=Fe.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new bu(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(e,t),Sr(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 r=E.chrome||E.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.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 r of this.tile.children)r.isWidget()&&r.widget instanceof Ds&&s.push(r.dom);i.updateGaps(s)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(ah)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,r=s==i,o=!r&&!(this.view.state.facet(ft)||i.tabIndex>-1)&&Dn(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),E.gecko&&a.empty&&!this.hasComposition&&ku(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=c=new Ke(u,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!Ai(h.node,h.offset,f.anchorNode,f.anchorOffset)||!Ai(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{E.android&&E.chrome&&i.contains(f.focusNode)&&Du(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=Pi(this.view.root);if(u)if(a.empty){if(E.gecko){let d=Cu(h.node,h.offset);if(d&&d!=3){let p=(d==1?Ka:Ua)(h.node,h.offset);p&&(h=new Ke(p.node,p.offset))}}u.collapse(h.node,h.offset),a.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=a.bidiLevel)}else if(u.extend){u.collapse(h.node,h.offset);try{u.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new Ke(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new Ke(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Ai(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=Pi(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(s,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=pt(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return s;for(;r&&!de.get(r);)r=r.nextSibling;if(!r)return s+i.length;for(let o=0,l=s;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?e==i.dom?s+t:s+(t?i.length:0):s}domAtPos(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(s,t)}inlineDOMNearPos(e,t){let i,s=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(r=!0)}else{let f=c+h.length;if(c<=e&&(i=h,s=e-c,r=f<e),f>=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:a&&i&&(o=null),i&&t<0||!o?i.domIn(s,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof Ds?null:i.coordsInWidget(s,t,!0):i.coordsIn(s,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function s(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=s(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=fe(r.text,o);if(l==o)return null;let a=Ni(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==te.LTR,h=0,c=(f,u,d)=>{for(let p=0;p<f.children.length&&!(u>s);p++){let m=f.children[p],y=u+m.length,b=m.dom.getBoundingClientRect(),{height:A}=b;if(d&&!p&&(h+=b.top-d.top),m instanceof vt)y>i&&c(m,u,b);else if(u>=i&&(h>0&&t.push(-h),t.push(A+h),h=0,o)){let S=m.dom.lastChild,O=S?Ci(S):[];if(O.length){let C=O[O.length-1],M=a?C.right-b.left:b.right-C.left;M>l&&(l=M,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=y)}}d&&p==f.children.length-1&&(h+=d.bottom-b.bottom),u=y+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?te.RTL:te.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Ci(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),i,s,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Ci(t.firstChild)[0];i=t.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:s,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(P.replace({widget:new Ds(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return P.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Wi).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(fh).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=i,t.push(j.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ch).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){if(e.isSnapshot){let h=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=h.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let h of this.view.state.facet(lh))try{if(h(this.view,e.range,e))return!0}catch(c){Re(this.view.state,c,"scroll handler")}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=ro(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;Yf(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==te.LTR)}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Sr(this.tile)}}function Sr(n,e){let t=e==null?void 0:e.get(n);if(t!=1){t==null&&n.destroy();for(let i of n.children)Sr(i,e)}}function ku(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function mh(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=Ka(t.focusNode,t.focusOffset),s=Ua(t.focusNode,t.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=de.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=de.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Su(n,e,t){let i=mh(n,t);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc;return{range:new Fe(a.mapPos(r),a.mapPos(o),r,o),text:s}}function Cu(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let Au=class{constructor(){this.changes=[]}compareRange(e,t){Jt(e,t,this.changes)}comparePoint(e,t){Jt(e,t,this.changes)}boundChange(e){Jt(e,e,this.changes)}};function Mu(n,e,t){let i=new Au;return j.compare(n,e,t,i),i.changes}class Tu{constructor(){this.changes=[]}compareRange(e,t){Jt(e,t,this.changes)}comparePoint(){}boundChange(e){Jt(e,e,this.changes)}}function Ou(n,e,t){let i=new Tu;return j.compare(n,e,t,i),i.changes}function Du(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function Eu(n,e){let t=!1;return e&&n.iterChangedRanges((i,s)=>{i<e.to&&s>e.from&&(t=!0)}),t}class Ds extends ct{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Bu(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return w.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=fe(s.text,r,!1):l=fe(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=fe(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=fe(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return w.range(o+s.from,l+s.from)}function Ru(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+fr(o,r,n.state.tabSize)}function Cr(n,e,t){let i=n.lineBlockAt(e);if(Array.isArray(i.type)){let s;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!s||r.type==xe.Text&&(s.type!=r.type||(t<0?r.from<e:r.to>e)))&&(s=r)}}return s||i}return i}function Lu(n,e,t,i){let s=Cr(n,e.head,e.assoc||-1),r=!i||s.type!=xe.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==te.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return w.cursor(a,t?-1:1)}return w.cursor(t?s.to:s.from,t?-1:1)}function Qo(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let h=lu(s,r,o,l,t),c=Qa;if(!h){if(s.number==(t?n.state.doc.lines:1))return l;c=`
`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),h=n.visualLineSide(s,!t)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function Pu(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==se.Space&&(s=o),s==o}}function Iu(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return w.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,e.assoc||-1),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+c}let f=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,m=Ar(n,{x:f,y:p},!1,r);return w.cursor(m.pos,m.assoc,void 0,o)}}function Mi(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function gh(n,e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=Mi(n,s.from,0);o!=s.from&&(r=w.cursor(o,-1))}else{let o=Mi(n,s.from,-1),l=Mi(n,s.to,1);(o!=s.from||l!=s.to)&&(r=w.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?w.create(t,e.mainIndex):e}function Es(n,e,t){let i=Mi(n.state.facet(Xi).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:w.cursor(i,i<t.from?1:-1)}class st{constructor(e,t){this.pos=e,this.assoc=t}}function Ar(n,e,t,i){let s=n.contentDOM.getBoundingClientRect(),r=s.top+n.viewState.paddingTop,{x:o,y:l}=e,a=l-r,h;for(;;){if(a<0)return new st(0,1);if(a>n.viewState.docHeight)return new st(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==xe.Text){let u=n.docView.coordsAt(i<0?h.from:h.to,i);if(u&&(i<0?u.top<=a+r:u.bottom>=a+r))break}let f=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(t)return null;if(h.type==xe.Text){let f=Ru(n,s,h,o,l);return new st(f,f==h.from?1:-1)}}if(h.type!=xe.Text)return a<(h.top+h.bottom)/2?new st(h.from,1):new st(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),yh(n,c,h.from,o,l)}function yh(n,e,t,i,s){let r=-1,o=null,l=1e9,a=1e9,h=s,c=s,f=(u,d)=>{for(let p=0;p<u.length;p++){let m=u[p];if(m.top==m.bottom)continue;let y=m.left>i?m.left-i:m.right<i?i-m.right:0,b=m.top>s?m.top-s:m.bottom<s?s-m.bottom:0;m.top<=c&&m.bottom>=h&&(h=Math.min(m.top,h),c=Math.max(m.bottom,c),b=0),(r<0||(b-a||y-l)<0)&&(r>=0&&a&&l<y&&o.top<=c-2&&o.bottom>=h+2?a=0:(r=d,l=y,a=b,o=m))}};if(e.isText()){for(let d=0;d<e.length;){let p=fe(e.text,d);if(f(Ni(e.dom,d,p).getClientRects(),d),!l&&!a)break;d=p}return i>(o.left+o.right)/2==(Zo(n,r+t)==te.LTR)?new st(t+fe(e.text,r),-1):new st(t+r,1)}else{if(!e.length)return new st(t,1);for(let m=0;m<e.children.length;m++){let y=e.children[m];if(y.flags&48)continue;let b=(y.dom.nodeType==1?y.dom:Ni(y.dom,0,y.length)).getClientRects();if(f(b,m),!l&&!a)break}let u=e.children[r],d=e.posBefore(u,t);return u.isComposite()||u.isText()?yh(n,u,d,Math.max(o.left,Math.min(o.right,i)),s):i>(o.left+o.right)/2==(Zo(n,r+t)==te.LTR)?new st(d+u.length,-1):new st(d,1)}}function Zo(n,e){let t=n.state.doc.lineAt(e);return n.bidiSpans(t)[ut.find(n.bidiSpans(t),e-t.from,-1,1)].dir}const xi="";class Nu{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(K.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=xi}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=de.get(s),l=s.nextSibling;if(l==t){o!=null&&o.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=de.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:Fn(s))||Fn(l)&&(s.nodeName!="BR"||o!=null&&o.isWidget())&&this.text.length>r)&&!Hu(l,t)&&this.lineBreak(),s=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){let t=de.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(Wu(e,i.node,i.offset)?t:0))}}function Wu(n,e,t){for(;;){if(!e||t<pt(e))return!1;if(e==n)return!0;t=Mt(e)+1,e=e.parentNode}}function Hu(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let i=de.get(n);if(!(i!=null&&i.isWidget()))return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let s=i.overrideDOMText;if(s!=null&&s.length)return!1}return!0}class el{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Fu{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=bh(e.docView.tile,t,i,0))){let l=r||o?[]:zu(e),a=new Nu(l,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=qu(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!br(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!br(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=e.viewport;if((E.ios||E.chrome)&&e.state.selection.main.empty&&a!=h&&(c.from>0||c.to<e.state.doc.length)){let f=Math.min(a,h),u=Math.max(a,h),d=c.from-f,p=c.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==e.state.doc.length)&&(a=0,h=e.state.doc.length)}e.inputState.composing>-1&&e.state.selection.ranges.length>1?this.newSel=e.state.selection.replaceRange(w.range(h,a)):this.newSel=w.single(h,a)}}}function bh(n,e,t,i){if(n.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let f=n.children[a],u=h+f.length;if(h<e&&u>t)return bh(f,e,t,h);if(u>=e&&s==-1&&(s=a,r=h),h>t&&f.dom.parentNode==n.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:r,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function xh(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,h=null;(r===8||E.android&&e.text.length<l-o)&&(a=s.to,h="end");let c=wh(n.state.doc.sliceString(o,l,xi),e.text,a-o,h);c&&(E.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==xi+xi&&c.toB--,t={from:o+c.from,to:o+c.toA,insert:J.of(e.text.slice(c.from,c.toB).split(xi))})}else i&&(!n.hasFocus&&n.state.facet(ft)||i.main.eq(s))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!s.empty&&i&&i.main.empty?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:(E.mac||E.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:J.of([t.insert.toString().replace("."," ")])}):t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:n.state.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:n.state.toText(n.inputState.insertingText)}:E.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
 `&&n.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:J.of([" "])}),t)return oo(n,t,i,r);if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=gh(n.state.facet(Xi).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function oo(n,e,t,i=-1){if(E.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(E.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Xt(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&Xt(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Xt(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=Vu(n,e,t));return n.state.facet(nh).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function Vu(n,e,t){let i,s=n.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let a=e.from<r.from?-1:1,h=a<0?r.from:r.to,c=Mi(s.facet(Xi).map(f=>f(n)),h,a);e.from==c&&(o=c)}if(o>-1)i={changes:e,selection:w.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let a=r.from<e.from?s.sliceDoc(r.from,e.from):"",h=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let c=n.state.sliceDoc(e.from,e.to),f,u=t&&mh(n,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);f={from:u.from,to:u.to-p}}else f=n.state.doc.lineAt(r.head);let d=r.to-e.to;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,y=m-c.length;if(n.state.sliceDoc(y,m)!=c||m>=f.from&&y<=f.to)return{range:p};let b=s.changes({from:y,to:m,insert:e.insert}),A=p.to-r.to;return{changes:b,range:h?w.range(Math.max(0,h.anchor+A),Math.max(0,h.head+A)):p.map(b)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function wh(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function zu(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new el(t,i)),(s!=t||r!=i)&&e.push(new el(s,r))),e}function qu(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?w.single(t+e,i+e):null}class _u{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,E.safari&&e.contentDOM.addEventListener("input",()=>null),E.gecko&&sd(e.contentDOM.ownerDocument)}handleEvent(e){!Xu(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=$u(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&kh.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),E.android&&E.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return E.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=vh.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||ju.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Xt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:E.safari&&!E.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function tl(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){Re(t.state,s)}}}function $u(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&t(l).handlers.push(tl(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(tl(i.value,a))}}for(let i in Ge)t(i).handlers.push(Ge[i]);for(let i in _e)t(i).observers.push(_e[i]);return e}const vh=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ju="dthko",kh=[16,17,18,20,91,92,224,225],an=6;function hn(n){return Math.max(0,n)*.7+8}function Ku(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class Uu{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Jf(e.contentDOM),this.atoms=e.state.facet(Xi).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(K.allowMultipleSelections)&&Gu(e,t),this.dragging=Ju(e,t)&&Ah(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Ku(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=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:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ro(this.view);e.clientX-a.left<=s+an?t=-hn(s-e.clientX):e.clientX+a.right>=o-an&&(t=hn(e.clientX-o)),e.clientY-a.top<=r+an?i=-hn(r-e.clientY):e.clientY+a.bottom>=l-an&&(i=hn(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=gh(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Gu(n,e){let t=n.state.facet(Za);return t.length?t[0](e):E.mac?e.metaKey:e.ctrlKey}function Yu(n,e){let t=n.state.facet(eh);return t.length?t[0](e):E.mac?!e.altKey:!e.ctrlKey}function Ju(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=Pi(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Xu(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=de.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Ge=Object.create(null),_e=Object.create(null),Sh=E.ie&&E.ie_version<15||E.ios&&E.webkit_version<604;function Qu(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),Ch(n,t.value)},50)}function hs(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function Ch(n,e){e=hs(n.state,io,e);let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Mr!=null&&t.selection.ranges.every(a=>a.empty)&&Mr==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:w.cursor(h.from+f.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:w.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}_e.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Ge.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);_e.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};_e.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ge.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(th))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=ed(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new Uu(n,e,t,i)),i&&n.observer.ignore(()=>{$a(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function il(n,e,t,i){if(i==1)return w.cursor(e,t);if(i==2)return Bu(n.state,e,t);{let s=n.docView.lineAt(e,t),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,w.range(o,l)}}const Zu=E.ie&&E.ie_version<=11;let nl=null,sl=0,rl=0;function Ah(n){if(!Zu)return n.detail;let e=nl,t=rl;return nl=n,rl=Date.now(),sl=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(sl+1)%3:1}function ed(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Ah(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=n.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=il(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let f=il(n,t.pos,t.assoc,i),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?w.range(u,d):w.range(d,u)}return o?s.replaceRange(s.main.extend(c.from,c.to)):l&&i==1&&s.ranges.length>1&&(h=td(s,a.pos))?h:l?s.addRange(c):w.create([c])}}}function td(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return w.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}Ge.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.tile.nearest(e.target);if(s&&s.isWidget()){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=w.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",hs(n.state,no,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Ge.dragend=n=>(n.inputState.draggedContent=null,!1);function ol(n,e,t,i){if(t=hs(n.state,io,t),!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&Yu(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ge.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&ol(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return ol(n,e,i,!0),!0}return!1};Ge.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Sh?null:e.clipboardData;return t?(Ch(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Qu(n),!1)};function id(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function nd(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:hs(n,no,e.join(n.lineBreak)),ranges:t,linewise:i}}let Mr=null;Ge.copy=Ge.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=nd(n.state);if(!t&&!s)return!1;Mr=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Sh?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(id(n,t),!1)};const Mh=at.define();function Th(n,e){let t=[];for(let i of n.facet(sh)){let s=i(n,e);s&&t.push(s)}return t.length?n.update({effects:t,annotations:Mh.of(!0)}):null}function Oh(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=Th(n.state,e);t?n.dispatch(t):n.update([])}},10)}_e.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Oh(n)};_e.blur=n=>{n.observer.clearSelectionRange(),Oh(n)};_e.compositionstart=_e.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};_e.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,E.chrome&&E.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};_e.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ge.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return oo(n,{from:a,to:h,insert:n.state.toText(r)},null),!0}}let s;if(E.chrome&&E.android&&(s=vh.find(r=>r.inputType==e.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((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)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return E.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),E.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>_e.compositionend(n,e),20),!1};const ll=new Set;function sd(n){ll.has(n)||(ll.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const al=["pre-wrap","normal","pre-line","break-spaces"];let ri=!1;function hl(){ri=!1}class rd{constructor(e){this.lineWrapping=e,this.doc=J.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return al.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=al.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class od{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class je{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?xe.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 Ft?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new je(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var ne=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(ne||(ne={}));const En=.001;class Te{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>En&&(ri=!0),this.height=e)}replace(e,t,i){return Te.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],u=r.lineAt(a,ne.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,ne.ByPosNoHeight,i,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,ne.ByPosNoHeight,i,0,0));c+=u.from-a,a=u.from;let p=lo.build(i.setDoc(o),e,c,f);r=_n(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new Ie(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new ad(Te.of(e.slice(0,t)),o,Te.of(e.slice(i)))}}function _n(n,e){return n==e?n:(n.constructor!=e.constructor&&(ri=!0),e)}Te.prototype.size=1;const ld=P.replace({});class Dh extends Te{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new je(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,s){return this.spaceAbove&&e<i+this.spaceAbove?new je(s,0,i,this.spaceAbove,ld):this.mainBlock(i,s)}lineAt(e,t,i,s,r){let o=this.mainBlock(s,r);return this.spaceAbove?this.blockAt(0,i,s,r).join(o):o}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,ne.ByPos,i,s,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ie extends Dh{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new je(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Ie||s instanceof ge&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ge?s=new Ie(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):Te.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ge extends Te{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(i,e-f/2);return new je(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:c,length:f}=t.doc.line(r+h);return new je(c,f,i+l*h,l,0)}}lineAt(e,t,i,s,r){if(t==ne.ByHeight)return this.blockAt(e,i,s,r);if(t==ne.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new je(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=s+l*f+a*(h.from-r-f);return new je(h.from,h.length,Math.max(s,Math.min(u,s+this.height-c)),c,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=e,f=s;c<=t;){let u=i.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new je(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof ge?i[i.length-1]=new ge(r.length+s):i.push(null,new ge(s-1))}if(e>0){let r=i[0];r instanceof ge?i[0]=new ge(e+r.length):i.unshift(new ge(e-1),null)}return Te.of(i)}decomposeLeft(e,t){t.push(new ge(e-1),null)}decomposeRight(e,t){t.push(null,new ge(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new ge(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++],u=0;f<0&&(u=-f,f=s.heights[s.index++]),a==-1?a=f:Math.abs(f-a)>=En&&(a=-2);let d=new Ie(c,f,u);d.outdated=!1,o.push(d),l+=c+1}l<=r&&o.push(null,new ge(r-l).updateHeight(e,l));let h=Te.of(o);return(a<0||Math.abs(h.height-this.height)>=En||Math.abs(a-this.heightMetrics(e,t).perLine)>=En)&&(ri=!0),_n(this,h)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class ad extends Te{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==ne.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==ne.ByPosNoHeight?ne.ByPosNoHeight:ne.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,ne.ByPos,i,s,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,s,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&cl(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),cl(r,l)}return Te.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Te.of(this.break?[e,null,t]:[e,t]):(this.left=_n(this.left,e),this.right=_n(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function cl(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ge&&(i=n[e+1])instanceof ge&&n.splice(e-1,3,new ge(t.length+1+i.length))}const hd=5;class lo{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Ie?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ie(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Dh(o,s,i)):(o||r||s>=hd)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ie(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new ge(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ie)return e;let t=new Ie(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ie)&&!this.isCovered?this.nodes.push(new Ie(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof Ie&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new lo(i,e);return j.spans(t,i,s,r,0),r.finish(i)}}function cd(n,e,t){let i=new fd;return j.compare(n,e,t,i,0),i.changes}class fd{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&Jt(e,t,this.changes,5)}}function ud(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let u=c.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==n.parentNode?s.innerHeight:a,u.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function dd(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function pd(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Bs{constructor(e,t,i,s){this.from=e,this.to=t,this.size=i,this.displaySize=s}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return P.replace({widget:new md(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class md extends ct{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class fl{constructor(e){this.state=e,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=ul,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=te.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(so).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new rd(t),this.stateDeco=e.facet(Wi).filter(i=>typeof i!="function"),this.heightMap=Te.empty().applyChanges(this.stateDeco,J.empty,this.heightOracle.setDoc(e.doc),[new Fe(0,0,0,e.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=P.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new cn(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?ul:new ao(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(wi(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Wi).filter(c=>typeof c!="function");let s=e.changedRanges,r=Fe.extendWithRanges(s,cd(i,this.stateDeco,e?e.changes:ce.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);hl(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||ri)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(oh)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?te.RTL:te.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:O,scaleY:C}=_a(t,l);(O>.005&&Math.abs(this.scaleX-O)>.005||C>.005&&Math.abs(this.scaleY-C)>.005)&&(this.scaleX=O,this.scaleY=C,h|=16,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=ja(e.scrollDOM);let p=(this.printing?pd:ud)(t,this.paddingTop),m=p.top-this.pixelViewport.top,y=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&&(a=!0)),!this.inView&&!this.scrollTarget&&!dd(e.dom))return 0;let A=l.width;if((this.contentDOMWidth!=A||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let O=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(O)&&(o=!0),o||s.lineWrapping&&Math.abs(A-this.contentDOMWidth)>s.charWidth){let{lineHeight:C,charWidth:M,textHeight:v}=e.docView.measureTextSize();o=C>0&&s.refresh(r,C,M,v,Math.max(5,A/M),O),o&&(e.docView.minWidth=0,h|=16)}m>0&&y>0?c=Math.max(m,y):m<0&&y<0&&(c=Math.min(m,y)),hl();for(let C of this.viewports){let M=C.from==this.viewport.from?O:e.docView.measureVisibleLineHeights(C);this.heightMap=(o?Te.empty().applyChanges(this.stateDeco,J.empty,this.heightOracle,[new Fe(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new od(C.from,M))}ri&&(h|=2)}let S=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new cn(s.lineAt(o-i*1e3,ne.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,ne.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,ne.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new cn(s.lineAt(u-1e3/2,ne.ByHeight,r,0,0).from,s.lineAt(u+c+1e3/2,ne.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new cn(this.heightMap.lineAt(i,ne.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,ne.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,ne.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,ne.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new Bs(t.mapPos(s.from),t.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=te.LTR&&!i)return[];let l=[],a=(c,f,u,d)=>{if(f-c<r)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let b of m)if(b>c&&b<f){a(c,b-10,u,d),a(b+10,f,u,d);return}let y=yd(e,b=>b.from>=u.from&&b.to<=u.to&&Math.abs(b.from-c)<r&&Math.abs(b.to-f)<r&&!m.some(A=>b.from<A&&b.to>A));if(!y){if(f<u.to&&t&&i&&t.visibleRanges.some(S=>S.from<=f&&S.to>=f)){let S=t.moveToLineBoundary(w.cursor(f),!1,!0).head;S>c&&(f=S)}let b=this.gapSize(u,c,f,d),A=i||b<2e6?b:2e6;y=new Bs(c,f,b,A)}l.push(y)},h=c=>{if(c.length<o||c.type!=xe.Text)return;let f=gd(c.from,c.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,y,b;if(u!=null){let A=un(f,u),S=((this.visibleBottom-this.visibleTop)/2+m)/c.height;y=A-S,b=A+S}else y=(this.visibleTop-c.top-m)/c.height,b=(this.visibleBottom-c.top+m)/c.height;d=fn(f,y),p=fn(f,b)}else{let m=f.total*this.heightOracle.charWidth,y=s*this.heightOracle.charWidth,b=0;if(m>2e6)for(let M of e)M.from>=c.from&&M.from<c.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+b<this.pixelViewport.left&&(b=M.size-M.displaySize);let A=this.pixelViewport.left+b,S=this.pixelViewport.right+b,O,C;if(u!=null){let M=un(f,u),v=((S-A)/2+y)/m;O=M-v,C=M+v}else O=(A-y)/m,C=(S+y)/m;d=fn(f,O),p=fn(f,C)}d>c.from&&a(c.from,d,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(e,t,i,s){let r=un(s,i)-un(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){Bs.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=P.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];j.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r<i.length&&!(s&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(s|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||wi(this.heightMap.lineAt(e,ne.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||wi(this.heightMap.lineAt(this.scaler.fromDOM(e),ne.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return wi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class cn{constructor(e,t){this.from=e,this.to=t}}function gd(n,e,t){let i=[],s=n,r=0;return j.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function fn({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function un(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function yd(n,e){for(let t of n)if(e(t))return t}const ul={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class ao{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,ne.ByPos,e,0,0).top,c=t.lineAt(a,ne.ByPos,e,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}eq(e){return e instanceof ao?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function wi(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new je(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>wi(s,e)):n._content)}const dn=B.define({combine:n=>n.join(" ")}),Tr=B.define({combine:n=>n.indexOf(!0)>-1}),Or=Ct.newName(),Eh=Ct.newName(),Bh=Ct.newName(),Rh={"&light":"."+Eh,"&dark":"."+Bh};function Dr(n,e,t){return new Ct(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}const bd=Dr("."+Or,{"&":{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"}},Rh),xd={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Rs=E.ie&&E.ie_version<=11;class wd{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Xf,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(E.ie&&E.ie_version<=11||E.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&E.android&&e.constructor.EDIT_CONTEXT!==!1&&!(E.chrome&&E.chrome_version<126)&&(this.editContext=new kd(e),e.state.facet(ft)&&(e.contentDOM.editContext=this.editContext.editContext)),Rs&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(ft)?i.root.activeElement!=this.dom:!Dn(this.dom,s))return;let r=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(E.ie&&E.ie_version<=11||E.android&&E.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Ai(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Pi(e.root);if(!t)return!1;let i=E.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&vd(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=Dn(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Zf(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,xd),Rs&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Rs&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Xt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,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 e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&Dn(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Fu(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=xh(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=dl(t,e.previousSibling||e.target.previousSibling,-1),s=dl(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(ft)!=e.state.facet(ft)&&(e.view.contentDOM.editContext=e.state.facet(ft)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.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 dl(n,e,t){for(;e;){let i=de.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function pl(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return Ai(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function vd(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return pl(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?pl(n,t):null}class kd{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let s=e.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let c=wh(e.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let u=w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));u.main.eq(s)||e.dispatch({selection:u,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:J.of(i.text.slice(c.from,c.toB).split(`
`))};if((E.mac||E.android)&&f.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:J.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let u=this.to-this.from+(f.to-f.from+f.insert.length);oo(e,f,w.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),f.from<f.to&&!f.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(P.mark({attributes:{style:c}}).range(a,h))}}}e.dispatch({effects:ah.of(P.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=Pi(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,t+=c,this.to+=c;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class D{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(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Qf(e.parent)||document,this.viewState=new fl(e.state||K.create(e)),e.scrollTo&&e.scrollTo.is(ln)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(jt).map(s=>new Ms(s));for(let s of this.plugins)s.update(this);this.observer=new wd(this),this.inputState=new _u(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Xo(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...e){let t=e.length==1&&e[0]instanceof ue?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(Mh))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Th(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(K.phrases)!=this.state.facet(K.phrases))return this.setState(r);s=Vn.create(this,r,e),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Qt(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(ln)&&(f=d.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=$n.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(bi)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(dn)!=s.state.facet(dn)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(kr))try{u(s)}catch(d){Re(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!xh(this,c)&&h.force&&Xt(this.contentDOM,h.key,h.keyCode)})}setState(e){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=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new fl(e),this.plugins=e.facet(jt).map(i=>new Ms(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Xo(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(jt),i=e.state.facet(jt);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new Ms(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){Re(this.state,i,"doc view update listener")}}}measure(e=!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,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,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(ja(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!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 h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(p){return Re(this.state,p),ml}}),f=Vn.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d<h.length;d++)if(c[d]!=ml)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){Re(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.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=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).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(t&&!t.empty)for(let l of this.state.facet(kr))l(t)}get themeClasses(){return Or+" "+(this.state.facet(Tr)?Bh:Eh)+" "+this.state.facet(dn)}updateAttrs(){let e=gl(this,hh,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(ft)?"true":"false",class:"cm-content",style:`${E.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),gl(this,so,t);let i=this.observer.ignore(()=>{let s=jo(this.contentDOM,this.contentAttrs,t),r=jo(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(D.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(bi);let e=this.state.facet(D.cspNonce);Ct.mount(this.root,this.styleModules.concat(bd).reverse(),e?{nonce:e}: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(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Es(this,e,Qo(this,e,t,i))}moveByGroup(e,t){return Es(this,e,Qo(this,e,t,i=>Pu(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return w.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return Lu(this,e,t,i)}moveVertically(e,t,i){return Es(this,e,Iu(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=Ar(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),Ar(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[ut.find(r,e-s.from,-1,t)];return Ii(i,o.dir==te.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(rh)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Sd)return Xa(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Ja(r.isolates,i=Go(this,e))))return r.order;i||(i=Go(this,e));let s=ou(e.text,t,i);return this.bidiCache.push(new $n(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||E.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{$a(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return ln.of(new Qt(typeof e=="number"?w.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return ln.of(new Qt(w.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return he.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return he.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=Ct.newName(),s=[dn.of(i),bi.of(Dr(`.${i}`,e))];return t&&t.dark&&s.push(Tr.of(!0)),s}static baseTheme(e){return qt.lowest(bi.of(Dr("."+Or,e,Rh)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&de.get(i)||de.get(e);return((t=s==null?void 0:s.root)===null||t===void 0?void 0:t.view)||null}}D.styleModule=bi;D.inputHandler=nh;D.clipboardInputFilter=io;D.clipboardOutputFilter=no;D.scrollHandler=lh;D.focusChangeEffect=sh;D.perLineTextDirection=rh;D.exceptionSink=ih;D.updateListener=kr;D.editable=ft;D.mouseSelectionStyle=th;D.dragMovesSelection=eh;D.clickAddsSelectionRange=Za;D.decorations=Wi;D.blockWrappers=ch;D.outerDecorations=fh;D.atomicRanges=Xi;D.bidiIsolatedRanges=uh;D.scrollMargins=dh;D.darkTheme=Tr;D.cspNonce=B.define({combine:n=>n.length?n[0]:""});D.contentAttributes=so;D.editorAttributes=hh;D.lineWrapping=D.contentAttributes.of({class:"cm-lineWrapping"});D.announce=q.define();const Sd=4096,ml={};class $n{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:te.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new $n(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function gl(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&Zr(o,t)}return t}const Cd=E.mac?"mac":E.windows?"win":E.linux?"linux":"key";function Ad(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function pn(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const Md=qt.default(D.domEventHandlers({keydown(n,e){return Ph(Lh(e.state),n,e,"editor")}})),cs=B.define({enables:Md}),yl=new WeakMap;function Lh(n){let e=n.facet(cs),t=yl.get(e);return t||yl.set(e,t=Dd(e.reduce((i,s)=>i.concat(s),[]))),t}function Td(n,e,t){return Ph(Lh(n.state),e,n,t)}let bt=null;const Od=4e3;function Dd(n,e=Cd){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>Ad(b,e));for(let b=1;b<p.length;b++){let A=p.slice(0,b).join(" ");s(A,!0),d[A]||(d[A]={preventDefault:!0,stopPropagation:!1,run:[S=>{let O=bt={view:S,prefix:A,scope:o};return setTimeout(()=>{bt==O&&(bt=null)},Od),!0}]})}let m=p.join(" ");s(m,!1);let y=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&y.run.push(a),h&&(y.preventDefault=!0),c&&(y.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,Er))}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Er=null;function Ph(n,e,t,i){Er=e;let s=_f(e),r=De(s,0),o=nt(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;bt&&bt.view==t&&bt.scope==i&&(l=bt.prefix+" ",kh.indexOf(e.keyCode)<0&&(h=!0,bt=null));let f=new Set,u=y=>{if(y){for(let b of y.run)if(!f.has(b)&&(f.add(b),b(t)))return y.stopPropagation&&(c=!0),!0;y.preventDefault&&(y.stopPropagation&&(c=!0),h=!0)}return!1},d=n[i],p,m;return d&&(u(d[l+pn(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(E.windows&&e.ctrlKey&&e.altKey)&&!(E.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=At[e.keyCode])&&p!=s?(u(d[l+pn(p,e,!0)])||e.shiftKey&&(m=Ri[e.keyCode])!=s&&m!=p&&u(d[l+pn(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+pn(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),Er=null,a}class Qi{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=Ih(e);return[new Qi(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Ed(e,t,i)}}function Ih(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==te.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function bl(n,e,t,i){let s=n.coordsAtPos(e,t*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Ed(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==te.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=Ih(n),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=Cr(n,i,1),p=Cr(n,s,-1),m=d.type==xe.Text?d:null,y=p.type==xe.Text?p:null;if(m&&(n.lineWrapping||d.widgetLineBreaks)&&(m=bl(n,i,1,m)),y&&(n.lineWrapping||p.widgetLineBreaks)&&(y=bl(n,s,-1,y)),m&&y&&m.from==y.from&&m.to==y.to)return A(S(t.from,t.to,m));{let C=m?S(t.from,null,m):O(d,!1),M=y?S(null,t.to,y):O(p,!0),v=[];return(m||d).to<(y||p).from-(m&&y?1:0)||d.widgetLineBreaks>1&&C.bottom+n.defaultLineHeight/2<M.top?v.push(b(f,C.bottom,u,M.top)):C.bottom<M.top&&n.elementAtHeight((C.bottom+M.top)/2).type==xe.Text&&(C.bottom=M.top=(C.bottom+M.top)/2),A(C).concat(v).concat(A(M))}function b(C,M,v,W){return new Qi(e,C-a.left,M-a.top,v-C,W-M)}function A({top:C,bottom:M,horizontal:v}){let W=[];for(let R=0;R<v.length;R+=2)W.push(b(v[R],C,v[R+1],M));return W}function S(C,M,v){let W=1e9,R=-1e9,_=[];function H(z,Y,ie,re,pe){let X=n.coordsAtPos(z,z==v.to?-2:2),oe=n.coordsAtPos(ie,ie==v.from?2:-2);!X||!oe||(W=Math.min(X.top,oe.top,W),R=Math.max(X.bottom,oe.bottom,R),pe==te.LTR?_.push(r&&Y?f:X.left,r&&re?u:oe.right):_.push(!r&&re?f:oe.left,!r&&Y?u:X.right))}let L=C??v.from,F=M??v.to;for(let z of n.visibleRanges)if(z.to>L&&z.from<F)for(let Y=Math.max(z.from,L),ie=Math.min(z.to,F);;){let re=n.state.doc.lineAt(Y);for(let pe of n.bidiSpans(re)){let X=pe.from+re.from,oe=pe.to+re.from;if(X>=ie)break;oe>Y&&H(Math.max(X,Y),C==null&&X<=L,Math.min(oe,ie),M==null&&oe>=F,pe.dir)}if(Y=re.to+1,Y>=ie)break}return _.length==0&&H(L,C==null,F,M==null,n.textDirection),{top:W,bottom:R,horizontal:_}}function O(C,M){let v=l.top+(M?C.top:C.bottom);return{top:v,bottom:v,horizontal:[]}}}function Bd(n,e){return n.constructor==e.constructor&&n.eq(e)}class Rd{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Bn)!=e.state.facet(Bn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(Bn);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!Bd(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e,E.safari&&E.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Bn=B.define();function Nh(n){return[he.define(e=>new Rd(e,n)),Bn.of(n)]}const Hi=B.define({combine(n){return ht(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Ld(n={}){return[Hi.of(n),Pd,Id,Nd,oh.of(!0)]}function Wh(n){return n.startState.facet(Hi)!=n.state.facet(Hi)}const Pd=Nh({above:!0,markers(n){let{state:e}=n,t=e.facet(Hi),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:w.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Qi.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Wh(n);return t&&xl(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){xl(e.state,n)},class:"cm-cursorLayer"});function xl(n,e){e.style.animationDuration=n.facet(Hi).cursorBlinkRate+"ms"}const Id=Nh({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:Qi.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||Wh(n)},class:"cm-selectionLayer"}),Nd=qt.highest(D.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),Hh=q.define({map(n,e){return n==null?null:e.mapPos(n)}}),vi=we.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(Hh)?i.value:t,n)}}),Wd=he.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(vi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(vi)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(vi),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(vi)!=n&&this.view.dispatch({effects:Hh.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Hd(){return[vi,Wd]}function wl(n,e,t,i,s){e.lastIndex=0;for(let r=n.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function Fd(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let i=[];for(let{from:s,to:r}of t)s=Math.max(n.state.doc.lineAt(s).from,s-e),r=Math.min(n.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class Vd{constructor(e){const{regexp:t,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,h,c)=>s(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new dt,i=t.add.bind(t);for(let{from:s,to:r}of Fd(e,this.maxLength))wl(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>=e.view.viewport.from&&l<=e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),e.viewportMoved||s-i>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>=o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(r.from,a.from),f=Math.min(r.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let u=[],d,p=(m,y,b)=>u.push(b.range(m,y));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else wl(e.state.doc,this.regexp,c,f,(m,y)=>this.addMatch(y,e,m,p));t=t.update({filterFrom:c,filterTo:f,filter:(m,y)=>m<c||y>f,add:u})}}return t}}const Br=/x/.unicode!=null?"gu":"g",zd=new RegExp(`[\0-\b
--­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF￹-￼]`,Br),qd={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Ls=null;function _d(){var n;if(Ls==null&&typeof document<"u"&&document.body){let e=document.body.style;Ls=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return Ls||!1}const Rn=B.define({combine(n){let e=ht(n,{render:null,specialChars:zd,addSpecialChars:null});return(e.replaceTabs=!_d())&&(e.specialChars=new RegExp("	|"+e.specialChars.source,Br)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Br)),e}});function $d(n={}){return[Rn.of(n),jd()]}let vl=null;function jd(){return vl||(vl=he.fromClass(class{constructor(n){this.view=n,this.decorations=P.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(Rn)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Vd({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=De(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=hi(o.text,l,i-o.from);return P.replace({widget:new Yd((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=P.replace({widget:new Gd(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(Rn);n.startState.facet(Rn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const Kd="•";function Ud(n){return n>=32?Kd:n==10?"␤":String.fromCharCode(9216+n)}class Gd extends ct{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Ud(this.code),i=e.state.phrase("Control character")+" "+(qd[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Yd extends ct{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent="	",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function Jd(){return Qd}const Xd=P.line({class:"cm-activeLine"}),Qd=he.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push(Xd.range(s.from)),e=s.from)}return P.set(t)}},{decorations:n=>n.decorations});class Zd extends ct{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?Ci(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),s=Ii(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function ep(n){let e=he.fromClass(class{constructor(t){this.view=t,this.placeholder=n?P.set([P.widget({widget:new Zd(n),side:1}).range(0)]):P.none}get decorations(){return this.view.state.doc.length?P.none:this.placeholder}},{decorations:t=>t.decorations});return typeof n=="string"?[e,D.contentAttributes.of({"aria-placeholder":n})]:e}const Rr=2e3;function tp(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>Rr||t.off>Rr||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&r.push(w.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=fr(h.text,o,n.tabSize,!0);if(c<0)r.push(w.cursor(h.to));else{let f=fr(h.text,l,n.tabSize);r.push(w.range(h.from+c,h.from+f))}}}return r}function ip(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function kl(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=n.state.doc.lineAt(t),s=t-i.from,r=s>Rr?-1:s==i.length?ip(n,e.clientX):hi(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function np(n,e){let t=kl(n,e),i=n.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=kl(n,s);if(!l)return i;let a=tp(n.state,t,l);return a.length?o?w.create(a.concat(i.ranges)):w.create(a):i}}:null}function sp(n){let e=(t=>t.altKey&&t.button==0);return D.mouseSelectionStyle.of((t,i)=>e(i)?np(t,i):null)}const rp={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},op={style:"cursor: crosshair"};function lp(n={}){let[e,t]=rp[n.key||"Alt"],i=he.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||t(s))},keyup(s){(s.keyCode==e||!t(s))&&this.set(!1)},mousemove(s){this.set(t(s))}}});return[i,D.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?op:null})]}const mn="-10000px";class Fh{constructor(e,t,i,s){this.facet=t,this.createTooltipView=i,this.removeTooltipView=s,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let h=r[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==h.create&&(c=f)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function ap(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Ps=B.define({combine:n=>{var e,t,i;return{position:E.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||ap}}}),Sl=new WeakMap,ho=he.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Ps);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Fh(n,co,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Ps);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=mn,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(E.safari){let o=r.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!r.offsetParent&&r.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let r=this.parent.getBoundingClientRect();r.width&&r.height&&(n=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),s=ro(this.view);return{visible:{left:i.left+s.left,top:i.top+s.top,right:i.right-s.right,bottom:i.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((r,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(r.pos):this.view.coordsAtPos(r.pos)}),size:this.manager.tooltipViews.map(({dom:r})=>r.getBoundingClientRect()),space:this.view.state.facet(Ps).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=n.pos[l],u=n.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(t.top,i.top)||f.top>=Math.min(t.bottom,i.bottom)||f.right<Math.max(t.left,i.left)-.1||f.left>Math.min(t.right,i.right)+.1)){c.style.top=mn;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,y=(e=Sl.get(h))!==null&&e!==void 0?e:u.bottom-u.top,b=h.offset||cp,A=this.view.textDirection==te.LTR,S=u.width>i.right-i.left?A?i.left:i.right-u.width:A?Math.max(i.left,Math.min(f.left-(d?14:0)+b.x,i.right-m)):Math.min(Math.max(i.left,f.left-m+(d?14:0)-b.x),i.right-m),O=this.above[l];!a.strictSide&&(O?f.top-y-p-b.y<i.top:f.bottom+y+p+b.y>i.bottom)&&O==i.bottom-f.bottom>f.top-i.top&&(O=this.above[l]=!O);let C=(O?f.top-i.top:i.bottom-f.bottom)-p;if(C<y&&h.resize!==!1){if(C<this.view.defaultLineHeight){c.style.top=mn;continue}Sl.set(h,y),c.style.height=(y=C)/r+"px"}else c.style.height&&(c.style.height="");let M=O?f.top-y-p-b.y:f.bottom+p+b.y,v=S+m;if(h.overlap!==!0)for(let W of o)W.left<v&&W.right>S&&W.top<M+y&&W.bottom>M&&(M=O?W.top-y-2-p:W.bottom+p+2);if(this.position=="absolute"?(c.style.top=(M-n.parent.top)/r+"px",Cl(c,(S-n.parent.left)/s)):(c.style.top=M/r+"px",Cl(c,S/s)),d){let W=f.left+(A?b.x:-b.x)-(S+14-7);d.style.left=W/s+"px"}h.overlap!==!0&&o.push({left:S,top:M,right:v,bottom:M+y}),c.classList.toggle("cm-tooltip-above",O),c.classList.toggle("cm-tooltip-below",!O),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=mn}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Cl(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}const hp=D.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),cp={x:0,y:0},co=B.define({enables:[ho,hp]}),jn=B.define({combine:n=>n.reduce((e,t)=>e.concat(t),[])});class fs{static create(e){return new fs(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Fh(e,jn,(t,i)=>this.createHostedView(t,i),t=>t.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let s=i[e];if(s!==void 0){if(t===void 0)t=s;else if(t!==s)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const fp=co.compute([jn],n=>{let e=n.facet(jn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var i;return(i=t.end)!==null&&i!==void 0?i:t.pos})),create:fs.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class up{constructor(e,t,i,s,r){this.view=e,this.source=t,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.tile.nearest(t.target);if(!i)return;let s,r=1;if(i.isWidget())s=i.posAtStart;else{if(s=e.posAtCoords(t),s==null)return;let l=e.coordsAtPos(s);if(!l||t.y<l.top||t.y>l.bottom||t.x<l.left-e.defaultCharacterWidth||t.x>l.right+e.defaultCharacterWidth)return;let a=e.bidiSpans(e.state.doc.lineAt(s)).find(c=>c.from<=s&&c.to>=s),h=a&&a.dir==te.RTL?-1:1;r=t.x<l.left?-h:h}let o=this.source(e,s,r);if(o!=null&&o.then){let l=this.pending={pos:s};o.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>Re(e.state,a,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(ho),t=e?e.manager.tooltips.findIndex(i=>i.create==fs.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:r}=this;if(s.length&&r&&!dp(r.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,l=(i=(t=s[0])===null||t===void 0?void 0:t.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!pp(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:i}=this;i&&i.dom.contains(e.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const gn=4;function dp(n,e){let{left:t,right:i,top:s,bottom:r}=n.getBoundingClientRect(),o;if(o=n.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();s=Math.min(l.top,s),r=Math.max(l.bottom,r)}return e.clientX>=t-gn&&e.clientX<=i+gn&&e.clientY>=s-gn&&e.clientY<=r+gn}function pp(n,e,t,i,s,r){let o=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(o.left>i||o.right<i||o.top>s||Math.min(o.bottom,l)<s)return!1;let a=n.posAtCoords({x:i,y:s},!1);return a>=e&&a<=t}function mp(n,e={}){let t=q.define(),i=we.define({create(){return[]},update(s,r){if(s.length&&(e.hideOnChange&&(r.docChanged||r.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(r,o))),r.docChanged)){let o=[];for(let l of s){let a=r.changes.mapPos(l.pos,-1,Me.TrackDel);if(a!=null){let h=Object.assign(Object.create(null),l);h.pos=a,h.end!=null&&(h.end=r.changes.mapPos(h.end)),o.push(h)}}s=o}for(let o of r.effects)o.is(t)&&(s=o.value),o.is(gp)&&(s=[]);return s},provide:s=>jn.from(s)});return{active:i,extension:[i,he.define(s=>new up(s,n,i,t,e.hoverTime||300)),fp]}}function Vh(n,e){let t=n.plugin(ho);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const gp=q.define(),Al=B.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Fi(n,e){let t=n.plugin(zh),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const zh=he.fromClass(class{constructor(n){this.input=n.state.facet(Vi),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Al);this.top=new yn(n,!0,e.topContainer),this.bottom=new yn(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(Al);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new yn(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new yn(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Vi);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>D.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class yn{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Ml(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Ml(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Ml(n){let e=n.nextSibling;return n.remove(),e}const Vi=B.define({enables:zh});class mt extends St{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}mt.prototype.elementClass="";mt.prototype.toDOM=void 0;mt.prototype.mapMode=Me.TrackBefore;mt.prototype.startSide=mt.prototype.endSide=-1;mt.prototype.point=!0;const Ln=B.define(),yp=B.define(),bp={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>j.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Ti=B.define();function xp(n){return[qh(),Ti.of({...bp,...n})]}const Tl=B.define({combine:n=>n.some(e=>e)});function qh(n){return[wp]}const wp=he.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Ti).map(e=>new Dl(n,e)),this.fixed=!n.state.facet(Tl);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Tl)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=j.iter(this.view.state.facet(Ln),this.view.viewport.from),i=[],s=this.gutters.map(r=>new vp(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==xe.Text&&o){Lr(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==xe.Text){Lr(t,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(Ti),t=n.state.facet(Ti),i=n.docChanged||n.heightChanged||n.viewportChanged||!j.eq(n.startState.facet(Ln),n.state.facet(Ln),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new Dl(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>D.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,s=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==te.LTR?{left:i,right:s}:{right:i,left:s}})});function Ol(n){return Array.isArray(n)?n:[n]}function Lr(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class vp{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=j.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new _h(e,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];Lr(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),s=i?[i]:null;for(let r of e.state.facet(yp)){let o=r(e,t.widget,t);o&&(s||(s=[])).push(o)}s&&this.addElement(e,t,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Dl{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=Ol(t.markers(e)),t.initialSpacer&&(this.spacer=new _h(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Ol(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!j.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class _h{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),kp(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function kp(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const Sp=B.define(),Cp=B.define(),Kt=B.define({combine(n){return ht(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let s in t){let r=i[s],o=t[s];i[s]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class Is extends mt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Ns(n,e){return n.state.facet(Kt).formatNumber(e,n.state)}const Ap=Ti.compute([Kt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(Sp)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new Is(Ns(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let s of e.state.facet(Cp)){let r=s(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Kt)!=e.state.facet(Kt),initialSpacer(e){return new Is(Ns(e,El(e.state.doc.lines)))},updateSpacer(e,t){let i=Ns(t.view,El(t.view.state.doc.lines));return i==e.number?e:new Is(i)},domEventHandlers:n.facet(Kt).domEventHandlers,side:"before"}));function Mp(n={}){return[Kt.of(n),qh(),Ap]}function El(n){let e=9;for(;e<n;)e=e*10+9;return e}const Tp=new class extends mt{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Op=Ln.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(Tp.range(s)))}return j.of(e)});function Dp(){return Op}const Ep=1024;let Bp=0;class Ws{constructor(e,t){this.from=e,this.to=t}}class U{constructor(e={}){this.id=Bp++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=We.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}U.closedBy=new U({deserialize:n=>n.split(" ")});U.openedBy=new U({deserialize:n=>n.split(" ")});U.group=new U({deserialize:n=>n.split(" ")});U.isolate=new U({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});U.contextHash=new U({perNode:!0});U.lookAhead=new U({perNode:!0});U.mounted=new U({perNode:!0});class Oi{constructor(e,t,i,s=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=s}static get(e){return e&&e.props&&e.props[U.mounted.id]}}const Rp=Object.create(null);class We{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Rp,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new We(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(U.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(U.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}}We.none=new We("",Object.create(null),0,8);class $h{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let r of e){let o=r(i);if(o){s||(s=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in s&&(l=a.combine(s[a.id],l)),s[a.id]=l}}t.push(s?new We(i.name,s,i.id,i.flags):i)}return new $h(t)}}const bn=new WeakMap,Bl=new WeakMap;var ae;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(ae||(ae={}));class be{constructor(e,t,i,s,r){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Oi.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Ir(this.topNode,e)}cursorAt(e,t=0,i=0){let s=bn.get(this)||this.topNode,r=new Ir(s);return r.moveTo(e,t),bn.set(this,r._tree),r}get topNode(){return new qe(this,0,0,null)}resolve(e,t=0){let i=zi(bn.get(this)||this.topNode,e,t,!1);return bn.set(this,i),i}resolveInner(e,t=0){let i=zi(Bl.get(this)||this.topNode,e,t,!0);return Bl.set(this,i),i}resolveStack(e,t=0){return Ip(this,e,t)}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e,o=e.mode||0,l=(o&ae.IncludeAnonymous)>0;for(let a=this.cursor(o|ae.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:po(We.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new be(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new be(We.none,t,i,s)))}static build(e){return Np(e)}}be.empty=new be(We.none,[],[],0);class fo{constructor(e,t){this.buffer=e,this.index=t}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 fo(this.buffer,this.index)}}class Tt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return We.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,s,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(jh(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=s[l++],r[a++]=s[l++]-i;let h=r[a++]=s[l++]-i;r[a++]=s[l++]-e,o=Math.max(o,h)}return new Tt(r,o,this.set)}}function jh(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function zi(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof qe&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:ae.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof qe&&o.index<0&&((s=l.enter(e,t,r))===null||s===void 0?void 0:s.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,r);if(!o)return n;n=o}}class Kh{cursor(e=0){return new Ir(this,e)}getChild(e,t=null,i=null){let s=Rl(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return Rl(this,e,t,i)}resolve(e,t=0){return zi(this,e,t,!1)}resolveInner(e,t=0){return zi(this,e,t,!0)}matchContext(e){return Pr(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let s=t.lastChild;if(!s||s.to!=t.to)break;s.type.isError&&s.from==s.to?(i=t,t=s.prevSibling):t=s}return i}get node(){return this}get next(){return this.parent}}class qe extends Kh{constructor(e,t,i,s){super(),this._tree=e,this.from=t,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(e,t,i,s,r=0){var o;for(let l=this;;){for(let{children:a,positions:h}=l._tree,c=t>0?a.length:-1;e!=c;e+=t){let f=a[e],u=h[e]+l.from;if(!(!(r&ae.EnterBracketed&&f instanceof be&&((o=Oi.get(f))===null||o===void 0?void 0:o.overlay)===null&&(u>=i||u+f.length<=i))&&!jh(s,i,u,u+f.length))){if(f instanceof Tt){if(r&ae.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,t,i-u,s);if(d>-1)return new wt(new Lp(l,f,e,u),null,d)}else if(r&ae.IncludeAnonymous||!f.type.isAnonymous||uo(f)){let d;if(!(r&ae.IgnoreMounts)&&(d=Oi.get(f))&&!d.overlay)return new qe(d.tree,u,e,l);let p=new qe(f,u,e,l);return r&ae.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?f.children.length-1:0,t,i,s,r)}}}if(r&ae.IncludeAnonymous||!l.type.isAnonymous||(l.index>=0?e=l.index+t:e=t<0?-1:l._parent._tree.children.length,l=l._parent,!l))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let s;if(!(i&ae.IgnoreOverlays)&&(s=Oi.get(this._tree))&&s.overlay){let r=e-this.from,o=i&ae.EnterBracketed&&s.bracketed;for(let{from:l,to:a}of s.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new qe(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Rl(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=s.type.is(t),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function Pr(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class Lp{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}}class wt extends Kh{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(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new wt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&ae.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new wt(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new wt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new wt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];e.push(i.slice(s,r,o)),t.push(0)}return new be(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Uh(n){if(!n.length)return null;let e=0,t=n[0];for(let r=1;r<n.length;r++){let o=n[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof qe&&t.index<0?null:t.parent,s=n.slice();return i?s[e]=i:s.splice(e,1),new Pp(s,t)}class Pp{constructor(e,t){this.heads=e,this.node=t}get next(){return Uh(this.heads)}}function Ip(n,e,t){let i=n.resolveInner(e,t),s=null;for(let r=i instanceof qe?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(s||(s=[i])).push(o.resolve(e,t)),r=o}else{let o=Oi.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new qe(o.tree,o.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(zi(l,e,t,!1))}}return s?Uh(s):i}class Ir{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~ae.EnterBracketed,e instanceof qe)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof qe?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&ae.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&ae.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&ae.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&ae.IncludeAnonymous||l instanceof Tt||!l.type.isAnonymous||uo(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}for(let s=i;s<this.stack.length;s++)t=new wt(this.buffer,t,this.stack[s]);return this.bufferNode=new wt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&t&&t(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return Pr(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Pr(this._tree,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function uo(n){return n.children.some(e=>e instanceof Tt||!e.type.isAnonymous||uo(e))}function Np(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=Ep,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new fo(t,t.length):t,a=i.types,h=0,c=0;function f(C,M,v,W,R,_){let{id:H,start:L,end:F,size:z}=l,Y=c,ie=h;if(z<0)if(l.next(),z==-1){let g=r[H];v.push(g),W.push(L-C);return}else if(z==-3){h=H;return}else if(z==-4){c=H;return}else throw new RangeError(`Unrecognized record size: ${z}`);let re=a[H],pe,X,oe=L-C;if(F-L<=s&&(X=y(l.pos-M,R))){let g=new Uint16Array(X.size-X.skip),k=l.pos-X.size,I=g.length;for(;l.pos>k;)I=b(X.start,g,I);pe=new Tt(g,F-X.start,i),oe=X.start-C}else{let g=l.pos-z;l.next();let k=[],I=[],N=H>=o?H:-1,$=0,G=F;for(;l.pos>g;)N>=0&&l.id==N&&l.size>=0?(l.end<=G-s&&(p(k,I,L,$,l.end,G,N,Y,ie),$=k.length,G=l.end),l.next()):_>2500?u(L,g,k,I):f(L,g,k,I,N,_+1);if(N>=0&&$>0&&$<k.length&&p(k,I,L,$,L,G,N,Y,ie),k.reverse(),I.reverse(),N>-1&&$>0){let Q=d(re,ie);pe=po(re,k,I,0,k.length,0,F-L,Q,Q)}else pe=m(re,k,I,F-L,Y-F,ie)}v.push(pe),W.push(oe)}function u(C,M,v,W){let R=[],_=0,H=-1;for(;l.pos>M;){let{id:L,start:F,end:z,size:Y}=l;if(Y>4)l.next();else{if(H>-1&&F<H)break;H<0&&(H=z-s),R.push(L,F,z),_++,l.next()}}if(_){let L=new Uint16Array(_*4),F=R[R.length-2];for(let z=R.length-3,Y=0;z>=0;z-=3)L[Y++]=R[z],L[Y++]=R[z+1]-F,L[Y++]=R[z+2]-F,L[Y++]=Y;v.push(new Tt(L,R[2]-F,i)),W.push(F-C)}}function d(C,M){return(v,W,R)=>{let _=0,H=v.length-1,L,F;if(H>=0&&(L=v[H])instanceof be){if(!H&&L.type==C&&L.length==R)return L;(F=L.prop(U.lookAhead))&&(_=W[H]+L.length+F)}return m(C,v,W,R,_,M)}}function p(C,M,v,W,R,_,H,L,F){let z=[],Y=[];for(;C.length>W;)z.push(C.pop()),Y.push(M.pop()+v-R);C.push(m(i.types[H],z,Y,_-R,L-_,F)),M.push(R-v)}function m(C,M,v,W,R,_,H){if(_){let L=[U.contextHash,_];H=H?[L].concat(H):[L]}if(R>25){let L=[U.lookAhead,R];H=H?[L].concat(H):[L]}return new be(C,M,v,W,H)}function y(C,M){let v=l.fork(),W=0,R=0,_=0,H=v.end-s,L={size:0,start:0,skip:0};e:for(let F=v.pos-C;v.pos>F;){let z=v.size;if(v.id==M&&z>=0){L.size=W,L.start=R,L.skip=_,_+=4,W+=4,v.next();continue}let Y=v.pos-z;if(z<0||Y<F||v.start<H)break;let ie=v.id>=o?4:0,re=v.start;for(v.next();v.pos>Y;){if(v.size<0)if(v.size==-3||v.size==-4)ie+=4;else break e;else v.id>=o&&(ie+=4);v.next()}R=re,W+=z,_+=ie}return(M<0||W==C)&&(L.size=W,L.start=R,L.skip=_),L.size>4?L:void 0}function b(C,M,v){let{id:W,start:R,end:_,size:H}=l;if(l.next(),H>=0&&W<o){let L=v;if(H>4){let F=l.pos-(H-4);for(;l.pos>F;)v=b(C,M,v)}M[--v]=L,M[--v]=_-C,M[--v]=R-C,M[--v]=W}else H==-3?h=W:H==-4&&(c=W);return v}let A=[],S=[];for(;l.pos>0;)f(n.start||0,n.bufferStart||0,A,S,-1,0);let O=(e=n.length)!==null&&e!==void 0?e:A.length?S[0]+A[0].length:0;return new be(a[n.topID],A.reverse(),S.reverse(),O)}const Ll=new WeakMap;function Pn(n,e){if(!n.isAnonymous||e instanceof Tt||e.type!=n)return 1;let t=Ll.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof be)){t=1;break}t+=Pn(n,i)}Ll.set(e,t)}return t}function po(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=Pn(n,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,y,b,A){for(let S=y;S<b;){let O=S,C=m[S],M=Pn(n,p[S]);for(S++;S<b;S++){let v=Pn(n,p[S]);if(M+v>=c)break;M+=v}if(S==O+1){if(M>c){let v=p[O];d(v.children,v.positions,0,v.children.length,m[O]+A);continue}f.push(p[O])}else{let v=m[S-1]+p[S-1].length-C;f.push(po(n,p,m,O,S,C,v,null,a))}u.push(C+A-r)}}return d(e,t,i,s,0),(l||a)(f,u,o)}class Wt{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new Wt(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=i)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Wt(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&s.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}}class Wp{startParse(e,t,i){return typeof e=="string"&&(e=new Hp(e)),i=i?i.length?i.map(s=>new Ws(s.from,s.to)):[new Ws(0,0)]:[new Ws(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}}class Hp{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new U({perNode:!0});let Fp=0;class He{constructor(e,t,i,s){this.name=e,this.set=t,this.base=i,this.modified=s,this.id=Fp++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof He&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let s=new He(i,[],null,[]);if(s.set.push(s),t)for(let r of t.set)s.set.push(r);return s}static defineModifier(e){let t=new Kn(e);return i=>i.modified.indexOf(t)>-1?i:Kn.get(i.base||i,i.modified.concat(t).sort((s,r)=>s.id-r.id))}}let Vp=0;class Kn{constructor(e){this.name=e,this.instances=[],this.id=Vp++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&zp(t,l.modified));if(i)return i;let s=[],r=new He(e.name,s,e,t);for(let l of t)l.instances.push(r);let o=qp(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(Kn.get(l,a));return r}}function zp(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function qp(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function _p(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let f=0;;){if(l=="..."&&f>0&&f+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==s.length)break;let d=s[f++];if(f==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(f)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let c=new qi(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Gh.add(e)}const Gh=new U({combine(n,e){let t,i,s;for(;n||e;){if(!n||e&&n.depth>=e.depth?(s=e,e=e.next):(s=n,n=n.next),t&&t.mode==s.mode&&!s.context&&!t.context)continue;let r=new qi(s.tags,s.mode,s.context);t?t.next=r:i=r,t=r}return i}});class qi{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}qi.empty=new qi([],2,null);function Yh(n,e){let t=Object.create(null);for(let r of n)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:s=null}=e||{};return{style:r=>{let o=s;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function $p(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function jp(n,e,t,i=0,s=n.length){let r=new Kp(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class Kp{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,c=Up(e)||qi.empty,f=$p(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(U.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(y=>!y.scope||y.scope(u.tree.type)),m=e.firstChild();for(let y=0,b=l;;y++){let A=y<u.overlay.length?u.overlay[y]:null,S=A?A.from+l:a,O=Math.max(t,b),C=Math.min(i,S);if(O<C&&m)for(;e.from<C&&(this.highlightRange(e,O,C,s,r),this.startSpan(Math.min(C,e.to),h),!(e.to>=S||!e.nextSibling())););if(!A||S>i)break;b=A.to+l,b>t&&(this.highlightRange(d.cursor(),Math.max(t,A.from+l),Math.min(i,b),"",p),this.startSpan(Math.min(i,b),h))}m&&e.parent()}else if(e.firstChild()){u&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function Up(n){let e=n.type.prop(Gh);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const T=He.define,xn=T(),gt=T(),Pl=T(gt),Il=T(gt),yt=T(),wn=T(yt),Hs=T(yt),tt=T(),Et=T(tt),Ze=T(),et=T(),Nr=T(),mi=T(Nr),vn=T(),x={comment:xn,lineComment:T(xn),blockComment:T(xn),docComment:T(xn),name:gt,variableName:T(gt),typeName:Pl,tagName:T(Pl),propertyName:Il,attributeName:T(Il),className:T(gt),labelName:T(gt),namespace:T(gt),macroName:T(gt),literal:yt,string:wn,docString:T(wn),character:T(wn),attributeValue:T(wn),number:Hs,integer:T(Hs),float:T(Hs),bool:T(yt),regexp:T(yt),escape:T(yt),color:T(yt),url:T(yt),keyword:Ze,self:T(Ze),null:T(Ze),atom:T(Ze),unit:T(Ze),modifier:T(Ze),operatorKeyword:T(Ze),controlKeyword:T(Ze),definitionKeyword:T(Ze),moduleKeyword:T(Ze),operator:et,derefOperator:T(et),arithmeticOperator:T(et),logicOperator:T(et),bitwiseOperator:T(et),compareOperator:T(et),updateOperator:T(et),definitionOperator:T(et),typeOperator:T(et),controlOperator:T(et),punctuation:Nr,separator:T(Nr),bracket:mi,angleBracket:T(mi),squareBracket:T(mi),paren:T(mi),brace:T(mi),content:tt,heading:Et,heading1:T(Et),heading2:T(Et),heading3:T(Et),heading4:T(Et),heading5:T(Et),heading6:T(Et),contentSeparator:T(tt),list:T(tt),quote:T(tt),emphasis:T(tt),strong:T(tt),link:T(tt),monospace:T(tt),strikethrough:T(tt),inserted:T(),deleted:T(),changed:T(),invalid:T(),meta:vn,documentMeta:T(vn),annotation:T(vn),processingInstruction:T(vn),definition:He.defineModifier("definition"),constant:He.defineModifier("constant"),function:He.defineModifier("function"),standard:He.defineModifier("standard"),local:He.defineModifier("local"),special:He.defineModifier("special")};for(let n in x){let e=x[n];e instanceof He&&(e.name=n)}Yh([{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"}]);var Fs;const Ut=new U;function Gp(n){return B.define({combine:n?e=>e.concat(n):void 0})}const Yp=new U;class Ue{constructor(e,t,i=[],s=""){this.data=e,this.name=s,K.prototype.hasOwnProperty("tree")||Object.defineProperty(K.prototype,"tree",{get(){return Se(this)}}),this.parser=t,this.extension=[Ot.of(this),K.languageData.of((r,o,l)=>{let a=Nl(r,o,l),h=a.type.prop(Ut);if(!h)return[];let c=r.facet(h),f=a.type.prop(Yp);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return Nl(e,t,i).type.prop(Ut)==this.data}findRegions(e){let t=e.facet(Ot);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Ut)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(U.mounted);if(l){if(l.tree.prop(Ut)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof be&&s(h,r.positions[a]+o)}};return s(Se(e),0),i}get allowsNesting(){return!0}}Ue.setState=q.define();function Nl(n,e,t){let i=n.facet(Ot),s=Se(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,ae.ExcludeBuffers|ae.EnterBracketed))r.type.isTop&&(s=r);return s}class Wr extends Ue{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Gp(e.languageData);return new Wr(t,e.parser.configure({props:[Ut.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Wr(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Se(n){let e=n.field(Ue.state,!1);return e?e.tree:be.empty}class Jp{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let gi=null;class Un{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Un(e,t,[],be.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Jp(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=be.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Wt.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<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Wt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=gi;gi=this;try{return e()}finally{gi=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Wl(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Wt.applyChanges(i,a),s=be.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new Un(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=Wl(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Wp{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=gi;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new be(We.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return gi}}function Wl(n,e,t){return Wt.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class oi{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new oi(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Un.create(e.facet(Ot).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new oi(i)}}Ue.state=we.define({create:oi.init,update(n,e){for(let t of e.effects)if(t.is(Ue.setState))return t.value;return e.startState.facet(Ot)!=e.state.facet(Ot)?oi.init(e.state):n.apply(e)}});let Jh=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Jh=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Vs=typeof navigator<"u"&&(!((Fs=navigator.scheduling)===null||Fs===void 0)&&Fs.isInputPending)?()=>navigator.scheduling.isInputPending():null,Xp=he.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Ue.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Ue.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Jh(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Ue.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Vs?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>Vs&&Vs()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Ue.setState.of(new oi(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Re(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ot=B.define({combine(n){return n.length?n[0]:null},enables:n=>[Ue.state,Xp,D.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Zy{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Qp=B.define(),us=B.define({combine:n=>{if(!n.length)return"  ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Gn(n){let e=n.facet(us);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function _i(n,e){let t="",i=n.tabSize,s=n.facet(us)[0];if(s=="	"){for(;e>=i;)t+="	",e-=i;s=" "}for(let r=0;r<e;r++)t+=s;return t}function mo(n,e){n instanceof K&&(n=new ds(n));for(let i of n.state.facet(Qp)){let s=i(n,e);if(s!==void 0)return s}let t=Se(n.state);return t.length>=e?em(n,t,e):null}class ds{constructor(e,t={}){this.state=e,this.options=t,this.unit=Gn(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,t);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.countColumn(i,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return hi(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Zp=new U;function em(n,e,t){let i=e.resolveStack(t),s=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(s!=i.node){let r=[];for(let o=s;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Xh(i,n,t)}function Xh(n,e,t){for(let i=n;i;i=i.next){let s=im(i.node);if(s)return s(go.create(e,t,i))}return 0}function tm(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function im(n){let e=n.type.prop(Zp);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(U.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>om(o,!0,1,void 0,r&&!tm(o)?s.from:void 0)}return n.parent==null?nm:null}function nm(){return 0}class go extends ds{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new go(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(sm(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Xh(this.context.next,this.base,this.pos)}}function sm(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function rm(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function om(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=rm(n);return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}function eb({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const lm=200;function am(){return K.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+lm)return n;let r=t.sliceString(s.from,i);if(!e.some(h=>h.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let f=mo(o,c.from);if(f==null)continue;let u=/^\s*/.exec(c.text)[0],d=_i(o,f);u!=d&&a.push({from:c.from,to:c.from+u.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}const hm=B.define(),cm=new U;function tb(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function fm(n,e,t){let i=Se(n);if(i.length<t)return null;let s=i.resolveStack(t,1),r=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(r&&l.from<e)break;let a=l.type.prop(cm);if(a&&(l.to<i.length-50||i.length==n.doc.length||!um(l))){let h=a(l,n);h&&h.from<=t&&h.from>=e&&h.to>t&&(r=h)}}return r}function um(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function Yn(n,e,t){for(let i of n.facet(hm)){let s=i(n,e,t);if(s)return s}return fm(n,e,t)}function Qh(n,e){let t=e.mapPos(n.from,1),i=e.mapPos(n.to,-1);return t>=i?void 0:{from:t,to:i}}const ps=q.define({map:Qh}),Zi=q.define({map:Qh});function Zh(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(n.lineBlockAt(t));return e}const zt=we.define({create(){return P.none},update(n,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,i)=>n=Hl(n,t,i)),n=n.map(e.changes);for(let t of e.effects)if(t.is(ps)&&!dm(n,t.value.from,t.value.to)){let{preparePlaceholder:i}=e.state.facet(ic),s=i?P.replace({widget:new wm(i(e.state,t.value))}):Fl;n=n.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(Zi)&&(n=n.update({filter:(i,s)=>t.value.from!=i||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(n=Hl(n,e.selection.main.head)),n},provide:n=>D.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(i,s)=>{t.push(i,s)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let i=n[t++],s=n[t++];if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(Fl.range(i,s))}return P.set(e,!0)}});function Hl(n,e,t=e){let i=!1;return n.between(e,t,(s,r)=>{s<t&&r>e&&(i=!0)}),i?n.update({filterFrom:e,filterTo:t,filter:(s,r)=>s>=t||r<=e}):n}function Jn(n,e,t){var i;let s=null;return(i=n.field(zt,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!s||s.from>r)&&(s={from:r,to:o})}),s}function dm(n,e,t){let i=!1;return n.between(e,e,(s,r)=>{s==e&&r==t&&(i=!0)}),i}function ec(n,e){return n.field(zt,!1)?e:e.concat(q.appendConfig.of(nc()))}const pm=n=>{for(let e of Zh(n)){let t=Yn(n.state,e.from,e.to);if(t)return n.dispatch({effects:ec(n.state,[ps.of(t),tc(n,t)])}),!0}return!1},mm=n=>{if(!n.state.field(zt,!1))return!1;let e=[];for(let t of Zh(n)){let i=Jn(n.state,t.from,t.to);i&&e.push(Zi.of(i),tc(n,i,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function tc(n,e,t=!0){let i=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return D.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}const gm=n=>{let{state:e}=n,t=[];for(let i=0;i<e.doc.length;){let s=n.lineBlockAt(i),r=Yn(e,s.from,s.to);r&&t.push(ps.of(r)),i=(r?n.lineBlockAt(r.to):s).to+1}return t.length&&n.dispatch({effects:ec(n.state,t)}),!!t.length},ym=n=>{let e=n.state.field(zt,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(i,s)=>{t.push(Zi.of({from:i,to:s}))}),n.dispatch({effects:t}),!0},bm=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:pm},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:mm},{key:"Ctrl-Alt-[",run:gm},{key:"Ctrl-Alt-]",run:ym}],xm={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},ic=B.define({combine(n){return ht(n,xm)}});function nc(n){return[zt,Sm]}function sc(n,e){let{state:t}=n,i=t.facet(ic),s=o=>{let l=n.lineBlockAt(n.posAtDOM(o.target)),a=Jn(n.state,l.from,l.to);a&&n.dispatch({effects:Zi.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(n,s,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const Fl=P.replace({widget:new class extends ct{toDOM(n){return sc(n,null)}}});class wm extends ct{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return sc(e,this.value)}}const vm={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class zs extends mt{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function km(n={}){let e={...vm,...n},t=new zs(e,!0),i=new zs(e,!1),s=he.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Ot)!=o.state.facet(Ot)||o.startState.field(zt,!1)!=o.state.field(zt,!1)||Se(o.startState)!=Se(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new dt;for(let a of o.viewportLineBlocks){let h=Jn(o.state,a.from,a.to)?i:Yn(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:r}=e;return[s,xp({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||j.empty},initialSpacer(){return new zs(e,!1)},domEventHandlers:{...r,click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let h=Jn(o.state,l.from,l.to);if(h)return o.dispatch({effects:Zi.of(h)}),!0;let c=Yn(o.state,l.from,l.to);return c?(o.dispatch({effects:ps.of(c)}),!0):!1}}}),nc()]}const Sm=D.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class en{constructor(e,t){this.specs=e;let i;function s(l){let a=Ct.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Ue?l=>l.prop(Ut)==o.data:o?l=>l==o:void 0,this.style=Yh(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new Ct(i):null,this.themeType=t.themeType}static define(e,t){return new en(e,t||{})}}const Hr=B.define(),rc=B.define({combine(n){return n.length?[n[0]]:null}});function qs(n){let e=n.facet(Hr);return e.length?e:n.facet(rc)}function oc(n,e){let t=[Am],i;return n instanceof en&&(n.module&&t.push(D.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push(rc.of(n)):i?t.push(Hr.computeN([D.darkTheme],s=>s.facet(D.darkTheme)==(i=="dark")?[n]:[])):t.push(Hr.of(n)),t}class Cm{constructor(e){this.markCache=Object.create(null),this.tree=Se(e.state),this.decorations=this.buildDeco(e,qs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Se(e.state),i=qs(e.state),s=i!=qs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return P.none;let i=new dt;for(let{from:s,to:r}of e.visibleRanges)jp(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=P.mark({class:a})))},s,r);return i.finish()}}const Am=qt.high(he.fromClass(Cm,{decorations:n=>n.decorations})),Mm=en.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"}]),Tm=D.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),lc=1e4,ac="()[]{}",hc=B.define({combine(n){return ht(n,{afterCursor:!0,brackets:ac,maxScanDistance:lc,renderMatch:Em})}}),Om=P.mark({class:"cm-matchingBracket"}),Dm=P.mark({class:"cm-nonmatchingBracket"});function Em(n){let e=[],t=n.matched?Om:Dm;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const Bm=we.define({create(){return P.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(hc);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=rt(e.state,s.head,-1,i)||s.head>0&&rt(e.state,s.head-1,1,i)||i.afterCursor&&(rt(e.state,s.head,1,i)||s.head<e.state.doc.length&&rt(e.state,s.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return P.set(t,!0)},provide:n=>D.decorations.from(n)}),Rm=[Bm,Tm];function Lm(n={}){return[hc.of(n),Rm]}const Pm=new U;function Fr(n,e,t){let i=n.prop(e<0?U.openedBy:U.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Vr(n){let e=n.type.prop(Pm);return e?e(n.node):n}function rt(n,e,t,i={}){let s=i.maxScanDistance||lc,r=i.brackets||ac,o=Se(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Fr(a.type,t,r);if(h&&a.from<a.to){let c=Vr(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return Im(n,e,t,a,c,h,r)}}return Nm(n,e,t,o,l.type,s,r)}function Im(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},h=0,c=l==null?void 0:l.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let f=Vr(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Fr(c.type,t,o))h++;else if(Fr(c.type,-t,o)){if(h==0){let f=Vr(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function Nm(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,y=t>0?d.length:-1;m!=y;m+=t){let b=o.indexOf(d[m]);if(!(b<0||i.resolveInner(p+m,1).type!=s))if(b%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:b>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}const Wm=Object.create(null),Vl=[We.none],zl=[],ql=Object.create(null),Hm=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Hm[n]=Fm(Wm,e);function _s(n,e){zl.indexOf(n)>-1||(zl.push(n),console.warn(e))}function Fm(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=n[h]||x[h];c?typeof c=="function"?a.length?a=a.map(c):_s(h,`Modifier ${h} used at start of tag`):a.length?_s(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:_s(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=ql[s];if(r)return r.id;let o=ql[s]=We.define({id:Vl.length,name:i,props:[_p({[i]:t})]});return Vl.push(o),o.id}te.RTL,te.LTR;const Vm=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=bo(n.state,t.from);return i.line?zm(n):i.block?_m(n):!1};function yo(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}const zm=yo(Km,0),qm=yo(cc,0),_m=yo((n,e)=>cc(n,e,jm(e)),0);function bo(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const yi=50;function $m(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-yi,i),o=n.sliceDoc(s,s+yi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,f;s-i<=2*yi?c=f=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+yi),f=n.sliceDoc(s-yi,s));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function jm(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function cc(n,e,t=e.selection.ranges){let i=t.map(r=>bo(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>$m(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function Km(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9,h=bo(e,r).line;if(h){for(let c=r;c<=o;){let f=e.doc.lineAt(c);if(f.from>s&&(r==o||o>f.from)){s=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:h,indent:u,empty:d,single:!1})}c=f.to+1}if(a<1e9)for(let c=l;c<i.length;c++)i[c].indent<i[c].line.text.length&&(i[c].indent=a);i.length==l+1&&(i[l].single=!0)}}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}const zr=at.define(),Um=at.define(),Gm=B.define(),fc=B.define({combine(n){return ht(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),uc=we.define({create(){return ot.empty},update(n,e){let t=e.state.facet(fc),i=e.annotation(zr);if(i){let a=Le.fromTransaction(e,i.selection),h=i.side,c=h==0?n.undone:n.done;return a?c=Xn(c,c.length,t.minDepth,a):c=mc(c,e.startState.selection),new ot(h==0?i.rest:c,h==0?c:i.rest)}let s=e.annotation(Um);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(ue.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Le.fromTransaction(e),o=e.annotation(ue.time),l=e.annotation(ue.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new ot(n.done.map(Le.fromJSON),n.undone.map(Le.fromJSON))}});function Ym(n={}){return[uc,fc.of(n),D.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?dc:e.inputType=="historyRedo"?qr:null;return i?(e.preventDefault(),i(t)):!1}})]}function ms(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(uc,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}const dc=ms(0,!1),qr=ms(1,!1),Jm=ms(0,!0),Xm=ms(1,!0);class Le{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new Le(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new Le(e.changes&&ce.fromJSON(e.changes),[],e.mapped&&lt.fromJSON(e.mapped),e.startSelection&&w.fromJSON(e.startSelection),e.selectionsAfter.map(w.fromJSON))}static fromTransaction(e,t){let i=Ve;for(let s of e.startState.facet(Gm)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new Le(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ve)}static selection(e){return new Le(void 0,Ve,void 0,void 0,e)}}function Xn(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function Qm(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function Zm(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function pc(n,e){return n.length?e.length?n.concat(e):n:e}const Ve=[],eg=200;function mc(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-eg));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Xn(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Le.selection([e])]}function tg(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function $s(n,e){if(!n.length)return n;let t=n.length,i=Ve;for(;t;){let s=ig(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[Le.selection(i)]:Ve}function ig(n,e,t){let i=pc(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Ve,t);if(!n.changes)return Le.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Le(s,q.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const ng=/^(input\.type|delete)($|\.)/;class ot{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new ot(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||ng.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,Qm(l.changes,e.changes))||i=="input.type.compose")?o=Xn(o,o.length-1,s.minDepth,new Le(e.changes.compose(l.changes),pc(q.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ve)):o=Xn(o,o.length,s.minDepth,e),new ot(o,Ve,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ve;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Zm(r[r.length-1],e)?this:new ot(mc(this.done,e),this.undone,t,i)}addMapping(e){return new ot($s(this.done,e),$s(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||t.selection;if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:zr.of({side:e,rest:tg(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Ve:s.slice(0,s.length-1);return r.mapped&&(l=$s(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:zr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}ot.empty=new ot(Ve,Ve);const sg=[{key:"Mod-z",run:dc,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:qr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:qr,preventDefault:!0},{key:"Mod-u",run:Jm,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Xm,preventDefault:!0}];function ci(n,e){return w.create(n.ranges.map(e),n.mainIndex)}function Ye(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Je({state:n,dispatch:e},t){let i=ci(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Ye(n,i)),!0)}function gs(n,e){return w.cursor(e?n.to:n.from)}function gc(n,e){return Je(n,t=>t.empty?n.moveByChar(t,e):gs(t,e))}function Ce(n){return n.textDirectionAt(n.state.selection.main.head)==te.LTR}const yc=n=>gc(n,!Ce(n)),bc=n=>gc(n,Ce(n));function xc(n,e){return Je(n,t=>t.empty?n.moveByGroup(t,e):gs(t,e))}const rg=n=>xc(n,!Ce(n)),og=n=>xc(n,Ce(n));function lg(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function ys(n,e,t){let i=Se(n).resolveInner(e.head),s=t?U.closedBy:U.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;lg(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?rt(n,i.from,1):rt(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,w.cursor(l,t?-1:1)}const ag=n=>Je(n,e=>ys(n.state,e,!Ce(n))),hg=n=>Je(n,e=>ys(n.state,e,Ce(n)));function wc(n,e){return Je(n,t=>{if(!t.empty)return gs(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const vc=n=>wc(n,!1),kc=n=>wc(n,!0);function Sc(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,s;if(e){for(let r of n.state.facet(D.scrollMargins)){let o=r(n);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}s=n.scrollDOM.clientHeight-t-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,s-5)}}function Cc(n,e){let t=Sc(n),{state:i}=n,s=ci(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):gs(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=D.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Ye(i,s),{effects:r}),!0}const _l=n=>Cc(n,!1),_r=n=>Cc(n,!0);function Dt(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=w.cursor(i.from+r))}return s}const cg=n=>Je(n,e=>Dt(n,e,!0)),fg=n=>Je(n,e=>Dt(n,e,!1)),ug=n=>Je(n,e=>Dt(n,e,!Ce(n))),dg=n=>Je(n,e=>Dt(n,e,Ce(n))),pg=n=>Je(n,e=>w.cursor(n.lineBlockAt(e.head).from,1)),mg=n=>Je(n,e=>w.cursor(n.lineBlockAt(e.head).to,-1));function gg(n,e,t){let i=!1,s=ci(n.selection,r=>{let o=rt(n,r.head,-1)||rt(n,r.head,1)||r.head>0&&rt(n,r.head-1,1)||r.head<n.doc.length&&rt(n,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return w.cursor(l)});return i?(e(Ye(n,s)),!0):!1}const yg=({state:n,dispatch:e})=>gg(n,e);function $e(n,e){let t=ci(n.state.selection,i=>{let s=e(i);return w.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ye(n.state,t)),!0)}function Ac(n,e){return $e(n,t=>n.moveByChar(t,e))}const Mc=n=>Ac(n,!Ce(n)),Tc=n=>Ac(n,Ce(n));function Oc(n,e){return $e(n,t=>n.moveByGroup(t,e))}const bg=n=>Oc(n,!Ce(n)),xg=n=>Oc(n,Ce(n)),wg=n=>$e(n,e=>ys(n.state,e,!Ce(n))),vg=n=>$e(n,e=>ys(n.state,e,Ce(n)));function Dc(n,e){return $e(n,t=>n.moveVertically(t,e))}const Ec=n=>Dc(n,!1),Bc=n=>Dc(n,!0);function Rc(n,e){return $e(n,t=>n.moveVertically(t,e,Sc(n).height))}const $l=n=>Rc(n,!1),jl=n=>Rc(n,!0),kg=n=>$e(n,e=>Dt(n,e,!0)),Sg=n=>$e(n,e=>Dt(n,e,!1)),Cg=n=>$e(n,e=>Dt(n,e,!Ce(n))),Ag=n=>$e(n,e=>Dt(n,e,Ce(n))),Mg=n=>$e(n,e=>w.cursor(n.lineBlockAt(e.head).from)),Tg=n=>$e(n,e=>w.cursor(n.lineBlockAt(e.head).to)),Kl=({state:n,dispatch:e})=>(e(Ye(n,{anchor:0})),!0),Ul=({state:n,dispatch:e})=>(e(Ye(n,{anchor:n.doc.length})),!0),Gl=({state:n,dispatch:e})=>(e(Ye(n,{anchor:n.selection.main.anchor,head:0})),!0),Yl=({state:n,dispatch:e})=>(e(Ye(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),Og=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Dg=({state:n,dispatch:e})=>{let t=bs(n).map(({from:i,to:s})=>w.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:w.create(t),userEvent:"select"})),!0},Eg=({state:n,dispatch:e})=>{let t=ci(n.selection,i=>{let s=Se(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return w.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ye(n,t)),!0)};function Lc(n,e){let{state:t}=n,i=t.selection,s=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<n.state.doc.length:o.from>0)for(let l=r;;){let a=n.moveVertically(l,e);if(a.head<o.from||a.head>o.to){s.some(h=>h.head==a.head)||s.push(a);break}else{if(a.head==l.head)break;l=a}}}return s.length==i.ranges.length?!1:(n.dispatch(Ye(t,w.create(s,s.length-1))),!0)}const Bg=n=>Lc(n,!1),Rg=n=>Lc(n,!0),Lg=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=w.create([t.main]):t.main.empty||(i=w.create([w.cursor(t.main.head)])),i?(e(Ye(n,i)),!0):!1};function tn(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=kn(n,a,!1)):a>o&&(t="delete.forward",a=kn(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=kn(n,o,!1),l=kn(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?D.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function kn(n,e,t){if(n instanceof D)for(let i of n.state.facet(D.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const Pc=(n,e,t)=>tn(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]=="	")return s-1;let h=hi(l,r.tabSize),c=h%Gn(r)||Gn(r);for(let f=0;f<c&&l[l.length-1-f]==" ";f++)s--;a=s}else a=fe(o.text,s-o.from,e,e)+o.from,a==s&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=fe(o.text,a-o.from,!1,!1)+o.from);return a}),$r=n=>Pc(n,!1,!0),Ic=n=>Pc(n,!0,!1),Nc=(n,e)=>tn(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=fe(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t.head)&&(l=c),i=a}return i}),Wc=n=>Nc(n,!1),Pg=n=>Nc(n,!0),Ig=n=>tn(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),Ng=n=>tn(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),Wg=n=>tn(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),Hg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:J.of(["",""])},range:w.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Fg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:fe(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:fe(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:w.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function bs(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function Hc(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of bs(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(w.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(w.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:w.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Vg=({state:n,dispatch:e})=>Hc(n,e,!1),zg=({state:n,dispatch:e})=>Hc(n,e,!0);function Fc(n,e,t){if(n.readOnly)return!1;let i=[];for(let r of bs(n))t?i.push({from:r.from,insert:n.doc.slice(r.from,r.to)+n.lineBreak}):i.push({from:r.to,insert:n.lineBreak+n.doc.slice(r.from,r.to)});let s=n.changes(i);return e(n.update({changes:s,selection:n.selection.map(s,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const qg=({state:n,dispatch:e})=>Fc(n,e,!1),_g=({state:n,dispatch:e})=>Fc(n,e,!0),$g=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(bs(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=ci(e.selection,s=>{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function jg(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Se(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(U.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const Jl=Vc(!1),Kg=Vc(!0);function Vc(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&jg(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new ds(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=mo(h,r);for(c==null&&(c=hi(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",_i(e,c)];return a&&f.push(_i(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:J.of(f)},range:w.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function xo(n,e){let t=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Ug=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new ds(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=xo(n,(r,o,l)=>{let a=mo(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=_i(n,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},zc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(xo(n,(t,i)=>{i.push({from:t.from,insert:n.facet(us)})}),{userEvent:"input.indent"})),!0),qc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(xo(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=hi(s,n.tabSize),o=0,l=_i(n,Math.max(0,r-Gn(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Gg=n=>(n.setTabFocusMode(),!0),Yg=[{key:"Ctrl-b",run:yc,shift:Mc,preventDefault:!0},{key:"Ctrl-f",run:bc,shift:Tc},{key:"Ctrl-p",run:vc,shift:Ec},{key:"Ctrl-n",run:kc,shift:Bc},{key:"Ctrl-a",run:pg,shift:Mg},{key:"Ctrl-e",run:mg,shift:Tg},{key:"Ctrl-d",run:Ic},{key:"Ctrl-h",run:$r},{key:"Ctrl-k",run:Ig},{key:"Ctrl-Alt-h",run:Wc},{key:"Ctrl-o",run:Hg},{key:"Ctrl-t",run:Fg},{key:"Ctrl-v",run:_r}],Jg=[{key:"ArrowLeft",run:yc,shift:Mc,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:rg,shift:bg,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:ug,shift:Cg,preventDefault:!0},{key:"ArrowRight",run:bc,shift:Tc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:og,shift:xg,preventDefault:!0},{mac:"Cmd-ArrowRight",run:dg,shift:Ag,preventDefault:!0},{key:"ArrowUp",run:vc,shift:Ec,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Kl,shift:Gl},{mac:"Ctrl-ArrowUp",run:_l,shift:$l},{key:"ArrowDown",run:kc,shift:Bc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Ul,shift:Yl},{mac:"Ctrl-ArrowDown",run:_r,shift:jl},{key:"PageUp",run:_l,shift:$l},{key:"PageDown",run:_r,shift:jl},{key:"Home",run:fg,shift:Sg,preventDefault:!0},{key:"Mod-Home",run:Kl,shift:Gl},{key:"End",run:cg,shift:kg,preventDefault:!0},{key:"Mod-End",run:Ul,shift:Yl},{key:"Enter",run:Jl,shift:Jl},{key:"Mod-a",run:Og},{key:"Backspace",run:$r,shift:$r,preventDefault:!0},{key:"Delete",run:Ic,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Wc,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Pg,preventDefault:!0},{mac:"Mod-Backspace",run:Ng,preventDefault:!0},{mac:"Mod-Delete",run:Wg,preventDefault:!0}].concat(Yg.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Xg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:ag,shift:wg},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:hg,shift:vg},{key:"Alt-ArrowUp",run:Vg},{key:"Shift-Alt-ArrowUp",run:qg},{key:"Alt-ArrowDown",run:zg},{key:"Shift-Alt-ArrowDown",run:_g},{key:"Mod-Alt-ArrowUp",run:Bg},{key:"Mod-Alt-ArrowDown",run:Rg},{key:"Escape",run:Lg},{key:"Mod-Enter",run:Kg},{key:"Alt-l",mac:"Ctrl-l",run:Dg},{key:"Mod-i",run:Eg,preventDefault:!0},{key:"Mod-[",run:qc},{key:"Mod-]",run:zc},{key:"Mod-Alt-\\",run:Ug},{key:"Shift-Mod-k",run:$g},{key:"Shift-Mod-\\",run:yg},{key:"Mod-/",run:Vm},{key:"Alt-A",run:qm},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Gg}].concat(Jg),Qg={key:"Tab",run:zc,shift:qc},Xl=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class li{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(Xl(l)):Xl,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return De(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Gr(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=nt(e);let s=this.normalize(t);if(s.length)for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,i){let s=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:t,to:i}:this.matches.push(1,t)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(li.prototype[Symbol.iterator]=function(){return this});const _c={from:-1,to:-1,match:/.*/.exec("")},wo="gm"+(/x/.unicode==null?"":"u");class $c{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=_c,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new jc(e,t,i,s,r);this.re=new RegExp(t,wo+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=Qn(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=Qn(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const js=new WeakMap;class Zt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=js.get(e);if(!s||s.from>=i||s.to<=t){let l=new Zt(t,e.sliceString(t,i));return js.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<i&&(r+=e.sliceString(s.to,i)),js.set(e,new Zt(o,r)),new Zt(t,r.slice(t-o,i-o))}}class jc{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=_c,this.matchPos=Qn(e,s),this.re=new RegExp(t,wo+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Zt.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,s=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this.matchPos=Qn(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Zt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&($c.prototype[Symbol.iterator]=jc.prototype[Symbol.iterator]=function(){return this});function Zg(n){try{return new RegExp(n,wo),!0}catch{return!1}}function Qn(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}function jr(n){let e=String(n.state.doc.lineAt(n.state.selection.main.head).number),t=Z("input",{class:"cm-textfield",name:"line",value:e}),i=Z("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),n.dispatch({effects:Di.of(!1)}),n.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},Z("label",n.state.phrase("Go to line"),": ",t)," ",Z("button",{class:"cm-button",type:"submit"},n.state.phrase("go")),Z("button",{name:"close",onclick:()=>{n.dispatch({effects:Di.of(!1)}),n.focus()},"aria-label":n.state.phrase("close"),type:"button"},["×"]));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!r)return;let{state:o}=n,l=o.doc.lineAt(o.selection.main.head),[,a,h,c,f]=r,u=c?+c.slice(1):0,d=h?+h:l.number;if(h&&f){let y=d/100;a&&(y=y*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*y)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),m=w.cursor(p.from+Math.max(0,Math.min(u,p.length)));n.dispatch({effects:[Di.of(!1),D.scrollIntoView(m.from,{y:"center"})],selection:m}),n.focus()}return{dom:i}}const Di=q.define(),Ql=we.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(Di)&&(n=t.value);return n},provide:n=>Vi.from(n,e=>e?jr:null)}),e0=n=>{let e=Fi(n,jr);if(!e){let t=[Di.of(!0)];n.state.field(Ql,!1)==null&&t.push(q.appendConfig.of([Ql,t0])),n.dispatch({effects:t}),e=Fi(n,jr)}return e&&e.dom.querySelector("input").select(),!0},t0=D.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),i0={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},n0=B.define({combine(n){return ht(n,i0,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function s0(n){return[h0,a0]}const r0=P.mark({class:"cm-selectionMatch"}),o0=P.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Zl(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=se.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=se.Word)}function l0(n,e,t,i){return n(e.sliceDoc(t,t+1))==se.Word&&n(e.sliceDoc(i-1,i))==se.Word}const a0=he.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(n0),{state:t}=n,i=t.selection;if(i.ranges.length>1)return P.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return P.none;let a=t.wordAt(s.head);if(!a)return P.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return P.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Zl(o,t,s.from,s.to)&&l0(o,t,s.from,s.to)))return P.none}else if(r=t.sliceDoc(s.from,s.to),!r)return P.none}let l=[];for(let a of n.visibleRanges){let h=new li(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:f}=h.value;if((!o||Zl(o,t,c,f))&&(s.empty&&c<=s.from&&f>=s.to?l.push(o0.range(c,f)):(c>=s.to||f<=s.from)&&l.push(r0.range(c,f)),l.length>e.maxMatches))return P.none}}return P.set(l)}},{decorations:n=>n.decorations}),h0=D.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),c0=({state:n,dispatch:e})=>{let{selection:t}=n,i=w.create(t.ranges.map(s=>n.wordAt(s.head)||w.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function f0(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new li(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new li(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const u0=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return c0({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=f0(n,i);return s?(e(n.update({selection:n.selection.addRange(w.range(s.from,s.to),!1),effects:D.scrollIntoView(s.to)})),!0):!1},fi=B.define({combine(n){return ht(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new C0(e),scrollToMatch:e=>D.scrollIntoView(e)})}});class Kc{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Zg(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
`:i=="r"?"\r":i=="t"?"	":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new g0(this):new p0(this)}getCursor(e,t=0,i){let s=e.doc?e:K.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?$t(this,s,t,i):_t(this,s,t,i)}}class Uc{constructor(e){this.spec=e}}function _t(n,e,t,i){return new li(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?d0(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function d0(n,e){return(t,i,s,r)=>((r>t||r+s.length<i)&&(r=Math.max(0,t-2),s=n.sliceString(r,Math.min(n.length,i+2))),(e(Zn(s,t-r))!=se.Word||e(es(s,t-r))!=se.Word)&&(e(es(s,i-r))!=se.Word||e(Zn(s,i-r))!=se.Word))}class p0 extends Uc{constructor(e){super(e)}nextMatch(e,t,i){let s=_t(this.spec,e,i,e.doc.length).nextOverlapping();if(s.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);s=_t(this.spec,e,0,r).nextOverlapping()}return s.done||s.value.from==t&&s.value.to==i?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=_t(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){let s=this.prevMatchInRange(e,0,t);return s||(s=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=t||s.to!=i)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=_t(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=_t(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function $t(n,e,t,i){return new $c(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?m0(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function Zn(n,e){return n.slice(fe(n,e,!1),e)}function es(n,e){return n.slice(e,fe(n,e))}function m0(n){return(e,t,i)=>!i[0].length||(n(Zn(i.input,i.index))!=se.Word||n(es(i.input,i.index))!=se.Word)&&(n(es(i.input,i.index+i[0].length))!=se.Word||n(Zn(i.input,i.index+i[0].length))!=se.Word)}class g0 extends Uc{nextMatch(e,t,i){let s=$t(this.spec,e,i,e.doc.length).next();return s.done&&(s=$t(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let r=Math.max(t,i-s*1e4),o=$t(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let s=i.length;s>0;s--){let r=+i.slice(0,s);if(r>0&&r<e.match.length)return e.match[r]+i.slice(s)}return t})}matchAll(e,t){let i=$t(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=$t(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const $i=q.define(),vo=q.define(),kt=we.define({create(n){return new Ks(Kr(n).create(),null)},update(n,e){for(let t of e.effects)t.is($i)?n=new Ks(t.value.create(),n.panel):t.is(vo)&&(n=new Ks(n.query,t.value?ko:null));return n},provide:n=>Vi.from(n,e=>e.panel)});class Ks{constructor(e,t){this.query=e,this.panel=t}}const y0=P.mark({class:"cm-searchMatch"}),b0=P.mark({class:"cm-searchMatch cm-searchMatch-selected"}),x0=he.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(kt))}update(n){let e=n.state.field(kt);(e!=n.startState.field(kt)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return P.none;let{view:t}=this,i=new dt;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-500;)a=r[++s].to;n.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?b0:y0)})}return i.finish()}},{decorations:n=>n.decorations});function nn(n){return e=>{let t=e.state.field(kt,!1);return t&&t.query.spec.valid?n(e,t):Jc(e)}}const ts=nn((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let s=w.single(i.from,i.to),r=n.state.facet(fi);return n.dispatch({selection:s,effects:[So(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),Yc(n),!0}),is=nn((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);if(!s)return!1;let r=w.single(s.from,s.to),o=n.state.facet(fi);return n.dispatch({selection:r,effects:[So(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),Yc(n),!0}),w0=nn((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:w.create(t.map(i=>w.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),v0=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new li(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(w.range(l.value.from,l.value.to))}return e(n.update({selection:w.create(r,o),userEvent:"select.search.matches"})),!0},ea=nn((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=r,l=[],a,h,c=[];o.from==i&&o.to==s&&(h=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(t,o.from,o.to),c.push(D.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let f=n.state.changes(l);return o&&(a=w.single(o.from,o.to).map(f),c.push(So(n,o)),c.push(t.facet(fi).scrollToMatch(a.main,n))),n.dispatch({changes:f,selection:a,effects:c,userEvent:"input.replace"}),!0}),k0=nn((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(s=>{let{from:r,to:o}=s;return{from:r,to:o,insert:e.getReplacement(s)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:D.announce.of(i),userEvent:"input.replace.all"}),!0});function ko(n){return n.state.facet(fi).createPanel(n)}function Kr(n,e){var t,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=n.facet(fi);return new Kc({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:h.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Gc(n){let e=Fi(n,ko);return e&&e.dom.querySelector("[main-field]")}function Yc(n){let e=Gc(n);e&&e==n.root.activeElement&&e.select()}const Jc=n=>{let e=n.state.field(kt,!1);if(e&&e.panel){let t=Gc(n);if(t&&t!=n.root.activeElement){let i=Kr(n.state,e.query.spec);i.valid&&n.dispatch({effects:$i.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[vo.of(!0),e?$i.of(Kr(n.state,e.query.spec)):q.appendConfig.of(M0)]});return!0},Xc=n=>{let e=n.state.field(kt,!1);if(!e||!e.panel)return!1;let t=Fi(n,ko);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:vo.of(!1)}),!0},S0=[{key:"Mod-f",run:Jc,scope:"editor search-panel"},{key:"F3",run:ts,shift:is,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:ts,shift:is,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Xc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:v0},{key:"Mod-Alt-g",run:e0},{key:"Mod-d",run:u0,preventDefault:!0}];class C0{constructor(e){this.view=e;let t=this.query=e.state.field(kt).query.spec;this.commit=this.commit.bind(this),this.searchField=Z("input",{value:t.search,placeholder:Pe(e,"Find"),"aria-label":Pe(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Z("input",{value:t.replace,placeholder:Pe(e,"Replace"),"aria-label":Pe(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Z("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=Z("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=Z("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return Z("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=Z("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>ts(e),[Pe(e,"next")]),i("prev",()=>is(e),[Pe(e,"previous")]),i("select",()=>w0(e),[Pe(e,"all")]),Z("label",null,[this.caseField,Pe(e,"match case")]),Z("label",null,[this.reField,Pe(e,"regexp")]),Z("label",null,[this.wordField,Pe(e,"by word")]),...e.state.readOnly?[]:[Z("br"),this.replaceField,i("replace",()=>ea(e),[Pe(e,"replace")]),i("replaceAll",()=>k0(e),[Pe(e,"replace all")])],Z("button",{name:"close",onclick:()=>Xc(e),"aria-label":Pe(e,"close"),type:"button"},["×"])])}commit(){let e=new Kc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$i.of(e)}))}keydown(e){Td(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?is:ts)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),ea(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is($i)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(fi).top}}function Pe(n,e){return n.state.phrase(e)}const Sn=30,Cn=/[\s\.,:;?!]/;function So(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),s=n.state.doc.lineAt(t).to,r=Math.max(i.from,e-Sn),o=Math.min(s,t+Sn),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Sn;a++)if(!Cn.test(l[a+1])&&Cn.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-Sn;a--)if(!Cn.test(l[a-1])&&Cn.test(l[a])){l=l.slice(0,a);break}}return D.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const A0=D.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),M0=[kt,qt.low(x0),A0];class Qc{constructor(e,t,i,s){this.state=e,this.pos=t,this.explicit=i,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Se(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(Zc(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function ta(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function T0(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=ta(e)+ta(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function O0(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:T0(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}class ia{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}}function Ht(n){return n.selection.main.from}function Zc(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const ef=at.define();function D0(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return{...n.changeByRange(l=>{if(l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:a},range:w.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const na=new WeakMap;function E0(n){if(!Array.isArray(n))return n;let e=na.get(n);return e||na.set(n,e=O0(n)),e}const ns=q.define(),ji=q.define();class B0{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=De(e,t),s=nt(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(De(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let A=De(e,0),S=nt(A),O=S==e.length?0:-100;if(A!=t[0])if(A==i[0])O+=-200;else return null;return this.ret(O,[0,S])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let A=0,S=Math.min(e.length,200);A<S&&h<a;){let O=De(e,A);(O==t[h]||O==i[h])&&(s[h++]=A),A+=nt(O)}if(h<a)return null}let c=0,f=0,u=!1,d=0,p=-1,m=-1,y=/[a-z]/.test(e),b=!0;for(let A=0,S=Math.min(e.length,200),O=0;A<S&&f<a;){let C=De(e,A);l<0&&(c<a&&C==t[c]&&(r[c++]=A),d<a&&(C==t[d]||C==i[d]?(d==0&&(p=A),m=A+1,d++):d=0));let M,v=C<255?C>=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(M=Gr(C))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!A||v==1&&y||O==0&&v!=0)&&(t[f]==C||i[f]==C&&(u=!0)?o[f++]=A:o.length&&(b=!1)),O=v,A+=nt(C)}return f==a&&o[0]==0&&b?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(b?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?nt(De(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}}class R0{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const me=B.define({combine(n){return ht(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:L0,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>sa(e(i),t(i)),optionClass:(e,t)=>i=>sa(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function sa(n,e){return n?e?n+" "+e:n:e}function L0(n,e,t,i,s,r){let o=n.textDirection==te.RTL,l=o,a=!1,h="top",c,f,u=e.left-s.left,d=s.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))c=Math.max(s.top,Math.min(t.top,s.bottom-m))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:s.right-e.left)-30);let A=s.bottom-e.bottom;A>=m||A>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let y=(e.bottom-e.top)/r.offsetHeight,b=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${c/y}px; max-width: ${f/b}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function P0(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;h<r.length;){let c=r[h++],f=r[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Us(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class I0{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(me);this.optionContent=P0(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Us(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]<h.length){this.applyCompletion(e,h[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(me).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:ji.of(null)})}),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=Us(r.length,o,e.state.facet(me).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Us(t.options.length,t.selected,this.view.state.facet(me).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:s}=t.options[t.selected],{info:r}=s;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,s)}).catch(l=>Re(this.view.state,l,"completion info")):(this.addInfoPane(o,s),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&W0(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(me).positionInfo(this.view,t,s,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=s.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function N0(n,e){return t=>new I0(t,n,e)}function W0(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/s:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function ra(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function H0(n,e){let t=[],i=null,s=null,r=c=>{t.push(c);let{section:f}=c.completion;if(f){i||(i=[]);let u=typeof f=="string"?f:f.name;i.some(d=>d.name==u)||i.push(typeof f=="string"?{name:u}:f)}},o=e.facet(me);for(let c of n)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)r(new ia(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new R0(u):new B0(u);for(let m of c.result.options)if(d=p.match(m.label)){let y=m.displayLabel?f?f(m,d.matched):[]:d.matched,b=d.score+(m.boost||0);if(r(new ia(m,c.source,y,b)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:A}=m.section;s||(s=Object.create(null)),s[A]=Math.max(b,s[A]||-1e9)}}}}if(i){let c=Object.create(null),f=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?s[p.name]-s[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(u))f-=1e5,c[d.name]=f;for(let d of t){let{section:p}=d.completion;p&&(d.score+=c[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let c of t.sort((f,u)=>u.score-f.score||h(f.completion,u.completion))){let f=c.completion;!a||a.label!=f.label||a.detail!=f.detail||a.type!=null&&f.type!=null&&a.type!=f.type||a.apply!=f.apply||a.boost!=f.boost?l.push(c):ra(c.completion)>ra(a)&&(l[l.length-1]=c),a=c.completion}return l}class Gt{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Gt(this.options,oa(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r,o){if(s&&!o&&e.some(h=>h.isPending))return s.setDisabled();let l=H0(e,t);if(!l.length)return s&&e.some(h=>h.isPending)?s.setDisabled():null;let a=t.facet(me).selectOnOpen?0:-1;if(s&&s.selected!=a&&s.selected!=-1){let h=s.options[s.selected].completion;for(let c=0;c<l.length;c++)if(l[c].completion==h){a=c;break}}return new Gt(l,oa(i,a),{pos:e.reduce((h,c)=>c.hasResult()?Math.min(h,c.from):h,1e8),create:$0,above:r.aboveCursor},s?s.timestamp:Date.now(),a,!1)}map(e){return new Gt(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Gt(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class ss{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new ss(q0,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(me),r=(i.override||t.languageDataAt("autocomplete",Ht(t)).map(E0)).map(a=>(this.active.find(c=>c.source==a)||new ze(a,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((a,h)=>a==this.active[h])&&(r=this.active);let o=this.open,l=e.effects.some(a=>a.is(Co));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!F0(r,this.active)||l?o=Gt.build(r,t,this.id,o,i,l):o&&o.disabled&&!r.some(a=>a.isPending)&&(o=null),!o&&r.every(a=>!a.isPending)&&r.some(a=>a.hasResult())&&(r=r.map(a=>a.hasResult()?new ze(a.source,0):a));for(let a of e.effects)a.is(nf)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new ss(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?V0:z0}}function F0(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let s=t==n.length,r=i==e.length;if(s||r)return s==r;if(n[t++].result!=e[i++].result)return!1}}const V0={"aria-autocomplete":"list"},z0={};function oa(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const q0=[];function tf(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(ef);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class ze{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=tf(e,t),s=this;(i&8||i&16&&this.touches(e))&&(s=new ze(s.source,0)),i&4&&s.state==0&&(s=new ze(this.source,1)),s=s.updateFor(e,i);for(let r of e.effects)if(r.is(ns))s=new ze(s.source,1,r.value);else if(r.is(ji))s=new ze(s.source,0);else if(r.is(Co))for(let o of r.value)o.source==s.source&&(s=o);return s}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Ht(e.state))}}class ei extends ze{constructor(e,t,i,s,r,o){super(e,3,t),this.limit=i,this.result=s,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=Ht(e.state);if(l>o||!s||t&2&&(Ht(e.startState)==this.from||l<this.limit))return new ze(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return _0(s.validFor,e.state,r,o)?new ei(this.source,this.explicit,a,s,r,o):s.update&&(s=s.update(s,r,o,new Qc(e.state,l,!1)))?new ei(this.source,this.explicit,a,s,s.from,(i=s.to)!==null&&i!==void 0?i:Ht(e.state)):new ze(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new ei(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new ze(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function _0(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):Zc(n,!0).test(s)}const Co=q.define({map(n,e){return n.map(t=>t.map(e))}}),nf=q.define(),Ee=we.define({create(){return ss.start()},update(n,e){return n.update(e)},provide:n=>[co.from(n,e=>e.tooltip),D.contentAttributes.from(n,e=>e.attrs)]});function Ao(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(Ee).active.find(s=>s.source==e.source);return i instanceof ei?(typeof t=="string"?n.dispatch({...D0(n.state,t,i.from,i.to),annotations:ef.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}const $0=N0(Ee,Ao);function An(n,e="option"){return t=>{let i=t.state.field(Ee,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(me).interactionDelay)return!1;let s=1,r;e=="page"&&(r=Vh(t,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:nf.of(l)}),!0}}const j0=n=>{let e=n.state.field(Ee,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(me).interactionDelay?!1:Ao(n,e.open.options[e.open.selected])},Gs=n=>n.state.field(Ee,!1)?(n.dispatch({effects:ns.of(!0)}),!0):!1,K0=n=>{let e=n.state.field(Ee,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:ji.of(null)}),!0)};class U0{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const G0=50,Y0=1e3,J0=he.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(Ee).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(Ee),t=n.state.facet(me);if(!n.selectionSet&&!n.docChanged&&n.startState.field(Ee)==e)return;let i=n.transactions.some(r=>{let o=tf(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&n.docChanged||o.updates.length+n.transactions.length>G0&&Date.now()-o.time>Y0){for(let l of o.context.abortListeners)try{l()}catch(a){Re(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(r=>r.effects.some(o=>o.is(ns)))&&(this.pendingStart=!0);let s=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let r of n.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(Ee);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(me).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Ht(e),i=new Qc(e,t,n.explicit,this.view),s=new U0(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:ji.of(null)}),Re(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(me).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(me),i=this.view.state.field(Ee);for(let s=0;s<this.running.length;s++){let r=this.running[s];if(r.done===void 0)continue;if(this.running.splice(s--,1),r.done){let l=Ht(r.updates.length?r.updates[0].startState:this.view.state),a=Math.min(l,r.done.from+(r.active.explicit?0:1)),h=new ei(r.active.source,r.active.explicit,a,r.done,r.done.from,(n=r.done.to)!==null&&n!==void 0?n:l);for(let c of r.updates)h=h.update(c,t);if(h.hasResult()){e.push(h);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new ze(r.active.source,0);for(let a of r.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:Co.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(Ee,!1);if(e&&e.tooltip&&this.view.state.facet(me).closeOnBlur){let t=e.open&&Vh(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:ji.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ns.of(!1)}),20),this.composing=0}}}),X0=typeof navigator=="object"&&/Win/.test(navigator.platform),Q0=qt.highest(D.domEventHandlers({keydown(n,e){let t=e.state.field(Ee,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(X0&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],s=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(n.key)>-1&&Ao(e,i),!1}})),Z0=D.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),Ki={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Nt=q.define({map(n,e){let t=e.mapPos(n,-1,Me.TrackAfter);return t??void 0}}),Mo=new class extends St{};Mo.startSide=1;Mo.endSide=-1;const sf=we.define({create(){return j.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(Nt)&&(n=n.update({add:[Mo.range(t.value,t.value+1)]}));return n}});function ey(){return[iy,sf]}const Ys="()[]{}<>«»»«［］｛｝";function rf(n){for(let e=0;e<Ys.length;e+=2)if(Ys.charCodeAt(e)==n)return Ys.charAt(e+1);return Gr(n<128?n:n+1)}function of(n,e){return n.languageDataAt("closeBrackets",e)[0]||Ki}const ty=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),iy=D.inputHandler.of((n,e,t,i)=>{if((ty?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&nt(De(i,0))==1||e!=s.from||t!=s.to)return!1;let r=ry(n.state,i);return r?(n.dispatch(r),!0):!1}),ny=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=of(n,n.selection.main.head).brackets||Ki.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=oy(n.doc,o.head);for(let a of i)if(a==l&&xs(n.doc,o.head)==rf(De(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:w.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},sy=[{key:"Backspace",run:ny}];function ry(n,e){let t=of(n,n.selection.main.head),i=t.brackets||Ki.brackets;for(let s of i){let r=rf(De(s,0));if(e==s)return r==s?hy(n,s,i.indexOf(s+s+s)>-1,t):ly(n,s,r,t.before||Ki.before);if(e==r&&lf(n,n.selection.main.from))return ay(n,s,r)}return null}function lf(n,e){let t=!1;return n.field(sf).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function xs(n,e){let t=n.sliceString(e,e+2);return t.slice(0,nt(De(t,0)))}function oy(n,e){let t=n.sliceString(e-2,e);return nt(De(t,0))==t.length?t:t.slice(1)}function ly(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:Nt.of(o.to+e.length),range:w.range(o.anchor+e.length,o.head+e.length)};let l=xs(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:Nt.of(o.head+e.length),range:w.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function ay(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&xs(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:w.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function hy(n,e,t,i){let s=i.stringPrefixes||Ki.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:Nt.of(l.to+e.length),range:w.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=xs(n.doc,a),c;if(h==e){if(la(n,a))return{changes:{insert:e+e,from:a},effects:Nt.of(a+e.length),range:w.cursor(a+e.length)};if(lf(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:w.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(c=aa(n,a-2*e.length,s))>-1&&la(n,c))return{changes:{insert:e+e+e+e,from:a},effects:Nt.of(a+e.length),range:w.cursor(a+e.length)};if(n.charCategorizer(a)(h)!=se.Word&&aa(n,a,s)>-1&&!cy(n,a,e,s))return{changes:{insert:e+e,from:a},effects:Nt.of(a+e.length),range:w.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function la(n,e){let t=Se(n).resolveInner(e+1);return t.parent&&t.from==e}function cy(n,e,t,i){let s=Se(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let c=s.firstChild;for(;c&&c.from==s.from&&c.to-c.from>t.length+a;){if(n.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=s.to==e&&s.parent;if(!h)break;s=h}return!1}function aa(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=se.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=se.Word)return r}return-1}function fy(n={}){return[Q0,Ee,me.of(n),J0,uy,Z0]}const af=[{key:"Ctrl-Space",run:Gs},{mac:"Alt-`",run:Gs},{mac:"Alt-i",run:Gs},{key:"Escape",run:K0},{key:"ArrowDown",run:An(!0)},{key:"ArrowUp",run:An(!1)},{key:"PageDown",run:An(!0,"page")},{key:"PageUp",run:An(!1,"page")},{key:"Enter",run:j0}],uy=qt.highest(cs.computeN([me],n=>n.facet(me).defaultKeymap?[af]:[]));class ha{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Lt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let s=i.facet(Ui).markerFilter;s&&(e=s(e,i));let r=e.slice().sort((d,p)=>d.from-p.from||d.to-p.to),o=new dt,l=[],a=0,h=i.doc.iter(),c=0,f=i.doc.length;for(let d=0;;){let p=d==r.length?null:r[d];if(!p&&!l.length)break;let m,y;if(l.length)m=a,y=l.reduce((S,O)=>Math.min(S,O.to),p&&p.from>m?p.from:1e8);else{if(m=p.from,m>f)break;y=p.to,l.push(p),d++}for(;d<r.length;){let S=r[d];if(S.from==m&&(S.to>S.from||S.to==m))l.push(S),d++,y=Math.min(S.to,y);else{y=Math.min(S.from,y);break}}y=Math.min(y,f);let b=!1;if(l.some(S=>S.from==m&&(S.to==y||y==f))&&(b=m==y,!b&&y-m<10)){let S=m-(c+h.value.length);S>0&&(h.next(S),c=m);for(let O=m;;){if(O>=y){b=!0;break}if(!h.lineBreak&&c+h.value.length>O)break;O=c+h.value.length,c+=h.value.length,h.next()}}let A=Ay(l);if(b)o.add(m,m,P.widget({widget:new vy(A),diagnostics:l.slice()}));else{let S=l.reduce((O,C)=>C.markClass?O+" "+C.markClass:O,"");o.add(m,y,P.mark({class:"cm-lintRange cm-lintRange-"+A+S,diagnostics:l.slice(),inclusiveEnd:l.some(O=>O.to>y)}))}if(a=y,a==f)break;for(let S=0;S<l.length;S++)l[S].to<=a&&l.splice(S--,1)}let u=o.finish();return new Lt(u,t,ai(u))}}function ai(n,e=null,t=0){let i=null;return n.between(t,1e9,(s,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new ha(s,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new ha(i.from,r,i.diagnostic)}}),i}function dy(n,e){let t=e.pos,i=e.end||t,s=n.state.facet(Ui).hideOn(n,t,i);if(s!=null)return s;let r=n.startState.doc.lineAt(e.pos);return!!(n.effects.some(o=>o.is(hf))||n.changes.touchesRange(r.from,Math.max(r.to,i)))}function py(n,e){return n.field(Ne,!1)?e:e.concat(q.appendConfig.of(My))}const hf=q.define(),To=q.define(),cf=q.define(),Ne=we.define({create(){return new Lt(P.none,null,null)},update(n,e){if(e.docChanged&&n.diagnostics.size){let t=n.diagnostics.map(e.changes),i=null,s=n.panel;if(n.selected){let r=e.changes.mapPos(n.selected.from,1);i=ai(t,n.selected.diagnostic,r)||ai(t,null,r)}!t.size&&s&&e.state.facet(Ui).autoPanel&&(s=null),n=new Lt(t,s,i)}for(let t of e.effects)if(t.is(hf)){let i=e.state.facet(Ui).autoPanel?t.value.length?Gi.open:null:n.panel;n=Lt.init(t.value,i,e.state)}else t.is(To)?n=new Lt(n.diagnostics,t.value?Gi.open:null,n.selected):t.is(cf)&&(n=new Lt(n.diagnostics,n.panel,t.value));return n},provide:n=>[Vi.from(n,e=>e.panel),D.decorations.from(n,e=>e.diagnostics)]}),my=P.mark({class:"cm-lintRange cm-lintRange-active"});function gy(n,e,t){let{diagnostics:i}=n.state.field(Ne),s,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,h,{spec:c})=>{if(e>=a&&e<=h&&(a==h||(e>a||t>0)&&(e<h||t<0)))return s=c.diagnostics,r=a,o=h,!1});let l=n.state.facet(Ui).tooltipFilter;return s&&l&&(s=l(s,n.state)),s?{pos:r,end:o,above:n.state.doc.lineAt(r).to<o,create(){return{dom:yy(n,s)}}}:null}function yy(n,e){return Z("ul",{class:"cm-tooltip-lint"},e.map(t=>uf(n,t,!1)))}const by=n=>{let e=n.state.field(Ne,!1);(!e||!e.panel)&&n.dispatch({effects:py(n.state,[To.of(!0)])});let t=Fi(n,Gi.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},ca=n=>{let e=n.state.field(Ne,!1);return!e||!e.panel?!1:(n.dispatch({effects:To.of(!1)}),!0)},xy=n=>{let e=n.state.field(Ne,!1);if(!e)return!1;let t=n.state.selection.main,i=e.diagnostics.iter(t.to+1);return!i.value&&(i=e.diagnostics.iter(0),!i.value||i.from==t.from&&i.to==t.to)?!1:(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},wy=[{key:"Mod-Shift-m",run:by,preventDefault:!0},{key:"F8",run:xy}],Ui=B.define({combine(n){return{sources:n.map(e=>e.source).filter(e=>e!=null),...ht(n.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:fa,tooltipFilter:fa,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,s,r)=>e(i,s,r)||t(i,s,r):e:t,autoPanel:(e,t)=>e||t})}}});function fa(n,e){return n?e?(t,i)=>e(n(t,i),i):n:e}function ff(n){let e=[];if(n)e:for(let{name:t}of n){for(let i=0;i<t.length;i++){let s=t[i];if(/[a-zA-Z]/.test(s)&&!e.some(r=>r.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function uf(n,e,t){var i;let s=t?ff(e.actions):[];return Z("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Z("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(n):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=d=>{if(d.preventDefault(),l)return;l=!0;let p=ai(n.state.field(Ne).diagnostics,e);p&&r.apply(n,p.from,p.to)},{name:h}=r,c=s[o]?h.indexOf(s[o]):-1,f=c<0?h:[h.slice(0,c),Z("u",h.slice(c,c+1)),h.slice(c+1)],u=r.markClass?" "+r.markClass:"";return Z("button",{type:"button",class:"cm-diagnosticAction"+u,onclick:a,onmousedown:a,"aria-label":` Action: ${h}${c<0?"":` (access key "${s[o]})"`}.`},f)}),e.source&&Z("div",{class:"cm-diagnosticSource"},e.source))}class vy extends ct{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Z("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ua{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=uf(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Gi{constructor(e){this.view=e,this.items=[];let t=s=>{if(s.keyCode==27)ca(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=ff(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=ai(this.view.state.field(Ne).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()},i=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=Z("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=Z("div",{class:"cm-panel-lint"},this.list,Z("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>ca(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Ne).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Ne),i=0,s=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(l,a,{spec:h})=>{for(let c of h.diagnostics){if(o.has(c))continue;o.add(c);let f=-1,u;for(let d=i;d<this.items.length;d++)if(this.items[d].diagnostic==c){f=d;break}f<0?(u=new ua(this.view,c),this.items.splice(i,0,u),s=!0):(u=this.items[f],f>i&&(this.items.splice(i,f-i),s=!0)),t&&u.diagnostic==t.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new ua(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let h=a.height/this.list.offsetHeight;l.top<a.top?this.list.scrollTop-=(a.top-l.top)/h:l.bottom>a.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Ne),i=ai(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:cf.of(i)})}static open(e){return new Gi(e)}}function ky(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function Mn(n){return ky(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Sy=D.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Mn("#d11")},".cm-lintRange-warning":{backgroundImage:Mn("orange")},".cm-lintRange-info":{backgroundImage:Mn("#999")},".cm-lintRange-hint":{backgroundImage:Mn("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function Cy(n){return n=="error"?4:n=="warning"?3:n=="info"?2:1}function Ay(n){let e="hint",t=1;for(let i of n){let s=Cy(i.severity);s>t&&(t=s,e=i.severity)}return e}const My=[Ne,D.decorations.compute([Ne],n=>{let{selected:e,panel:t}=n.field(Ne);return!e||!t||e.from==e.to?P.none:P.set([my.range(e.from,e.to)])}),mp(gy,{hideOn:dy}),Sy];var da=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,i=[];e.closeBracketsKeymap!==!1&&(i=i.concat(sy)),e.defaultKeymap!==!1&&(i=i.concat(Xg)),e.searchKeymap!==!1&&(i=i.concat(S0)),e.historyKeymap!==!1&&(i=i.concat(sg)),e.foldKeymap!==!1&&(i=i.concat(bm)),e.completionKeymap!==!1&&(i=i.concat(af)),e.lintKeymap!==!1&&(i=i.concat(wy));var s=[];return e.lineNumbers!==!1&&s.push(Mp()),e.highlightActiveLineGutter!==!1&&s.push(Dp()),e.highlightSpecialChars!==!1&&s.push($d()),e.history!==!1&&s.push(Ym()),e.foldGutter!==!1&&s.push(km()),e.drawSelection!==!1&&s.push(Ld()),e.dropCursor!==!1&&s.push(Hd()),e.allowMultipleSelections!==!1&&s.push(K.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(am()),e.syntaxHighlighting!==!1&&s.push(oc(Mm,{fallback:!0})),e.bracketMatching!==!1&&s.push(Lm()),e.closeBrackets!==!1&&s.push(ey()),e.autocompletion!==!1&&s.push(fy()),e.rectangularSelection!==!1&&s.push(sp()),t!==!1&&s.push(lp()),e.highlightActiveLine!==!1&&s.push(Jd()),e.highlightSelectionMatches!==!1&&s.push(s0()),e.tabSize&&typeof e.tabSize=="number"&&s.push(us.of(" ".repeat(e.tabSize))),s.concat([cs.of(i.flat())]).filter(Boolean)};const Ty="#e5c07b",pa="#e06c75",Oy="#56b6c2",Dy="#ffffff",In="#abb2bf",Ur="#7d8799",Ey="#61afef",By="#98c379",ma="#d19a66",Ry="#c678dd",Ly="#21252b",ga="#2c313a",ya="#282c34",Js="#353a42",Py="#3E4451",ba="#528bff",Iy=D.theme({"&":{color:In,backgroundColor:ya},".cm-content":{caretColor:ba},".cm-cursor, .cm-dropCursor":{borderLeftColor:ba},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Py},".cm-panels":{backgroundColor:Ly,color:In},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:ya,color:Ur,border:"none"},".cm-activeLineGutter":{backgroundColor:ga},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Js},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Js,borderBottomColor:Js},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:ga,color:In}}},{dark:!0}),Ny=en.define([{tag:x.keyword,color:Ry},{tag:[x.name,x.deleted,x.character,x.propertyName,x.macroName],color:pa},{tag:[x.function(x.variableName),x.labelName],color:Ey},{tag:[x.color,x.constant(x.name),x.standard(x.name)],color:ma},{tag:[x.definition(x.name),x.separator],color:In},{tag:[x.typeName,x.className,x.number,x.changed,x.annotation,x.modifier,x.self,x.namespace],color:Ty},{tag:[x.operator,x.operatorKeyword,x.url,x.escape,x.regexp,x.link,x.special(x.string)],color:Oy},{tag:[x.meta,x.comment],color:Ur},{tag:x.strong,fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.link,color:Ur,textDecoration:"underline"},{tag:x.heading,fontWeight:"bold",color:pa},{tag:[x.atom,x.bool,x.special(x.variableName)],color:ma},{tag:[x.processingInstruction,x.string,x.inserted],color:By},{tag:x.invalid,color:Dy}]),Wy=[Iy,oc(Ny)];var Hy=D.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),Fy=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:i=!0,readOnly:s=!1,theme:r="light",placeholder:o="",basicSetup:l=!0}=e,a=[];switch(t&&a.unshift(cs.of([Qg])),l&&(typeof l=="boolean"?a.unshift(da()):a.unshift(da(l))),o&&a.unshift(ep(o)),r){case"light":a.push(Hy);break;case"dark":a.push(Wy);break;case"none":break;default:a.push(r);break}return i===!1&&a.push(D.editable.of(!1)),s&&a.push(K.readOnly.of(!0)),[...a]},Vy=n=>({line:n.state.doc.lineAt(n.state.selection.main.from),lineCount:n.state.doc.lines,lineBreak:n.state.lineBreak,length:n.state.doc.length,readOnly:n.state.readOnly,tabSize:n.state.tabSize,selection:n.state.selection,selectionAsSingle:n.state.selection.asSingle().main,ranges:n.state.selection.ranges,selectionCode:n.state.sliceDoc(n.state.selection.main.from,n.state.selection.main.to),selections:n.state.selection.ranges.map(e=>n.state.sliceDoc(e.from,e.to)),selectedText:n.state.selection.ranges.some(e=>!e.empty)});class zy{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(t=>{try{t()}catch(i){console.error("TimeoutLatch callback error:",i)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class xa{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var Xs=null,qy=()=>typeof window>"u"?new xa:(Xs||(Xs=new xa),Xs),wa=at.define(),_y=200,$y=[];function jy(n){var{value:e,selection:t,onChange:i,onStatistics:s,onCreateEditor:r,onUpdate:o,extensions:l=$y,autoFocus:a,theme:h="light",height:c=null,minHeight:f=null,maxHeight:u=null,width:d=null,minWidth:p=null,maxWidth:m=null,placeholder:y="",editable:b=!0,readOnly:A=!1,indentWithTab:S=!0,basicSetup:O=!0,root:C,initialState:M}=n,[v,W]=ve.useState(),[R,_]=ve.useState(),[H,L]=ve.useState(),F=ve.useState(()=>({current:null}))[0],z=ve.useState(()=>({current:null}))[0],Y=D.theme({"&":{height:c,minHeight:f,maxHeight:u,width:d,minWidth:p,maxWidth:m},"& .cm-scroller":{height:"100% !important"}}),ie=D.updateListener.of(X=>{if(X.docChanged&&typeof i=="function"&&!X.transactions.some(k=>k.annotation(wa))){F.current?F.current.reset():(F.current=new zy(()=>{if(z.current){var k=z.current;z.current=null,k()}F.current=null},_y),qy().add(F.current));var oe=X.state.doc,g=oe.toString();i(g,X)}s&&s(Vy(X))}),re=Fy({theme:h,editable:b,readOnly:A,placeholder:y,indentWithTab:S,basicSetup:O}),pe=[ie,Y,...re];return o&&typeof o=="function"&&pe.push(D.updateListener.of(o)),pe=pe.concat(l),ve.useLayoutEffect(()=>{if(v&&!H){var X={doc:e,selection:t,extensions:pe},oe=M?K.fromJSON(M.json,X,M.fields):K.create(X);if(L(oe),!R){var g=new D({state:oe,parent:v,root:C});_(g),r&&r(g,oe)}}return()=>{R&&(L(void 0),_(void 0))}},[v,H]),ve.useEffect(()=>{n.container&&W(n.container)},[n.container]),ve.useEffect(()=>()=>{R&&(R.destroy(),_(void 0)),F.current&&(F.current.cancel(),F.current=null)},[R]),ve.useEffect(()=>{a&&R&&R.focus()},[a,R]),ve.useEffect(()=>{R&&R.dispatch({effects:q.reconfigure.of(pe)})},[h,l,c,f,u,d,p,m,y,b,A,S,O,i,o]),ve.useEffect(()=>{if(e!==void 0){var X=R?R.state.doc.toString():"";if(R&&e!==X){var oe=F.current&&!F.current.isDone,g=()=>{R&&e!==R.state.doc.toString()&&R.dispatch({changes:{from:0,to:R.state.doc.toString().length,insert:e||""},annotations:[wa.of(!0)]})};oe?z.current=g:g()}}},[e,R]),{state:H,setState:L,view:R,setView:_,container:v,setContainer:W}}var Ky=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],Uy=ve.forwardRef((n,e)=>{var{className:t,value:i="",selection:s,extensions:r=[],onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:h,autoFocus:c,theme:f="light",height:u,minHeight:d,maxHeight:p,width:m,minWidth:y,maxWidth:b,basicSetup:A,placeholder:S,indentWithTab:O,editable:C,readOnly:M,root:v,initialState:W}=n,R=wf(n,Ky),_=ve.useRef(null),{state:H,view:L,container:F,setContainer:z}=jy({root:v,value:i,autoFocus:c,theme:f,height:u,minHeight:d,maxHeight:p,width:m,minWidth:y,maxWidth:b,basicSetup:A,placeholder:S,indentWithTab:O,editable:C,readOnly:M,selection:s,onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:h,extensions:r,initialState:W});ve.useImperativeHandle(e,()=>({editor:_.current,state:H,view:L}),[_,F,H,L]);var Y=ve.useCallback(re=>{_.current=re,z(re)},[z]);if(typeof i!="string")throw new Error("value must be typeof string but got "+typeof i);var ie=typeof f=="string"?"cm-theme-"+f:"cm-theme";return yf.jsx("div",Qs({ref:Y,className:""+ie+(t?" "+t:"")},R))});Uy.displayName="CodeMirror";export{Ep as D,D as E,ae as I,Zy as L,$h as N,Wp as P,Jy as R,be as T,Qs as _,We as a,U as b,Wr as c,eb as d,tb as e,cm as f,pf as g,ve as h,Zp as i,yf as j,Gy as k,Yy as l,Uy as m,Wy as o,xf as r,_p as s,x as t};
