diff --git a/assets/index-DJ8TvcxU.js b/assets/index-Cd8YKWY2.js similarity index 99% rename from assets/index-DJ8TvcxU.js rename to assets/index-Cd8YKWY2.js index ea6e00d4a..4953b6885 100644 --- a/assets/index-DJ8TvcxU.js +++ b/assets/index-Cd8YKWY2.js @@ -3667,7 +3667,7 @@ No matching component was found for: * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Bf=K;function ZX(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var JX=typeof Object.is=="function"?Object.is:ZX,QX=Bf.useState,ej=Bf.useEffect,tj=Bf.useLayoutEffect,nj=Bf.useDebugValue;function rj(t,e){var n=e(),r=QX({inst:{value:n,getSnapshot:e}}),i=r[0].inst,s=r[1];return tj(function(){i.value=n,i.getSnapshot=e,vS(i)&&s({inst:i})},[t,n,e]),ej(function(){return vS(i)&&s({inst:i}),t(function(){vS(i)&&s({inst:i})})},[t]),nj(n),n}function vS(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!JX(t,n)}catch{return!0}}function ij(t,e){return e()}var sj=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?ij:rj;O3.useSyncExternalStore=Bf.useSyncExternalStore!==void 0?Bf.useSyncExternalStore:sj;N3.exports=O3;var oj=N3.exports;const aj=Jf(oj);var k3={exports:{}};(function(t,e){(function(n,r){t.exports=r()})(IL,function(){return n.importState=function(i){var s=new n;return s.importState(i),s},n;function n(){return function(i){var s=0,o=0,a=0,l=1;i.length==0&&(i=[+new Date]);var c=r();s=c(" "),o=c(" "),a=c(" ");for(var h=0;h>>0,l-=i,l*=i,i=l>>>0,l-=i,i+=l*4294967296}return(i>>>0)*23283064365386963e-26};return s.version="Mash 0.9",s}})})(k3);var lj=k3.exports;const cj=Jf(lj);cj("089fad0j9awfem09wavefc09uwaef");function Gv(t,e,n){return Math.max(e,Math.min(n,t))}function OP(t){return 2*Math.floor(t/2)}function uj(t,e){return Math.round(t/e)*e}const yS=new Set,Oc={emit(t,e,n,r){Oc.invoke(dj(t,e,n,r))},invoke(t){yS.forEach(e=>e.handle(t))},connect(t){yS.add(t)},disconnect(t){yS.delete(t)}},fj="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let hj=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=fj[n[t]&63];return e};function GT(){return hj()}function dj(t,e,n,r){return{id:GT(),target:t,sender:e,data:n,player:r}}function pj(t){const[e,...n]=t.split(":");return{target:e,path:n.join(":")}}function WT(t,e,n){const r=GT(),i=t.toLowerCase(),s=e.map(a=>a.toLowerCase()),o={id(){return r},name(){return t},tags(){return e},emit(a,l,c){Oc.emit(a,r,l,c)},reply(a,l,c,h){o.emit(`${a.sender}:${l}`,c,h)},handle(a){const{target:l,path:c}=pj(a.target),h=l.toLowerCase();s.findIndex(d=>d==="all"||d===h)!==-1&&n(a),(r===l||h==="all"||i===h)&&n({...a,target:c})}};return Oc.connect(o),o}function mj(t){const e=new Set;function n(r){e.has(r.id)||(e.add(r.id),Oc.invoke(r))}return WT("forward",["all"],r=>{e.has(r.id)||(e.add(r.id),t(r))}),n}function gj(t){return new Worker("/assets/instance-LD1NVfuA.js",{name:t==null?void 0:t.name})}/*! + */var Bf=K;function ZX(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var JX=typeof Object.is=="function"?Object.is:ZX,QX=Bf.useState,ej=Bf.useEffect,tj=Bf.useLayoutEffect,nj=Bf.useDebugValue;function rj(t,e){var n=e(),r=QX({inst:{value:n,getSnapshot:e}}),i=r[0].inst,s=r[1];return tj(function(){i.value=n,i.getSnapshot=e,vS(i)&&s({inst:i})},[t,n,e]),ej(function(){return vS(i)&&s({inst:i}),t(function(){vS(i)&&s({inst:i})})},[t]),nj(n),n}function vS(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!JX(t,n)}catch{return!0}}function ij(t,e){return e()}var sj=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?ij:rj;O3.useSyncExternalStore=Bf.useSyncExternalStore!==void 0?Bf.useSyncExternalStore:sj;N3.exports=O3;var oj=N3.exports;const aj=Jf(oj);var k3={exports:{}};(function(t,e){(function(n,r){t.exports=r()})(IL,function(){return n.importState=function(i){var s=new n;return s.importState(i),s},n;function n(){return function(i){var s=0,o=0,a=0,l=1;i.length==0&&(i=[+new Date]);var c=r();s=c(" "),o=c(" "),a=c(" ");for(var h=0;h>>0,l-=i,l*=i,i=l>>>0,l-=i,i+=l*4294967296}return(i>>>0)*23283064365386963e-26};return s.version="Mash 0.9",s}})})(k3);var lj=k3.exports;const cj=Jf(lj);cj("089fad0j9awfem09wavefc09uwaef");function Gv(t,e,n){return Math.max(e,Math.min(n,t))}function OP(t){return 2*Math.floor(t/2)}function uj(t,e){return Math.round(t/e)*e}const yS=new Set,Oc={emit(t,e,n,r){Oc.invoke(dj(t,e,n,r))},invoke(t){yS.forEach(e=>e.handle(t))},connect(t){yS.add(t)},disconnect(t){yS.delete(t)}},fj="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let hj=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=fj[n[t]&63];return e};function GT(){return hj()}function dj(t,e,n,r){return{id:GT(),target:t,sender:e,data:n,player:r}}function pj(t){const[e,...n]=t.split(":");return{target:e,path:n.join(":")}}function WT(t,e,n){const r=GT(),i=t.toLowerCase(),s=e.map(a=>a.toLowerCase()),o={id(){return r},name(){return t},tags(){return e},emit(a,l,c){Oc.emit(a,r,l,c)},reply(a,l,c,h){o.emit(`${a.sender}:${l}`,c,h)},handle(a){const{target:l,path:c}=pj(a.target),h=l.toLowerCase();s.findIndex(d=>d==="all"||d===h)!==-1&&n(a),(r===l||h==="all"||i===h)&&n({...a,target:c})}};return Oc.connect(o),o}function mj(t){const e=new Set;function n(r){e.has(r.id)||(e.add(r.id),Oc.invoke(r))}return WT("forward",["all"],r=>{e.has(r.id)||(e.add(r.id),t(r))}),n}function gj(t){return new Worker("/assets/instance-DIq2GfeP.js",{name:t==null?void 0:t.name})}/*! * https://github.com/Starcounter-Jack/JSON-Patch * (c) 2017-2022 Joachim Wester * MIT licensed @@ -3676,7 +3676,7 @@ No matching component was found for: * https://github.com/Starcounter-Jack/JSON-Patch * (c) 2017-2021 Joachim Wester * MIT license - */var jT=new WeakMap,wj=function(){function t(e){this.observers=new Map,this.obj=e}return t}(),Mj=function(){function t(e,n){this.callback=e,this.observer=n}return t}();function Tj(t){return jT.get(t)}function Aj(t,e){return t.observers.get(e)}function Cj(t,e){t.observers.delete(e.callback)}function Rj(t,e){e.unobserve()}function bj(t,e){var n=[],r,i=Tj(t);if(!i)i=new wj(t),jT.set(t,i);else{var s=Aj(i,e);r=s&&s.observer}if(r)return r;if(r={},i.value=fi(t),e){r.callback=e,r.next=null;var o=function(){Nw(r)},a=function(){clearTimeout(r.next),r.next=setTimeout(o)};typeof window<"u"&&(window.addEventListener("mouseup",a),window.addEventListener("keyup",a),window.addEventListener("mousedown",a),window.addEventListener("keydown",a),window.addEventListener("change",a))}return r.patches=n,r.object=t,r.unobserve=function(){Nw(r),clearTimeout(r.next),Cj(i,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},i.observers.set(e,new Mj(e,r)),r}function Nw(t,e){e===void 0&&(e=!1);var n=jT.get(t.object);$T(n.value,t.object,t.patches,"",e),t.patches.length&&f_(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function $T(t,e,n,r,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var s=Pw(e),o=Pw(t),a=!1,l=o.length-1;l>=0;l--){var c=o[l],h=t[c];if(bw(e,c)&&!(e[c]===void 0&&h!==void 0&&Array.isArray(e)===!1)){var d=e[c];typeof h=="object"&&h!=null&&typeof d=="object"&&d!=null&&Array.isArray(h)===Array.isArray(d)?$T(h,d,n,r+"/"+sc(c),i):h!==d&&(i&&n.push({op:"test",path:r+"/"+sc(c),value:fi(h)}),n.push({op:"replace",path:r+"/"+sc(c),value:fi(d)}))}else Array.isArray(t)===Array.isArray(e)?(i&&n.push({op:"test",path:r+"/"+sc(c),value:fi(h)}),n.push({op:"remove",path:r+"/"+sc(c)}),a=!0):(i&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}))}if(!(!a&&s.length==o.length))for(var l=0;lnew Proxy(t,e);const Ow=Object.getPrototypeOf,kw=new WeakMap,F3=t=>t&&(kw.has(t)?kw.get(t):Ow(t)===Object.prototype||Ow(t)===Array.prototype),jv=t=>typeof t=="object"&&t!==null,Oj=t=>{if(Array.isArray(t))return Array.from(t);const e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(n=>{n.configurable=!0}),Object.create(Ow(t),e)},KT=t=>t[YT]||t,B3=(t,e,n,r)=>{if(!F3(t))return t;let i=r&&r.get(t);if(!i){const l=KT(t);i=(c=>Object.values(Object.getOwnPropertyDescriptors(c)).some(h=>!h.configurable&&!h.writable))(l)?[l,Oj(l)]:[l],r==null||r.set(t,i)}const[s,o]=i;let a=n&&n.get(s);return a&&a[1].f===!!o||(a=((l,c)=>{const h={f:c};let d=!1;const p=(y,S)=>{if(!d){let E=h[sd].get(l);if(E||(E={},h[sd].set(l,E)),y===Od)E[Od]=!0;else{let g=E[y];g||(g=new Set,E[y]=g),g.add(S)}}},m={get:(y,S)=>S===YT?l:(p("k",S),B3(Reflect.get(y,S),h[sd],h.c,h.t)),has:(y,S)=>S===Lj?(d=!0,h[sd].delete(l),!0):(p("h",S),Reflect.has(y,S)),getOwnPropertyDescriptor:(y,S)=>(p("o",S),Reflect.getOwnPropertyDescriptor(y,S)),ownKeys:y=>(p(Od),Reflect.ownKeys(y))};return c&&(m.set=m.deleteProperty=()=>!1),[m,h]})(s,!!o),a[1].p=Nj(o||s,a[0]),n&&n.set(s,a)),a[1][sd]=e,a[1].c=n,a[1].t=r,a[1].p},z3=(t,e,n,r,i=Object.is)=>{if(i(t,e))return!1;if(!jv(t)||!jv(e))return!0;const s=n.get(KT(t));if(!s)return!0;if(r){const a=r.get(t);if(a&&a.n===e)return a.g;r.set(t,{n:e,g:!1})}let o=null;try{for(const a of s.h||[])if(o=Reflect.has(t,a)!==Reflect.has(e,a),o)return o;if(s[Od]===!0){if(o=((a,l)=>{const c=Reflect.ownKeys(a),h=Reflect.ownKeys(l);return c.length!==h.length||c.some((d,p)=>d!==h[p])})(t,e),o)return o}else for(const a of s.o||[])if(o=!!Reflect.getOwnPropertyDescriptor(t,a)!=!!Reflect.getOwnPropertyDescriptor(e,a),o)return o;for(const a of s.k||[])if(o=z3(t[a],e[a],n,r,i),o)return o;return o===null&&(o=!0),o}finally{r&&r.set(t,{n:e,g:o})}},kj=t=>F3(t)&&t[YT]||null,DP=(t,e=!0)=>{kw.set(t,e)},Dj=(t,e,n)=>{const r=[],i=new WeakSet,s=(o,a)=>{if(i.has(o))return;jv(o)&&i.add(o);const l=jv(o)&&e.get(KT(o));if(l){var c,h;if((c=l.h)==null||c.forEach(p=>{const m=`:has(${String(p)})`;r.push(a?[...a,m]:[m])}),l[Od]===!0){const p=":ownKeys";r.push(a?[...a,p]:[p])}else{var d;(d=l.o)==null||d.forEach(p=>{const m=`:hasOwn(${String(p)})`;r.push(a?[...a,m]:[m])})}(h=l.k)==null||h.forEach(p=>{n&&!("value"in(Object.getOwnPropertyDescriptor(o,p)||{}))||s(o[p],a?[...a,p]:[p])})}else a&&r.push(a)};return s(t),r};var $v={ZSS_LANG_DEV:"false",ZSS_STATS_DEV:"false",ZSS_SHOW_CODE:"false",ZSS_BRANCH_NAME:"main",ZSS_BRANCH_VERSION:"0.2.1",ZSS_COMMIT_HASH:"cab08f3b1ebc108a4629bb4904e63ccbbafc54a1",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.1",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const _S=t=>typeof t=="object"&&t!==null,Wa=new WeakMap,S0=new WeakSet,Uj=(t=Object.is,e=(c,h)=>new Proxy(c,h),n=c=>_S(c)&&!S0.has(c)&&(Array.isArray(c)||!(Symbol.iterator in c))&&!(c instanceof WeakMap)&&!(c instanceof WeakSet)&&!(c instanceof Error)&&!(c instanceof Number)&&!(c instanceof Date)&&!(c instanceof String)&&!(c instanceof RegExp)&&!(c instanceof ArrayBuffer),r=c=>{switch(c.status){case"fulfilled":return c.value;case"rejected":throw c.reason;default:throw c}},i=new WeakMap,s=(c,h,d=r)=>{const p=i.get(c);if((p==null?void 0:p[0])===h)return p[1];const m=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c));return DP(m,!0),i.set(c,[h,m]),Reflect.ownKeys(c).forEach(y=>{if(Object.getOwnPropertyDescriptor(m,y))return;const S=Reflect.get(c,y),{enumerable:E}=Reflect.getOwnPropertyDescriptor(c,y),g={value:S,enumerable:E,configurable:!0};if(S0.has(S))DP(S,!1);else if(S instanceof Promise)delete g.value,g.get=()=>d(S);else if(Wa.has(S)){const[x,_]=Wa.get(S);g.value=s(x,_(),d)}Object.defineProperty(m,y,g)}),Object.preventExtensions(m)},o=new WeakMap,a=[1,1],l=c=>{if(!_S(c))throw new Error("object required");const h=o.get(c);if(h)return h;let d=a[0];const p=new Set,m=(R,P=++a[0])=>{d!==P&&(d=P,p.forEach(O=>O(R,P)))};let y=a[1];const S=(R=++a[1])=>(y!==R&&!p.size&&(y=R,g.forEach(([P])=>{const O=P[1](R);O>d&&(d=O)})),d),E=R=>(P,O)=>{const X=[...P];X[1]=[R,...X[1]],m(X,O)},g=new Map,x=(R,P)=>{if(($v?"production":void 0)!=="production"&&g.has(R))throw new Error("prop listener already exists");if(p.size){const O=P[3](E(R));g.set(R,[P,O])}else g.set(R,[P])},_=R=>{var P;const O=g.get(R);O&&(g.delete(R),(P=O[1])==null||P.call(O))},M=R=>(p.add(R),p.size===1&&g.forEach(([O,X],j)=>{if(($v?"production":void 0)!=="production"&&X)throw new Error("remove already exists");const H=O[3](E(j));g.set(j,[O,H])}),()=>{p.delete(R),p.size===0&&g.forEach(([O,X],j)=>{X&&(X(),g.set(j,[O]))})}),C=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c)),I=e(C,{deleteProperty(R,P){const O=Reflect.get(R,P);_(P);const X=Reflect.deleteProperty(R,P);return X&&m(["delete",[P],O]),X},set(R,P,O,X){const j=Reflect.has(R,P),H=Reflect.get(R,P,X);if(j&&(t(H,O)||o.has(O)&&t(H,o.get(O))))return!0;_(P),_S(O)&&(O=kj(O)||O);let J=O;if(O instanceof Promise)O.then(ee=>{O.status="fulfilled",O.value=ee,m(["resolve",[P],ee])}).catch(ee=>{O.status="rejected",O.reason=ee,m(["reject",[P],ee])});else{!Wa.has(O)&&n(O)&&(J=l(O));const ee=!S0.has(J)&&Wa.get(J);ee&&x(P,ee)}return Reflect.set(R,P,J,X),m(["set",[P],O,H]),!0}});o.set(c,I);const N=[C,S,s,M];return Wa.set(I,N),Reflect.ownKeys(c).forEach(R=>{const P=Object.getOwnPropertyDescriptor(c,R);"value"in P&&(I[R]=c[R],delete P.value,delete P.writable),Object.defineProperty(C,R,P)}),I})=>[l,Wa,S0,t,e,n,r,i,s,o,a],[Fj]=Uj();function qT(t={}){return Fj(t)}function Bj(t,e,n){const r=Wa.get(t);($v?"production":void 0)!=="production"&&!r&&console.warn("Please use proxy object");let i;const s=[],o=r[3];let a=!1;const c=o(h=>{if(s.push(h),n){e(s.splice(0));return}i||(i=Promise.resolve().then(()=>{i=void 0,a&&e(s.splice(0))}))});return a=!0,()=>{a=!1,c()}}function UP(t,e){const n=Wa.get(t);($v?"production":void 0)!=="production"&&!n&&console.warn("Please use proxy object");const[r,i,s]=n;return s(r,i(),e)}var zj={ZSS_LANG_DEV:"false",ZSS_STATS_DEV:"false",ZSS_SHOW_CODE:"false",ZSS_BRANCH_NAME:"main",ZSS_BRANCH_VERSION:"0.2.1",ZSS_COMMIT_HASH:"cab08f3b1ebc108a4629bb4904e63ccbbafc54a1",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.1",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const{use:FP}=Bd,{useSyncExternalStore:Hj}=aj,Vj=(t,e)=>{const n=K.useRef();K.useEffect(()=>{n.current=Dj(t,e,!0)}),K.useDebugValue(n.current)},Gj=new WeakMap;function h_(t,e){const n=e==null?void 0:e.sync,r=K.useRef(),i=K.useRef();let s=!0;const o=Hj(K.useCallback(c=>{const h=Bj(t,c,n);return c(),h},[t,n]),()=>{const c=UP(t,FP);try{if(!s&&r.current&&i.current&&!z3(r.current,c,i.current,new WeakMap))return r.current}catch{}return c},()=>UP(t,FP));s=!1;const a=new WeakMap;K.useEffect(()=>{r.current=o,i.current=a}),(zj?"production":void 0)!=="production"&&Vj(o,a);const l=K.useMemo(()=>new WeakMap,[]);return B3(o,a,l,Gj)}let xS=!1;const Ts=qT({state:{player:"",layers:[],layout:[],layoutreset:!1,layoutfocus:""}}),SS=WT("gadgetclient",["ready","second"],t=>{switch(t.target){case"ready":t.player&&Ts.state.player===""&&(Ts.state.player=t.player,SS.emit("vm:login",void 0,Ts.state.player));break;case"second":Ts.state.player&&SS.emit("vm:doot",void 0,Ts.state.player);break;case"reset":t.player===Ts.state.player&&(xS=!1,Ts.state=t.data);break;case"patch":if(t.player===Ts.state.player&&!xS)try{f_(Ts.state,t.data,!0)}catch(e){e instanceof XT&&(xS=!0,SS.reply(t,"desync",void 0,Ts.state.player))}break}});function Wj(){return Ts.state}const BP=1,zP=2,ES=4,wS=8,Ap=32,oa=64,Oi=128,d_=31,Dw=63,Tc=127,Xj=2147483647,vl=Math.floor,ev=Math.abs,H3=(t,e)=>tt>e?t:e,V3=t=>t!==0?t<0:1/t<0,G3=Number.MAX_SAFE_INTEGER,jj=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&vl(t)===t),Hf=()=>new Set,MS=t=>t[t.length-1],$j=(t,e)=>{for(let n=0;nt.toLowerCase(),qj=/^\s*/g,Zj=t=>t.replace(qj,""),Jj=/([A-Z])/g,HP=(t,e)=>Zj(t.replace(Jj,n=>`${e}${Kj(n)}`)),Qj=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let i=0;iCp.encode(t),t$=Cp?e$:Qj;let kd=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});kd&&kd.decode(new Uint8Array).length===1&&(kd=null);const _l=t=>new Error(t),So=()=>{throw _l("Method unimplemented")},To=()=>{throw _l("Unexpected case")};class em{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const cl=()=>new em,n$=t=>{let e=t.cpos;for(let n=0;n{const e=new Uint8Array(n$(t));let n=0;for(let r=0;r{const n=t.cbuf.length;n-t.cpos{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Uw=cr,Rt=(t,e)=>{for(;e>Tc;)cr(t,Oi|Tc&e),e=vl(e/128);cr(t,Tc&e)},ZT=(t,e)=>{const n=V3(e);for(n&&(e=-e),cr(t,(e>Dw?Oi:0)|(n?oa:0)|Dw&e),e=vl(e/64);e>0;)cr(t,(e>Tc?Oi:0)|Tc&e),e=vl(e/128)},Fw=new Uint8Array(3e4),i$=Fw.length/3,s$=(t,e)=>{if(e.length{const n=unescape(encodeURIComponent(e)),r=n.length;Rt(t,r);for(let i=0;i{const n=t.cbuf.length,r=t.cpos,i=H3(n-r,e.length),s=e.length-i;t.cbuf.set(e.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Yc(n*2,s)),t.cbuf.set(e.subarray(i)),t.cpos=s)},Nr=(t,e)=>{Rt(t,e.byteLength),p_(t,e)},JT=(t,e)=>{r$(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},a$=(t,e)=>JT(t,4).setFloat32(0,e,!1),l$=(t,e)=>JT(t,8).setFloat64(0,e,!1),c$=(t,e)=>JT(t,8).setBigInt64(0,e,!1),VP=new DataView(new ArrayBuffer(4)),u$=t=>(VP.setFloat32(0,t),VP.getFloat32(0)===t),Rp=(t,e)=>{switch(typeof e){case"string":cr(t,119),_f(t,e);break;case"number":jj(e)&&ev(e)<=Xj?(cr(t,125),ZT(t,e)):u$(e)?(cr(t,124),a$(t,e)):(cr(t,123),l$(t,e));break;case"bigint":cr(t,122),c$(t,e);break;case"object":if(e===null)cr(t,126);else if(Yj(e)){cr(t,117),Rt(t,e.length);for(let n=0;n0&&Rt(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const WP=t=>{t.count>0&&(ZT(t.encoder,t.count===1?t.s:-t.s),t.count>1&&Rt(t.encoder,t.count-2))};class tv{constructor(){this.encoder=new em,this.s=0,this.count=0}write(e){this.s===e?this.count++:(WP(this),this.count=1,this.s=e)}toUint8Array(){return WP(this),Os(this.encoder)}}const XP=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);ZT(t.encoder,e),t.count>1&&Rt(t.encoder,t.count-2)}};class TS{constructor(){this.encoder=new em,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(XP(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return XP(this),Os(this.encoder)}}class f${constructor(){this.sarr=[],this.s="",this.lensE=new tv}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new em;return this.sarr.push(this.s),this.s="",_f(e,this.sarr.join("")),p_(e,this.lensE.toUint8Array()),Os(e)}}const W3=_l("Unexpected end of array"),X3=_l("Integer out of Range");class m_{constructor(e){this.arr=e,this.pos=0}}const Kc=t=>new m_(t),h$=t=>t.pos!==t.arr.length,d$=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},Wr=t=>d$(t,bt(t)),Vf=t=>t.arr[t.pos++],bt=t=>{let e=0,n=1;const r=t.arr.length;for(;t.posG3)throw X3}throw W3},QT=t=>{let e=t.arr[t.pos++],n=e&Dw,r=64;const i=(e&oa)>0?-1:1;if(!(e&Oi))return i*n;const s=t.arr.length;for(;t.posG3)throw X3}throw W3},p$=t=>{let e=bt(t);if(e===0)return"";{let n=String.fromCodePoint(Vf(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(Vf(t));else for(;e>0;){const r=e<1e4?e:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(n))}},m$=t=>kd.decode(Wr(t)),xf=kd?m$:p$,eA=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},g$=t=>eA(t,4).getFloat32(0,!1),v$=t=>eA(t,8).getFloat64(0,!1),y$=t=>eA(t,8).getBigInt64(0,!1),_$=[t=>{},t=>null,QT,g$,v$,y$,t=>!1,t=>!0,xf,t=>{const e=bt(t),n={};for(let r=0;r{const e=bt(t),n=[];for(let r=0;r_$[127-Vf(t)](t);class jP extends m_{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),h$(this)?this.count=bt(this)+1:this.count=-1),this.count--,this.s}}class nv extends m_{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=QT(this);const e=V3(this.s);this.count=1,e&&(this.s=-this.s,this.count=bt(this)+2)}return this.count--,this.s}}class AS extends m_{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=QT(this),n=e&1;this.diff=vl(e/2),this.count=1,n&&(this.count=bt(this)+2)}return this.s+=this.diff,this.count--,this.s}}class x${constructor(e){this.decoder=new nv(e),this.str=xf(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const Bs=()=>new Map,Bw=t=>{const e=Bs();return t.forEach((n,r)=>{e.set(r,n)}),e},Ll=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},S$=(t,e)=>{const n=[];for(const[r,i]of t)n.push(e(i,r));return n},E$=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1};class w${constructor(){this._observers=Bs()}on(e,n){return Ll(this._observers,e,Hf).add(n),n}once(e,n){const r=(...i)=>{this.off(e,r),n(...i)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return yl((this._observers.get(e)||Bs()).values()).forEach(r=>r(...n))}destroy(){this._observers=Bs()}}const M$=crypto.getRandomValues.bind(crypto),j3=()=>M$(new Uint32Array(1))[0],T$="10000000-1000-4000-8000"+-1e11,A$=()=>T$.replace(/[018]/g,t=>(t^j3()&15>>t/4).toString(16)),$P=t=>new Promise(t);Promise.all.bind(Promise);const YP=t=>t===void 0?null:t;class C${constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let $3=new C$,R$=!0;try{typeof localStorage<"u"&&localStorage&&($3=localStorage,R$=!1)}catch{}const b$=$3,P$=Object.assign,I$=Object.keys,L$=(t,e)=>{for(const n in t)e(t[n],n)},KP=t=>I$(t).length,N$=t=>{for(const e in t)return!1;return!0},O$=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},k$=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),D$=(t,e)=>t===e||KP(t)===KP(e)&&O$(t,(n,r)=>(n!==void 0||k$(e,r))&&e[r]===n),tA=(t,e,n=0)=>{try{for(;nt,F$=(t,e)=>e.includes(t);var Y3={};const Pp=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let ao;const B$=()=>{if(ao===void 0)if(Pp){ao=Bs();const t=process.argv;let e=null;for(let n=0;n{if(t.length!==0){const[e,n]=t.split("=");ao.set(`--${HP(e,"-")}`,n),ao.set(`-${HP(e,"-")}`,n)}})):ao=Bs();return ao},zw=t=>B$().has(t),Hw=t=>YP(Pp?Y3[t.toUpperCase().replaceAll("-","_")]:b$.getItem(t)),z$=t=>zw("--"+t)||Hw(t)!==null;z$("production");const qP=Pp&&F$(Y3.FORCE_COLOR,["true","1","2"]),H$=!zw("no-colors")&&(!Pp||process.stdout.isTTY||qP)&&(!Pp||zw("color")||qP||Hw("COLORTERM")!==null||(Hw("TERM")||"").includes("color")),V$=t=>new Uint8Array(t),G$=t=>{const e=V$(t.byteLength);return e.set(t),e};class W${constructor(e,n){this.left=e,this.right=n}}const Zo=(t,e)=>new W$(t,e);typeof DOMParser<"u"&&new DOMParser;const X$=t=>S$(t,(e,n)=>`${n}:${e};`).join(""),ya=Symbol,K3=ya(),q3=ya(),j$=ya(),$$=ya(),Y$=ya(),Z3=ya(),K$=ya(),J3=ya(),q$=ya(),Z$=t=>{var r;t.length===1&&((r=t[0])==null?void 0:r.constructor)===Function&&(t=t[0]());const e=[];let n=0;for(;n{var o;t.length===1&&((o=t[0])==null?void 0:o.constructor)===Function&&(t=t[0]());const e=[],n=[],r=Bs();let i=[],s=0;for(;s0||c.length>0?(e.push("%c"+a),n.push(c)):e.push(a)}else break}}for(s>0&&(i=n,i.unshift(e.join("")));s{console.log(...eY(t)),nY.forEach(e=>e.print(t))},nY=Hf(),Q3=t=>({[Symbol.iterator](){return this},next:t}),rY=(t,e)=>Q3(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),CS=(t,e)=>Q3(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class nA{constructor(e,n){this.clock=e,this.len=n}}class tm{constructor(){this.clients=new Map}}const e4=(t,e,n)=>e.clients.forEach((r,i)=>{const s=t.doc.store.clients.get(i);for(let o=0;o{let n=0,r=t.length-1;for(;n<=r;){const i=vl((n+r)/2),s=t[i],o=s.clock;if(o<=e){if(e{const n=t.clients.get(e.client);return n!==void 0&&iY(n,e.clock)!==null},rA=t=>{t.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let n,r;for(n=1,r=1;n=s.clock?i.len=Yc(i.len,s.clock+s.len-i.clock):(r{const e=new tm;for(let n=0;n{if(!e.clients.has(i)){const s=r.slice();for(let o=n+1;o{Ll(t.clients,e,()=>[]).push(new nA(n,r))},oY=()=>new tm,aY=t=>{const e=oY();return t.clients.forEach((n,r)=>{const i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},uh=(t,e)=>{Rt(t.restEncoder,e.clients.size),yl(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),Rt(t.restEncoder,n);const i=r.length;Rt(t.restEncoder,i);for(let s=0;s{const e=new tm,n=bt(t.restDecoder);for(let r=0;r0){const o=Ll(e.clients,i,()=>[]);for(let a=0;a{const r=new tm,i=bt(t.restDecoder);for(let s=0;s0){const s=new kc;return Rt(s.restEncoder,0),uh(s,r),s.toUint8Array()}return null},n4=j3;class fh extends w${constructor({guid:e=A$(),collectionid:n=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=n4(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new f4,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=$P(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const l=()=>$P(c=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),c())};this.on("sync",h)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&nn(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(yl(this.subdocs).map(e=>e.guid))}transact(e,n=null){return nn(this,e,n)}get(e,n=Er){const r=Ll(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),i=r.constructor;if(n!==Er&&i!==n)if(i===Er){const s=new n;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,Ef)}getText(e=""){return this.get(e,Dc)}getMap(e=""){return this.get(e,Wf)}getXmlElement(e=""){return this.get(e,Xf)}getXmlFragment(e=""){return this.get(e,Uc)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){yl(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new fh({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,nn(e.parent.doc,r=>{const i=n.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class r4{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return bt(this.restDecoder)}readDsLen(){return bt(this.restDecoder)}}class i4 extends r4{readLeftID(){return Ot(bt(this.restDecoder),bt(this.restDecoder))}readRightID(){return Ot(bt(this.restDecoder),bt(this.restDecoder))}readClient(){return bt(this.restDecoder)}readInfo(){return Vf(this.restDecoder)}readString(){return xf(this.restDecoder)}readParentInfo(){return bt(this.restDecoder)===1}readTypeRef(){return bt(this.restDecoder)}readLen(){return bt(this.restDecoder)}readAny(){return bp(this.restDecoder)}readBuf(){return G$(Wr(this.restDecoder))}readJSON(){return JSON.parse(xf(this.restDecoder))}readKey(){return xf(this.restDecoder)}}class lY{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=bt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=bt(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class Gf extends lY{constructor(e){super(e),this.keys=[],bt(e),this.keyClockDecoder=new AS(Wr(e)),this.clientDecoder=new nv(Wr(e)),this.leftClockDecoder=new AS(Wr(e)),this.rightClockDecoder=new AS(Wr(e)),this.infoDecoder=new jP(Wr(e),Vf),this.stringDecoder=new x$(Wr(e)),this.parentInfoDecoder=new jP(Wr(e),Vf),this.typeRefDecoder=new nv(Wr(e)),this.lenDecoder=new nv(Wr(e))}readLeftID(){return new Sf(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Sf(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return bp(this.restDecoder)}readBuf(){return Wr(this.restDecoder)}readJSON(){return bp(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e{r=Yc(r,e[0].id.clock);const i=Ao(e,r);Rt(t.restEncoder,e.length-i),t.writeClient(n),Rt(t.restEncoder,r);const s=e[i];s.write(t,r-s.id.clock);for(let o=i+1;o{const r=new Map;n.forEach((i,s)=>{hr(e,s)>i&&r.set(s,i)}),g_(e).forEach((i,s)=>{n.has(s)||r.set(s,0)}),Rt(t.restEncoder,r.size),yl(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{cY(t,e.clients.get(i),i,s)})},uY=(t,e)=>{const n=Bs(),r=bt(t.restDecoder);for(let i=0;i{const r=[];let i=yl(n.keys()).sort((m,y)=>m-y);if(i.length===0)return null;const s=()=>{if(i.length===0)return null;let m=n.get(i[i.length-1]);for(;m.refs.length===m.i;)if(i.pop(),i.length>0)m=n.get(i[i.length-1]);else return null;return m};let o=s();if(o===null)return null;const a=new f4,l=new Map,c=(m,y)=>{const S=l.get(m);(S==null||S>y)&&l.set(m,y)};let h=o.refs[o.i++];const d=new Map,p=()=>{for(const m of r){const y=m.id.client,S=n.get(y);S?(S.i--,a.clients.set(y,S.refs.slice(S.i)),n.delete(y),S.i=0,S.refs=[]):a.clients.set(y,[m]),i=i.filter(E=>E!==y)}r.length=0};for(;;){if(h.constructor!==is){const y=Ll(d,h.id.client,()=>hr(e,h.id.client))-h.id.clock;if(y<0)r.push(h),c(h.id.client,h.id.clock-1),p();else{const S=h.getMissing(t,e);if(S!==null){r.push(h);const E=n.get(S)||{refs:[],i:0};if(E.refs.length===E.i)c(S,hr(e,S)),p();else{h=E.refs[E.i++];continue}}else(y===0||y0)h=r.pop();else if(o!==null&&o.i0){const m=new kc;return sA(m,a,new Map),Rt(m.restEncoder,0),{missing:l,update:m.toUint8Array()}}return null},hY=(t,e)=>sA(t,e.doc.store,e.beforeState),dY=(t,e,n,r=new Gf(t))=>nn(e,i=>{i.local=!1;let s=!1;const o=i.doc,a=o.store,l=uY(r,o),c=fY(i,a,l),h=a.pendingStructs;if(h){for(const[p,m]of h.missing)if(mm)&&h.missing.set(p,m)}h.update=Kv([h.update,c.update])}}else a.pendingStructs=c;const d=ZP(r,i,a);if(a.pendingDs){const p=new Gf(Kc(a.pendingDs));bt(p.restDecoder);const m=ZP(p,i,a);d&&m?a.pendingDs=Kv([d,m]):a.pendingDs=d||m}else a.pendingDs=d;if(s){const p=a.pendingStructs.update;a.pendingStructs=null,a4(i.doc,p)}},n,!1),a4=(t,e,n,r=Gf)=>{const i=Kc(e);dY(i,t,n,new r(i))},pY=(t,e,n)=>a4(t,e,n,i4),mY=(t,e,n=new Map)=>{sA(t,e.store,n),uh(t,aY(e.store))},gY=(t,e=new Uint8Array([0]),n=new kc)=>{const r=l4(e);mY(n,t,r);const i=[n.toUint8Array()];if(t.store.pendingDs&&i.push(t.store.pendingDs),t.store.pendingStructs&&i.push(LY(t.store.pendingStructs.update,e)),i.length>1){if(n.constructor===nm)return PY(i.map((s,o)=>o===0?s:OY(s)));if(n.constructor===kc)return Kv(i)}return i[0]},vY=(t,e)=>gY(t,e,new nm),yY=t=>{const e=new Map,n=bt(t.restDecoder);for(let r=0;ryY(new r4(Kc(t))),c4=(t,e)=>(Rt(t.restEncoder,e.size),yl(e.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{Rt(t.restEncoder,n),Rt(t.restEncoder,r)}),t),_Y=(t,e)=>c4(t,g_(e.store)),xY=(t,e=new o4)=>(t instanceof Map?c4(e,t):_Y(e,t),e.toUint8Array()),SY=t=>xY(t,new s4);class EY{constructor(){this.l=[]}}const JP=()=>new EY,QP=(t,e)=>t.l.push(e),eI=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter(i=>e!==i),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},u4=(t,e,n)=>tA(t.l,[e,n]);class Sf{constructor(e,n){this.client=e,this.clock=n}}const E0=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,Ot=(t,e)=>new Sf(t,e),wY=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw To()},Vu=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!t4(e.ds,t.id),Vw=(t,e)=>{const n=Ll(t.meta,Vw,Hf),r=t.doc.store;n.has(e)||(e.sv.forEach((i,s)=>{i{}),n.add(e))};class f4{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const g_=t=>{const e=new Map;return t.clients.forEach((n,r)=>{const i=n[n.length-1];e.set(r,i.id.clock+i.length)}),e},hr=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},h4=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw To()}n.push(e)},Ao=(t,e)=>{let n=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===e)return r;let o=vl(e/(s+i.length-1)*r);for(;n<=r;){if(i=t[o],s=i.id.clock,s<=e){if(e{const n=t.clients.get(e.client);return n[Ao(n,e.clock)]},RS=MY,Gw=(t,e,n)=>{const r=Ao(e,n),i=e[r];return i.id.clock{const n=t.doc.store.clients.get(e.client);return n[Gw(t,n,e.clock)]},tI=(t,e,n)=>{const r=e.clients.get(n.client),i=Ao(r,n.clock),s=r[i];return n.clock!==s.id.clock+s.length-1&&s.constructor!==rs&&r.splice(i+1,0,ty(t,s,n.clock-s.id.clock+1)),s},TY=(t,e,n)=>{const r=t.clients.get(e.id.client);r[Ao(r,e.id.clock)]=n},d4=(t,e,n,r,i)=>{if(r===0)return;const s=n+r;let o=Gw(t,e,n),a;do a=e[o++],se.deleteSet.clients.size===0&&!E$(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(rA(e.deleteSet),hY(t,e),uh(t,e.deleteSet),!0),rI=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&Ll(t.changed,e,Hf).add(n)},rv=(t,e)=>{let n=t[e],r=t[e-1],i=e;for(;i>0;n=r,r=t[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof qn&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const s=e-i;return s&&t.splice(e+1-s,s),s},CY=(t,e,n)=>{for(const[r,i]of t.clients.entries()){const s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){const a=i[o],l=a.clock+a.len;for(let c=Ao(s,a.clock),h=s[c];c{t.clients.forEach((n,r)=>{const i=e.clients.get(r);for(let s=n.length-1;s>=0;s--){const o=n[s],a=H3(i.length-1,1+Ao(i,o.clock+o.len-1));for(let l=a,c=i[l];l>0&&c.id.clock>=o.clock;c=i[l])l-=1+rv(i,l)}})},p4=(t,e)=>{if(ea.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(n,l)})),a.push(()=>{n.changedParentTypes.forEach((l,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=c,h._path=null}),l.sort((h,d)=>h.path.length-d.path.length),u4(c._dEH,l,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),tA(a,[]),n._needFormattingCleanup&&YY(n)}finally{r.gc&&CY(s,i,r.gcFilter),RY(s,i),n.afterState.forEach((h,d)=>{const p=n.beforeState.get(d)||0;if(p!==h){const m=i.clients.get(d),y=Yc(Ao(m,p),1);for(let S=m.length-1;S>=y;)S-=1+rv(m,S)}});for(let h=o.length-1;h>=0;h--){const{client:d,clock:p}=o[h].id,m=i.clients.get(d),y=Ao(m,p);y+11||y>0&&rv(m,y)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(tY(J3,K3,"[yjs] ",q3,Z3,"Changed the client-id because another client seems to be using it."),r.clientID=n4()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const h=new nm;nI(h,n)&&r.emit("update",[h.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const h=new kc;nI(h,n)&&r.emit("updateV2",[h.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:l,subdocsRemoved:c}=n;(a.size>0||c.size>0||l.size>0)&&(a.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),c.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:l,added:a,removed:c},r,n]),c.forEach(h=>h.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):p4(t,e+1)}}},nn=(t,e,n=null,r=!0)=>{const i=t._transactionCleanups;let s=!1,o=null;t._transaction===null&&(s=!0,t._transaction=new AY(t,n,r),i.push(t._transaction),i.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(s){const a=t._transaction===i[0];t._transaction=null,a&&p4(i,0)}}return o};function*bY(t){const e=bt(t.restDecoder);for(let n=0;nKv(t,i4,nm),IY=(t,e)=>{if(t.constructor===rs){const{client:n,clock:r}=t.id;return new rs(Ot(n,r+e),t.length-e)}else if(t.constructor===is){const{client:n,clock:r}=t.id;return new is(Ot(n,r+e),t.length-e)}else{const n=t,{client:r,clock:i}=n.id;return new qn(Ot(r,i+e),null,Ot(r,i+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Kv=(t,e=Gf,n=kc)=>{if(t.length===1)return t[0];const r=t.map(h=>new e(Kc(h)));let i=r.map(h=>new oA(h,!0)),s=null;const o=new n,a=new aA(o);for(;i=i.filter(p=>p.curr!==null),i.sort((p,m)=>{if(p.curr.id.client===m.curr.id.client){const y=p.curr.id.clock-m.curr.id.clock;return y===0?p.curr.constructor===m.curr.constructor?0:p.curr.constructor===is?1:-1:y}else return m.curr.id.client-p.curr.id.client}),i.length!==0;){const h=i[0],d=h.curr.id.client;if(s!==null){let p=h.curr,m=!1;for(;p!==null&&p.id.clock+p.length<=s.struct.id.clock+s.struct.length&&p.id.client>=s.struct.id.client;)p=h.next(),m=!0;if(p===null||p.id.client!==d||m&&p.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ya(a,s.struct,s.offset),s={struct:p,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===is?s.struct.length-=y:p=IY(p,y)),s.struct.mergeWith(p)||(Ya(a,s.struct,s.offset),s={struct:p,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let p=h.curr;p!==null&&p.id.client===d&&p.id.clock===s.struct.id.clock+s.struct.length&&p.constructor!==is;p=h.next())Ya(a,s.struct,s.offset),s={struct:p,offset:0}}s!==null&&(Ya(a,s.struct,s.offset),s=null),lA(a);const l=r.map(h=>iA(h)),c=sY(l);return uh(o,c),o.toUint8Array()},LY=(t,e,n=Gf,r=kc)=>{const i=l4(e),s=new r,o=new aA(s),a=new n(Kc(t)),l=new oA(a,!1);for(;l.curr;){const h=l.curr,d=h.id.client,p=i.get(d)||0;if(l.curr.constructor===is){l.next();continue}if(h.id.clock+h.length>p)for(Ya(o,h,Yc(p-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)Ya(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=p;)l.next()}lA(o);const c=iA(a);return uh(s,c),s.toUint8Array()},m4=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Os(t.encoder.restEncoder)}),t.encoder.restEncoder=cl(),t.written=0)},Ya=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&m4(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Rt(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},lA=t=>{m4(t);const e=t.encoder.restEncoder;Rt(e,t.clientStructs.length);for(let n=0;n{const i=new n(Kc(t)),s=new oA(i,!1),o=new r,a=new aA(o);for(let c=s.curr;c!==null;c=s.next())Ya(a,e(c),0);lA(a);const l=iA(i);return uh(o,l),o.toUint8Array()},OY=t=>NY(t,U$,Gf,nm),iI="You must not compute changes after the event-handler fired.";class v_{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=kY(this.currentTarget,this.target))}deletes(e){return t4(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _l(iI);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(i=>{if(i!==null){const s=n._map.get(i);let o,a;if(this.adds(s)){let l=s.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(s))if(l!==null&&this.deletes(l))o="delete",a=MS(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",a=MS(l.content.getContent())):(o="add",a=void 0)}else if(this.deletes(s))o="delete",a=MS(s.content.getContent());else return;e.set(i,{action:o,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw _l(iI);const n=this.target,r=Hf(),i=Hf(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const l=()=>{a&&s.push(a)};for(let c=n._start;c!==null;c=c.right)c.deleted?this.deletes(c)&&!this.adds(c)&&((a===null||a.delete===void 0)&&(l(),a={delete:0}),a.delete+=c.length,i.add(c)):this.adds(c)?((a===null||a.insert===void 0)&&(l(),a={insert:[]}),a.insert=a.insert.concat(c.content.getContent()),r.add(c)):((a===null||a.retain===void 0)&&(l(),a={retain:0}),a.retain+=c.length);a!==null&&a.retain===void 0&&l()}this._changes=e}return e}}const kY=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)i.deleted||r++,i=i.right;n.unshift(r)}e=e._item.parent}return n},g4=80;let cA=0;class DY{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=cA++}}const UY=t=>{t.timestamp=cA++},v4=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=cA++},FY=(t,e,n)=>{if(t.length>=g4){const r=t.reduce((i,s)=>i.timestamp{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((s,o)=>ev(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&ev(n.index-i){for(let r=t.length-1;r>=0;r--){const i=t[r];if(n>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){t.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Yc(e,i.index+n))}},__=(t,e,n)=>{const r=t,i=e.changedParentTypes;for(;Ll(i,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;u4(r._eH,n,e)};class Er{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=JP(),this._dEH=JP(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw So()}clone(){throw So()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){QP(this._eH,e)}observeDeep(e){QP(this._dEH,e)}unobserve(e){eI(this._eH,e)}unobserveDeep(e){eI(this._dEH,e)}toJSON(){}}const y4=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const i=[];let s=t._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let a=e;a0;a++)i.push(o[a]),r--;e=0}}s=s.right}return i},_4=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let i=0;i{let n=0,r=t._start;for(;r!==null;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let s=0;s{const n=[];return Lp(t,(r,i)=>{n.push(e(r,i,t))}),n},BY=t=>{let e=t._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),r=0,e=e.right}const i=n[r++];return n.length<=r&&(n=null),{done:!1,value:i}}}},S4=(t,e)=>{const n=y_(t,e);let r=t._start;for(n!==null&&(r=n.p,e-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=n;const s=t.doc,o=s.clientID,a=s.store,l=n===null?e._start:n.right;let c=[];const h=()=>{c.length>0&&(i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new Fc(c)),i.integrate(t,0),c=[])};r.forEach(d=>{if(d===null)c.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new rm(new Uint8Array(d))),i.integrate(t,0);break;case fh:i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new im(d)),i.integrate(t,0);break;default:if(d instanceof Er)i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new _a(d)),i.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},E4=()=>_l("Length exceeded!"),w4=(t,e,n,r)=>{if(n>e._length)throw E4();if(n===0)return e._searchMarker&&Ip(e._searchMarker,n,r.length),qv(t,e,null,r);const i=n,s=y_(e,n);let o=e._start;for(s!==null&&(o=s.p,n-=s.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return qv(t,e,i,n)},M4=(t,e,n,r)=>{if(r===0)return;const i=n,s=r,o=y_(e,n);let a=e._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n0&&a!==null;)a.deleted||(r0)throw E4();e._searchMarker&&Ip(e._searchMarker,i,-s+r)},Zv=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},uA=(t,e,n,r)=>{const i=e._map.get(n)||null,s=t.doc,o=s.clientID;let a;if(r==null)a=new Fc([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:a=new Fc([r]);break;case Uint8Array:a=new rm(r);break;case fh:a=new im(r);break;default:if(r instanceof Er)a=new _a(r);else throw new Error("Unexpected content type")}new qn(Ot(o,hr(s.store,o)),i,i&&i.lastId,null,null,e,n,a).integrate(t,0)},fA=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},T4=t=>{const e={};return t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},A4=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},HY=(t,e)=>{const n={};return t._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&Vu(s,e)&&(n[i]=s.content.getContent()[s.length-1])}),n},w0=t=>rY(t.entries(),e=>!e[1].deleted);class VY extends v_{constructor(e,n){super(e,n),this._transaction=n}}class Ef extends Er{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new Ef;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ef}clone(){const e=new Ef;return e.insert(0,this.toArray().map(n=>n instanceof Er?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),__(this,e,new VY(this,e))}insert(e,n){this.doc!==null?nn(this.doc,r=>{w4(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?nn(this.doc,n=>{zY(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?nn(this.doc,r=>{M4(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return S4(this,e)}toArray(){return _4(this)}slice(e=0,n=this.length){return y4(this,e,n)}toJSON(){return this.map(e=>e instanceof Er?e.toJSON():e)}map(e){return x4(this,e)}forEach(e){Lp(this,e)}[Symbol.iterator](){return BY(this)}_write(e){e.writeTypeRef(hK)}}const GY=t=>new Ef;class WY extends v_{constructor(e,n,r){super(e,n),this.keysChanged=r}}class Wf extends Er{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new Wf}clone(){const e=new Wf;return this.forEach((n,r)=>{e.set(r,n instanceof Er?n.clone():n)}),e}_callObserver(e,n){__(this,e,new WY(this,e,n))}toJSON(){const e={};return this._map.forEach((n,r)=>{if(!n.deleted){const i=n.content.getContent()[n.length-1];e[r]=i instanceof Er?i.toJSON():i}}),e}get size(){return[...w0(this._map)].length}keys(){return CS(w0(this._map),e=>e[0])}values(){return CS(w0(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return CS(w0(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,r)=>{n.deleted||e(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?nn(this.doc,n=>{Zv(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?nn(this.doc,r=>{uA(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return fA(this,e)}has(e){return A4(this,e)}clear(){this.doc!==null?nn(this.doc,e=>{this.forEach(function(n,r,i){Zv(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(dK)}}const XY=t=>new Wf,Za=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&D$(t,e);class Ww{constructor(e,n,r,i){this.left=e,this.right=n,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&To(),this.right.content.constructor){case Qn:this.right.deleted||hh(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const sI=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case Qn:e.right.deleted||hh(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n{const i=new Map,s=r?y_(e,n):null;if(s){const o=new Ww(s.p.left,s.p,s.index,i);return sI(t,o,n-s.index)}else{const o=new Ww(null,e._start,0,i);return sI(t,o,n)}},C4=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Qn&&Za(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const i=t.doc,s=i.clientID;r.forEach((o,a)=>{const l=n.left,c=n.right,h=new qn(Ot(s,hr(i.store,s)),l,l&&l.lastId,c,c&&c.id,e,null,new Qn(a,o));h.integrate(t,0),n.right=h,n.forward()})},hh=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},R4=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===Qn&&Za(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},b4=(t,e,n,r)=>{const i=t.doc,s=i.clientID,o=new Map;for(const a in r){const l=r[a],c=n.currentAttributes.get(a)??null;if(!Za(c,l)){o.set(a,c);const{left:h,right:d}=n;n.right=new qn(Ot(s,hr(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new Qn(a,l)),n.right.integrate(t,0),n.forward()}}return o},bS=(t,e,n,r,i)=>{n.currentAttributes.forEach((p,m)=>{i[m]===void 0&&(i[m]=null)});const s=t.doc,o=s.clientID;R4(n,i);const a=b4(t,e,n,i),l=r.constructor===String?new Co(r):r instanceof Er?new _a(r):new qc(r);let{left:c,right:h,index:d}=n;e._searchMarker&&Ip(e._searchMarker,n.index,l.getLength()),h=new qn(Ot(o,hr(s.store,o)),c,c&&c.lastId,h,h&&h.id,e,null,l),h.integrate(t,0),n.right=h,n.index=d,n.forward(),C4(t,e,n,a)},oI=(t,e,n,r,i)=>{const s=t.doc,o=s.clientID;R4(n,i);const a=b4(t,e,n,i);e:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===Qn));){if(!n.right.deleted)switch(n.right.content.constructor){case Qn:{const{key:l,value:c}=n.right.content,h=i[l];if(h!==void 0){if(Za(h,c))a.delete(l);else{if(r===0)break e;a.set(l,c)}n.right.delete(t)}else n.currentAttributes.set(l,c);break}default:r0){let l="";for(;r>0;r--)l+=` + */var jT=new WeakMap,wj=function(){function t(e){this.observers=new Map,this.obj=e}return t}(),Mj=function(){function t(e,n){this.callback=e,this.observer=n}return t}();function Tj(t){return jT.get(t)}function Aj(t,e){return t.observers.get(e)}function Cj(t,e){t.observers.delete(e.callback)}function Rj(t,e){e.unobserve()}function bj(t,e){var n=[],r,i=Tj(t);if(!i)i=new wj(t),jT.set(t,i);else{var s=Aj(i,e);r=s&&s.observer}if(r)return r;if(r={},i.value=fi(t),e){r.callback=e,r.next=null;var o=function(){Nw(r)},a=function(){clearTimeout(r.next),r.next=setTimeout(o)};typeof window<"u"&&(window.addEventListener("mouseup",a),window.addEventListener("keyup",a),window.addEventListener("mousedown",a),window.addEventListener("keydown",a),window.addEventListener("change",a))}return r.patches=n,r.object=t,r.unobserve=function(){Nw(r),clearTimeout(r.next),Cj(i,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},i.observers.set(e,new Mj(e,r)),r}function Nw(t,e){e===void 0&&(e=!1);var n=jT.get(t.object);$T(n.value,t.object,t.patches,"",e),t.patches.length&&f_(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function $T(t,e,n,r,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var s=Pw(e),o=Pw(t),a=!1,l=o.length-1;l>=0;l--){var c=o[l],h=t[c];if(bw(e,c)&&!(e[c]===void 0&&h!==void 0&&Array.isArray(e)===!1)){var d=e[c];typeof h=="object"&&h!=null&&typeof d=="object"&&d!=null&&Array.isArray(h)===Array.isArray(d)?$T(h,d,n,r+"/"+sc(c),i):h!==d&&(i&&n.push({op:"test",path:r+"/"+sc(c),value:fi(h)}),n.push({op:"replace",path:r+"/"+sc(c),value:fi(d)}))}else Array.isArray(t)===Array.isArray(e)?(i&&n.push({op:"test",path:r+"/"+sc(c),value:fi(h)}),n.push({op:"remove",path:r+"/"+sc(c)}),a=!0):(i&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}))}if(!(!a&&s.length==o.length))for(var l=0;lnew Proxy(t,e);const Ow=Object.getPrototypeOf,kw=new WeakMap,F3=t=>t&&(kw.has(t)?kw.get(t):Ow(t)===Object.prototype||Ow(t)===Array.prototype),jv=t=>typeof t=="object"&&t!==null,Oj=t=>{if(Array.isArray(t))return Array.from(t);const e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(n=>{n.configurable=!0}),Object.create(Ow(t),e)},KT=t=>t[YT]||t,B3=(t,e,n,r)=>{if(!F3(t))return t;let i=r&&r.get(t);if(!i){const l=KT(t);i=(c=>Object.values(Object.getOwnPropertyDescriptors(c)).some(h=>!h.configurable&&!h.writable))(l)?[l,Oj(l)]:[l],r==null||r.set(t,i)}const[s,o]=i;let a=n&&n.get(s);return a&&a[1].f===!!o||(a=((l,c)=>{const h={f:c};let d=!1;const p=(y,S)=>{if(!d){let E=h[sd].get(l);if(E||(E={},h[sd].set(l,E)),y===Od)E[Od]=!0;else{let g=E[y];g||(g=new Set,E[y]=g),g.add(S)}}},m={get:(y,S)=>S===YT?l:(p("k",S),B3(Reflect.get(y,S),h[sd],h.c,h.t)),has:(y,S)=>S===Lj?(d=!0,h[sd].delete(l),!0):(p("h",S),Reflect.has(y,S)),getOwnPropertyDescriptor:(y,S)=>(p("o",S),Reflect.getOwnPropertyDescriptor(y,S)),ownKeys:y=>(p(Od),Reflect.ownKeys(y))};return c&&(m.set=m.deleteProperty=()=>!1),[m,h]})(s,!!o),a[1].p=Nj(o||s,a[0]),n&&n.set(s,a)),a[1][sd]=e,a[1].c=n,a[1].t=r,a[1].p},z3=(t,e,n,r,i=Object.is)=>{if(i(t,e))return!1;if(!jv(t)||!jv(e))return!0;const s=n.get(KT(t));if(!s)return!0;if(r){const a=r.get(t);if(a&&a.n===e)return a.g;r.set(t,{n:e,g:!1})}let o=null;try{for(const a of s.h||[])if(o=Reflect.has(t,a)!==Reflect.has(e,a),o)return o;if(s[Od]===!0){if(o=((a,l)=>{const c=Reflect.ownKeys(a),h=Reflect.ownKeys(l);return c.length!==h.length||c.some((d,p)=>d!==h[p])})(t,e),o)return o}else for(const a of s.o||[])if(o=!!Reflect.getOwnPropertyDescriptor(t,a)!=!!Reflect.getOwnPropertyDescriptor(e,a),o)return o;for(const a of s.k||[])if(o=z3(t[a],e[a],n,r,i),o)return o;return o===null&&(o=!0),o}finally{r&&r.set(t,{n:e,g:o})}},kj=t=>F3(t)&&t[YT]||null,DP=(t,e=!0)=>{kw.set(t,e)},Dj=(t,e,n)=>{const r=[],i=new WeakSet,s=(o,a)=>{if(i.has(o))return;jv(o)&&i.add(o);const l=jv(o)&&e.get(KT(o));if(l){var c,h;if((c=l.h)==null||c.forEach(p=>{const m=`:has(${String(p)})`;r.push(a?[...a,m]:[m])}),l[Od]===!0){const p=":ownKeys";r.push(a?[...a,p]:[p])}else{var d;(d=l.o)==null||d.forEach(p=>{const m=`:hasOwn(${String(p)})`;r.push(a?[...a,m]:[m])})}(h=l.k)==null||h.forEach(p=>{n&&!("value"in(Object.getOwnPropertyDescriptor(o,p)||{}))||s(o[p],a?[...a,p]:[p])})}else a&&r.push(a)};return s(t),r};var $v={ZSS_LANG_DEV:"false",ZSS_STATS_DEV:"false",ZSS_SHOW_CODE:"false",ZSS_BRANCH_NAME:"main",ZSS_BRANCH_VERSION:"0.2.2",ZSS_COMMIT_HASH:"9b88f8ce2ee656d2b45fdd98977515a61ee80f22",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.2",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const _S=t=>typeof t=="object"&&t!==null,Wa=new WeakMap,S0=new WeakSet,Uj=(t=Object.is,e=(c,h)=>new Proxy(c,h),n=c=>_S(c)&&!S0.has(c)&&(Array.isArray(c)||!(Symbol.iterator in c))&&!(c instanceof WeakMap)&&!(c instanceof WeakSet)&&!(c instanceof Error)&&!(c instanceof Number)&&!(c instanceof Date)&&!(c instanceof String)&&!(c instanceof RegExp)&&!(c instanceof ArrayBuffer),r=c=>{switch(c.status){case"fulfilled":return c.value;case"rejected":throw c.reason;default:throw c}},i=new WeakMap,s=(c,h,d=r)=>{const p=i.get(c);if((p==null?void 0:p[0])===h)return p[1];const m=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c));return DP(m,!0),i.set(c,[h,m]),Reflect.ownKeys(c).forEach(y=>{if(Object.getOwnPropertyDescriptor(m,y))return;const S=Reflect.get(c,y),{enumerable:E}=Reflect.getOwnPropertyDescriptor(c,y),g={value:S,enumerable:E,configurable:!0};if(S0.has(S))DP(S,!1);else if(S instanceof Promise)delete g.value,g.get=()=>d(S);else if(Wa.has(S)){const[x,_]=Wa.get(S);g.value=s(x,_(),d)}Object.defineProperty(m,y,g)}),Object.preventExtensions(m)},o=new WeakMap,a=[1,1],l=c=>{if(!_S(c))throw new Error("object required");const h=o.get(c);if(h)return h;let d=a[0];const p=new Set,m=(R,P=++a[0])=>{d!==P&&(d=P,p.forEach(O=>O(R,P)))};let y=a[1];const S=(R=++a[1])=>(y!==R&&!p.size&&(y=R,g.forEach(([P])=>{const O=P[1](R);O>d&&(d=O)})),d),E=R=>(P,O)=>{const X=[...P];X[1]=[R,...X[1]],m(X,O)},g=new Map,x=(R,P)=>{if(($v?"production":void 0)!=="production"&&g.has(R))throw new Error("prop listener already exists");if(p.size){const O=P[3](E(R));g.set(R,[P,O])}else g.set(R,[P])},_=R=>{var P;const O=g.get(R);O&&(g.delete(R),(P=O[1])==null||P.call(O))},M=R=>(p.add(R),p.size===1&&g.forEach(([O,X],j)=>{if(($v?"production":void 0)!=="production"&&X)throw new Error("remove already exists");const H=O[3](E(j));g.set(j,[O,H])}),()=>{p.delete(R),p.size===0&&g.forEach(([O,X],j)=>{X&&(X(),g.set(j,[O]))})}),C=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c)),I=e(C,{deleteProperty(R,P){const O=Reflect.get(R,P);_(P);const X=Reflect.deleteProperty(R,P);return X&&m(["delete",[P],O]),X},set(R,P,O,X){const j=Reflect.has(R,P),H=Reflect.get(R,P,X);if(j&&(t(H,O)||o.has(O)&&t(H,o.get(O))))return!0;_(P),_S(O)&&(O=kj(O)||O);let J=O;if(O instanceof Promise)O.then(ee=>{O.status="fulfilled",O.value=ee,m(["resolve",[P],ee])}).catch(ee=>{O.status="rejected",O.reason=ee,m(["reject",[P],ee])});else{!Wa.has(O)&&n(O)&&(J=l(O));const ee=!S0.has(J)&&Wa.get(J);ee&&x(P,ee)}return Reflect.set(R,P,J,X),m(["set",[P],O,H]),!0}});o.set(c,I);const N=[C,S,s,M];return Wa.set(I,N),Reflect.ownKeys(c).forEach(R=>{const P=Object.getOwnPropertyDescriptor(c,R);"value"in P&&(I[R]=c[R],delete P.value,delete P.writable),Object.defineProperty(C,R,P)}),I})=>[l,Wa,S0,t,e,n,r,i,s,o,a],[Fj]=Uj();function qT(t={}){return Fj(t)}function Bj(t,e,n){const r=Wa.get(t);($v?"production":void 0)!=="production"&&!r&&console.warn("Please use proxy object");let i;const s=[],o=r[3];let a=!1;const c=o(h=>{if(s.push(h),n){e(s.splice(0));return}i||(i=Promise.resolve().then(()=>{i=void 0,a&&e(s.splice(0))}))});return a=!0,()=>{a=!1,c()}}function UP(t,e){const n=Wa.get(t);($v?"production":void 0)!=="production"&&!n&&console.warn("Please use proxy object");const[r,i,s]=n;return s(r,i(),e)}var zj={ZSS_LANG_DEV:"false",ZSS_STATS_DEV:"false",ZSS_SHOW_CODE:"false",ZSS_BRANCH_NAME:"main",ZSS_BRANCH_VERSION:"0.2.2",ZSS_COMMIT_HASH:"9b88f8ce2ee656d2b45fdd98977515a61ee80f22",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.2",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const{use:FP}=Bd,{useSyncExternalStore:Hj}=aj,Vj=(t,e)=>{const n=K.useRef();K.useEffect(()=>{n.current=Dj(t,e,!0)}),K.useDebugValue(n.current)},Gj=new WeakMap;function h_(t,e){const n=e==null?void 0:e.sync,r=K.useRef(),i=K.useRef();let s=!0;const o=Hj(K.useCallback(c=>{const h=Bj(t,c,n);return c(),h},[t,n]),()=>{const c=UP(t,FP);try{if(!s&&r.current&&i.current&&!z3(r.current,c,i.current,new WeakMap))return r.current}catch{}return c},()=>UP(t,FP));s=!1;const a=new WeakMap;K.useEffect(()=>{r.current=o,i.current=a}),(zj?"production":void 0)!=="production"&&Vj(o,a);const l=K.useMemo(()=>new WeakMap,[]);return B3(o,a,l,Gj)}let xS=!1;const Ts=qT({state:{player:"",layers:[],layout:[],layoutreset:!1,layoutfocus:""}}),SS=WT("gadgetclient",["ready","second"],t=>{switch(t.target){case"ready":t.player&&Ts.state.player===""&&(Ts.state.player=t.player,SS.emit("vm:login",void 0,Ts.state.player));break;case"second":Ts.state.player&&SS.emit("vm:doot",void 0,Ts.state.player);break;case"reset":t.player===Ts.state.player&&(xS=!1,Ts.state=t.data);break;case"patch":if(t.player===Ts.state.player&&!xS)try{f_(Ts.state,t.data,!0)}catch(e){e instanceof XT&&(xS=!0,SS.reply(t,"desync",void 0,Ts.state.player))}break}});function Wj(){return Ts.state}const BP=1,zP=2,ES=4,wS=8,Ap=32,oa=64,Oi=128,d_=31,Dw=63,Tc=127,Xj=2147483647,vl=Math.floor,ev=Math.abs,H3=(t,e)=>tt>e?t:e,V3=t=>t!==0?t<0:1/t<0,G3=Number.MAX_SAFE_INTEGER,jj=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&vl(t)===t),Hf=()=>new Set,MS=t=>t[t.length-1],$j=(t,e)=>{for(let n=0;nt.toLowerCase(),qj=/^\s*/g,Zj=t=>t.replace(qj,""),Jj=/([A-Z])/g,HP=(t,e)=>Zj(t.replace(Jj,n=>`${e}${Kj(n)}`)),Qj=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let i=0;iCp.encode(t),t$=Cp?e$:Qj;let kd=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});kd&&kd.decode(new Uint8Array).length===1&&(kd=null);const _l=t=>new Error(t),So=()=>{throw _l("Method unimplemented")},To=()=>{throw _l("Unexpected case")};class em{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const cl=()=>new em,n$=t=>{let e=t.cpos;for(let n=0;n{const e=new Uint8Array(n$(t));let n=0;for(let r=0;r{const n=t.cbuf.length;n-t.cpos{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Uw=cr,Rt=(t,e)=>{for(;e>Tc;)cr(t,Oi|Tc&e),e=vl(e/128);cr(t,Tc&e)},ZT=(t,e)=>{const n=V3(e);for(n&&(e=-e),cr(t,(e>Dw?Oi:0)|(n?oa:0)|Dw&e),e=vl(e/64);e>0;)cr(t,(e>Tc?Oi:0)|Tc&e),e=vl(e/128)},Fw=new Uint8Array(3e4),i$=Fw.length/3,s$=(t,e)=>{if(e.length{const n=unescape(encodeURIComponent(e)),r=n.length;Rt(t,r);for(let i=0;i{const n=t.cbuf.length,r=t.cpos,i=H3(n-r,e.length),s=e.length-i;t.cbuf.set(e.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Yc(n*2,s)),t.cbuf.set(e.subarray(i)),t.cpos=s)},Nr=(t,e)=>{Rt(t,e.byteLength),p_(t,e)},JT=(t,e)=>{r$(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},a$=(t,e)=>JT(t,4).setFloat32(0,e,!1),l$=(t,e)=>JT(t,8).setFloat64(0,e,!1),c$=(t,e)=>JT(t,8).setBigInt64(0,e,!1),VP=new DataView(new ArrayBuffer(4)),u$=t=>(VP.setFloat32(0,t),VP.getFloat32(0)===t),Rp=(t,e)=>{switch(typeof e){case"string":cr(t,119),_f(t,e);break;case"number":jj(e)&&ev(e)<=Xj?(cr(t,125),ZT(t,e)):u$(e)?(cr(t,124),a$(t,e)):(cr(t,123),l$(t,e));break;case"bigint":cr(t,122),c$(t,e);break;case"object":if(e===null)cr(t,126);else if(Yj(e)){cr(t,117),Rt(t,e.length);for(let n=0;n0&&Rt(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const WP=t=>{t.count>0&&(ZT(t.encoder,t.count===1?t.s:-t.s),t.count>1&&Rt(t.encoder,t.count-2))};class tv{constructor(){this.encoder=new em,this.s=0,this.count=0}write(e){this.s===e?this.count++:(WP(this),this.count=1,this.s=e)}toUint8Array(){return WP(this),Os(this.encoder)}}const XP=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);ZT(t.encoder,e),t.count>1&&Rt(t.encoder,t.count-2)}};class TS{constructor(){this.encoder=new em,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(XP(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return XP(this),Os(this.encoder)}}class f${constructor(){this.sarr=[],this.s="",this.lensE=new tv}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new em;return this.sarr.push(this.s),this.s="",_f(e,this.sarr.join("")),p_(e,this.lensE.toUint8Array()),Os(e)}}const W3=_l("Unexpected end of array"),X3=_l("Integer out of Range");class m_{constructor(e){this.arr=e,this.pos=0}}const Kc=t=>new m_(t),h$=t=>t.pos!==t.arr.length,d$=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},Wr=t=>d$(t,bt(t)),Vf=t=>t.arr[t.pos++],bt=t=>{let e=0,n=1;const r=t.arr.length;for(;t.posG3)throw X3}throw W3},QT=t=>{let e=t.arr[t.pos++],n=e&Dw,r=64;const i=(e&oa)>0?-1:1;if(!(e&Oi))return i*n;const s=t.arr.length;for(;t.posG3)throw X3}throw W3},p$=t=>{let e=bt(t);if(e===0)return"";{let n=String.fromCodePoint(Vf(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(Vf(t));else for(;e>0;){const r=e<1e4?e:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(n))}},m$=t=>kd.decode(Wr(t)),xf=kd?m$:p$,eA=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},g$=t=>eA(t,4).getFloat32(0,!1),v$=t=>eA(t,8).getFloat64(0,!1),y$=t=>eA(t,8).getBigInt64(0,!1),_$=[t=>{},t=>null,QT,g$,v$,y$,t=>!1,t=>!0,xf,t=>{const e=bt(t),n={};for(let r=0;r{const e=bt(t),n=[];for(let r=0;r_$[127-Vf(t)](t);class jP extends m_{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),h$(this)?this.count=bt(this)+1:this.count=-1),this.count--,this.s}}class nv extends m_{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=QT(this);const e=V3(this.s);this.count=1,e&&(this.s=-this.s,this.count=bt(this)+2)}return this.count--,this.s}}class AS extends m_{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=QT(this),n=e&1;this.diff=vl(e/2),this.count=1,n&&(this.count=bt(this)+2)}return this.s+=this.diff,this.count--,this.s}}class x${constructor(e){this.decoder=new nv(e),this.str=xf(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const Bs=()=>new Map,Bw=t=>{const e=Bs();return t.forEach((n,r)=>{e.set(r,n)}),e},Ll=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},S$=(t,e)=>{const n=[];for(const[r,i]of t)n.push(e(i,r));return n},E$=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1};class w${constructor(){this._observers=Bs()}on(e,n){return Ll(this._observers,e,Hf).add(n),n}once(e,n){const r=(...i)=>{this.off(e,r),n(...i)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return yl((this._observers.get(e)||Bs()).values()).forEach(r=>r(...n))}destroy(){this._observers=Bs()}}const M$=crypto.getRandomValues.bind(crypto),j3=()=>M$(new Uint32Array(1))[0],T$="10000000-1000-4000-8000"+-1e11,A$=()=>T$.replace(/[018]/g,t=>(t^j3()&15>>t/4).toString(16)),$P=t=>new Promise(t);Promise.all.bind(Promise);const YP=t=>t===void 0?null:t;class C${constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let $3=new C$,R$=!0;try{typeof localStorage<"u"&&localStorage&&($3=localStorage,R$=!1)}catch{}const b$=$3,P$=Object.assign,I$=Object.keys,L$=(t,e)=>{for(const n in t)e(t[n],n)},KP=t=>I$(t).length,N$=t=>{for(const e in t)return!1;return!0},O$=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},k$=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),D$=(t,e)=>t===e||KP(t)===KP(e)&&O$(t,(n,r)=>(n!==void 0||k$(e,r))&&e[r]===n),tA=(t,e,n=0)=>{try{for(;nt,F$=(t,e)=>e.includes(t);var Y3={};const Pp=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let ao;const B$=()=>{if(ao===void 0)if(Pp){ao=Bs();const t=process.argv;let e=null;for(let n=0;n{if(t.length!==0){const[e,n]=t.split("=");ao.set(`--${HP(e,"-")}`,n),ao.set(`-${HP(e,"-")}`,n)}})):ao=Bs();return ao},zw=t=>B$().has(t),Hw=t=>YP(Pp?Y3[t.toUpperCase().replaceAll("-","_")]:b$.getItem(t)),z$=t=>zw("--"+t)||Hw(t)!==null;z$("production");const qP=Pp&&F$(Y3.FORCE_COLOR,["true","1","2"]),H$=!zw("no-colors")&&(!Pp||process.stdout.isTTY||qP)&&(!Pp||zw("color")||qP||Hw("COLORTERM")!==null||(Hw("TERM")||"").includes("color")),V$=t=>new Uint8Array(t),G$=t=>{const e=V$(t.byteLength);return e.set(t),e};class W${constructor(e,n){this.left=e,this.right=n}}const Zo=(t,e)=>new W$(t,e);typeof DOMParser<"u"&&new DOMParser;const X$=t=>S$(t,(e,n)=>`${n}:${e};`).join(""),ya=Symbol,K3=ya(),q3=ya(),j$=ya(),$$=ya(),Y$=ya(),Z3=ya(),K$=ya(),J3=ya(),q$=ya(),Z$=t=>{var r;t.length===1&&((r=t[0])==null?void 0:r.constructor)===Function&&(t=t[0]());const e=[];let n=0;for(;n{var o;t.length===1&&((o=t[0])==null?void 0:o.constructor)===Function&&(t=t[0]());const e=[],n=[],r=Bs();let i=[],s=0;for(;s0||c.length>0?(e.push("%c"+a),n.push(c)):e.push(a)}else break}}for(s>0&&(i=n,i.unshift(e.join("")));s{console.log(...eY(t)),nY.forEach(e=>e.print(t))},nY=Hf(),Q3=t=>({[Symbol.iterator](){return this},next:t}),rY=(t,e)=>Q3(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),CS=(t,e)=>Q3(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class nA{constructor(e,n){this.clock=e,this.len=n}}class tm{constructor(){this.clients=new Map}}const e4=(t,e,n)=>e.clients.forEach((r,i)=>{const s=t.doc.store.clients.get(i);for(let o=0;o{let n=0,r=t.length-1;for(;n<=r;){const i=vl((n+r)/2),s=t[i],o=s.clock;if(o<=e){if(e{const n=t.clients.get(e.client);return n!==void 0&&iY(n,e.clock)!==null},rA=t=>{t.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let n,r;for(n=1,r=1;n=s.clock?i.len=Yc(i.len,s.clock+s.len-i.clock):(r{const e=new tm;for(let n=0;n{if(!e.clients.has(i)){const s=r.slice();for(let o=n+1;o{Ll(t.clients,e,()=>[]).push(new nA(n,r))},oY=()=>new tm,aY=t=>{const e=oY();return t.clients.forEach((n,r)=>{const i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},uh=(t,e)=>{Rt(t.restEncoder,e.clients.size),yl(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),Rt(t.restEncoder,n);const i=r.length;Rt(t.restEncoder,i);for(let s=0;s{const e=new tm,n=bt(t.restDecoder);for(let r=0;r0){const o=Ll(e.clients,i,()=>[]);for(let a=0;a{const r=new tm,i=bt(t.restDecoder);for(let s=0;s0){const s=new kc;return Rt(s.restEncoder,0),uh(s,r),s.toUint8Array()}return null},n4=j3;class fh extends w${constructor({guid:e=A$(),collectionid:n=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=n4(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new f4,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=$P(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const l=()=>$P(c=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),c())};this.on("sync",h)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&nn(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(yl(this.subdocs).map(e=>e.guid))}transact(e,n=null){return nn(this,e,n)}get(e,n=Er){const r=Ll(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),i=r.constructor;if(n!==Er&&i!==n)if(i===Er){const s=new n;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,Ef)}getText(e=""){return this.get(e,Dc)}getMap(e=""){return this.get(e,Wf)}getXmlElement(e=""){return this.get(e,Xf)}getXmlFragment(e=""){return this.get(e,Uc)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){yl(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new fh({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,nn(e.parent.doc,r=>{const i=n.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class r4{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return bt(this.restDecoder)}readDsLen(){return bt(this.restDecoder)}}class i4 extends r4{readLeftID(){return Ot(bt(this.restDecoder),bt(this.restDecoder))}readRightID(){return Ot(bt(this.restDecoder),bt(this.restDecoder))}readClient(){return bt(this.restDecoder)}readInfo(){return Vf(this.restDecoder)}readString(){return xf(this.restDecoder)}readParentInfo(){return bt(this.restDecoder)===1}readTypeRef(){return bt(this.restDecoder)}readLen(){return bt(this.restDecoder)}readAny(){return bp(this.restDecoder)}readBuf(){return G$(Wr(this.restDecoder))}readJSON(){return JSON.parse(xf(this.restDecoder))}readKey(){return xf(this.restDecoder)}}class lY{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=bt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=bt(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class Gf extends lY{constructor(e){super(e),this.keys=[],bt(e),this.keyClockDecoder=new AS(Wr(e)),this.clientDecoder=new nv(Wr(e)),this.leftClockDecoder=new AS(Wr(e)),this.rightClockDecoder=new AS(Wr(e)),this.infoDecoder=new jP(Wr(e),Vf),this.stringDecoder=new x$(Wr(e)),this.parentInfoDecoder=new jP(Wr(e),Vf),this.typeRefDecoder=new nv(Wr(e)),this.lenDecoder=new nv(Wr(e))}readLeftID(){return new Sf(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Sf(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return bp(this.restDecoder)}readBuf(){return Wr(this.restDecoder)}readJSON(){return bp(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e{r=Yc(r,e[0].id.clock);const i=Ao(e,r);Rt(t.restEncoder,e.length-i),t.writeClient(n),Rt(t.restEncoder,r);const s=e[i];s.write(t,r-s.id.clock);for(let o=i+1;o{const r=new Map;n.forEach((i,s)=>{hr(e,s)>i&&r.set(s,i)}),g_(e).forEach((i,s)=>{n.has(s)||r.set(s,0)}),Rt(t.restEncoder,r.size),yl(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{cY(t,e.clients.get(i),i,s)})},uY=(t,e)=>{const n=Bs(),r=bt(t.restDecoder);for(let i=0;i{const r=[];let i=yl(n.keys()).sort((m,y)=>m-y);if(i.length===0)return null;const s=()=>{if(i.length===0)return null;let m=n.get(i[i.length-1]);for(;m.refs.length===m.i;)if(i.pop(),i.length>0)m=n.get(i[i.length-1]);else return null;return m};let o=s();if(o===null)return null;const a=new f4,l=new Map,c=(m,y)=>{const S=l.get(m);(S==null||S>y)&&l.set(m,y)};let h=o.refs[o.i++];const d=new Map,p=()=>{for(const m of r){const y=m.id.client,S=n.get(y);S?(S.i--,a.clients.set(y,S.refs.slice(S.i)),n.delete(y),S.i=0,S.refs=[]):a.clients.set(y,[m]),i=i.filter(E=>E!==y)}r.length=0};for(;;){if(h.constructor!==is){const y=Ll(d,h.id.client,()=>hr(e,h.id.client))-h.id.clock;if(y<0)r.push(h),c(h.id.client,h.id.clock-1),p();else{const S=h.getMissing(t,e);if(S!==null){r.push(h);const E=n.get(S)||{refs:[],i:0};if(E.refs.length===E.i)c(S,hr(e,S)),p();else{h=E.refs[E.i++];continue}}else(y===0||y0)h=r.pop();else if(o!==null&&o.i0){const m=new kc;return sA(m,a,new Map),Rt(m.restEncoder,0),{missing:l,update:m.toUint8Array()}}return null},hY=(t,e)=>sA(t,e.doc.store,e.beforeState),dY=(t,e,n,r=new Gf(t))=>nn(e,i=>{i.local=!1;let s=!1;const o=i.doc,a=o.store,l=uY(r,o),c=fY(i,a,l),h=a.pendingStructs;if(h){for(const[p,m]of h.missing)if(mm)&&h.missing.set(p,m)}h.update=Kv([h.update,c.update])}}else a.pendingStructs=c;const d=ZP(r,i,a);if(a.pendingDs){const p=new Gf(Kc(a.pendingDs));bt(p.restDecoder);const m=ZP(p,i,a);d&&m?a.pendingDs=Kv([d,m]):a.pendingDs=d||m}else a.pendingDs=d;if(s){const p=a.pendingStructs.update;a.pendingStructs=null,a4(i.doc,p)}},n,!1),a4=(t,e,n,r=Gf)=>{const i=Kc(e);dY(i,t,n,new r(i))},pY=(t,e,n)=>a4(t,e,n,i4),mY=(t,e,n=new Map)=>{sA(t,e.store,n),uh(t,aY(e.store))},gY=(t,e=new Uint8Array([0]),n=new kc)=>{const r=l4(e);mY(n,t,r);const i=[n.toUint8Array()];if(t.store.pendingDs&&i.push(t.store.pendingDs),t.store.pendingStructs&&i.push(LY(t.store.pendingStructs.update,e)),i.length>1){if(n.constructor===nm)return PY(i.map((s,o)=>o===0?s:OY(s)));if(n.constructor===kc)return Kv(i)}return i[0]},vY=(t,e)=>gY(t,e,new nm),yY=t=>{const e=new Map,n=bt(t.restDecoder);for(let r=0;ryY(new r4(Kc(t))),c4=(t,e)=>(Rt(t.restEncoder,e.size),yl(e.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{Rt(t.restEncoder,n),Rt(t.restEncoder,r)}),t),_Y=(t,e)=>c4(t,g_(e.store)),xY=(t,e=new o4)=>(t instanceof Map?c4(e,t):_Y(e,t),e.toUint8Array()),SY=t=>xY(t,new s4);class EY{constructor(){this.l=[]}}const JP=()=>new EY,QP=(t,e)=>t.l.push(e),eI=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter(i=>e!==i),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},u4=(t,e,n)=>tA(t.l,[e,n]);class Sf{constructor(e,n){this.client=e,this.clock=n}}const E0=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,Ot=(t,e)=>new Sf(t,e),wY=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw To()},Vu=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!t4(e.ds,t.id),Vw=(t,e)=>{const n=Ll(t.meta,Vw,Hf),r=t.doc.store;n.has(e)||(e.sv.forEach((i,s)=>{i{}),n.add(e))};class f4{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const g_=t=>{const e=new Map;return t.clients.forEach((n,r)=>{const i=n[n.length-1];e.set(r,i.id.clock+i.length)}),e},hr=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},h4=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw To()}n.push(e)},Ao=(t,e)=>{let n=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===e)return r;let o=vl(e/(s+i.length-1)*r);for(;n<=r;){if(i=t[o],s=i.id.clock,s<=e){if(e{const n=t.clients.get(e.client);return n[Ao(n,e.clock)]},RS=MY,Gw=(t,e,n)=>{const r=Ao(e,n),i=e[r];return i.id.clock{const n=t.doc.store.clients.get(e.client);return n[Gw(t,n,e.clock)]},tI=(t,e,n)=>{const r=e.clients.get(n.client),i=Ao(r,n.clock),s=r[i];return n.clock!==s.id.clock+s.length-1&&s.constructor!==rs&&r.splice(i+1,0,ty(t,s,n.clock-s.id.clock+1)),s},TY=(t,e,n)=>{const r=t.clients.get(e.id.client);r[Ao(r,e.id.clock)]=n},d4=(t,e,n,r,i)=>{if(r===0)return;const s=n+r;let o=Gw(t,e,n),a;do a=e[o++],se.deleteSet.clients.size===0&&!E$(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(rA(e.deleteSet),hY(t,e),uh(t,e.deleteSet),!0),rI=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&Ll(t.changed,e,Hf).add(n)},rv=(t,e)=>{let n=t[e],r=t[e-1],i=e;for(;i>0;n=r,r=t[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof qn&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const s=e-i;return s&&t.splice(e+1-s,s),s},CY=(t,e,n)=>{for(const[r,i]of t.clients.entries()){const s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){const a=i[o],l=a.clock+a.len;for(let c=Ao(s,a.clock),h=s[c];c{t.clients.forEach((n,r)=>{const i=e.clients.get(r);for(let s=n.length-1;s>=0;s--){const o=n[s],a=H3(i.length-1,1+Ao(i,o.clock+o.len-1));for(let l=a,c=i[l];l>0&&c.id.clock>=o.clock;c=i[l])l-=1+rv(i,l)}})},p4=(t,e)=>{if(ea.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(n,l)})),a.push(()=>{n.changedParentTypes.forEach((l,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=c,h._path=null}),l.sort((h,d)=>h.path.length-d.path.length),u4(c._dEH,l,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),tA(a,[]),n._needFormattingCleanup&&YY(n)}finally{r.gc&&CY(s,i,r.gcFilter),RY(s,i),n.afterState.forEach((h,d)=>{const p=n.beforeState.get(d)||0;if(p!==h){const m=i.clients.get(d),y=Yc(Ao(m,p),1);for(let S=m.length-1;S>=y;)S-=1+rv(m,S)}});for(let h=o.length-1;h>=0;h--){const{client:d,clock:p}=o[h].id,m=i.clients.get(d),y=Ao(m,p);y+11||y>0&&rv(m,y)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(tY(J3,K3,"[yjs] ",q3,Z3,"Changed the client-id because another client seems to be using it."),r.clientID=n4()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const h=new nm;nI(h,n)&&r.emit("update",[h.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const h=new kc;nI(h,n)&&r.emit("updateV2",[h.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:l,subdocsRemoved:c}=n;(a.size>0||c.size>0||l.size>0)&&(a.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),c.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:l,added:a,removed:c},r,n]),c.forEach(h=>h.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):p4(t,e+1)}}},nn=(t,e,n=null,r=!0)=>{const i=t._transactionCleanups;let s=!1,o=null;t._transaction===null&&(s=!0,t._transaction=new AY(t,n,r),i.push(t._transaction),i.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(s){const a=t._transaction===i[0];t._transaction=null,a&&p4(i,0)}}return o};function*bY(t){const e=bt(t.restDecoder);for(let n=0;nKv(t,i4,nm),IY=(t,e)=>{if(t.constructor===rs){const{client:n,clock:r}=t.id;return new rs(Ot(n,r+e),t.length-e)}else if(t.constructor===is){const{client:n,clock:r}=t.id;return new is(Ot(n,r+e),t.length-e)}else{const n=t,{client:r,clock:i}=n.id;return new qn(Ot(r,i+e),null,Ot(r,i+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Kv=(t,e=Gf,n=kc)=>{if(t.length===1)return t[0];const r=t.map(h=>new e(Kc(h)));let i=r.map(h=>new oA(h,!0)),s=null;const o=new n,a=new aA(o);for(;i=i.filter(p=>p.curr!==null),i.sort((p,m)=>{if(p.curr.id.client===m.curr.id.client){const y=p.curr.id.clock-m.curr.id.clock;return y===0?p.curr.constructor===m.curr.constructor?0:p.curr.constructor===is?1:-1:y}else return m.curr.id.client-p.curr.id.client}),i.length!==0;){const h=i[0],d=h.curr.id.client;if(s!==null){let p=h.curr,m=!1;for(;p!==null&&p.id.clock+p.length<=s.struct.id.clock+s.struct.length&&p.id.client>=s.struct.id.client;)p=h.next(),m=!0;if(p===null||p.id.client!==d||m&&p.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ya(a,s.struct,s.offset),s={struct:p,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===is?s.struct.length-=y:p=IY(p,y)),s.struct.mergeWith(p)||(Ya(a,s.struct,s.offset),s={struct:p,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let p=h.curr;p!==null&&p.id.client===d&&p.id.clock===s.struct.id.clock+s.struct.length&&p.constructor!==is;p=h.next())Ya(a,s.struct,s.offset),s={struct:p,offset:0}}s!==null&&(Ya(a,s.struct,s.offset),s=null),lA(a);const l=r.map(h=>iA(h)),c=sY(l);return uh(o,c),o.toUint8Array()},LY=(t,e,n=Gf,r=kc)=>{const i=l4(e),s=new r,o=new aA(s),a=new n(Kc(t)),l=new oA(a,!1);for(;l.curr;){const h=l.curr,d=h.id.client,p=i.get(d)||0;if(l.curr.constructor===is){l.next();continue}if(h.id.clock+h.length>p)for(Ya(o,h,Yc(p-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===d;)Ya(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===d&&l.curr.id.clock+l.curr.length<=p;)l.next()}lA(o);const c=iA(a);return uh(s,c),s.toUint8Array()},m4=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Os(t.encoder.restEncoder)}),t.encoder.restEncoder=cl(),t.written=0)},Ya=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&m4(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Rt(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},lA=t=>{m4(t);const e=t.encoder.restEncoder;Rt(e,t.clientStructs.length);for(let n=0;n{const i=new n(Kc(t)),s=new oA(i,!1),o=new r,a=new aA(o);for(let c=s.curr;c!==null;c=s.next())Ya(a,e(c),0);lA(a);const l=iA(i);return uh(o,l),o.toUint8Array()},OY=t=>NY(t,U$,Gf,nm),iI="You must not compute changes after the event-handler fired.";class v_{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=kY(this.currentTarget,this.target))}deletes(e){return t4(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _l(iI);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(i=>{if(i!==null){const s=n._map.get(i);let o,a;if(this.adds(s)){let l=s.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(s))if(l!==null&&this.deletes(l))o="delete",a=MS(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",a=MS(l.content.getContent())):(o="add",a=void 0)}else if(this.deletes(s))o="delete",a=MS(s.content.getContent());else return;e.set(i,{action:o,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw _l(iI);const n=this.target,r=Hf(),i=Hf(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const l=()=>{a&&s.push(a)};for(let c=n._start;c!==null;c=c.right)c.deleted?this.deletes(c)&&!this.adds(c)&&((a===null||a.delete===void 0)&&(l(),a={delete:0}),a.delete+=c.length,i.add(c)):this.adds(c)?((a===null||a.insert===void 0)&&(l(),a={insert:[]}),a.insert=a.insert.concat(c.content.getContent()),r.add(c)):((a===null||a.retain===void 0)&&(l(),a={retain:0}),a.retain+=c.length);a!==null&&a.retain===void 0&&l()}this._changes=e}return e}}const kY=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)i.deleted||r++,i=i.right;n.unshift(r)}e=e._item.parent}return n},g4=80;let cA=0;class DY{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=cA++}}const UY=t=>{t.timestamp=cA++},v4=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=cA++},FY=(t,e,n)=>{if(t.length>=g4){const r=t.reduce((i,s)=>i.timestamp{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((s,o)=>ev(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&ev(n.index-i){for(let r=t.length-1;r>=0;r--){const i=t[r];if(n>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){t.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Yc(e,i.index+n))}},__=(t,e,n)=>{const r=t,i=e.changedParentTypes;for(;Ll(i,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;u4(r._eH,n,e)};class Er{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=JP(),this._dEH=JP(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw So()}clone(){throw So()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){QP(this._eH,e)}observeDeep(e){QP(this._dEH,e)}unobserve(e){eI(this._eH,e)}unobserveDeep(e){eI(this._dEH,e)}toJSON(){}}const y4=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const i=[];let s=t._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let a=e;a0;a++)i.push(o[a]),r--;e=0}}s=s.right}return i},_4=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let i=0;i{let n=0,r=t._start;for(;r!==null;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let s=0;s{const n=[];return Lp(t,(r,i)=>{n.push(e(r,i,t))}),n},BY=t=>{let e=t._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),r=0,e=e.right}const i=n[r++];return n.length<=r&&(n=null),{done:!1,value:i}}}},S4=(t,e)=>{const n=y_(t,e);let r=t._start;for(n!==null&&(r=n.p,e-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=n;const s=t.doc,o=s.clientID,a=s.store,l=n===null?e._start:n.right;let c=[];const h=()=>{c.length>0&&(i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new Fc(c)),i.integrate(t,0),c=[])};r.forEach(d=>{if(d===null)c.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new rm(new Uint8Array(d))),i.integrate(t,0);break;case fh:i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new im(d)),i.integrate(t,0);break;default:if(d instanceof Er)i=new qn(Ot(o,hr(a,o)),i,i&&i.lastId,l,l&&l.id,e,null,new _a(d)),i.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},E4=()=>_l("Length exceeded!"),w4=(t,e,n,r)=>{if(n>e._length)throw E4();if(n===0)return e._searchMarker&&Ip(e._searchMarker,n,r.length),qv(t,e,null,r);const i=n,s=y_(e,n);let o=e._start;for(s!==null&&(o=s.p,n-=s.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return qv(t,e,i,n)},M4=(t,e,n,r)=>{if(r===0)return;const i=n,s=r,o=y_(e,n);let a=e._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n0&&a!==null;)a.deleted||(r0)throw E4();e._searchMarker&&Ip(e._searchMarker,i,-s+r)},Zv=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},uA=(t,e,n,r)=>{const i=e._map.get(n)||null,s=t.doc,o=s.clientID;let a;if(r==null)a=new Fc([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:a=new Fc([r]);break;case Uint8Array:a=new rm(r);break;case fh:a=new im(r);break;default:if(r instanceof Er)a=new _a(r);else throw new Error("Unexpected content type")}new qn(Ot(o,hr(s.store,o)),i,i&&i.lastId,null,null,e,n,a).integrate(t,0)},fA=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},T4=t=>{const e={};return t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},A4=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},HY=(t,e)=>{const n={};return t._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&Vu(s,e)&&(n[i]=s.content.getContent()[s.length-1])}),n},w0=t=>rY(t.entries(),e=>!e[1].deleted);class VY extends v_{constructor(e,n){super(e,n),this._transaction=n}}class Ef extends Er{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new Ef;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ef}clone(){const e=new Ef;return e.insert(0,this.toArray().map(n=>n instanceof Er?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),__(this,e,new VY(this,e))}insert(e,n){this.doc!==null?nn(this.doc,r=>{w4(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?nn(this.doc,n=>{zY(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?nn(this.doc,r=>{M4(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return S4(this,e)}toArray(){return _4(this)}slice(e=0,n=this.length){return y4(this,e,n)}toJSON(){return this.map(e=>e instanceof Er?e.toJSON():e)}map(e){return x4(this,e)}forEach(e){Lp(this,e)}[Symbol.iterator](){return BY(this)}_write(e){e.writeTypeRef(hK)}}const GY=t=>new Ef;class WY extends v_{constructor(e,n,r){super(e,n),this.keysChanged=r}}class Wf extends Er{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new Wf}clone(){const e=new Wf;return this.forEach((n,r)=>{e.set(r,n instanceof Er?n.clone():n)}),e}_callObserver(e,n){__(this,e,new WY(this,e,n))}toJSON(){const e={};return this._map.forEach((n,r)=>{if(!n.deleted){const i=n.content.getContent()[n.length-1];e[r]=i instanceof Er?i.toJSON():i}}),e}get size(){return[...w0(this._map)].length}keys(){return CS(w0(this._map),e=>e[0])}values(){return CS(w0(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return CS(w0(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,r)=>{n.deleted||e(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?nn(this.doc,n=>{Zv(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?nn(this.doc,r=>{uA(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return fA(this,e)}has(e){return A4(this,e)}clear(){this.doc!==null?nn(this.doc,e=>{this.forEach(function(n,r,i){Zv(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(dK)}}const XY=t=>new Wf,Za=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&D$(t,e);class Ww{constructor(e,n,r,i){this.left=e,this.right=n,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&To(),this.right.content.constructor){case Qn:this.right.deleted||hh(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const sI=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case Qn:e.right.deleted||hh(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n{const i=new Map,s=r?y_(e,n):null;if(s){const o=new Ww(s.p.left,s.p,s.index,i);return sI(t,o,n-s.index)}else{const o=new Ww(null,e._start,0,i);return sI(t,o,n)}},C4=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Qn&&Za(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const i=t.doc,s=i.clientID;r.forEach((o,a)=>{const l=n.left,c=n.right,h=new qn(Ot(s,hr(i.store,s)),l,l&&l.lastId,c,c&&c.id,e,null,new Qn(a,o));h.integrate(t,0),n.right=h,n.forward()})},hh=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},R4=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===Qn&&Za(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},b4=(t,e,n,r)=>{const i=t.doc,s=i.clientID,o=new Map;for(const a in r){const l=r[a],c=n.currentAttributes.get(a)??null;if(!Za(c,l)){o.set(a,c);const{left:h,right:d}=n;n.right=new qn(Ot(s,hr(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new Qn(a,l)),n.right.integrate(t,0),n.forward()}}return o},bS=(t,e,n,r,i)=>{n.currentAttributes.forEach((p,m)=>{i[m]===void 0&&(i[m]=null)});const s=t.doc,o=s.clientID;R4(n,i);const a=b4(t,e,n,i),l=r.constructor===String?new Co(r):r instanceof Er?new _a(r):new qc(r);let{left:c,right:h,index:d}=n;e._searchMarker&&Ip(e._searchMarker,n.index,l.getLength()),h=new qn(Ot(o,hr(s.store,o)),c,c&&c.lastId,h,h&&h.id,e,null,l),h.integrate(t,0),n.right=h,n.index=d,n.forward(),C4(t,e,n,a)},oI=(t,e,n,r,i)=>{const s=t.doc,o=s.clientID;R4(n,i);const a=b4(t,e,n,i);e:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===Qn));){if(!n.right.deleted)switch(n.right.content.constructor){case Qn:{const{key:l,value:c}=n.right.content,h=i[l];if(h!==void 0){if(Za(h,c))a.delete(l);else{if(r===0)break e;a.set(l,c)}n.right.delete(t)}else n.currentAttributes.set(l,c);break}default:r0){let l="";for(;r>0;r--)l+=` `;n.right=new qn(Ot(o,hr(s.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new Co(l)),n.right.integrate(t,0),n.forward()}C4(t,e,n,a)},P4=(t,e,n,r,i)=>{let s=e;const o=Bs();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===Qn){const c=s.content;o.set(c.key,c)}s=s.right}let a=0,l=!1;for(;e!==s;){if(n===e&&(l=!0),!e.deleted){const c=e.content;switch(c.constructor){case Qn:{const{key:h,value:d}=c,p=r.get(h)??null;(o.get(h)!==c||p===d)&&(e.delete(t),a++,!l&&(i.get(h)??null)===d&&p!==d&&(p===null?i.delete(h):i.set(h,p))),!l&&!e.deleted&&hh(i,c);break}}}e=e.right}return a},jY=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===Qn){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}},$Y=t=>{let e=0;return nn(t.doc,n=>{let r=t._start,i=t._start,s=Bs();const o=Bw(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Qn:hh(o,i.content);break;default:e+=P4(n,r,i,s,o),s=Bw(o),r=i;break}i=i.right}}),e},YY=t=>{const e=new Set,n=t.doc;for(const[r,i]of t.afterState.entries()){const s=t.beforeState.get(r)||0;i!==s&&d4(t,n.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===Qn&&o.constructor!==rs&&e.add(o.parent)})}nn(n,r=>{e4(t,t.deleteSet,i=>{if(i instanceof rs||!i.parent._hasFormatting||e.has(i.parent))return;const s=i.parent;i.content.constructor===Qn?e.add(s):jY(r,i)});for(const i of e)$Y(i)})},aI=(t,e,n)=>{const r=n,i=Bw(e.currentAttributes),s=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case _a:case qc:case Co:n{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,n=[];nn(e,r=>{const i=new Map,s=new Map;let o=this.target._start,a=null;const l={};let c="",h=0,d=0;const p=()=>{if(a!==null){let m=null;switch(a){case"delete":d>0&&(m={delete:d}),d=0;break;case"insert":(typeof c=="object"||c.length>0)&&(m={insert:c},i.size>0&&(m.attributes={},i.forEach((y,S)=>{y!==null&&(m.attributes[S]=y)}))),c="";break;case"retain":h>0&&(m={retain:h},N$(l)||(m.attributes=P$({},l))),h=0;break}m&&n.push(m),a=null}};for(;o!==null;){switch(o.content.constructor){case _a:case qc:this.adds(o)?this.deletes(o)||(p(),a="insert",c=o.content.getContent()[0],p()):this.deletes(o)?(a!=="delete"&&(p(),a="delete"),d+=1):o.deleted||(a!=="retain"&&(p(),a="retain"),h+=1);break;case Co:this.adds(o)?this.deletes(o)||(a!=="insert"&&(p(),a="insert"),c+=o.content.str):this.deletes(o)?(a!=="delete"&&(p(),a="delete"),d+=o.length):o.deleted||(a!=="retain"&&(p(),a="retain"),h+=o.length);break;case Qn:{const{key:m,value:y}=o.content;if(this.adds(o)){if(!this.deletes(o)){const S=i.get(m)??null;Za(S,y)?y!==null&&o.delete(r):(a==="retain"&&p(),Za(y,s.get(m)??null)?delete l[m]:l[m]=y)}}else if(this.deletes(o)){s.set(m,y);const S=i.get(m)??null;Za(S,y)||(a==="retain"&&p(),l[m]=S)}else if(!o.deleted){s.set(m,y);const S=l[m];S!==void 0&&(Za(S,y)?S!==null&&o.delete(r):(a==="retain"&&p(),y===null?delete l[m]:l[m]=y))}o.deleted||(a==="insert"&&p(),hh(i,o.content));break}}o=o.right}for(p();n.length>0;){const m=n[n.length-1];if(m.retain!==void 0&&m.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Dc extends Er{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new Dc}clone(){const e=new Dc;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const r=new KY(this,e,n);__(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===Co&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?nn(this.doc,r=>{const i=new Ww(null,this._start,0,new Map);for(let s=0;s0)&&bS(r,this,i,a,o.attributes||{})}else o.retain!==void 0?oI(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&aI(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,r){const i=[],s=new Map,o=this.doc;let a="",l=this._start;function c(){if(a.length>0){const d={};let p=!1;s.forEach((y,S)=>{p=!0,d[S]=y});const m={insert:a};p&&(m.attributes=d),i.push(m),a=""}}const h=()=>{for(;l!==null;){if(Vu(l,e)||n!==void 0&&Vu(l,n))switch(l.content.constructor){case Co:{const d=s.get("ychange");e!==void 0&&!Vu(l,e)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(c(),s.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!Vu(l,n)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(c(),s.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(c(),s.delete("ychange")),a+=l.content.str;break}case _a:case qc:{c();const d={insert:l.content.getContent()[0]};if(s.size>0){const p={};d.attributes=p,s.forEach((m,y)=>{p[y]=m})}i.push(d);break}case Qn:Vu(l,e)&&(c(),hh(s,l.content));break}l=l.right}c()};return e||n?nn(o,d=>{e&&Vw(d,e),n&&Vw(d,n),h()},"cleanup"):h(),i}insert(e,n,r){if(n.length<=0)return;const i=this.doc;i!==null?nn(i,s=>{const o=M0(s,this,e,!r);r||(r={},o.currentAttributes.forEach((a,l)=>{r[l]=a})),bS(s,this,o,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const i=this.doc;i!==null?nn(i,s=>{const o=M0(s,this,e,!r);bS(s,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(e,n,r||{}))}delete(e,n){if(n===0)return;const r=this.doc;r!==null?nn(r,i=>{aI(i,M0(i,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,r){if(n===0)return;const i=this.doc;i!==null?nn(i,s=>{const o=M0(s,this,e,!1);o.right!==null&&oI(s,this,o,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?nn(this.doc,n=>{Zv(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?nn(this.doc,r=>{uA(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return fA(this,e)}getAttributes(){return T4(this)}_write(e){e.writeTypeRef(pK)}}const qY=t=>new Dc;class PS{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===Xf||n.constructor===Uc)&&n._start!==null)e=n._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Uc extends Er{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Uc}clone(){const e=new Uc;return e.insert(0,this.toArray().map(n=>n instanceof Er?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new PS(this,e)}querySelector(e){e=e.toUpperCase();const r=new PS(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),yl(new PS(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){__(this,e,new QY(this,n,e))}toString(){return x4(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},r){const i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),Lp(this,s=>{i.insertBefore(s.toDOM(e,n,r),null)}),i}insert(e,n){this.doc!==null?nn(this.doc,r=>{w4(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)nn(this.doc,r=>{const i=e&&e instanceof Er?e._item:e;qv(r,this,i,n)});else{const r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw _l("Reference item not found");r.splice(i,0,...n)}}delete(e,n=1){this.doc!==null?nn(this.doc,r=>{M4(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return _4(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return S4(this,e)}slice(e=0,n=this.length){return y4(this,e,n)}forEach(e){Lp(this,e)}_write(e){e.writeTypeRef(gK)}}const ZY=t=>new Uc;class Xf extends Uc{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,n){super._integrate(e,n),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new Xf(this.nodeName)}clone(){const e=new Xf(this.nodeName),n=this.getAttributes();return L$(n,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof Er?r.clone():r)),e}toString(){const e=this.getAttributes(),n=[],r=[];for(const a in e)r.push(a);r.sort();const i=r.length;for(let a=0;a0?" "+n.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?nn(this.doc,n=>{Zv(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?nn(this.doc,r=>{uA(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return fA(this,e)}hasAttribute(e){return A4(this,e)}getAttributes(e){return e?HY(this,e):T4(this)}toDOM(e=document,n={},r){const i=e.createElement(this.nodeName),s=this.getAttributes();for(const o in s){const a=s[o];typeof a=="string"&&i.setAttribute(o,a)}return Lp(this,o=>{i.appendChild(o.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(mK),e.writeKey(this.nodeName)}}const JY=t=>new Xf(t.readKey());class QY extends v_{constructor(e,n,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}}class Jv extends Wf{constructor(e){super(),this.hookName=e}_copy(){return new Jv(this.hookName)}clone(){const e=new Jv(this.hookName);return this.forEach((n,r)=>{e.set(r,n)}),e}toDOM(e=document,n={},r){const i=n[this.hookName];let s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(vK),e.writeKey(this.hookName)}}const eK=t=>new Jv(t.readKey());class Qv extends Dc{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Qv}clone(){const e=new Qv;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,r){const i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{const n=[];for(const i in e.attributes){const s=[];for(const o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,a)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(yK)}}const tK=t=>new Qv;class hA{constructor(e,n){this.id=e,this.length=n}get deleted(){throw So()}mergeWith(e){return!1}write(e,n,r){throw So()}integrate(e,n){throw So()}}const nK=0;class rs extends hA{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),h4(e.doc.store,this)}write(e,n){e.writeInfo(nK),e.writeLen(this.length-n)}getMissing(e,n){return null}}class rm{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new rm(this.content)}splice(e){throw So()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const rK=t=>new rm(t.readBuf());class Np{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Np(this.len)}splice(e){const n=new Np(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Yv(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const iK=t=>new Np(t.readLen()),I4=(t,e)=>new fh({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class im{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new im(I4(this.doc.guid,this.opts))}splice(e){throw So()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const sK=t=>new im(I4(t.readString(),t.readAny()));class qc{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new qc(this.embed)}splice(e){throw So()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const oK=t=>new qc(t.readJSON());class Qn{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Qn(this.key,this.value)}splice(e){throw So()}mergeWith(e){return!1}integrate(e,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const aK=t=>new Qn(t.readKey(),t.readJSON());class ey{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ey(this.arr)}splice(e){const n=new ey(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let i=n;i{const e=t.readLen(),n=[];for(let r=0;r{const e=t.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const uK=t=>new Co(t.readString()),fK=[GY,XY,qY,JY,ZY,eK,tK],hK=0,dK=1,pK=2,mK=3,gK=4,vK=5,yK=6;class _a{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new _a(this.type._copy())}splice(e){throw So()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const _K=t=>new _a(fK[t.readTypeRef()](t)),ty=(t,e,n)=>{const{client:r,clock:i}=e.id,s=new qn(Ot(r,i+n),e,Ot(r,i+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=Ot(e.redone.client,e.redone.clock+n)),e.right=s,s.right!==null&&(s.right.left=s),t._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=n,s};class qn extends hA{constructor(e,n,r,i,s,o,a,l){super(e,l.getLength()),this.origin=r,this.left=n,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=a,this.redone=null,this.content=l,this.info=this.content.isCountable()?zP:0}set marker(e){(this.info&wS)>0!==e&&(this.info^=wS)}get marker(){return(this.info&wS)>0}get keep(){return(this.info&BP)>0}set keep(e){this.keep!==e&&(this.info^=BP)}get countable(){return(this.info&zP)>0}get deleted(){return(this.info&ES)>0}set deleted(e){this.deleted!==e&&(this.info^=ES)}markDeleted(){this.info|=ES}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=hr(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=hr(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Sf&&this.id.client!==this.parent.client&&this.parent.clock>=hr(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=tI(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=xl(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===rs||this.right&&this.right.constructor===rs)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===qn&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===qn&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Sf){const r=RS(n,this.parent);r.constructor===rs?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=tI(e,e.doc.store,Ot(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),E0(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Yv(e.deleteSet,this.id.client,this.id.clock,this.length),rI(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw To();this.content.gc(e),n?TY(e,this,new rs(this.id,this.length)):this.content=new Np(this.length)}write(e,n){const r=n>0?Ot(this.id.client,this.id.clock+n-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&d_|(r===null?0:Oi)|(i===null?0:oa)|(s===null?0:Ap);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){const a=this.parent;if(a._item!==void 0){const l=a._item;if(l===null){const c=wY(a);e.writeParentInfo(!0),e.writeString(c)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===Sf?(e.writeParentInfo(!1),e.writeLeftID(a)):To();s!==null&&e.writeString(s)}this.content.write(e,n)}}const L4=(t,e)=>xK[e&d_](t),xK=[()=>{To()},iK,lK,rK,uK,oK,aK,_K,cK,sK,()=>{To()}],SK=10;class is extends hA{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){To()}write(e,n){e.writeInfo(SK),Rt(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const N4=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},O4="__ $YJS$ __";N4[O4]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");N4[O4]=!0;const dA=0,k4=1,D4=2,EK=(t,e)=>{Rt(t,dA);const n=SY(e);Nr(t,n)},U4=(t,e,n)=>{Rt(t,k4),Nr(t,vY(e,n))},wK=(t,e,n)=>U4(e,n,Wr(t)),F4=(t,e,n)=>{try{pY(e,Wr(t),n)}catch(r){console.error("Caught error while handling a Yjs update",r)}},MK=(t,e)=>{Rt(t,D4),Nr(t,e)},TK=F4,AK=(t,e,n,r)=>{const i=bt(t);switch(i){case dA:wK(t,e,n);break;case k4:F4(t,n,r);break;case D4:TK(t,n,r);break;default:throw new Error("Unknown message type")}return i},uf={},lI={},aa={},lc={},Rs=WT("shared",["second"],t=>{switch(t.target){case"second":Object.keys(aa).forEach(e=>{const n=lc[e];n===void 0?Rs.emit("shared:join",e):n<10?lc[e]=n+1:delete lc[e]}),Object.keys(lI).forEach(e=>{Rs.emit("shared:active",e)});break;case"join":{const e=t.data,n=uf[e];if(n&&lI[e]){Rs.reply(t,"joinack",e);const r=cl();EK(r,n),Rs.reply(t,"sync",iv(e,r));const i=cl();U4(i,n),Rs.reply(t,"sync",iv(e,i))}break}case"joinack":{const e=t.data;uf[e]&&aa[e]&&(lc[e]=0);break}case"active":{const e=t.data;uf[e]&&aa[e]&&(lc[e]=0);break}case"sync":{const[e,n,r]=t.data,i=uf[n];if(i&&e!==Rs.id()){const s=Kc(r),o=cl();if(AK(s,o,i,Rs)===dA){const l=iv(n,o);Rs.emit("shared:sync",l)}}break}}});function CK(t){let e=uf[t];if(e)return e;uf[t]=e=new fh({guid:t});function n(r){const i=cl();MK(i,r),Rs.emit("shared:sync",iv(t,i))}return e.on("update",n),e.on("destroy",()=>{e==null||e.off("update",n)}),e}function pA(t){return CK(t).getMap()}function iv(t,e){const n=Os(e);return[Rs.id()??"",t,n]}function B4(t,e){const n=t.get(e);return n!=null&&n.toJSON?n.toJSON():n}function RK(t,e,n){typeof n=="string"?t.set(e,new Dc(n)):t.set(e,n)}function z4(t){aa[t]=(aa[t]??0)+1,aa[t]===1&&(delete lc[t],Rs.emit("shared:join",t))}function H4(t){const e=aa[t]??0;e<=1?(delete aa[t],delete lc[t]):aa[t]=e-1}function bK(t,e,n){const r=pA(t),i=B4(r,e);(i===void 0||n!==i)&&RK(r,e,n)}function PK(t,e,n){const r=pA(t);function i(){n(B4(r,e))}function s(o){o.keysChanged.has(e)&&i()}return i(),r.observe(s),()=>{r.unobserve(s)}}function IK(t,e,n){const r=pA(t);let i=r.get(e);function s(){n(i)}function o(l){l.keysChanged.has(e)&&i===void 0&&a(),i&&r.unobserve(o)}function a(){i=r.get(e),i?(i.observeDeep(s),s()):r.observe(o)}return a(),()=>{i?i.unobserveDeep(s):r.unobserve(o)}}function LK(t,e,n){z4(t);const r=PK(t,e,n);return()=>{r(),H4(t)}}function NK(t,e,n){z4(t);const r=IK(t,e,n);return()=>{r(),H4(t)}}const V4=new gj,OK=mj(t=>V4.postMessage(t));V4.addEventListener("message",t=>{OK(t.data)});/** * postprocessing v6.35.3 build Sat Mar 30 2024 diff --git a/assets/instance-DIq2GfeP.js b/assets/instance-DIq2GfeP.js new file mode 100644 index 000000000..029c0a367 --- /dev/null +++ b/assets/instance-DIq2GfeP.js @@ -0,0 +1,290 @@ +var nL=Object.defineProperty;var rL=(xe,Dt,_n)=>Dt in xe?nL(xe,Dt,{enumerable:!0,configurable:!0,writable:!0,value:_n}):xe[Dt]=_n;var U=(xe,Dt,_n)=>(rL(xe,typeof Dt!="symbol"?Dt+"":Dt,_n),_n);(function(){"use strict";const xe=new Set,Dt={emit(e,t,n,r){Dt.invoke(ug(e,t,n,r))},invoke(e){xe.forEach(t=>t.handle(e))},connect(e){xe.add(e)},disconnect(e){xe.delete(e)}},_n="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ag=e=>crypto.getRandomValues(new Uint8Array(e)),cg=(e,t,n)=>{let r=(2<{let o="";for(;;){let a=n(s),c=s;for(;c--;)if(o+=e[a[c]&r]||"",o.length===i)return o}}},Pc=(e,t=21)=>cg(e,t,ag),lg=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=_n[n[e]&63];return t};function Ue(){return lg()}function ug(e,t,n,r){return{id:Ue(),target:e,sender:t,data:n,player:r}}function Dc(e){const[t,...n]=e.split(":");return{target:t,path:n.join(":")}}function Rr(e,t,n){const r=Ue(),s=e.toLowerCase(),i=t.map(a=>a.toLowerCase()),o={id(){return r},name(){return e},tags(){return t},emit(a,c,l){Dt.emit(a,r,c,l)},reply(a,c,l,u){o.emit(`${a.sender}:${c}`,l,u)},handle(a){const{target:c,path:l}=Dc(a.target),u=c.toLowerCase();i.findIndex(h=>h==="all"||h===u)!==-1&&n(a),(r===c||u==="all"||s===u)&&n({...a,target:l})}};return Dt.connect(o),o}function hg(e){const t=new Set;function n(r){t.has(r.id)||(t.add(r.id),Dt.invoke(r))}return Rr("forward",["all"],r=>{t.has(r.id)||(t.add(r.id),e(r))}),n}var ws=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ro(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function fg(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}),n}var Fc="abcdefghijklmnopqrstuvwxyz",$c="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Bc="0123456789",dg="346789ABCDEFGHJKLMNPQRTUVWXYabcdefghijkmnpqrtwxyz",pg="6789BCDFGHJKLMNPQRTWbcdfghjkmnpqrtwz";const gg=Bc,mg=Fc,Eg=$c;var _g=gg+mg+Eg,so={lowercase:Fc,uppercase:$c,numbers:Bc,nolookalikes:dg,nolookalikesSafe:pg,alphanumeric:_g};const Gc=32,yg=33;function Rs(e,t){return new Array(e).fill(t)}function Tg(e,t,n,r,s=0){const i=n*r;return{id:`tiles:${e}:${t}`,type:1,width:n,height:r,char:Rs(i,0),color:Rs(i,0),bg:Rs(i,s)}}function Sg(e,t,n,r=1,s=15){return{id:`sprites:${e}:${t}:${n}`,x:0,y:0,char:r,color:s,bg:Gc}}function Ag(e,t){return{id:`sprites:${e}:${t}`,type:2,sprites:[]}}function wg(e,t,n,r,s=0){const i=n*r;return{id:`dither:${e}:${t}`,type:3,width:n,height:r,alphas:Rs(i,s)}}function Rg(e,t){return{id:`control:${e}:${t}`,type:5,focusx:0,focusy:0,focusid:e,viewscale:2}}var Yt=(e=>(e[e.START=0]="START",e[e.LEFT=1]="LEFT",e[e.RIGHT=2]="RIGHT",e[e.TOP=3]="TOP",e[e.BOTTOM=4]="BOTTOM",e[e.SCROLL=5]="SCROLL",e))(Yt||{});const vg={start:0,left:1,right:2,top:3,bottom:4,scroll:5},Ng={0:1,1:20,2:20,3:1,4:1,5:40},Cg=1,Ig=16,Lg=256;var ct=(e=>(e[e.NONE=0]="NONE",e[e.MOVE_UP=1]="MOVE_UP",e[e.MOVE_DOWN=2]="MOVE_DOWN",e[e.MOVE_LEFT=3]="MOVE_LEFT",e[e.MOVE_RIGHT=4]="MOVE_RIGHT",e[e.OK_BUTTON=5]="OK_BUTTON",e[e.CANCEL_BUTTON=6]="CANCEL_BUTTON",e[e.MENU_BUTTON=7]="MENU_BUTTON",e))(ct||{}),Kc={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(ws,function(){return n.importState=function(s){var i=new n;return i.importState(s),i},n;function n(){return function(s){var i=0,o=0,a=0,c=1;s.length==0&&(s=[+new Date]);var l=r();i=l(" "),o=l(" "),a=l(" ");for(var u=0;u>>0,c-=s,c*=s,s=c>>>0,c-=s,s+=c*4294967296}return(s>>>0)*23283064365386963e-26};return i.version="Mash 0.9",i}})})(Kc);var Og=Kc.exports,kg=ro(Og);const bg=kg("089fad0j9awfem09wavefc09uwaef");function io(e,t,n){return Math.max(t,Math.min(n,e))}function Mg(){return bg()}function Wn(e,t){const n=Math.min(e,t),s=Math.max(e,t)-n+1;return n+Math.floor(Mg()*s)}/*! + * https://github.com/Starcounter-Jack/JSON-Patch + * (c) 2017-2022 Joachim Wester + * MIT licensed + */var xg=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var i in s)s.hasOwnProperty(i)&&(r[i]=s[i])},e(t,n)};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ug=Object.prototype.hasOwnProperty;function oo(e,t){return Ug.call(e,t)}function ao(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=48&&r<=57){t++;continue}return!1}return!0}function yn(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function Wc(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function lo(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,n=e.length;t0&&c[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&d===void 0&&(l[f]===void 0?d=c.slice(0,u).join("/"):u==h-1&&(d=t.path),d!==void 0&&p(t,0,e,d)),u++,Array.isArray(l)){if(f==="-")f=l.length;else{if(n&&!co(f))throw new et("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,t,e);co(f)&&(f=~~f)}if(u>=h){if(n&&t.op==="add"&&f>l.length)throw new et("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,t,e);var o=Dg[t.op].call(t,l,f,e);if(o.test===!1)throw new et("Test operation failed","TEST_OPERATION_FAILED",i,t,e);return o}}else if(u>=h){var o=jn[t.op].call(t,l,f,e);if(o.test===!1)throw new et("Test operation failed","TEST_OPERATION_FAILED",i,t,e);return o}if(l=l[f],n&&u0)throw new et('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,n);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new et("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new et("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&lo(e.value))throw new et("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,n);if(n){if(e.op=="add"){var s=e.path.split("/").length,i=r.split("/").length;if(s!==i+1&&s!==i)throw new et("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,n)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==r)throw new et("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,n)}else if(e.op==="move"||e.op==="copy"){var o={op:"_get",path:e.from,value:void 0},a=Vc([o],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new et("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,n)}}}else throw new et("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,n)}function Vc(e,t,n){try{if(!Array.isArray(e))throw new et("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)uo(It(t),It(e),n||!0);else{n=n||Ns;for(var r=0;r0&&(e.patches=[],e.callback&&e.callback(r)),r}function po(e,t,n,r,s){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var i=ao(t),o=ao(e),a=!1,c=o.length-1;c>=0;c--){var l=o[c],u=e[l];if(oo(t,l)&&!(t[l]===void 0&&u!==void 0&&Array.isArray(t)===!1)){var h=t[l];typeof u=="object"&&u!=null&&typeof h=="object"&&h!=null&&Array.isArray(u)===Array.isArray(h)?po(u,h,n,r+"/"+yn(l),s):u!==h&&(s&&n.push({op:"test",path:r+"/"+yn(l),value:It(u)}),n.push({op:"replace",path:r+"/"+yn(l),value:It(h)}))}else Array.isArray(e)===Array.isArray(t)?(s&&n.push({op:"test",path:r+"/"+yn(l),value:It(u)}),n.push({op:"remove",path:r+"/"+yn(l)}),a=!0):(s&&n.push({op:"test",path:r,value:e}),n.push({op:"replace",path:r,value:t}))}if(!(!a&&i.length==o.length))for(var c=0;ctypeof i=="string"?e==null?void 0:e.objects[i]:e==null?void 0:e.terrain[i]).filter(_)}function tm(e,t){const n=ka(t),r=Sf(t),s=Af(t);return e.filter(i=>!(_(n)&&rm(i)!==n||_(r)&&sm(i)!==r||_(s)&&im(i)!==s)).filter(_)}function _o(e,t){return _(e)?t.map(n=>{var r;if(typeof n=="string"){const s=e.objects[n];if(_(s))return s;const i=Eo(e,n.toLowerCase());if(i.length)return i}else if(sn(n)&&n.x>=0&&n.x=0&&n.y=e.width||t.y<0||t.y>=e.height))return e.terrain[t.x+t.y*e.width]=t,t}function To(e,t){if(!_(e)||!_(t))return;const n={...t,id:t.id??Ue()};return e.objects[n.id]=n,n}function am(e,t,n,r){return om(e,{x:t,y:n,kind:r})}function cm(e,t,n,r){return To(e,{x:t,y:n,kind:r})}function Xc(e,t){if(e)return e.objects[t]}function Fe(e,t){switch(t){case B.NORTH:--e.y;break;case B.SOUTH:++e.y;break;case B.WEST:--e.x;break;case B.EAST:++e.x;break}return e}function Hn(e,t,n){const r=(t==null?void 0:t.x)??0,s=(t==null?void 0:t.y)??0,i={x:r,y:s},o={...i},a=rr({x:(t==null?void 0:t.lx)??i.x,y:(t==null?void 0:t.ly)??i.y},i);for(let c=0;c0){if(++t>=Xm)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function tE(e){return function(){return e}}var Is=function(){try{var e=An(Object,"defineProperty");return e({},"",{}),e}catch{}}(),eE=Is?function(e,t){return Is(e,"toString",{configurable:!0,enumerable:!1,value:tE(t),writable:!0})}:Vn,nE=eE,rE=Zm(nE);function al(e,t){for(var n=-1,r=e==null?0:e.length;++n-1}var oE=9007199254740991,aE=/^(?:0|[1-9]\d*)$/;function Ls(e,t){var n=typeof e;return t=t??oE,!!t&&(n=="number"||n!="symbol"&&aE.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=hE}function me(e){return e!=null&&Oo(e.length)&&!$e(e)}function ks(e,t,n){if(!qt(n))return!1;var r=typeof t;return(r=="number"?me(n)&&Ls(t,n.length):r=="string"&&t in n)?Lr(n[t],e):!1}function fE(e){return Lo(function(t,n){var r=-1,s=n.length,i=s>1?n[s-1]:void 0,o=s>2?n[2]:void 0;for(i=e.length>3&&typeof i=="function"?(s--,i):void 0,o&&ks(n[0],n[1],o)&&(i=s<3?void 0:i,s=1),t=Object(t);++r-1}function N_(e,t){var n=this.__data__,r=xs(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Be(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t0&&n(a)?t>1?Ds(a,t-1,n,r,s):Po(s,a):r||(s[s.length]=a)}return s}function ie(e){var t=e==null?0:e.length;return t?Ds(e,1):[]}var W_=yl(Object.getPrototypeOf,Object),Al=W_;function wl(e,t,n){var r=-1,s=e.length;t<0&&(t=-t>s?0:s+t),n=n>s?s:n,n<0&&(n+=s),s=t>n?0:n-t>>>0,t>>>=0;for(var i=Array(s);++ra))return!1;var l=i.get(e),u=i.get(t);if(l&&u)return l==t&&u==e;var h=-1,d=!0,f=n&RT?new qn:void 0;for(i.set(e,t),i.set(t,e);++h2?t[2]:void 0;for(s&&ks(t[0],t[1],s)&&(r=1);++n=mS&&(i=Wo,o=!1,t=new qn(t));t:for(;++s-1?s[i?t[o]:o]:void 0}}var AS=Math.max;function wS(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var s=n==null?0:Ir(n);return s<0&&(s=AS(r+s,0)),cl(e,_e(t),s)}var Jn=SS(wS);function ae(e){return e&&e.length?e[0]:void 0}function RS(e,t){var n=-1,r=me(e)?Array(e.length):[];return vn(e,function(s,i,o){r[++n]=t(s,i,o)}),r}function L(e,t){var n=W(e)?Cr:RS;return n(e,_e(t))}function Jt(e,t){return Ds(L(e,t),1)}var vS=Object.prototype,NS=vS.hasOwnProperty,CS=pS(function(e,t,n){NS.call(e,n)?e[n].push(t):Io(e,n,[t])}),IS=Object.prototype,LS=IS.hasOwnProperty;function OS(e,t){return e!=null&&LS.call(e,t)}function k(e,t){return e!=null&&Zl(e,t,OS)}var kS="[object String]";function Mt(e){return typeof e=="string"||!W(e)&&se(e)&&tn(e)==kS}function bS(e,t){return Cr(t,function(n){return e[n]})}function ht(e){return e==null?[]:bS(e,$t(e))}var MS=Math.max;function Lt(e,t,n,r){e=me(e)?e:ht(e),n=n&&!r?Ir(n):0;var s=e.length;return n<0&&(n=MS(s+n,0)),Mt(e)?n<=s&&e.indexOf(t,n)>-1:!!s&&Co(e,t,n)>-1}var xS=Math.max;function su(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var s=n==null?0:Ir(n);return s<0&&(s=xS(r+s,0)),Co(e,t,s)}var US="[object Map]",PS="[object Set]",DS=Object.prototype,FS=DS.hasOwnProperty;function z(e){if(e==null)return!0;if(me(e)&&(W(e)||typeof e=="string"||typeof e.splice=="function"||br(e)||bo(e)||bs(e)))return!e.length;var t=zn(e);if(t==US||t==PS)return!e.size;if(kr(e))return!Tl(e).length;for(var n in e)if(FS.call(e,n))return!1;return!0}var $S="[object RegExp]";function BS(e){return se(e)&&tn(e)==$S}var iu=en&&en.isRegExp,Ke=iu?Mr(iu):BS;function We(e){return e===void 0}var GS="Expected a function";function KS(e){if(typeof e!="function")throw new TypeError(GS);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}function WS(e,t,n,r){if(!qt(e))return e;t=Ps(t,e);for(var s=-1,i=t.length,o=i-1,a=e;a!=null&&++s=qS){var l=t?null:zS(e);if(l)return jo(l);o=!1,s=Wo,c=new qn}else c=t?[]:a;t:for(;++r{n.accept(t)})}}class Kt extends ye{constructor(t){super([]),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}set definition(t){}get definition(){return this.referencedRule!==void 0?this.referencedRule.definition:[]}accept(t){t.visit(this)}}class Qn extends ye{constructor(t){super(t.definition),this.orgText="",Bt(this,ce(t,n=>n!==void 0))}}class xt extends ye{constructor(t){super(t.definition),this.ignoreAmbiguities=!1,Bt(this,ce(t,n=>n!==void 0))}}class Ut extends ye{constructor(t){super(t.definition),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}}class Te extends ye{constructor(t){super(t.definition),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}}class Se extends ye{constructor(t){super(t.definition),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}}class ft extends ye{constructor(t){super(t.definition),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}}class le extends ye{constructor(t){super(t.definition),this.idx=1,Bt(this,ce(t,n=>n!==void 0))}}class ue extends ye{get definition(){return this._definition}set definition(t){this._definition=t}constructor(t){super(t.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Bt(this,ce(t,n=>n!==void 0))}}class Z{constructor(t){this.idx=1,Bt(this,ce(t,n=>n!==void 0))}accept(t){t.visit(this)}}function ZS(e){return L(e,Ws)}function Ws(e){function t(n){return L(n,Ws)}if(e instanceof Kt){const n={type:"NonTerminal",name:e.nonTerminalName,idx:e.idx};return Mt(e.label)&&(n.label=e.label),n}else{if(e instanceof xt)return{type:"Alternative",definition:t(e.definition)};if(e instanceof Ut)return{type:"Option",idx:e.idx,definition:t(e.definition)};if(e instanceof Te)return{type:"RepetitionMandatory",idx:e.idx,definition:t(e.definition)};if(e instanceof Se)return{type:"RepetitionMandatoryWithSeparator",idx:e.idx,separator:Ws(new Z({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof le)return{type:"RepetitionWithSeparator",idx:e.idx,separator:Ws(new Z({terminalType:e.separator})),definition:t(e.definition)};if(e instanceof ft)return{type:"Repetition",idx:e.idx,definition:t(e.definition)};if(e instanceof ue)return{type:"Alternation",idx:e.idx,definition:t(e.definition)};if(e instanceof Z){const n={type:"Terminal",name:e.terminalType.name,label:JS(e.terminalType),idx:e.idx};Mt(e.label)&&(n.terminalLabel=e.label);const r=e.terminalType.PATTERN;return e.terminalType.PATTERN&&(n.pattern=Ke(r)?r.source:r),n}else{if(e instanceof Qn)return{type:"Rule",name:e.name,orgText:e.orgText,definition:t(e.definition)};throw Error("non exhaustive match")}}}class Zn{visit(t){const n=t;switch(n.constructor){case Kt:return this.visitNonTerminal(n);case xt:return this.visitAlternative(n);case Ut:return this.visitOption(n);case Te:return this.visitRepetitionMandatory(n);case Se:return this.visitRepetitionMandatoryWithSeparator(n);case le:return this.visitRepetitionWithSeparator(n);case ft:return this.visitRepetition(n);case ue:return this.visitAlternation(n);case Z:return this.visitTerminal(n);case Qn:return this.visitRule(n);default:throw Error("non exhaustive match")}}visitNonTerminal(t){}visitAlternative(t){}visitOption(t){}visitRepetition(t){}visitRepetitionMandatory(t){}visitRepetitionMandatoryWithSeparator(t){}visitRepetitionWithSeparator(t){}visitAlternation(t){}visitTerminal(t){}visitRule(t){}}function tA(e){return e instanceof xt||e instanceof Ut||e instanceof ft||e instanceof Te||e instanceof Se||e instanceof le||e instanceof Z||e instanceof Qn}function js(e,t=[]){return e instanceof Ut||e instanceof ft||e instanceof le?!0:e instanceof ue?ou(e.definition,r=>js(r,t)):e instanceof Kt&&Lt(t,e)?!1:e instanceof ye?(e instanceof Kt&&t.push(e),oe(e.definition,r=>js(r,t))):!1}function eA(e){return e instanceof ue}function Ae(e){if(e instanceof Kt)return"SUBRULE";if(e instanceof Ut)return"OPTION";if(e instanceof ue)return"OR";if(e instanceof Te)return"AT_LEAST_ONE";if(e instanceof Se)return"AT_LEAST_ONE_SEP";if(e instanceof le)return"MANY_SEP";if(e instanceof ft)return"MANY";if(e instanceof Z)return"CONSUME";throw Error("non exhaustive match")}class Hs{walk(t,n=[]){b(t.definition,(r,s)=>{const i=At(t.definition,s+1);if(r instanceof Kt)this.walkProdRef(r,i,n);else if(r instanceof Z)this.walkTerminal(r,i,n);else if(r instanceof xt)this.walkFlat(r,i,n);else if(r instanceof Ut)this.walkOption(r,i,n);else if(r instanceof Te)this.walkAtLeastOne(r,i,n);else if(r instanceof Se)this.walkAtLeastOneSep(r,i,n);else if(r instanceof le)this.walkManySep(r,i,n);else if(r instanceof ft)this.walkMany(r,i,n);else if(r instanceof ue)this.walkOr(r,i,n);else throw Error("non exhaustive match")})}walkTerminal(t,n,r){}walkProdRef(t,n,r){}walkFlat(t,n,r){const s=n.concat(r);this.walk(t,s)}walkOption(t,n,r){const s=n.concat(r);this.walk(t,s)}walkAtLeastOne(t,n,r){const s=[new Ut({definition:t.definition})].concat(n,r);this.walk(t,s)}walkAtLeastOneSep(t,n,r){const s=uu(t,n,r);this.walk(t,s)}walkMany(t,n,r){const s=[new Ut({definition:t.definition})].concat(n,r);this.walk(t,s)}walkManySep(t,n,r){const s=uu(t,n,r);this.walk(t,s)}walkOr(t,n,r){const s=n.concat(r);b(t.definition,i=>{const o=new xt({definition:[i]});this.walk(o,s)})}}function uu(e,t,n){return[new Ut({definition:[new Z({terminalType:e.separator})].concat(e.definition)})].concat(t,n)}function Br(e){if(e instanceof Kt)return Br(e.referencedRule);if(e instanceof Z)return sA(e);if(tA(e))return nA(e);if(eA(e))return rA(e);throw Error("non exhaustive match")}function nA(e){let t=[];const n=e.definition;let r=0,s=n.length>r,i,o=!0;for(;s&&o;)i=n[r],o=js(i),t=t.concat(Br(i)),r=r+1,s=n.length>r;return zo(t)}function rA(e){const t=L(e.definition,n=>Br(n));return zo(ie(t))}function sA(e){return[e.terminalType]}const hu="_~IN~_";class iA extends Hs{constructor(t){super(),this.topProd=t,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(t,n,r){}walkProdRef(t,n,r){const s=aA(t.referencedRule,t.idx)+this.topProd.name,i=n.concat(r),o=new xt({definition:i}),a=Br(o);this.follows[s]=a}}function oA(e){const t={};return b(e,n=>{const r=new iA(n).startWalking();Bt(t,r)}),t}function aA(e,t){return e.name+t+hu}function M(e){return e.charCodeAt(0)}function Xo(e,t){Array.isArray(e)?e.forEach(function(n){t.push(n)}):t.push(e)}function Gr(e,t){if(e[t]===!0)throw"duplicate flag "+t;e[t],e[t]=!0}function tr(e){if(e===void 0)throw Error("Internal Error - Should never get here!");return!0}function cA(){throw Error("Internal Error - Should never get here!")}function fu(e){return e.type==="Character"}const Vs=[];for(let e=M("0");e<=M("9");e++)Vs.push(e);const Ys=[M("_")].concat(Vs);for(let e=M("a");e<=M("z");e++)Ys.push(e);for(let e=M("A");e<=M("Z");e++)Ys.push(e);const du=[M(" "),M("\f"),M(` +`),M("\r"),M(" "),M("\v"),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M("\u2028"),M("\u2029"),M(" "),M(" "),M(" "),M("\uFEFF")],lA=/[0-9a-fA-F]/,zs=/[0-9]/,uA=/[1-9]/;class hA{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(t){this.idx=t.idx,this.input=t.input,this.groupIdx=t.groupIdx}pattern(t){this.idx=0,this.input=t,this.groupIdx=0,this.consumeChar("/");const n=this.disjunction();this.consumeChar("/");const r={type:"Flags",loc:{begin:this.idx,end:t.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case"g":Gr(r,"global");break;case"i":Gr(r,"ignoreCase");break;case"m":Gr(r,"multiLine");break;case"u":Gr(r,"unicode");break;case"y":Gr(r,"sticky");break}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:r,value:n,loc:this.loc(0)}}disjunction(){const t=[],n=this.idx;for(t.push(this.alternative());this.peekChar()==="|";)this.consumeChar("|"),t.push(this.alternative());return{type:"Disjunction",value:t,loc:this.loc(n)}}alternative(){const t=[],n=this.idx;for(;this.isTerm();)t.push(this.term());return{type:"Alternative",value:t,loc:this.loc(n)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){const t=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(t)};case"$":return{type:"EndAnchor",loc:this.loc(t)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(t)};case"B":return{type:"NonWordBoundary",loc:this.loc(t)}}throw Error("Invalid Assertion Escape");case"(":this.consumeChar("?");let n;switch(this.popChar()){case"=":n="Lookahead";break;case"!":n="NegativeLookahead";break}tr(n);const r=this.disjunction();return this.consumeChar(")"),{type:n,value:r,loc:this.loc(t)}}return cA()}quantifier(t=!1){let n;const r=this.idx;switch(this.popChar()){case"*":n={atLeast:0,atMost:1/0};break;case"+":n={atLeast:1,atMost:1/0};break;case"?":n={atLeast:0,atMost:1};break;case"{":const s=this.integerIncludingZero();switch(this.popChar()){case"}":n={atLeast:s,atMost:s};break;case",":let i;this.isDigit()?(i=this.integerIncludingZero(),n={atLeast:s,atMost:i}):n={atLeast:s,atMost:1/0},this.consumeChar("}");break}if(t===!0&&n===void 0)return;tr(n);break}if(!(t===!0&&n===void 0)&&tr(n))return this.peekChar(0)==="?"?(this.consumeChar("?"),n.greedy=!1):n.greedy=!0,n.type="Quantifier",n.loc=this.loc(r),n}atom(){let t;const n=this.idx;switch(this.peekChar()){case".":t=this.dotAll();break;case"\\":t=this.atomEscape();break;case"[":t=this.characterClass();break;case"(":t=this.group();break}if(t===void 0&&this.isPatternCharacter()&&(t=this.patternCharacter()),tr(t))return t.loc=this.loc(n),this.isQuantifier()&&(t.quantifier=this.quantifier()),t}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[M(` +`),M("\r"),M("\u2028"),M("\u2029")]}}atomEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:"GroupBackReference",value:this.positiveInteger()}}characterClassEscape(){let t,n=!1;switch(this.popChar()){case"d":t=Vs;break;case"D":t=Vs,n=!0;break;case"s":t=du;break;case"S":t=du,n=!0;break;case"w":t=Ys;break;case"W":t=Ys,n=!0;break}if(tr(t))return{type:"Set",value:t,complement:n}}controlEscapeAtom(){let t;switch(this.popChar()){case"f":t=M("\f");break;case"n":t=M(` +`);break;case"r":t=M("\r");break;case"t":t=M(" ");break;case"v":t=M("\v");break}if(tr(t))return{type:"Character",value:t}}controlLetterEscapeAtom(){this.consumeChar("c");const t=this.popChar();if(/[a-zA-Z]/.test(t)===!1)throw Error("Invalid ");return{type:"Character",value:t.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:M("\0")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){const t=this.popChar();return{type:"Character",value:M(t)}}classPatternCharacterAtom(){switch(this.peekChar()){case` +`:case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:const t=this.popChar();return{type:"Character",value:M(t)}}}characterClass(){const t=[];let n=!1;for(this.consumeChar("["),this.peekChar(0)==="^"&&(this.consumeChar("^"),n=!0);this.isClassAtom();){const r=this.classAtom();if(r.type,fu(r)&&this.isRangeDash()){this.consumeChar("-");const s=this.classAtom();if(s.type,fu(s)){if(s.value=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(t){return{begin:t,end:this.idx}}}class Jo{visitChildren(t){for(const n in t){const r=t[n];t.hasOwnProperty(n)&&(r.type!==void 0?this.visit(r):Array.isArray(r)&&r.forEach(s=>{this.visit(s)},this))}}visit(t){switch(t.type){case"Pattern":this.visitPattern(t);break;case"Flags":this.visitFlags(t);break;case"Disjunction":this.visitDisjunction(t);break;case"Alternative":this.visitAlternative(t);break;case"StartAnchor":this.visitStartAnchor(t);break;case"EndAnchor":this.visitEndAnchor(t);break;case"WordBoundary":this.visitWordBoundary(t);break;case"NonWordBoundary":this.visitNonWordBoundary(t);break;case"Lookahead":this.visitLookahead(t);break;case"NegativeLookahead":this.visitNegativeLookahead(t);break;case"Character":this.visitCharacter(t);break;case"Set":this.visitSet(t);break;case"Group":this.visitGroup(t);break;case"GroupBackReference":this.visitGroupBackReference(t);break;case"Quantifier":this.visitQuantifier(t);break}this.visitChildren(t)}visitPattern(t){}visitFlags(t){}visitDisjunction(t){}visitAlternative(t){}visitStartAnchor(t){}visitEndAnchor(t){}visitWordBoundary(t){}visitNonWordBoundary(t){}visitLookahead(t){}visitNegativeLookahead(t){}visitCharacter(t){}visitSet(t){}visitGroup(t){}visitGroupBackReference(t){}visitQuantifier(t){}}let qs={};const fA=new hA;function Xs(e){const t=e.toString();if(qs.hasOwnProperty(t))return qs[t];{const n=fA.pattern(t);return qs[t]=n,n}}function dA(){qs={}}const pu="Complement Sets are not supported for first char optimization",Js=`Unable to use "first char" lexer optimizations: +`;function pA(e,t=!1){try{const n=Xs(e);return Qo(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===pu)t&&au(`${Js} Unable to optimize: < ${e.toString()} > + Complement Sets cannot be automatically optimized. + This will disable the lexer's first char optimizations. + See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let r="";t&&(r=` + This will disable the lexer's first char optimizations. + See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),qo(`${Js} + Failed parsing: < ${e.toString()} > + Using the @chevrotain/regexp-to-ast library + Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+r)}}return[]}function Qo(e,t,n){switch(e.type){case"Disjunction":for(let s=0;s{if(typeof c=="number")Qs(c,t,n);else{const l=c;if(n===!0)for(let u=l.from;u<=l.to;u++)Qs(u,t,n);else{for(let u=l.from;u<=l.to&&u=Wr){const u=l.from>=Wr?l.from:Wr,h=l.to,d=nn(u),f=nn(h);for(let p=d;p<=f;p++)t[p]=p}}}});break;case"Group":Qo(o.value,t,n);break;default:throw Error("Non Exhaustive Match")}const a=o.quantifier!==void 0&&o.quantifier.atLeast===0;if(o.type==="Group"&&Zo(o)===!1||o.type!=="Group"&&a===!1)break}break;default:throw Error("non exhaustive match!")}return ht(t)}function Qs(e,t,n){const r=nn(e);t[r]=r,n===!0&&gA(e,t)}function gA(e,t){const n=String.fromCharCode(e),r=n.toUpperCase();if(r!==n){const s=nn(r.charCodeAt(0));t[s]=s}else{const s=n.toLowerCase();if(s!==n){const i=nn(s.charCodeAt(0));t[i]=i}}}function gu(e,t){return Jn(e.value,n=>{if(typeof n=="number")return Lt(t,n);{const r=n;return Jn(t,s=>r.from<=s&&s<=r.to)!==void 0}})}function Zo(e){const t=e.quantifier;return t&&t.atLeast===0?!0:e.value?W(e.value)?oe(e.value,Zo):Zo(e.value):!1}class mA extends Jo{constructor(t){super(),this.targetCharCodes=t,this.found=!1}visitChildren(t){if(this.found!==!0){switch(t.type){case"Lookahead":this.visitLookahead(t);return;case"NegativeLookahead":this.visitNegativeLookahead(t);return}super.visitChildren(t)}}visitCharacter(t){Lt(this.targetCharCodes,t.value)&&(this.found=!0)}visitSet(t){t.complement?gu(t,this.targetCharCodes)===void 0&&(this.found=!0):gu(t,this.targetCharCodes)!==void 0&&(this.found=!0)}}function ta(e,t){if(t instanceof RegExp){const n=Xs(t),r=new mA(e);return r.visit(n),r.found}else return Jn(t,n=>Lt(e,n.charCodeAt(0)))!==void 0}const Nn="PATTERN",Kr="defaultMode",Zs="modes";let mu=typeof new RegExp("(?:)").sticky=="boolean";function EA(e,t){t=Yo(t,{useSticky:mu,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",` +`],tracer:(R,y)=>y()});const n=t.tracer;n("initCharCodeToOptimizedIndexMap",()=>{BA()});let r;n("Reject Lexer.NA",()=>{r=Ks(e,R=>R[Nn]===gt.NA)});let s=!1,i;n("Transform Patterns",()=>{s=!1,i=L(r,R=>{const y=R[Nn];if(Ke(y)){const N=y.source;return N.length===1&&N!=="^"&&N!=="$"&&N!=="."&&!y.ignoreCase?N:N.length===2&&N[0]==="\\"&&!Lt(["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"],N[1])?N[1]:t.useSticky?_u(y):Eu(y)}else{if($e(y))return s=!0,{exec:y};if(typeof y=="object")return s=!0,y;if(typeof y=="string"){if(y.length===1)return y;{const N=y.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),T=new RegExp(N);return t.useSticky?_u(T):Eu(T)}}else throw Error("non exhaustive match")}})});let o,a,c,l,u;n("misc mapping",()=>{o=L(r,R=>R.tokenTypeIdx),a=L(r,R=>{const y=R.GROUP;if(y!==gt.SKIPPED){if(Mt(y))return y;if(We(y))return!1;throw Error("non exhaustive match")}}),c=L(r,R=>{const y=R.LONGER_ALT;if(y)return W(y)?L(y,T=>su(r,T)):[su(r,y)]}),l=L(r,R=>R.PUSH_MODE),u=L(r,R=>k(R,"POP_MODE"))});let h;n("Line Terminator Handling",()=>{const R=Su(t.lineTerminatorCharacters);h=L(r,y=>!1),t.positionTracking!=="onlyOffset"&&(h=L(r,y=>k(y,"LINE_BREAKS")?!!y.LINE_BREAKS:Tu(y,R)===!1&&ta(R,y.PATTERN)))});let d,f,p,E;n("Misc Mapping #2",()=>{d=L(r,yu),f=L(i,DA),p=Gt(r,(R,y)=>{const N=y.GROUP;return Mt(N)&&N!==gt.SKIPPED&&(R[N]=[]),R},{}),E=L(i,(R,y)=>({pattern:i[y],longerAlt:c[y],canLineTerminator:h[y],isCustom:d[y],short:f[y],group:a[y],push:l[y],pop:u[y],tokenTypeIdx:o[y],tokenType:r[y]}))});let w=!0,A=[];return t.safeMode||n("First Char Optimization",()=>{A=Gt(r,(R,y,N)=>{if(typeof y.PATTERN=="string"){const T=y.PATTERN.charCodeAt(0),m=nn(T);ea(R,m,E[N])}else if(W(y.START_CHARS_HINT)){let T;b(y.START_CHARS_HINT,m=>{const g=typeof m=="string"?m.charCodeAt(0):m,S=nn(g);T!==S&&(T=S,ea(R,S,E[N]))})}else if(Ke(y.PATTERN))if(y.PATTERN.unicode)w=!1,t.ensureOptimizations&&qo(`${Js} Unable to analyze < ${y.PATTERN.toString()} > pattern. + The regexp unicode flag is not currently supported by the regexp-to-ast library. + This will disable the lexer's first char optimizations. + For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{const T=pA(y.PATTERN,t.ensureOptimizations);z(T)&&(w=!1),b(T,m=>{ea(R,m,E[N])})}else t.ensureOptimizations&&qo(`${Js} TokenType: <${y.name}> is using a custom token pattern without providing parameter. + This will disable the lexer's first char optimizations. + For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),w=!1;return R},[])}),{emptyGroups:p,patternIdxToConfig:E,charCodeToPatternIdxToConfig:A,hasCustom:s,canBeOptimized:w}}function _A(e,t){let n=[];const r=TA(e);n=n.concat(r.errors);const s=SA(r.valid),i=s.valid;return n=n.concat(s.errors),n=n.concat(yA(i)),n=n.concat(LA(i)),n=n.concat(OA(i,t)),n=n.concat(kA(i)),n}function yA(e){let t=[];const n=Xt(e,r=>Ke(r[Nn]));return t=t.concat(wA(n)),t=t.concat(NA(n)),t=t.concat(CA(n)),t=t.concat(IA(n)),t=t.concat(RA(n)),t}function TA(e){const t=Xt(e,s=>!k(s,Nn)),n=L(t,s=>({message:"Token Type: ->"+s.name+"<- missing static 'PATTERN' property",type:nt.MISSING_PATTERN,tokenTypes:[s]})),r=Gs(e,t);return{errors:n,valid:r}}function SA(e){const t=Xt(e,s=>{const i=s[Nn];return!Ke(i)&&!$e(i)&&!k(i,"exec")&&!Mt(i)}),n=L(t,s=>({message:"Token Type: ->"+s.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:nt.INVALID_PATTERN,tokenTypes:[s]})),r=Gs(e,t);return{errors:n,valid:r}}const AA=/[^\\][$]/;function wA(e){class t extends Jo{constructor(){super(...arguments),this.found=!1}visitEndAnchor(i){this.found=!0}}const n=Xt(e,s=>{const i=s.PATTERN;try{const o=Xs(i),a=new t;return a.visit(o),a.found}catch{return AA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: + Token Type: ->`+s.name+`<- static 'PATTERN' cannot contain end of input anchor '$' + See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:nt.EOI_ANCHOR_FOUND,tokenTypes:[s]}))}function RA(e){const t=Xt(e,r=>r.PATTERN.test(""));return L(t,r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' must not match an empty string",type:nt.EMPTY_MATCH_PATTERN,tokenTypes:[r]}))}const vA=/[^\\[][\^]|^\^/;function NA(e){class t extends Jo{constructor(){super(...arguments),this.found=!1}visitStartAnchor(i){this.found=!0}}const n=Xt(e,s=>{const i=s.PATTERN;try{const o=Xs(i),a=new t;return a.visit(o),a.found}catch{return vA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: + Token Type: ->`+s.name+`<- static 'PATTERN' cannot contain start of input anchor '^' + See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:nt.SOI_ANCHOR_FOUND,tokenTypes:[s]}))}function CA(e){const t=Xt(e,r=>{const s=r[Nn];return s instanceof RegExp&&(s.multiline||s.global)});return L(t,r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:nt.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[r]}))}function IA(e){const t=[];let n=L(e,i=>Gt(e,(o,a)=>(i.PATTERN.source===a.PATTERN.source&&!Lt(t,a)&&a.PATTERN!==gt.NA&&(t.push(a),o.push(a)),o),[]));n=Fr(n);const r=Xt(n,i=>i.length>1);return L(r,i=>{const o=L(i,c=>c.name);return{message:`The same RegExp pattern ->${ae(i).PATTERN}<-has been used in all of the following Token Types: ${o.join(", ")} <-`,type:nt.DUPLICATE_PATTERNS_FOUND,tokenTypes:i}})}function LA(e){const t=Xt(e,r=>{if(!k(r,"GROUP"))return!1;const s=r.GROUP;return s!==gt.SKIPPED&&s!==gt.NA&&!Mt(s)});return L(t,r=>({message:"Token Type: ->"+r.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:nt.INVALID_GROUP_TYPE_FOUND,tokenTypes:[r]}))}function OA(e,t){const n=Xt(e,s=>s.PUSH_MODE!==void 0&&!Lt(t,s.PUSH_MODE));return L(n,s=>({message:`Token Type: ->${s.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${s.PUSH_MODE}<-which does not exist`,type:nt.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[s]}))}function kA(e){const t=[],n=Gt(e,(r,s,i)=>{const o=s.PATTERN;return o===gt.NA||(Mt(o)?r.push({str:o,idx:i,tokenType:s}):Ke(o)&&MA(o)&&r.push({str:o.source,idx:i,tokenType:s})),r},[]);return b(e,(r,s)=>{b(n,({str:i,idx:o,tokenType:a})=>{if(s${a.name}<- can never be matched. +Because it appears AFTER the Token Type ->${r.name}<-in the lexer's definition. +See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;t.push({message:c,type:nt.UNREACHABLE_PATTERN,tokenTypes:[r,a]})}})}),t}function bA(e,t){if(Ke(t)){const n=t.exec(e);return n!==null&&n.index===0}else{if($e(t))return t(e,0,[],{});if(k(t,"exec"))return t.exec(e,0,[],{});if(typeof t=="string")return t===e;throw Error("non exhaustive match")}}function MA(e){return Jn([".","\\","[","]","|","^","$","(",")","?","*","+","{"],n=>e.source.indexOf(n)!==-1)===void 0}function Eu(e){const t=e.ignoreCase?"i":"";return new RegExp(`^(?:${e.source})`,t)}function _u(e){const t=e.ignoreCase?"iy":"y";return new RegExp(`${e.source}`,t)}function xA(e,t,n){const r=[];return k(e,Kr)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+Kr+`> property in its definition +`,type:nt.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),k(e,Zs)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+Zs+`> property in its definition +`,type:nt.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),k(e,Zs)&&k(e,Kr)&&!k(e.modes,e.defaultMode)&&r.push({message:`A MultiMode Lexer cannot be initialized with a ${Kr}: <${e.defaultMode}>which does not exist +`,type:nt.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),k(e,Zs)&&b(e.modes,(s,i)=>{b(s,(o,a)=>{if(We(o))r.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${i}> at index: <${a}> +`,type:nt.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED});else if(k(o,"LONGER_ALT")){const c=W(o.LONGER_ALT)?o.LONGER_ALT:[o.LONGER_ALT];b(c,l=>{!We(l)&&!Lt(s,l)&&r.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${l.name}> on token <${o.name}> outside of mode <${i}> +`,type:nt.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})}})}),r}function UA(e,t,n){const r=[];let s=!1;const i=Fr(ie(ht(e.modes))),o=Ks(i,c=>c[Nn]===gt.NA),a=Su(n);return t&&b(o,c=>{const l=Tu(c,a);if(l!==!1){const h={message:$A(c,l),type:l.issue,tokenType:c};r.push(h)}else k(c,"LINE_BREAKS")?c.LINE_BREAKS===!0&&(s=!0):ta(a,c.PATTERN)&&(s=!0)}),t&&!s&&r.push({message:`Warning: No LINE_BREAKS Found. + This Lexer has been defined to track line and column information, + But none of the Token Types can be identified as matching a line terminator. + See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS + for details.`,type:nt.NO_LINE_BREAKS_FLAGS}),r}function PA(e){const t={},n=$t(e);return b(n,r=>{const s=e[r];if(W(s))t[r]=[];else throw Error("non exhaustive match")}),t}function yu(e){const t=e.PATTERN;if(Ke(t))return!1;if($e(t))return!0;if(k(t,"exec"))return!0;if(Mt(t))return!1;throw Error("non exhaustive match")}function DA(e){return Mt(e)&&e.length===1?e.charCodeAt(0):!1}const FA={test:function(e){const t=e.length;for(let n=this.lastIndex;n Token Type + Root cause: ${t.errMsg}. + For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(t.issue===nt.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the option. + The problem is in the <${e.name}> Token Type + For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error("non exhaustive match")}function Su(e){return L(e,n=>Mt(n)?n.charCodeAt(0):n)}function ea(e,t,n){e[t]===void 0?e[t]=[n]:e[t].push(n)}const Wr=256;let ti=[];function nn(e){return e255?255+~~(e/255):e}}function jr(e,t){const n=e.tokenTypeIdx;return n===t.tokenTypeIdx?!0:t.isParent===!0&&t.categoryMatchesMap[n]===!0}function ei(e,t){return e.tokenTypeIdx===t.tokenTypeIdx}let Au=1;const wu={};function Hr(e){const t=GA(e);KA(t),jA(t),WA(t),b(t,n=>{n.isParent=n.categoryMatches.length>0})}function GA(e){let t=St(e),n=e,r=!0;for(;r;){n=Fr(ie(L(n,i=>i.CATEGORIES)));const s=Gs(n,t);t=t.concat(s),z(s)?r=!1:n=s}return t}function KA(e){b(e,t=>{vu(t)||(wu[Au]=t,t.tokenTypeIdx=Au++),Nu(t)&&!W(t.CATEGORIES)&&(t.CATEGORIES=[t.CATEGORIES]),Nu(t)||(t.CATEGORIES=[]),HA(t)||(t.categoryMatches=[]),VA(t)||(t.categoryMatchesMap={})})}function WA(e){b(e,t=>{t.categoryMatches=[],b(t.categoryMatchesMap,(n,r)=>{t.categoryMatches.push(wu[r].tokenTypeIdx)})})}function jA(e){b(e,t=>{Ru([],t)})}function Ru(e,t){b(e,n=>{t.categoryMatchesMap[n.tokenTypeIdx]=!0}),b(t.CATEGORIES,n=>{const r=e.concat(t);Lt(r,n)||Ru(r,n)})}function vu(e){return k(e,"tokenTypeIdx")}function Nu(e){return k(e,"CATEGORIES")}function HA(e){return k(e,"categoryMatches")}function VA(e){return k(e,"categoryMatchesMap")}function YA(e){return k(e,"tokenTypeIdx")}const zA={buildUnableToPopLexerModeMessage(e){return`Unable to pop Lexer Mode after encountering Token ->${e.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(e,t,n,r,s){return`unexpected character: ->${e.charAt(t)}<- at offset: ${t}, skipped ${n} characters.`}};var nt;(function(e){e[e.MISSING_PATTERN=0]="MISSING_PATTERN",e[e.INVALID_PATTERN=1]="INVALID_PATTERN",e[e.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",e[e.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",e[e.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",e[e.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",e[e.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",e[e.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",e[e.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",e[e.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",e[e.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",e[e.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",e[e.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",e[e.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",e[e.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",e[e.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",e[e.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",e[e.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(nt||(nt={}));const Vr={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[` +`,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:zA,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(Vr);class gt{constructor(t,n=Vr){if(this.lexerDefinition=t,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(s,i)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;const o=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent <${s}>`);const{time:a,value:c}=cu(i),l=a>10?console.warn:console.log;return this.traceInitIndent time: ${a}ms`),this.traceInitIndent--,c}else return i()},typeof n=="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object. +a boolean 2nd argument is no longer supported`);this.config=Bt({},Vr,n);const r=this.config.traceInitPerf;r===!0?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof r=="number"&&(this.traceInitMaxIdent=r,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let s,i=!0;this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===Vr.lineTerminatorsPattern)this.config.lineTerminatorsPattern=FA;else if(this.config.lineTerminatorCharacters===Vr.lineTerminatorCharacters)throw Error(`Error: Missing property on the Lexer config. + For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(n.safeMode&&n.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),W(t)?s={modes:{defaultMode:St(t)},defaultMode:Kr}:(i=!1,s=St(t))}),this.config.skipValidations===!1&&(this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(xA(s,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(UA(s,this.trackStartLines,this.config.lineTerminatorCharacters))})),s.modes=s.modes?s.modes:{},b(s.modes,(a,c)=>{s.modes[c]=Ks(a,l=>We(l))});const o=$t(s.modes);if(b(s.modes,(a,c)=>{this.TRACE_INIT(`Mode: <${c}> processing`,()=>{if(this.modes.push(c),this.config.skipValidations===!1&&this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(_A(a,o))}),z(this.lexerDefinitionErrors)){Hr(a);let l;this.TRACE_INIT("analyzeTokenTypes",()=>{l=EA(a,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:n.positionTracking,ensureOptimizations:n.ensureOptimizations,safeMode:n.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[c]=l.patternIdxToConfig,this.charCodeToPatternIdxToConfig[c]=l.charCodeToPatternIdxToConfig,this.emptyGroups=Bt({},this.emptyGroups,l.emptyGroups),this.hasCustom=l.hasCustom||this.hasCustom,this.canModeBeOptimized[c]=l.canBeOptimized}})}),this.defaultMode=s.defaultMode,!z(this.lexerDefinitionErrors)&&!this.config.deferDefinitionErrorsHandling){const c=L(this.lexerDefinitionErrors,l=>l.message).join(`----------------------- +`);throw new Error(`Errors detected in definition of Lexer: +`+c)}b(this.lexerDefinitionWarning,a=>{au(a.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(mu?(this.chopInput=Vn,this.match=this.matchWithTest):(this.updateLastIndex=ut,this.match=this.matchWithExec),i&&(this.handleModes=ut),this.trackStartLines===!1&&(this.computeNewColumn=Vn),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=ut),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid config option: "${this.config.positionTracking}"`);this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT("Failed Optimization Warnings",()=>{const a=Gt(this.canModeBeOptimized,(c,l,u)=>(l===!1&&c.push(u),c),[]);if(n.ensureOptimizations&&!z(a))throw Error(`Lexer Modes: < ${a.join(", ")} > cannot be optimized. + Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode. + Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{dA()}),this.TRACE_INIT("toFastProperties",()=>{lu(this)})})}tokenize(t,n=this.defaultMode){if(!z(this.lexerDefinitionErrors)){const s=L(this.lexerDefinitionErrors,i=>i.message).join(`----------------------- +`);throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer: +`+s)}return this.tokenizeInternal(t,n)}tokenizeInternal(t,n){let r,s,i,o,a,c,l,u,h,d,f,p,E,w,A;const R=t,y=R.length;let N=0,T=0;const m=this.hasCustom?0:Math.floor(t.length/10),g=new Array(m),S=[];let v=this.trackStartLines?1:void 0,j=this.trackStartLines?1:void 0;const yt=PA(this.emptyGroups),Ar=this.trackStartLines,Tt=this.config.lineTerminatorsPattern;let Me=0,ne=[],Ss=[];const no=[],Zp=[];Object.freeze(Zp);let As;function tg(){return ne}function eg(Ct){const re=nn(Ct),wr=Ss[re];return wr===void 0?Zp:wr}const eL=Ct=>{if(no.length===1&&Ct.tokenType.PUSH_MODE===void 0){const re=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(Ct);S.push({offset:Ct.startOffset,line:Ct.startLine,column:Ct.startColumn,length:Ct.image.length,message:re})}else{no.pop();const re=Xn(no);ne=this.patternIdxToConfig[re],Ss=this.charCodeToPatternIdxToConfig[re],Me=ne.length;const wr=this.canModeBeOptimized[re]&&this.config.safeMode===!1;Ss&&wr?As=eg:As=tg}};function ng(Ct){no.push(Ct),Ss=this.charCodeToPatternIdxToConfig[Ct],ne=this.patternIdxToConfig[Ct],Me=ne.length,Me=ne.length;const re=this.canModeBeOptimized[Ct]&&this.config.safeMode===!1;Ss&&re?As=eg:As=tg}ng.call(this,n);let pe;const rg=this.config.recoveryEnabled;for(;Nc.length){c=o,l=u,pe=Ze;break}}}break}}if(c!==null){if(h=c.length,d=pe.group,d!==void 0&&(f=pe.tokenTypeIdx,p=this.createTokenInstance(c,N,f,pe.tokenType,v,j,h),this.handlePayload(p,l),d===!1?T=this.addToken(g,T,p):yt[d].push(p)),t=this.chopInput(t,h),N=N+h,j=this.computeNewColumn(j,h),Ar===!0&&pe.canLineTerminator===!0){let Vt=0,Qe,En;Tt.lastIndex=0;do Qe=Tt.test(c),Qe===!0&&(En=Tt.lastIndex-1,Vt++);while(Qe===!0);Vt!==0&&(v=v+Vt,j=h-En,this.updateTokenEndLineColumnLocation(p,d,En,Vt,v,j,h))}this.handleModes(pe,eL,ng,p)}else{const Vt=N,Qe=v,En=j;let Ze=rg===!1;for(;Ze===!1&&N ${Yr(e)} <--`:`token of type --> ${e.name} <--`} but found --> '${t.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:e,ruleName:t}){return"Redundant input, expecting EOF but found: "+e.image},buildNoViableAltMessage({expectedPathsPerAlt:e,actual:t,previous:n,customUserDescription:r,ruleName:s}){const i="Expecting: ",a=` +but found: '`+ae(t).image+"'";if(r)return i+r+a;{const c=Gt(e,(d,f)=>d.concat(f),[]),l=L(c,d=>`[${L(d,f=>Yr(f)).join(", ")}]`),h=`one of these possible Token sequences: +${L(l,(d,f)=>` ${f+1}. ${d}`).join(` +`)}`;return i+h+a}},buildEarlyExitMessage({expectedIterationPaths:e,actual:t,customUserDescription:n,ruleName:r}){const s="Expecting: ",o=` +but found: '`+ae(t).image+"'";if(n)return s+n+o;{const c=`expecting at least one iteration which starts with one of these possible Token sequences:: + <${L(e,l=>`[${L(l,u=>Yr(u)).join(",")}]`).join(" ,")}>`;return s+c+o}}};Object.freeze(Pu);const QA={buildRuleNotFoundError(e,t){return"Invalid grammar, reference to a rule which is not defined: ->"+t.nonTerminalName+`<- +inside top level rule: ->`+e.name+"<-"}},In={buildDuplicateFoundError(e,t){function n(u){return u instanceof Z?u.terminalType.name:u instanceof Kt?u.nonTerminalName:""}const r=e.name,s=ae(t),i=s.idx,o=Ae(s),a=n(s),c=i>0;let l=`->${o}${c?i:""}<- ${a?`with argument: ->${a}<-`:""} + appears more than once (${t.length} times) in the top level rule: ->${r}<-. + For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES + `;return l=l.replace(/[ \t]+/g," "),l=l.replace(/\s\s+/g,` +`),l},buildNamespaceConflictError(e){return`Namespace conflict found in grammar. +The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${e.name}>. +To resolve this make sure each Terminal and Non-Terminal names are unique +This is easy to accomplish by using the convention that Terminal names start with an uppercase letter +and Non-Terminal names start with a lower case letter.`},buildAlternationPrefixAmbiguityError(e){const t=L(e.prefixPath,s=>Yr(s)).join(", "),n=e.alternation.idx===0?"":e.alternation.idx;return`Ambiguous alternatives: <${e.ambiguityIndices.join(" ,")}> due to common lookahead prefix +in inside <${e.topLevelRule.name}> Rule, +<${t}> may appears as a prefix path in all these alternatives. +See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX +For Further details.`},buildAlternationAmbiguityError(e){const t=L(e.prefixPath,s=>Yr(s)).join(", "),n=e.alternation.idx===0?"":e.alternation.idx;let r=`Ambiguous Alternatives Detected: <${e.ambiguityIndices.join(" ,")}> in inside <${e.topLevelRule.name}> Rule, +<${t}> may appears as a prefix path in all these alternatives. +`;return r=r+`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES +For Further details.`,r},buildEmptyRepetitionError(e){let t=Ae(e.repetition);return e.repetition.idx!==0&&(t+=e.repetition.idx),`The repetition <${t}> within Rule <${e.topLevelRule.name}> can never consume any tokens. +This could lead to an infinite loop.`},buildTokenNameError(e){return"deprecated"},buildEmptyAlternationError(e){return`Ambiguous empty alternative: <${e.emptyChoiceIdx+1}> in inside <${e.topLevelRule.name}> Rule. +Only the last alternative may be an empty alternative.`},buildTooManyAlternativesError(e){return`An Alternation cannot have more than 256 alternatives: + inside <${e.topLevelRule.name}> Rule. + has ${e.alternation.definition.length+1} alternatives.`},buildLeftRecursionError(e){const t=e.topLevelRule.name,n=L(e.leftRecursionPath,i=>i.name),r=`${t} --> ${n.concat([t]).join(" --> ")}`;return`Left Recursion found in grammar. +rule: <${t}> can be invoked from itself (directly or indirectly) +without consuming any Tokens. The grammar path that causes this is: + ${r} + To fix this refactor your grammar to remove the left recursion. +see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(e){return"deprecated"},buildDuplicateRuleNameError(e){let t;return e.topLevelRule instanceof Qn?t=e.topLevelRule.name:t=e.topLevelRule,`Duplicate definition, rule: ->${t}<- is already defined in the grammar: ->${e.grammarName}<-`}};function ZA(e,t){const n=new tw(e,t);return n.resolveRefs(),n.errors}class tw extends Zn{constructor(t,n){super(),this.nameToTopRule=t,this.errMsgProvider=n,this.errors=[]}resolveRefs(){b(ht(this.nameToTopRule),t=>{this.currTopLevel=t,t.accept(this)})}visitNonTerminal(t){const n=this.nameToTopRule[t.nonTerminalName];if(n)t.referencedRule=n;else{const r=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,t);this.errors.push({message:r,type:Ot.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:t.nonTerminalName})}}}class ew extends Hs{constructor(t,n){super(),this.topProd=t,this.path=n,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=St(this.path.ruleStack).reverse(),this.occurrenceStack=St(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(t,n=[]){this.found||super.walk(t,n)}walkProdRef(t,n,r){if(t.referencedRule.name===this.nextProductionName&&t.idx===this.nextProductionOccurrence){const s=n.concat(r);this.updateExpectedNext(),this.walk(t.referencedRule,s)}}updateExpectedNext(){z(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}}class nw extends ew{constructor(t,n){super(t,n),this.path=n,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(t,n,r){if(this.isAtEndOfPath&&t.terminalType.name===this.nextTerminalName&&t.idx===this.nextTerminalOccurrence&&!this.found){const s=n.concat(r),i=new xt({definition:s});this.possibleTokTypes=Br(i),this.found=!0}}}class ri extends Hs{constructor(t,n){super(),this.topRule=t,this.occurrence=n,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class rw extends ri{walkMany(t,n,r){if(t.idx===this.occurrence){const s=ae(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkMany(t,n,r)}}class Du extends ri{walkManySep(t,n,r){if(t.idx===this.occurrence){const s=ae(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkManySep(t,n,r)}}class sw extends ri{walkAtLeastOne(t,n,r){if(t.idx===this.occurrence){const s=ae(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkAtLeastOne(t,n,r)}}class Fu extends ri{walkAtLeastOneSep(t,n,r){if(t.idx===this.occurrence){const s=ae(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkAtLeastOneSep(t,n,r)}}function na(e,t,n=[]){n=St(n);let r=[],s=0;function i(a){return a.concat(At(e,s+1))}function o(a){const c=na(i(a),t,n);return r.concat(c)}for(;n.length{z(c.definition)===!1&&(r=o(c.definition))}),r;if(a instanceof Z)n.push(a.terminalType);else throw Error("non exhaustive match")}s++}return r.push({partialPath:n,suffixDef:At(e,s)}),r}function $u(e,t,n,r){const s="EXIT_NONE_TERMINAL",i=[s],o="EXIT_ALTERNATIVE";let a=!1;const c=t.length,l=c-r-1,u=[],h=[];for(h.push({idx:-1,def:e,ruleStack:[],occurrenceStack:[]});!z(h);){const d=h.pop();if(d===o){a&&Xn(h).idx<=l&&h.pop();continue}const f=d.def,p=d.idx,E=d.ruleStack,w=d.occurrenceStack;if(z(f))continue;const A=f[0];if(A===s){const R={idx:p,def:At(f),ruleStack:$r(E),occurrenceStack:$r(w)};h.push(R)}else if(A instanceof Z)if(p=0;R--){const y=A.definition[R],N={idx:p,def:y.definition.concat(At(f)),ruleStack:E,occurrenceStack:w};h.push(N),h.push(o)}else if(A instanceof xt)h.push({idx:p,def:A.definition.concat(At(f)),ruleStack:E,occurrenceStack:w});else if(A instanceof Qn)h.push(iw(A,p,E,w));else throw Error("non exhaustive match")}return u}function iw(e,t,n,r){const s=St(n);s.push(e.name);const i=St(r);return i.push(1),{idx:t,def:e.definition,ruleStack:s,occurrenceStack:i}}var rt;(function(e){e[e.OPTION=0]="OPTION",e[e.REPETITION=1]="REPETITION",e[e.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",e[e.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",e[e.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",e[e.ALTERNATION=5]="ALTERNATION"})(rt||(rt={}));function Bu(e){if(e instanceof Ut||e==="Option")return rt.OPTION;if(e instanceof ft||e==="Repetition")return rt.REPETITION;if(e instanceof Te||e==="RepetitionMandatory")return rt.REPETITION_MANDATORY;if(e instanceof Se||e==="RepetitionMandatoryWithSeparator")return rt.REPETITION_MANDATORY_WITH_SEPARATOR;if(e instanceof le||e==="RepetitionWithSeparator")return rt.REPETITION_WITH_SEPARATOR;if(e instanceof ue||e==="Alternation")return rt.ALTERNATION;throw Error("non exhaustive match")}function ow(e,t,n,r,s,i){const o=sa(e,t,n),a=ju(o)?ei:jr;return i(o,r,a,s)}function aw(e,t,n,r,s,i){const o=ia(e,t,s,n),a=ju(o)?ei:jr;return i(o[0],a,r)}function cw(e,t,n,r){const s=e.length,i=oe(e,o=>oe(o,a=>a.length===1));if(t)return function(o){const a=L(o,c=>c.GATE);for(let c=0;cie(c)),a=Gt(o,(c,l,u)=>(b(l,h=>{k(c,h.tokenTypeIdx)||(c[h.tokenTypeIdx]=u),b(h.categoryMatches,d=>{k(c,d)||(c[d]=u)})}),c),{});return function(){const c=this.LA(1);return a[c.tokenTypeIdx]}}else return function(){for(let o=0;oi.length===1),s=e.length;if(r&&!n){const i=ie(e);if(i.length===1&&z(i[0].categoryMatches)){const a=i[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===a}}else{const o=Gt(i,(a,c,l)=>(a[c.tokenTypeIdx]=!0,b(c.categoryMatches,u=>{a[u]=!0}),a),[]);return function(){const a=this.LA(1);return o[a.tokenTypeIdx]===!0}}}else return function(){t:for(let i=0;ina([o],1)),r=Ku(n.length),s=L(n,o=>{const a={};return b(o,c=>{const l=ra(c.partialPath);b(l,u=>{a[u]=!0})}),a});let i=n;for(let o=1;o<=t;o++){const a=i;i=Ku(a.length);for(let c=0;c{const A=ra(w.partialPath);b(A,R=>{s[c][R]=!0})})}}}}return r}function sa(e,t,n,r){const s=new Gu(e,rt.ALTERNATION,r);return t.accept(s),Wu(s.result,n)}function ia(e,t,n,r){const s=new Gu(e,n);t.accept(s);const i=s.result,a=new uw(t,e,n).startWalking(),c=new xt({definition:i}),l=new xt({definition:a});return Wu([c,l],r)}function oa(e,t){t:for(let n=0;n{const s=t[r];return n===s||s.categoryMatchesMap[n.tokenTypeIdx]})}function ju(e){return oe(e,t=>oe(t,n=>oe(n,r=>z(r.categoryMatches))))}function dw(e){const t=e.lookaheadStrategy.validate({rules:e.rules,tokenTypes:e.tokenTypes,grammarName:e.grammarName});return L(t,n=>Object.assign({type:Ot.CUSTOM_LOOKAHEAD_VALIDATION},n))}function pw(e,t,n,r){const s=Jt(e,c=>gw(c,n)),i=Cw(e,t,n),o=Jt(e,c=>ww(c,n)),a=Jt(e,c=>_w(c,e,r,n));return s.concat(i,o,a)}function gw(e,t){const n=new Ew;e.accept(n);const r=n.allProductions,s=CS(r,mw),i=ce(s,a=>a.length>1);return L(ht(i),a=>{const c=ae(a),l=t.buildDuplicateFoundError(e,a),u=Ae(c),h={message:l,type:Ot.DUPLICATE_PRODUCTIONS,ruleName:e.name,dslName:u,occurrence:c.idx},d=Hu(c);return d&&(h.parameter=d),h})}function mw(e){return`${Ae(e)}_#_${e.idx}_#_${Hu(e)}`}function Hu(e){return e instanceof Z?e.terminalType.name:e instanceof Kt?e.nonTerminalName:""}class Ew extends Zn{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(t){this.allProductions.push(t)}visitOption(t){this.allProductions.push(t)}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}visitAlternation(t){this.allProductions.push(t)}visitTerminal(t){this.allProductions.push(t)}}function _w(e,t,n,r){const s=[];if(Gt(t,(o,a)=>a.name===e.name?o+1:o,0)>1){const o=r.buildDuplicateRuleNameError({topLevelRule:e,grammarName:n});s.push({message:o,type:Ot.DUPLICATE_RULE_NAME,ruleName:e.name})}return s}function yw(e,t,n){const r=[];let s;return Lt(t,e)||(s=`Invalid rule override, rule: ->${e}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,r.push({message:s,type:Ot.INVALID_RULE_OVERRIDE,ruleName:e})),r}function Vu(e,t,n,r=[]){const s=[],i=si(t.definition);if(z(i))return[];{const o=e.name;Lt(i,e)&&s.push({message:n.buildLeftRecursionError({topLevelRule:e,leftRecursionPath:r}),type:Ot.LEFT_RECURSION,ruleName:o});const c=Gs(i,r.concat([e])),l=Jt(c,u=>{const h=St(r);return h.push(u),Vu(e,u,n,h)});return s.concat(l)}}function si(e){let t=[];if(z(e))return t;const n=ae(e);if(n instanceof Kt)t.push(n.referencedRule);else if(n instanceof xt||n instanceof Ut||n instanceof Te||n instanceof Se||n instanceof le||n instanceof ft)t=t.concat(si(n.definition));else if(n instanceof ue)t=ie(L(n.definition,i=>si(i.definition)));else if(!(n instanceof Z))throw Error("non exhaustive match");const r=js(n),s=e.length>1;if(r&&s){const i=At(e);return t.concat(si(i))}else return t}class aa extends Zn{constructor(){super(...arguments),this.alternations=[]}visitAlternation(t){this.alternations.push(t)}}function Tw(e,t){const n=new aa;e.accept(n);const r=n.alternations;return Jt(r,i=>{const o=$r(i.definition);return Jt(o,(a,c)=>{const l=$u([a],[],jr,1);return z(l)?[{message:t.buildEmptyAlternationError({topLevelRule:e,alternation:i,emptyChoiceIdx:c}),type:Ot.NONE_LAST_EMPTY_ALT,ruleName:e.name,occurrence:i.idx,alternative:c+1}]:[]})})}function Sw(e,t,n){const r=new aa;e.accept(r);let s=r.alternations;return s=Ks(s,o=>o.ignoreAmbiguities===!0),Jt(s,o=>{const a=o.idx,c=o.maxLookahead||t,l=sa(a,e,c,o),u=vw(l,o,e,n),h=Nw(l,o,e,n);return u.concat(h)})}class Aw extends Zn{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}}function ww(e,t){const n=new aa;e.accept(n);const r=n.alternations;return Jt(r,i=>i.definition.length>255?[{message:t.buildTooManyAlternativesError({topLevelRule:e,alternation:i}),type:Ot.TOO_MANY_ALTS,ruleName:e.name,occurrence:i.idx}]:[])}function Rw(e,t,n){const r=[];return b(e,s=>{const i=new Aw;s.accept(i);const o=i.allProductions;b(o,a=>{const c=Bu(a),l=a.maxLookahead||t,u=a.idx,d=ia(u,s,c,l)[0];if(z(ie(d))){const f=n.buildEmptyRepetitionError({topLevelRule:s,repetition:a});r.push({message:f,type:Ot.NO_NON_EMPTY_LOOKAHEAD,ruleName:s.name})}})}),r}function vw(e,t,n,r){const s=[],i=Gt(e,(a,c,l)=>(t.definition[l].ignoreAmbiguities===!0||b(c,u=>{const h=[l];b(e,(d,f)=>{l!==f&&oa(d,u)&&t.definition[f].ignoreAmbiguities!==!0&&h.push(f)}),h.length>1&&!oa(s,u)&&(s.push(u),a.push({alts:h,path:u}))}),a),[]);return L(i,a=>{const c=L(a.alts,u=>u+1);return{message:r.buildAlternationAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:c,prefixPath:a.path}),type:Ot.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:t.idx,alternatives:a.alts}})}function Nw(e,t,n,r){const s=Gt(e,(o,a,c)=>{const l=L(a,u=>({idx:c,path:u}));return o.concat(l)},[]);return Fr(Jt(s,o=>{if(t.definition[o.idx].ignoreAmbiguities===!0)return[];const c=o.idx,l=o.path,u=Xt(s,d=>t.definition[d.idx].ignoreAmbiguities!==!0&&d.idx{const f=[d.idx+1,c+1],p=t.idx===0?"":t.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:t,ambiguityIndices:f,prefixPath:d.path}),type:Ot.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:p,alternatives:f}})}))}function Cw(e,t,n){const r=[],s=L(t,i=>i.name);return b(e,i=>{const o=i.name;if(Lt(s,o)){const a=n.buildNamespaceConflictError(i);r.push({message:a,type:Ot.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:o})}}),r}function Iw(e){const t=Yo(e,{errMsgProvider:QA}),n={};return b(e.rules,r=>{n[r.name]=r}),ZA(n,t.errMsgProvider)}function Lw(e){return e=Yo(e,{errMsgProvider:In}),pw(e.rules,e.tokenTypes,e.errMsgProvider,e.grammarName)}const Yu="MismatchedTokenException",zu="NoViableAltException",qu="EarlyExitException",Xu="NotAllInputParsedException",Ju=[Yu,zu,qu,Xu];Object.freeze(Ju);function ii(e){return Lt(Ju,e.name)}class oi extends Error{constructor(t,n){super(t),this.token=n,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class Qu extends oi{constructor(t,n,r){super(t,n),this.previousToken=r,this.name=Yu}}class Ow extends oi{constructor(t,n,r){super(t,n),this.previousToken=r,this.name=zu}}class kw extends oi{constructor(t,n){super(t,n),this.name=Xu}}class bw extends oi{constructor(t,n,r){super(t,n),this.previousToken=r,this.name=qu}}const ca={},Zu="InRuleRecoveryException";class Mw extends Error{constructor(t){super(t),this.name=Zu}}class xw{initRecoverable(t){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=k(t,"recoveryEnabled")?t.recoveryEnabled:je.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=Uw)}getTokenToInsert(t){const n=ni(t,"",NaN,NaN,NaN,NaN,NaN,NaN);return n.isInsertedInRecovery=!0,n}canTokenTypeBeInsertedInRecovery(t){return!0}canTokenTypeBeDeletedInRecovery(t){return!0}tryInRepetitionRecovery(t,n,r,s){const i=this.findReSyncTokenType(),o=this.exportLexerState(),a=[];let c=!1;const l=this.LA(1);let u=this.LA(1);const h=()=>{const d=this.LA(0),f=this.errorMessageProvider.buildMismatchTokenMessage({expected:s,actual:l,previous:d,ruleName:this.getCurrRuleFullName()}),p=new Qu(f,l,this.LA(0));p.resyncedTokens=$r(a),this.SAVE_ERROR(p)};for(;!c;)if(this.tokenMatcher(u,s)){h();return}else if(r.call(this)){h(),t.apply(this,n);return}else this.tokenMatcher(u,i)?c=!0:(u=this.SKIP_TOKEN(),this.addToResyncTokens(u,a));this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(t,n,r){return!(r===!1||this.tokenMatcher(this.LA(1),t)||this.isBackTracking()||this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,n)))}getFollowsForInRuleRecovery(t,n){const r=this.getCurrentGrammarPath(t,n);return this.getNextPossibleTokenTypes(r)}tryInRuleRecovery(t,n){if(this.canRecoverWithSingleTokenInsertion(t,n))return this.getTokenToInsert(t);if(this.canRecoverWithSingleTokenDeletion(t)){const r=this.SKIP_TOKEN();return this.consumeToken(),r}throw new Mw("sad sad panda")}canPerformInRuleRecovery(t,n){return this.canRecoverWithSingleTokenInsertion(t,n)||this.canRecoverWithSingleTokenDeletion(t)}canRecoverWithSingleTokenInsertion(t,n){if(!this.canTokenTypeBeInsertedInRecovery(t)||z(n))return!1;const r=this.LA(1);return Jn(n,i=>this.tokenMatcher(r,i))!==void 0}canRecoverWithSingleTokenDeletion(t){return this.canTokenTypeBeDeletedInRecovery(t)?this.tokenMatcher(this.LA(2),t):!1}isInCurrentRuleReSyncSet(t){const n=this.getCurrFollowKey(),r=this.getFollowSetFromFollowKey(n);return Lt(r,t)}findReSyncTokenType(){const t=this.flattenFollowSet();let n=this.LA(1),r=2;for(;;){const s=Jn(t,i=>JA(n,i));if(s!==void 0)return s;n=this.LA(r),r++}}getCurrFollowKey(){if(this.RULE_STACK.length===1)return ca;const t=this.getLastExplicitRuleShortName(),n=this.getLastExplicitRuleOccurrenceIndex(),r=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:n,inRule:this.shortRuleNameToFullName(r)}}buildFullFollowKeyStack(){const t=this.RULE_STACK,n=this.RULE_OCCURRENCE_STACK;return L(t,(r,s)=>s===0?ca:{ruleName:this.shortRuleNameToFullName(r),idxInCallingRule:n[s],inRule:this.shortRuleNameToFullName(t[s-1])})}flattenFollowSet(){const t=L(this.buildFullFollowKeyStack(),n=>this.getFollowSetFromFollowKey(n));return ie(t)}getFollowSetFromFollowKey(t){if(t===ca)return[Cn];const n=t.ruleName+t.idxInCallingRule+hu+t.inRule;return this.resyncFollows[n]}addToResyncTokens(t,n){return this.tokenMatcher(t,Cn)||n.push(t),n}reSyncTo(t){const n=[];let r=this.LA(1);for(;this.tokenMatcher(r,t)===!1;)r=this.SKIP_TOKEN(),this.addToResyncTokens(r,n);return $r(n)}attemptInRepetitionRecovery(t,n,r,s,i,o,a){}getCurrentGrammarPath(t,n){const r=this.getHumanReadableRuleStack(),s=St(this.RULE_OCCURRENCE_STACK);return{ruleStack:r,occurrenceStack:s,lastTok:t,lastTokOccurrence:n}}getHumanReadableRuleStack(){return L(this.RULE_STACK,t=>this.shortRuleNameToFullName(t))}}function Uw(e,t,n,r,s,i,o){const a=this.getKeyForAutomaticLookahead(r,s);let c=this.firstAfterRepMap[a];if(c===void 0){const d=this.getCurrRuleFullName(),f=this.getGAstProductions()[d];c=new i(f,s).startWalking(),this.firstAfterRepMap[a]=c}let l=c.token,u=c.occurrence;const h=c.isEndOfRule;this.RULE_STACK.length===1&&h&&l===void 0&&(l=Cn,u=1),!(l===void 0||u===void 0)&&this.shouldInRepetitionRecoveryBeTried(l,u,o)&&this.tryInRepetitionRecovery(e,t,n,l)}const Pw=4,rn=8,th=1<Vu(n,n,In))}validateEmptyOrAlternatives(t){return Jt(t,n=>Tw(n,In))}validateAmbiguousAlternationAlternatives(t,n){return Jt(t,r=>Sw(r,n,In))}validateSomeNonEmptyLookaheadPath(t,n){return Rw(t,n,In)}buildLookaheadForAlternation(t){return ow(t.prodOccurrence,t.rule,t.maxLookahead,t.hasPredicates,t.dynamicTokensEnabled,cw)}buildLookaheadForOptional(t){return aw(t.prodOccurrence,t.rule,t.maxLookahead,t.dynamicTokensEnabled,Bu(t.prodType),lw)}}class Fw{initLooksAhead(t){this.dynamicTokensEnabled=k(t,"dynamicTokensEnabled")?t.dynamicTokensEnabled:je.dynamicTokensEnabled,this.maxLookahead=k(t,"maxLookahead")?t.maxLookahead:je.maxLookahead,this.lookaheadStrategy=k(t,"lookaheadStrategy")?t.lookaheadStrategy:new Dw({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=new Map}preComputeLookaheadFunctions(t){b(t,n=>{this.TRACE_INIT(`${n.name} Rule Lookahead`,()=>{const{alternation:r,repetition:s,option:i,repetitionMandatory:o,repetitionMandatoryWithSeparator:a,repetitionWithSeparator:c}=Bw(n);b(r,l=>{const u=l.idx===0?"":l.idx;this.TRACE_INIT(`${Ae(l)}${u}`,()=>{const h=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:l.idx,rule:n,maxLookahead:l.maxLookahead||this.maxLookahead,hasPredicates:l.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled}),d=fa(this.fullRuleNameToShort[n.name],th,l.idx);this.setLaFuncCache(d,h)})}),b(s,l=>{this.computeLookaheadFunc(n,l.idx,la,"Repetition",l.maxLookahead,Ae(l))}),b(i,l=>{this.computeLookaheadFunc(n,l.idx,eh,"Option",l.maxLookahead,Ae(l))}),b(o,l=>{this.computeLookaheadFunc(n,l.idx,ua,"RepetitionMandatory",l.maxLookahead,Ae(l))}),b(a,l=>{this.computeLookaheadFunc(n,l.idx,ai,"RepetitionMandatoryWithSeparator",l.maxLookahead,Ae(l))}),b(c,l=>{this.computeLookaheadFunc(n,l.idx,ha,"RepetitionWithSeparator",l.maxLookahead,Ae(l))})})})}computeLookaheadFunc(t,n,r,s,i,o){this.TRACE_INIT(`${o}${n===0?"":n}`,()=>{const a=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:n,rule:t,maxLookahead:i||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:s}),c=fa(this.fullRuleNameToShort[t.name],r,n);this.setLaFuncCache(c,a)})}getKeyForAutomaticLookahead(t,n){const r=this.getLastExplicitRuleShortName();return fa(r,t,n)}getLaFuncFromCache(t){return this.lookAheadFuncsCache.get(t)}setLaFuncCache(t,n){this.lookAheadFuncsCache.set(t,n)}}class $w extends Zn{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(t){this.dslMethods.option.push(t)}visitRepetitionWithSeparator(t){this.dslMethods.repetitionWithSeparator.push(t)}visitRepetitionMandatory(t){this.dslMethods.repetitionMandatory.push(t)}visitRepetitionMandatoryWithSeparator(t){this.dslMethods.repetitionMandatoryWithSeparator.push(t)}visitRepetition(t){this.dslMethods.repetition.push(t)}visitAlternation(t){this.dslMethods.alternation.push(t)}}const ci=new $w;function Bw(e){ci.reset(),e.accept(ci);const t=ci.dslMethods;return ci.reset(),t}function nh(e,t){isNaN(e.startOffset)===!0?(e.startOffset=t.startOffset,e.endOffset=t.endOffset):e.endOffseto.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>: + ${i.join(` + +`).replace(/\n/g,` + `)}`)}}};return n.prototype=r,n.prototype.constructor=n,n._RULE_NAMES=t,n}function Vw(e,t,n){const r=function(){};sh(r,e+"BaseSemanticsWithDefaults");const s=Object.create(n.prototype);return b(t,i=>{s[i]=jw}),r.prototype=s,r.prototype.constructor=r,r}var da;(function(e){e[e.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",e[e.MISSING_METHOD=1]="MISSING_METHOD"})(da||(da={}));function Yw(e,t){return zw(e,t)}function zw(e,t){const n=Xt(t,s=>$e(e[s])===!1),r=L(n,s=>({msg:`Missing visitor method: <${s}> on ${e.constructor.name} CST Visitor.`,type:da.MISSING_METHOD,methodName:s}));return Fr(r)}class qw{initTreeBuilder(t){if(this.CST_STACK=[],this.outputCst=t.outputCst,this.nodeLocationTracking=k(t,"nodeLocationTracking")?t.nodeLocationTracking:je.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=ut,this.cstFinallyStateUpdate=ut,this.cstPostTerminal=ut,this.cstPostNonTerminal=ut,this.cstPostRule=ut;else if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=rh,this.setNodeLocationFromNode=rh,this.cstPostRule=ut,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=ut,this.setNodeLocationFromNode=ut,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=nh,this.setNodeLocationFromNode=nh,this.cstPostRule=ut,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=ut,this.setNodeLocationFromNode=ut,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=ut,this.setNodeLocationFromNode=ut,this.cstPostRule=ut,this.setInitialNodeLocation=ut;else throw Error(`Invalid config option: "${t.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(t){t.location={startOffset:NaN,endOffset:NaN}}setInitialNodeLocationOnlyOffsetRegular(t){t.location={startOffset:this.LA(1).startOffset,endOffset:NaN}}setInitialNodeLocationFullRecovery(t){t.location={startOffset:NaN,startLine:NaN,startColumn:NaN,endOffset:NaN,endLine:NaN,endColumn:NaN}}setInitialNodeLocationFullRegular(t){const n=this.LA(1);t.location={startOffset:n.startOffset,startLine:n.startLine,startColumn:n.startColumn,endOffset:NaN,endLine:NaN,endColumn:NaN}}cstInvocationStateUpdate(t){const n={name:t,children:Object.create(null)};this.setInitialNodeLocation(n),this.CST_STACK.push(n)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(t){const n=this.LA(0),r=t.location;r.startOffset<=n.startOffset?(r.endOffset=n.endOffset,r.endLine=n.endLine,r.endColumn=n.endColumn):(r.startOffset=NaN,r.startLine=NaN,r.startColumn=NaN)}cstPostRuleOnlyOffset(t){const n=this.LA(0),r=t.location;r.startOffset<=n.startOffset?r.endOffset=n.endOffset:r.startOffset=NaN}cstPostTerminal(t,n){const r=this.CST_STACK[this.CST_STACK.length-1];Gw(r,n,t),this.setNodeLocationFromToken(r.location,n)}cstPostNonTerminal(t,n){const r=this.CST_STACK[this.CST_STACK.length-1];Kw(r,n,t),this.setNodeLocationFromNode(r.location,t.location)}getBaseCstVisitorConstructor(){if(We(this.baseCstVisitorConstructor)){const t=Hw(this.className,$t(this.gastProductionsCache));return this.baseCstVisitorConstructor=t,t}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(We(this.baseCstVisitorWithDefaultsConstructor)){const t=Vw(this.className,$t(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=t,t}return this.baseCstVisitorWithDefaultsConstructor}getLastExplicitRuleShortName(){const t=this.RULE_STACK;return t[t.length-1]}getPreviousExplicitRuleShortName(){const t=this.RULE_STACK;return t[t.length-2]}getLastExplicitRuleOccurrenceIndex(){const t=this.RULE_OCCURRENCE_STACK;return t[t.length-1]}}class Xw{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(t){if(this.selfAnalysisDone!==!0)throw Error("Missing invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=t,this.tokVectorLength=t.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVector.length-2?(this.consumeToken(),this.LA(1)):hi}LA(t){const n=this.currIdx+t;return n<0||this.tokVectorLength<=n?hi:this.tokVector[n]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(t){this.currIdx=t}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVector.length-1}getLexerPosition(){return this.exportLexerState()}}class Jw{ACTION(t){return t.call(this)}consume(t,n,r){return this.consumeInternal(n,t,r)}subrule(t,n,r){return this.subruleInternal(n,t,r)}option(t,n){return this.optionInternal(n,t)}or(t,n){return this.orInternal(n,t)}many(t,n){return this.manyInternal(t,n)}atLeastOne(t,n){return this.atLeastOneInternal(t,n)}CONSUME(t,n){return this.consumeInternal(t,0,n)}CONSUME1(t,n){return this.consumeInternal(t,1,n)}CONSUME2(t,n){return this.consumeInternal(t,2,n)}CONSUME3(t,n){return this.consumeInternal(t,3,n)}CONSUME4(t,n){return this.consumeInternal(t,4,n)}CONSUME5(t,n){return this.consumeInternal(t,5,n)}CONSUME6(t,n){return this.consumeInternal(t,6,n)}CONSUME7(t,n){return this.consumeInternal(t,7,n)}CONSUME8(t,n){return this.consumeInternal(t,8,n)}CONSUME9(t,n){return this.consumeInternal(t,9,n)}SUBRULE(t,n){return this.subruleInternal(t,0,n)}SUBRULE1(t,n){return this.subruleInternal(t,1,n)}SUBRULE2(t,n){return this.subruleInternal(t,2,n)}SUBRULE3(t,n){return this.subruleInternal(t,3,n)}SUBRULE4(t,n){return this.subruleInternal(t,4,n)}SUBRULE5(t,n){return this.subruleInternal(t,5,n)}SUBRULE6(t,n){return this.subruleInternal(t,6,n)}SUBRULE7(t,n){return this.subruleInternal(t,7,n)}SUBRULE8(t,n){return this.subruleInternal(t,8,n)}SUBRULE9(t,n){return this.subruleInternal(t,9,n)}OPTION(t){return this.optionInternal(t,0)}OPTION1(t){return this.optionInternal(t,1)}OPTION2(t){return this.optionInternal(t,2)}OPTION3(t){return this.optionInternal(t,3)}OPTION4(t){return this.optionInternal(t,4)}OPTION5(t){return this.optionInternal(t,5)}OPTION6(t){return this.optionInternal(t,6)}OPTION7(t){return this.optionInternal(t,7)}OPTION8(t){return this.optionInternal(t,8)}OPTION9(t){return this.optionInternal(t,9)}OR(t){return this.orInternal(t,0)}OR1(t){return this.orInternal(t,1)}OR2(t){return this.orInternal(t,2)}OR3(t){return this.orInternal(t,3)}OR4(t){return this.orInternal(t,4)}OR5(t){return this.orInternal(t,5)}OR6(t){return this.orInternal(t,6)}OR7(t){return this.orInternal(t,7)}OR8(t){return this.orInternal(t,8)}OR9(t){return this.orInternal(t,9)}MANY(t){this.manyInternal(0,t)}MANY1(t){this.manyInternal(1,t)}MANY2(t){this.manyInternal(2,t)}MANY3(t){this.manyInternal(3,t)}MANY4(t){this.manyInternal(4,t)}MANY5(t){this.manyInternal(5,t)}MANY6(t){this.manyInternal(6,t)}MANY7(t){this.manyInternal(7,t)}MANY8(t){this.manyInternal(8,t)}MANY9(t){this.manyInternal(9,t)}MANY_SEP(t){this.manySepFirstInternal(0,t)}MANY_SEP1(t){this.manySepFirstInternal(1,t)}MANY_SEP2(t){this.manySepFirstInternal(2,t)}MANY_SEP3(t){this.manySepFirstInternal(3,t)}MANY_SEP4(t){this.manySepFirstInternal(4,t)}MANY_SEP5(t){this.manySepFirstInternal(5,t)}MANY_SEP6(t){this.manySepFirstInternal(6,t)}MANY_SEP7(t){this.manySepFirstInternal(7,t)}MANY_SEP8(t){this.manySepFirstInternal(8,t)}MANY_SEP9(t){this.manySepFirstInternal(9,t)}AT_LEAST_ONE(t){this.atLeastOneInternal(0,t)}AT_LEAST_ONE1(t){return this.atLeastOneInternal(1,t)}AT_LEAST_ONE2(t){this.atLeastOneInternal(2,t)}AT_LEAST_ONE3(t){this.atLeastOneInternal(3,t)}AT_LEAST_ONE4(t){this.atLeastOneInternal(4,t)}AT_LEAST_ONE5(t){this.atLeastOneInternal(5,t)}AT_LEAST_ONE6(t){this.atLeastOneInternal(6,t)}AT_LEAST_ONE7(t){this.atLeastOneInternal(7,t)}AT_LEAST_ONE8(t){this.atLeastOneInternal(8,t)}AT_LEAST_ONE9(t){this.atLeastOneInternal(9,t)}AT_LEAST_ONE_SEP(t){this.atLeastOneSepFirstInternal(0,t)}AT_LEAST_ONE_SEP1(t){this.atLeastOneSepFirstInternal(1,t)}AT_LEAST_ONE_SEP2(t){this.atLeastOneSepFirstInternal(2,t)}AT_LEAST_ONE_SEP3(t){this.atLeastOneSepFirstInternal(3,t)}AT_LEAST_ONE_SEP4(t){this.atLeastOneSepFirstInternal(4,t)}AT_LEAST_ONE_SEP5(t){this.atLeastOneSepFirstInternal(5,t)}AT_LEAST_ONE_SEP6(t){this.atLeastOneSepFirstInternal(6,t)}AT_LEAST_ONE_SEP7(t){this.atLeastOneSepFirstInternal(7,t)}AT_LEAST_ONE_SEP8(t){this.atLeastOneSepFirstInternal(8,t)}AT_LEAST_ONE_SEP9(t){this.atLeastOneSepFirstInternal(9,t)}RULE(t,n,r=fi){if(Lt(this.definedRulesNames,t)){const o={message:In.buildDuplicateRuleNameError({topLevelRule:t,grammarName:this.className}),type:Ot.DUPLICATE_RULE_NAME,ruleName:t};this.definitionErrors.push(o)}this.definedRulesNames.push(t);const s=this.defineRule(t,n,r);return this[t]=s,s}OVERRIDE_RULE(t,n,r=fi){const s=yw(t,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(s);const i=this.defineRule(t,n,r);return this[t]=i,i}BACKTRACK(t,n){return function(){this.isBackTrackingStack.push(1);const r=this.saveRecogState();try{return t.apply(this,n),!0}catch(s){if(ii(s))return!1;throw s}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return ZS(ht(this.gastProductionsCache))}}class Qw{initRecognizerEngine(t,n){if(this.className=this.constructor.name,this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=ei,this.subruleIdx=0,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.gastProductionsCache={},k(n,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a property. + See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0 + For Further details.`);if(W(t)){if(z(t))throw Error(`A Token Vocabulary cannot be empty. + Note that the first argument for the parser constructor + is no longer a Token vector (since v4.0).`);if(typeof t[0].startOffset=="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument. + See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0 + For Further details.`)}if(W(t))this.tokensMap=Gt(t,(i,o)=>(i[o.name]=o,i),{});else if(k(t,"modes")&&oe(ie(ht(t.modes)),YA)){const i=ie(ht(t.modes)),o=zo(i);this.tokensMap=Gt(o,(a,c)=>(a[c.name]=c,a),{})}else if(qt(t))this.tokensMap=St(t);else throw new Error(" argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=Cn;const r=k(t,"modes")?ie(ht(t.modes)):ht(t),s=oe(r,i=>z(i.categoryMatches));this.tokenMatcher=s?ei:jr,Hr(ht(this.tokensMap))}defineRule(t,n,r){if(this.selfAnalysisDone)throw Error(`Grammar rule <${t}> may not be defined after the 'performSelfAnalysis' method has been called' +Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);const s=k(r,"resyncEnabled")?r.resyncEnabled:fi.resyncEnabled,i=k(r,"recoveryValueFunc")?r.recoveryValueFunc:fi.recoveryValueFunc,o=this.ruleShortNameIdx<o.call(this)&&a.call(this)}}else i=t;if(s.call(this)===!0)return i.call(this)}atLeastOneInternal(t,n){const r=this.getKeyForAutomaticLookahead(ua,t);return this.atLeastOneInternalLogic(t,n,r)}atLeastOneInternalLogic(t,n,r){let s=this.getLaFuncFromCache(r),i;if(typeof n!="function"){i=n.DEF;const o=n.GATE;if(o!==void 0){const a=s;s=()=>o.call(this)&&a.call(this)}}else i=n;if(s.call(this)===!0){let o=this.doSingleRepetition(i);for(;s.call(this)===!0&&o===!0;)o=this.doSingleRepetition(i)}else throw this.raiseEarlyExitException(t,rt.REPETITION_MANDATORY,n.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[t,n],s,ua,t,sw)}atLeastOneSepFirstInternal(t,n){const r=this.getKeyForAutomaticLookahead(ai,t);this.atLeastOneSepFirstInternalLogic(t,n,r)}atLeastOneSepFirstInternalLogic(t,n,r){const s=n.DEF,i=n.SEP;if(this.getLaFuncFromCache(r).call(this)===!0){s.call(this);const a=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,i,a,s,Fu],a,ai,t,Fu)}else throw this.raiseEarlyExitException(t,rt.REPETITION_MANDATORY_WITH_SEPARATOR,n.ERR_MSG)}manyInternal(t,n){const r=this.getKeyForAutomaticLookahead(la,t);return this.manyInternalLogic(t,n,r)}manyInternalLogic(t,n,r){let s=this.getLaFuncFromCache(r),i;if(typeof n!="function"){i=n.DEF;const a=n.GATE;if(a!==void 0){const c=s;s=()=>a.call(this)&&c.call(this)}}else i=n;let o=!0;for(;s.call(this)===!0&&o===!0;)o=this.doSingleRepetition(i);this.attemptInRepetitionRecovery(this.manyInternal,[t,n],s,la,t,rw,o)}manySepFirstInternal(t,n){const r=this.getKeyForAutomaticLookahead(ha,t);this.manySepFirstInternalLogic(t,n,r)}manySepFirstInternalLogic(t,n,r){const s=n.DEF,i=n.SEP;if(this.getLaFuncFromCache(r).call(this)===!0){s.call(this);const a=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,i,a,s,Du],a,ha,t,Du)}}repetitionSepSecondInternal(t,n,r,s,i){for(;r();)this.CONSUME(n),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,n,r,s,i],r,ai,t,i)}doSingleRepetition(t){const n=this.getLexerPosition();return t.call(this),this.getLexerPosition()>n}orInternal(t,n){const r=this.getKeyForAutomaticLookahead(th,n),s=W(t)?t:t.DEF,o=this.getLaFuncFromCache(r).call(this,s);if(o!==void 0)return s[o].ALT.call(this);this.raiseNoAltException(n,t.ERR_MSG)}ruleFinallyStateUpdate(){if(this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop(),this.cstFinallyStateUpdate(),this.RULE_STACK.length===0&&this.isAtEndOfInput()===!1){const t=this.LA(1),n=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:t,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new kw(n,t))}}subruleInternal(t,n,r){let s;try{const i=r!==void 0?r.ARGS:void 0;return this.subruleIdx=n,s=t.apply(this,i),this.cstPostNonTerminal(s,r!==void 0&&r.LABEL!==void 0?r.LABEL:t.ruleName),s}catch(i){throw this.subruleInternalError(i,r,t.ruleName)}}subruleInternalError(t,n,r){throw ii(t)&&t.partialCstResult!==void 0&&(this.cstPostNonTerminal(t.partialCstResult,n!==void 0&&n.LABEL!==void 0?n.LABEL:r),delete t.partialCstResult),t}consumeInternal(t,n,r){let s;try{const i=this.LA(1);this.tokenMatcher(i,t)===!0?(this.consumeToken(),s=i):this.consumeInternalError(t,i,r)}catch(i){s=this.consumeInternalRecovery(t,n,i)}return this.cstPostTerminal(r!==void 0&&r.LABEL!==void 0?r.LABEL:t.name,s),s}consumeInternalError(t,n,r){let s;const i=this.LA(0);throw r!==void 0&&r.ERR_MSG?s=r.ERR_MSG:s=this.errorMessageProvider.buildMismatchTokenMessage({expected:t,actual:n,previous:i,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new Qu(s,n,i))}consumeInternalRecovery(t,n,r){if(this.recoveryEnabled&&r.name==="MismatchedTokenException"&&!this.isBackTracking()){const s=this.getFollowsForInRuleRecovery(t,n);try{return this.tryInRuleRecovery(t,s)}catch(i){throw i.name===Zu?r:i}}else throw r}saveRecogState(){const t=this.errors,n=St(this.RULE_STACK);return{errors:t,lexerState:this.exportLexerState(),RULE_STACK:n,CST_STACK:this.CST_STACK}}reloadRecogState(t){this.errors=t.errors,this.importLexerState(t.lexerState),this.RULE_STACK=t.RULE_STACK}ruleInvocationStateUpdate(t,n,r){this.RULE_OCCURRENCE_STACK.push(r),this.RULE_STACK.push(t),this.cstInvocationStateUpdate(n)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){const t=this.getLastExplicitRuleShortName();return this.shortRuleNameToFull[t]}shortRuleNameToFullName(t){return this.shortRuleNameToFull[t]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),Cn)}reset(){this.resetLexerState(),this.subruleIdx=0,this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]}}class Zw{initErrorHandler(t){this._errors=[],this.errorMessageProvider=k(t,"errorMessageProvider")?t.errorMessageProvider:je.errorMessageProvider}SAVE_ERROR(t){if(ii(t))return t.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:St(this.RULE_OCCURRENCE_STACK)},this._errors.push(t),t;throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return St(this._errors)}set errors(t){this._errors=t}raiseEarlyExitException(t,n,r){const s=this.getCurrRuleFullName(),i=this.getGAstProductions()[s],a=ia(t,i,n,this.maxLookahead)[0],c=[];for(let u=1;u<=this.maxLookahead;u++)c.push(this.LA(u));const l=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:a,actual:c,previous:this.LA(0),customUserDescription:r,ruleName:s});throw this.SAVE_ERROR(new bw(l,this.LA(1),this.LA(0)))}raiseNoAltException(t,n){const r=this.getCurrRuleFullName(),s=this.getGAstProductions()[r],i=sa(t,s,this.maxLookahead),o=[];for(let l=1;l<=this.maxLookahead;l++)o.push(this.LA(l));const a=this.LA(0),c=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:i,actual:o,previous:a,customUserDescription:n,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new Ow(c,this.LA(1),a))}}class tR{initContentAssist(){}computeContentAssist(t,n){const r=this.gastProductionsCache[t];if(We(r))throw Error(`Rule ->${t}<- does not exist in this grammar.`);return $u([r],n,this.tokenMatcher,this.maxLookahead)}getNextPossibleTokenTypes(t){const n=ae(t.ruleStack),s=this.getGAstProductions()[n];return new nw(s,t).startWalking()}}const li={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(li);const ih=!0,oh=Math.pow(2,rn)-1,ah=x({name:"RECORDING_PHASE_TOKEN",pattern:gt.NA});Hr([ah]);const ch=ni(ah,`This IToken indicates the Parser is in Recording Phase + See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(ch);const eR={name:`This CSTNode indicates the Parser is in Recording Phase + See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class nR{initGastRecorder(t){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let t=0;t<10;t++){const n=t>0?t:"";this[`CONSUME${n}`]=function(r,s){return this.consumeInternalRecord(r,t,s)},this[`SUBRULE${n}`]=function(r,s){return this.subruleInternalRecord(r,t,s)},this[`OPTION${n}`]=function(r){return this.optionInternalRecord(r,t)},this[`OR${n}`]=function(r){return this.orInternalRecord(r,t)},this[`MANY${n}`]=function(r){this.manyInternalRecord(t,r)},this[`MANY_SEP${n}`]=function(r){this.manySepFirstInternalRecord(t,r)},this[`AT_LEAST_ONE${n}`]=function(r){this.atLeastOneInternalRecord(t,r)},this[`AT_LEAST_ONE_SEP${n}`]=function(r){this.atLeastOneSepFirstInternalRecord(t,r)}}this.consume=function(t,n,r){return this.consumeInternalRecord(n,t,r)},this.subrule=function(t,n,r){return this.subruleInternalRecord(n,t,r)},this.option=function(t,n){return this.optionInternalRecord(n,t)},this.or=function(t,n){return this.orInternalRecord(n,t)},this.many=function(t,n){this.manyInternalRecord(t,n)},this.atLeastOne=function(t,n){this.atLeastOneInternalRecord(t,n)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{const t=this;for(let n=0;n<10;n++){const r=n>0?n:"";delete t[`CONSUME${r}`],delete t[`SUBRULE${r}`],delete t[`OPTION${r}`],delete t[`OR${r}`],delete t[`MANY${r}`],delete t[`MANY_SEP${r}`],delete t[`AT_LEAST_ONE${r}`],delete t[`AT_LEAST_ONE_SEP${r}`]}delete t.consume,delete t.subrule,delete t.option,delete t.or,delete t.many,delete t.atLeastOne,delete t.ACTION,delete t.BACKTRACK,delete t.LA})}ACTION_RECORD(t){}BACKTRACK_RECORD(t,n){return()=>!0}LA_RECORD(t){return hi}topLevelRuleRecord(t,n){try{const r=new Qn({definition:[],name:t});return r.name=t,this.recordingProdStack.push(r),n.call(this),this.recordingProdStack.pop(),r}catch(r){if(r.KNOWN_RECORDER_ERROR!==!0)try{r.message=r.message+` + This error was thrown during the "grammar recording phase" For more info see: + https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw r}throw r}}optionInternalRecord(t,n){return zr.call(this,Ut,t,n)}atLeastOneInternalRecord(t,n){zr.call(this,Te,n,t)}atLeastOneSepFirstInternalRecord(t,n){zr.call(this,Se,n,t,ih)}manyInternalRecord(t,n){zr.call(this,ft,n,t)}manySepFirstInternalRecord(t,n){zr.call(this,le,n,t,ih)}orInternalRecord(t,n){return rR.call(this,t,n)}subruleInternalRecord(t,n,r){if(ui(n),!t||k(t,"ruleName")===!1){const a=new Error(` argument is invalid expecting a Parser method reference but got: <${JSON.stringify(t)}> + inside top level rule: <${this.recordingProdStack[0].name}>`);throw a.KNOWN_RECORDER_ERROR=!0,a}const s=Xn(this.recordingProdStack),i=t.ruleName,o=new Kt({idx:n,nonTerminalName:i,label:r==null?void 0:r.LABEL,referencedRule:void 0});return s.definition.push(o),this.outputCst?eR:li}consumeInternalRecord(t,n,r){if(ui(n),!vu(t)){const o=new Error(` argument is invalid expecting a TokenType reference but got: <${JSON.stringify(t)}> + inside top level rule: <${this.recordingProdStack[0].name}>`);throw o.KNOWN_RECORDER_ERROR=!0,o}const s=Xn(this.recordingProdStack),i=new Z({idx:n,terminalType:t,label:r==null?void 0:r.LABEL});return s.definition.push(i),ch}}function zr(e,t,n,r=!1){ui(n);const s=Xn(this.recordingProdStack),i=$e(t)?t:t.DEF,o=new e({definition:[],idx:n});return r&&(o.separator=t.SEP),k(t,"MAX_LOOKAHEAD")&&(o.maxLookahead=t.MAX_LOOKAHEAD),this.recordingProdStack.push(o),i.call(this),s.definition.push(o),this.recordingProdStack.pop(),li}function rR(e,t){ui(t);const n=Xn(this.recordingProdStack),r=W(e)===!1,s=r===!1?e:e.DEF,i=new ue({definition:[],idx:t,ignoreAmbiguities:r&&e.IGNORE_AMBIGUITIES===!0});k(e,"MAX_LOOKAHEAD")&&(i.maxLookahead=e.MAX_LOOKAHEAD);const o=ou(s,a=>$e(a.GATE));return i.hasPredicates=o,n.definition.push(i),b(s,a=>{const c=new xt({definition:[]});i.definition.push(c),k(a,"IGNORE_AMBIGUITIES")?c.ignoreAmbiguities=a.IGNORE_AMBIGUITIES:k(a,"GATE")&&(c.ignoreAmbiguities=!0),this.recordingProdStack.push(c),a.ALT.call(this),this.recordingProdStack.pop()}),li}function lh(e){return e===0?"":`${e}`}function ui(e){if(e<0||e>oh){const t=new Error(`Invalid DSL Method idx value: <${e}> + Idx value must be a none negative value smaller than ${oh+1}`);throw t.KNOWN_RECORDER_ERROR=!0,t}}class sR{initPerformanceTracer(t){if(k(t,"traceInitPerf")){const n=t.traceInitPerf,r=typeof n=="number";this.traceInitMaxIdent=r?n:1/0,this.traceInitPerf=r?n>0:n}else this.traceInitMaxIdent=0,this.traceInitPerf=je.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(t,n){if(this.traceInitPerf===!0){this.traceInitIndent++;const r=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent <${t}>`);const{time:s,value:i}=cu(n),o=s>10?console.warn:console.log;return this.traceInitIndent time: ${s}ms`),this.traceInitIndent--,i}else return n()}}function iR(e,t){t.forEach(n=>{const r=n.prototype;Object.getOwnPropertyNames(r).forEach(s=>{if(s==="constructor")return;const i=Object.getOwnPropertyDescriptor(r,s);i&&(i.get||i.set)?Object.defineProperty(e.prototype,s,i):e.prototype[s]=n.prototype[s]})})}const hi=ni(Cn,"",NaN,NaN,NaN,NaN,NaN,NaN);Object.freeze(hi);const je=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:Pu,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),fi=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0});var Ot;(function(e){e[e.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",e[e.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",e[e.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",e[e.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",e[e.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",e[e.LEFT_RECURSION=5]="LEFT_RECURSION",e[e.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",e[e.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",e[e.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",e[e.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",e[e.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",e[e.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",e[e.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",e[e.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(Ot||(Ot={}));class qr{static performSelfAnalysis(t){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT("performSelfAnalysis",()=>{let t;this.selfAnalysisDone=!0;const n=this.className;this.TRACE_INIT("toFastProps",()=>{lu(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),b(this.definedRulesNames,s=>{const o=this[s].originalGrammarAction;let a;this.TRACE_INIT(`${s} Rule`,()=>{a=this.topLevelRuleRecord(s,o)}),this.gastProductionsCache[s]=a})}finally{this.disableRecording()}});let r=[];if(this.TRACE_INIT("Grammar Resolving",()=>{r=Iw({rules:ht(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT("Grammar Validations",()=>{if(z(r)&&this.skipValidations===!1){const s=Lw({rules:ht(this.gastProductionsCache),tokenTypes:ht(this.tokensMap),errMsgProvider:In,grammarName:n}),i=dw({lookaheadStrategy:this.lookaheadStrategy,rules:ht(this.gastProductionsCache),tokenTypes:ht(this.tokensMap),grammarName:n});this.definitionErrors=this.definitionErrors.concat(s,i)}}),z(this.definitionErrors)&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{const s=oA(ht(this.gastProductionsCache));this.resyncFollows=s}),this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var s,i;(i=(s=this.lookaheadStrategy).initialize)===null||i===void 0||i.call(s,{rules:ht(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(ht(this.gastProductionsCache))})),!qr.DEFER_DEFINITION_ERRORS_HANDLING&&!z(this.definitionErrors))throw t=L(this.definitionErrors,s=>s.message),new Error(`Parser Definition Errors detected: + ${t.join(` +------------------------------- +`)}`)})}constructor(t,n){this.definitionErrors=[],this.selfAnalysisDone=!1;const r=this;if(r.initErrorHandler(n),r.initLexerAdapter(),r.initLooksAhead(n),r.initRecognizerEngine(t,n),r.initRecoverable(n),r.initTreeBuilder(n),r.initContentAssist(),r.initGastRecorder(n),r.initPerformanceTracer(n),k(n,"ignoredIssues"))throw new Error(`The IParserConfig property has been deprecated. + Please use the flag on the relevant DSL method instead. + See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES + For further details.`);this.skipValidations=k(n,"skipValidations")?n.skipValidations:je.skipValidations}}qr.DEFER_DEFINITION_ERRORS_HANDLING=!1,iR(qr,[xw,Fw,qw,Xw,Qw,Jw,Zw,tR,nR,sR]);class oR extends qr{constructor(t,n=je){const r=St(n);r.outputCst=!0,super(t,r)}}const we=!!JSON.parse("false");JSON.parse("false");const aR=!!JSON.parse("false"),pa=mo(32,126).map(e=>String.fromCharCode(e)),Xr=x({name:"Newline",line_breaks:!0,start_chars_hint:[` +`,"\r"],pattern:/\n|\r\n?/}),cR=x({name:"Whitespace",pattern:/ +/,group:gt.SKIPPED}),lR=x({name:"Whitespace",pattern:/\s+/,line_breaks:!0,group:gt.SKIPPED}),ga=x({name:"Stat",pattern:/@.*/,start_chars_hint:["@"]}),he=x({name:"Command",pattern:/#/,start_chars_hint:["#"]});let uh=!1;function uR(e,t,n){if(!uh)return null;const[r]=n.slice(-1);if(r&&r.tokenType!==Xr)return null;let s=t;for(;e[s]===" ";)s++;if("@#/?':!".includes(e[s]))return null;let i=t+1;for(;i"@#/?':!".includes(e)===!1)}),fh=x({name:"Comment",pattern:/'.*/,start_chars_hint:["'"]}),dh=x({name:"Label",pattern:/:[^;:\n]*/,start_chars_hint:[":"]}),ph=x({name:"HyperLink",pattern:/!/,start_chars_hint:["!"]}),gh=x({name:"HyperLinkText",pattern:/;[^;\n]*/,start_chars_hint:[";"]}),Wt=x({name:"StringLiteral",pattern:/[^-0-9"!;@#/?\s]+[^-"!;@#/?\s]*/,start_chars_hint:pa}),mh=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),Eh=x({name:"NumberLiteral",pattern:/-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?/});function Qt(e){return x({name:e,pattern:new RegExp(e.toLowerCase(),"i"),longer_alt:Wt})}const _h=x({name:"IsEq",pattern:/=|is|eq|equal/,longer_alt:Wt}),yh=x({name:"IsNotEq",pattern:/!=|not ?eq|not ?equal/,longer_alt:Wt}),Th=x({name:"IsLessThan",pattern:/<|below/,longer_alt:Wt}),Sh=x({name:"IsGreaterThan",pattern:/>|above/,longer_alt:Wt}),Ah=x({name:"IsLessThanOrEqual",pattern:/<=|below ?or ?eq|below ?or ?equal/,longer_alt:Wt}),wh=x({name:"IsGreaterThanOrEqual",pattern:/>=|above ?or ?eq|above ?or ?equal/,longer_alt:Wt}),ma=x({name:"Or",pattern:/or/i,longer_alt:Wt}),Ea=x({name:"Not",pattern:/not/i,longer_alt:Wt}),_a=x({name:"And",pattern:/and/i,longer_alt:Wt}),ya=x({name:"Plus",pattern:/\+/}),Ta=x({name:"Minus",pattern:/-/}),Rh=x({name:"Power",pattern:/\*\*/}),vh=x({name:"Multiply",pattern:/\*/}),Sa=x({name:"Divide",pattern:/\//}),Nh=x({name:"ModDivide",pattern:/%/}),Ch=x({name:"FloorDivide",pattern:/%%/}),Ih=x({name:"Query",pattern:/\?/}),Lh=x({name:"LParen",pattern:/\(/,push_mode:"ignore_newlines"}),Oh=x({name:"RParen",pattern:/\)/,pop_mode:!0}),kh=x({name:"play",pattern:/play .*/,start_chars_hint:pa,longer_alt:Wt}),Aa=Qt("if"),Ln=Qt("do"),wa=Qt("else"),bh=Qt("endif"),Mh=Qt("while"),xh=Qt("endwhile"),Uh=Qt("repeat"),Ph=Qt("endrepeat"),Dh=Qt("read"),Fh=Qt("endread"),$h=Qt("break"),Bh=Qt("continue");function Gh(e){return[...e,_h,yh,Ah,Th,wh,Sh,ma,Ea,_a,ya,Ta,Rh,vh,Sa,Ch,Nh,Ih,Lh,Oh,mh,Wt,Eh]}const Kh=Gh([hh,ga,kh,he,fh,dh,ph,gh,Xr,cR,Aa,Ln,wa,bh,Mh,xh,Uh,Ph,Dh,Fh,$h,Bh]),hR=new gt({defaultMode:"use_newlines",modes:{use_newlines:Kh,ignore_newlines:Gh([lR])}},{skipValidations:!we,ensureOptimizations:we});function Ra(e){uh=!0;const t=hR.tokenize(e||` +`),[n]=(Array.isArray(t.tokens)?t.tokens:[]).slice(-1);return n&&n.tokenType.name!=="Newline"&&t.tokens.push(ni(Xr,` +`,n.startOffset,n.endOffset??NaN,n.startLine??NaN,n.endLine??NaN,n.startColumn??NaN,n.endColumn??NaN)),t}var jt=(e=>(e[e.ERROR=0]="ERROR",e[e.FUNC=1]="FUNC",e[e.BOARD=2]="BOARD",e[e.OBJECT=3]="OBJECT",e[e.TERRAIN=4]="TERRAIN",e[e.CHARSET=5]="CHARSET",e[e.PALETTE=6]="PALETTE",e))(jt||{});function Re(e,t){return{id:Ue(),code:e,...t}}function fR(e){return e.map(t=>t.image)}function dR(e,t){const[n,r,...s]=t;if(_(e.stats)&&_(n))switch(n.image.toLowerCase()){case"rn":case"range":case"sl":case"select":case"nm":case"number":case"tx":case"text":case"ln":case"link":if(_(r)){const i=r.image.toLowerCase();e.stats[i]=fR(s??[])}break}}function Wh(e){var n;if(!_(e))return{};if(_((n=e.stats)==null?void 0:n.type))return e.stats;e.stats={};const t=Ra(e.code);for(let r=0;rpR(i)===t&&(i.id===n||r===gR(i)))}function Na(e,t,n){const r=va(e,t,n);if(r)switch(t){case jt.ERROR:return r.error;case jt.FUNC:return r.code;case jt.BOARD:return r.board;case jt.OBJECT:return r.object;case jt.TERRAIN:return r.terrain;case jt.CHARSET:return r.charset;case jt.PALETTE:return r.palette}}function Ca(e,t){const n=t??"",r=va(e,jt.OBJECT,n),s=Na(e,jt.OBJECT,n);return _(r)?{...s,name:n,code:r.code}:void 0}function di(e,t){if(_(t)&&_(t.kind))return _(t.kinddata)||(t.kinddata=Ca(e,t.kind)),t.kinddata}function Hh(e,t){const n=t??"",r=va(e,jt.TERRAIN,n),s=Na(e,jt.TERRAIN,n);return _(r)?{...s,name:n,code:r.code}:void 0}function Ia(e,t){if(_(t)&&_(t.kind))return _(t.kinddata)||(t.kinddata=Hh(e,t.kind)),t.kinddata}function er(e,t){return Na(e,jt.BOARD,t)}function Vh(e,t){if(e)return e.flags[t]=e.flags[t]??{},e.flags[t]}function mR(e,t,n){const r=Vh(e,t);return r==null?void 0:r[n]}function ER(e,t,n,r){const s=Vh(e,t);return s&&(s[n]=r),r}function Yh(e,t){return er(e,(e==null?void 0:e.players[t])??"")}function _R(e,t,n){_(e)&&_(er(e,n))&&(e.players[t]=n)}function yR(e){return Qg(Object.values((e==null?void 0:e.players)??[])).map(t=>er(e,t)).filter(_)}function TR(e,t,n,r){const s=Xc(t,(n==null?void 0:n.id)??"");if(!_(e)||!_(t)||!_(s)||!_(t.lookup)||r.x<0||r.x>=t.width||r.y<0||r.y>=t.height)return{kind:"edge",...r};const i=r.x+r.y*t.width,o=di(e,s),a=s.collision??(o==null?void 0:o.collision)??mt.WALK,c=Xc(t,t.lookup[i]??"");if(_(c))return{...c};const l=t.terrain[i];if(_(l)){const u=Ia(e,l),h=l.collision??(u==null?void 0:u.collision)??mt.WALK;if(Zg(a,h))return{...l,...r}}t.lookup[i]=void 0,s.x=r.x,s.y=r.y,t.lookup[s.x+s.y*t.width]=s.id??""}function nr(e,t){if(_(t==null?void 0:t.x)&&_(t.y)&&_(t.id)){const r=di(e,t);return(t.name??(r==null?void 0:r.name)??"object").toLowerCase()}const n=Ia(e,t);return((t==null?void 0:t.name)??(n==null?void 0:n.name)??"terrain").toLowerCase()}function zh(e,t,n,r){if(!_(e)||!_(t)||!_(t.named)||!_(n))return;const s=nr(e,n);t.named[s]||(t.named[s]=new Set),t.named[s].add((n==null?void 0:n.id)??r??"")}function qh(e,t,n){if(!_(e)||!_(t)||!_(t.lookup)||!_(n==null?void 0:n.id))return;const r=n.x??0,s=n.y??0;t.lookup[r+s*t.width]=n.id}function La(e,t){if(!_(e)||!_(t)||_(t.lookup)&&_(t.named))return;const n=new Array(t.width*t.height).fill(void 0),r={},s=Object.values(t.objects);for(let a=0;a=t.width&&(i=0,++o)}t.lookup=n,t.named=r,e.name==="temp"&&console.info(t)}function Xh(e,t,n,r){nr(e,n)!=="player"&&_(n)&&(n.removed=r,Jh(e,t,n))}function Jh(e,t,n){var r,s;if(_(e)&&_(t)&&_(n==null?void 0:n.id)&&_(n.x)&&_(n.y)){if(_(t.lookup)){const o=n.x+n.y*t.width;((r=t.lookup)==null?void 0:r[o])===n.id&&delete t.lookup[o]}const i=nr(e,n);_((s=t.named)==null?void 0:s[i])&&t.named[i].delete(n.id)}}function SR(e,t,n){if(!_(e)||!_(t))return;const r=Object.values(t.objects);for(let s=0;sRo*5&&So(t,i.id)}}function AR(e,t,n,r){if(!_(e)||!_(t))return;t.lookup=void 0,La(e,t);const s=Object.values(t.objects);for(let i=0;i(e[e.VIEW=0]="VIEW",e[e.EDIT=1]="EDIT",e))(Jr||{});function Qh(e){return{id:Ue(),type:e}}function Zh(e,t){const n=Qh(0);return n.book=e,n.board=t,n}function wR(e,t){const n=Qh(1);return n.book=e,n.board=t,n}const He={defaultplayer:"",books:new Map,chips:new Map,frames:new Map};function RR(e){He.defaultplayer=e}function tf(e){const t=[Zh(void 0,void 0)];return He.frames.set(e,t),t}function vR(e,t,n){const r=pi(e);_(r)&&r.push(Zh(t,n))}function NR(e,t,n){const r=pi(e);_(r)&&r.push(wR(t,n))}function pi(e){return He.frames.get(e)??tf(e)}function Qr(e){const t=e.toLowerCase();return He.books.get(e)??[...He.books.values()].find(n=>n.name.toLowerCase()===t)}function ef(e){return He.books.set(e.id,e),e.id}function V(e){let t=He.chips.get(e);return _(t)||(t={book:void 0,board:void 0,target:void 0,inputqueue:new Set,inputmods:{[ct.NONE]:0,[ct.MOVE_UP]:0,[ct.MOVE_DOWN]:0,[ct.MOVE_LEFT]:0,[ct.MOVE_RIGHT]:0,[ct.OK_BUTTON]:0,[ct.CANCEL_BUTTON]:0,[ct.MENU_BUTTON]:0},inputcurrent:void 0},He.chips.set(e,t)),t}const nf="player",rf="title";function CR(e){const t=Qr(_i.name),n=er(t,rf),r=Ca(t,nf);if(_(n)&&_(r)){const s=To(n,{id:e,x:0,y:0,kind:nf,stats:{player:e}});_(s==null?void 0:s.id)&&_R(t,e,rf)}}function IR(e){He.books.forEach(t=>So(Yh(t,e),e))}function LR(e,t){function n(s,i,o,a,c){const l=V(a);l.book=s,l.board=i,l.target=o,l.inputcurrent=void 0,e.tick(a,c)}const r=Qr(_i.name);yR(r).forEach(s=>AR(r,s,t,n))}function OR(e,t,n,r,s){const i=[];let o=t;const a=o===0,c=r.width??0,l=r.height??0,u=a?Q.BLACK:Q.CLEAR,h=Tg(e,o++,c,l,u);i.push(h);const d=wg(e,o++,c,l);i.push(d);const f=o++,p=Ag(e,f);i.push(p);const E=Rg(e,o++);s&&i.push(E),r.terrain.forEach((A,R)=>{if(A){const y=Ia(n,A);h.char[R]=A.char??(y==null?void 0:y.char)??0,h.color[R]=A.color??(y==null?void 0:y.color)??u,h.bg[R]=A.bg??(y==null?void 0:y.bg)??u}});const w=r.objects??{};return Object.values(w).forEach(A=>{if(_(A.removed))return;const R=A.id??"",y=di(n,A),N=Sg(e,f,R),T=A.lx??A.x??0,m=A.ly??A.y??0;N.x=A.x??0,N.y=A.y??0,N.char=A.char??(y==null?void 0:y.char)??1,N.color=A.color??(y==null?void 0:y.color)??Q.WHITE,N.bg=A.bg??(y==null?void 0:y.bg)??Q.CLEAR,p.sprites.push(N),N.bg===Q.SHADOW&&(d.alphas[T+m*c]=.5),R===e&&(E.focusx=N.x,E.focusy=N.y,E.focusid=R)}),i}function sf(e){switch(e.type){case Jr.EDIT:return 1;case Jr.VIEW:return 2}return 0}function kR(e){const t=Qr(_i.name),n=Yh(t,e),r=[];if(!_(t)||!_(n))return r;let s=0;return pi(n.id??"").toSorted((o,a)=>sf(o)-sf(a)).forEach(o=>{const a=Qr(o.book??"")??t,c=er(a,o.board??"")??n;if(_(a)&&_(c)){const l=OR(e,s,a,c,o.type===Jr.VIEW);s+=l.length,r.push(...l)}}),r}var Q=(e=>(e[e.BLACK=0]="BLACK",e[e.DKBLUE=1]="DKBLUE",e[e.DKGREEN=2]="DKGREEN",e[e.DKCYAN=3]="DKCYAN",e[e.DKRED=4]="DKRED",e[e.DKPURPLE=5]="DKPURPLE",e[e.DKYELLOW=6]="DKYELLOW",e[e.LTGRAY=7]="LTGRAY",e[e.DKGRAY=8]="DKGRAY",e[e.BLUE=9]="BLUE",e[e.GREEN=10]="GREEN",e[e.CYAN=11]="CYAN",e[e.RED=12]="RED",e[e.PURPLE=13]="PURPLE",e[e.YELLOW=14]="YELLOW",e[e.WHITE=15]="WHITE",e[e.ONBLACK=16]="ONBLACK",e[e.ONDKBLUE=17]="ONDKBLUE",e[e.ONDKGREEN=18]="ONDKGREEN",e[e.ONDKCYAN=19]="ONDKCYAN",e[e.ONDKRED=20]="ONDKRED",e[e.ONDKPURPLE=21]="ONDKPURPLE",e[e.ONDKYELLOW=22]="ONDKYELLOW",e[e.ONLTGRAY=23]="ONLTGRAY",e[e.ONDKGRAY=24]="ONDKGRAY",e[e.ONBLUE=25]="ONBLUE",e[e.ONGREEN=26]="ONGREEN",e[e.ONCYAN=27]="ONCYAN",e[e.ONRED=28]="ONRED",e[e.ONPURPLE=29]="ONPURPLE",e[e.ONYELLOW=30]="ONYELLOW",e[e.ONWHITE=31]="ONWHITE",e[e.CLEAR=Gc]="CLEAR",e[e.SHADOW=yg]="SHADOW",e))(Q||{}),B=(e=>(e[e.IDLE=0]="IDLE",e[e.NORTH=1]="NORTH",e[e.SOUTH=2]="SOUTH",e[e.WEST=3]="WEST",e[e.EAST=4]="EAST",e[e.BY=5]="BY",e[e.AT=6]="AT",e[e.FLOW=7]="FLOW",e[e.SEEK=8]="SEEK",e[e.RNDNS=9]="RNDNS",e[e.RNDNE=10]="RNDNE",e[e.RND=11]="RND",e[e.CW=12]="CW",e[e.CCW=13]="CCW",e[e.OPP=14]="OPP",e[e.RNDP=15]="RNDP",e))(B||{}),mt=(e=>(e[e.SOLID=0]="SOLID",e[e.WALK=1]="WALK",e[e.SWIM=2]="SWIM",e[e.BULLET=3]="BULLET",e))(mt||{}),gi=(e=>(e[e.TERRAIN=0]="TERRAIN",e[e.OBJECT=1]="OBJECT",e))(gi||{});function sn(e){return _(e)&&_(e.x)&&_(e.y)}function rr(e,t){const n=t.x-e.x,r=t.y-e.y;if(n<0)return 3;if(n>0)return 4;if(r<0)return 1;if(r>0)return 2}const of={terrain:"TERRAIN",object:"OBJECT"};function on(e){return Pe(e)&&af(e[0])}function af(e){return _(gi[e])&<(e)}function cf(e){if(lt(e))return of[e.toLowerCase()]}function lf(e){if(on(e))return e;if(af(e))return[e];const t=cf(e);if(_(t))return[t]}function mi(e,t){const n=e.words[t],r=lf(n);if(on(r))return[r,t+1];const[s,i]=Rt(e,t),o=lf(s);return on(o)?[o,i]:[void 0,t]}const uf={solid:"SOLID",walk:"WALK",swim:"SWIM",bullet:"BULLET",walkable:"WALK",swimmable:"SWIM"};function On(e){return Pe(e)&&Oa(e[0])}function Oa(e){return _(mt[e])&<(e)}function bR(e){if(lt(e))return uf[e.toLowerCase()]}function hf(e,t){const n=e.words[t];if(On(n))return[n,t+1];if(Oa(n))return[[n],t+1];const[r,s]=Rt(e,t);return On(r)?[r,s]:Oa(r)?[[r],s]:[void 0,t]}const ff={black:"BLACK",dkblue:"DKBLUE",dkgreen:"DKGREEN",dkcyan:"DKCYAN",dkred:"DKRED",dkpurple:"DKPURPLE",dkyellow:"DKYELLOW",ltgray:"LTGRAY",dkgray:"DKGRAY",blue:"BLUE",green:"GREEN",cyan:"CYAN",red:"RED",purple:"PURPLE",yellow:"YELLOW",white:"WHITE",clear:"CLEAR",shadow:"SHADOW",brown:"DKYELLOW",dkwhite:"LTGRAY",ltgrey:"LTGRAY",gray:"LTGRAY",grey:"LTGRAY",dkgrey:"DKGRAY",ltblack:"DKGRAY",onblack:"ONBLACK",ondkblue:"ONDKBLUE",ondkgreen:"ONDKGREEN",ondkcyan:"ONDKCYAN",ondkred:"ONDKRED",ondkpurple:"ONDKPURPLE",ondkyellow:"ONDKYELLOW",onltgray:"ONLTGRAY",ondkgray:"ONDKGRAY",onblue:"ONBLUE",ongreen:"ONGREEN",oncyan:"ONCYAN",onred:"ONRED",onpurple:"ONPURPLE",onyellow:"ONYELLOW",onwhite:"ONWHITE",onbrown:"ONDKYELLOW",ondkwhite:"ONLTGRAY",onltgrey:"ONLTGRAY",ongray:"ONLTGRAY",ongrey:"ONLTGRAY",ondkgrey:"ONDKGRAY",onltblack:"ONDKGRAY"};function Zt(e){return Pe(e)&&pf(e[0])}function df(e){return Zt(e)&&e[0].startsWith("ON")}function pf(e){return _(Q[e])&<(e)}function gf(e){if(lt(e))return ff[e.toLowerCase()]}function mf(e){return e.map(t=>Q[t]).find(t=>_(t)&&t<16)}function Ef(e){return e.map(t=>Q[t]).find(t=>_(t)&&t>=16)}function _f(e){if(Zt(e))return e;if(pf(e))return[e];const t=gf(e);if(_(t))return[t]}function yf(e,t){const n=e.words[t],r=_f(n);if(Zt(r))return[r,t+1];const[s,i]=Rt(e,t),o=_f(s);return Zt(o)?[o,i]:[void 0,t]}function Ei(e,t){const n=[];let r=t;const[s,i]=yf(e,t);if(Zt(s)&&(n.push(...s),r=i),Zt(n)&&!df(n)){const[o,a]=yf(e,i);df(o)&&(n.push(...o),r=a)}return n.length?[n,r]:[void 0,t]}function sr(e){return Pe(e)&&typeof e[0]=="string"}function Tf(e,t){const n=e.words[t];if(sr(n))return[n,t+1];const[r,s]=Ei(e,t),[i,o]=Rt(e,s,!1);return lt(i)?[[i,r],o]:[void 0,t]}function ka(e){if(!sr(e))return;const[t]=e;return t}function Sf(e){if(!sr(e))return;const[,t]=e,n=_(t)?mf(t):void 0;return _(n)?n:void 0}function Af(e){if(!sr(e))return;const[,t]=e,n=_(t)?Ef(t):void 0;return _(n)?n:void 0}const wf={idle:"IDLE",up:"NORTH",down:"SOUTH",left:"WEST",right:"EAST",by:"BY",at:"AT",flow:"FLOW",seek:"SEEK",rndns:"RNDNS",rndne:"RNDNE",rnd:"RND",cw:"CW",ccw:"CCW",opp:"OPP",rndp:"RNDP",u:"NORTH",north:"NORTH",n:"NORTH",d:"SOUTH",south:"SOUTH",s:"SOUTH",l:"WEST",west:"WEST",w:"WEST",r:"EAST",east:"EAST",e:"EAST",edit:"EDIT"};function Ve(e){return Pe(e)&&Rf(e[0])}function Rf(e){return _(B[e])&<(e)}function vf(e){if(lt(e))return wf[e.toLowerCase()]}function Nf(e){if(Ve(e))return e;if(Rf(e))return[e];const t=vf(e);if(_(t))return[t]}function Cf(e,t){const n=e.words[t],r=Nf(n);if(Ve(r))return[r,t+1];const[s,i]=Rt(e,t),o=Nf(s);return Ve(o)?[o,i]:[void 0,t]}function ba(e,t){const n=[];let[r,s]=Cf(e,t);for(;Ve(r);){n.push(...r);const[i,o]=Cf(e,s);r=i,s=o}return n.length?[n,t+n.length]:[void 0,t]}function K(e,t){return{...V(e.id()),chip:e,words:t}}function Rt(e,t,n=!0){const r=e.words[t];if(cf(r)){const[s,i]=mi(e,t);if(_(s))return[s,i]}if(bR(r)){const[s,i]=hf(e,t);if(_(s))return[s,i]}if(gf(r)){const[s,i]=Ei(e,t);if(_(s))return[s,i]}if(lt(r)&&r.toLowerCase()==="rnd"){const[s,i]=Rt(e,t+1),[o,a]=Rt(e,i);return Ft(s)&&Ft(o)?[Wn(s,o),a]:Ft(s)?[Wn(0,s),i]:[Wn(0,1),t+1]}if(vf(r)){const[s,i]=ba(e,t);if(_(s))return[s,i]}if(!_(r))return[void 0,t];if(sn(r)||Ft(r)||Pe(r))return[r,t+1];if(lt(r)){const s=r.toLowerCase();if(n){const i=e.chip.get(r);if(_(i))return[i,t+1]}switch(s){case"aligned":case"alligned":break;case"contact":break;case"blocked":break;case"any":break;case"abs":{const[i,o]=I(e,t+1,[5]);return[Math.abs(i),o]}case"ceil":{const[i,o]=I(e,t+1,[5]);return[Math.ceil(i),o]}case"floor":{const[i,o]=I(e,t+1,[5]);return[Math.floor(i),o]}case"round":{const[i,o]=I(e,t+1,[5]);return[Math.round(i),o]}case"min":{const i=[];for(let o=t+1;o(e[e.CATEGORY=0]="CATEGORY",e[e.COLLISION=1]="COLLISION",e[e.COLOR=2]="COLOR",e[e.KIND=3]="KIND",e[e.DIR=4]="DIR",e[e.NUMBER=5]="NUMBER",e[e.STRING=6]="STRING",e[e.NUMBER_OR_STRING=7]="NUMBER_OR_STRING",e[e.MAYBE_CATEGORY=8]="MAYBE_CATEGORY",e[e.MAYBE_COLLISION=9]="MAYBE_COLLISION",e[e.MAYBE_COLOR=10]="MAYBE_COLOR",e[e.MAYBE_KIND=11]="MAYBE_KIND",e[e.MAYBE_DIR=12]="MAYBE_DIR",e[e.MAYBE_NUMBER=13]="MAYBE_NUMBER",e[e.MAYBE_STRING=14]="MAYBE_STRING",e[e.MAYBE_NUMBER_OR_STRING=15]="MAYBE_NUMBER_OR_STRING",e[e.ANY=16]="ANY",e))(C||{});function vt(e,t){throw new Error(`Invalid arg, expected: ${e} but got ${JSON.stringify(t)}`)}function I(e,t,n){const r=[];let s=t;for(let i=0;i{for(let t=0;t<32;t++)To(e,{x:Wn(0,e.width-1),y:Wn(0,e.height-1),kind:"spin"});return e})}),Re(MR,{object:{char:219,color:Q.WHITE,bg:Q.CLEAR}}),Re(xR,{object:{char:1,color:Q.WHITE,bg:Q.CLEAR}}),Re("@terrain field",{terrain:{char:176,color:Q.DKGRAY,collision:mt.WALK}}),Re("@terrain wall",{terrain:{char:219,color:Q.CYAN,collision:mt.SOLID}})]);var If={exports:{}},Ma={exports:{}},Lf;function UR(){return Lf||(Lf=1,function(e,t){(function(n,r){e.exports=r()})(ws,function(){function n(E){return!isNaN(parseFloat(E))&&isFinite(E)}function r(E){return E.charAt(0).toUpperCase()+E.substring(1)}function s(E){return function(){return this[E]}}var i=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],a=["fileName","functionName","source"],c=["args"],l=["evalOrigin"],u=i.concat(o,a,c,l);function h(E){if(E)for(var w=0;w-1&&(u=u.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var h=u.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),d=h.match(/ (\(.+\)$)/);h=d?h.replace(d[0],""):h;var f=this.extractLocation(d?d[1]:h),p=d&&h||void 0,E=["eval",""].indexOf(f[0])>-1?void 0:f[0];return new r({functionName:p,fileName:E,lineNumber:f[1],columnNumber:f[2],source:u})},this)},parseFFOrSafari:function(c){var l=c.stack.split(` +`).filter(function(u){return!u.match(o)},this);return l.map(function(u){if(u.indexOf(" > eval")>-1&&(u=u.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),u.indexOf("@")===-1&&u.indexOf(":")===-1)return new r({functionName:u});var h=/((.*".+"[^@]*)?[^@]*)(?:@)/,d=u.match(h),f=d&&d[1]?d[1]:void 0,p=this.extractLocation(u.replace(h,""));return new r({functionName:f,fileName:p[0],lineNumber:p[1],columnNumber:p[2],source:u})},this)},parseOpera:function(c){return!c.stacktrace||c.message.indexOf(` +`)>-1&&c.message.split(` +`).length>c.stacktrace.split(` +`).length?this.parseOpera9(c):c.stack?this.parseOpera11(c):this.parseOpera10(c)},parseOpera9:function(c){for(var l=/Line (\d+).*script (?:in )?(\S+)/i,u=c.message.split(` +`),h=[],d=2,f=u.length;d/,"$2").replace(/\([^)]*\)/g,"")||void 0,E;f.match(/\(([^)]*)\)/)&&(E=f.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var w=E===void 0||E==="[arguments not available]"?void 0:E.split(",");return new r({functionName:p,args:w,fileName:d[0],lineNumber:d[1],columnNumber:d[2],source:u})},this)}}})})(If);var PR=If.exports,DR=ro(PR),Of={},kf={},bf={};const Mf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");bf.encode=function(e){if(0<=e&&e>>=xf,s>0&&(r|=BR),n+=FR.encode(r);while(s>0);return n};var Zr={};(function(e){function t(m,g,S){if(g in m)return m[g];if(arguments.length===3)return S;throw new Error('"'+g+'" is a required argument.')}e.getArg=t;const n=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/,r=/^data:.+\,.+$/;function s(m){const g=m.match(n);return g?{scheme:g[1],auth:g[2],host:g[3],port:g[4],path:g[5]}:null}e.urlParse=s;function i(m){let g="";return m.scheme&&(g+=m.scheme+":"),g+="//",m.auth&&(g+=m.auth+"@"),m.host&&(g+=m.host),m.port&&(g+=":"+m.port),m.path&&(g+=m.path),g}e.urlGenerate=i;const o=32;function a(m){const g=[];return function(S){for(let j=0;jo&&g.pop(),v}}const c=a(function(g){let S=g;const v=s(g);if(v){if(!v.path)return g;S=v.path}const j=e.isAbsolute(S),yt=[];let Ar=0,Tt=0;for(;;)if(Ar=Tt,Tt=S.indexOf("/",Ar),Tt===-1){yt.push(S.slice(Ar));break}else for(yt.push(S.slice(Ar,Tt));Tt=0;Tt--){const ne=yt[Tt];ne==="."?yt.splice(Tt,1):ne===".."?Me++:Me>0&&(ne===""?(yt.splice(Tt+1,Me),Me=0):(yt.splice(Tt,2),Me--))}return S=yt.join("/"),S===""&&(S=j?"/":"."),v?(v.path=S,i(v)):S});e.normalize=c;function l(m,g){m===""&&(m="."),g===""&&(g=".");const S=s(g),v=s(m);if(v&&(m=v.path||"/"),S&&!S.scheme)return v&&(S.scheme=v.scheme),i(S);if(S||g.match(r))return g;if(v&&!v.host&&!v.path)return v.host=g,i(v);const j=g.charAt(0)==="/"?g:c(m.replace(/\/+$/,"")+"/"+g);return v?(v.path=j,i(v)):j}e.join=l,e.isAbsolute=function(m){return m.charAt(0)==="/"||n.test(m)};function u(m,g){m===""&&(m="."),m=m.replace(/\/$/,"");let S=0;for(;g.indexOf(m+"/")!==0;){const v=m.lastIndexOf("/");if(v<0||(m=m.slice(0,v),m.match(/^([^\/]+:\/)?\/*$/)))return g;++S}return Array(S+1).join("../")+g.substr(m.length+1)}e.relative=u;const h=function(){return!("__proto__"in Object.create(null))}();function d(m){return m}function f(m){return E(m)?"$"+m:m}e.toSetString=h?d:f;function p(m){return E(m)?m.slice(1):m}e.fromSetString=h?d:p;function E(m){if(!m)return!1;const g=m.length;if(g<9||m.charCodeAt(g-1)!==95||m.charCodeAt(g-2)!==95||m.charCodeAt(g-3)!==111||m.charCodeAt(g-4)!==116||m.charCodeAt(g-5)!==111||m.charCodeAt(g-6)!==114||m.charCodeAt(g-7)!==112||m.charCodeAt(g-8)!==95||m.charCodeAt(g-9)!==95)return!1;for(let S=g-10;S>=0;S--)if(m.charCodeAt(S)!==36)return!1;return!0}function w(m,g,S){let v=R(m.source,g.source);return v!==0||(v=m.originalLine-g.originalLine,v!==0)||(v=m.originalColumn-g.originalColumn,v!==0||S)||(v=m.generatedColumn-g.generatedColumn,v!==0)||(v=m.generatedLine-g.generatedLine,v!==0)?v:R(m.name,g.name)}e.compareByOriginalPositions=w;function A(m,g,S){let v=m.generatedLine-g.generatedLine;return v!==0||(v=m.generatedColumn-g.generatedColumn,v!==0||S)||(v=R(m.source,g.source),v!==0)||(v=m.originalLine-g.originalLine,v!==0)||(v=m.originalColumn-g.originalColumn,v!==0)?v:R(m.name,g.name)}e.compareByGeneratedPositionsDeflated=A;function R(m,g){return m===g?0:m===null?1:g===null?-1:m>g?1:-1}function y(m,g){let S=m.generatedLine-g.generatedLine;return S!==0||(S=m.generatedColumn-g.generatedColumn,S!==0)||(S=R(m.source,g.source),S!==0)||(S=m.originalLine-g.originalLine,S!==0)||(S=m.originalColumn-g.originalColumn,S!==0)?S:R(m.name,g.name)}e.compareByGeneratedPositionsInflated=y;function N(m){return JSON.parse(m.replace(/^\)]}'[^\n]*\n/,""))}e.parseSourceMapInput=N;function T(m,g,S){if(g=g||"",m&&(m[m.length-1]!=="/"&&g[0]!=="/"&&(m+="/"),g=m+g),S){const v=s(S);if(!v)throw new Error("sourceMapURL could not be parsed");if(v.path){const j=v.path.lastIndexOf("/");j>=0&&(v.path=v.path.substring(0,j+1))}g=l(i(v),g)}return c(g)}e.computeSourceURL=T})(Zr);var xa={};let KR=class ig{constructor(){this._array=[],this._set=new Map}static fromArray(t,n){const r=new ig;for(let s=0,i=t.length;s=0)return n;throw new Error('"'+t+'" is not in the set.')}at(t){if(t>=0&&tn||r==n&&i>=s||Df.compareByGeneratedPositionsInflated(e,t)<=0}let jR=class{constructor(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}unsortedForEach(t,n){this._array.forEach(t,n)}add(t){WR(this._last,t)?(this._last=t,this._array.push(t)):(this._sorted=!1,this._array.push(t))}toArray(){return this._sorted||(this._array.sort(Df.compareByGeneratedPositionsInflated),this._sorted=!0),this._array}};Pf.MappingList=jR;const ts=kf,at=Zr,yi=xa.ArraySet,HR=Pf.MappingList;let Ff=class og{constructor(t){t||(t={}),this._file=at.getArg(t,"file",null),this._sourceRoot=at.getArg(t,"sourceRoot",null),this._skipValidation=at.getArg(t,"skipValidation",!1),this._sources=new yi,this._names=new yi,this._mappings=new HR,this._sourcesContents=null}static fromSourceMap(t){const n=t.sourceRoot,r=new og({file:t.file,sourceRoot:n});return t.eachMapping(function(s){const i={generated:{line:s.generatedLine,column:s.generatedColumn}};s.source!=null&&(i.source=s.source,n!=null&&(i.source=at.relative(n,i.source)),i.original={line:s.originalLine,column:s.originalColumn},s.name!=null&&(i.name=s.name)),r.addMapping(i)}),t.sources.forEach(function(s){let i=s;n!==null&&(i=at.relative(n,s)),r._sources.has(i)||r._sources.add(i);const o=t.sourceContentFor(s);o!=null&&r.setSourceContent(s,o)}),r}addMapping(t){const n=at.getArg(t,"generated"),r=at.getArg(t,"original",null);let s=at.getArg(t,"source",null),i=at.getArg(t,"name",null);this._skipValidation||this._validateMapping(n,r,s,i),s!=null&&(s=String(s),this._sources.has(s)||this._sources.add(s)),i!=null&&(i=String(i),this._names.has(i)||this._names.add(i)),this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:r!=null&&r.line,originalColumn:r!=null&&r.column,source:s,name:i})}setSourceContent(t,n){let r=t;this._sourceRoot!=null&&(r=at.relative(this._sourceRoot,r)),n!=null?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[at.toSetString(r)]=n):this._sourcesContents&&(delete this._sourcesContents[at.toSetString(r)],Object.keys(this._sourcesContents).length===0&&(this._sourcesContents=null))}applySourceMap(t,n,r){let s=n;if(n==null){if(t.file==null)throw new Error(`SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.`);s=t.file}const i=this._sourceRoot;i!=null&&(s=at.relative(i,s));const o=this._mappings.toArray().length>0?new yi:this._sources,a=new yi;this._mappings.unsortedForEach(function(c){if(c.source===s&&c.originalLine!=null){const h=t.originalPositionFor({line:c.originalLine,column:c.originalColumn});h.source!=null&&(c.source=h.source,r!=null&&(c.source=at.join(r,c.source)),i!=null&&(c.source=at.relative(i,c.source)),c.originalLine=h.line,c.originalColumn=h.column,h.name!=null&&(c.name=h.name))}const l=c.source;l!=null&&!o.has(l)&&o.add(l);const u=c.name;u!=null&&!a.has(u)&&a.add(u)},this),this._sources=o,this._names=a,t.sources.forEach(function(c){const l=t.sourceContentFor(c);l!=null&&(r!=null&&(c=at.join(r,c)),i!=null&&(c=at.relative(i,c)),this.setSourceContent(c,l))},this)}_validateMapping(t,n,r,s){if(n&&typeof n.line!="number"&&typeof n.column!="number")throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if(!(t&&"line"in t&&"column"in t&&t.line>0&&t.column>=0&&!n&&!r&&!s)){if(!(t&&"line"in t&&"column"in t&&n&&"line"in n&&"column"in n&&t.line>0&&t.column>=0&&n.line>0&&n.column>=0&&r))throw new Error("Invalid mapping: "+JSON.stringify({generated:t,source:r,original:n,name:s}))}}_serializeMappings(){let t=0,n=1,r=0,s=0,i=0,o=0,a="",c,l,u,h;const d=this._mappings.toArray();for(let f=0,p=d.length;f0){if(!at.compareByGeneratedPositionsInflated(l,d[f-1]))continue;c+=","}c+=ts.encode(l.generatedColumn-t),t=l.generatedColumn,l.source!=null&&(h=this._sources.indexOf(l.source),c+=ts.encode(h-o),o=h,c+=ts.encode(l.originalLine-1-s),s=l.originalLine-1,c+=ts.encode(l.originalColumn-r),r=l.originalColumn,l.name!=null&&(u=this._names.indexOf(l.name),c+=ts.encode(u-i),i=u)),a+=c}return a}_generateSourcesContent(t,n){return t.map(function(r){if(!this._sourcesContents)return null;n!=null&&(r=at.relative(n,r));const s=at.toSetString(r);return Object.prototype.hasOwnProperty.call(this._sourcesContents,s)?this._sourcesContents[s]:null},this)}toJSON(){const t={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return this._file!=null&&(t.file=this._file),this._sourceRoot!=null&&(t.sourceRoot=this._sourceRoot),this._sourcesContents&&(t.sourcesContent=this._generateSourcesContent(t.sources,t.sourceRoot)),t}toString(){return JSON.stringify(this.toJSON())}};Ff.prototype._version=3,Of.SourceMapGenerator=Ff;var $f={};(function(e){e.GREATEST_LOWER_BOUND=1,e.LEAST_UPPER_BOUND=2;function t(n,r,s,i,o,a){const c=Math.floor((r-n)/2)+n,l=o(s,i[c],!0);return l===0?c:l>0?r-c>1?t(c,r,s,i,o,a):a==e.LEAST_UPPER_BOUND?r1?t(n,c,s,i,o,a):a==e.LEAST_UPPER_BOUND?c:n<0?-1:n}e.search=function(r,s,i,o){if(s.length===0)return-1;let a=t(-1,s.length,r,s,i,o||e.GREATEST_LOWER_BOUND);if(a<0)return-1;for(;a-1>=0&&i(s[a],s[a-1],!0)===0;)--a;return a}})($f);var es={exports:{}},VR={},YR=Object.freeze({__proto__:null,default:VR}),Bf=fg(YR);if((function(){return typeof window<"u"&&this===window}).call()){let e=null;es.exports=function(){if(typeof e=="string")return fetch(e).then(n=>n.arrayBuffer());if(e instanceof ArrayBuffer)return Promise.resolve(e);throw new Error("You must provide the string URL or ArrayBuffer contents of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer")},es.exports.initialize=t=>e=t}else{const e=Bf,t=Bf;es.exports=function(){return new Promise((r,s)=>{const i=t.join(__dirname,"mappings.wasm");e.readFile(i,null,(o,a)=>{if(o){s(o);return}r(a.buffer)})})},es.exports.initialize=n=>{console.debug("SourceMapConsumer.initialize is a no-op when running in node.js")}}var Gf=es.exports;const zR=Gf;function qR(){this.generatedLine=0,this.generatedColumn=0,this.lastGeneratedColumn=null,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null}let ns=null;var XR=function(){if(ns)return ns;const t=[];return ns=zR().then(n=>WebAssembly.instantiate(n,{env:{mapping_callback(r,s,i,o,a,c,l,u,h,d){const f=new qR;f.generatedLine=r+1,f.generatedColumn=s,i&&(f.lastGeneratedColumn=o-1),a&&(f.source=c,f.originalLine=l+1,f.originalColumn=u,h&&(f.name=d)),t[t.length-1](f)},start_all_generated_locations_for(){console.time("all_generated_locations_for")},end_all_generated_locations_for(){console.timeEnd("all_generated_locations_for")},start_compute_column_spans(){console.time("compute_column_spans")},end_compute_column_spans(){console.timeEnd("compute_column_spans")},start_generated_location_for(){console.time("generated_location_for")},end_generated_location_for(){console.timeEnd("generated_location_for")},start_original_location_for(){console.time("original_location_for")},end_original_location_for(){console.timeEnd("original_location_for")},start_parse_mappings(){console.time("parse_mappings")},end_parse_mappings(){console.timeEnd("parse_mappings")},start_sort_by_generated_location(){console.time("sort_by_generated_location")},end_sort_by_generated_location(){console.timeEnd("sort_by_generated_location")},start_sort_by_original_location(){console.time("sort_by_original_location")},end_sort_by_original_location(){console.timeEnd("sort_by_original_location")}}})).then(n=>({exports:n.instance.exports,withMappingCallback:(r,s)=>{t.push(r);try{s()}finally{t.pop()}}})).then(null,n=>{throw ns=null,n}),ns};const O=Zr,Ua=$f,Ti=xa.ArraySet,JR=Gf,QR=XR,Pa=Symbol("smcInternal");class st{constructor(t,n){return t==Pa?Promise.resolve(this):tv(t,n)}static initialize(t){JR.initialize(t["lib/mappings.wasm"])}static fromSourceMap(t,n){return ev(t,n)}static async with(t,n,r){const s=await new st(t,n);try{return await r(s)}finally{s.destroy()}}_parseMappings(t,n){throw new Error("Subclasses must implement _parseMappings")}eachMapping(t,n,r){throw new Error("Subclasses must implement eachMapping")}allGeneratedPositionsFor(t){throw new Error("Subclasses must implement allGeneratedPositionsFor")}destroy(){throw new Error("Subclasses must implement destroy")}}st.prototype._version=3,st.GENERATED_ORDER=1,st.ORIGINAL_ORDER=2,st.GREATEST_LOWER_BOUND=1,st.LEAST_UPPER_BOUND=2;class rs extends st{constructor(t,n){return super(Pa).then(r=>{let s=t;typeof t=="string"&&(s=O.parseSourceMapInput(t));const i=O.getArg(s,"version");let o=O.getArg(s,"sources");const a=O.getArg(s,"names",[]);let c=O.getArg(s,"sourceRoot",null);const l=O.getArg(s,"sourcesContent",null),u=O.getArg(s,"mappings"),h=O.getArg(s,"file",null);if(i!=r._version)throw new Error("Unsupported version: "+i);return c&&(c=O.normalize(c)),o=o.map(String).map(O.normalize).map(function(d){return c&&O.isAbsolute(c)&&O.isAbsolute(d)?O.relative(c,d):d}),r._names=Ti.fromArray(a.map(String),!0),r._sources=Ti.fromArray(o,!0),r._absoluteSources=r._sources.toArray().map(function(d){return O.computeSourceURL(c,d,n)}),r.sourceRoot=c,r.sourcesContent=l,r._mappings=u,r._sourceMapURL=n,r.file=h,r._computedColumnSpans=!1,r._mappingsPtr=0,r._wasm=null,QR().then(d=>(r._wasm=d,r))})}_findSourceIndex(t){let n=t;if(this.sourceRoot!=null&&(n=O.relative(this.sourceRoot,n)),this._sources.has(n))return this._sources.indexOf(n);for(let r=0;r{a.source!==null&&(a.source=this._sources.at(a.source),a.source=O.computeSourceURL(o,a.source,this._sourceMapURL),a.name!==null&&(a.name=this._names.at(a.name))),t.call(s,a)},()=>{switch(i){case st.GENERATED_ORDER:this._wasm.exports.by_generated_location(this._getMappingsPtr());break;case st.ORIGINAL_ORDER:this._wasm.exports.by_original_location(this._getMappingsPtr());break;default:throw new Error("Unknown order of iteration.")}})}allGeneratedPositionsFor(t){let n=O.getArg(t,"source");const r=O.getArg(t,"line"),s=t.column||0;if(n=this._findSourceIndex(n),n<0)return[];if(r<1)throw new Error("Line numbers must be >= 1");if(s<0)throw new Error("Column numbers must be >= 0");const i=[];return this._wasm.withMappingCallback(o=>{let a=o.lastGeneratedColumn;this._computedColumnSpans&&a===null&&(a=1/0),i.push({line:o.generatedLine,column:o.generatedColumn,lastColumn:a})},()=>{this._wasm.exports.all_generated_locations_for(this._getMappingsPtr(),n,r-1,"column"in t,s)}),i}destroy(){this._mappingsPtr!==0&&(this._wasm.exports.free_mappings(this._mappingsPtr),this._mappingsPtr=0)}computeColumnSpans(){this._computedColumnSpans||(this._wasm.exports.compute_column_spans(this._getMappingsPtr()),this._computedColumnSpans=!0)}originalPositionFor(t){const n={generatedLine:O.getArg(t,"line"),generatedColumn:O.getArg(t,"column")};if(n.generatedLine<1)throw new Error("Line numbers must be >= 1");if(n.generatedColumn<0)throw new Error("Column numbers must be >= 0");let r=O.getArg(t,"bias",st.GREATEST_LOWER_BOUND);r==null&&(r=st.GREATEST_LOWER_BOUND);let s;if(this._wasm.withMappingCallback(i=>s=i,()=>{this._wasm.exports.original_location_for(this._getMappingsPtr(),n.generatedLine-1,n.generatedColumn,r)}),s&&s.generatedLine===n.generatedLine){let i=O.getArg(s,"source",null);i!==null&&(i=this._sources.at(i),i=O.computeSourceURL(this.sourceRoot,i,this._sourceMapURL));let o=O.getArg(s,"name",null);return o!==null&&(o=this._names.at(o)),{source:i,line:O.getArg(s,"originalLine",null),column:O.getArg(s,"originalColumn",null),name:o}}return{source:null,line:null,column:null,name:null}}hasContentsOfAllSources(){return this.sourcesContent?this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(t){return t==null}):!1}sourceContentFor(t,n){if(!this.sourcesContent)return null;const r=this._findSourceIndex(t);if(r>=0)return this.sourcesContent[r];let s=t;this.sourceRoot!=null&&(s=O.relative(this.sourceRoot,s));let i;if(this.sourceRoot!=null&&(i=O.urlParse(this.sourceRoot))){const o=s.replace(/^file:\/\//,"");if(i.scheme=="file"&&this._sources.has(o))return this.sourcesContent[this._sources.indexOf(o)];if((!i.path||i.path=="/")&&this._sources.has("/"+s))return this.sourcesContent[this._sources.indexOf("/"+s)]}if(n)return null;throw new Error('"'+s+'" is not in the SourceMap.')}generatedPositionFor(t){let n=O.getArg(t,"source");if(n=this._findSourceIndex(n),n<0)return{line:null,column:null,lastColumn:null};const r={source:n,originalLine:O.getArg(t,"line"),originalColumn:O.getArg(t,"column")};if(r.originalLine<1)throw new Error("Line numbers must be >= 1");if(r.originalColumn<0)throw new Error("Column numbers must be >= 0");let s=O.getArg(t,"bias",st.GREATEST_LOWER_BOUND);s==null&&(s=st.GREATEST_LOWER_BOUND);let i;if(this._wasm.withMappingCallback(o=>i=o,()=>{this._wasm.exports.generated_location_for(this._getMappingsPtr(),r.source,r.originalLine-1,r.originalColumn,s)}),i&&i.source===r.source){let o=i.lastGeneratedColumn;return this._computedColumnSpans&&o===null&&(o=1/0),{line:O.getArg(i,"generatedLine",null),column:O.getArg(i,"generatedColumn",null),lastColumn:o}}return{line:null,column:null,lastColumn:null}}}rs.prototype.consumer=st;class ZR extends st{constructor(t,n){return super(Pa).then(r=>{let s=t;typeof t=="string"&&(s=O.parseSourceMapInput(t));const i=O.getArg(s,"version"),o=O.getArg(s,"sections");if(i!=r._version)throw new Error("Unsupported version: "+i);r._sources=new Ti,r._names=new Ti,r.__generatedMappings=null,r.__originalMappings=null,r.__generatedMappingsUnsorted=null,r.__originalMappingsUnsorted=null;let a={line:-1,column:0};return Promise.all(o.map(c=>{if(c.url)throw new Error("Support for url field in sections not implemented.");const l=O.getArg(c,"offset"),u=O.getArg(l,"line"),h=O.getArg(l,"column");if(u({generatedOffset:{generatedLine:u+1,generatedColumn:h+1},consumer:f}))})).then(c=>(r._sections=c,r))})}get _generatedMappings(){return this.__generatedMappings||this._sortGeneratedMappings(),this.__generatedMappings}get _originalMappings(){return this.__originalMappings||this._sortOriginalMappings(),this.__originalMappings}get _generatedMappingsUnsorted(){return this.__generatedMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__generatedMappingsUnsorted}get _originalMappingsUnsorted(){return this.__originalMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__originalMappingsUnsorted}_sortGeneratedMappings(){const t=this._generatedMappingsUnsorted;t.sort(O.compareByGeneratedPositionsDeflated),this.__generatedMappings=t}_sortOriginalMappings(){const t=this._originalMappingsUnsorted;t.sort(O.compareByOriginalPositions),this.__originalMappings=t}get sources(){const t=[];for(let n=0;na.push(c));for(let c=0;c= 1");if(r.originalColumn<0)throw new Error("Column numbers must be >= 0");const s=[];let i=this._findMapping(r,this._originalMappings,"originalLine","originalColumn",O.compareByOriginalPositions,Ua.LEAST_UPPER_BOUND);if(i>=0){let o=this._originalMappings[i];if(t.column===void 0){const a=o.originalLine;for(;o&&o.originalLine===a;){let c=o.lastGeneratedColumn;this._computedColumnSpans&&c===null&&(c=1/0),s.push({line:O.getArg(o,"generatedLine",null),column:O.getArg(o,"generatedColumn",null),lastColumn:c}),o=this._originalMappings[++i]}}else{const a=o.originalColumn;for(;o&&o.originalLine===n&&o.originalColumn==a;){let c=o.lastGeneratedColumn;this._computedColumnSpans&&c===null&&(c=1/0),s.push({line:O.getArg(o,"generatedLine",null),column:O.getArg(o,"generatedColumn",null),lastColumn:c}),o=this._originalMappings[++i]}}}return s}destroy(){for(let t=0;t=0;n--)this.prepend(t[n]);else if(t[ir]||typeof t=="string")this.children.unshift(t);else throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+t);return this}walk(t){let n;for(let r=0,s=this.children.length;r0){for(n=[],r=0;rString.fromCharCode(e)),Rv=x({name:"Whitespace",pattern:/ +/}),vv=x({name:"WhitespaceSkipped",pattern:/ +/,group:gt.SKIPPED}),td=x({name:"StringLiteral",pattern:/[^ $]+/,start_chars_hint:wv}),ed=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),Ka=x({name:"MaybeFlag",pattern:/\$[^ $]+/}),nd=x({name:"NumberLiteral",pattern:/\$-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?\+?/}),rd=x({name:"ContinueLine",pattern:/\\/});function sd(e,t=""){return x({name:t||e,pattern:new RegExp(e.toLowerCase(),"i")})}const id=[["blue"],["green"],["cyan"],["red"],["purple"],["yellow"],["white"],["dkblue"],["dkgreen"],["dkcyan"],["dkred"],["dkpurple"],["dkyellow|brown","brown"],["dkwhite|ltgray|ltgrey|gray|grey","gray"],["dkgray|dkgrey|ltblack","dkgray"],["black"],["clear"]],od=id.map(([e,t])=>sd(`\\$(${e})`,t||e)),ad=[...id.map(([e,t])=>sd(`\\$on(${e})`,`on${t||e}`))],Nv=[Rv,rd,...od,...ad,ed,td,nd,Ka],Cv=new gt(Nv,{skipValidations:!we,ensureOptimizations:we}),Iv=new gt([vv,rd,...od,...ad,ed,td,nd,Ka],{skipValidations:!we,ensureOptimizations:we});function Lv(e,t=!1){return t?Iv.tokenize(e):Cv.tokenize(e)}function Ov(e,t,n,r){return{measureOnly:!1,resetCheck:!0,x:0,y:0,isEven:!0,resetColor:n,resetBg:r,activeColor:n,activeBg:r,width:e,height:t,leftEdge:void 0,rightEdge:void 0,bottomEdge:void 0,char:[],color:[],bg:[]}}Av.createContext(Ov(1,1,15,1));let kv=0,cd=0;const ld=we,bv=["Command","lines"];class Mv extends oR{constructor(){super(Kh,{traceInitPerf:we,skipValidations:!we,maxLookahead:2,recoveryEnabled:!0,nodeLocationTracking:"full"});U(this,"program",this.RULED("program",()=>{this.MANY(()=>this.SUBRULE(this.line))}));U(this,"line",this.RULED("line",()=>{this.OPTION(()=>this.SUBRULE(this.stmt)),this.AT_LEAST_ONE(()=>this.CONSUME(Xr))}));U(this,"stmt",this.RULED("stmt",()=>{this.OR([{ALT:()=>this.SUBRULE(this.stat)},{ALT:()=>this.SUBRULE(this.text)},{ALT:()=>this.SUBRULE(this.label)},{ALT:()=>this.SUBRULE(this.comment)},{ALT:()=>this.SUBRULE(this.commands)}])}));U(this,"stat",this.RULED("stat",()=>{this.CONSUME(ga)}));U(this,"text",this.RULED("text",()=>{this.CONSUME(hh)}));U(this,"label",this.RULED("label",()=>{this.CONSUME(dh)}));U(this,"comment",this.RULED("comment",()=>{this.CONSUME(fh)}));U(this,"commands",this.RULED("commands",()=>{this.OR([{ALT:()=>{this.CONSUME(he),this.AT_LEAST_ONE1(()=>this.SUBRULE1(this.command))}},{ALT:()=>{this.AT_LEAST_ONE2(()=>this.SUBRULE2(this.command))}}])}));U(this,"command",this.RULED("command",()=>{this.OR([{ALT:()=>this.SUBRULE(this.flat_cmd)},{ALT:()=>this.SUBRULE(this.structured_cmd)}])}));U(this,"flat_cmd",this.RULED("flat_cmd",()=>{this.OR([{ALT:()=>this.SUBRULE(this.words)},{ALT:()=>this.SUBRULE(this.hyperlink)},{ALT:()=>this.SUBRULE(this.Short_go)},{ALT:()=>this.SUBRULE(this.Short_try)},{ALT:()=>this.SUBRULE(this.Command_play)}])}));U(this,"structured_cmd",this.RULED("structured_cmd",()=>{this.OR([{ALT:()=>this.SUBRULE(this.Command_if)},{ALT:()=>this.SUBRULE(this.Command_read)},{ALT:()=>this.SUBRULE(this.Command_while)},{ALT:()=>this.SUBRULE(this.Command_repeat)},{ALT:()=>this.SUBRULE(this.Command_break)},{ALT:()=>this.SUBRULE(this.Command_continue)}])}));U(this,"hyperlink",this.RULED("hyperlink",()=>{this.CONSUME(ph),this.SUBRULE(this.words),this.CONSUME(gh)}));U(this,"Short_go",this.RULED("Short_go",()=>{this.CONSUME(Sa),this.SUBRULE(this.words)}));U(this,"Short_try",this.RULED("Short_try",()=>{this.CONSUME(Ih),this.SUBRULE(this.words)}));U(this,"Command_play",this.RULED("Command_play",()=>{this.CONSUME(kh)}));U(this,"do_line",this.RULED("do_line",()=>{this.OPTION(()=>this.SUBRULE(this.do_stmt)),this.AT_LEAST_ONE(()=>this.CONSUME(Xr))}));U(this,"do_stmt",this.RULED("do_stmt",()=>{this.OR([{ALT:()=>this.SUBRULE(this.text)},{ALT:()=>this.SUBRULE(this.comment)},{ALT:()=>this.SUBRULE(this.commands)}])}));U(this,"Command_if",this.RULED("Command_if",()=>{this.CONSUME(Aa),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.OR2([{GATE:this.BACKTRACK(this.Command_else_if),ALT:()=>this.SUBRULE(this.Command_else_if)},{GATE:this.BACKTRACK(this.Command_else),ALT:()=>this.SUBRULE(this.Command_else)},{GATE:this.BACKTRACK(this.Command_endif),ALT:()=>this.SUBRULE(this.Command_endif)}])}}])})}));U(this,"Command_else_if",this.RULED("Command_else_if",()=>{this.CONSUME(he),this.CONSUME(wa),this.CONSUME(Aa),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.OR2([{GATE:this.BACKTRACK(this.Command_else_if),ALT:()=>this.SUBRULE(this.Command_else_if)},{GATE:this.BACKTRACK(this.Command_else),ALT:()=>this.SUBRULE(this.Command_else)},{GATE:this.BACKTRACK(this.Command_endif),ALT:()=>this.SUBRULE(this.Command_endif)}])}}])})}));U(this,"Command_else",this.RULED("Command_else",()=>{this.CONSUME(he),this.CONSUME(wa),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.SUBRULE(this.Command_endif)}}])})}));U(this,"Command_endif",this.RULED("Command_endif",()=>{this.CONSUME(he),this.CONSUME(bh)}));U(this,"Command_while",this.RULED("Command_while",()=>{this.CONSUME(he),this.CONSUME(Mh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(he),this.CONSUME4(xh)}}])})}));U(this,"Command_repeat",this.RULED("Command_repeat",()=>{this.CONSUME(he),this.CONSUME(Uh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(he),this.CONSUME4(Ph)}}])})}));U(this,"Command_read",this.RULED("Command_read",()=>{this.CONSUME(he),this.CONSUME(Dh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(he),this.CONSUME4(Fh)}}])})}));U(this,"Command_break",this.RULED("Command_break",()=>{this.CONSUME($h)}));U(this,"Command_continue",this.RULED("Command_continue",()=>{this.CONSUME(Bh)}));U(this,"expr",this.RULED("expr",()=>{this.SUBRULE1(this.and_test),this.MANY(()=>{this.CONSUME(ma),this.SUBRULE2(this.and_test)})}));U(this,"and_test",this.RULED("and_test",()=>{this.SUBRULE1(this.not_test),this.MANY(()=>{this.CONSUME(_a),this.SUBRULE2(this.not_test)})}));U(this,"not_test",this.RULED("not_test",()=>{this.OR([{ALT:()=>{this.CONSUME(Ea),this.SUBRULE1(this.not_test)}},{ALT:()=>this.SUBRULE2(this.comparison)}])}));U(this,"comparison",this.RULED("comparison",()=>{this.SUBRULE1(this.arith_expr),this.MANY(()=>{this.SUBRULE(this.comp_op),this.SUBRULE2(this.arith_expr)})}));U(this,"comp_op",this.RULED("comp_op",()=>{this.OR([{ALT:()=>this.CONSUME(_h)},{ALT:()=>this.CONSUME(yh)},{ALT:()=>this.CONSUME(Th)},{ALT:()=>this.CONSUME(Sh)},{ALT:()=>this.CONSUME(Ah)},{ALT:()=>this.CONSUME(wh)}])}));U(this,"expr_value",this.RULED("expr_value",()=>{this.SUBRULE1(this.and_test_value),this.MANY(()=>{this.CONSUME(ma),this.SUBRULE2(this.and_test_value)})}));U(this,"and_test_value",this.RULED("and_test_value",()=>{this.SUBRULE1(this.not_test_value),this.MANY(()=>{this.CONSUME(_a),this.SUBRULE2(this.not_test_value)})}));U(this,"not_test_value",this.RULED("not_test_value",()=>{this.OR([{ALT:()=>{this.CONSUME(Ea),this.SUBRULE1(this.not_test_value)}},{ALT:()=>this.SUBRULE2(this.arith_expr)}])}));U(this,"arith_expr",this.RULED("arith_expr",()=>{this.SUBRULE1(this.term),this.MANY(()=>this.SUBRULE2(this.arith_expr_item))}));U(this,"arith_expr_item",this.RULED("arith_expr_item",()=>{this.OR([{ALT:()=>this.CONSUME(ya)},{ALT:()=>this.CONSUME(Ta)}]),this.SUBRULE(this.term)}));U(this,"term",this.RULED("term",()=>{this.SUBRULE1(this.factor),this.MANY(()=>this.SUBRULE2(this.term_item))}));U(this,"term_item",this.RULED("term_item",()=>{this.OR([{ALT:()=>this.CONSUME(vh)},{ALT:()=>this.CONSUME(Sa)},{ALT:()=>this.CONSUME(Nh)},{ALT:()=>this.CONSUME(Ch)}]),this.SUBRULE(this.factor)}));U(this,"factor",this.RULED("factor",()=>{this.OR1([{ALT:()=>{this.OR2([{ALT:()=>this.CONSUME(ya)},{ALT:()=>this.CONSUME(Ta)}]),this.SUBRULE(this.factor)}},{ALT:()=>this.SUBRULE(this.power)}])}));U(this,"power",this.RULED("power",()=>{this.SUBRULE(this.token),this.OPTION(()=>{this.CONSUME(Rh),this.SUBRULE(this.factor)})}));U(this,"words",this.RULED("words",()=>{this.AT_LEAST_ONE(()=>this.SUBRULE(this.expr))}));U(this,"token",this.RULED("token",()=>{this.OR([{ALT:()=>this.CONSUME(mh)},{ALT:()=>this.CONSUME(Wt)},{ALT:()=>this.CONSUME(Eh)},{ALT:()=>{this.CONSUME(Lh),this.SUBRULE(this.expr),this.CONSUME(Oh)}}])}));this.performSelfAnalysis()}PEEK(n,r,...s){console.info(n,s.map(i=>[i.image,i.tokenType]),r)}RULED(n,r,s){const i=bv.some(o=>n.includes(o));return this.RULE(n,()=>{const o=kv++,a=cd++,c=a.toString().padStart(3),l=" ".repeat(a),u=i?"font-weight: bold;":"";if(ld&&!this.RECORDING_PHASE){const d=[this.LA(0),this.LA(1),this.LA(2)].map(f=>[`[${f.tokenType.name}]`,f.image.replaceAll(` +`,"\\n")]).flat();console.info(`${c}%c${l}> ${n} ${o} ${d.join(" ")}`,u)}r(),ld&&!this.RECORDING_PHASE&&console.info(`${c}%c${l}< ${n} ${o}`,u),cd--},s)}}const is=new Mv,xv=is.getBaseCstVisitorConstructor();var q=(e=>(e[e.PROGRAM=0]="PROGRAM",e[e.TEXT=1]="TEXT",e[e.LABEL=2]="LABEL",e[e.HYPERLINK=3]="HYPERLINK",e[e.STAT=4]="STAT",e[e.MOVE=5]="MOVE",e[e.COMMAND=6]="COMMAND",e[e.LITERAL=7]="LITERAL",e[e.IF=8]="IF",e[e.ELSE_IF=9]="ELSE_IF",e[e.ELSE=10]="ELSE",e[e.WHILE=11]="WHILE",e[e.BREAK=12]="BREAK",e[e.CONTINUE=13]="CONTINUE",e[e.REPEAT=14]="REPEAT",e[e.READ=15]="READ",e[e.OR=16]="OR",e[e.AND=17]="AND",e[e.NOT=18]="NOT",e[e.COMPARE=19]="COMPARE",e[e.OPERATOR=20]="OPERATOR",e[e.OPERATOR_ITEM=21]="OPERATOR_ITEM",e[e.EXPR=22]="EXPR",e))(q||{}),kn=(e=>(e[e.IS_EQ=0]="IS_EQ",e[e.IS_NOT_EQ=1]="IS_NOT_EQ",e[e.IS_LESS_THAN=2]="IS_LESS_THAN",e[e.IS_GREATER_THAN=3]="IS_GREATER_THAN",e[e.IS_LESS_THAN_OR_EQ=4]="IS_LESS_THAN_OR_EQ",e[e.IS_GREATER_THAN_OR_EQ=5]="IS_GREATER_THAN_OR_EQ",e))(kn||{}),ve=(e=>(e[e.EMPTY=0]="EMPTY",e[e.PLUS=1]="PLUS",e[e.MINUS=2]="MINUS",e[e.POWER=3]="POWER",e[e.MULTIPLY=4]="MULTIPLY",e[e.DIVIDE=5]="DIVIDE",e[e.MOD_DIVIDE=6]="MOD_DIVIDE",e[e.FLOOR_DIVIDE=7]="FLOOR_DIVIDE",e[e.UNI_PLUS=8]="UNI_PLUS",e[e.UNI_MINUS=9]="UNI_MINUS",e))(ve||{}),vi=(e=>(e[e.NUMBER=0]="NUMBER",e[e.STRING=1]="STRING",e[e.TEMPLATE=2]="TEMPLATE",e))(vi||{});function iL(e){return e}function it(e,t){return((t==null?void 0:t.map(n=>e.visit(n)).filter(n=>n))||[]).flat()}function an(e){return e.image}function ud(e,t){return F(e,{type:7,literal:1,value:t})}function Uv(e){return!!(e!=null&&e.tokenType)}function Pv(e){const t=Object.values(e).flat().filter(n=>!!n).map(n=>n&&Uv(n)?{startLine:n.startLine,startColumn:n.startColumn,startOffset:n.startOffset,endLine:n.endLine,endColumn:n.endColumn,endOffset:n.endOffset}:n!=null&&n.location?{...n.location}:{startLine:0,startColumn:0,startOffset:0,endLine:0,endColumn:0,endOffset:0}).filter(n=>n.startLine!==0&&n.endLine!==0);return{startLine:Math.min(...t.map(n=>n.startLine||1)),startColumn:Math.min(...t.map(n=>n.startColumn||1)),startOffset:Math.min(...t.map(n=>n.startOffset||1)),endLine:Math.max(...t.map(n=>n.endLine||1)),endColumn:Math.max(...t.map(n=>n.endColumn||1)),endOffset:Math.max(...t.map(n=>n.endOffset||1))}}function F(e,t){return{...t,...Pv(e)}}class Dv extends xv{constructor(){super(),we&&this.validateVisitor()}program(t){return F(t,{type:0,lines:it(this,t.line)})}line(t){if(t.stmt)return this.visit(t.stmt)}stmt(t){if(t.stat)return this.visit(t.stat);if(t.text)return this.visit(t.text);if(t.label)return this.visit(t.label);if(t.comment)return this.visit(t.comment);if(t.commands)return this.visit(t.commands)}stat(){}text(t){if(t.Text)return F(t,{type:1,value:an(t.Text[0])})}label(t){var n;return F(t,{type:2,active:!0,name:an(((n=t.Label)==null?void 0:n[0])??":").slice(1).trim()})}comment(t){return F(t,{type:2,active:!1,name:an(t.Comment[0]).slice(1).trim()})}commands(t){return it(this,t.command)}command(t){if(t.flat_cmd)return this.visit(t.flat_cmd);if(t.structured_cmd)return this.visit(t.structured_cmd)}flat_cmd(t){if(t.words)return F(t,{type:6,words:it(this,t.words).flat()});if(t.hyperlink)return this.visit(t.hyperlink);if(t.Short_go)return this.visit(t.Short_go);if(t.Short_try)return this.visit(t.Short_try);if(t.Command_play)return this.visit(t.Command_play)}structured_cmd(t){if(t.Command_if)return this.visit(t.Command_if);if(t.Command_read)return this.visit(t.Command_read);if(t.Command_while)return this.visit(t.Command_while);if(t.Command_repeat)return this.visit(t.Command_repeat);if(t.Command_break)return this.visit(t.Command_break);if(t.Command_continue)return this.visit(t.Command_continue)}hyperlink(t){var n;return F(t,{type:3,link:it(this,t.words).flat(),text:an(((n=t.HyperLinkText)==null?void 0:n[0])??";").slice(1)})}Short_go(t){if(t.Divide)return F(t,{type:5,wait:!0,words:it(this,t.words).flat()})}Short_try(t){if(t.Query)return F(t,{type:5,wait:!1,words:it(this,t.words).flat()})}Command_play(t){if(t.Command_play)return F(t,{type:6,words:[ud(t,"play"),ud(t,an(t.Command_play[0]).replace("#play","").trim())]})}do_line(t){return this.visit(t.do_stmt)}do_stmt(t){if(t.text)return this.visit(t.text);if(t.comment)return this.visit(t.comment);if(t.commands)return this.visit(t.commands)}Command_if(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat(),s=[this.visit(t.Command_else_if),this.visit(t.Command_else)].flat();return F(t,{type:8,method:"if",words:n.filter(_),lines:r.filter(_),branches:s.filter(_)})}Command_else_if(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat(),s=it(this,t.Command_else_if).flat();return[F(t,{type:9,method:"if",words:n.filter(_),lines:r.filter(_)}),...s.filter(_),this.visit(t.Command_else)]}Command_else(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat();return F(t,{type:10,method:"if",words:n.filter(_),lines:r.filter(_)})}Command_endif(){}Command_while(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat();return F(t,{type:11,words:n.filter(_),lines:r.filter(_)})}Command_repeat(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat();return F(t,{type:14,words:n.filter(_),lines:r.filter(_)})}Command_read(t){const n=it(this,t.words).flat(),r=[this.visit(t.command),...it(this,t.do_line)].flat();return F(t,{type:15,words:n.filter(_),lines:r.filter(_)})}Command_break(t){return F(t,{type:12})}Command_continue(t){return F(t,{type:13})}expr(t){return t.and_test.length===1?this.visit(t.and_test):F(t,{type:16,items:this.visit(t.and_test)})}and_test(t){return t.not_test.length===1?this.visit(t.not_test):F(t,{type:17,items:this.visit(t.not_test)})}not_test(t){if(t.comparison)return this.visit(t.comparison);if(t.not_test)return F(t,{type:18,items:this.visit(t.not_test)})}comparison(t){return t.arith_expr.length===1?this.visit(t.arith_expr):F(t,{type:19,lhs:this.visit(t.arith_expr[0]),compare:this.visit(t.comp_op),rhs:this.visit(t.arith_expr[1])})}comp_op(t){if(t.is||t.IsEq)return 0;if(t.IsNotEq)return 1;if(t.IsLessThan)return 2;if(t.IsGreaterThan)return 3;if(t.IsLessThanOrEqual)return 4;if(t.IsGreaterThanOrEqual)return 5}expr_value(t){return t.and_test_value.length===1?this.visit(t.and_test_value):F(t,{type:16,items:this.visit(t.and_test_value)})}and_test_value(t){return t.not_test_value.length===1?this.visit(t.not_test_value):F(t,{type:17,items:this.visit(t.not_test_value)})}not_test_value(t){if(t.arith_expr)return this.visit(t.arith_expr);if(t.not_test)return F(t,{type:18,items:this.visit(t.not_test)})}arith_expr(t){const n=this.visit(t.term);return t.arith_expr_item?F(t,{type:20,lhs:n,items:this.visit(t.arith_expr_item)}):n}arith_expr_item(t){return F(t,{type:21,operator:t.Plus?1:2,rhs:this.visit(t.term)})}term(t){return t.term_item?F(t,{type:20,lhs:this.visit(t.factor),items:this.visit(t.term_item)}):this.visit(t.factor)}term_item(t){let n=0;return t.Multiply&&(n=4),t.Divide&&(n=5),t.ModDivide&&(n=6),t.FloorDivide&&(n=7),F(t,{type:21,operator:n,rhs:this.visit(t.factor)})}factor(t){if(t.power)return this.visit(t.power);let n=0;return t.Plus&&(n=8),t.Minus&&(n=9),F(t,{type:20,lhs:void 0,items:[F(t,{type:21,operator:n,rhs:this.visit(t.factor)})]})}power(t){const n=this.visit(t.token);return t.factor?F(t,{type:20,lhs:n,items:[F(t,{type:21,operator:3,rhs:this.visit(t.factor)})]}):n}words(t){return it(this,t.expr)}token(t){if(t.StringLiteralDouble){const n=an(t.StringLiteralDouble[0]);return F(t,{type:7,literal:2,value:n.substring(1,n.length-1)})}if(t.StringLiteral)return F(t,{type:7,literal:1,value:an(t.StringLiteral[0])});if(t.NumberLiteral)return F(t,{type:7,literal:0,value:parseFloat(an(t.NumberLiteral[0]))});if(t.LParen)return F(t,{type:22,words:it(this,t.expr).flat()})}}const Fv=new Dv,Pt={internal:0,labels:{},labelIndex:0},Ni="if (api.hm()) { continue zss; }",hd=`if (api.sy()) { yield 1; ${Ni} };`,Ci=`yield 1; ${Ni}`,Ii="zss.js";function ot(e,t){return new ov(e.startLine||1,e.startColumn||1,Ii,t)}function Wa(e){return e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}function $v(e){return`'${Wa(e)}'`}function Li(e){if(e.startsWith('"'))return Li(e.substring(1,e.length-1));const t=Lv(e);return t.errors.length?e:`'${t.tokens.map(r=>r.tokenType===Ka?`', api.group('${Wa(r.image.substring(1))}'), '`:Wa(r.image)).join("")}'`}function Ne(e){return e.filter(t=>t!==void 0).map(H)}function fd(e){return ot(e,"")}function Bv(e,t){const n=[];return e.forEach(r=>{n.push(r,t)}),n.pop(),n}function tt(e,t,n){return ot(e,[`api.${t}(`,...Bv(n,", "),")"])}function Gv(e){if(e.type===q.COMPARE)switch(e.compare){case kn.IS_EQ:return tt(e,"isEq",[H(e.lhs),H(e.rhs)]);case kn.IS_NOT_EQ:return tt(e,"isNotEq",[H(e.lhs),H(e.rhs)]);case kn.IS_LESS_THAN:return tt(e,"isLessThan",[H(e.lhs),H(e.rhs)]);case kn.IS_GREATER_THAN:return tt(e,"isGreaterThan",[H(e.lhs),H(e.rhs)]);case kn.IS_LESS_THAN_OR_EQ:return tt(e,"isLessThanOrEq",[H(e.lhs),H(e.rhs)]);case kn.IS_GREATER_THAN_OR_EQ:return tt(e,"isGreaterThanOrEq",[H(e.lhs),H(e.rhs)])}return ot(e,"")}function bn(e,t,n,r){return t.prepend(`api.${n}(`),t.add([", ",H(r),")"])}function dd(e,t,n,r){return t.prepend(`api.${n}(`),t.add([H(r),")"])}function Kv(e,t){if(e.type===q.OPERATOR_ITEM)switch(e.operator){case ve.PLUS:return bn(e,t,"opPlus",e.rhs);case ve.MINUS:return bn(e,t,"opMinus",e.rhs);case ve.POWER:return bn(e,t,"opPower",e.rhs);case ve.MULTIPLY:return bn(e,t,"opMultiply",e.rhs);case ve.DIVIDE:return bn(e,t,"opDivide",e.rhs);case ve.MOD_DIVIDE:return bn(e,t,"opModDivide",e.rhs);case ve.FLOOR_DIVIDE:return bn(e,t,"opFloorDivide",e.rhs);case ve.UNI_PLUS:return dd(e,t,"opUniPlus",e.rhs);case ve.UNI_MINUS:return dd(e,t,"opUniMinus",e.rhs)}return ot(e,"")}function Wv(e){if(e.type===q.OPERATOR){const t=e.lhs?H(e.lhs):ot(e,"");return e.items.forEach(n=>Kv(n,t)),t}return ot(e,"")}function H(e){switch(e.type){case q.PROGRAM:return ot(e,[`try { // first-line +`,`zss: while (true) { +`,`switch (api.getcase()) { +`,`default: +`,`case 1: +`,...e.lines.map(t=>[H(t),` +`]).flat(),`} +`,`api.endofprogram(); +`,`while(true) { ${Ci} } +`,`} +`,`} catch (e) { +`,`console.error(e); +`,`const source = api.stacktrace(e); +`,`const err = new Error(e.message); +`,`err.name = 'GameError'; +`,`err.meta = { line: source.line, column: source.column }; +`,`throw err; +`,`} +`,`//# sourceURL=${Ii}`]);case q.LITERAL:switch(e.literal){case vi.NUMBER:return ot(e,`${e.value}`);case vi.STRING:return ot(e,$v(e.value));case vi.TEMPLATE:return ot(e,Li(e.value))}return fd(e);case q.TEXT:return tt(e,"text",[Li(e.value)]);case q.STAT:return tt(e,"stat",Ne(e.words));case q.LABEL:{const t=Pt.labelIndex++;return Pt.labels[e.name]||(Pt.labels[e.name]=[]),Pt.labels[e.name].push(e.active?t:-t),ot(e,`case ${t}: // ${e.name}`)}case q.HYPERLINK:return tt(e,"hyperlink",[Li(e.text),...Ne(e.link)]);case q.MOVE:return ot(e,["while (",tt(e,"move",[e.wait?"true":"false",...Ne(e.words)]),`) { ${Ci} }; + ${hd} ${Ni}`]);case q.COMMAND:return ot(e,["while (",tt(e,"command",Ne(e.words)),`) { ${Ci} }; + ${hd} ${Ni}`]);case q.IF:{const t=ot(e,["if (",tt(e,`${e.method}`,Ne(e.words)),`) { +`]);return e.lines&&e.lines.forEach(n=>t.add([H(n),` +`])),e.branches&&e.branches.forEach(n=>t.add(H(n))),t.add("}"),t}case q.ELSE_IF:{const t=ot(e,["} else if (",tt(e,e.method,Ne(e.words)),`) { +`]);return e.lines&&e.lines.forEach(n=>t.add([H(n),` +`])),t}case q.ELSE:{const t=ot(e,`} else { +`);return e.words.length&&t.add(["while (",tt(e,"command",Ne(e.words)),`) { ${Ci} };`]),e.lines&&e.lines.forEach(n=>t.add([H(n),` +`])),t}case q.WHILE:{const t=ot(e,["while (",tt(e,"if",Ne(e.words)),`) { +`]);return e.lines&&e.lines.forEach(n=>t.add([H(n),` +`])),t.add("}"),t}case q.REPEAT:{const t=ot(e,[tt(e,"repeatStart",[`${Pt.internal}`,...Ne(e.words)]),`; +while (`,tt(e,"repeat",[`${Pt.internal}`]),`) { +`]);return Pt.internal+=1,e.lines&&e.lines.forEach(n=>t.add([H(n),` +`])),t.add("}"),t}case q.READ:{const[t,...n]=e.words,r=ot(e,[tt(e,"readStart",[`${Pt.internal}`,H(t)]),`; +while (`,tt(e,"read",[`${Pt.internal}`,...Ne(n)]),`) { +`]);return Pt.internal+=1,e.lines&&e.lines.forEach(s=>r.add([H(s),` +`])),r.add("}"),r}case q.BREAK:return ot(e,`break; +`);case q.CONTINUE:return ot(e,`continue; +`);case q.OR:return tt(e,"or",e.items.map(H));case q.AND:return tt(e,"and",e.items.map(H));case q.NOT:return tt(e,"not",e.items.map(H));case q.COMPARE:return Gv(e);case q.OPERATOR:return Wv(e);case q.EXPR:return tt(e,"expr",e.words.map(H));default:return console.error("",e),fd(e)}}function jv(e){return Pt.internal=0,Pt.labels={restart:[1]},Pt.labelIndex=2,{...H(e).toStringWithSourceMap({file:`${Ii}.map`}),...Pt}}const Hv=64;function Vv(e){return Array.isArray(e)?e.length>0?1:0:e??0}function Ye(e){return`${e??""}`}function Yv(e,t){var N;const n=qg(t.labels??{});let r,s="",i,o=0;const a={},c={},l={};let u=!1,h=3,d=0,f=0,p=!1;const E=[];let w={};function A(T){if(w[T]===void 0)for(let m=0;mHv},hm(){var m;const T=(i==null?void 0:i.target)??"";return((m=n[T])==null?void 0:m.find(g=>g>0))??0},yield(){u=!0},sy(){return u||y.shouldhalt()},send(T,m,g){const S=`vm:${T}:${m}`;Dt.emit(S,e,g)},lock(T){s=T},unlock(){s=""},message(T){s&&T.sender!==s||(i=T)},zap(T){const m=n[T];if(m){const g=m.findIndex(S=>S>0);g>=0&&(m[g]*=-1)}},restore(T){const m=n[T];if(m)for(let g=0;gS.fileName===Ii);return{line:(g==null?void 0:g.lineNumber)??0,column:(g==null?void 0:g.columnNumber)??0}},text(T){return R("text",[T])},stat(...T){return R("stat",T)},hyperlink(...T){return R("hyperlink",T)},move(T,...m){const g=y.command("go",...m);return y.yield(),g&&T?1:0},command(...T){if(T.length===0)return 0;const[m,...g]=T,S=A(Ye(m));return S?S(y,g):R("send",[m,...g])},if(...T){const m=K(y,T),[g,S]=I(m,0,[C.ANY]),v=Vv(g);return v&&S0,S=c[T];return g&&S&&y.command(...S),g},readStart(T,m){if(!lt(m))return;const g=y.get(m)??[];l[T]=Array.isArray(g)?g:[g]},read(T,...m){const g=l[T];if(Array.isArray(g)===!1)return!1;const S=g.shift();if(S===void 0)return!1;const v=m.map(Ye);switch(typeof S){case"number":case"string":v.forEach(j=>{y.set(j,S)});break;case"object":v.forEach(j=>{const yt=S[j];y.set(j,yt)});break}return!0},or(...T){const m=K(y,T);let g=0;for(let S=0;SS?1:0},isLessThanOrEq(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return g<=S?1:0},isGreaterThanOrEq(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return g>=S?1:0},opPlus(T,m){const[g]=I(K(y,[T]),0,[C.ANY]),[S]=I(K(y,[m]),0,[C.ANY]);return g+S},opMinus(T,m){const[g]=I(K(y,[T]),0,[C.ANY]),[S]=I(K(y,[m]),0,[C.ANY]);return g-S},opPower(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return Math.pow(g,S)},opMultiply(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return g*S},opDivide(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return g/S},opModDivide(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return g%S},opFloorDivide(T,m){const[g]=I(K(y,[T]),0,[C.NUMBER]),[S]=I(K(y,[m]),0,[C.NUMBER]);return Math.floor(g/S)},opUniPlus(T){const[m]=I(K(y,[T]),0,[C.NUMBER]);return+m},opUniMinus(T){const[m]=I(K(y,[T]),0,[C.NUMBER]);return-m}};return r=(N=t.code)==null?void 0:N.call(t,y),y}function pd(e){const t={},n={...e,getcommand(r){return t[r]},command(r,s){return t[r]=s,n}};return n}var gd={exports:{}};/*! Case - v1.6.2 - 2020-03-24 +* Copyright (c) 2020 Nathan Bubna; Licensed MIT, GPL */(function(e){(function(){var t=function(f,p){return p=p||"",f.replace(/(^|-)/g,"$1\\u"+p).replace(/,/g,"\\u"+p)},n=t("20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7","00"),r="a-z"+t("DF-F6,F8-FF","00"),s="A-Z"+t("C0-D6,D8-DE","00"),i="A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via",o=function(f,p,E,w){return f=f||n,p=p||r,E=E||s,w=w||i,{capitalize:new RegExp("(^|["+f+"])(["+p+"])","g"),pascal:new RegExp("(^|["+f+"])+(["+p+E+"])","g"),fill:new RegExp("["+f+"]+(.|$)","g"),sentence:new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+p+"])","g"),improper:new RegExp("\\b("+w+")\\b","g"),relax:new RegExp("([^"+E+"])(["+E+"]*)(["+E+"])(?=[^"+E+"]|$)","g"),upper:new RegExp("^[^"+p+"]+$"),hole:/[^\s]\s[^\s]/,apostrophe:/'/g,room:new RegExp("["+f+"]")}},a=o(),c={re:a,unicodes:t,regexps:o,types:[],up:String.prototype.toUpperCase,low:String.prototype.toLowerCase,cap:function(f){return c.up.call(f.charAt(0))+f.slice(1)},decap:function(f){return c.low.call(f.charAt(0))+f.slice(1)},deapostrophe:function(f){return f.replace(a.apostrophe,"")},fill:function(f,p,E){return p!=null&&(f=f.replace(a.fill,function(w,A){return A?p+A:""})),E&&(f=c.deapostrophe(f)),f},prep:function(f,p,E,w){if(f=f==null?"":f+"",!w&&a.upper.test(f)&&(f=c.low.call(f)),!p&&!a.hole.test(f)){var A=c.fill(f," ");a.hole.test(A)&&(f=A)}return!E&&!a.room.test(f)&&(f=f.replace(a.relax,c.relax)),f},relax:function(f,p,E,w){return p+" "+(E?E+" ":"")+w}},l={_:c,of:function(f){for(var p=0,E=c.types.length;p0&&wee>t?e:t,yd=e=>e!==0?e<0:1/e<0,Td=Number.MAX_SAFE_INTEGER,Jv=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&cn(e)===e),ar=()=>new Set,Ya=e=>e[e.length-1],Qv=(e,t)=>{for(let n=0;ne.toLowerCase(),eN=/^\s*/g,nN=e=>e.replace(eN,""),rN=/([A-Z])/g,Sd=(e,t)=>nN(e.replace(rN,n=>`${t}${tN(n)}`)),sN=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;sas.encode(e):sN;let cs=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});cs&&cs.decode(new Uint8Array).length===1&&(cs=null);const un=e=>new Error(e),Ce=()=>{throw un("Method unimplemented")},Ie=()=>{throw un("Unexpected case")};class ls{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const hn=()=>new ls,oN=e=>{let t=e.cpos;for(let n=0;n{const t=new Uint8Array(oN(e));let n=0;for(let r=0;r{const n=e.cbuf.length;n-e.cpos{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},za=Et,P=(e,t)=>{for(;t>Mn;)Et(e,Ht|Mn&t),t=cn(t/128);Et(e,Mn&t)},qa=(e,t)=>{const n=yd(t);for(n&&(t=-t),Et(e,(t>Va?Ht:0)|(n?ze:0)|Va&t),t=cn(t/64);t>0;)Et(e,(t>Mn?Ht:0)|Mn&t),t=cn(t/128)},Xa=new Uint8Array(3e4),cN=Xa.length/3,lN=(e,t)=>{if(t.length{const n=unescape(encodeURIComponent(t)),r=n.length;P(e,r);for(let s=0;s{const n=e.cbuf.length,r=e.cpos,s=_d(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(xn(n*2,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},Nt=(e,t)=>{P(e,t.byteLength),bi(e,t)},Ja=(e,t)=>{aN(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},hN=(e,t)=>Ja(e,4).setFloat32(0,t,!1),fN=(e,t)=>Ja(e,8).setFloat64(0,t,!1),dN=(e,t)=>Ja(e,8).setBigInt64(0,t,!1),Ad=new DataView(new ArrayBuffer(4)),pN=e=>(Ad.setFloat32(0,e),Ad.getFloat32(0)===e),us=(e,t)=>{switch(typeof t){case"string":Et(e,119),cr(e,t);break;case"number":Jv(t)&&ki(t)<=Xv?(Et(e,125),qa(e,t)):pN(t)?(Et(e,124),hN(e,t)):(Et(e,123),fN(e,t));break;case"bigint":Et(e,122),dN(e,t);break;case"object":if(t===null)Et(e,126);else if(Zv(t)){Et(e,117),P(e,t.length);for(let n=0;n0&&P(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Rd=e=>{e.count>0&&(qa(e.encoder,e.count===1?e.s:-e.s),e.count>1&&P(e.encoder,e.count-2))};class Mi{constructor(){this.encoder=new ls,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Rd(this),this.count=1,this.s=t)}toUint8Array(){return Rd(this),fe(this.encoder)}}const vd=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);qa(e.encoder,t),e.count>1&&P(e.encoder,e.count-2)}};class Qa{constructor(){this.encoder=new ls,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(vd(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return vd(this),fe(this.encoder)}}class gN{constructor(){this.sarr=[],this.s="",this.lensE=new Mi}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new ls;return this.sarr.push(this.s),this.s="",cr(t,this.sarr.join("")),bi(t,this.lensE.toUint8Array()),fe(t)}}const Nd=un("Unexpected end of array"),Cd=un("Integer out of Range");class xi{constructor(t){this.arr=t,this.pos=0}}const Un=e=>new xi(e),mN=e=>e.pos!==e.arr.length,EN=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},bt=e=>EN(e,D(e)),lr=e=>e.arr[e.pos++],D=e=>{let t=0,n=1;const r=e.arr.length;for(;e.posTd)throw Cd}throw Nd},Za=e=>{let t=e.arr[e.pos++],n=t&Va,r=64;const s=(t&ze)>0?-1:1;if(!(t&Ht))return s*n;const i=e.arr.length;for(;e.posTd)throw Cd}throw Nd},ur=cs?e=>cs.decode(bt(e)):e=>{let t=D(e);if(t===0)return"";{let n=String.fromCodePoint(lr(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(lr(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},tc=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},_N=[e=>{},e=>null,Za,e=>tc(e,4).getFloat32(0,!1),e=>tc(e,8).getFloat64(0,!1),e=>tc(e,8).getBigInt64(0,!1),e=>!1,e=>!0,ur,e=>{const t=D(e),n={};for(let r=0;r{const t=D(e),n=[];for(let r=0;r_N[127-lr(e)](e);class Id extends xi{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),mN(this)?this.count=D(this)+1:this.count=-1),this.count--,this.s}}class Ui extends xi{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Za(this);const t=yd(this.s);this.count=1,t&&(this.s=-this.s,this.count=D(this)+2)}return this.count--,this.s}}class ec extends xi{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Za(this),n=t&1;this.diff=cn(t/2),this.count=1,n&&(this.count=D(this)+2)}return this.s+=this.diff,this.count--,this.s}}class yN{constructor(t){this.decoder=new Ui(t),this.str=ur(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const de=()=>new Map,nc=e=>{const t=de();return e.forEach((n,r)=>{t.set(r,n)}),t},fn=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},TN=(e,t)=>{const n=[];for(const[r,s]of e)n.push(t(s,r));return n},SN=(e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1};class AN{constructor(){this._observers=de()}on(t,n){return fn(this._observers,t,ar).add(n),n}once(t,n){const r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){const r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return ln((this._observers.get(t)||de()).values()).forEach(r=>r(...n))}destroy(){this._observers=de()}}const wN=crypto.getRandomValues.bind(crypto),Ld=()=>wN(new Uint32Array(1))[0],RN="10000000-1000-4000-8000"+-1e11,vN=()=>RN.replace(/[018]/g,e=>(e^Ld()&15>>e/4).toString(16)),Od=e=>new Promise(e);Promise.all.bind(Promise);const kd=e=>e===void 0?null:e;class NN{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let bd=new NN,CN=!0;try{typeof localStorage<"u"&&localStorage&&(bd=localStorage,CN=!1)}catch{}const IN=bd,LN=Object.assign,ON=Object.keys,kN=(e,t)=>{for(const n in e)t(e[n],n)},Md=e=>ON(e).length,bN=e=>{for(const t in e)return!1;return!0},MN=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},xN=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),UN=(e,t)=>e===t||Md(e)===Md(t)&&MN(e,(n,r)=>(n!==void 0||xN(t,r))&&t[r]===n),rc=(e,t,n=0)=>{try{for(;ne,DN=(e,t)=>t.includes(e);var xd={};const fs=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let Le;const FN=()=>{if(Le===void 0)if(fs){Le=de();const e=process.argv;let t=null;for(let n=0;n{if(e.length!==0){const[t,n]=e.split("=");Le.set(`--${Sd(t,"-")}`,n),Le.set(`-${Sd(t,"-")}`,n)}})):Le=de();return Le},sc=e=>FN().has(e),ic=e=>kd(fs?xd[e.toUpperCase().replaceAll("-","_")]:IN.getItem(e));(e=>sc("--"+e)||ic(e)!==null)("production");const Ud=fs&&DN(xd.FORCE_COLOR,["true","1","2"]),$N=!sc("no-colors")&&(!fs||process.stdout.isTTY||Ud)&&(!fs||sc("color")||Ud||ic("COLORTERM")!==null||(ic("TERM")||"").includes("color")),BN=e=>new Uint8Array(e),GN=e=>{const t=BN(e.byteLength);return t.set(e),t};class KN{constructor(t,n){this.left=t,this.right=n}}const qe=(e,t)=>new KN(e,t);typeof DOMParser<"u"&&new DOMParser;const WN=e=>TN(e,(t,n)=>`${n}:${t};`).join(""),Xe=Symbol,Pd=Xe(),Dd=Xe(),jN=Xe(),HN=Xe(),VN=Xe(),Fd=Xe(),YN=Xe(),$d=Xe(),zN=Xe(),qN=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[];let n=0;for(;n{var o;e.length===1&&((o=e[0])==null?void 0:o.constructor)===Function&&(e=e[0]());const t=[],n=[],r=de();let s=[],i=0;for(;i0||l.length>0?(t.push("%c"+a),n.push(l)):t.push(a)}else break}}for(i>0&&(s=n,s.unshift(t.join("")));i{console.log(...JN(e)),ZN.forEach(t=>t.print(e))},ZN=ar(),Bd=e=>({[Symbol.iterator](){return this},next:e}),tC=(e,t)=>Bd(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),oc=(e,t)=>Bd(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});class ac{constructor(t,n){this.clock=t,this.len=n}}class ds{constructor(){this.clients=new Map}}const Gd=(e,t,n)=>t.clients.forEach((r,s)=>{const i=e.doc.store.clients.get(s);for(let o=0;o{let n=0,r=e.length-1;for(;n<=r;){const s=cn((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t{const n=e.clients.get(t.client);return n!==void 0&&eC(n,t.clock)!==null},cc=e=>{e.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n=i.clock?s.len=xn(s.len,i.clock+i.len-s.clock):(r{const t=new ds;for(let n=0;n{if(!t.clients.has(s)){const i=r.slice();for(let o=n+1;o{fn(e.clients,t,()=>[]).push(new ac(n,r))},rC=()=>new ds,sC=e=>{const t=rC();return e.clients.forEach((n,r)=>{const s=[];for(let i=0;i0&&t.clients.set(r,s)}),t},hr=(e,t)=>{P(e.restEncoder,t.clients.size),ln(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),P(e.restEncoder,n);const s=r.length;P(e.restEncoder,s);for(let i=0;i{const t=new ds,n=D(e.restDecoder);for(let r=0;r0){const o=fn(t.clients,s,()=>[]);for(let a=0;a{const r=new ds,s=D(e.restDecoder);for(let i=0;i0){const i=new Pn;return P(i.restEncoder,0),hr(i,r),i.toUint8Array()}return null},jd=Ld;class fr extends AN{constructor({guid:t=vN(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=jd(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new np,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=Od(l=>{this.on("load",()=>{this.isLoaded=!0,l(this)})});const c=()=>Od(l=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),l())};this.on("sync",u)});this.on("sync",l=>{l===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=l===void 0||l===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&X(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ln(this.subdocs).map(t=>t.guid))}transact(t,n=null){return X(this,t,n)}get(t,n=wt){const r=fn(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==wt&&s!==n)if(s===wt){const i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,mr)}getText(t=""){return this.get(t,Dn)}getMap(t=""){return this.get(t,Er)}getXmlElement(t=""){return this.get(t,yr)}getXmlFragment(t=""){return this.get(t,Fn)}toJSON(){const t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){ln(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new fr({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,X(t.parent.doc,r=>{const s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Hd{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return D(this.restDecoder)}readDsLen(){return D(this.restDecoder)}}class Vd extends Hd{readLeftID(){return G(D(this.restDecoder),D(this.restDecoder))}readRightID(){return G(D(this.restDecoder),D(this.restDecoder))}readClient(){return D(this.restDecoder)}readInfo(){return lr(this.restDecoder)}readString(){return ur(this.restDecoder)}readParentInfo(){return D(this.restDecoder)===1}readTypeRef(){return D(this.restDecoder)}readLen(){return D(this.restDecoder)}readAny(){return hs(this.restDecoder)}readBuf(){return GN(bt(this.restDecoder))}readJSON(){return JSON.parse(ur(this.restDecoder))}readKey(){return ur(this.restDecoder)}}class iC{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=D(this.restDecoder),this.dsCurrVal}readDsLen(){const t=D(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class dr extends iC{constructor(t){super(t),this.keys=[],D(t),this.keyClockDecoder=new ec(bt(t)),this.clientDecoder=new Ui(bt(t)),this.leftClockDecoder=new ec(bt(t)),this.rightClockDecoder=new ec(bt(t)),this.infoDecoder=new Id(bt(t),lr),this.stringDecoder=new yN(bt(t)),this.parentInfoDecoder=new Id(bt(t),lr),this.typeRefDecoder=new Ui(bt(t)),this.lenDecoder=new Ui(bt(t))}readLeftID(){return new pr(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new pr(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return hs(this.restDecoder)}readBuf(){return bt(this.restDecoder)}readJSON(){return hs(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t{r=xn(r,t[0].id.clock);const s=Oe(t,r);P(e.restEncoder,t.length-s),e.writeClient(n),P(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o{const r=new Map;n.forEach((s,i)=>{_t(t,i)>s&&r.set(i,s)}),Fi(t).forEach((s,i)=>{n.has(i)||r.set(i,0)}),P(e.restEncoder,r.size),ln(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{oC(e,t.clients.get(s),s,i)})},aC=(e,t)=>{const n=de(),r=D(e.restDecoder);for(let s=0;s{const r=[];let s=ln(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;const i=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f};let o=i();if(o===null)return null;const a=new np,c=new Map,l=(f,p)=>{const E=c.get(f);(E==null||E>p)&&c.set(f,p)};let u=o.refs[o.i++];const h=new Map,d=()=>{for(const f of r){const p=f.id.client,E=n.get(p);E?(E.i--,a.clients.set(p,E.refs.slice(E.i)),n.delete(p),E.i=0,E.refs=[]):a.clients.set(p,[f]),s=s.filter(w=>w!==p)}r.length=0};for(;;){if(u.constructor!==ee){const p=fn(h,u.id.client,()=>_t(t,u.id.client))-u.id.clock;if(p<0)r.push(u),l(u.id.client,u.id.clock-1),d();else{const E=u.getMissing(e,t);if(E!==null){r.push(u);const w=n.get(E)||{refs:[],i:0};if(w.refs.length===w.i)l(E,_t(t,E)),d();else{u=w.refs[w.i++];continue}}else(p===0||p0)u=r.pop();else if(o!==null&&o.i0){const f=new Pn;return uc(f,a,new Map),P(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},lC=(e,t)=>uc(e,t.doc.store,t.beforeState),uC=(e,t,n,r=new dr(e))=>X(t,s=>{s.local=!1;let i=!1;const o=s.doc,a=o.store,c=aC(r,o),l=cC(s,a,c),u=a.pendingStructs;if(u){for(const[d,f]of u.missing)if(f<_t(a,d)){i=!0;break}if(l){for(const[d,f]of l.missing){const p=u.missing.get(d);(p==null||p>f)&&u.missing.set(d,f)}u.update=Bi([u.update,l.update])}}else a.pendingStructs=l;const h=Wd(r,s,a);if(a.pendingDs){const d=new dr(Un(a.pendingDs));D(d.restDecoder);const f=Wd(d,s,a);h&&f?a.pendingDs=Bi([h,f]):a.pendingDs=h||f}else a.pendingDs=h;if(i){const d=a.pendingStructs.update;a.pendingStructs=null,qd(s.doc,d)}},n,!1),qd=(e,t,n,r=dr)=>{const s=Un(t);uC(s,e,n,new r(s))},hC=(e,t,n)=>qd(e,t,n,Vd),fC=(e,t,n=new Map)=>{uc(e,t.store,n),hr(e,sC(t.store))},dC=(e,t=new Uint8Array([0]),n=new Pn)=>{const r=Xd(t);fC(n,e,r);const s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(IC(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===ps)return NC(s.map((i,o)=>o===0?i:OC(i)));if(n.constructor===Pn)return Bi(s)}return s[0]},pC=(e,t)=>dC(e,t,new ps),gC=e=>{const t=new Map,n=D(e.restDecoder);for(let r=0;rgC(new Hd(Un(e))),Jd=(e,t)=>(P(e.restEncoder,t.size),ln(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{P(e.restEncoder,n),P(e.restEncoder,r)}),e),mC=(e,t)=>Jd(e,Fi(t.store)),EC=(e,t=new zd)=>(e instanceof Map?Jd(t,e):mC(t,e),t.toUint8Array()),_C=e=>EC(e,new Yd);class yC{constructor(){this.l=[]}}const Qd=()=>new yC,Zd=(e,t)=>e.l.push(t),tp=(e,t)=>{const n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},ep=(e,t,n)=>rc(e.l,[t,n]);class pr{constructor(t,n){this.client=t,this.clock=n}}const Di=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,G=(e,t)=>new pr(e,t),TC=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Ie()},gr=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Kd(t.ds,e.id),hc=(e,t)=>{const n=fn(e.meta,hc,ar),r=e.doc.store;n.has(t)||(t.sv.forEach((s,i)=>{s<_t(r,i)&&dn(e,G(i,s))}),Gd(e,t.ds,s=>{}),n.add(t))};class np{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Fi=e=>{const t=new Map;return e.clients.forEach((n,r)=>{const s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},_t=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},rp=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw Ie()}n.push(t)},Oe=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=cn(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t{const n=e.clients.get(t.client);return n[Oe(n,t.clock)]},dc=(e,t,n)=>{const r=Oe(t,n),s=t[r];return s.id.clock{const n=e.doc.store.clients.get(t.client);return n[dc(e,n,t.clock)]},sp=(e,t,n)=>{const r=t.clients.get(n.client),s=Oe(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==te&&r.splice(s+1,0,Ji(e,i,n.clock-i.id.clock+1)),i},SC=(e,t,n)=>{const r=e.clients.get(t.id.client);r[Oe(r,t.id.clock)]=n},ip=(e,t,n,r,s)=>{if(r===0)return;const i=n+r;let o=dc(e,t,n),a;do a=t[o++],it.deleteSet.clients.size===0&&!SN(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(cc(t.deleteSet),lC(e,t),hr(e,t.deleteSet),!0),ap=(e,t,n)=>{const r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&fn(e.changed,t,ar).add(n)},$i=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof pt&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const i=t-s;return i&&e.splice(t+1-i,i),i},wC=(e,t,n)=>{for(const[r,s]of e.clients.entries()){const i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){const a=s[o],c=a.clock+a.len;for(let l=Oe(i,a.clock),u=i[l];l{e.clients.forEach((n,r)=>{const s=t.clients.get(r);for(let i=n.length-1;i>=0;i--){const o=n[i],a=_d(s.length-1,1+Oe(s,o.clock+o.len-1));for(let c=a,l=s[c];c>0&&l.id.clock>=o.clock;l=s[c])c-=1+$i(s,c)}})},cp=(e,t)=>{if(ta.push(()=>{(l._item===null||!l._item.deleted)&&l._callObserver(n,c)})),a.push(()=>{n.changedParentTypes.forEach((c,l)=>{l._dEH.l.length>0&&(l._item===null||!l._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=l,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),ep(l._dEH,c,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),rc(a,[]),n._needFormattingCleanup&&jC(n)}finally{r.gc&&wC(i,s,r.gcFilter),RC(i,s),n.afterState.forEach((u,h)=>{const d=n.beforeState.get(h)||0;if(d!==u){const f=s.clients.get(h),p=xn(Oe(f,d),1);for(let E=f.length-1;E>=p;)E-=1+$i(f,E)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:d}=o[u].id,f=s.clients.get(h),p=Oe(f,d);p+11||p>0&&$i(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(QN($d,Pd,"[yjs] ",Dd,Fd,"Changed the client-id because another client seems to be using it."),r.clientID=jd()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const u=new ps;op(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const u=new Pn;op(u,n)&&r.emit("updateV2",[u.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:c,subdocsRemoved:l}=n;(a.size>0||l.size>0||c.size>0)&&(a.forEach(u=>{u.clientID=r.clientID,u.collectionid==null&&(u.collectionid=r.collectionid),r.subdocs.add(u)}),l.forEach(u=>r.subdocs.delete(u)),r.emit("subdocs",[{loaded:c,added:a,removed:l},r,n]),l.forEach(u=>u.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):cp(e,t+1)}}},X=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new AC(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const a=e._transaction===s[0];e._transaction=null,a&&cp(s,0)}}return o};function*vC(e){const t=D(e.restDecoder);for(let n=0;nBi(e,Vd,ps),CC=(e,t)=>{if(e.constructor===te){const{client:n,clock:r}=e.id;return new te(G(n,r+t),e.length-t)}else if(e.constructor===ee){const{client:n,clock:r}=e.id;return new ee(G(n,r+t),e.length-t)}else{const n=e,{client:r,clock:s}=n.id;return new pt(G(r,s+t),null,G(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Bi=(e,t=dr,n=Pn)=>{if(e.length===1)return e[0];const r=e.map(u=>new t(Un(u)));let s=r.map(u=>new pc(u,!0)),i=null;const o=new n,a=new gc(o);for(;s=s.filter(d=>d.curr!==null),s.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const p=d.curr.id.clock-f.curr.id.clock;return p===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===ee?1:-1:p}else return f.curr.id.client-d.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(i!==null){let d=u.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=u.next(),f=!0;if(d===null||d.id.client!==h||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(h!==i.struct.id.client)pn(a,i.struct,i.offset),i={struct:d,offset:0},u.next();else if(i.struct.id.clock+i.struct.length0&&(i.struct.constructor===ee?i.struct.length-=p:d=CC(d,p)),i.struct.mergeWith(d)||(pn(a,i.struct,i.offset),i={struct:d,offset:0},u.next())}}else i={struct:u.curr,offset:0},u.next();for(let d=u.curr;d!==null&&d.id.client===h&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==ee;d=u.next())pn(a,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(pn(a,i.struct,i.offset),i=null),mc(a);const c=r.map(u=>lc(u)),l=nC(c);return hr(o,l),o.toUint8Array()},IC=(e,t,n=dr,r=Pn)=>{const s=Xd(t),i=new r,o=new gc(i),a=new n(Un(e)),c=new pc(a,!1);for(;c.curr;){const u=c.curr,h=u.id.client,d=s.get(h)||0;if(c.curr.constructor===ee){c.next();continue}if(u.id.clock+u.length>d)for(pn(o,u,xn(d-u.id.clock,0)),c.next();c.curr&&c.curr.id.client===h;)pn(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===h&&c.curr.id.clock+c.curr.length<=d;)c.next()}mc(o);const l=lc(a);return hr(i,l),i.toUint8Array()},lp=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:fe(e.encoder.restEncoder)}),e.encoder.restEncoder=hn(),e.written=0)},pn=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&lp(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),P(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},mc=e=>{lp(e);const t=e.encoder.restEncoder;P(t,e.clientStructs.length);for(let n=0;n{const s=new n(Un(e)),i=new pc(s,!1),o=new r,a=new gc(o);for(let l=i.curr;l!==null;l=i.next())pn(a,t(l),0);mc(a);const c=lc(s);return hr(o,c),o.toUint8Array()},OC=e=>LC(e,PN,dr,ps),up="You must not compute changes after the event-handler fired.";class Gi{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=kC(this.currentTarget,this.target))}deletes(t){return Kd(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw un(up);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const i=n._map.get(s);let o,a;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))o="delete",a=Ya(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",a=Ya(c.content.getContent())):(o="add",a=void 0)}else if(this.deletes(i))o="delete",a=Ya(i.content.getContent());else return;t.set(s,{action:o,oldValue:a})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw un(up);const n=this.target,r=ar(),s=ar(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const c=()=>{a&&i.push(a)};for(let l=n._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((a===null||a.delete===void 0)&&(c(),a={delete:0}),a.delete+=l.length,s.add(l)):this.adds(l)?((a===null||a.insert===void 0)&&(c(),a={insert:[]}),a.insert=a.insert.concat(l.content.getContent()),r.add(l)):((a===null||a.retain===void 0)&&(c(),a={retain:0}),a.retain+=l.length);a!==null&&a.retain===void 0&&c()}this._changes=t}return t}}const kC=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)s.deleted||r++,s=s.right;n.unshift(r)}t=t._item.parent}return n},hp=80;let Ec=0;class bC{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Ec++}}const MC=e=>{e.timestamp=Ec++},fp=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ec++},xC=(e,t,n)=>{if(e.length>=hp){const r=e.reduce((s,i)=>s.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>ki(t-i.index)t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&ki(n.index-s){for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){e.splice(r,1);continue}s.p=i,i.marker=!0}(t0&&t===s.index)&&(s.index=xn(t,s.index+n))}},Wi=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;fn(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;ep(r._eH,n,t)};class wt{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Qd(),this._dEH=Qd(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw Ce()}clone(){throw Ce()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Zd(this._eH,t)}observeDeep(t){Zd(this._dEH,t)}unobserve(t){tp(this._eH,t)}unobserveDeep(t){tp(this._dEH,t)}toJSON(){}}const dp=(e,t,n)=>{t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let a=t;a0;a++)s.push(o[a]),r--;t=0}}i=i.right}return s},pp=e=>{const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let s=0;s{let n=0,r=e._start;for(;r!==null;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let i=0;i{const n=[];return ms(e,(r,s)=>{n.push(t(r,s,e))}),n},UC=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}const s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},mp=(e,t)=>{const n=Ki(e,t);let r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let s=n;const i=e.doc,o=i.clientID,a=i.store,c=n===null?t._start:n.right;let l=[];const u=()=>{l.length>0&&(s=new pt(G(o,_t(a,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Bn(l)),s.integrate(e,0),l=[])};r.forEach(h=>{if(h===null)l.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new pt(G(o,_t(a,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Es(new Uint8Array(h))),s.integrate(e,0);break;case fr:s=new pt(G(o,_t(a,o)),s,s&&s.lastId,c,c&&c.id,t,null,new ys(h)),s.integrate(e,0);break;default:if(h instanceof wt)s=new pt(G(o,_t(a,o)),s,s&&s.lastId,c,c&&c.id,t,null,new Je(h)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Ep=()=>un("Length exceeded!"),_p=(e,t,n,r)=>{if(n>t._length)throw Ep();if(n===0)return t._searchMarker&&gs(t._searchMarker,n,r.length),ji(e,t,null,r);const s=n,i=Ki(t,n);let o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let s=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return ji(e,t,s,n)},yp=(e,t,n,r)=>{if(r===0)return;const s=n,i=r,o=Ki(t,n);let a=t._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n0&&a!==null;)a.deleted||(r0)throw Ep();t._searchMarker&&gs(t._searchMarker,s,-i+r)},Hi=(e,t,n)=>{const r=t._map.get(n);r!==void 0&&r.delete(e)},_c=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let a;if(r==null)a=new Bn([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:a=new Bn([r]);break;case Uint8Array:a=new Es(r);break;case fr:a=new ys(r);break;default:if(r instanceof wt)a=new Je(r);else throw new Error("Unexpected content type")}new pt(G(o,_t(i.store,o)),s,s&&s.lastId,null,null,t,n,a).integrate(e,0)},yc=(e,t)=>{const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Tp=e=>{const t={};return e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},Sp=(e,t)=>{const n=e._map.get(t);return n!==void 0&&!n.deleted},DC=(e,t)=>{const n={};return e._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&gr(i,t)&&(n[s]=i.content.getContent()[i.length-1])}),n},Vi=e=>tC(e.entries(),t=>!t[1].deleted);class FC extends Gi{constructor(t,n){super(t,n),this._transaction=n}}class mr extends wt{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new mr;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new mr}clone(){const t=new mr;return t.insert(0,this.toArray().map(n=>n instanceof wt?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,n){super._callObserver(t,n),Wi(this,t,new FC(this,t))}insert(t,n){this.doc!==null?X(this.doc,r=>{_p(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?X(this.doc,n=>{PC(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?X(this.doc,r=>{yp(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return mp(this,t)}toArray(){return pp(this)}slice(t=0,n=this.length){return dp(this,t,n)}toJSON(){return this.map(t=>t instanceof wt?t.toJSON():t)}map(t){return gp(this,t)}forEach(t){ms(this,t)}[Symbol.iterator](){return UC(this)}_write(t){t.writeTypeRef(cI)}}const $C=e=>new mr;class BC extends Gi{constructor(t,n,r){super(t,n),this.keysChanged=r}}class Er extends wt{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new Er}clone(){const t=new Er;return this.forEach((n,r)=>{t.set(r,n instanceof wt?n.clone():n)}),t}_callObserver(t,n){Wi(this,t,new BC(this,t,n))}toJSON(){const t={};return this._map.forEach((n,r)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];t[r]=s instanceof wt?s.toJSON():s}}),t}get size(){return[...Vi(this._map)].length}keys(){return oc(Vi(this._map),t=>t[0])}values(){return oc(Vi(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return oc(Vi(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?X(this.doc,n=>{Hi(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?X(this.doc,r=>{_c(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return yc(this,t)}has(t){return Sp(this,t)}clear(){this.doc!==null?X(this.doc,t=>{this.forEach(function(n,r,s){Hi(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(lI)}}const GC=e=>new Er,gn=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&UN(e,t);class Tc{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){switch(this.right===null&&Ie(),this.right.content.constructor){case dt:this.right.deleted||_r(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Ap=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case dt:t.right.deleted||_r(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{const s=new Map,i=r?Ki(t,n):null;if(i){const o=new Tc(i.p.left,i.p,i.index,s);return Ap(e,o,n-i.index)}else{const o=new Tc(null,t._start,0,s);return Ap(e,o,n)}},wp=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===dt&&gn(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=e.doc,i=s.clientID;r.forEach((o,a)=>{const c=n.left,l=n.right,u=new pt(G(i,_t(s.store,i)),c,c&&c.lastId,l,l&&l.id,t,null,new dt(a,o));u.integrate(e,0),n.right=u,n.forward()})},_r=(e,t)=>{const{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Rp=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===dt&&gn(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},vp=(e,t,n,r)=>{const s=e.doc,i=s.clientID,o=new Map;for(const a in r){const c=r[a],l=n.currentAttributes.get(a)??null;if(!gn(l,c)){o.set(a,l);const{left:u,right:h}=n;n.right=new pt(G(i,_t(s.store,i)),u,u&&u.lastId,h,h&&h.id,t,null,new dt(a,c)),n.right.integrate(e,0),n.forward()}}return o},Sc=(e,t,n,r,s)=>{n.currentAttributes.forEach((d,f)=>{s[f]===void 0&&(s[f]=null)});const i=e.doc,o=i.clientID;Rp(n,s);const a=vp(e,t,n,s),c=r.constructor===String?new ke(r):r instanceof wt?new Je(r):new $n(r);let{left:l,right:u,index:h}=n;t._searchMarker&&gs(t._searchMarker,n.index,c.getLength()),u=new pt(G(o,_t(i.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=h,n.forward(),wp(e,t,n,a)},Np=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;Rp(n,s);const a=vp(e,t,n,s);t:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===dt));){if(!n.right.deleted)switch(n.right.content.constructor){case dt:{const{key:c,value:l}=n.right.content,u=s[c];if(u!==void 0){if(gn(u,l))a.delete(c);else{if(r===0)break t;a.set(c,l)}n.right.delete(e)}else n.currentAttributes.set(c,l);break}default:r0){let c="";for(;r>0;r--)c+=` +`;n.right=new pt(G(o,_t(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ke(c)),n.right.integrate(e,0),n.forward()}wp(e,t,n,a)},Cp=(e,t,n,r,s)=>{let i=t;const o=de();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===dt){const l=i.content;o.set(l.key,l)}i=i.right}let a=0,c=!1;for(;t!==i;){if(n===t&&(c=!0),!t.deleted){const l=t.content;switch(l.constructor){case dt:{const{key:u,value:h}=l,d=r.get(u)??null;(o.get(u)!==l||d===h)&&(t.delete(e),a++,!c&&(s.get(u)??null)===h&&d!==h&&(d===null?s.delete(u):s.set(u,d))),!c&&!t.deleted&&_r(s,l);break}}}t=t.right}return a},KC=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===dt){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},WC=e=>{let t=0;return X(e.doc,n=>{let r=e._start,s=e._start,i=de();const o=nc(i);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case dt:_r(o,s.content);break;default:t+=Cp(n,r,s,i,o),i=nc(o),r=s;break}s=s.right}}),t},jC=e=>{const t=new Set,n=e.doc;for(const[r,s]of e.afterState.entries()){const i=e.beforeState.get(r)||0;s!==i&&ip(e,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===dt&&o.constructor!==te&&t.add(o.parent)})}X(n,r=>{Gd(e,e.deleteSet,s=>{if(s instanceof te||!s.parent._hasFormatting||t.has(s.parent))return;const i=s.parent;s.content.constructor===dt?t.add(i):KC(r,s)});for(const s of t)WC(s)})},Ip=(e,t,n)=>{const r=n,s=nc(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Je:case $n:case ke:n{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,n=[];X(t,r=>{const s=new Map,i=new Map;let o=this.target._start,a=null;const c={};let l="",u=0,h=0;const d=()=>{if(a!==null){let f=null;switch(a){case"delete":h>0&&(f={delete:h}),h=0;break;case"insert":(typeof l=="object"||l.length>0)&&(f={insert:l},s.size>0&&(f.attributes={},s.forEach((p,E)=>{p!==null&&(f.attributes[E]=p)}))),l="";break;case"retain":u>0&&(f={retain:u},bN(c)||(f.attributes=LN({},c))),u=0;break}f&&n.push(f),a=null}};for(;o!==null;){switch(o.content.constructor){case Je:case $n:this.adds(o)?this.deletes(o)||(d(),a="insert",l=o.content.getContent()[0],d()):this.deletes(o)?(a!=="delete"&&(d(),a="delete"),h+=1):o.deleted||(a!=="retain"&&(d(),a="retain"),u+=1);break;case ke:this.adds(o)?this.deletes(o)||(a!=="insert"&&(d(),a="insert"),l+=o.content.str):this.deletes(o)?(a!=="delete"&&(d(),a="delete"),h+=o.length):o.deleted||(a!=="retain"&&(d(),a="retain"),u+=o.length);break;case dt:{const{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){const E=s.get(f)??null;gn(E,p)?p!==null&&o.delete(r):(a==="retain"&&d(),gn(p,i.get(f)??null)?delete c[f]:c[f]=p)}}else if(this.deletes(o)){i.set(f,p);const E=s.get(f)??null;gn(E,p)||(a==="retain"&&d(),c[f]=E)}else if(!o.deleted){i.set(f,p);const E=c[f];E!==void 0&&(gn(E,p)?E!==null&&o.delete(r):(a==="retain"&&d(),p===null?delete c[f]:c[f]=p))}o.deleted||(a==="insert"&&d(),_r(s,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Dn extends wt{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new Dn}clone(){const t=new Dn;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const r=new HC(this,t,n);Wi(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===ke&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?X(this.doc,r=>{const s=new Tc(null,this._start,0,new Map);for(let i=0;i0)&&Sc(r,this,s,a,o.attributes||{})}else o.retain!==void 0?Np(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ip(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){const s=[],i=new Map,o=this.doc;let a="",c=this._start;function l(){if(a.length>0){const h={};let d=!1;i.forEach((p,E)=>{d=!0,h[E]=p});const f={insert:a};d&&(f.attributes=h),s.push(f),a=""}}const u=()=>{for(;c!==null;){if(gr(c,t)||n!==void 0&&gr(c,n))switch(c.content.constructor){case ke:{const h=i.get("ychange");t!==void 0&&!gr(c,t)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(l(),i.set("ychange",r?r("removed",c.id):{type:"removed"})):n!==void 0&&!gr(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(l(),i.set("ychange",r?r("added",c.id):{type:"added"})):h!==void 0&&(l(),i.delete("ychange")),a+=c.content.str;break}case Je:case $n:{l();const h={insert:c.content.getContent()[0]};if(i.size>0){const d={};h.attributes=d,i.forEach((f,p)=>{d[p]=f})}s.push(h);break}case dt:gr(c,t)&&(l(),_r(i,c.content));break}c=c.right}l()};return t||n?X(o,h=>{t&&hc(h,t),n&&hc(h,n),u()},"cleanup"):u(),s}insert(t,n,r){if(n.length<=0)return;const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,t,!r);r||(r={},o.currentAttributes.forEach((a,c)=>{r[c]=a})),Sc(i,this,o,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,t,!r);Sc(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;const r=this.doc;r!==null?X(r,s=>{Ip(s,Yi(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,t,!1);o.right!==null&&Np(i,this,o,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?X(this.doc,n=>{Hi(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?X(this.doc,r=>{_c(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return yc(this,t)}getAttributes(){return Tp(this)}_write(t){t.writeTypeRef(uI)}}const VC=e=>new Dn;class Ac{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===yr||n.constructor===Fn)&&n._start!==null)t=n._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Fn extends wt{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Fn}clone(){const t=new Fn;return t.insert(0,this.toArray().map(n=>n instanceof wt?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ac(this,t)}querySelector(t){t=t.toUpperCase();const r=new Ac(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),ln(new Ac(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Wi(this,t,new qC(this,n,t))}toString(){return gp(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){const s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),ms(this,i=>{s.insertBefore(i.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?X(this.doc,r=>{_p(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)X(this.doc,r=>{const s=t&&t instanceof wt?t._item:t;ji(r,this,s,n)});else{const r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw un("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?X(this.doc,r=>{yp(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return pp(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return mp(this,t)}slice(t=0,n=this.length){return dp(this,t,n)}forEach(t){ms(this,t)}_write(t){t.writeTypeRef(fI)}}const YC=e=>new Fn;class yr extends Fn{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new yr(this.nodeName)}clone(){const t=new yr(this.nodeName),n=this.getAttributes();return kN(n,(r,s)=>{typeof r=="string"&&t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof wt?r.clone():r)),t}toString(){const t=this.getAttributes(),n=[],r=[];for(const a in t)r.push(a);r.sort();const s=r.length;for(let a=0;a0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}`}removeAttribute(t){this.doc!==null?X(this.doc,n=>{Hi(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?X(this.doc,r=>{_c(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return yc(this,t)}hasAttribute(t){return Sp(this,t)}getAttributes(t){return t?DC(this,t):Tp(this)}toDOM(t=document,n={},r){const s=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const a=i[o];typeof a=="string"&&s.setAttribute(o,a)}return ms(this,o=>{s.appendChild(o.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(hI),t.writeKey(this.nodeName)}}const zC=e=>new yr(e.readKey());class qC extends Gi{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class zi extends Er{constructor(t){super(),this.hookName=t}_copy(){return new zi(this.hookName)}clone(){const t=new zi(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){const s=n[this.hookName];let i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(dI),t.writeKey(this.hookName)}}const XC=e=>new zi(e.readKey());class qi extends Dn{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new qi}clone(){const t=new qi;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){const s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const n=[];for(const s in t.attributes){const i=[];for(const o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,a)=>o.keys.nodeName=0;s--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(pI)}}const JC=e=>new qi;class wc{constructor(t,n){this.id=t,this.length=n}get deleted(){throw Ce()}mergeWith(t){return!1}write(t,n,r){throw Ce()}integrate(t,n){throw Ce()}}const QC=0;class te extends wc{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),rp(t.doc.store,this)}write(t,n){t.writeInfo(QC),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Es{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Es(this.content)}splice(t){throw Ce()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const ZC=e=>new Es(e.readBuf());class _s{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new _s(this.len)}splice(t){const n=new _s(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Pi(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const tI=e=>new _s(e.readLen()),Lp=(e,t)=>new fr({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ys{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ys(Lp(this.doc.guid,this.opts))}splice(t){throw Ce()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const eI=e=>new ys(Lp(e.readString(),e.readAny()));class $n{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new $n(this.embed)}splice(t){throw Ce()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const nI=e=>new $n(e.readJSON());class dt{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new dt(this.key,this.value)}splice(t){throw Ce()}mergeWith(t){return!1}integrate(t,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const rI=e=>new dt(e.readKey(),e.readJSON());class Xi{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xi(this.arr)}splice(t){const n=new Xi(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const r=this.arr.length;t.writeLen(r-n);for(let s=n;s{const t=e.readLen(),n=[];for(let r=0;r{const t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const oI=e=>new ke(e.readString()),aI=[$C,GC,VC,zC,YC,XC,JC],cI=0,lI=1,uI=2,hI=3,fI=4,dI=5,pI=6;class Je{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Je(this.type._copy())}splice(t){throw Ce()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const gI=e=>new Je(aI[e.readTypeRef()](e)),Ji=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new pt(G(r,s+n),t,G(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=G(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i};class pt extends wc{constructor(t,n,r,s,i,o,a,c){super(t,c.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=a,this.redone=null,this.content=c,this.info=this.content.isCountable()?Ed:0}set marker(t){(this.info&Ha)>0!==t&&(this.info^=Ha)}get marker(){return(this.info&Ha)>0}get keep(){return(this.info&md)>0}set keep(t){this.keep!==t&&(this.info^=md)}get countable(){return(this.info&Ed)>0}get deleted(){return(this.info&ja)>0}set deleted(t){this.deleted!==t&&(this.info^=ja)}markDeleted(){this.info|=ja}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_t(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_t(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===pr&&this.id.client!==this.parent.client&&this.parent.clock>=_t(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sp(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=dn(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===te||this.right&&this.right.constructor===te)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===pt&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===pt&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===pr){const r=fc(n,this.parent);r.constructor===te?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=sp(t,t.doc.store,G(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Di(this.origin,s.origin)){if(s.id.client{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Pi(t.deleteSet,this.id.client,this.id.clock,this.length),ap(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw Ie();this.content.gc(t),n?SC(t,this,new te(this.id,this.length)):this.content=new _s(this.length)}write(t,n){const r=n>0?G(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Oi|(r===null?0:Ht)|(s===null?0:ze)|(i===null?0:os);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){const a=this.parent;if(a._item!==void 0){const c=a._item;if(c===null){const l=TC(a);t.writeParentInfo(!0),t.writeString(l)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else a.constructor===String?(t.writeParentInfo(!0),t.writeString(a)):a.constructor===pr?(t.writeParentInfo(!1),t.writeLeftID(a)):Ie();i!==null&&t.writeString(i)}this.content.write(t,n)}}const Op=(e,t)=>mI[t&Oi](e),mI=[()=>{Ie()},tI,sI,ZC,oI,nI,rI,gI,iI,eI,()=>{Ie()}],EI=10;class ee extends wc{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){Ie()}write(t,n){t.writeInfo(EI),P(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const kp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},bp="__ $YJS$ __";kp[bp]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),kp[bp]=!0;const Rc=0,Mp=1,xp=2,_I=(e,t)=>{P(e,Rc);const n=_C(t);Nt(e,n)},Up=(e,t,n)=>{P(e,Mp),Nt(e,pC(t,n))},yI=(e,t,n)=>Up(t,n,bt(e)),Pp=(e,t,n)=>{try{hC(t,bt(e),n)}catch(r){console.error("Caught error while handling a Yjs update",r)}},TI=(e,t)=>{P(e,xp),Nt(e,t)},SI=Pp,AI=(e,t,n,r)=>{const s=D(e);switch(s){case Rc:yI(e,t,n);break;case Mp:Pp(e,n,r);break;case xp:SI(e,n,r);break;default:throw new Error("Unknown message type")}return s},Tr={},vc={},Nc={},Ts={},be=Rr("shared",["second"],e=>{switch(e.target){case"second":Object.keys(Nc).forEach(t=>{const n=Ts[t];n===void 0?be.emit("shared:join",t):n<10?Ts[t]=n+1:delete Ts[t]}),Object.keys(vc).forEach(t=>{be.emit("shared:active",t)});break;case"join":{const t=e.data,n=Tr[t];if(n&&vc[t]){be.reply(e,"joinack",t);const r=hn();_I(r,n),be.reply(e,"sync",Zi(t,r));const s=hn();Up(s,n),be.reply(e,"sync",Zi(t,s))}break}case"joinack":{const t=e.data;Tr[t]&&Nc[t]&&(Ts[t]=0);break}case"active":{const t=e.data;Tr[t]&&Nc[t]&&(Ts[t]=0);break}case"sync":{const[t,n,r]=e.data,s=Tr[n];if(s&&t!==be.id()){const i=Un(r),o=hn();if(AI(i,o,s,be)===Rc){const c=Zi(n,o);be.emit("shared:sync",c)}}break}}});function wI(e){let t=Tr[e];if(t)return t;Tr[e]=t=new fr({guid:e});function n(r){const s=hn();TI(s,r),be.emit("shared:sync",Zi(e,s))}return t.on("update",n),t.on("destroy",()=>{t==null||t.off("update",n)}),t}function Qi(e){return wI(e).getMap()}function Zi(e,t){const n=fe(t);return[be.id()??"",e,n]}function Dp(e,t){const n=e.get(t);return n!=null&&n.toJSON?n.toJSON():n}function Fp(e,t,n){typeof n=="string"?e.set(t,new Dn(n)):e.set(t,n)}function RI(e,t,n){console.info({guid:e,key:t,value:n}),vc[e]=!0;const r=Qi(e);r.get(t)===void 0&&n!==void 0&&Fp(r,t,n)}function vI(e,t,n){const r=Qi(e),s=Dp(r,t);(s===void 0||n!==s)&&Fp(r,t,n)}function NI(e,t,n){const r=Qi(e);function s(){n(Dp(r,t))}function i(o){o.keysChanged.has(t)&&s()}return s(),r.observe(i),()=>{r.unobserve(i)}}function CI(e,t,n){const r=Qi(e);let s=r.get(t);function i(){n(s)}function o(c){c.keysChanged.has(t)&&s===void 0&&a(),s&&r.unobserve(o)}function a(){s=r.get(t),s?(s.observeDeep(i),i()):r.observe(o)}return a(),()=>{s?s.unobserveDeep(i):r.unobserve(o)}}const mn={};function $p(e,t){return e.player=t,e.layers=[],e.layout=[],e.layoutreset=!0,e.layoutfocus="scroll",e}function Bp(e){e.text=[],Object.values(mn[e.id]??{}).forEach(t=>t==null?void 0:t()),mn[e.id]={}}function Gp(e){const t=e.layout.find(n=>n.name===e.layoutfocus);if(!t){const n={id:Ue(),name:e.layoutfocus,edge:Yt.RIGHT,size:20,text:[]};return e.layout.push(n),e.layoutreset=!1,n}return t}const Cc={},II=new Set(["hk","hotkey","rn","range","sl","select","nm","number","tx","text"]),LI=new Set(["rn","range","sl","select","nm","number","tx","text"]),OI=new Set(["tx","text"]),kI={rn:1,range:1,sl:0,select:0,nm:0,number:0,tx:"",text:""};function Gn(e){let t=Cc[e];return _(t)?t:Cc[e]=t=$p({},e)}function bI(){return Object.keys(Cc)}function MI(e){const t=Gn(e);t.layout=t.layout.filter(n=>n.edge!==Yt.SCROLL)}function xI(e,t,n){Object.values(mn).forEach(r=>{r[t]!==void 0&&vI(e.id(),t,n)})}function UI(e){const t=Gn(e.id());t.layout=t.layout.filter(n=>n.edge!==Yt.SCROLL||n.text.length>0)}function Ic(e,t,n,r,s){const i=Gn(e.id()),o=r,a=s||qv.capital(t),c=i.layout.find(l=>l.name===a);if(c)i.layoutreset=!0,i.layoutfocus=a,Ft(o)&&(c.size=o);else switch(n){case Yt.START:$p(i,e.id());break;case Yt.LEFT:case Yt.RIGHT:case Yt.TOP:case Yt.BOTTOM:case Yt.SCROLL:const l={id:Ue(),name:a,edge:n,size:o??Ng[n],text:[]};i.layout.push(l),i.layoutfocus=a;break}}function PI(e,t){const n=Gn(e.id()),r=Gp(n);n.layoutreset&&(n.layoutreset=!1,Bp(r)),r.text.push(t)}function DI(e,t,n,r){const s=Gn(e.id()),i=Gp(s);s.layoutreset&&(s.layoutreset=!1,Bp(i));const o=n.toLowerCase(),a=[e.id(),t,...II.has(o)?[o]:["hypertext",n],...r],c=a[2];if(LI.has(c)){const l=`${a[3]??""}`;mn[i.id]=mn[i.id]??{};const u=e.get(l);mn[i.id][l]===void 0&&(RI(e.id(),l,u??kI[c]),OI.has(c)?mn[i.id][l]=CI(e.id(),l,h=>{if(h!==void 0){const d=h.toJSON();d!==e.get(l)&&e.set(l,d)}}):mn[i.id][l]=NI(e.id(),l,h=>{h!==void 0&&h!==e.get(l)&&e.set(l,h)}))}i.text.push(a)}const FI=pd({get(){return[!1,void 0]},set(e,t,n){return xI(e,t,n),[!1,void 0]},shouldtick(){},tick(e){var r,s;const t=V(e.id()),n=((r=t.target)==null?void 0:r.name)??((s=t.target)==null?void 0:s.kind)??"Scroll";Ic(e,"scroll",Yt.SCROLL,void 0,n)},tock(e){UI(e)}}).command("color",(e,t)=>{const n=V(e.id()),[r]=I({...n,chip:e,words:t},0,[C.COLOR]);return _(n.target)&&_(r)&&yo(n.target,r),0}).command("gadget",(e,t)=>{const r={...V(e.id()),chip:e,words:t},[s]=I(r,0,[C.STRING]),i=vg[s.toLowerCase()];if(i===Yt.SCROLL){const[,o,a]=I(r,0,[C.STRING,C.MAYBE_STRING,C.MAYBE_NUMBER]);Ic(e,s,i,a,o)}else{const[,o,a]=I(r,0,[C.STRING,C.MAYBE_NUMBER,C.MAYBE_STRING]);Ic(e,s,i,o,a)}return 0}).command("book",(e,t)=>{const n=V(e.id()),[r,s]=I({...n,chip:e,words:t},0,[C.STRING,C.STRING]),i=r.toLowerCase(),o=s.toLowerCase();switch(o){case"create":ef(jh(i,[Re("@board title",{board:qc(a=>a)}),Re("@terrain dirt",{terrain:{char:176,bg:Q.BLACK,color:Q.DKYELLOW,collision:mt.WALK}}),Re("@terrain dirt2",{terrain:{char:176,bg:Q.BLACK,color:Q.DKGRAY,collision:mt.WALK}}),Re("@terrain wall",{terrain:{char:177,bg:Q.DKGREEN,color:Q.GREEN,collision:mt.SOLID}}),Re("@terrain wall2",{terrain:{char:176,bg:Q.DKGREEN,color:Q.GREEN,collision:mt.SOLID}})]));break;default:console.info("book",{ltarget:i,laction:o});break}return 0}).command("frame",(e,t)=>{var c;const n=V(e.id()),[r,s,i]=I({...n,chip:e,words:t},0,[C.STRING,C.MAYBE_STRING,C.MAYBE_STRING]),o=((c=n.board)==null?void 0:c.id)??"",a=r.toLowerCase();if(a==="reset")tf(o);else if(_(s)&&_(i)){const l=s.toLowerCase();switch(l){case"edit":NR(o,a,i);break;case"view":vR(o,a,i);break;default:console.info("frame",{ltype:l,ltarget:a,maybeboard:i});break}}return 0});function Kp(e,t,n,r){if(!_(e)||!_(t)||!_(n))return;const[s,i]=n,o=Hh(e,s);if(_(o)){const c=am(t,r.x,r.y,s);yo(c,i),qh(e,t,c),zh(e,t,c,r.x+r.y*t.width)}const a=Ca(e,s);if(_(a)&&_(a.name)){const c=cm(t,r.x,r.y,s);yo(c,i),qh(e,t,c),zh(e,t,c)}}const Wp=new Set(["cycle","player","sender","inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu","data"]),$I=new Set(["inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu"]);function BI(e){const t=of[e];if(_(t))return t;const n=uf[e];if(_(n))return n;const r=ff[e];if(_(r))return r;const s=wf[e];if(_(s))return s}const GI=["NORTH","SOUTH","WEST","EAST"];function KI(e){const t=V(e.id??"");if(t.inputcurrent!==void 0)return;const[n=ct.NONE]=t.inputqueue;e.stats===void 0&&(e.stats={}),e.stats.inputmove=[],e.stats.inputok=0,e.stats.inputcancel=0,e.stats.inputmenu=0;const r=t.inputmods[n];switch(e.stats.inputalt=r&Cg?1:0,e.stats.inputctrl=r&Ig?1:0,e.stats.inputshift=r&Lg?1:0,n){case ct.MOVE_UP:case ct.MOVE_DOWN:case ct.MOVE_LEFT:case ct.MOVE_RIGHT:e.stats.inputmove=[GI[n-ct.MOVE_UP]];break;case ct.OK_BUTTON:e.stats.inputok=1;break;case ct.CANCEL_BUTTON:e.stats.inputcancel=1;break;case ct.MENU_BUTTON:e.stats.inputmenu=1;break}t.inputcurrent=n,t.inputqueue.delete(n)}function to(e,t,n,r){const s=lt(t)?t:t.id,i=lt(n)?n:n.id;_(s)&&_(i)&&e.send(i,r,s)}function jp(e,t,n,r,s){const i=TR(t,n,r,s);return _(i)&&(r.kind==="player"?(to(e,i,e.id(),"thud"),to(e,e.id(),i,"touch")):(to(e,i,e.id(),"thud"),to(e,e.id(),i,"bump"))),!_(i)}function Hp(e,t){if(lt(e)){const n=e.toLowerCase();switch(n){case"edit":return[n,t+1]}}return[void 0,t]}function Vp(e,t,n){let r;const s=pi((t==null?void 0:t.id)??"");switch(n){case"edit":{r=s.find(a=>a.type===Jr.EDIT);break}}const i=r?Qr((r==null?void 0:r.book)??""):e,o=r?er(i,(r==null?void 0:r.board)??""):t;return{maybebook:i,maybeboard:o}}const WI={zzt:pd({get(e,t){var o;const n=BI(t);if(_(n))return[!0,n];const r=V(e.id());if(r.target){$I.has(t)&&KI(r.target);const a=(o=r.target.stats)==null?void 0:o[t];if(_(a)||Wp.has(t))return[!0,a]}const s=r.board?Ao(r.board,r.target):void 0,i=mR(r.book,(s==null?void 0:s.id)??"",t);return[_(i),i]},set(e,t,n){var i,o;const r=V(e.id());if(_(r.target)&&(_((o=(i=r.target)==null?void 0:i.stats)==null?void 0:o[t])||Wp.has(t)))return r.target.stats||(r.target.stats={}),r.target.stats[t]=n,[!0,n];const s=r.board?Ao(r.board,r.target):void 0;return ER(r.book,(s==null?void 0:s.id)??"",t,n),[!0,n]},shouldtick(e){var n,r,s,i;const t=V(e.id());if((r=(n=t.target)==null?void 0:n.stats)!=null&&r.stepx||(i=(s=t.target)==null?void 0:s.stats)!=null&&i.stepy){const o={x:(t.target.x??0)+(t.target.stats.stepx??0),y:(t.target.y??0)+(t.target.stats.stepy??0)};jp(e,t.book,t.board,t.target,o)}},tick(){},tock(){}}).command("become",(e,t)=>(console.info(t),0)).command("bind",(e,t)=>(console.info(t),0)).command("change",(e,t)=>{const n=V(e.id()),[r,s]=Hp(t[0],0),[i,o]=I({...n,chip:e,words:t},s,[C.KIND,C.KIND]),{maybebook:a,maybeboard:c}=Vp(n.book,n.board,r);La(a,c);const l=ka(i)??"",u=Eo(c,l),h=tm(u,i),d=ka(o),f=Sf(o),p=Af(o);return h.forEach(E=>{if(nr(a,E)===d)_(f)&&(E.color=f),_(p)&&(E.bg=p);else{if(_(E.id))switch(r){case"edit":Jh(a,c,E),So(c,E.id);break;default:Xh(a,c,E,e.timestamp());break}sn(E)&&Kp(a,c,o,E)}}),0}).command("char",(e,t)=>{const n=V(e.id()),[r]=I({...n,chip:e,words:t},0,[C.NUMBER]);return _(n.target)&&(n.target.char=r),0}).command("clear",(e,t)=>{const n=Ye(t[0]);return e.set(n,void 0),0}).command("cycle",(e,t)=>{const n=V(e.id()),[r]=I({...n,chip:e,words:t},0,[C.NUMBER]);return e.cycle(io(Math.round(r),1,255)),0}).command("die",e=>{const t=V(e.id());return Xh(t.book,t.board,t.target,e.timestamp()),e.endofprogram(),0}).command("end",e=>(e.endofprogram(),0)).command("endgame",e=>(e.set("health",0),0)).command("give",(e,t)=>{const n=V(e.id()),[r,s,i]=I({...n,chip:e,words:t},0,[C.STRING,C.MAYBE_NUMBER]),o=e.get(r),a=Ft(o)?o:0,c=s??1;if(!Ft(c))return 0;const l=o===void 0?1:0;return l&&i{const n=V(e.id());if(!_(n.target))return 0;let r=0,s=1;const[i,o]=Rt({...n,chip:e,words:t},0);for(Ft(i)&&(r=o,s=io(Math.round(i),1,1024));s>0;){const[l]=I({...n,chip:e,words:t},r,[C.DIR]);jp(e,n.book,n.board,n.target,l)?--s:s=-1}const a=n.target.x,c=n.target.y;return n.target.x===a&&n.target.y===c?1:0}).command("idle",e=>(e.yield(),0)).command("lock",e=>(e.lock(e.id()),0)).command("play",(e,t)=>(console.info({chip:e,play:t}),0)).command("put",(e,t)=>{const n=V(e.id()),[r,s]=Hp(t[0],0),[i,o]=I({...n,chip:e,words:t},s,[C.DIR,C.KIND]),{maybebook:a,maybeboard:c}=Vp(n.book,n.board,r);return La(a,c),Kp(a,c,o,i),0}).command("restore",(e,t)=>(e.restore(Ye(t[0])),0)).command("send",(e,t)=>{var h,d;const n=V(e.id()),[r,s]=I({...n,chip:e,words:t},0,[C.STRING,C.ANY]),[i,o]=r.split(":"),a=_(o)?i:"self",c=o??i;function l(f){f.forEach(p=>{_(p.id)&&e.send(p.id,c,s)})}const u=a.toLowerCase();switch(u){case"all":for(const f of Object.keys(((h=n.board)==null?void 0:h.objects)??{}))e.send(f,c,s);break;case"self":e.send(e.id(),c,s);break;case"others":for(const f of Object.keys(((d=n.board)==null?void 0:d.objects)??{}))f!==e.id()&&e.send(f,c,s);break;case"player":break;default:{l(_o(n.board,[a]));const f=e.get(u);Array.isArray(f)?l(_o(n.board,f)):l(_o(n.board,[f]));break}}return 0}).command("set",(e,t)=>{const n=V(e.id()),[r,s]=I({...n,chip:e,words:t},0,[C.STRING,C.ANY]);return e.set(r,s),0}).command("shoot",(e,t)=>{const n=V(e.id()),[r,s]=I({...n,chip:e,words:t},0,[C.DIR,C.MAYBE_KIND]);return console.info({dir:r,maybekind:s}),0}).command("take",(e,t)=>{const n=V(e.id()),[r,s,i]=I({...n,chip:e,words:t},0,[C.STRING,C.MAYBE_NUMBER]),o=e.get(r),a=s??1;if(!Ft(o))return 1;const c=o-a;return c<0?(i{const n=V(e.id());return I({...n,chip:e,words:t},0,[C.DIR,C.MAYBE_KIND]),0}).command("try",(e,t)=>{const n=V(e.id()),[,r]=I({...n,chip:e,words:t},0,[C.DIR]);return e.command("go",...t.slice(0,r))&&r(e.unlock(),0)).command("walk",(e,t)=>{var s;const n=V(e.id()),[r]=I({...n,chip:e,words:t},0,[C.DIR]);return _((s=n.target)==null?void 0:s.stats)&&(n.target.stats.stepx=r.x-(n.target.x??0),n.target.stats.stepy=r.y-(n.target.y??0)),0}).command("zap",(e,t)=>(e.zap(Ye(t[0])),0)).command("stat",(e,t)=>{const n=V(e.id());return n.target&&(n.target.name=t.map(Ye).join(" ")),0}).command("text",(e,t)=>{const n=t.map(Ye).join("");return PI(e,n),0}).command("hyperlink",(e,t)=>{const[n,r,...s]=t,i=Ye(n),o=Ye(r);return DI(e,i,o,s),0}),zss:FI};function jI(e){Object.values(WI).forEach(t=>{e.install(t)})}function Lc(e){if(!e||e.type===void 0)return;const t=[{start:e.startOffset,end:e.endOffset||0}];return Object.keys(e).forEach(n=>{if(n!=="parent"){const r=e[n];Array.isArray(r)?r.forEach(s=>{t.push(Lc(s))}):t.push(Lc(r))}}),e.range={start:Math.min(...t.filter(n=>n).map(n=>(n==null?void 0:n.start)||0)),end:Math.max(...t.filter(n=>n).map(n=>(n==null?void 0:n.end)||0))},e.range}function HI(e){const t=Ra(`${e} +`);if(t.errors.length>0)return{errors:t.errors,tokens:[]};is.input=t.tokens;const n=is.program();if(is.errors.length>0)return{tokens:t.tokens,errors:is.errors};const r=Fv.visit(n);return r?(Lc(r),{tokens:t.tokens,cst:n,ast:r}):{tokens:t.tokens,cst:n,errors:["no ast output"]}}const Oc=Object.getPrototypeOf(function*(){}).constructor;function VI(e){const t=HI(e);if(t.errors&&t.errors.length>0)return t;if(!t.ast)return{...t,errors:["no ast output"]};const n=jv(t.ast);if(n.code){aR&&console.info(n.code);try{return{...t,...n,source:n.code,code:new Oc("api",n.code)}}catch(r){return{errors:[{message:r.message}],source:"there was an error",code:new Oc("api"," ")}}}return{...t,...n,source:"there was an error",code:new Oc("api"," ")}}function YI(){const e={},t={};function n(s){const i=e[s];if(i)return i;const o=VI(s);return e[s]=o,o}return{ids(){return Object.keys(t)},has(s){return _(t[s])},halt(s){const i=t[s];return i&&delete t[s],!!i},tick(s,i){var a;let o=t[s];if(!_(t[s])){const c=n(i);if((a=c.errors)!=null&&a.length)return console.error(c.errors),console.info(c.tokens),t[s]=null,!1;o=t[s]=Yv(s,c),jI(o)}return!!(o!=null&&o.tick())},message(s){const{target:i,path:o}=Dc(s.target),a=t[i];_(a)&&a.message({...s,target:o})}}}const zI=Pc(so.numbers,4),qI=Pc(`${so.numbers}${so.lowercase}`,16),Yp=`pid_${zI()}_${qI()}`;RR(Yp);const zp=YI(),XI=32*15,Sr={},JI=Rr("vm",["login","tick","tock"],e=>{switch(e.target){case"login":e.player&&(Sr[e.player]=0,CR(e.player));break;case"tick":LR(zp,e.data);break;case"tock":Object.keys(Sr).forEach(t=>{++Sr[t],Sr[t]>XI&&(delete Sr[t],IR(t))});break;case"doot":e.player&&(Sr[e.player]=0);break;case"input":if(e.player){const t=V(e.player),[n=ct.NONE,r=0]=e.data??{};t.inputqueue.add(n),t.inputmods[n]=r}break;default:zp.message(e);break}});function QI(){ef(_i),JI.emit("ready",void 0,Yp)}const kc=Rr("clock",[],()=>{});let bc=0,qp=performance.now(),Mc=0,eo=0;function ZI(){kc.emit("tick",eo),kc.emit("tock",eo),++Mc,++eo,Mc>=Ro&&(Mc%=Ro,kc.emit("second",eo))}function Xp(){const e=performance.now(),t=e-qp;bc+=t,bc>=wo&&(bc%=wo,ZI()),qp=e,setTimeout(Xp)}Xp();const Jp={},Qp=Rr("gadgetserver",["tock"],e=>{switch(e.target){case"tock":bI().forEach(t=>{const n=Gn(t);n.layers=kR(t);const r=go(Jp[t]??{},n);r.length&&(Jp[t]=It(n),Qp.emit("gadgetclient:patch",r,t))});break;case"desync":if(e.player){const t=Gn(e.player);Qp.emit("gadgetclient:reset",t,e.player)}break;case"clearscroll":e.player&&MI(e.player);break}}),tL=hg(e=>postMessage(e));onmessage=function(t){tL(t.data)},queueMicrotask(QI)})(); diff --git a/assets/instance-LD1NVfuA.js b/assets/instance-LD1NVfuA.js deleted file mode 100644 index f37a1c3ec..000000000 --- a/assets/instance-LD1NVfuA.js +++ /dev/null @@ -1,290 +0,0 @@ -var tL=Object.defineProperty;var nL=(xt,De,_n)=>De in xt?tL(xt,De,{enumerable:!0,configurable:!0,writable:!0,value:_n}):xt[De]=_n;var U=(xt,De,_n)=>(nL(xt,typeof De!="symbol"?De+"":De,_n),_n);(function(){"use strict";const xt=new Set,De={emit(t,e,n,r){De.invoke(cg(t,e,n,r))},invoke(t){xt.forEach(e=>e.handle(t))},connect(t){xt.add(t)},disconnect(t){xt.delete(t)}},_n="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ig=t=>crypto.getRandomValues(new Uint8Array(t)),og=(t,e,n)=>{let r=(2<{let o="";for(;;){let a=n(s),c=s;for(;c--;)if(o+=t[a[c]&r]||"",o.length===i)return o}}},Uc=(t,e=21)=>og(t,e,ig),ag=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=_n[n[t]&63];return e};function Ut(){return ag()}function cg(t,e,n,r){return{id:Ut(),target:t,sender:e,data:n,player:r}}function Pc(t){const[e,...n]=t.split(":");return{target:e,path:n.join(":")}}function wr(t,e,n){const r=Ut(),s=t.toLowerCase(),i=e.map(a=>a.toLowerCase()),o={id(){return r},name(){return t},tags(){return e},emit(a,c,l){De.emit(a,r,c,l)},reply(a,c,l,u){o.emit(`${a.sender}:${c}`,l,u)},handle(a){const{target:c,path:l}=Pc(a.target),u=c.toLowerCase();i.findIndex(h=>h==="all"||h===u)!==-1&&n(a),(r===c||u==="all"||s===u)&&n({...a,target:l})}};return De.connect(o),o}function lg(t){const e=new Set;function n(r){e.has(r.id)||(e.add(r.id),De.invoke(r))}return wr("forward",["all"],r=>{e.has(r.id)||(e.add(r.id),t(r))}),n}var ws=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ro(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function ug(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var n=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:function(){return t[r]}})}),n}var Dc="abcdefghijklmnopqrstuvwxyz",Fc="ABCDEFGHIJKLMNOPQRSTUVWXYZ",$c="0123456789",hg="346789ABCDEFGHJKLMNPQRTUVWXYabcdefghijkmnpqrtwxyz",fg="6789BCDFGHJKLMNPQRTWbcdfghjkmnpqrtwz";const dg=$c,pg=Dc,gg=Fc;var mg=dg+pg+gg,so={lowercase:Dc,uppercase:Fc,numbers:$c,nolookalikes:hg,nolookalikesSafe:fg,alphanumeric:mg};const Bc=32,Eg=33;function Rs(t,e){return new Array(t).fill(e)}function _g(t,e,n,r,s=0){const i=n*r;return{id:`tiles:${t}:${e}`,type:1,width:n,height:r,char:Rs(i,0),color:Rs(i,0),bg:Rs(i,s)}}function yg(t,e,n,r=1,s=15){return{id:`sprites:${t}:${e}:${n}`,x:0,y:0,char:r,color:s,bg:Bc}}function Tg(t,e){return{id:`sprites:${t}:${e}`,type:2,sprites:[]}}function Sg(t,e,n,r,s=0){const i=n*r;return{id:`dither:${t}:${e}`,type:3,width:n,height:r,alphas:Rs(i,s)}}function Ag(t,e){return{id:`control:${t}:${e}`,type:5,focusx:0,focusy:0,focusid:t,viewscale:2}}var Ye=(t=>(t[t.START=0]="START",t[t.LEFT=1]="LEFT",t[t.RIGHT=2]="RIGHT",t[t.TOP=3]="TOP",t[t.BOTTOM=4]="BOTTOM",t[t.SCROLL=5]="SCROLL",t))(Ye||{});const wg={start:0,left:1,right:2,top:3,bottom:4,scroll:5},Rg={0:1,1:20,2:20,3:1,4:1,5:40},vg=1,Ng=16,Cg=256;var ce=(t=>(t[t.NONE=0]="NONE",t[t.MOVE_UP=1]="MOVE_UP",t[t.MOVE_DOWN=2]="MOVE_DOWN",t[t.MOVE_LEFT=3]="MOVE_LEFT",t[t.MOVE_RIGHT=4]="MOVE_RIGHT",t[t.OK_BUTTON=5]="OK_BUTTON",t[t.CANCEL_BUTTON=6]="CANCEL_BUTTON",t[t.MENU_BUTTON=7]="MENU_BUTTON",t))(ce||{}),Gc={exports:{}};(function(t,e){(function(n,r){t.exports=r()})(ws,function(){return n.importState=function(s){var i=new n;return i.importState(s),i},n;function n(){return function(s){var i=0,o=0,a=0,c=1;s.length==0&&(s=[+new Date]);var l=r();i=l(" "),o=l(" "),a=l(" ");for(var u=0;u>>0,c-=s,c*=s,s=c>>>0,c-=s,s+=c*4294967296}return(s>>>0)*23283064365386963e-26};return i.version="Mash 0.9",i}})})(Gc);var Ig=Gc.exports,Lg=ro(Ig);const Og=Lg("089fad0j9awfem09wavefc09uwaef");function io(t,e,n){return Math.max(e,Math.min(n,t))}function kg(){return Og()}function Wn(t,e){const n=Math.min(t,e),s=Math.max(t,e)-n+1;return n+Math.floor(kg()*s)}/*! - * https://github.com/Starcounter-Jack/JSON-Patch - * (c) 2017-2022 Joachim Wester - * MIT licensed - */var bg=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var i in s)s.hasOwnProperty(i)&&(r[i]=s[i])},t(e,n)};return function(e,n){t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),Mg=Object.prototype.hasOwnProperty;function oo(t,e){return Mg.call(t,e)}function ao(t){if(Array.isArray(t)){for(var e=new Array(t.length),n=0;n=48&&r<=57){e++;continue}return!1}return!0}function yn(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function Kc(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function lo(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,n=t.length;e0&&c[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&d===void 0&&(l[f]===void 0?d=c.slice(0,u).join("/"):u==h-1&&(d=e.path),d!==void 0&&p(e,0,t,d)),u++,Array.isArray(l)){if(f==="-")f=l.length;else{if(n&&!co(f))throw new te("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,e,t);co(f)&&(f=~~f)}if(u>=h){if(n&&e.op==="add"&&f>l.length)throw new te("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,e,t);var o=Ug[e.op].call(e,l,f,t);if(o.test===!1)throw new te("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return o}}else if(u>=h){var o=jn[e.op].call(e,l,f,t);if(o.test===!1)throw new te("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return o}if(l=l[f],n&&u0)throw new te('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,n);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new te("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new te("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&lo(t.value))throw new te("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,n);if(n){if(t.op=="add"){var s=t.path.split("/").length,i=r.split("/").length;if(s!==i+1&&s!==i)throw new te("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,n)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==r)throw new te("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,n)}else if(t.op==="move"||t.op==="copy"){var o={op:"_get",path:t.from,value:void 0},a=Hc([o],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new te("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,n)}}}else throw new te("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,n)}function Hc(t,e,n){try{if(!Array.isArray(t))throw new te("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)uo(Ie(e),Ie(t),n||!0);else{n=n||Ns;for(var r=0;r0&&(t.patches=[],t.callback&&t.callback(r)),r}function po(t,e,n,r,s){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var i=ao(e),o=ao(t),a=!1,c=o.length-1;c>=0;c--){var l=o[c],u=t[l];if(oo(e,l)&&!(e[l]===void 0&&u!==void 0&&Array.isArray(e)===!1)){var h=e[l];typeof u=="object"&&u!=null&&typeof h=="object"&&h!=null&&Array.isArray(u)===Array.isArray(h)?po(u,h,n,r+"/"+yn(l),s):u!==h&&(s&&n.push({op:"test",path:r+"/"+yn(l),value:Ie(u)}),n.push({op:"replace",path:r+"/"+yn(l),value:Ie(h)}))}else Array.isArray(t)===Array.isArray(e)?(s&&n.push({op:"test",path:r+"/"+yn(l),value:Ie(u)}),n.push({op:"remove",path:r+"/"+yn(l)}),a=!0):(s&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}))}if(!(!a&&i.length==o.length))for(var c=0;ctypeof i=="string"?t==null?void 0:t.objects[i]:t==null?void 0:t.terrain[i]).filter(y)}function Qg(t,e){const n=Oa(e),r=yf(e),s=Tf(e);return t.filter(i=>!(y(n)&&tm(i)!==n||y(r)&&nm(i)!==r||y(s)&&rm(i)!==s)).filter(y)}function _o(t,e){return y(t)?e.map(n=>{var r;if(typeof n=="string"){const s=t.objects[n];if(y(s))return s;const i=Eo(t,n.toLowerCase());if(i.length)return i}else if(sn(n)&&n.x>=0&&n.x=0&&n.y=0&&e<((t==null?void 0:t.width)??-1))??(n>=0&&n<((t==null?void 0:t.height)??-1))?t==null?void 0:t.terrain[e+n*t.width]:void 0}function im(t,e,n,r){if(!(!y(t)||e<0||e>=t.width||n<0||n>=t.height))return t.terrain[e+n*t.width]=r,r}function om(t,e,n,r){im(t,e,n,{kind:r})}function qc(t,e){if(!y(t)||!y(e))return;const n={...e,id:e.id??Ut()};return t.objects[n.id]=n,n}function am(t,e,n,r){return console.info({kind:r}),{}}function Xc(t,e){if(t)return t.objects[e]}function Ft(t,e){switch(e){case B.NORTH:--t.y;break;case B.SOUTH:++t.y;break;case B.WEST:--t.x;break;case B.EAST:++t.x;break}return t}function Hn(t,e,n){const r=(e==null?void 0:e.x)??0,s=(e==null?void 0:e.y)??0,i={x:r,y:s},o={...i},a=nr({x:(e==null?void 0:e.lx)??i.x,y:(e==null?void 0:e.ly)??i.y},i);for(let c=0;c0){if(++e>=qm)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}function Zm(t){return function(){return t}}var Is=function(){try{var t=An(Object,"defineProperty");return t({},"",{}),t}catch{}}(),eE=Is?function(t,e){return Is(t,"toString",{configurable:!0,enumerable:!1,value:Zm(e),writable:!0})}:Vn,tE=eE,nE=Qm(tE);function al(t,e){for(var n=-1,r=t==null?0:t.length;++n-1}var iE=9007199254740991,oE=/^(?:0|[1-9]\d*)$/;function Ls(t,e){var n=typeof t;return e=e??iE,!!e&&(n=="number"||n!="symbol"&&oE.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=uE}function mt(t){return t!=null&&Lo(t.length)&&!$t(t)}function ks(t,e,n){if(!qe(n))return!1;var r=typeof e;return(r=="number"?mt(n)&&Ls(e,n.length):r=="string"&&e in n)?Ir(n[e],t):!1}function hE(t){return Io(function(e,n){var r=-1,s=n.length,i=s>1?n[s-1]:void 0,o=s>2?n[2]:void 0;for(i=t.length>3&&typeof i=="function"?(s--,i):void 0,o&&ks(n[0],n[1],o)&&(i=s<3?void 0:i,s=1),e=Object(e);++r-1}function v_(t,e){var n=this.__data__,r=xs(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this}function Bt(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e0&&n(a)?e>1?Ds(a,e-1,n,r,s):Uo(s,a):r||(s[s.length]=a)}return s}function it(t){var e=t==null?0:t.length;return e?Ds(t,1):[]}var K_=yl(Object.getPrototypeOf,Object),Al=K_;function wl(t,e,n){var r=-1,s=t.length;e<0&&(e=-e>s?0:s+e),n=n>s?s:n,n<0&&(n+=s),s=e>n?0:n-e>>>0,e>>>=0;for(var i=Array(s);++ra))return!1;var l=i.get(t),u=i.get(e);if(l&&u)return l==e&&u==t;var h=-1,d=!0,f=n&wT?new qn:void 0;for(i.set(t,e),i.set(e,t);++h2?e[2]:void 0;for(s&&ks(e[0],e[1],s)&&(r=1);++n=gS&&(i=Ko,o=!1,e=new qn(e));e:for(;++s-1?s[i?e[o]:o]:void 0}}var SS=Math.max;function AS(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var s=n==null?0:Cr(n);return s<0&&(s=SS(r+s,0)),cl(t,_t(e),s)}var Jn=TS(AS);function at(t){return t&&t.length?t[0]:void 0}function wS(t,e){var n=-1,r=mt(t)?Array(t.length):[];return vn(t,function(s,i,o){r[++n]=e(s,i,o)}),r}function L(t,e){var n=W(t)?Nr:wS;return n(t,_t(e))}function Je(t,e){return Ds(L(t,e),1)}var RS=Object.prototype,vS=RS.hasOwnProperty,NS=dS(function(t,e,n){vS.call(t,n)?t[n].push(e):Co(t,n,[e])}),CS=Object.prototype,IS=CS.hasOwnProperty;function LS(t,e){return t!=null&&IS.call(t,e)}function k(t,e){return t!=null&&Zl(t,e,LS)}var OS="[object String]";function Me(t){return typeof t=="string"||!W(t)&&st(t)&&en(t)==OS}function kS(t,e){return Nr(e,function(n){return t[n]})}function he(t){return t==null?[]:kS(t,$e(t))}var bS=Math.max;function Le(t,e,n,r){t=mt(t)?t:he(t),n=n&&!r?Cr(n):0;var s=t.length;return n<0&&(n=bS(s+n,0)),Me(t)?n<=s&&t.indexOf(e,n)>-1:!!s&&No(t,e,n)>-1}var MS=Math.max;function su(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var s=n==null?0:Cr(n);return s<0&&(s=MS(r+s,0)),No(t,e,s)}var xS="[object Map]",US="[object Set]",PS=Object.prototype,DS=PS.hasOwnProperty;function z(t){if(t==null)return!0;if(mt(t)&&(W(t)||typeof t=="string"||typeof t.splice=="function"||kr(t)||ko(t)||bs(t)))return!t.length;var e=zn(t);if(e==xS||e==US)return!t.size;if(Or(t))return!Tl(t).length;for(var n in t)if(DS.call(t,n))return!1;return!0}var FS="[object RegExp]";function $S(t){return st(t)&&en(t)==FS}var iu=tn&&tn.isRegExp,Kt=iu?br(iu):$S;function Wt(t){return t===void 0}var BS="Expected a function";function GS(t){if(typeof t!="function")throw new TypeError(BS);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}function KS(t,e,n,r){if(!qe(t))return t;e=Ps(e,t);for(var s=-1,i=e.length,o=i-1,a=t;a!=null&&++s=zS){var l=e?null:YS(t);if(l)return Wo(l);o=!1,s=Ko,c=new qn}else c=e?[]:a;e:for(;++r{n.accept(e)})}}class Ke extends yt{constructor(e){super([]),this.idx=1,Be(this,ct(e,n=>n!==void 0))}set definition(e){}get definition(){return this.referencedRule!==void 0?this.referencedRule.definition:[]}accept(e){e.visit(this)}}class Qn extends yt{constructor(e){super(e.definition),this.orgText="",Be(this,ct(e,n=>n!==void 0))}}class xe extends yt{constructor(e){super(e.definition),this.ignoreAmbiguities=!1,Be(this,ct(e,n=>n!==void 0))}}class Ue extends yt{constructor(e){super(e.definition),this.idx=1,Be(this,ct(e,n=>n!==void 0))}}class Tt extends yt{constructor(e){super(e.definition),this.idx=1,Be(this,ct(e,n=>n!==void 0))}}class St extends yt{constructor(e){super(e.definition),this.idx=1,Be(this,ct(e,n=>n!==void 0))}}class fe extends yt{constructor(e){super(e.definition),this.idx=1,Be(this,ct(e,n=>n!==void 0))}}class lt extends yt{constructor(e){super(e.definition),this.idx=1,Be(this,ct(e,n=>n!==void 0))}}class ut extends yt{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){super(e.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Be(this,ct(e,n=>n!==void 0))}}class Z{constructor(e){this.idx=1,Be(this,ct(e,n=>n!==void 0))}accept(e){e.visit(this)}}function QS(t){return L(t,Ws)}function Ws(t){function e(n){return L(n,Ws)}if(t instanceof Ke){const n={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};return Me(t.label)&&(n.label=t.label),n}else{if(t instanceof xe)return{type:"Alternative",definition:e(t.definition)};if(t instanceof Ue)return{type:"Option",idx:t.idx,definition:e(t.definition)};if(t instanceof Tt)return{type:"RepetitionMandatory",idx:t.idx,definition:e(t.definition)};if(t instanceof St)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:Ws(new Z({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof lt)return{type:"RepetitionWithSeparator",idx:t.idx,separator:Ws(new Z({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof fe)return{type:"Repetition",idx:t.idx,definition:e(t.definition)};if(t instanceof ut)return{type:"Alternation",idx:t.idx,definition:e(t.definition)};if(t instanceof Z){const n={type:"Terminal",name:t.terminalType.name,label:XS(t.terminalType),idx:t.idx};Me(t.label)&&(n.terminalLabel=t.label);const r=t.terminalType.PATTERN;return t.terminalType.PATTERN&&(n.pattern=Kt(r)?r.source:r),n}else{if(t instanceof Qn)return{type:"Rule",name:t.name,orgText:t.orgText,definition:e(t.definition)};throw Error("non exhaustive match")}}}class Zn{visit(e){const n=e;switch(n.constructor){case Ke:return this.visitNonTerminal(n);case xe:return this.visitAlternative(n);case Ue:return this.visitOption(n);case Tt:return this.visitRepetitionMandatory(n);case St:return this.visitRepetitionMandatoryWithSeparator(n);case lt:return this.visitRepetitionWithSeparator(n);case fe:return this.visitRepetition(n);case ut:return this.visitAlternation(n);case Z:return this.visitTerminal(n);case Qn:return this.visitRule(n);default:throw Error("non exhaustive match")}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}}function ZS(t){return t instanceof xe||t instanceof Ue||t instanceof fe||t instanceof Tt||t instanceof St||t instanceof lt||t instanceof Z||t instanceof Qn}function js(t,e=[]){return t instanceof Ue||t instanceof fe||t instanceof lt?!0:t instanceof ut?ou(t.definition,r=>js(r,e)):t instanceof Ke&&Le(e,t)?!1:t instanceof yt?(t instanceof Ke&&e.push(t),ot(t.definition,r=>js(r,e))):!1}function eA(t){return t instanceof ut}function At(t){if(t instanceof Ke)return"SUBRULE";if(t instanceof Ue)return"OPTION";if(t instanceof ut)return"OR";if(t instanceof Tt)return"AT_LEAST_ONE";if(t instanceof St)return"AT_LEAST_ONE_SEP";if(t instanceof lt)return"MANY_SEP";if(t instanceof fe)return"MANY";if(t instanceof Z)return"CONSUME";throw Error("non exhaustive match")}class Hs{walk(e,n=[]){b(e.definition,(r,s)=>{const i=Ae(e.definition,s+1);if(r instanceof Ke)this.walkProdRef(r,i,n);else if(r instanceof Z)this.walkTerminal(r,i,n);else if(r instanceof xe)this.walkFlat(r,i,n);else if(r instanceof Ue)this.walkOption(r,i,n);else if(r instanceof Tt)this.walkAtLeastOne(r,i,n);else if(r instanceof St)this.walkAtLeastOneSep(r,i,n);else if(r instanceof lt)this.walkManySep(r,i,n);else if(r instanceof fe)this.walkMany(r,i,n);else if(r instanceof ut)this.walkOr(r,i,n);else throw Error("non exhaustive match")})}walkTerminal(e,n,r){}walkProdRef(e,n,r){}walkFlat(e,n,r){const s=n.concat(r);this.walk(e,s)}walkOption(e,n,r){const s=n.concat(r);this.walk(e,s)}walkAtLeastOne(e,n,r){const s=[new Ue({definition:e.definition})].concat(n,r);this.walk(e,s)}walkAtLeastOneSep(e,n,r){const s=uu(e,n,r);this.walk(e,s)}walkMany(e,n,r){const s=[new Ue({definition:e.definition})].concat(n,r);this.walk(e,s)}walkManySep(e,n,r){const s=uu(e,n,r);this.walk(e,s)}walkOr(e,n,r){const s=n.concat(r);b(e.definition,i=>{const o=new xe({definition:[i]});this.walk(o,s)})}}function uu(t,e,n){return[new Ue({definition:[new Z({terminalType:t.separator})].concat(t.definition)})].concat(e,n)}function $r(t){if(t instanceof Ke)return $r(t.referencedRule);if(t instanceof Z)return rA(t);if(ZS(t))return tA(t);if(eA(t))return nA(t);throw Error("non exhaustive match")}function tA(t){let e=[];const n=t.definition;let r=0,s=n.length>r,i,o=!0;for(;s&&o;)i=n[r],o=js(i),e=e.concat($r(i)),r=r+1,s=n.length>r;return Yo(e)}function nA(t){const e=L(t.definition,n=>$r(n));return Yo(it(e))}function rA(t){return[t.terminalType]}const hu="_~IN~_";class sA extends Hs{constructor(e){super(),this.topProd=e,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(e,n,r){}walkProdRef(e,n,r){const s=oA(e.referencedRule,e.idx)+this.topProd.name,i=n.concat(r),o=new xe({definition:i}),a=$r(o);this.follows[s]=a}}function iA(t){const e={};return b(t,n=>{const r=new sA(n).startWalking();Be(e,r)}),e}function oA(t,e){return t.name+e+hu}function M(t){return t.charCodeAt(0)}function qo(t,e){Array.isArray(t)?t.forEach(function(n){e.push(n)}):e.push(t)}function Br(t,e){if(t[e]===!0)throw"duplicate flag "+e;t[e],t[e]=!0}function er(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function aA(){throw Error("Internal Error - Should never get here!")}function fu(t){return t.type==="Character"}const Vs=[];for(let t=M("0");t<=M("9");t++)Vs.push(t);const Ys=[M("_")].concat(Vs);for(let t=M("a");t<=M("z");t++)Ys.push(t);for(let t=M("A");t<=M("Z");t++)Ys.push(t);const du=[M(" "),M("\f"),M(` -`),M("\r"),M(" "),M("\v"),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M(" "),M("\u2028"),M("\u2029"),M(" "),M(" "),M(" "),M("\uFEFF")],cA=/[0-9a-fA-F]/,zs=/[0-9]/,lA=/[1-9]/;class uA{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx}pattern(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar("/");const n=this.disjunction();this.consumeChar("/");const r={type:"Flags",loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case"g":Br(r,"global");break;case"i":Br(r,"ignoreCase");break;case"m":Br(r,"multiLine");break;case"u":Br(r,"unicode");break;case"y":Br(r,"sticky");break}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:r,value:n,loc:this.loc(0)}}disjunction(){const e=[],n=this.idx;for(e.push(this.alternative());this.peekChar()==="|";)this.consumeChar("|"),e.push(this.alternative());return{type:"Disjunction",value:e,loc:this.loc(n)}}alternative(){const e=[],n=this.idx;for(;this.isTerm();)e.push(this.term());return{type:"Alternative",value:e,loc:this.loc(n)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){const e=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(e)};case"$":return{type:"EndAnchor",loc:this.loc(e)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(e)};case"B":return{type:"NonWordBoundary",loc:this.loc(e)}}throw Error("Invalid Assertion Escape");case"(":this.consumeChar("?");let n;switch(this.popChar()){case"=":n="Lookahead";break;case"!":n="NegativeLookahead";break}er(n);const r=this.disjunction();return this.consumeChar(")"),{type:n,value:r,loc:this.loc(e)}}return aA()}quantifier(e=!1){let n;const r=this.idx;switch(this.popChar()){case"*":n={atLeast:0,atMost:1/0};break;case"+":n={atLeast:1,atMost:1/0};break;case"?":n={atLeast:0,atMost:1};break;case"{":const s=this.integerIncludingZero();switch(this.popChar()){case"}":n={atLeast:s,atMost:s};break;case",":let i;this.isDigit()?(i=this.integerIncludingZero(),n={atLeast:s,atMost:i}):n={atLeast:s,atMost:1/0},this.consumeChar("}");break}if(e===!0&&n===void 0)return;er(n);break}if(!(e===!0&&n===void 0)&&er(n))return this.peekChar(0)==="?"?(this.consumeChar("?"),n.greedy=!1):n.greedy=!0,n.type="Quantifier",n.loc=this.loc(r),n}atom(){let e;const n=this.idx;switch(this.peekChar()){case".":e=this.dotAll();break;case"\\":e=this.atomEscape();break;case"[":e=this.characterClass();break;case"(":e=this.group();break}if(e===void 0&&this.isPatternCharacter()&&(e=this.patternCharacter()),er(e))return e.loc=this.loc(n),this.isQuantifier()&&(e.quantifier=this.quantifier()),e}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[M(` -`),M("\r"),M("\u2028"),M("\u2029")]}}atomEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:"GroupBackReference",value:this.positiveInteger()}}characterClassEscape(){let e,n=!1;switch(this.popChar()){case"d":e=Vs;break;case"D":e=Vs,n=!0;break;case"s":e=du;break;case"S":e=du,n=!0;break;case"w":e=Ys;break;case"W":e=Ys,n=!0;break}if(er(e))return{type:"Set",value:e,complement:n}}controlEscapeAtom(){let e;switch(this.popChar()){case"f":e=M("\f");break;case"n":e=M(` -`);break;case"r":e=M("\r");break;case"t":e=M(" ");break;case"v":e=M("\v");break}if(er(e))return{type:"Character",value:e}}controlLetterEscapeAtom(){this.consumeChar("c");const e=this.popChar();if(/[a-zA-Z]/.test(e)===!1)throw Error("Invalid ");return{type:"Character",value:e.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:M("\0")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){const e=this.popChar();return{type:"Character",value:M(e)}}classPatternCharacterAtom(){switch(this.peekChar()){case` -`:case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:const e=this.popChar();return{type:"Character",value:M(e)}}}characterClass(){const e=[];let n=!1;for(this.consumeChar("["),this.peekChar(0)==="^"&&(this.consumeChar("^"),n=!0);this.isClassAtom();){const r=this.classAtom();if(r.type,fu(r)&&this.isRangeDash()){this.consumeChar("-");const s=this.classAtom();if(s.type,fu(s)){if(s.value=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(e){return{begin:e,end:this.idx}}}class Xo{visitChildren(e){for(const n in e){const r=e[n];e.hasOwnProperty(n)&&(r.type!==void 0?this.visit(r):Array.isArray(r)&&r.forEach(s=>{this.visit(s)},this))}}visit(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e);break}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}}let qs={};const hA=new uA;function Xs(t){const e=t.toString();if(qs.hasOwnProperty(e))return qs[e];{const n=hA.pattern(e);return qs[e]=n,n}}function fA(){qs={}}const pu="Complement Sets are not supported for first char optimization",Js=`Unable to use "first char" lexer optimizations: -`;function dA(t,e=!1){try{const n=Xs(t);return Jo(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===pu)e&&au(`${Js} Unable to optimize: < ${t.toString()} > - Complement Sets cannot be automatically optimized. - This will disable the lexer's first char optimizations. - See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let r="";e&&(r=` - This will disable the lexer's first char optimizations. - See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),zo(`${Js} - Failed parsing: < ${t.toString()} > - Using the @chevrotain/regexp-to-ast library - Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+r)}}return[]}function Jo(t,e,n){switch(t.type){case"Disjunction":for(let s=0;s{if(typeof c=="number")Qs(c,e,n);else{const l=c;if(n===!0)for(let u=l.from;u<=l.to;u++)Qs(u,e,n);else{for(let u=l.from;u<=l.to&&u=Kr){const u=l.from>=Kr?l.from:Kr,h=l.to,d=nn(u),f=nn(h);for(let p=d;p<=f;p++)e[p]=p}}}});break;case"Group":Jo(o.value,e,n);break;default:throw Error("Non Exhaustive Match")}const a=o.quantifier!==void 0&&o.quantifier.atLeast===0;if(o.type==="Group"&&Qo(o)===!1||o.type!=="Group"&&a===!1)break}break;default:throw Error("non exhaustive match!")}return he(e)}function Qs(t,e,n){const r=nn(t);e[r]=r,n===!0&&pA(t,e)}function pA(t,e){const n=String.fromCharCode(t),r=n.toUpperCase();if(r!==n){const s=nn(r.charCodeAt(0));e[s]=s}else{const s=n.toLowerCase();if(s!==n){const i=nn(s.charCodeAt(0));e[i]=i}}}function gu(t,e){return Jn(t.value,n=>{if(typeof n=="number")return Le(e,n);{const r=n;return Jn(e,s=>r.from<=s&&s<=r.to)!==void 0}})}function Qo(t){const e=t.quantifier;return e&&e.atLeast===0?!0:t.value?W(t.value)?ot(t.value,Qo):Qo(t.value):!1}class gA extends Xo{constructor(e){super(),this.targetCharCodes=e,this.found=!1}visitChildren(e){if(this.found!==!0){switch(e.type){case"Lookahead":this.visitLookahead(e);return;case"NegativeLookahead":this.visitNegativeLookahead(e);return}super.visitChildren(e)}}visitCharacter(e){Le(this.targetCharCodes,e.value)&&(this.found=!0)}visitSet(e){e.complement?gu(e,this.targetCharCodes)===void 0&&(this.found=!0):gu(e,this.targetCharCodes)!==void 0&&(this.found=!0)}}function Zo(t,e){if(e instanceof RegExp){const n=Xs(e),r=new gA(t);return r.visit(n),r.found}else return Jn(e,n=>Le(t,n.charCodeAt(0)))!==void 0}const Nn="PATTERN",Gr="defaultMode",Zs="modes";let mu=typeof new RegExp("(?:)").sticky=="boolean";function mA(t,e){e=Vo(e,{useSticky:mu,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",` -`],tracer:(R,_)=>_()});const n=e.tracer;n("initCharCodeToOptimizedIndexMap",()=>{$A()});let r;n("Reject Lexer.NA",()=>{r=Ks(t,R=>R[Nn]===ge.NA)});let s=!1,i;n("Transform Patterns",()=>{s=!1,i=L(r,R=>{const _=R[Nn];if(Kt(_)){const N=_.source;return N.length===1&&N!=="^"&&N!=="$"&&N!=="."&&!_.ignoreCase?N:N.length===2&&N[0]==="\\"&&!Le(["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"],N[1])?N[1]:e.useSticky?_u(_):Eu(_)}else{if($t(_))return s=!0,{exec:_};if(typeof _=="object")return s=!0,_;if(typeof _=="string"){if(_.length===1)return _;{const N=_.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),T=new RegExp(N);return e.useSticky?_u(T):Eu(T)}}else throw Error("non exhaustive match")}})});let o,a,c,l,u;n("misc mapping",()=>{o=L(r,R=>R.tokenTypeIdx),a=L(r,R=>{const _=R.GROUP;if(_!==ge.SKIPPED){if(Me(_))return _;if(Wt(_))return!1;throw Error("non exhaustive match")}}),c=L(r,R=>{const _=R.LONGER_ALT;if(_)return W(_)?L(_,T=>su(r,T)):[su(r,_)]}),l=L(r,R=>R.PUSH_MODE),u=L(r,R=>k(R,"POP_MODE"))});let h;n("Line Terminator Handling",()=>{const R=Su(e.lineTerminatorCharacters);h=L(r,_=>!1),e.positionTracking!=="onlyOffset"&&(h=L(r,_=>k(_,"LINE_BREAKS")?!!_.LINE_BREAKS:Tu(_,R)===!1&&Zo(R,_.PATTERN)))});let d,f,p,E;n("Misc Mapping #2",()=>{d=L(r,yu),f=L(i,PA),p=Ge(r,(R,_)=>{const N=_.GROUP;return Me(N)&&N!==ge.SKIPPED&&(R[N]=[]),R},{}),E=L(i,(R,_)=>({pattern:i[_],longerAlt:c[_],canLineTerminator:h[_],isCustom:d[_],short:f[_],group:a[_],push:l[_],pop:u[_],tokenTypeIdx:o[_],tokenType:r[_]}))});let w=!0,A=[];return e.safeMode||n("First Char Optimization",()=>{A=Ge(r,(R,_,N)=>{if(typeof _.PATTERN=="string"){const T=_.PATTERN.charCodeAt(0),m=nn(T);ea(R,m,E[N])}else if(W(_.START_CHARS_HINT)){let T;b(_.START_CHARS_HINT,m=>{const g=typeof m=="string"?m.charCodeAt(0):m,S=nn(g);T!==S&&(T=S,ea(R,S,E[N]))})}else if(Kt(_.PATTERN))if(_.PATTERN.unicode)w=!1,e.ensureOptimizations&&zo(`${Js} Unable to analyze < ${_.PATTERN.toString()} > pattern. - The regexp unicode flag is not currently supported by the regexp-to-ast library. - This will disable the lexer's first char optimizations. - For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{const T=dA(_.PATTERN,e.ensureOptimizations);z(T)&&(w=!1),b(T,m=>{ea(R,m,E[N])})}else e.ensureOptimizations&&zo(`${Js} TokenType: <${_.name}> is using a custom token pattern without providing parameter. - This will disable the lexer's first char optimizations. - For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),w=!1;return R},[])}),{emptyGroups:p,patternIdxToConfig:E,charCodeToPatternIdxToConfig:A,hasCustom:s,canBeOptimized:w}}function EA(t,e){let n=[];const r=yA(t);n=n.concat(r.errors);const s=TA(r.valid),i=s.valid;return n=n.concat(s.errors),n=n.concat(_A(i)),n=n.concat(IA(i)),n=n.concat(LA(i,e)),n=n.concat(OA(i)),n}function _A(t){let e=[];const n=Xe(t,r=>Kt(r[Nn]));return e=e.concat(AA(n)),e=e.concat(vA(n)),e=e.concat(NA(n)),e=e.concat(CA(n)),e=e.concat(wA(n)),e}function yA(t){const e=Xe(t,s=>!k(s,Nn)),n=L(e,s=>({message:"Token Type: ->"+s.name+"<- missing static 'PATTERN' property",type:ne.MISSING_PATTERN,tokenTypes:[s]})),r=Gs(t,e);return{errors:n,valid:r}}function TA(t){const e=Xe(t,s=>{const i=s[Nn];return!Kt(i)&&!$t(i)&&!k(i,"exec")&&!Me(i)}),n=L(e,s=>({message:"Token Type: ->"+s.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:ne.INVALID_PATTERN,tokenTypes:[s]})),r=Gs(t,e);return{errors:n,valid:r}}const SA=/[^\\][$]/;function AA(t){class e extends Xo{constructor(){super(...arguments),this.found=!1}visitEndAnchor(i){this.found=!0}}const n=Xe(t,s=>{const i=s.PATTERN;try{const o=Xs(i),a=new e;return a.visit(o),a.found}catch{return SA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: - Token Type: ->`+s.name+`<- static 'PATTERN' cannot contain end of input anchor '$' - See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:ne.EOI_ANCHOR_FOUND,tokenTypes:[s]}))}function wA(t){const e=Xe(t,r=>r.PATTERN.test(""));return L(e,r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' must not match an empty string",type:ne.EMPTY_MATCH_PATTERN,tokenTypes:[r]}))}const RA=/[^\\[][\^]|^\^/;function vA(t){class e extends Xo{constructor(){super(...arguments),this.found=!1}visitStartAnchor(i){this.found=!0}}const n=Xe(t,s=>{const i=s.PATTERN;try{const o=Xs(i),a=new e;return a.visit(o),a.found}catch{return RA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: - Token Type: ->`+s.name+`<- static 'PATTERN' cannot contain start of input anchor '^' - See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:ne.SOI_ANCHOR_FOUND,tokenTypes:[s]}))}function NA(t){const e=Xe(t,r=>{const s=r[Nn];return s instanceof RegExp&&(s.multiline||s.global)});return L(e,r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:ne.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[r]}))}function CA(t){const e=[];let n=L(t,i=>Ge(t,(o,a)=>(i.PATTERN.source===a.PATTERN.source&&!Le(e,a)&&a.PATTERN!==ge.NA&&(e.push(a),o.push(a)),o),[]));n=Dr(n);const r=Xe(n,i=>i.length>1);return L(r,i=>{const o=L(i,c=>c.name);return{message:`The same RegExp pattern ->${at(i).PATTERN}<-has been used in all of the following Token Types: ${o.join(", ")} <-`,type:ne.DUPLICATE_PATTERNS_FOUND,tokenTypes:i}})}function IA(t){const e=Xe(t,r=>{if(!k(r,"GROUP"))return!1;const s=r.GROUP;return s!==ge.SKIPPED&&s!==ge.NA&&!Me(s)});return L(e,r=>({message:"Token Type: ->"+r.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:ne.INVALID_GROUP_TYPE_FOUND,tokenTypes:[r]}))}function LA(t,e){const n=Xe(t,s=>s.PUSH_MODE!==void 0&&!Le(e,s.PUSH_MODE));return L(n,s=>({message:`Token Type: ->${s.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${s.PUSH_MODE}<-which does not exist`,type:ne.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[s]}))}function OA(t){const e=[],n=Ge(t,(r,s,i)=>{const o=s.PATTERN;return o===ge.NA||(Me(o)?r.push({str:o,idx:i,tokenType:s}):Kt(o)&&bA(o)&&r.push({str:o.source,idx:i,tokenType:s})),r},[]);return b(t,(r,s)=>{b(n,({str:i,idx:o,tokenType:a})=>{if(s${a.name}<- can never be matched. -Because it appears AFTER the Token Type ->${r.name}<-in the lexer's definition. -See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;e.push({message:c,type:ne.UNREACHABLE_PATTERN,tokenTypes:[r,a]})}})}),e}function kA(t,e){if(Kt(e)){const n=e.exec(t);return n!==null&&n.index===0}else{if($t(e))return e(t,0,[],{});if(k(e,"exec"))return e.exec(t,0,[],{});if(typeof e=="string")return e===t;throw Error("non exhaustive match")}}function bA(t){return Jn([".","\\","[","]","|","^","$","(",")","?","*","+","{"],n=>t.source.indexOf(n)!==-1)===void 0}function Eu(t){const e=t.ignoreCase?"i":"";return new RegExp(`^(?:${t.source})`,e)}function _u(t){const e=t.ignoreCase?"iy":"y";return new RegExp(`${t.source}`,e)}function MA(t,e,n){const r=[];return k(t,Gr)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+Gr+`> property in its definition -`,type:ne.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),k(t,Zs)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+Zs+`> property in its definition -`,type:ne.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),k(t,Zs)&&k(t,Gr)&&!k(t.modes,t.defaultMode)&&r.push({message:`A MultiMode Lexer cannot be initialized with a ${Gr}: <${t.defaultMode}>which does not exist -`,type:ne.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),k(t,Zs)&&b(t.modes,(s,i)=>{b(s,(o,a)=>{if(Wt(o))r.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${i}> at index: <${a}> -`,type:ne.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED});else if(k(o,"LONGER_ALT")){const c=W(o.LONGER_ALT)?o.LONGER_ALT:[o.LONGER_ALT];b(c,l=>{!Wt(l)&&!Le(s,l)&&r.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${l.name}> on token <${o.name}> outside of mode <${i}> -`,type:ne.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})}})}),r}function xA(t,e,n){const r=[];let s=!1;const i=Dr(it(he(t.modes))),o=Ks(i,c=>c[Nn]===ge.NA),a=Su(n);return e&&b(o,c=>{const l=Tu(c,a);if(l!==!1){const h={message:FA(c,l),type:l.issue,tokenType:c};r.push(h)}else k(c,"LINE_BREAKS")?c.LINE_BREAKS===!0&&(s=!0):Zo(a,c.PATTERN)&&(s=!0)}),e&&!s&&r.push({message:`Warning: No LINE_BREAKS Found. - This Lexer has been defined to track line and column information, - But none of the Token Types can be identified as matching a line terminator. - See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS - for details.`,type:ne.NO_LINE_BREAKS_FLAGS}),r}function UA(t){const e={},n=$e(t);return b(n,r=>{const s=t[r];if(W(s))e[r]=[];else throw Error("non exhaustive match")}),e}function yu(t){const e=t.PATTERN;if(Kt(e))return!1;if($t(e))return!0;if(k(e,"exec"))return!0;if(Me(e))return!1;throw Error("non exhaustive match")}function PA(t){return Me(t)&&t.length===1?t.charCodeAt(0):!1}const DA={test:function(t){const e=t.length;for(let n=this.lastIndex;n Token Type - Root cause: ${e.errMsg}. - For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(e.issue===ne.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the option. - The problem is in the <${t.name}> Token Type - For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error("non exhaustive match")}function Su(t){return L(t,n=>Me(n)?n.charCodeAt(0):n)}function ea(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}const Kr=256;let ei=[];function nn(t){return t255?255+~~(t/255):t}}function Wr(t,e){const n=t.tokenTypeIdx;return n===e.tokenTypeIdx?!0:e.isParent===!0&&e.categoryMatchesMap[n]===!0}function ti(t,e){return t.tokenTypeIdx===e.tokenTypeIdx}let Au=1;const wu={};function jr(t){const e=BA(t);GA(e),WA(e),KA(e),b(e,n=>{n.isParent=n.categoryMatches.length>0})}function BA(t){let e=Se(t),n=t,r=!0;for(;r;){n=Dr(it(L(n,i=>i.CATEGORIES)));const s=Gs(n,e);e=e.concat(s),z(s)?r=!1:n=s}return e}function GA(t){b(t,e=>{vu(e)||(wu[Au]=e,e.tokenTypeIdx=Au++),Nu(e)&&!W(e.CATEGORIES)&&(e.CATEGORIES=[e.CATEGORIES]),Nu(e)||(e.CATEGORIES=[]),jA(e)||(e.categoryMatches=[]),HA(e)||(e.categoryMatchesMap={})})}function KA(t){b(t,e=>{e.categoryMatches=[],b(e.categoryMatchesMap,(n,r)=>{e.categoryMatches.push(wu[r].tokenTypeIdx)})})}function WA(t){b(t,e=>{Ru([],e)})}function Ru(t,e){b(t,n=>{e.categoryMatchesMap[n.tokenTypeIdx]=!0}),b(e.CATEGORIES,n=>{const r=t.concat(e);Le(r,n)||Ru(r,n)})}function vu(t){return k(t,"tokenTypeIdx")}function Nu(t){return k(t,"CATEGORIES")}function jA(t){return k(t,"categoryMatches")}function HA(t){return k(t,"categoryMatchesMap")}function VA(t){return k(t,"tokenTypeIdx")}const YA={buildUnableToPopLexerModeMessage(t){return`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(t,e,n,r,s){return`unexpected character: ->${t.charAt(e)}<- at offset: ${e}, skipped ${n} characters.`}};var ne;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(ne||(ne={}));const Hr={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[` -`,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:YA,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(Hr);class ge{constructor(e,n=Hr){if(this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(s,i)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;const o=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent <${s}>`);const{time:a,value:c}=cu(i),l=a>10?console.warn:console.log;return this.traceInitIndent time: ${a}ms`),this.traceInitIndent--,c}else return i()},typeof n=="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object. -a boolean 2nd argument is no longer supported`);this.config=Be({},Hr,n);const r=this.config.traceInitPerf;r===!0?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof r=="number"&&(this.traceInitMaxIdent=r,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let s,i=!0;this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===Hr.lineTerminatorsPattern)this.config.lineTerminatorsPattern=DA;else if(this.config.lineTerminatorCharacters===Hr.lineTerminatorCharacters)throw Error(`Error: Missing property on the Lexer config. - For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(n.safeMode&&n.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),W(e)?s={modes:{defaultMode:Se(e)},defaultMode:Gr}:(i=!1,s=Se(e))}),this.config.skipValidations===!1&&(this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(MA(s,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(xA(s,this.trackStartLines,this.config.lineTerminatorCharacters))})),s.modes=s.modes?s.modes:{},b(s.modes,(a,c)=>{s.modes[c]=Ks(a,l=>Wt(l))});const o=$e(s.modes);if(b(s.modes,(a,c)=>{this.TRACE_INIT(`Mode: <${c}> processing`,()=>{if(this.modes.push(c),this.config.skipValidations===!1&&this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(EA(a,o))}),z(this.lexerDefinitionErrors)){jr(a);let l;this.TRACE_INIT("analyzeTokenTypes",()=>{l=mA(a,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:n.positionTracking,ensureOptimizations:n.ensureOptimizations,safeMode:n.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[c]=l.patternIdxToConfig,this.charCodeToPatternIdxToConfig[c]=l.charCodeToPatternIdxToConfig,this.emptyGroups=Be({},this.emptyGroups,l.emptyGroups),this.hasCustom=l.hasCustom||this.hasCustom,this.canModeBeOptimized[c]=l.canBeOptimized}})}),this.defaultMode=s.defaultMode,!z(this.lexerDefinitionErrors)&&!this.config.deferDefinitionErrorsHandling){const c=L(this.lexerDefinitionErrors,l=>l.message).join(`----------------------- -`);throw new Error(`Errors detected in definition of Lexer: -`+c)}b(this.lexerDefinitionWarning,a=>{au(a.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(mu?(this.chopInput=Vn,this.match=this.matchWithTest):(this.updateLastIndex=ue,this.match=this.matchWithExec),i&&(this.handleModes=ue),this.trackStartLines===!1&&(this.computeNewColumn=Vn),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=ue),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid config option: "${this.config.positionTracking}"`);this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT("Failed Optimization Warnings",()=>{const a=Ge(this.canModeBeOptimized,(c,l,u)=>(l===!1&&c.push(u),c),[]);if(n.ensureOptimizations&&!z(a))throw Error(`Lexer Modes: < ${a.join(", ")} > cannot be optimized. - Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode. - Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{fA()}),this.TRACE_INIT("toFastProperties",()=>{lu(this)})})}tokenize(e,n=this.defaultMode){if(!z(this.lexerDefinitionErrors)){const s=L(this.lexerDefinitionErrors,i=>i.message).join(`----------------------- -`);throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer: -`+s)}return this.tokenizeInternal(e,n)}tokenizeInternal(e,n){let r,s,i,o,a,c,l,u,h,d,f,p,E,w,A;const R=e,_=R.length;let N=0,T=0;const m=this.hasCustom?0:Math.floor(e.length/10),g=new Array(m),S=[];let v=this.trackStartLines?1:void 0,j=this.trackStartLines?1:void 0;const ye=UA(this.emptyGroups),Sr=this.trackStartLines,Te=this.config.lineTerminatorsPattern;let Mt=0,nt=[],Ss=[];const no=[],Jp=[];Object.freeze(Jp);let As;function Qp(){return nt}function Zp(Ce){const rt=nn(Ce),Ar=Ss[rt];return Ar===void 0?Jp:Ar}const eL=Ce=>{if(no.length===1&&Ce.tokenType.PUSH_MODE===void 0){const rt=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(Ce);S.push({offset:Ce.startOffset,line:Ce.startLine,column:Ce.startColumn,length:Ce.image.length,message:rt})}else{no.pop();const rt=Xn(no);nt=this.patternIdxToConfig[rt],Ss=this.charCodeToPatternIdxToConfig[rt],Mt=nt.length;const Ar=this.canModeBeOptimized[rt]&&this.config.safeMode===!1;Ss&&Ar?As=Zp:As=Qp}};function eg(Ce){no.push(Ce),Ss=this.charCodeToPatternIdxToConfig[Ce],nt=this.patternIdxToConfig[Ce],Mt=nt.length,Mt=nt.length;const rt=this.canModeBeOptimized[Ce]&&this.config.safeMode===!1;Ss&&rt?As=Zp:As=Qp}eg.call(this,n);let pt;const tg=this.config.recoveryEnabled;for(;N<_;){c=null;const Ce=R.charCodeAt(N),rt=As(Ce),Ar=rt.length;for(r=0;rc.length){c=o,l=u,pt=Zt;break}}}break}}if(c!==null){if(h=c.length,d=pt.group,d!==void 0&&(f=pt.tokenTypeIdx,p=this.createTokenInstance(c,N,f,pt.tokenType,v,j,h),this.handlePayload(p,l),d===!1?T=this.addToken(g,T,p):ye[d].push(p)),e=this.chopInput(e,h),N=N+h,j=this.computeNewColumn(j,h),Sr===!0&&pt.canLineTerminator===!0){let Ve=0,Qt,En;Te.lastIndex=0;do Qt=Te.test(c),Qt===!0&&(En=Te.lastIndex-1,Ve++);while(Qt===!0);Ve!==0&&(v=v+Ve,j=h-En,this.updateTokenEndLineColumnLocation(p,d,En,Ve,v,j,h))}this.handleModes(pt,eL,eg,p)}else{const Ve=N,Qt=v,En=j;let Zt=tg===!1;for(;Zt===!1&&N<_;)for(e=this.chopInput(e,1),N++,s=0;s ${Vr(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${e.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:t,ruleName:e}){return"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage({expectedPathsPerAlt:t,actual:e,previous:n,customUserDescription:r,ruleName:s}){const i="Expecting: ",a=` -but found: '`+at(e).image+"'";if(r)return i+r+a;{const c=Ge(t,(d,f)=>d.concat(f),[]),l=L(c,d=>`[${L(d,f=>Vr(f)).join(", ")}]`),h=`one of these possible Token sequences: -${L(l,(d,f)=>` ${f+1}. ${d}`).join(` -`)}`;return i+h+a}},buildEarlyExitMessage({expectedIterationPaths:t,actual:e,customUserDescription:n,ruleName:r}){const s="Expecting: ",o=` -but found: '`+at(e).image+"'";if(n)return s+n+o;{const c=`expecting at least one iteration which starts with one of these possible Token sequences:: - <${L(t,l=>`[${L(l,u=>Vr(u)).join(",")}]`).join(" ,")}>`;return s+c+o}}};Object.freeze(Pu);const JA={buildRuleNotFoundError(t,e){return"Invalid grammar, reference to a rule which is not defined: ->"+e.nonTerminalName+`<- -inside top level rule: ->`+t.name+"<-"}},In={buildDuplicateFoundError(t,e){function n(u){return u instanceof Z?u.terminalType.name:u instanceof Ke?u.nonTerminalName:""}const r=t.name,s=at(e),i=s.idx,o=At(s),a=n(s),c=i>0;let l=`->${o}${c?i:""}<- ${a?`with argument: ->${a}<-`:""} - appears more than once (${e.length} times) in the top level rule: ->${r}<-. - For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES - `;return l=l.replace(/[ \t]+/g," "),l=l.replace(/\s\s+/g,` -`),l},buildNamespaceConflictError(t){return`Namespace conflict found in grammar. -The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${t.name}>. -To resolve this make sure each Terminal and Non-Terminal names are unique -This is easy to accomplish by using the convention that Terminal names start with an uppercase letter -and Non-Terminal names start with a lower case letter.`},buildAlternationPrefixAmbiguityError(t){const e=L(t.prefixPath,s=>Vr(s)).join(", "),n=t.alternation.idx===0?"":t.alternation.idx;return`Ambiguous alternatives: <${t.ambiguityIndices.join(" ,")}> due to common lookahead prefix -in inside <${t.topLevelRule.name}> Rule, -<${e}> may appears as a prefix path in all these alternatives. -See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX -For Further details.`},buildAlternationAmbiguityError(t){const e=L(t.prefixPath,s=>Vr(s)).join(", "),n=t.alternation.idx===0?"":t.alternation.idx;let r=`Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(" ,")}> in inside <${t.topLevelRule.name}> Rule, -<${e}> may appears as a prefix path in all these alternatives. -`;return r=r+`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES -For Further details.`,r},buildEmptyRepetitionError(t){let e=At(t.repetition);return t.repetition.idx!==0&&(e+=t.repetition.idx),`The repetition <${e}> within Rule <${t.topLevelRule.name}> can never consume any tokens. -This could lead to an infinite loop.`},buildTokenNameError(t){return"deprecated"},buildEmptyAlternationError(t){return`Ambiguous empty alternative: <${t.emptyChoiceIdx+1}> in inside <${t.topLevelRule.name}> Rule. -Only the last alternative may be an empty alternative.`},buildTooManyAlternativesError(t){return`An Alternation cannot have more than 256 alternatives: - inside <${t.topLevelRule.name}> Rule. - has ${t.alternation.definition.length+1} alternatives.`},buildLeftRecursionError(t){const e=t.topLevelRule.name,n=L(t.leftRecursionPath,i=>i.name),r=`${e} --> ${n.concat([e]).join(" --> ")}`;return`Left Recursion found in grammar. -rule: <${e}> can be invoked from itself (directly or indirectly) -without consuming any Tokens. The grammar path that causes this is: - ${r} - To fix this refactor your grammar to remove the left recursion. -see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(t){return"deprecated"},buildDuplicateRuleNameError(t){let e;return t.topLevelRule instanceof Qn?e=t.topLevelRule.name:e=t.topLevelRule,`Duplicate definition, rule: ->${e}<- is already defined in the grammar: ->${t.grammarName}<-`}};function QA(t,e){const n=new ZA(t,e);return n.resolveRefs(),n.errors}class ZA extends Zn{constructor(e,n){super(),this.nameToTopRule=e,this.errMsgProvider=n,this.errors=[]}resolveRefs(){b(he(this.nameToTopRule),e=>{this.currTopLevel=e,e.accept(this)})}visitNonTerminal(e){const n=this.nameToTopRule[e.nonTerminalName];if(n)e.referencedRule=n;else{const r=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:r,type:Oe.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}}}class ew extends Hs{constructor(e,n){super(),this.topProd=e,this.path=n,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=Se(this.path.ruleStack).reverse(),this.occurrenceStack=Se(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(e,n=[]){this.found||super.walk(e,n)}walkProdRef(e,n,r){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){const s=n.concat(r);this.updateExpectedNext(),this.walk(e.referencedRule,s)}}updateExpectedNext(){z(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}}class tw extends ew{constructor(e,n){super(e,n),this.path=n,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(e,n,r){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){const s=n.concat(r),i=new xe({definition:s});this.possibleTokTypes=$r(i),this.found=!0}}}class ri extends Hs{constructor(e,n){super(),this.topRule=e,this.occurrence=n,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class nw extends ri{walkMany(e,n,r){if(e.idx===this.occurrence){const s=at(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkMany(e,n,r)}}class Du extends ri{walkManySep(e,n,r){if(e.idx===this.occurrence){const s=at(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkManySep(e,n,r)}}class rw extends ri{walkAtLeastOne(e,n,r){if(e.idx===this.occurrence){const s=at(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkAtLeastOne(e,n,r)}}class Fu extends ri{walkAtLeastOneSep(e,n,r){if(e.idx===this.occurrence){const s=at(n.concat(r));this.result.isEndOfRule=s===void 0,s instanceof Z&&(this.result.token=s.terminalType,this.result.occurrence=s.idx)}else super.walkAtLeastOneSep(e,n,r)}}function ta(t,e,n=[]){n=Se(n);let r=[],s=0;function i(a){return a.concat(Ae(t,s+1))}function o(a){const c=ta(i(a),e,n);return r.concat(c)}for(;n.length{z(c.definition)===!1&&(r=o(c.definition))}),r;if(a instanceof Z)n.push(a.terminalType);else throw Error("non exhaustive match")}s++}return r.push({partialPath:n,suffixDef:Ae(t,s)}),r}function $u(t,e,n,r){const s="EXIT_NONE_TERMINAL",i=[s],o="EXIT_ALTERNATIVE";let a=!1;const c=e.length,l=c-r-1,u=[],h=[];for(h.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});!z(h);){const d=h.pop();if(d===o){a&&Xn(h).idx<=l&&h.pop();continue}const f=d.def,p=d.idx,E=d.ruleStack,w=d.occurrenceStack;if(z(f))continue;const A=f[0];if(A===s){const R={idx:p,def:Ae(f),ruleStack:Fr(E),occurrenceStack:Fr(w)};h.push(R)}else if(A instanceof Z)if(p=0;R--){const _=A.definition[R],N={idx:p,def:_.definition.concat(Ae(f)),ruleStack:E,occurrenceStack:w};h.push(N),h.push(o)}else if(A instanceof xe)h.push({idx:p,def:A.definition.concat(Ae(f)),ruleStack:E,occurrenceStack:w});else if(A instanceof Qn)h.push(sw(A,p,E,w));else throw Error("non exhaustive match")}return u}function sw(t,e,n,r){const s=Se(n);s.push(t.name);const i=Se(r);return i.push(1),{idx:e,def:t.definition,ruleStack:s,occurrenceStack:i}}var re;(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(re||(re={}));function Bu(t){if(t instanceof Ue||t==="Option")return re.OPTION;if(t instanceof fe||t==="Repetition")return re.REPETITION;if(t instanceof Tt||t==="RepetitionMandatory")return re.REPETITION_MANDATORY;if(t instanceof St||t==="RepetitionMandatoryWithSeparator")return re.REPETITION_MANDATORY_WITH_SEPARATOR;if(t instanceof lt||t==="RepetitionWithSeparator")return re.REPETITION_WITH_SEPARATOR;if(t instanceof ut||t==="Alternation")return re.ALTERNATION;throw Error("non exhaustive match")}function iw(t,e,n,r,s,i){const o=ra(t,e,n),a=ju(o)?ti:Wr;return i(o,r,a,s)}function ow(t,e,n,r,s,i){const o=sa(t,e,s,n),a=ju(o)?ti:Wr;return i(o[0],a,r)}function aw(t,e,n,r){const s=t.length,i=ot(t,o=>ot(o,a=>a.length===1));if(e)return function(o){const a=L(o,c=>c.GATE);for(let c=0;cit(c)),a=Ge(o,(c,l,u)=>(b(l,h=>{k(c,h.tokenTypeIdx)||(c[h.tokenTypeIdx]=u),b(h.categoryMatches,d=>{k(c,d)||(c[d]=u)})}),c),{});return function(){const c=this.LA(1);return a[c.tokenTypeIdx]}}else return function(){for(let o=0;oi.length===1),s=t.length;if(r&&!n){const i=it(t);if(i.length===1&&z(i[0].categoryMatches)){const a=i[0].tokenTypeIdx;return function(){return this.LA(1).tokenTypeIdx===a}}else{const o=Ge(i,(a,c,l)=>(a[c.tokenTypeIdx]=!0,b(c.categoryMatches,u=>{a[u]=!0}),a),[]);return function(){const a=this.LA(1);return o[a.tokenTypeIdx]===!0}}}else return function(){e:for(let i=0;ita([o],1)),r=Ku(n.length),s=L(n,o=>{const a={};return b(o,c=>{const l=na(c.partialPath);b(l,u=>{a[u]=!0})}),a});let i=n;for(let o=1;o<=e;o++){const a=i;i=Ku(a.length);for(let c=0;c{const A=na(w.partialPath);b(A,R=>{s[c][R]=!0})})}}}}return r}function ra(t,e,n,r){const s=new Gu(t,re.ALTERNATION,r);return e.accept(s),Wu(s.result,n)}function sa(t,e,n,r){const s=new Gu(t,n);e.accept(s);const i=s.result,a=new lw(e,t,n).startWalking(),c=new xe({definition:i}),l=new xe({definition:a});return Wu([c,l],r)}function ia(t,e){e:for(let n=0;n{const s=e[r];return n===s||s.categoryMatchesMap[n.tokenTypeIdx]})}function ju(t){return ot(t,e=>ot(e,n=>ot(n,r=>z(r.categoryMatches))))}function fw(t){const e=t.lookaheadStrategy.validate({rules:t.rules,tokenTypes:t.tokenTypes,grammarName:t.grammarName});return L(e,n=>Object.assign({type:Oe.CUSTOM_LOOKAHEAD_VALIDATION},n))}function dw(t,e,n,r){const s=Je(t,c=>pw(c,n)),i=Nw(t,e,n),o=Je(t,c=>Aw(c,n)),a=Je(t,c=>Ew(c,t,r,n));return s.concat(i,o,a)}function pw(t,e){const n=new mw;t.accept(n);const r=n.allProductions,s=NS(r,gw),i=ct(s,a=>a.length>1);return L(he(i),a=>{const c=at(a),l=e.buildDuplicateFoundError(t,a),u=At(c),h={message:l,type:Oe.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:u,occurrence:c.idx},d=Hu(c);return d&&(h.parameter=d),h})}function gw(t){return`${At(t)}_#_${t.idx}_#_${Hu(t)}`}function Hu(t){return t instanceof Z?t.terminalType.name:t instanceof Ke?t.nonTerminalName:""}class mw extends Zn{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(e){this.allProductions.push(e)}visitOption(e){this.allProductions.push(e)}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}visitAlternation(e){this.allProductions.push(e)}visitTerminal(e){this.allProductions.push(e)}}function Ew(t,e,n,r){const s=[];if(Ge(e,(o,a)=>a.name===t.name?o+1:o,0)>1){const o=r.buildDuplicateRuleNameError({topLevelRule:t,grammarName:n});s.push({message:o,type:Oe.DUPLICATE_RULE_NAME,ruleName:t.name})}return s}function _w(t,e,n){const r=[];let s;return Le(e,t)||(s=`Invalid rule override, rule: ->${t}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,r.push({message:s,type:Oe.INVALID_RULE_OVERRIDE,ruleName:t})),r}function Vu(t,e,n,r=[]){const s=[],i=si(e.definition);if(z(i))return[];{const o=t.name;Le(i,t)&&s.push({message:n.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:r}),type:Oe.LEFT_RECURSION,ruleName:o});const c=Gs(i,r.concat([t])),l=Je(c,u=>{const h=Se(r);return h.push(u),Vu(t,u,n,h)});return s.concat(l)}}function si(t){let e=[];if(z(t))return e;const n=at(t);if(n instanceof Ke)e.push(n.referencedRule);else if(n instanceof xe||n instanceof Ue||n instanceof Tt||n instanceof St||n instanceof lt||n instanceof fe)e=e.concat(si(n.definition));else if(n instanceof ut)e=it(L(n.definition,i=>si(i.definition)));else if(!(n instanceof Z))throw Error("non exhaustive match");const r=js(n),s=t.length>1;if(r&&s){const i=Ae(t);return e.concat(si(i))}else return e}class oa extends Zn{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}}function yw(t,e){const n=new oa;t.accept(n);const r=n.alternations;return Je(r,i=>{const o=Fr(i.definition);return Je(o,(a,c)=>{const l=$u([a],[],Wr,1);return z(l)?[{message:e.buildEmptyAlternationError({topLevelRule:t,alternation:i,emptyChoiceIdx:c}),type:Oe.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:i.idx,alternative:c+1}]:[]})})}function Tw(t,e,n){const r=new oa;t.accept(r);let s=r.alternations;return s=Ks(s,o=>o.ignoreAmbiguities===!0),Je(s,o=>{const a=o.idx,c=o.maxLookahead||e,l=ra(a,t,c,o),u=Rw(l,o,t,n),h=vw(l,o,t,n);return u.concat(h)})}class Sw extends Zn{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}}function Aw(t,e){const n=new oa;t.accept(n);const r=n.alternations;return Je(r,i=>i.definition.length>255?[{message:e.buildTooManyAlternativesError({topLevelRule:t,alternation:i}),type:Oe.TOO_MANY_ALTS,ruleName:t.name,occurrence:i.idx}]:[])}function ww(t,e,n){const r=[];return b(t,s=>{const i=new Sw;s.accept(i);const o=i.allProductions;b(o,a=>{const c=Bu(a),l=a.maxLookahead||e,u=a.idx,d=sa(u,s,c,l)[0];if(z(it(d))){const f=n.buildEmptyRepetitionError({topLevelRule:s,repetition:a});r.push({message:f,type:Oe.NO_NON_EMPTY_LOOKAHEAD,ruleName:s.name})}})}),r}function Rw(t,e,n,r){const s=[],i=Ge(t,(a,c,l)=>(e.definition[l].ignoreAmbiguities===!0||b(c,u=>{const h=[l];b(t,(d,f)=>{l!==f&&ia(d,u)&&e.definition[f].ignoreAmbiguities!==!0&&h.push(f)}),h.length>1&&!ia(s,u)&&(s.push(u),a.push({alts:h,path:u}))}),a),[]);return L(i,a=>{const c=L(a.alts,u=>u+1);return{message:r.buildAlternationAmbiguityError({topLevelRule:n,alternation:e,ambiguityIndices:c,prefixPath:a.path}),type:Oe.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:e.idx,alternatives:a.alts}})}function vw(t,e,n,r){const s=Ge(t,(o,a,c)=>{const l=L(a,u=>({idx:c,path:u}));return o.concat(l)},[]);return Dr(Je(s,o=>{if(e.definition[o.idx].ignoreAmbiguities===!0)return[];const c=o.idx,l=o.path,u=Xe(s,d=>e.definition[d.idx].ignoreAmbiguities!==!0&&d.idx{const f=[d.idx+1,c+1],p=e.idx===0?"":e.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:e,ambiguityIndices:f,prefixPath:d.path}),type:Oe.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:p,alternatives:f}})}))}function Nw(t,e,n){const r=[],s=L(e,i=>i.name);return b(t,i=>{const o=i.name;if(Le(s,o)){const a=n.buildNamespaceConflictError(i);r.push({message:a,type:Oe.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:o})}}),r}function Cw(t){const e=Vo(t,{errMsgProvider:JA}),n={};return b(t.rules,r=>{n[r.name]=r}),QA(n,e.errMsgProvider)}function Iw(t){return t=Vo(t,{errMsgProvider:In}),dw(t.rules,t.tokenTypes,t.errMsgProvider,t.grammarName)}const Yu="MismatchedTokenException",zu="NoViableAltException",qu="EarlyExitException",Xu="NotAllInputParsedException",Ju=[Yu,zu,qu,Xu];Object.freeze(Ju);function ii(t){return Le(Ju,t.name)}class oi extends Error{constructor(e,n){super(e),this.token=n,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class Qu extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Yu}}class Lw extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=zu}}class Ow extends oi{constructor(e,n){super(e,n),this.name=Xu}}class kw extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=qu}}const aa={},Zu="InRuleRecoveryException";class bw extends Error{constructor(e){super(e),this.name=Zu}}class Mw{initRecoverable(e){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=k(e,"recoveryEnabled")?e.recoveryEnabled:jt.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=xw)}getTokenToInsert(e){const n=ni(e,"",NaN,NaN,NaN,NaN,NaN,NaN);return n.isInsertedInRecovery=!0,n}canTokenTypeBeInsertedInRecovery(e){return!0}canTokenTypeBeDeletedInRecovery(e){return!0}tryInRepetitionRecovery(e,n,r,s){const i=this.findReSyncTokenType(),o=this.exportLexerState(),a=[];let c=!1;const l=this.LA(1);let u=this.LA(1);const h=()=>{const d=this.LA(0),f=this.errorMessageProvider.buildMismatchTokenMessage({expected:s,actual:l,previous:d,ruleName:this.getCurrRuleFullName()}),p=new Qu(f,l,this.LA(0));p.resyncedTokens=Fr(a),this.SAVE_ERROR(p)};for(;!c;)if(this.tokenMatcher(u,s)){h();return}else if(r.call(this)){h(),e.apply(this,n);return}else this.tokenMatcher(u,i)?c=!0:(u=this.SKIP_TOKEN(),this.addToResyncTokens(u,a));this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(e,n,r){return!(r===!1||this.tokenMatcher(this.LA(1),e)||this.isBackTracking()||this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,n)))}getFollowsForInRuleRecovery(e,n){const r=this.getCurrentGrammarPath(e,n);return this.getNextPossibleTokenTypes(r)}tryInRuleRecovery(e,n){if(this.canRecoverWithSingleTokenInsertion(e,n))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){const r=this.SKIP_TOKEN();return this.consumeToken(),r}throw new bw("sad sad panda")}canPerformInRuleRecovery(e,n){return this.canRecoverWithSingleTokenInsertion(e,n)||this.canRecoverWithSingleTokenDeletion(e)}canRecoverWithSingleTokenInsertion(e,n){if(!this.canTokenTypeBeInsertedInRecovery(e)||z(n))return!1;const r=this.LA(1);return Jn(n,i=>this.tokenMatcher(r,i))!==void 0}canRecoverWithSingleTokenDeletion(e){return this.canTokenTypeBeDeletedInRecovery(e)?this.tokenMatcher(this.LA(2),e):!1}isInCurrentRuleReSyncSet(e){const n=this.getCurrFollowKey(),r=this.getFollowSetFromFollowKey(n);return Le(r,e)}findReSyncTokenType(){const e=this.flattenFollowSet();let n=this.LA(1),r=2;for(;;){const s=Jn(e,i=>XA(n,i));if(s!==void 0)return s;n=this.LA(r),r++}}getCurrFollowKey(){if(this.RULE_STACK.length===1)return aa;const e=this.getLastExplicitRuleShortName(),n=this.getLastExplicitRuleOccurrenceIndex(),r=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(e),idxInCallingRule:n,inRule:this.shortRuleNameToFullName(r)}}buildFullFollowKeyStack(){const e=this.RULE_STACK,n=this.RULE_OCCURRENCE_STACK;return L(e,(r,s)=>s===0?aa:{ruleName:this.shortRuleNameToFullName(r),idxInCallingRule:n[s],inRule:this.shortRuleNameToFullName(e[s-1])})}flattenFollowSet(){const e=L(this.buildFullFollowKeyStack(),n=>this.getFollowSetFromFollowKey(n));return it(e)}getFollowSetFromFollowKey(e){if(e===aa)return[Cn];const n=e.ruleName+e.idxInCallingRule+hu+e.inRule;return this.resyncFollows[n]}addToResyncTokens(e,n){return this.tokenMatcher(e,Cn)||n.push(e),n}reSyncTo(e){const n=[];let r=this.LA(1);for(;this.tokenMatcher(r,e)===!1;)r=this.SKIP_TOKEN(),this.addToResyncTokens(r,n);return Fr(n)}attemptInRepetitionRecovery(e,n,r,s,i,o,a){}getCurrentGrammarPath(e,n){const r=this.getHumanReadableRuleStack(),s=Se(this.RULE_OCCURRENCE_STACK);return{ruleStack:r,occurrenceStack:s,lastTok:e,lastTokOccurrence:n}}getHumanReadableRuleStack(){return L(this.RULE_STACK,e=>this.shortRuleNameToFullName(e))}}function xw(t,e,n,r,s,i,o){const a=this.getKeyForAutomaticLookahead(r,s);let c=this.firstAfterRepMap[a];if(c===void 0){const d=this.getCurrRuleFullName(),f=this.getGAstProductions()[d];c=new i(f,s).startWalking(),this.firstAfterRepMap[a]=c}let l=c.token,u=c.occurrence;const h=c.isEndOfRule;this.RULE_STACK.length===1&&h&&l===void 0&&(l=Cn,u=1),!(l===void 0||u===void 0)&&this.shouldInRepetitionRecoveryBeTried(l,u,o)&&this.tryInRepetitionRecovery(t,e,n,l)}const Uw=4,rn=8,eh=1<Vu(n,n,In))}validateEmptyOrAlternatives(e){return Je(e,n=>yw(n,In))}validateAmbiguousAlternationAlternatives(e,n){return Je(e,r=>Tw(r,n,In))}validateSomeNonEmptyLookaheadPath(e,n){return ww(e,n,In)}buildLookaheadForAlternation(e){return iw(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,aw)}buildLookaheadForOptional(e){return ow(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,Bu(e.prodType),cw)}}class Dw{initLooksAhead(e){this.dynamicTokensEnabled=k(e,"dynamicTokensEnabled")?e.dynamicTokensEnabled:jt.dynamicTokensEnabled,this.maxLookahead=k(e,"maxLookahead")?e.maxLookahead:jt.maxLookahead,this.lookaheadStrategy=k(e,"lookaheadStrategy")?e.lookaheadStrategy:new Pw({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=new Map}preComputeLookaheadFunctions(e){b(e,n=>{this.TRACE_INIT(`${n.name} Rule Lookahead`,()=>{const{alternation:r,repetition:s,option:i,repetitionMandatory:o,repetitionMandatoryWithSeparator:a,repetitionWithSeparator:c}=$w(n);b(r,l=>{const u=l.idx===0?"":l.idx;this.TRACE_INIT(`${At(l)}${u}`,()=>{const h=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:l.idx,rule:n,maxLookahead:l.maxLookahead||this.maxLookahead,hasPredicates:l.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled}),d=ha(this.fullRuleNameToShort[n.name],eh,l.idx);this.setLaFuncCache(d,h)})}),b(s,l=>{this.computeLookaheadFunc(n,l.idx,ca,"Repetition",l.maxLookahead,At(l))}),b(i,l=>{this.computeLookaheadFunc(n,l.idx,th,"Option",l.maxLookahead,At(l))}),b(o,l=>{this.computeLookaheadFunc(n,l.idx,la,"RepetitionMandatory",l.maxLookahead,At(l))}),b(a,l=>{this.computeLookaheadFunc(n,l.idx,ai,"RepetitionMandatoryWithSeparator",l.maxLookahead,At(l))}),b(c,l=>{this.computeLookaheadFunc(n,l.idx,ua,"RepetitionWithSeparator",l.maxLookahead,At(l))})})})}computeLookaheadFunc(e,n,r,s,i,o){this.TRACE_INIT(`${o}${n===0?"":n}`,()=>{const a=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:n,rule:e,maxLookahead:i||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:s}),c=ha(this.fullRuleNameToShort[e.name],r,n);this.setLaFuncCache(c,a)})}getKeyForAutomaticLookahead(e,n){const r=this.getLastExplicitRuleShortName();return ha(r,e,n)}getLaFuncFromCache(e){return this.lookAheadFuncsCache.get(e)}setLaFuncCache(e,n){this.lookAheadFuncsCache.set(e,n)}}class Fw extends Zn{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(e){this.dslMethods.option.push(e)}visitRepetitionWithSeparator(e){this.dslMethods.repetitionWithSeparator.push(e)}visitRepetitionMandatory(e){this.dslMethods.repetitionMandatory.push(e)}visitRepetitionMandatoryWithSeparator(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)}visitRepetition(e){this.dslMethods.repetition.push(e)}visitAlternation(e){this.dslMethods.alternation.push(e)}}const ci=new Fw;function $w(t){ci.reset(),t.accept(ci);const e=ci.dslMethods;return ci.reset(),e}function nh(t,e){isNaN(t.startOffset)===!0?(t.startOffset=e.startOffset,t.endOffset=e.endOffset):t.endOffseto.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>: - ${i.join(` - -`).replace(/\n/g,` - `)}`)}}};return n.prototype=r,n.prototype.constructor=n,n._RULE_NAMES=e,n}function Hw(t,e,n){const r=function(){};sh(r,t+"BaseSemanticsWithDefaults");const s=Object.create(n.prototype);return b(e,i=>{s[i]=Ww}),r.prototype=s,r.prototype.constructor=r,r}var fa;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(fa||(fa={}));function Vw(t,e){return Yw(t,e)}function Yw(t,e){const n=Xe(e,s=>$t(t[s])===!1),r=L(n,s=>({msg:`Missing visitor method: <${s}> on ${t.constructor.name} CST Visitor.`,type:fa.MISSING_METHOD,methodName:s}));return Dr(r)}class zw{initTreeBuilder(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=k(e,"nodeLocationTracking")?e.nodeLocationTracking:jt.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=ue,this.cstFinallyStateUpdate=ue,this.cstPostTerminal=ue,this.cstPostNonTerminal=ue,this.cstPostRule=ue;else if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=rh,this.setNodeLocationFromNode=rh,this.cstPostRule=ue,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=ue,this.setNodeLocationFromNode=ue,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=nh,this.setNodeLocationFromNode=nh,this.cstPostRule=ue,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=ue,this.setNodeLocationFromNode=ue,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=ue,this.setNodeLocationFromNode=ue,this.cstPostRule=ue,this.setInitialNodeLocation=ue;else throw Error(`Invalid config option: "${e.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(e){e.location={startOffset:NaN,endOffset:NaN}}setInitialNodeLocationOnlyOffsetRegular(e){e.location={startOffset:this.LA(1).startOffset,endOffset:NaN}}setInitialNodeLocationFullRecovery(e){e.location={startOffset:NaN,startLine:NaN,startColumn:NaN,endOffset:NaN,endLine:NaN,endColumn:NaN}}setInitialNodeLocationFullRegular(e){const n=this.LA(1);e.location={startOffset:n.startOffset,startLine:n.startLine,startColumn:n.startColumn,endOffset:NaN,endLine:NaN,endColumn:NaN}}cstInvocationStateUpdate(e){const n={name:e,children:Object.create(null)};this.setInitialNodeLocation(n),this.CST_STACK.push(n)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(e){const n=this.LA(0),r=e.location;r.startOffset<=n.startOffset?(r.endOffset=n.endOffset,r.endLine=n.endLine,r.endColumn=n.endColumn):(r.startOffset=NaN,r.startLine=NaN,r.startColumn=NaN)}cstPostRuleOnlyOffset(e){const n=this.LA(0),r=e.location;r.startOffset<=n.startOffset?r.endOffset=n.endOffset:r.startOffset=NaN}cstPostTerminal(e,n){const r=this.CST_STACK[this.CST_STACK.length-1];Bw(r,n,e),this.setNodeLocationFromToken(r.location,n)}cstPostNonTerminal(e,n){const r=this.CST_STACK[this.CST_STACK.length-1];Gw(r,n,e),this.setNodeLocationFromNode(r.location,e.location)}getBaseCstVisitorConstructor(){if(Wt(this.baseCstVisitorConstructor)){const e=jw(this.className,$e(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(Wt(this.baseCstVisitorWithDefaultsConstructor)){const e=Hw(this.className,$e(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor}getLastExplicitRuleShortName(){const e=this.RULE_STACK;return e[e.length-1]}getPreviousExplicitRuleShortName(){const e=this.RULE_STACK;return e[e.length-2]}getLastExplicitRuleOccurrenceIndex(){const e=this.RULE_OCCURRENCE_STACK;return e[e.length-1]}}class qw{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(e){if(this.selfAnalysisDone!==!0)throw Error("Missing invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=e,this.tokVectorLength=e.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVector.length-2?(this.consumeToken(),this.LA(1)):hi}LA(e){const n=this.currIdx+e;return n<0||this.tokVectorLength<=n?hi:this.tokVector[n]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(e){this.currIdx=e}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVector.length-1}getLexerPosition(){return this.exportLexerState()}}class Xw{ACTION(e){return e.call(this)}consume(e,n,r){return this.consumeInternal(n,e,r)}subrule(e,n,r){return this.subruleInternal(n,e,r)}option(e,n){return this.optionInternal(n,e)}or(e,n){return this.orInternal(n,e)}many(e,n){return this.manyInternal(e,n)}atLeastOne(e,n){return this.atLeastOneInternal(e,n)}CONSUME(e,n){return this.consumeInternal(e,0,n)}CONSUME1(e,n){return this.consumeInternal(e,1,n)}CONSUME2(e,n){return this.consumeInternal(e,2,n)}CONSUME3(e,n){return this.consumeInternal(e,3,n)}CONSUME4(e,n){return this.consumeInternal(e,4,n)}CONSUME5(e,n){return this.consumeInternal(e,5,n)}CONSUME6(e,n){return this.consumeInternal(e,6,n)}CONSUME7(e,n){return this.consumeInternal(e,7,n)}CONSUME8(e,n){return this.consumeInternal(e,8,n)}CONSUME9(e,n){return this.consumeInternal(e,9,n)}SUBRULE(e,n){return this.subruleInternal(e,0,n)}SUBRULE1(e,n){return this.subruleInternal(e,1,n)}SUBRULE2(e,n){return this.subruleInternal(e,2,n)}SUBRULE3(e,n){return this.subruleInternal(e,3,n)}SUBRULE4(e,n){return this.subruleInternal(e,4,n)}SUBRULE5(e,n){return this.subruleInternal(e,5,n)}SUBRULE6(e,n){return this.subruleInternal(e,6,n)}SUBRULE7(e,n){return this.subruleInternal(e,7,n)}SUBRULE8(e,n){return this.subruleInternal(e,8,n)}SUBRULE9(e,n){return this.subruleInternal(e,9,n)}OPTION(e){return this.optionInternal(e,0)}OPTION1(e){return this.optionInternal(e,1)}OPTION2(e){return this.optionInternal(e,2)}OPTION3(e){return this.optionInternal(e,3)}OPTION4(e){return this.optionInternal(e,4)}OPTION5(e){return this.optionInternal(e,5)}OPTION6(e){return this.optionInternal(e,6)}OPTION7(e){return this.optionInternal(e,7)}OPTION8(e){return this.optionInternal(e,8)}OPTION9(e){return this.optionInternal(e,9)}OR(e){return this.orInternal(e,0)}OR1(e){return this.orInternal(e,1)}OR2(e){return this.orInternal(e,2)}OR3(e){return this.orInternal(e,3)}OR4(e){return this.orInternal(e,4)}OR5(e){return this.orInternal(e,5)}OR6(e){return this.orInternal(e,6)}OR7(e){return this.orInternal(e,7)}OR8(e){return this.orInternal(e,8)}OR9(e){return this.orInternal(e,9)}MANY(e){this.manyInternal(0,e)}MANY1(e){this.manyInternal(1,e)}MANY2(e){this.manyInternal(2,e)}MANY3(e){this.manyInternal(3,e)}MANY4(e){this.manyInternal(4,e)}MANY5(e){this.manyInternal(5,e)}MANY6(e){this.manyInternal(6,e)}MANY7(e){this.manyInternal(7,e)}MANY8(e){this.manyInternal(8,e)}MANY9(e){this.manyInternal(9,e)}MANY_SEP(e){this.manySepFirstInternal(0,e)}MANY_SEP1(e){this.manySepFirstInternal(1,e)}MANY_SEP2(e){this.manySepFirstInternal(2,e)}MANY_SEP3(e){this.manySepFirstInternal(3,e)}MANY_SEP4(e){this.manySepFirstInternal(4,e)}MANY_SEP5(e){this.manySepFirstInternal(5,e)}MANY_SEP6(e){this.manySepFirstInternal(6,e)}MANY_SEP7(e){this.manySepFirstInternal(7,e)}MANY_SEP8(e){this.manySepFirstInternal(8,e)}MANY_SEP9(e){this.manySepFirstInternal(9,e)}AT_LEAST_ONE(e){this.atLeastOneInternal(0,e)}AT_LEAST_ONE1(e){return this.atLeastOneInternal(1,e)}AT_LEAST_ONE2(e){this.atLeastOneInternal(2,e)}AT_LEAST_ONE3(e){this.atLeastOneInternal(3,e)}AT_LEAST_ONE4(e){this.atLeastOneInternal(4,e)}AT_LEAST_ONE5(e){this.atLeastOneInternal(5,e)}AT_LEAST_ONE6(e){this.atLeastOneInternal(6,e)}AT_LEAST_ONE7(e){this.atLeastOneInternal(7,e)}AT_LEAST_ONE8(e){this.atLeastOneInternal(8,e)}AT_LEAST_ONE9(e){this.atLeastOneInternal(9,e)}AT_LEAST_ONE_SEP(e){this.atLeastOneSepFirstInternal(0,e)}AT_LEAST_ONE_SEP1(e){this.atLeastOneSepFirstInternal(1,e)}AT_LEAST_ONE_SEP2(e){this.atLeastOneSepFirstInternal(2,e)}AT_LEAST_ONE_SEP3(e){this.atLeastOneSepFirstInternal(3,e)}AT_LEAST_ONE_SEP4(e){this.atLeastOneSepFirstInternal(4,e)}AT_LEAST_ONE_SEP5(e){this.atLeastOneSepFirstInternal(5,e)}AT_LEAST_ONE_SEP6(e){this.atLeastOneSepFirstInternal(6,e)}AT_LEAST_ONE_SEP7(e){this.atLeastOneSepFirstInternal(7,e)}AT_LEAST_ONE_SEP8(e){this.atLeastOneSepFirstInternal(8,e)}AT_LEAST_ONE_SEP9(e){this.atLeastOneSepFirstInternal(9,e)}RULE(e,n,r=fi){if(Le(this.definedRulesNames,e)){const o={message:In.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:Oe.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(o)}this.definedRulesNames.push(e);const s=this.defineRule(e,n,r);return this[e]=s,s}OVERRIDE_RULE(e,n,r=fi){const s=_w(e,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(s);const i=this.defineRule(e,n,r);return this[e]=i,i}BACKTRACK(e,n){return function(){this.isBackTrackingStack.push(1);const r=this.saveRecogState();try{return e.apply(this,n),!0}catch(s){if(ii(s))return!1;throw s}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return QS(he(this.gastProductionsCache))}}class Jw{initRecognizerEngine(e,n){if(this.className=this.constructor.name,this.shortRuleNameToFull={},this.fullRuleNameToShort={},this.ruleShortNameIdx=256,this.tokenMatcher=ti,this.subruleIdx=0,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.gastProductionsCache={},k(n,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a property. - See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0 - For Further details.`);if(W(e)){if(z(e))throw Error(`A Token Vocabulary cannot be empty. - Note that the first argument for the parser constructor - is no longer a Token vector (since v4.0).`);if(typeof e[0].startOffset=="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument. - See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0 - For Further details.`)}if(W(e))this.tokensMap=Ge(e,(i,o)=>(i[o.name]=o,i),{});else if(k(e,"modes")&&ot(it(he(e.modes)),VA)){const i=it(he(e.modes)),o=Yo(i);this.tokensMap=Ge(o,(a,c)=>(a[c.name]=c,a),{})}else if(qe(e))this.tokensMap=Se(e);else throw new Error(" argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=Cn;const r=k(e,"modes")?it(he(e.modes)):he(e),s=ot(r,i=>z(i.categoryMatches));this.tokenMatcher=s?ti:Wr,jr(he(this.tokensMap))}defineRule(e,n,r){if(this.selfAnalysisDone)throw Error(`Grammar rule <${e}> may not be defined after the 'performSelfAnalysis' method has been called' -Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);const s=k(r,"resyncEnabled")?r.resyncEnabled:fi.resyncEnabled,i=k(r,"recoveryValueFunc")?r.recoveryValueFunc:fi.recoveryValueFunc,o=this.ruleShortNameIdx<o.call(this)&&a.call(this)}}else i=e;if(s.call(this)===!0)return i.call(this)}atLeastOneInternal(e,n){const r=this.getKeyForAutomaticLookahead(la,e);return this.atLeastOneInternalLogic(e,n,r)}atLeastOneInternalLogic(e,n,r){let s=this.getLaFuncFromCache(r),i;if(typeof n!="function"){i=n.DEF;const o=n.GATE;if(o!==void 0){const a=s;s=()=>o.call(this)&&a.call(this)}}else i=n;if(s.call(this)===!0){let o=this.doSingleRepetition(i);for(;s.call(this)===!0&&o===!0;)o=this.doSingleRepetition(i)}else throw this.raiseEarlyExitException(e,re.REPETITION_MANDATORY,n.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,n],s,la,e,rw)}atLeastOneSepFirstInternal(e,n){const r=this.getKeyForAutomaticLookahead(ai,e);this.atLeastOneSepFirstInternalLogic(e,n,r)}atLeastOneSepFirstInternalLogic(e,n,r){const s=n.DEF,i=n.SEP;if(this.getLaFuncFromCache(r).call(this)===!0){s.call(this);const a=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,i,a,s,Fu],a,ai,e,Fu)}else throw this.raiseEarlyExitException(e,re.REPETITION_MANDATORY_WITH_SEPARATOR,n.ERR_MSG)}manyInternal(e,n){const r=this.getKeyForAutomaticLookahead(ca,e);return this.manyInternalLogic(e,n,r)}manyInternalLogic(e,n,r){let s=this.getLaFuncFromCache(r),i;if(typeof n!="function"){i=n.DEF;const a=n.GATE;if(a!==void 0){const c=s;s=()=>a.call(this)&&c.call(this)}}else i=n;let o=!0;for(;s.call(this)===!0&&o===!0;)o=this.doSingleRepetition(i);this.attemptInRepetitionRecovery(this.manyInternal,[e,n],s,ca,e,nw,o)}manySepFirstInternal(e,n){const r=this.getKeyForAutomaticLookahead(ua,e);this.manySepFirstInternalLogic(e,n,r)}manySepFirstInternalLogic(e,n,r){const s=n.DEF,i=n.SEP;if(this.getLaFuncFromCache(r).call(this)===!0){s.call(this);const a=()=>this.tokenMatcher(this.LA(1),i);for(;this.tokenMatcher(this.LA(1),i)===!0;)this.CONSUME(i),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,i,a,s,Du],a,ua,e,Du)}}repetitionSepSecondInternal(e,n,r,s,i){for(;r();)this.CONSUME(n),s.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,s,i],r,ai,e,i)}doSingleRepetition(e){const n=this.getLexerPosition();return e.call(this),this.getLexerPosition()>n}orInternal(e,n){const r=this.getKeyForAutomaticLookahead(eh,n),s=W(e)?e:e.DEF,o=this.getLaFuncFromCache(r).call(this,s);if(o!==void 0)return s[o].ALT.call(this);this.raiseNoAltException(n,e.ERR_MSG)}ruleFinallyStateUpdate(){if(this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop(),this.cstFinallyStateUpdate(),this.RULE_STACK.length===0&&this.isAtEndOfInput()===!1){const e=this.LA(1),n=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:e,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new Ow(n,e))}}subruleInternal(e,n,r){let s;try{const i=r!==void 0?r.ARGS:void 0;return this.subruleIdx=n,s=e.apply(this,i),this.cstPostNonTerminal(s,r!==void 0&&r.LABEL!==void 0?r.LABEL:e.ruleName),s}catch(i){throw this.subruleInternalError(i,r,e.ruleName)}}subruleInternalError(e,n,r){throw ii(e)&&e.partialCstResult!==void 0&&(this.cstPostNonTerminal(e.partialCstResult,n!==void 0&&n.LABEL!==void 0?n.LABEL:r),delete e.partialCstResult),e}consumeInternal(e,n,r){let s;try{const i=this.LA(1);this.tokenMatcher(i,e)===!0?(this.consumeToken(),s=i):this.consumeInternalError(e,i,r)}catch(i){s=this.consumeInternalRecovery(e,n,i)}return this.cstPostTerminal(r!==void 0&&r.LABEL!==void 0?r.LABEL:e.name,s),s}consumeInternalError(e,n,r){let s;const i=this.LA(0);throw r!==void 0&&r.ERR_MSG?s=r.ERR_MSG:s=this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:n,previous:i,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new Qu(s,n,i))}consumeInternalRecovery(e,n,r){if(this.recoveryEnabled&&r.name==="MismatchedTokenException"&&!this.isBackTracking()){const s=this.getFollowsForInRuleRecovery(e,n);try{return this.tryInRuleRecovery(e,s)}catch(i){throw i.name===Zu?r:i}}else throw r}saveRecogState(){const e=this.errors,n=Se(this.RULE_STACK);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:n,CST_STACK:this.CST_STACK}}reloadRecogState(e){this.errors=e.errors,this.importLexerState(e.lexerState),this.RULE_STACK=e.RULE_STACK}ruleInvocationStateUpdate(e,n,r){this.RULE_OCCURRENCE_STACK.push(r),this.RULE_STACK.push(e),this.cstInvocationStateUpdate(n)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){const e=this.getLastExplicitRuleShortName();return this.shortRuleNameToFull[e]}shortRuleNameToFullName(e){return this.shortRuleNameToFull[e]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),Cn)}reset(){this.resetLexerState(),this.subruleIdx=0,this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]}}class Qw{initErrorHandler(e){this._errors=[],this.errorMessageProvider=k(e,"errorMessageProvider")?e.errorMessageProvider:jt.errorMessageProvider}SAVE_ERROR(e){if(ii(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:Se(this.RULE_OCCURRENCE_STACK)},this._errors.push(e),e;throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return Se(this._errors)}set errors(e){this._errors=e}raiseEarlyExitException(e,n,r){const s=this.getCurrRuleFullName(),i=this.getGAstProductions()[s],a=sa(e,i,n,this.maxLookahead)[0],c=[];for(let u=1;u<=this.maxLookahead;u++)c.push(this.LA(u));const l=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:a,actual:c,previous:this.LA(0),customUserDescription:r,ruleName:s});throw this.SAVE_ERROR(new kw(l,this.LA(1),this.LA(0)))}raiseNoAltException(e,n){const r=this.getCurrRuleFullName(),s=this.getGAstProductions()[r],i=ra(e,s,this.maxLookahead),o=[];for(let l=1;l<=this.maxLookahead;l++)o.push(this.LA(l));const a=this.LA(0),c=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:i,actual:o,previous:a,customUserDescription:n,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new Lw(c,this.LA(1),a))}}class Zw{initContentAssist(){}computeContentAssist(e,n){const r=this.gastProductionsCache[e];if(Wt(r))throw Error(`Rule ->${e}<- does not exist in this grammar.`);return $u([r],n,this.tokenMatcher,this.maxLookahead)}getNextPossibleTokenTypes(e){const n=at(e.ruleStack),s=this.getGAstProductions()[n];return new tw(s,e).startWalking()}}const li={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(li);const ih=!0,oh=Math.pow(2,rn)-1,ah=x({name:"RECORDING_PHASE_TOKEN",pattern:ge.NA});jr([ah]);const ch=ni(ah,`This IToken indicates the Parser is in Recording Phase - See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(ch);const eR={name:`This CSTNode indicates the Parser is in Recording Phase - See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class tR{initGastRecorder(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let e=0;e<10;e++){const n=e>0?e:"";this[`CONSUME${n}`]=function(r,s){return this.consumeInternalRecord(r,e,s)},this[`SUBRULE${n}`]=function(r,s){return this.subruleInternalRecord(r,e,s)},this[`OPTION${n}`]=function(r){return this.optionInternalRecord(r,e)},this[`OR${n}`]=function(r){return this.orInternalRecord(r,e)},this[`MANY${n}`]=function(r){this.manyInternalRecord(e,r)},this[`MANY_SEP${n}`]=function(r){this.manySepFirstInternalRecord(e,r)},this[`AT_LEAST_ONE${n}`]=function(r){this.atLeastOneInternalRecord(e,r)},this[`AT_LEAST_ONE_SEP${n}`]=function(r){this.atLeastOneSepFirstInternalRecord(e,r)}}this.consume=function(e,n,r){return this.consumeInternalRecord(n,e,r)},this.subrule=function(e,n,r){return this.subruleInternalRecord(n,e,r)},this.option=function(e,n){return this.optionInternalRecord(n,e)},this.or=function(e,n){return this.orInternalRecord(n,e)},this.many=function(e,n){this.manyInternalRecord(e,n)},this.atLeastOne=function(e,n){this.atLeastOneInternalRecord(e,n)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{const e=this;for(let n=0;n<10;n++){const r=n>0?n:"";delete e[`CONSUME${r}`],delete e[`SUBRULE${r}`],delete e[`OPTION${r}`],delete e[`OR${r}`],delete e[`MANY${r}`],delete e[`MANY_SEP${r}`],delete e[`AT_LEAST_ONE${r}`],delete e[`AT_LEAST_ONE_SEP${r}`]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})}ACTION_RECORD(e){}BACKTRACK_RECORD(e,n){return()=>!0}LA_RECORD(e){return hi}topLevelRuleRecord(e,n){try{const r=new Qn({definition:[],name:e});return r.name=e,this.recordingProdStack.push(r),n.call(this),this.recordingProdStack.pop(),r}catch(r){if(r.KNOWN_RECORDER_ERROR!==!0)try{r.message=r.message+` - This error was thrown during the "grammar recording phase" For more info see: - https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw r}throw r}}optionInternalRecord(e,n){return Yr.call(this,Ue,e,n)}atLeastOneInternalRecord(e,n){Yr.call(this,Tt,n,e)}atLeastOneSepFirstInternalRecord(e,n){Yr.call(this,St,n,e,ih)}manyInternalRecord(e,n){Yr.call(this,fe,n,e)}manySepFirstInternalRecord(e,n){Yr.call(this,lt,n,e,ih)}orInternalRecord(e,n){return nR.call(this,e,n)}subruleInternalRecord(e,n,r){if(ui(n),!e||k(e,"ruleName")===!1){const a=new Error(` argument is invalid expecting a Parser method reference but got: <${JSON.stringify(e)}> - inside top level rule: <${this.recordingProdStack[0].name}>`);throw a.KNOWN_RECORDER_ERROR=!0,a}const s=Xn(this.recordingProdStack),i=e.ruleName,o=new Ke({idx:n,nonTerminalName:i,label:r==null?void 0:r.LABEL,referencedRule:void 0});return s.definition.push(o),this.outputCst?eR:li}consumeInternalRecord(e,n,r){if(ui(n),!vu(e)){const o=new Error(` argument is invalid expecting a TokenType reference but got: <${JSON.stringify(e)}> - inside top level rule: <${this.recordingProdStack[0].name}>`);throw o.KNOWN_RECORDER_ERROR=!0,o}const s=Xn(this.recordingProdStack),i=new Z({idx:n,terminalType:e,label:r==null?void 0:r.LABEL});return s.definition.push(i),ch}}function Yr(t,e,n,r=!1){ui(n);const s=Xn(this.recordingProdStack),i=$t(e)?e:e.DEF,o=new t({definition:[],idx:n});return r&&(o.separator=e.SEP),k(e,"MAX_LOOKAHEAD")&&(o.maxLookahead=e.MAX_LOOKAHEAD),this.recordingProdStack.push(o),i.call(this),s.definition.push(o),this.recordingProdStack.pop(),li}function nR(t,e){ui(e);const n=Xn(this.recordingProdStack),r=W(t)===!1,s=r===!1?t:t.DEF,i=new ut({definition:[],idx:e,ignoreAmbiguities:r&&t.IGNORE_AMBIGUITIES===!0});k(t,"MAX_LOOKAHEAD")&&(i.maxLookahead=t.MAX_LOOKAHEAD);const o=ou(s,a=>$t(a.GATE));return i.hasPredicates=o,n.definition.push(i),b(s,a=>{const c=new xe({definition:[]});i.definition.push(c),k(a,"IGNORE_AMBIGUITIES")?c.ignoreAmbiguities=a.IGNORE_AMBIGUITIES:k(a,"GATE")&&(c.ignoreAmbiguities=!0),this.recordingProdStack.push(c),a.ALT.call(this),this.recordingProdStack.pop()}),li}function lh(t){return t===0?"":`${t}`}function ui(t){if(t<0||t>oh){const e=new Error(`Invalid DSL Method idx value: <${t}> - Idx value must be a none negative value smaller than ${oh+1}`);throw e.KNOWN_RECORDER_ERROR=!0,e}}class rR{initPerformanceTracer(e){if(k(e,"traceInitPerf")){const n=e.traceInitPerf,r=typeof n=="number";this.traceInitMaxIdent=r?n:1/0,this.traceInitPerf=r?n>0:n}else this.traceInitMaxIdent=0,this.traceInitPerf=jt.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(e,n){if(this.traceInitPerf===!0){this.traceInitIndent++;const r=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent <${e}>`);const{time:s,value:i}=cu(n),o=s>10?console.warn:console.log;return this.traceInitIndent time: ${s}ms`),this.traceInitIndent--,i}else return n()}}function sR(t,e){e.forEach(n=>{const r=n.prototype;Object.getOwnPropertyNames(r).forEach(s=>{if(s==="constructor")return;const i=Object.getOwnPropertyDescriptor(r,s);i&&(i.get||i.set)?Object.defineProperty(t.prototype,s,i):t.prototype[s]=n.prototype[s]})})}const hi=ni(Cn,"",NaN,NaN,NaN,NaN,NaN,NaN);Object.freeze(hi);const jt=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:Pu,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),fi=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0});var Oe;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(Oe||(Oe={}));class zr{static performSelfAnalysis(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT("performSelfAnalysis",()=>{let e;this.selfAnalysisDone=!0;const n=this.className;this.TRACE_INIT("toFastProps",()=>{lu(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),b(this.definedRulesNames,s=>{const o=this[s].originalGrammarAction;let a;this.TRACE_INIT(`${s} Rule`,()=>{a=this.topLevelRuleRecord(s,o)}),this.gastProductionsCache[s]=a})}finally{this.disableRecording()}});let r=[];if(this.TRACE_INIT("Grammar Resolving",()=>{r=Cw({rules:he(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT("Grammar Validations",()=>{if(z(r)&&this.skipValidations===!1){const s=Iw({rules:he(this.gastProductionsCache),tokenTypes:he(this.tokensMap),errMsgProvider:In,grammarName:n}),i=fw({lookaheadStrategy:this.lookaheadStrategy,rules:he(this.gastProductionsCache),tokenTypes:he(this.tokensMap),grammarName:n});this.definitionErrors=this.definitionErrors.concat(s,i)}}),z(this.definitionErrors)&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{const s=iA(he(this.gastProductionsCache));this.resyncFollows=s}),this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var s,i;(i=(s=this.lookaheadStrategy).initialize)===null||i===void 0||i.call(s,{rules:he(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(he(this.gastProductionsCache))})),!zr.DEFER_DEFINITION_ERRORS_HANDLING&&!z(this.definitionErrors))throw e=L(this.definitionErrors,s=>s.message),new Error(`Parser Definition Errors detected: - ${e.join(` -------------------------------- -`)}`)})}constructor(e,n){this.definitionErrors=[],this.selfAnalysisDone=!1;const r=this;if(r.initErrorHandler(n),r.initLexerAdapter(),r.initLooksAhead(n),r.initRecognizerEngine(e,n),r.initRecoverable(n),r.initTreeBuilder(n),r.initContentAssist(),r.initGastRecorder(n),r.initPerformanceTracer(n),k(n,"ignoredIssues"))throw new Error(`The IParserConfig property has been deprecated. - Please use the flag on the relevant DSL method instead. - See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES - For further details.`);this.skipValidations=k(n,"skipValidations")?n.skipValidations:jt.skipValidations}}zr.DEFER_DEFINITION_ERRORS_HANDLING=!1,sR(zr,[Mw,Dw,zw,qw,Jw,Xw,Qw,Zw,tR,rR]);class iR extends zr{constructor(e,n=jt){const r=Se(n);r.outputCst=!0,super(e,r)}}const wt=!!JSON.parse("false");JSON.parse("false");const oR=!!JSON.parse("false"),da=mo(32,126).map(t=>String.fromCharCode(t)),qr=x({name:"Newline",line_breaks:!0,start_chars_hint:[` -`,"\r"],pattern:/\n|\r\n?/}),aR=x({name:"Whitespace",pattern:/ +/,group:ge.SKIPPED}),cR=x({name:"Whitespace",pattern:/\s+/,line_breaks:!0,group:ge.SKIPPED}),pa=x({name:"Stat",pattern:/@.*/,start_chars_hint:["@"]}),ht=x({name:"Command",pattern:/#/,start_chars_hint:["#"]});let uh=!1;function lR(t,e,n){if(!uh)return null;const[r]=n.slice(-1);if(r&&r.tokenType!==qr)return null;let s=e;for(;t[s]===" ";)s++;if("@#/?':!".includes(t[s]))return null;let i=e+1;for(;i"@#/?':!".includes(t)===!1)}),fh=x({name:"Comment",pattern:/'.*/,start_chars_hint:["'"]}),dh=x({name:"Label",pattern:/:[^;:\n]*/,start_chars_hint:[":"]}),ph=x({name:"HyperLink",pattern:/!/,start_chars_hint:["!"]}),gh=x({name:"HyperLinkText",pattern:/;[^;\n]*/,start_chars_hint:[";"]}),We=x({name:"StringLiteral",pattern:/[^-0-9"!;@#/?\s]+[^-"!;@#/?\s]*/,start_chars_hint:da}),mh=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),Eh=x({name:"NumberLiteral",pattern:/-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?/});function Qe(t){return x({name:t,pattern:new RegExp(t.toLowerCase(),"i"),longer_alt:We})}const _h=x({name:"IsEq",pattern:/=|is|eq|equal/,longer_alt:We}),yh=x({name:"IsNotEq",pattern:/!=|not ?eq|not ?equal/,longer_alt:We}),Th=x({name:"IsLessThan",pattern:/<|below/,longer_alt:We}),Sh=x({name:"IsGreaterThan",pattern:/>|above/,longer_alt:We}),Ah=x({name:"IsLessThanOrEqual",pattern:/<=|below ?or ?eq|below ?or ?equal/,longer_alt:We}),wh=x({name:"IsGreaterThanOrEqual",pattern:/>=|above ?or ?eq|above ?or ?equal/,longer_alt:We}),ga=x({name:"Or",pattern:/or/i,longer_alt:We}),ma=x({name:"Not",pattern:/not/i,longer_alt:We}),Ea=x({name:"And",pattern:/and/i,longer_alt:We}),_a=x({name:"Plus",pattern:/\+/}),ya=x({name:"Minus",pattern:/-/}),Rh=x({name:"Power",pattern:/\*\*/}),vh=x({name:"Multiply",pattern:/\*/}),Ta=x({name:"Divide",pattern:/\//}),Nh=x({name:"ModDivide",pattern:/%/}),Ch=x({name:"FloorDivide",pattern:/%%/}),Ih=x({name:"Query",pattern:/\?/}),Lh=x({name:"LParen",pattern:/\(/,push_mode:"ignore_newlines"}),Oh=x({name:"RParen",pattern:/\)/,pop_mode:!0}),kh=x({name:"play",pattern:/play .*/,start_chars_hint:da,longer_alt:We}),Sa=Qe("if"),Ln=Qe("do"),Aa=Qe("else"),bh=Qe("endif"),Mh=Qe("while"),xh=Qe("endwhile"),Uh=Qe("repeat"),Ph=Qe("endrepeat"),Dh=Qe("read"),Fh=Qe("endread"),$h=Qe("break"),Bh=Qe("continue");function Gh(t){return[...t,_h,yh,Ah,Th,wh,Sh,ga,ma,Ea,_a,ya,Rh,vh,Ta,Ch,Nh,Ih,Lh,Oh,mh,We,Eh]}const Kh=Gh([hh,pa,kh,ht,fh,dh,ph,gh,qr,aR,Sa,Ln,Aa,bh,Mh,xh,Uh,Ph,Dh,Fh,$h,Bh]),uR=new ge({defaultMode:"use_newlines",modes:{use_newlines:Kh,ignore_newlines:Gh([cR])}},{skipValidations:!wt,ensureOptimizations:wt});function wa(t){uh=!0;const e=uR.tokenize(t||` -`),[n]=(Array.isArray(e.tokens)?e.tokens:[]).slice(-1);return n&&n.tokenType.name!=="Newline"&&e.tokens.push(ni(qr,` -`,n.startOffset,n.endOffset??NaN,n.startLine??NaN,n.endLine??NaN,n.startColumn??NaN,n.endColumn??NaN)),e}var je=(t=>(t[t.ERROR=0]="ERROR",t[t.FUNC=1]="FUNC",t[t.BOARD=2]="BOARD",t[t.OBJECT=3]="OBJECT",t[t.TERRAIN=4]="TERRAIN",t[t.CHARSET=5]="CHARSET",t[t.PALETTE=6]="PALETTE",t))(je||{});function Rt(t,e){return{id:Ut(),code:t,...e}}function hR(t){return t.map(e=>e.image)}function fR(t,e){const[n,r,...s]=e;if(y(t.stats)&&y(n))switch(n.image.toLowerCase()){case"rn":case"range":case"sl":case"select":case"nm":case"number":case"tx":case"text":case"ln":case"link":if(y(r)){const i=r.image.toLowerCase();t.stats[i]=hR(s??[])}break}}function Wh(t){var n;if(!y(t))return{};if(y((n=t.stats)==null?void 0:n.type))return t.stats;t.stats={};const e=wa(t.code);for(let r=0;rdR(i)===e&&(i.id===n||r===pR(i)))}function va(t,e,n){const r=Ra(t,e,n);if(r)switch(e){case je.ERROR:return r.error;case je.FUNC:return r.code;case je.BOARD:return r.board;case je.OBJECT:return r.object;case je.TERRAIN:return r.terrain;case je.CHARSET:return r.charset;case je.PALETTE:return r.palette}}function Na(t,e){const n=e??"",r=Ra(t,je.OBJECT,n),s=va(t,je.OBJECT,n);return y(r)?{...s,name:n,code:r.code}:void 0}function di(t,e){if(y(e)&&y(e.kind))return y(e.kinddata)||(e.kinddata=Na(t,e.kind)),e.kinddata}function Hh(t,e){const n=e??"",r=Ra(t,je.TERRAIN,n),s=va(t,je.TERRAIN,n);return y(r)?{...s,name:n,code:r.code}:void 0}function Ca(t,e){if(y(e)&&y(e.kind))return y(e.kinddata)||(e.kinddata=Hh(t,e.kind)),e.kinddata}function tr(t,e){return va(t,je.BOARD,e)}function Vh(t,e){if(t)return t.flags[e]=t.flags[e]??{},t.flags[e]}function gR(t,e,n){const r=Vh(t,e);return r==null?void 0:r[n]}function mR(t,e,n,r){const s=Vh(t,e);return s&&(s[n]=r),r}function Yh(t,e){return tr(t,(t==null?void 0:t.players[e])??"")}function ER(t,e,n){y(t)&&y(tr(t,n))&&(t.players[e]=n)}function _R(t){return Xg(Object.values((t==null?void 0:t.players)??[])).map(e=>tr(t,e)).filter(y)}function yR(t,e,n,r){const s=Xc(e,(n==null?void 0:n.id)??"");if(!y(t)||!y(e)||!y(s)||!y(e.lookup)||r.x<0||r.x>=e.width||r.y<0||r.y>=e.height)return{kind:"edge",...r};const i=r.x+r.y*e.width,o=di(t,s),a=s.collision??(o==null?void 0:o.collision)??me.WALK,c=Xc(e,e.lookup[i]??"");if(y(c))return{...c};const l=e.terrain[i];if(y(l)){const u=Ca(t,l),h=l.collision??(u==null?void 0:u.collision)??me.WALK;if(Jg(a,h))return{...l,...r}}e.lookup[i]=void 0,s.x=r.x,s.y=r.y,e.lookup[s.x+s.y*e.width]=s.id??""}function Xr(t,e){if(y(e==null?void 0:e.x)&&y(e.y)&&y(e.id)){const r=di(t,e);return(e.name??(r==null?void 0:r.name)??"object").toLowerCase()}const n=Ca(t,e);return((e==null?void 0:e.name)??(n==null?void 0:n.name)??"terrain").toLowerCase()}function Ia(t,e){if(!y(t)||!y(e)||y(e.lookup)&&y(e.named))return;const n=new Array(e.width*e.height).fill(void 0),r={},s=Object.values(e.objects);for(let a=0;a=e.width&&(i=0,++o)}e.lookup=n,e.named=r}function zh(t,e,n,r){Xr(t,n)!=="player"&&y(n)&&(n.removed=r,qh(t,e,n))}function qh(t,e,n){var r,s;if(y(t)&&y(e)&&y(n==null?void 0:n.id)&&y(n.x)&&y(n.y)){if(y(e.lookup)){const o=n.x+n.y*e.width;((r=e.lookup)==null?void 0:r[o])===n.id&&delete e.lookup[o]}const i=Xr(t,n);y((s=e.named)==null?void 0:s[i])&&e.named[i].delete(n.id)}}function TR(t,e,n){if(!y(t)||!y(e))return;const r=Object.values(e.objects);for(let s=0;swo*5&&To(e,i.id)}}function SR(t,e,n,r){if(!y(t)||!y(e))return;e.lookup=void 0,Ia(t,e);const s=Object.values(e.objects);for(let i=0;i(t[t.VIEW=0]="VIEW",t[t.EDIT=1]="EDIT",t))(Jr||{});function Xh(t){return{id:Ut(),type:t}}function Jh(t,e){const n=Xh(0);return n.book=t,n.board=e,n}function AR(t,e){const n=Xh(1);return n.book=t,n.board=e,n}const Ht={defaultplayer:"",books:new Map,chips:new Map,frames:new Map};function wR(t){Ht.defaultplayer=t}function Qh(t){const e=[Jh(void 0,void 0)];return Ht.frames.set(t,e),e}function RR(t,e,n){const r=pi(t);y(r)&&r.push(Jh(e,n))}function vR(t,e,n){const r=pi(t);y(r)&&r.push(AR(e,n))}function pi(t){return Ht.frames.get(t)??Qh(t)}function Qr(t){const e=t.toLowerCase();return Ht.books.get(t)??[...Ht.books.values()].find(n=>n.name.toLowerCase()===e)}function Zh(t){return Ht.books.set(t.id,t),t.id}function V(t){let e=Ht.chips.get(t);return y(e)||(e={book:void 0,board:void 0,target:void 0,inputqueue:new Set,inputmods:{[ce.NONE]:0,[ce.MOVE_UP]:0,[ce.MOVE_DOWN]:0,[ce.MOVE_LEFT]:0,[ce.MOVE_RIGHT]:0,[ce.OK_BUTTON]:0,[ce.CANCEL_BUTTON]:0,[ce.MENU_BUTTON]:0},inputcurrent:void 0},Ht.chips.set(t,e)),e}const ef="player",tf="title";function NR(t){const e=Qr(_i.name),n=tr(e,tf),r=Na(e,ef);if(y(n)&&y(r)){const s=qc(n,{id:t,x:0,y:0,kind:ef,stats:{player:t}});y(s==null?void 0:s.id)&&ER(e,t,tf)}}function CR(t){Ht.books.forEach(e=>To(Yh(e,t),t))}function IR(t,e){function n(s,i,o,a,c){const l=V(a);l.book=s,l.board=i,l.target=o,l.inputcurrent=void 0,t.tick(a,c)}const r=Qr(_i.name);_R(r).forEach(s=>SR(r,s,e,n))}function LR(t,e,n,r,s){const i=[];let o=e;const a=o===0,c=r.width??0,l=r.height??0,u=a?Q.BLACK:Q.CLEAR,h=_g(t,o++,c,l,u);i.push(h);const d=Sg(t,o++,c,l);i.push(d);const f=o++,p=Tg(t,f);i.push(p);const E=Ag(t,o++);s&&i.push(E),r.terrain.forEach((A,R)=>{if(A){const _=Ca(n,A);h.char[R]=A.char??(_==null?void 0:_.char)??0,h.color[R]=A.color??(_==null?void 0:_.color)??u,h.bg[R]=A.bg??(_==null?void 0:_.bg)??u}});const w=r.objects??{};return Object.values(w).forEach(A=>{if(y(A.removed))return;const R=A.id??"",_=di(n,A),N=yg(t,f,R),T=A.lx??A.x??0,m=A.ly??A.y??0;N.x=A.x??0,N.y=A.y??0,N.char=A.char??(_==null?void 0:_.char)??1,N.color=A.color??(_==null?void 0:_.color)??Q.WHITE,N.bg=A.bg??(_==null?void 0:_.bg)??Q.CLEAR,p.sprites.push(N),N.bg===Q.SHADOW&&(d.alphas[T+m*c]=.5),R===t&&(E.focusx=N.x,E.focusy=N.y,E.focusid=R)}),i}function nf(t){switch(t.type){case Jr.EDIT:return 1;case Jr.VIEW:return 2}return 0}function OR(t){const e=Qr(_i.name),n=Yh(e,t),r=[];if(!y(e)||!y(n))return r;let s=0;return pi(n.id??"").toSorted((o,a)=>nf(o)-nf(a)).forEach(o=>{const a=Qr(o.book??"")??e,c=tr(a,o.board??"")??n;if(y(a)&&y(c)){const l=LR(t,s,a,c,o.type===Jr.VIEW);s+=l.length,r.push(...l)}}),r}var Q=(t=>(t[t.BLACK=0]="BLACK",t[t.DKBLUE=1]="DKBLUE",t[t.DKGREEN=2]="DKGREEN",t[t.DKCYAN=3]="DKCYAN",t[t.DKRED=4]="DKRED",t[t.DKPURPLE=5]="DKPURPLE",t[t.DKYELLOW=6]="DKYELLOW",t[t.LTGRAY=7]="LTGRAY",t[t.DKGRAY=8]="DKGRAY",t[t.BLUE=9]="BLUE",t[t.GREEN=10]="GREEN",t[t.CYAN=11]="CYAN",t[t.RED=12]="RED",t[t.PURPLE=13]="PURPLE",t[t.YELLOW=14]="YELLOW",t[t.WHITE=15]="WHITE",t[t.ONBLACK=16]="ONBLACK",t[t.ONDKBLUE=17]="ONDKBLUE",t[t.ONDKGREEN=18]="ONDKGREEN",t[t.ONDKCYAN=19]="ONDKCYAN",t[t.ONDKRED=20]="ONDKRED",t[t.ONDKPURPLE=21]="ONDKPURPLE",t[t.ONDKYELLOW=22]="ONDKYELLOW",t[t.ONLTGRAY=23]="ONLTGRAY",t[t.ONDKGRAY=24]="ONDKGRAY",t[t.ONBLUE=25]="ONBLUE",t[t.ONGREEN=26]="ONGREEN",t[t.ONCYAN=27]="ONCYAN",t[t.ONRED=28]="ONRED",t[t.ONPURPLE=29]="ONPURPLE",t[t.ONYELLOW=30]="ONYELLOW",t[t.ONWHITE=31]="ONWHITE",t[t.CLEAR=Bc]="CLEAR",t[t.SHADOW=Eg]="SHADOW",t))(Q||{}),B=(t=>(t[t.IDLE=0]="IDLE",t[t.NORTH=1]="NORTH",t[t.SOUTH=2]="SOUTH",t[t.WEST=3]="WEST",t[t.EAST=4]="EAST",t[t.BY=5]="BY",t[t.AT=6]="AT",t[t.FLOW=7]="FLOW",t[t.SEEK=8]="SEEK",t[t.RNDNS=9]="RNDNS",t[t.RNDNE=10]="RNDNE",t[t.RND=11]="RND",t[t.CW=12]="CW",t[t.CCW=13]="CCW",t[t.OPP=14]="OPP",t[t.RNDP=15]="RNDP",t))(B||{}),me=(t=>(t[t.SOLID=0]="SOLID",t[t.WALK=1]="WALK",t[t.SWIM=2]="SWIM",t[t.BULLET=3]="BULLET",t))(me||{}),gi=(t=>(t[t.TERRAIN=0]="TERRAIN",t[t.OBJECT=1]="OBJECT",t))(gi||{});function sn(t){return y(t)&&y(t.x)&&y(t.y)}function nr(t,e){const n=e.x-t.x,r=e.y-t.y;if(n<0)return 3;if(n>0)return 4;if(r<0)return 1;if(r>0)return 2}const rf={terrain:"TERRAIN",object:"OBJECT"};function on(t){return Pt(t)&&sf(t[0])}function sf(t){return y(gi[t])&&le(t)}function of(t){if(le(t))return rf[t.toLowerCase()]}function af(t){if(on(t))return t;if(sf(t))return[t];const e=of(t);if(y(e))return[e]}function mi(t,e){const n=t.words[e],r=af(n);if(on(r))return[r,e+1];const[s,i]=Re(t,e),o=af(s);return on(o)?[o,i]:[void 0,e]}const cf={solid:"SOLID",walk:"WALK",swim:"SWIM",bullet:"BULLET",walkable:"WALK",swimmable:"SWIM"};function On(t){return Pt(t)&&La(t[0])}function La(t){return y(me[t])&&le(t)}function kR(t){if(le(t))return cf[t.toLowerCase()]}function lf(t,e){const n=t.words[e];if(On(n))return[n,e+1];if(La(n))return[[n],e+1];const[r,s]=Re(t,e);return On(r)?[r,s]:La(r)?[[r],s]:[void 0,e]}const uf={black:"BLACK",dkblue:"DKBLUE",dkgreen:"DKGREEN",dkcyan:"DKCYAN",dkred:"DKRED",dkpurple:"DKPURPLE",dkyellow:"DKYELLOW",ltgray:"LTGRAY",dkgray:"DKGRAY",blue:"BLUE",green:"GREEN",cyan:"CYAN",red:"RED",purple:"PURPLE",yellow:"YELLOW",white:"WHITE",clear:"CLEAR",shadow:"SHADOW",brown:"DKYELLOW",dkwhite:"LTGRAY",ltgrey:"LTGRAY",gray:"LTGRAY",grey:"LTGRAY",dkgrey:"DKGRAY",ltblack:"DKGRAY",onblack:"ONBLACK",ondkblue:"ONDKBLUE",ondkgreen:"ONDKGREEN",ondkcyan:"ONDKCYAN",ondkred:"ONDKRED",ondkpurple:"ONDKPURPLE",ondkyellow:"ONDKYELLOW",onltgray:"ONLTGRAY",ondkgray:"ONDKGRAY",onblue:"ONBLUE",ongreen:"ONGREEN",oncyan:"ONCYAN",onred:"ONRED",onpurple:"ONPURPLE",onyellow:"ONYELLOW",onwhite:"ONWHITE",onbrown:"ONDKYELLOW",ondkwhite:"ONLTGRAY",onltgrey:"ONLTGRAY",ongray:"ONLTGRAY",ongrey:"ONLTGRAY",ondkgrey:"ONDKGRAY",onltblack:"ONDKGRAY"};function Ze(t){return Pt(t)&&ff(t[0])}function hf(t){return Ze(t)&&t[0].startsWith("ON")}function ff(t){return y(Q[t])&&le(t)}function df(t){if(le(t))return uf[t.toLowerCase()]}function pf(t){return t.map(e=>Q[e]).find(e=>y(e)&&e<16)}function gf(t){return t.map(e=>Q[e]).find(e=>y(e)&&e>=16)}function mf(t){if(Ze(t))return t;if(ff(t))return[t];const e=df(t);if(y(e))return[e]}function Ef(t,e){const n=t.words[e],r=mf(n);if(Ze(r))return[r,e+1];const[s,i]=Re(t,e),o=mf(s);return Ze(o)?[o,i]:[void 0,e]}function Ei(t,e){const n=[];let r=e;const[s,i]=Ef(t,e);if(Ze(s)&&(n.push(...s),r=i),Ze(n)&&!hf(n)){const[o,a]=Ef(t,i);hf(o)&&(n.push(...o),r=a)}return n.length?[n,r]:[void 0,e]}function rr(t){return Pt(t)&&typeof t[0]=="string"}function _f(t,e){const n=t.words[e];if(rr(n))return[n,e+1];const[r,s]=Ei(t,e),[i,o]=Re(t,s,!1);return le(i)?[[i,r],o]:[void 0,e]}function Oa(t){if(!rr(t))return;const[e]=t;return e}function yf(t){if(!rr(t))return;const[,e]=t,n=y(e)?pf(e):void 0;return y(n)?n:void 0}function Tf(t){if(!rr(t))return;const[,e]=t,n=y(e)?gf(e):void 0;return y(n)?n:void 0}const Sf={idle:"IDLE",up:"NORTH",down:"SOUTH",left:"WEST",right:"EAST",by:"BY",at:"AT",flow:"FLOW",seek:"SEEK",rndns:"RNDNS",rndne:"RNDNE",rnd:"RND",cw:"CW",ccw:"CCW",opp:"OPP",rndp:"RNDP",u:"NORTH",north:"NORTH",n:"NORTH",d:"SOUTH",south:"SOUTH",s:"SOUTH",l:"WEST",west:"WEST",w:"WEST",r:"EAST",east:"EAST",e:"EAST",edit:"EDIT"};function Vt(t){return Pt(t)&&Af(t[0])}function Af(t){return y(B[t])&&le(t)}function wf(t){if(le(t))return Sf[t.toLowerCase()]}function Rf(t){if(Vt(t))return t;if(Af(t))return[t];const e=wf(t);if(y(e))return[e]}function vf(t,e){const n=t.words[e],r=Rf(n);if(Vt(r))return[r,e+1];const[s,i]=Re(t,e),o=Rf(s);return Vt(o)?[o,i]:[void 0,e]}function ka(t,e){const n=[];let[r,s]=vf(t,e);for(;Vt(r);){n.push(...r);const[i,o]=vf(t,s);r=i,s=o}return n.length?[n,e+n.length]:[void 0,e]}function K(t,e){return{...V(t.id()),chip:t,words:e}}function Re(t,e,n=!0){const r=t.words[e];if(of(r)){const[s,i]=mi(t,e);if(y(s))return[s,i]}if(kR(r)){const[s,i]=lf(t,e);if(y(s))return[s,i]}if(df(r)){const[s,i]=Ei(t,e);if(y(s))return[s,i]}if(le(r)&&r.toLowerCase()==="rnd"){const[s,i]=Re(t,e+1),[o,a]=Re(t,i);return Fe(s)&&Fe(o)?[Wn(s,o),a]:Fe(s)?[Wn(0,s),i]:[Wn(0,1),e+1]}if(wf(r)){const[s,i]=ka(t,e);if(y(s))return[s,i]}if(!y(r))return[void 0,e];if(sn(r)||Fe(r)||Pt(r))return[r,e+1];if(le(r)){const s=r.toLowerCase();if(n){const i=t.chip.get(r);if(y(i))return[i,e+1]}switch(s){case"aligned":case"alligned":break;case"contact":break;case"blocked":break;case"any":break;case"abs":{const[i,o]=I(t,e+1,[5]);return[Math.abs(i),o]}case"ceil":{const[i,o]=I(t,e+1,[5]);return[Math.ceil(i),o]}case"floor":{const[i,o]=I(t,e+1,[5]);return[Math.floor(i),o]}case"round":{const[i,o]=I(t,e+1,[5]);return[Math.round(i),o]}case"min":{const i=[];for(let o=e+1;o(t[t.CATEGORY=0]="CATEGORY",t[t.COLLISION=1]="COLLISION",t[t.COLOR=2]="COLOR",t[t.KIND=3]="KIND",t[t.DIR=4]="DIR",t[t.NUMBER=5]="NUMBER",t[t.STRING=6]="STRING",t[t.NUMBER_OR_STRING=7]="NUMBER_OR_STRING",t[t.MAYBE_CATEGORY=8]="MAYBE_CATEGORY",t[t.MAYBE_COLLISION=9]="MAYBE_COLLISION",t[t.MAYBE_COLOR=10]="MAYBE_COLOR",t[t.MAYBE_KIND=11]="MAYBE_KIND",t[t.MAYBE_DIR=12]="MAYBE_DIR",t[t.MAYBE_NUMBER=13]="MAYBE_NUMBER",t[t.MAYBE_STRING=14]="MAYBE_STRING",t[t.MAYBE_NUMBER_OR_STRING=15]="MAYBE_NUMBER_OR_STRING",t[t.ANY=16]="ANY",t))(C||{});function ve(t,e){throw new Error(`Invalid arg, expected: ${t} but got ${JSON.stringify(e)}`)}function I(t,e,n){const r=[];let s=e;for(let i=0;i{for(let e=0;e<32;e++)qc(t,{x:Wn(0,t.width-1),y:Wn(0,t.height-1),kind:"spin"});return t})}),Rt(bR,{object:{char:219,color:Q.WHITE,bg:Q.CLEAR}}),Rt(MR,{object:{char:1,color:Q.WHITE,bg:Q.CLEAR}}),Rt("@terrain field",{terrain:{char:176,color:Q.DKGRAY,collision:me.WALK}}),Rt("@terrain wall",{terrain:{char:219,color:Q.CYAN,collision:me.SOLID}})]);var Nf={exports:{}},ba={exports:{}},Cf;function xR(){return Cf||(Cf=1,function(t,e){(function(n,r){t.exports=r()})(ws,function(){function n(E){return!isNaN(parseFloat(E))&&isFinite(E)}function r(E){return E.charAt(0).toUpperCase()+E.substring(1)}function s(E){return function(){return this[E]}}var i=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],a=["fileName","functionName","source"],c=["args"],l=["evalOrigin"],u=i.concat(o,a,c,l);function h(E){if(E)for(var w=0;w-1&&(u=u.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var h=u.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),d=h.match(/ (\(.+\)$)/);h=d?h.replace(d[0],""):h;var f=this.extractLocation(d?d[1]:h),p=d&&h||void 0,E=["eval",""].indexOf(f[0])>-1?void 0:f[0];return new r({functionName:p,fileName:E,lineNumber:f[1],columnNumber:f[2],source:u})},this)},parseFFOrSafari:function(c){var l=c.stack.split(` -`).filter(function(u){return!u.match(o)},this);return l.map(function(u){if(u.indexOf(" > eval")>-1&&(u=u.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),u.indexOf("@")===-1&&u.indexOf(":")===-1)return new r({functionName:u});var h=/((.*".+"[^@]*)?[^@]*)(?:@)/,d=u.match(h),f=d&&d[1]?d[1]:void 0,p=this.extractLocation(u.replace(h,""));return new r({functionName:f,fileName:p[0],lineNumber:p[1],columnNumber:p[2],source:u})},this)},parseOpera:function(c){return!c.stacktrace||c.message.indexOf(` -`)>-1&&c.message.split(` -`).length>c.stacktrace.split(` -`).length?this.parseOpera9(c):c.stack?this.parseOpera11(c):this.parseOpera10(c)},parseOpera9:function(c){for(var l=/Line (\d+).*script (?:in )?(\S+)/i,u=c.message.split(` -`),h=[],d=2,f=u.length;d/,"$2").replace(/\([^)]*\)/g,"")||void 0,E;f.match(/\(([^)]*)\)/)&&(E=f.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var w=E===void 0||E==="[arguments not available]"?void 0:E.split(",");return new r({functionName:p,args:w,fileName:d[0],lineNumber:d[1],columnNumber:d[2],source:u})},this)}}})})(Nf);var UR=Nf.exports,PR=ro(UR),If={},Lf={},Of={};const kf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");Of.encode=function(t){if(0<=t&&t>>=bf,s>0&&(r|=$R),n+=DR.encode(r);while(s>0);return n};var Zr={};(function(t){function e(m,g,S){if(g in m)return m[g];if(arguments.length===3)return S;throw new Error('"'+g+'" is a required argument.')}t.getArg=e;const n=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/,r=/^data:.+\,.+$/;function s(m){const g=m.match(n);return g?{scheme:g[1],auth:g[2],host:g[3],port:g[4],path:g[5]}:null}t.urlParse=s;function i(m){let g="";return m.scheme&&(g+=m.scheme+":"),g+="//",m.auth&&(g+=m.auth+"@"),m.host&&(g+=m.host),m.port&&(g+=":"+m.port),m.path&&(g+=m.path),g}t.urlGenerate=i;const o=32;function a(m){const g=[];return function(S){for(let j=0;jo&&g.pop(),v}}const c=a(function(g){let S=g;const v=s(g);if(v){if(!v.path)return g;S=v.path}const j=t.isAbsolute(S),ye=[];let Sr=0,Te=0;for(;;)if(Sr=Te,Te=S.indexOf("/",Sr),Te===-1){ye.push(S.slice(Sr));break}else for(ye.push(S.slice(Sr,Te));Te=0;Te--){const nt=ye[Te];nt==="."?ye.splice(Te,1):nt===".."?Mt++:Mt>0&&(nt===""?(ye.splice(Te+1,Mt),Mt=0):(ye.splice(Te,2),Mt--))}return S=ye.join("/"),S===""&&(S=j?"/":"."),v?(v.path=S,i(v)):S});t.normalize=c;function l(m,g){m===""&&(m="."),g===""&&(g=".");const S=s(g),v=s(m);if(v&&(m=v.path||"/"),S&&!S.scheme)return v&&(S.scheme=v.scheme),i(S);if(S||g.match(r))return g;if(v&&!v.host&&!v.path)return v.host=g,i(v);const j=g.charAt(0)==="/"?g:c(m.replace(/\/+$/,"")+"/"+g);return v?(v.path=j,i(v)):j}t.join=l,t.isAbsolute=function(m){return m.charAt(0)==="/"||n.test(m)};function u(m,g){m===""&&(m="."),m=m.replace(/\/$/,"");let S=0;for(;g.indexOf(m+"/")!==0;){const v=m.lastIndexOf("/");if(v<0||(m=m.slice(0,v),m.match(/^([^\/]+:\/)?\/*$/)))return g;++S}return Array(S+1).join("../")+g.substr(m.length+1)}t.relative=u;const h=function(){return!("__proto__"in Object.create(null))}();function d(m){return m}function f(m){return E(m)?"$"+m:m}t.toSetString=h?d:f;function p(m){return E(m)?m.slice(1):m}t.fromSetString=h?d:p;function E(m){if(!m)return!1;const g=m.length;if(g<9||m.charCodeAt(g-1)!==95||m.charCodeAt(g-2)!==95||m.charCodeAt(g-3)!==111||m.charCodeAt(g-4)!==116||m.charCodeAt(g-5)!==111||m.charCodeAt(g-6)!==114||m.charCodeAt(g-7)!==112||m.charCodeAt(g-8)!==95||m.charCodeAt(g-9)!==95)return!1;for(let S=g-10;S>=0;S--)if(m.charCodeAt(S)!==36)return!1;return!0}function w(m,g,S){let v=R(m.source,g.source);return v!==0||(v=m.originalLine-g.originalLine,v!==0)||(v=m.originalColumn-g.originalColumn,v!==0||S)||(v=m.generatedColumn-g.generatedColumn,v!==0)||(v=m.generatedLine-g.generatedLine,v!==0)?v:R(m.name,g.name)}t.compareByOriginalPositions=w;function A(m,g,S){let v=m.generatedLine-g.generatedLine;return v!==0||(v=m.generatedColumn-g.generatedColumn,v!==0||S)||(v=R(m.source,g.source),v!==0)||(v=m.originalLine-g.originalLine,v!==0)||(v=m.originalColumn-g.originalColumn,v!==0)?v:R(m.name,g.name)}t.compareByGeneratedPositionsDeflated=A;function R(m,g){return m===g?0:m===null?1:g===null?-1:m>g?1:-1}function _(m,g){let S=m.generatedLine-g.generatedLine;return S!==0||(S=m.generatedColumn-g.generatedColumn,S!==0)||(S=R(m.source,g.source),S!==0)||(S=m.originalLine-g.originalLine,S!==0)||(S=m.originalColumn-g.originalColumn,S!==0)?S:R(m.name,g.name)}t.compareByGeneratedPositionsInflated=_;function N(m){return JSON.parse(m.replace(/^\)]}'[^\n]*\n/,""))}t.parseSourceMapInput=N;function T(m,g,S){if(g=g||"",m&&(m[m.length-1]!=="/"&&g[0]!=="/"&&(m+="/"),g=m+g),S){const v=s(S);if(!v)throw new Error("sourceMapURL could not be parsed");if(v.path){const j=v.path.lastIndexOf("/");j>=0&&(v.path=v.path.substring(0,j+1))}g=l(i(v),g)}return c(g)}t.computeSourceURL=T})(Zr);var Ma={};let GR=class rg{constructor(){this._array=[],this._set=new Map}static fromArray(e,n){const r=new rg;for(let s=0,i=e.length;s=0)return n;throw new Error('"'+e+'" is not in the set.')}at(e){if(e>=0&&en||r==n&&i>=s||Uf.compareByGeneratedPositionsInflated(t,e)<=0}let WR=class{constructor(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}unsortedForEach(e,n){this._array.forEach(e,n)}add(e){KR(this._last,e)?(this._last=e,this._array.push(e)):(this._sorted=!1,this._array.push(e))}toArray(){return this._sorted||(this._array.sort(Uf.compareByGeneratedPositionsInflated),this._sorted=!0),this._array}};xf.MappingList=WR;const es=Lf,ae=Zr,yi=Ma.ArraySet,jR=xf.MappingList;let Pf=class sg{constructor(e){e||(e={}),this._file=ae.getArg(e,"file",null),this._sourceRoot=ae.getArg(e,"sourceRoot",null),this._skipValidation=ae.getArg(e,"skipValidation",!1),this._sources=new yi,this._names=new yi,this._mappings=new jR,this._sourcesContents=null}static fromSourceMap(e){const n=e.sourceRoot,r=new sg({file:e.file,sourceRoot:n});return e.eachMapping(function(s){const i={generated:{line:s.generatedLine,column:s.generatedColumn}};s.source!=null&&(i.source=s.source,n!=null&&(i.source=ae.relative(n,i.source)),i.original={line:s.originalLine,column:s.originalColumn},s.name!=null&&(i.name=s.name)),r.addMapping(i)}),e.sources.forEach(function(s){let i=s;n!==null&&(i=ae.relative(n,s)),r._sources.has(i)||r._sources.add(i);const o=e.sourceContentFor(s);o!=null&&r.setSourceContent(s,o)}),r}addMapping(e){const n=ae.getArg(e,"generated"),r=ae.getArg(e,"original",null);let s=ae.getArg(e,"source",null),i=ae.getArg(e,"name",null);this._skipValidation||this._validateMapping(n,r,s,i),s!=null&&(s=String(s),this._sources.has(s)||this._sources.add(s)),i!=null&&(i=String(i),this._names.has(i)||this._names.add(i)),this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:r!=null&&r.line,originalColumn:r!=null&&r.column,source:s,name:i})}setSourceContent(e,n){let r=e;this._sourceRoot!=null&&(r=ae.relative(this._sourceRoot,r)),n!=null?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[ae.toSetString(r)]=n):this._sourcesContents&&(delete this._sourcesContents[ae.toSetString(r)],Object.keys(this._sourcesContents).length===0&&(this._sourcesContents=null))}applySourceMap(e,n,r){let s=n;if(n==null){if(e.file==null)throw new Error(`SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.`);s=e.file}const i=this._sourceRoot;i!=null&&(s=ae.relative(i,s));const o=this._mappings.toArray().length>0?new yi:this._sources,a=new yi;this._mappings.unsortedForEach(function(c){if(c.source===s&&c.originalLine!=null){const h=e.originalPositionFor({line:c.originalLine,column:c.originalColumn});h.source!=null&&(c.source=h.source,r!=null&&(c.source=ae.join(r,c.source)),i!=null&&(c.source=ae.relative(i,c.source)),c.originalLine=h.line,c.originalColumn=h.column,h.name!=null&&(c.name=h.name))}const l=c.source;l!=null&&!o.has(l)&&o.add(l);const u=c.name;u!=null&&!a.has(u)&&a.add(u)},this),this._sources=o,this._names=a,e.sources.forEach(function(c){const l=e.sourceContentFor(c);l!=null&&(r!=null&&(c=ae.join(r,c)),i!=null&&(c=ae.relative(i,c)),this.setSourceContent(c,l))},this)}_validateMapping(e,n,r,s){if(n&&typeof n.line!="number"&&typeof n.column!="number")throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if(!(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0&&!n&&!r&&!s)){if(!(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&r))throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:r,original:n,name:s}))}}_serializeMappings(){let e=0,n=1,r=0,s=0,i=0,o=0,a="",c,l,u,h;const d=this._mappings.toArray();for(let f=0,p=d.length;f0){if(!ae.compareByGeneratedPositionsInflated(l,d[f-1]))continue;c+=","}c+=es.encode(l.generatedColumn-e),e=l.generatedColumn,l.source!=null&&(h=this._sources.indexOf(l.source),c+=es.encode(h-o),o=h,c+=es.encode(l.originalLine-1-s),s=l.originalLine-1,c+=es.encode(l.originalColumn-r),r=l.originalColumn,l.name!=null&&(u=this._names.indexOf(l.name),c+=es.encode(u-i),i=u)),a+=c}return a}_generateSourcesContent(e,n){return e.map(function(r){if(!this._sourcesContents)return null;n!=null&&(r=ae.relative(n,r));const s=ae.toSetString(r);return Object.prototype.hasOwnProperty.call(this._sourcesContents,s)?this._sourcesContents[s]:null},this)}toJSON(){const e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return this._file!=null&&(e.file=this._file),this._sourceRoot!=null&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e}toString(){return JSON.stringify(this.toJSON())}};Pf.prototype._version=3,If.SourceMapGenerator=Pf;var Df={};(function(t){t.GREATEST_LOWER_BOUND=1,t.LEAST_UPPER_BOUND=2;function e(n,r,s,i,o,a){const c=Math.floor((r-n)/2)+n,l=o(s,i[c],!0);return l===0?c:l>0?r-c>1?e(c,r,s,i,o,a):a==t.LEAST_UPPER_BOUND?r1?e(n,c,s,i,o,a):a==t.LEAST_UPPER_BOUND?c:n<0?-1:n}t.search=function(r,s,i,o){if(s.length===0)return-1;let a=e(-1,s.length,r,s,i,o||t.GREATEST_LOWER_BOUND);if(a<0)return-1;for(;a-1>=0&&i(s[a],s[a-1],!0)===0;)--a;return a}})(Df);var ts={exports:{}},HR={},VR=Object.freeze({__proto__:null,default:HR}),Ff=ug(VR);if((function(){return typeof window<"u"&&this===window}).call()){let t=null;ts.exports=function(){if(typeof t=="string")return fetch(t).then(n=>n.arrayBuffer());if(t instanceof ArrayBuffer)return Promise.resolve(t);throw new Error("You must provide the string URL or ArrayBuffer contents of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer")},ts.exports.initialize=e=>t=e}else{const t=Ff,e=Ff;ts.exports=function(){return new Promise((r,s)=>{const i=e.join(__dirname,"mappings.wasm");t.readFile(i,null,(o,a)=>{if(o){s(o);return}r(a.buffer)})})},ts.exports.initialize=n=>{console.debug("SourceMapConsumer.initialize is a no-op when running in node.js")}}var $f=ts.exports;const YR=$f;function zR(){this.generatedLine=0,this.generatedColumn=0,this.lastGeneratedColumn=null,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null}let ns=null;var qR=function(){if(ns)return ns;const e=[];return ns=YR().then(n=>WebAssembly.instantiate(n,{env:{mapping_callback(r,s,i,o,a,c,l,u,h,d){const f=new zR;f.generatedLine=r+1,f.generatedColumn=s,i&&(f.lastGeneratedColumn=o-1),a&&(f.source=c,f.originalLine=l+1,f.originalColumn=u,h&&(f.name=d)),e[e.length-1](f)},start_all_generated_locations_for(){console.time("all_generated_locations_for")},end_all_generated_locations_for(){console.timeEnd("all_generated_locations_for")},start_compute_column_spans(){console.time("compute_column_spans")},end_compute_column_spans(){console.timeEnd("compute_column_spans")},start_generated_location_for(){console.time("generated_location_for")},end_generated_location_for(){console.timeEnd("generated_location_for")},start_original_location_for(){console.time("original_location_for")},end_original_location_for(){console.timeEnd("original_location_for")},start_parse_mappings(){console.time("parse_mappings")},end_parse_mappings(){console.timeEnd("parse_mappings")},start_sort_by_generated_location(){console.time("sort_by_generated_location")},end_sort_by_generated_location(){console.timeEnd("sort_by_generated_location")},start_sort_by_original_location(){console.time("sort_by_original_location")},end_sort_by_original_location(){console.timeEnd("sort_by_original_location")}}})).then(n=>({exports:n.instance.exports,withMappingCallback:(r,s)=>{e.push(r);try{s()}finally{e.pop()}}})).then(null,n=>{throw ns=null,n}),ns};const O=Zr,xa=Df,Ti=Ma.ArraySet,XR=$f,JR=qR,Ua=Symbol("smcInternal");class se{constructor(e,n){return e==Ua?Promise.resolve(this):ZR(e,n)}static initialize(e){XR.initialize(e["lib/mappings.wasm"])}static fromSourceMap(e,n){return ev(e,n)}static async with(e,n,r){const s=await new se(e,n);try{return await r(s)}finally{s.destroy()}}_parseMappings(e,n){throw new Error("Subclasses must implement _parseMappings")}eachMapping(e,n,r){throw new Error("Subclasses must implement eachMapping")}allGeneratedPositionsFor(e){throw new Error("Subclasses must implement allGeneratedPositionsFor")}destroy(){throw new Error("Subclasses must implement destroy")}}se.prototype._version=3,se.GENERATED_ORDER=1,se.ORIGINAL_ORDER=2,se.GREATEST_LOWER_BOUND=1,se.LEAST_UPPER_BOUND=2;class rs extends se{constructor(e,n){return super(Ua).then(r=>{let s=e;typeof e=="string"&&(s=O.parseSourceMapInput(e));const i=O.getArg(s,"version");let o=O.getArg(s,"sources");const a=O.getArg(s,"names",[]);let c=O.getArg(s,"sourceRoot",null);const l=O.getArg(s,"sourcesContent",null),u=O.getArg(s,"mappings"),h=O.getArg(s,"file",null);if(i!=r._version)throw new Error("Unsupported version: "+i);return c&&(c=O.normalize(c)),o=o.map(String).map(O.normalize).map(function(d){return c&&O.isAbsolute(c)&&O.isAbsolute(d)?O.relative(c,d):d}),r._names=Ti.fromArray(a.map(String),!0),r._sources=Ti.fromArray(o,!0),r._absoluteSources=r._sources.toArray().map(function(d){return O.computeSourceURL(c,d,n)}),r.sourceRoot=c,r.sourcesContent=l,r._mappings=u,r._sourceMapURL=n,r.file=h,r._computedColumnSpans=!1,r._mappingsPtr=0,r._wasm=null,JR().then(d=>(r._wasm=d,r))})}_findSourceIndex(e){let n=e;if(this.sourceRoot!=null&&(n=O.relative(this.sourceRoot,n)),this._sources.has(n))return this._sources.indexOf(n);for(let r=0;r{a.source!==null&&(a.source=this._sources.at(a.source),a.source=O.computeSourceURL(o,a.source,this._sourceMapURL),a.name!==null&&(a.name=this._names.at(a.name))),e.call(s,a)},()=>{switch(i){case se.GENERATED_ORDER:this._wasm.exports.by_generated_location(this._getMappingsPtr());break;case se.ORIGINAL_ORDER:this._wasm.exports.by_original_location(this._getMappingsPtr());break;default:throw new Error("Unknown order of iteration.")}})}allGeneratedPositionsFor(e){let n=O.getArg(e,"source");const r=O.getArg(e,"line"),s=e.column||0;if(n=this._findSourceIndex(n),n<0)return[];if(r<1)throw new Error("Line numbers must be >= 1");if(s<0)throw new Error("Column numbers must be >= 0");const i=[];return this._wasm.withMappingCallback(o=>{let a=o.lastGeneratedColumn;this._computedColumnSpans&&a===null&&(a=1/0),i.push({line:o.generatedLine,column:o.generatedColumn,lastColumn:a})},()=>{this._wasm.exports.all_generated_locations_for(this._getMappingsPtr(),n,r-1,"column"in e,s)}),i}destroy(){this._mappingsPtr!==0&&(this._wasm.exports.free_mappings(this._mappingsPtr),this._mappingsPtr=0)}computeColumnSpans(){this._computedColumnSpans||(this._wasm.exports.compute_column_spans(this._getMappingsPtr()),this._computedColumnSpans=!0)}originalPositionFor(e){const n={generatedLine:O.getArg(e,"line"),generatedColumn:O.getArg(e,"column")};if(n.generatedLine<1)throw new Error("Line numbers must be >= 1");if(n.generatedColumn<0)throw new Error("Column numbers must be >= 0");let r=O.getArg(e,"bias",se.GREATEST_LOWER_BOUND);r==null&&(r=se.GREATEST_LOWER_BOUND);let s;if(this._wasm.withMappingCallback(i=>s=i,()=>{this._wasm.exports.original_location_for(this._getMappingsPtr(),n.generatedLine-1,n.generatedColumn,r)}),s&&s.generatedLine===n.generatedLine){let i=O.getArg(s,"source",null);i!==null&&(i=this._sources.at(i),i=O.computeSourceURL(this.sourceRoot,i,this._sourceMapURL));let o=O.getArg(s,"name",null);return o!==null&&(o=this._names.at(o)),{source:i,line:O.getArg(s,"originalLine",null),column:O.getArg(s,"originalColumn",null),name:o}}return{source:null,line:null,column:null,name:null}}hasContentsOfAllSources(){return this.sourcesContent?this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(e){return e==null}):!1}sourceContentFor(e,n){if(!this.sourcesContent)return null;const r=this._findSourceIndex(e);if(r>=0)return this.sourcesContent[r];let s=e;this.sourceRoot!=null&&(s=O.relative(this.sourceRoot,s));let i;if(this.sourceRoot!=null&&(i=O.urlParse(this.sourceRoot))){const o=s.replace(/^file:\/\//,"");if(i.scheme=="file"&&this._sources.has(o))return this.sourcesContent[this._sources.indexOf(o)];if((!i.path||i.path=="/")&&this._sources.has("/"+s))return this.sourcesContent[this._sources.indexOf("/"+s)]}if(n)return null;throw new Error('"'+s+'" is not in the SourceMap.')}generatedPositionFor(e){let n=O.getArg(e,"source");if(n=this._findSourceIndex(n),n<0)return{line:null,column:null,lastColumn:null};const r={source:n,originalLine:O.getArg(e,"line"),originalColumn:O.getArg(e,"column")};if(r.originalLine<1)throw new Error("Line numbers must be >= 1");if(r.originalColumn<0)throw new Error("Column numbers must be >= 0");let s=O.getArg(e,"bias",se.GREATEST_LOWER_BOUND);s==null&&(s=se.GREATEST_LOWER_BOUND);let i;if(this._wasm.withMappingCallback(o=>i=o,()=>{this._wasm.exports.generated_location_for(this._getMappingsPtr(),r.source,r.originalLine-1,r.originalColumn,s)}),i&&i.source===r.source){let o=i.lastGeneratedColumn;return this._computedColumnSpans&&o===null&&(o=1/0),{line:O.getArg(i,"generatedLine",null),column:O.getArg(i,"generatedColumn",null),lastColumn:o}}return{line:null,column:null,lastColumn:null}}}rs.prototype.consumer=se;class QR extends se{constructor(e,n){return super(Ua).then(r=>{let s=e;typeof e=="string"&&(s=O.parseSourceMapInput(e));const i=O.getArg(s,"version"),o=O.getArg(s,"sections");if(i!=r._version)throw new Error("Unsupported version: "+i);r._sources=new Ti,r._names=new Ti,r.__generatedMappings=null,r.__originalMappings=null,r.__generatedMappingsUnsorted=null,r.__originalMappingsUnsorted=null;let a={line:-1,column:0};return Promise.all(o.map(c=>{if(c.url)throw new Error("Support for url field in sections not implemented.");const l=O.getArg(c,"offset"),u=O.getArg(l,"line"),h=O.getArg(l,"column");if(u({generatedOffset:{generatedLine:u+1,generatedColumn:h+1},consumer:f}))})).then(c=>(r._sections=c,r))})}get _generatedMappings(){return this.__generatedMappings||this._sortGeneratedMappings(),this.__generatedMappings}get _originalMappings(){return this.__originalMappings||this._sortOriginalMappings(),this.__originalMappings}get _generatedMappingsUnsorted(){return this.__generatedMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__generatedMappingsUnsorted}get _originalMappingsUnsorted(){return this.__originalMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__originalMappingsUnsorted}_sortGeneratedMappings(){const e=this._generatedMappingsUnsorted;e.sort(O.compareByGeneratedPositionsDeflated),this.__generatedMappings=e}_sortOriginalMappings(){const e=this._originalMappingsUnsorted;e.sort(O.compareByOriginalPositions),this.__originalMappings=e}get sources(){const e=[];for(let n=0;na.push(c));for(let c=0;c= 1");if(r.originalColumn<0)throw new Error("Column numbers must be >= 0");const s=[];let i=this._findMapping(r,this._originalMappings,"originalLine","originalColumn",O.compareByOriginalPositions,xa.LEAST_UPPER_BOUND);if(i>=0){let o=this._originalMappings[i];if(e.column===void 0){const a=o.originalLine;for(;o&&o.originalLine===a;){let c=o.lastGeneratedColumn;this._computedColumnSpans&&c===null&&(c=1/0),s.push({line:O.getArg(o,"generatedLine",null),column:O.getArg(o,"generatedColumn",null),lastColumn:c}),o=this._originalMappings[++i]}}else{const a=o.originalColumn;for(;o&&o.originalLine===n&&o.originalColumn==a;){let c=o.lastGeneratedColumn;this._computedColumnSpans&&c===null&&(c=1/0),s.push({line:O.getArg(o,"generatedLine",null),column:O.getArg(o,"generatedColumn",null),lastColumn:c}),o=this._originalMappings[++i]}}}return s}destroy(){for(let e=0;e=0;n--)this.prepend(e[n]);else if(e[sr]||typeof e=="string")this.children.unshift(e);else throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);return this}walk(e){let n;for(let r=0,s=this.children.length;r0){for(n=[],r=0;rString.fromCharCode(t)),wv=x({name:"Whitespace",pattern:/ +/}),Rv=x({name:"WhitespaceSkipped",pattern:/ +/,group:ge.SKIPPED}),Qf=x({name:"StringLiteral",pattern:/[^ $]+/,start_chars_hint:Av}),Zf=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),Ga=x({name:"MaybeFlag",pattern:/\$[^ $]+/}),ed=x({name:"NumberLiteral",pattern:/\$-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?\+?/}),td=x({name:"ContinueLine",pattern:/\\/});function nd(t,e=""){return x({name:e||t,pattern:new RegExp(t.toLowerCase(),"i")})}const rd=[["blue"],["green"],["cyan"],["red"],["purple"],["yellow"],["white"],["dkblue"],["dkgreen"],["dkcyan"],["dkred"],["dkpurple"],["dkyellow|brown","brown"],["dkwhite|ltgray|ltgrey|gray|grey","gray"],["dkgray|dkgrey|ltblack","dkgray"],["black"],["clear"]],sd=rd.map(([t,e])=>nd(`\\$(${t})`,e||t)),id=[...rd.map(([t,e])=>nd(`\\$on(${t})`,`on${e||t}`))],vv=[wv,td,...sd,...id,Zf,Qf,ed,Ga],Nv=new ge(vv,{skipValidations:!wt,ensureOptimizations:wt}),Cv=new ge([Rv,td,...sd,...id,Zf,Qf,ed,Ga],{skipValidations:!wt,ensureOptimizations:wt});function Iv(t,e=!1){return e?Cv.tokenize(t):Nv.tokenize(t)}function Lv(t,e,n,r){return{measureOnly:!1,resetCheck:!0,x:0,y:0,isEven:!0,resetColor:n,resetBg:r,activeColor:n,activeBg:r,width:t,height:e,leftEdge:void 0,rightEdge:void 0,bottomEdge:void 0,char:[],color:[],bg:[]}}Sv.createContext(Lv(1,1,15,1));let Ov=0,od=0;const ad=wt,kv=["Command","lines"];class bv extends iR{constructor(){super(Kh,{traceInitPerf:wt,skipValidations:!wt,maxLookahead:2,recoveryEnabled:!0,nodeLocationTracking:"full"});U(this,"program",this.RULED("program",()=>{this.MANY(()=>this.SUBRULE(this.line))}));U(this,"line",this.RULED("line",()=>{this.OPTION(()=>this.SUBRULE(this.stmt)),this.AT_LEAST_ONE(()=>this.CONSUME(qr))}));U(this,"stmt",this.RULED("stmt",()=>{this.OR([{ALT:()=>this.SUBRULE(this.stat)},{ALT:()=>this.SUBRULE(this.text)},{ALT:()=>this.SUBRULE(this.label)},{ALT:()=>this.SUBRULE(this.comment)},{ALT:()=>this.SUBRULE(this.commands)}])}));U(this,"stat",this.RULED("stat",()=>{this.CONSUME(pa)}));U(this,"text",this.RULED("text",()=>{this.CONSUME(hh)}));U(this,"label",this.RULED("label",()=>{this.CONSUME(dh)}));U(this,"comment",this.RULED("comment",()=>{this.CONSUME(fh)}));U(this,"commands",this.RULED("commands",()=>{this.OR([{ALT:()=>{this.CONSUME(ht),this.AT_LEAST_ONE1(()=>this.SUBRULE1(this.command))}},{ALT:()=>{this.AT_LEAST_ONE2(()=>this.SUBRULE2(this.command))}}])}));U(this,"command",this.RULED("command",()=>{this.OR([{ALT:()=>this.SUBRULE(this.flat_cmd)},{ALT:()=>this.SUBRULE(this.structured_cmd)}])}));U(this,"flat_cmd",this.RULED("flat_cmd",()=>{this.OR([{ALT:()=>this.SUBRULE(this.words)},{ALT:()=>this.SUBRULE(this.hyperlink)},{ALT:()=>this.SUBRULE(this.Short_go)},{ALT:()=>this.SUBRULE(this.Short_try)},{ALT:()=>this.SUBRULE(this.Command_play)}])}));U(this,"structured_cmd",this.RULED("structured_cmd",()=>{this.OR([{ALT:()=>this.SUBRULE(this.Command_if)},{ALT:()=>this.SUBRULE(this.Command_read)},{ALT:()=>this.SUBRULE(this.Command_while)},{ALT:()=>this.SUBRULE(this.Command_repeat)},{ALT:()=>this.SUBRULE(this.Command_break)},{ALT:()=>this.SUBRULE(this.Command_continue)}])}));U(this,"hyperlink",this.RULED("hyperlink",()=>{this.CONSUME(ph),this.SUBRULE(this.words),this.CONSUME(gh)}));U(this,"Short_go",this.RULED("Short_go",()=>{this.CONSUME(Ta),this.SUBRULE(this.words)}));U(this,"Short_try",this.RULED("Short_try",()=>{this.CONSUME(Ih),this.SUBRULE(this.words)}));U(this,"Command_play",this.RULED("Command_play",()=>{this.CONSUME(kh)}));U(this,"do_line",this.RULED("do_line",()=>{this.OPTION(()=>this.SUBRULE(this.do_stmt)),this.AT_LEAST_ONE(()=>this.CONSUME(qr))}));U(this,"do_stmt",this.RULED("do_stmt",()=>{this.OR([{ALT:()=>this.SUBRULE(this.text)},{ALT:()=>this.SUBRULE(this.comment)},{ALT:()=>this.SUBRULE(this.commands)}])}));U(this,"Command_if",this.RULED("Command_if",()=>{this.CONSUME(Sa),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.OR2([{GATE:this.BACKTRACK(this.Command_else_if),ALT:()=>this.SUBRULE(this.Command_else_if)},{GATE:this.BACKTRACK(this.Command_else),ALT:()=>this.SUBRULE(this.Command_else)},{GATE:this.BACKTRACK(this.Command_endif),ALT:()=>this.SUBRULE(this.Command_endif)}])}}])})}));U(this,"Command_else_if",this.RULED("Command_else_if",()=>{this.CONSUME(ht),this.CONSUME(Aa),this.CONSUME(Sa),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.OR2([{GATE:this.BACKTRACK(this.Command_else_if),ALT:()=>this.SUBRULE(this.Command_else_if)},{GATE:this.BACKTRACK(this.Command_else),ALT:()=>this.SUBRULE(this.Command_else)},{GATE:this.BACKTRACK(this.Command_endif),ALT:()=>this.SUBRULE(this.Command_endif)}])}}])})}));U(this,"Command_else",this.RULED("Command_else",()=>{this.CONSUME(ht),this.CONSUME(Aa),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.SUBRULE(this.Command_endif)}}])})}));U(this,"Command_endif",this.RULED("Command_endif",()=>{this.CONSUME(ht),this.CONSUME(bh)}));U(this,"Command_while",this.RULED("Command_while",()=>{this.CONSUME(ht),this.CONSUME(Mh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(ht),this.CONSUME4(xh)}}])})}));U(this,"Command_repeat",this.RULED("Command_repeat",()=>{this.CONSUME(ht),this.CONSUME(Uh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(ht),this.CONSUME4(Ph)}}])})}));U(this,"Command_read",this.RULED("Command_read",()=>{this.CONSUME(ht),this.CONSUME(Dh),this.SUBRULE(this.words),this.OPTION(()=>{this.OR([{ALT:()=>this.SUBRULE(this.command)},{ALT:()=>{this.CONSUME(Ln),this.AT_LEAST_ONE(()=>this.SUBRULE(this.do_line)),this.CONSUME4(ht),this.CONSUME4(Fh)}}])})}));U(this,"Command_break",this.RULED("Command_break",()=>{this.CONSUME($h)}));U(this,"Command_continue",this.RULED("Command_continue",()=>{this.CONSUME(Bh)}));U(this,"expr",this.RULED("expr",()=>{this.SUBRULE1(this.and_test),this.MANY(()=>{this.CONSUME(ga),this.SUBRULE2(this.and_test)})}));U(this,"and_test",this.RULED("and_test",()=>{this.SUBRULE1(this.not_test),this.MANY(()=>{this.CONSUME(Ea),this.SUBRULE2(this.not_test)})}));U(this,"not_test",this.RULED("not_test",()=>{this.OR([{ALT:()=>{this.CONSUME(ma),this.SUBRULE1(this.not_test)}},{ALT:()=>this.SUBRULE2(this.comparison)}])}));U(this,"comparison",this.RULED("comparison",()=>{this.SUBRULE1(this.arith_expr),this.MANY(()=>{this.SUBRULE(this.comp_op),this.SUBRULE2(this.arith_expr)})}));U(this,"comp_op",this.RULED("comp_op",()=>{this.OR([{ALT:()=>this.CONSUME(_h)},{ALT:()=>this.CONSUME(yh)},{ALT:()=>this.CONSUME(Th)},{ALT:()=>this.CONSUME(Sh)},{ALT:()=>this.CONSUME(Ah)},{ALT:()=>this.CONSUME(wh)}])}));U(this,"expr_value",this.RULED("expr_value",()=>{this.SUBRULE1(this.and_test_value),this.MANY(()=>{this.CONSUME(ga),this.SUBRULE2(this.and_test_value)})}));U(this,"and_test_value",this.RULED("and_test_value",()=>{this.SUBRULE1(this.not_test_value),this.MANY(()=>{this.CONSUME(Ea),this.SUBRULE2(this.not_test_value)})}));U(this,"not_test_value",this.RULED("not_test_value",()=>{this.OR([{ALT:()=>{this.CONSUME(ma),this.SUBRULE1(this.not_test_value)}},{ALT:()=>this.SUBRULE2(this.arith_expr)}])}));U(this,"arith_expr",this.RULED("arith_expr",()=>{this.SUBRULE1(this.term),this.MANY(()=>this.SUBRULE2(this.arith_expr_item))}));U(this,"arith_expr_item",this.RULED("arith_expr_item",()=>{this.OR([{ALT:()=>this.CONSUME(_a)},{ALT:()=>this.CONSUME(ya)}]),this.SUBRULE(this.term)}));U(this,"term",this.RULED("term",()=>{this.SUBRULE1(this.factor),this.MANY(()=>this.SUBRULE2(this.term_item))}));U(this,"term_item",this.RULED("term_item",()=>{this.OR([{ALT:()=>this.CONSUME(vh)},{ALT:()=>this.CONSUME(Ta)},{ALT:()=>this.CONSUME(Nh)},{ALT:()=>this.CONSUME(Ch)}]),this.SUBRULE(this.factor)}));U(this,"factor",this.RULED("factor",()=>{this.OR1([{ALT:()=>{this.OR2([{ALT:()=>this.CONSUME(_a)},{ALT:()=>this.CONSUME(ya)}]),this.SUBRULE(this.factor)}},{ALT:()=>this.SUBRULE(this.power)}])}));U(this,"power",this.RULED("power",()=>{this.SUBRULE(this.token),this.OPTION(()=>{this.CONSUME(Rh),this.SUBRULE(this.factor)})}));U(this,"words",this.RULED("words",()=>{this.AT_LEAST_ONE(()=>this.SUBRULE(this.expr))}));U(this,"token",this.RULED("token",()=>{this.OR([{ALT:()=>this.CONSUME(mh)},{ALT:()=>this.CONSUME(We)},{ALT:()=>this.CONSUME(Eh)},{ALT:()=>{this.CONSUME(Lh),this.SUBRULE(this.expr),this.CONSUME(Oh)}}])}));this.performSelfAnalysis()}PEEK(n,r,...s){console.info(n,s.map(i=>[i.image,i.tokenType]),r)}RULED(n,r,s){const i=kv.some(o=>n.includes(o));return this.RULE(n,()=>{const o=Ov++,a=od++,c=a.toString().padStart(3),l=" ".repeat(a),u=i?"font-weight: bold;":"";if(ad&&!this.RECORDING_PHASE){const d=[this.LA(0),this.LA(1),this.LA(2)].map(f=>[`[${f.tokenType.name}]`,f.image.replaceAll(` -`,"\\n")]).flat();console.info(`${c}%c${l}> ${n} ${o} ${d.join(" ")}`,u)}r(),ad&&!this.RECORDING_PHASE&&console.info(`${c}%c${l}< ${n} ${o}`,u),od--},s)}}const is=new bv,Mv=is.getBaseCstVisitorConstructor();var q=(t=>(t[t.PROGRAM=0]="PROGRAM",t[t.TEXT=1]="TEXT",t[t.LABEL=2]="LABEL",t[t.HYPERLINK=3]="HYPERLINK",t[t.STAT=4]="STAT",t[t.MOVE=5]="MOVE",t[t.COMMAND=6]="COMMAND",t[t.LITERAL=7]="LITERAL",t[t.IF=8]="IF",t[t.ELSE_IF=9]="ELSE_IF",t[t.ELSE=10]="ELSE",t[t.WHILE=11]="WHILE",t[t.BREAK=12]="BREAK",t[t.CONTINUE=13]="CONTINUE",t[t.REPEAT=14]="REPEAT",t[t.READ=15]="READ",t[t.OR=16]="OR",t[t.AND=17]="AND",t[t.NOT=18]="NOT",t[t.COMPARE=19]="COMPARE",t[t.OPERATOR=20]="OPERATOR",t[t.OPERATOR_ITEM=21]="OPERATOR_ITEM",t[t.EXPR=22]="EXPR",t))(q||{}),kn=(t=>(t[t.IS_EQ=0]="IS_EQ",t[t.IS_NOT_EQ=1]="IS_NOT_EQ",t[t.IS_LESS_THAN=2]="IS_LESS_THAN",t[t.IS_GREATER_THAN=3]="IS_GREATER_THAN",t[t.IS_LESS_THAN_OR_EQ=4]="IS_LESS_THAN_OR_EQ",t[t.IS_GREATER_THAN_OR_EQ=5]="IS_GREATER_THAN_OR_EQ",t))(kn||{}),vt=(t=>(t[t.EMPTY=0]="EMPTY",t[t.PLUS=1]="PLUS",t[t.MINUS=2]="MINUS",t[t.POWER=3]="POWER",t[t.MULTIPLY=4]="MULTIPLY",t[t.DIVIDE=5]="DIVIDE",t[t.MOD_DIVIDE=6]="MOD_DIVIDE",t[t.FLOOR_DIVIDE=7]="FLOOR_DIVIDE",t[t.UNI_PLUS=8]="UNI_PLUS",t[t.UNI_MINUS=9]="UNI_MINUS",t))(vt||{}),vi=(t=>(t[t.NUMBER=0]="NUMBER",t[t.STRING=1]="STRING",t[t.TEMPLATE=2]="TEMPLATE",t))(vi||{});function sL(t){return t}function ie(t,e){return((e==null?void 0:e.map(n=>t.visit(n)).filter(n=>n))||[]).flat()}function an(t){return t.image}function cd(t,e){return F(t,{type:7,literal:1,value:e})}function xv(t){return!!(t!=null&&t.tokenType)}function Uv(t){const e=Object.values(t).flat().filter(n=>!!n).map(n=>n&&xv(n)?{startLine:n.startLine,startColumn:n.startColumn,startOffset:n.startOffset,endLine:n.endLine,endColumn:n.endColumn,endOffset:n.endOffset}:n!=null&&n.location?{...n.location}:{startLine:0,startColumn:0,startOffset:0,endLine:0,endColumn:0,endOffset:0}).filter(n=>n.startLine!==0&&n.endLine!==0);return{startLine:Math.min(...e.map(n=>n.startLine||1)),startColumn:Math.min(...e.map(n=>n.startColumn||1)),startOffset:Math.min(...e.map(n=>n.startOffset||1)),endLine:Math.max(...e.map(n=>n.endLine||1)),endColumn:Math.max(...e.map(n=>n.endColumn||1)),endOffset:Math.max(...e.map(n=>n.endOffset||1))}}function F(t,e){return{...e,...Uv(t)}}class Pv extends Mv{constructor(){super(),wt&&this.validateVisitor()}program(e){return F(e,{type:0,lines:ie(this,e.line)})}line(e){if(e.stmt)return this.visit(e.stmt)}stmt(e){if(e.stat)return this.visit(e.stat);if(e.text)return this.visit(e.text);if(e.label)return this.visit(e.label);if(e.comment)return this.visit(e.comment);if(e.commands)return this.visit(e.commands)}stat(){}text(e){if(e.Text)return F(e,{type:1,value:an(e.Text[0])})}label(e){var n;return F(e,{type:2,active:!0,name:an(((n=e.Label)==null?void 0:n[0])??":").slice(1).trim()})}comment(e){return F(e,{type:2,active:!1,name:an(e.Comment[0]).slice(1).trim()})}commands(e){return ie(this,e.command)}command(e){if(e.flat_cmd)return this.visit(e.flat_cmd);if(e.structured_cmd)return this.visit(e.structured_cmd)}flat_cmd(e){if(e.words)return F(e,{type:6,words:ie(this,e.words).flat()});if(e.hyperlink)return this.visit(e.hyperlink);if(e.Short_go)return this.visit(e.Short_go);if(e.Short_try)return this.visit(e.Short_try);if(e.Command_play)return this.visit(e.Command_play)}structured_cmd(e){if(e.Command_if)return this.visit(e.Command_if);if(e.Command_read)return this.visit(e.Command_read);if(e.Command_while)return this.visit(e.Command_while);if(e.Command_repeat)return this.visit(e.Command_repeat);if(e.Command_break)return this.visit(e.Command_break);if(e.Command_continue)return this.visit(e.Command_continue)}hyperlink(e){var n;return F(e,{type:3,link:ie(this,e.words).flat(),text:an(((n=e.HyperLinkText)==null?void 0:n[0])??";").slice(1)})}Short_go(e){if(e.Divide)return F(e,{type:5,wait:!0,words:ie(this,e.words).flat()})}Short_try(e){if(e.Query)return F(e,{type:5,wait:!1,words:ie(this,e.words).flat()})}Command_play(e){if(e.Command_play)return F(e,{type:6,words:[cd(e,"play"),cd(e,an(e.Command_play[0]).replace("#play","").trim())]})}do_line(e){return this.visit(e.do_stmt)}do_stmt(e){if(e.text)return this.visit(e.text);if(e.comment)return this.visit(e.comment);if(e.commands)return this.visit(e.commands)}Command_if(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat(),s=[this.visit(e.Command_else_if),this.visit(e.Command_else)].flat();return F(e,{type:8,method:"if",words:n.filter(y),lines:r.filter(y),branches:s.filter(y)})}Command_else_if(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat(),s=ie(this,e.Command_else_if).flat();return[F(e,{type:9,method:"if",words:n.filter(y),lines:r.filter(y)}),...s.filter(y),this.visit(e.Command_else)]}Command_else(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat();return F(e,{type:10,method:"if",words:n.filter(y),lines:r.filter(y)})}Command_endif(){}Command_while(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat();return F(e,{type:11,words:n.filter(y),lines:r.filter(y)})}Command_repeat(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat();return F(e,{type:14,words:n.filter(y),lines:r.filter(y)})}Command_read(e){const n=ie(this,e.words).flat(),r=[this.visit(e.command),...ie(this,e.do_line)].flat();return F(e,{type:15,words:n.filter(y),lines:r.filter(y)})}Command_break(e){return F(e,{type:12})}Command_continue(e){return F(e,{type:13})}expr(e){return e.and_test.length===1?this.visit(e.and_test):F(e,{type:16,items:this.visit(e.and_test)})}and_test(e){return e.not_test.length===1?this.visit(e.not_test):F(e,{type:17,items:this.visit(e.not_test)})}not_test(e){if(e.comparison)return this.visit(e.comparison);if(e.not_test)return F(e,{type:18,items:this.visit(e.not_test)})}comparison(e){return e.arith_expr.length===1?this.visit(e.arith_expr):F(e,{type:19,lhs:this.visit(e.arith_expr[0]),compare:this.visit(e.comp_op),rhs:this.visit(e.arith_expr[1])})}comp_op(e){if(e.is||e.IsEq)return 0;if(e.IsNotEq)return 1;if(e.IsLessThan)return 2;if(e.IsGreaterThan)return 3;if(e.IsLessThanOrEqual)return 4;if(e.IsGreaterThanOrEqual)return 5}expr_value(e){return e.and_test_value.length===1?this.visit(e.and_test_value):F(e,{type:16,items:this.visit(e.and_test_value)})}and_test_value(e){return e.not_test_value.length===1?this.visit(e.not_test_value):F(e,{type:17,items:this.visit(e.not_test_value)})}not_test_value(e){if(e.arith_expr)return this.visit(e.arith_expr);if(e.not_test)return F(e,{type:18,items:this.visit(e.not_test)})}arith_expr(e){const n=this.visit(e.term);return e.arith_expr_item?F(e,{type:20,lhs:n,items:this.visit(e.arith_expr_item)}):n}arith_expr_item(e){return F(e,{type:21,operator:e.Plus?1:2,rhs:this.visit(e.term)})}term(e){return e.term_item?F(e,{type:20,lhs:this.visit(e.factor),items:this.visit(e.term_item)}):this.visit(e.factor)}term_item(e){let n=0;return e.Multiply&&(n=4),e.Divide&&(n=5),e.ModDivide&&(n=6),e.FloorDivide&&(n=7),F(e,{type:21,operator:n,rhs:this.visit(e.factor)})}factor(e){if(e.power)return this.visit(e.power);let n=0;return e.Plus&&(n=8),e.Minus&&(n=9),F(e,{type:20,lhs:void 0,items:[F(e,{type:21,operator:n,rhs:this.visit(e.factor)})]})}power(e){const n=this.visit(e.token);return e.factor?F(e,{type:20,lhs:n,items:[F(e,{type:21,operator:3,rhs:this.visit(e.factor)})]}):n}words(e){return ie(this,e.expr)}token(e){if(e.StringLiteralDouble){const n=an(e.StringLiteralDouble[0]);return F(e,{type:7,literal:2,value:n.substring(1,n.length-1)})}if(e.StringLiteral)return F(e,{type:7,literal:1,value:an(e.StringLiteral[0])});if(e.NumberLiteral)return F(e,{type:7,literal:0,value:parseFloat(an(e.NumberLiteral[0]))});if(e.LParen)return F(e,{type:22,words:ie(this,e.expr).flat()})}}const Dv=new Pv,Pe={internal:0,labels:{},labelIndex:0},Ni="if (api.hm()) { continue zss; }",ld=`if (api.sy()) { yield 1; ${Ni} };`,Ci=`yield 1; ${Ni}`,Ii="zss.js";function oe(t,e){return new iv(t.startLine||1,t.startColumn||1,Ii,e)}function Ka(t){return t.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}function Fv(t){return`'${Ka(t)}'`}function Li(t){if(t.startsWith('"'))return Li(t.substring(1,t.length-1));const e=Iv(t);return e.errors.length?t:`'${e.tokens.map(r=>r.tokenType===Ga?`', api.group('${Ka(r.image.substring(1))}'), '`:Ka(r.image)).join("")}'`}function Nt(t){return t.filter(e=>e!==void 0).map(H)}function ud(t){return oe(t,"")}function $v(t,e){const n=[];return t.forEach(r=>{n.push(r,e)}),n.pop(),n}function ee(t,e,n){return oe(t,[`api.${e}(`,...$v(n,", "),")"])}function Bv(t){if(t.type===q.COMPARE)switch(t.compare){case kn.IS_EQ:return ee(t,"isEq",[H(t.lhs),H(t.rhs)]);case kn.IS_NOT_EQ:return ee(t,"isNotEq",[H(t.lhs),H(t.rhs)]);case kn.IS_LESS_THAN:return ee(t,"isLessThan",[H(t.lhs),H(t.rhs)]);case kn.IS_GREATER_THAN:return ee(t,"isGreaterThan",[H(t.lhs),H(t.rhs)]);case kn.IS_LESS_THAN_OR_EQ:return ee(t,"isLessThanOrEq",[H(t.lhs),H(t.rhs)]);case kn.IS_GREATER_THAN_OR_EQ:return ee(t,"isGreaterThanOrEq",[H(t.lhs),H(t.rhs)])}return oe(t,"")}function bn(t,e,n,r){return e.prepend(`api.${n}(`),e.add([", ",H(r),")"])}function hd(t,e,n,r){return e.prepend(`api.${n}(`),e.add([H(r),")"])}function Gv(t,e){if(t.type===q.OPERATOR_ITEM)switch(t.operator){case vt.PLUS:return bn(t,e,"opPlus",t.rhs);case vt.MINUS:return bn(t,e,"opMinus",t.rhs);case vt.POWER:return bn(t,e,"opPower",t.rhs);case vt.MULTIPLY:return bn(t,e,"opMultiply",t.rhs);case vt.DIVIDE:return bn(t,e,"opDivide",t.rhs);case vt.MOD_DIVIDE:return bn(t,e,"opModDivide",t.rhs);case vt.FLOOR_DIVIDE:return bn(t,e,"opFloorDivide",t.rhs);case vt.UNI_PLUS:return hd(t,e,"opUniPlus",t.rhs);case vt.UNI_MINUS:return hd(t,e,"opUniMinus",t.rhs)}return oe(t,"")}function Kv(t){if(t.type===q.OPERATOR){const e=t.lhs?H(t.lhs):oe(t,"");return t.items.forEach(n=>Gv(n,e)),e}return oe(t,"")}function H(t){switch(t.type){case q.PROGRAM:return oe(t,[`try { // first-line -`,`zss: while (true) { -`,`switch (api.getcase()) { -`,`default: -`,`case 1: -`,...t.lines.map(e=>[H(e),` -`]).flat(),`} -`,`api.endofprogram(); -`,`while(true) { ${Ci} } -`,`} -`,`} catch (e) { -`,`console.error(e); -`,`const source = api.stacktrace(e); -`,`const err = new Error(e.message); -`,`err.name = 'GameError'; -`,`err.meta = { line: source.line, column: source.column }; -`,`throw err; -`,`} -`,`//# sourceURL=${Ii}`]);case q.LITERAL:switch(t.literal){case vi.NUMBER:return oe(t,`${t.value}`);case vi.STRING:return oe(t,Fv(t.value));case vi.TEMPLATE:return oe(t,Li(t.value))}return ud(t);case q.TEXT:return ee(t,"text",[Li(t.value)]);case q.STAT:return ee(t,"stat",Nt(t.words));case q.LABEL:{const e=Pe.labelIndex++;return Pe.labels[t.name]||(Pe.labels[t.name]=[]),Pe.labels[t.name].push(t.active?e:-e),oe(t,`case ${e}: // ${t.name}`)}case q.HYPERLINK:return ee(t,"hyperlink",[Li(t.text),...Nt(t.link)]);case q.MOVE:return oe(t,["while (",ee(t,"move",[t.wait?"true":"false",...Nt(t.words)]),`) { ${Ci} }; - ${ld} ${Ni}`]);case q.COMMAND:return oe(t,["while (",ee(t,"command",Nt(t.words)),`) { ${Ci} }; - ${ld} ${Ni}`]);case q.IF:{const e=oe(t,["if (",ee(t,`${t.method}`,Nt(t.words)),`) { -`]);return t.lines&&t.lines.forEach(n=>e.add([H(n),` -`])),t.branches&&t.branches.forEach(n=>e.add(H(n))),e.add("}"),e}case q.ELSE_IF:{const e=oe(t,["} else if (",ee(t,t.method,Nt(t.words)),`) { -`]);return t.lines&&t.lines.forEach(n=>e.add([H(n),` -`])),e}case q.ELSE:{const e=oe(t,`} else { -`);return t.words.length&&e.add(["while (",ee(t,"command",Nt(t.words)),`) { ${Ci} };`]),t.lines&&t.lines.forEach(n=>e.add([H(n),` -`])),e}case q.WHILE:{const e=oe(t,["while (",ee(t,"if",Nt(t.words)),`) { -`]);return t.lines&&t.lines.forEach(n=>e.add([H(n),` -`])),e.add("}"),e}case q.REPEAT:{const e=oe(t,[ee(t,"repeatStart",[`${Pe.internal}`,...Nt(t.words)]),`; -while (`,ee(t,"repeat",[`${Pe.internal}`]),`) { -`]);return Pe.internal+=1,t.lines&&t.lines.forEach(n=>e.add([H(n),` -`])),e.add("}"),e}case q.READ:{const[e,...n]=t.words,r=oe(t,[ee(t,"readStart",[`${Pe.internal}`,H(e)]),`; -while (`,ee(t,"read",[`${Pe.internal}`,...Nt(n)]),`) { -`]);return Pe.internal+=1,t.lines&&t.lines.forEach(s=>r.add([H(s),` -`])),r.add("}"),r}case q.BREAK:return oe(t,`break; -`);case q.CONTINUE:return oe(t,`continue; -`);case q.OR:return ee(t,"or",t.items.map(H));case q.AND:return ee(t,"and",t.items.map(H));case q.NOT:return ee(t,"not",t.items.map(H));case q.COMPARE:return Bv(t);case q.OPERATOR:return Kv(t);case q.EXPR:return ee(t,"expr",t.words.map(H));default:return console.error("",t),ud(t)}}function Wv(t){return Pe.internal=0,Pe.labels={restart:[1]},Pe.labelIndex=2,{...H(t).toStringWithSourceMap({file:`${Ii}.map`}),...Pe}}const jv=64;function Hv(t){return Array.isArray(t)?t.length>0?1:0:t??0}function Yt(t){return`${t??""}`}function Vv(t,e){var N;const n=Yg(e.labels??{});let r,s="",i,o=0;const a={},c={},l={};let u=!1,h=3,d=0,f=0,p=!1;const E=[];let w={};function A(T){if(w[T]===void 0)for(let m=0;mjv},hm(){var m;const T=(i==null?void 0:i.target)??"";return((m=n[T])==null?void 0:m.find(g=>g>0))??0},yield(){u=!0},sy(){return u||_.shouldhalt()},send(T,m,g){const S=`vm:${T}:${m}`;De.emit(S,t,g)},lock(T){s=T},unlock(){s=""},message(T){s&&T.sender!==s||(i=T)},zap(T){const m=n[T];if(m){const g=m.findIndex(S=>S>0);g>=0&&(m[g]*=-1)}},restore(T){const m=n[T];if(m)for(let g=0;gS.fileName===Ii);return{line:(g==null?void 0:g.lineNumber)??0,column:(g==null?void 0:g.columnNumber)??0}},text(T){return R("text",[T])},stat(...T){return R("stat",T)},hyperlink(...T){return R("hyperlink",T)},move(T,...m){const g=_.command("go",...m);return _.yield(),g&&T?1:0},command(...T){if(T.length===0)return 0;const[m,...g]=T,S=A(Yt(m));return S?S(_,g):R("send",[m,...g])},if(...T){const m=K(_,T),[g,S]=I(m,0,[C.ANY]),v=Hv(g);return v&&S0,S=c[T];return g&&S&&_.command(...S),g},readStart(T,m){if(!le(m))return;const g=_.get(m)??[];l[T]=Array.isArray(g)?g:[g]},read(T,...m){const g=l[T];if(Array.isArray(g)===!1)return!1;const S=g.shift();if(S===void 0)return!1;const v=m.map(Yt);switch(typeof S){case"number":case"string":v.forEach(j=>{_.set(j,S)});break;case"object":v.forEach(j=>{const ye=S[j];_.set(j,ye)});break}return!0},or(...T){const m=K(_,T);let g=0;for(let S=0;SS?1:0},isLessThanOrEq(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return g<=S?1:0},isGreaterThanOrEq(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return g>=S?1:0},opPlus(T,m){const[g]=I(K(_,[T]),0,[C.ANY]),[S]=I(K(_,[m]),0,[C.ANY]);return g+S},opMinus(T,m){const[g]=I(K(_,[T]),0,[C.ANY]),[S]=I(K(_,[m]),0,[C.ANY]);return g-S},opPower(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return Math.pow(g,S)},opMultiply(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return g*S},opDivide(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return g/S},opModDivide(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return g%S},opFloorDivide(T,m){const[g]=I(K(_,[T]),0,[C.NUMBER]),[S]=I(K(_,[m]),0,[C.NUMBER]);return Math.floor(g/S)},opUniPlus(T){const[m]=I(K(_,[T]),0,[C.NUMBER]);return+m},opUniMinus(T){const[m]=I(K(_,[T]),0,[C.NUMBER]);return-m}};return r=(N=e.code)==null?void 0:N.call(e,_),_}function fd(t){const e={},n={...t,getcommand(r){return e[r]},command(r,s){return e[r]=s,n}};return n}var dd={exports:{}};/*! Case - v1.6.2 - 2020-03-24 -* Copyright (c) 2020 Nathan Bubna; Licensed MIT, GPL */(function(t){(function(){var e=function(f,p){return p=p||"",f.replace(/(^|-)/g,"$1\\u"+p).replace(/,/g,"\\u"+p)},n=e("20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7","00"),r="a-z"+e("DF-F6,F8-FF","00"),s="A-Z"+e("C0-D6,D8-DE","00"),i="A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via",o=function(f,p,E,w){return f=f||n,p=p||r,E=E||s,w=w||i,{capitalize:new RegExp("(^|["+f+"])(["+p+"])","g"),pascal:new RegExp("(^|["+f+"])+(["+p+E+"])","g"),fill:new RegExp("["+f+"]+(.|$)","g"),sentence:new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+p+"])","g"),improper:new RegExp("\\b("+w+")\\b","g"),relax:new RegExp("([^"+E+"])(["+E+"]*)(["+E+"])(?=[^"+E+"]|$)","g"),upper:new RegExp("^[^"+p+"]+$"),hole:/[^\s]\s[^\s]/,apostrophe:/'/g,room:new RegExp("["+f+"]")}},a=o(),c={re:a,unicodes:e,regexps:o,types:[],up:String.prototype.toUpperCase,low:String.prototype.toLowerCase,cap:function(f){return c.up.call(f.charAt(0))+f.slice(1)},decap:function(f){return c.low.call(f.charAt(0))+f.slice(1)},deapostrophe:function(f){return f.replace(a.apostrophe,"")},fill:function(f,p,E){return p!=null&&(f=f.replace(a.fill,function(w,A){return A?p+A:""})),E&&(f=c.deapostrophe(f)),f},prep:function(f,p,E,w){if(f=f==null?"":f+"",!w&&a.upper.test(f)&&(f=c.low.call(f)),!p&&!a.hole.test(f)){var A=c.fill(f," ");a.hole.test(A)&&(f=A)}return!E&&!a.room.test(f)&&(f=f.replace(a.relax,c.relax)),f},relax:function(f,p,E,w){return p+" "+(E?E+" ":"")+w}},l={_:c,of:function(f){for(var p=0,E=c.types.length;p0&&wtt>e?t:e,Ed=t=>t!==0?t<0:1/t<0,_d=Number.MAX_SAFE_INTEGER,Xv=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&cn(t)===t),or=()=>new Set,Va=t=>t[t.length-1],Jv=(t,e)=>{for(let n=0;nt.toLowerCase(),eN=/^\s*/g,tN=t=>t.replace(eN,""),nN=/([A-Z])/g,yd=(t,e)=>tN(t.replace(nN,n=>`${e}${Zv(n)}`)),rN=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let s=0;sas.encode(t):rN;let cs=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});cs&&cs.decode(new Uint8Array).length===1&&(cs=null);const un=t=>new Error(t),Ct=()=>{throw un("Method unimplemented")},It=()=>{throw un("Unexpected case")};class ls{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const hn=()=>new ls,iN=t=>{let e=t.cpos;for(let n=0;n{const e=new Uint8Array(iN(t));let n=0;for(let r=0;r{const n=t.cbuf.length;n-t.cpos{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Ya=Ee,P=(t,e)=>{for(;e>Mn;)Ee(t,He|Mn&e),e=cn(e/128);Ee(t,Mn&e)},za=(t,e)=>{const n=Ed(e);for(n&&(e=-e),Ee(t,(e>Ha?He:0)|(n?zt:0)|Ha&e),e=cn(e/64);e>0;)Ee(t,(e>Mn?He:0)|Mn&e),e=cn(e/128)},qa=new Uint8Array(3e4),aN=qa.length/3,cN=(t,e)=>{if(e.length{const n=unescape(encodeURIComponent(e)),r=n.length;P(t,r);for(let s=0;s{const n=t.cbuf.length,r=t.cpos,s=md(n-r,e.length),i=e.length-s;t.cbuf.set(e.subarray(0,s),r),t.cpos+=s,i>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(xn(n*2,i)),t.cbuf.set(e.subarray(s)),t.cpos=i)},Ne=(t,e)=>{P(t,e.byteLength),bi(t,e)},Xa=(t,e)=>{oN(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},uN=(t,e)=>Xa(t,4).setFloat32(0,e,!1),hN=(t,e)=>Xa(t,8).setFloat64(0,e,!1),fN=(t,e)=>Xa(t,8).setBigInt64(0,e,!1),Td=new DataView(new ArrayBuffer(4)),dN=t=>(Td.setFloat32(0,t),Td.getFloat32(0)===t),us=(t,e)=>{switch(typeof e){case"string":Ee(t,119),ar(t,e);break;case"number":Xv(e)&&ki(e)<=qv?(Ee(t,125),za(t,e)):dN(e)?(Ee(t,124),uN(t,e)):(Ee(t,123),hN(t,e));break;case"bigint":Ee(t,122),fN(t,e);break;case"object":if(e===null)Ee(t,126);else if(Qv(e)){Ee(t,117),P(t,e.length);for(let n=0;n0&&P(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Ad=t=>{t.count>0&&(za(t.encoder,t.count===1?t.s:-t.s),t.count>1&&P(t.encoder,t.count-2))};class Mi{constructor(){this.encoder=new ls,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Ad(this),this.count=1,this.s=e)}toUint8Array(){return Ad(this),ft(this.encoder)}}const wd=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);za(t.encoder,e),t.count>1&&P(t.encoder,t.count-2)}};class Ja{constructor(){this.encoder=new ls,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(wd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return wd(this),ft(this.encoder)}}class pN{constructor(){this.sarr=[],this.s="",this.lensE=new Mi}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new ls;return this.sarr.push(this.s),this.s="",ar(e,this.sarr.join("")),bi(e,this.lensE.toUint8Array()),ft(e)}}const Rd=un("Unexpected end of array"),vd=un("Integer out of Range");class xi{constructor(e){this.arr=e,this.pos=0}}const Un=t=>new xi(t),gN=t=>t.pos!==t.arr.length,mN=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},be=t=>mN(t,D(t)),cr=t=>t.arr[t.pos++],D=t=>{let e=0,n=1;const r=t.arr.length;for(;t.pos_d)throw vd}throw Rd},Qa=t=>{let e=t.arr[t.pos++],n=e&Ha,r=64;const s=(e&zt)>0?-1:1;if(!(e&He))return s*n;const i=t.arr.length;for(;t.pos_d)throw vd}throw Rd},lr=cs?t=>cs.decode(be(t)):t=>{let e=D(t);if(e===0)return"";{let n=String.fromCodePoint(cr(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(cr(t));else for(;e>0;){const r=e<1e4?e:1e4,s=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,s),e-=r}return decodeURIComponent(escape(n))}},Za=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},EN=[t=>{},t=>null,Qa,t=>Za(t,4).getFloat32(0,!1),t=>Za(t,8).getFloat64(0,!1),t=>Za(t,8).getBigInt64(0,!1),t=>!1,t=>!0,lr,t=>{const e=D(t),n={};for(let r=0;r{const e=D(t),n=[];for(let r=0;rEN[127-cr(t)](t);class Nd extends xi{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),gN(this)?this.count=D(this)+1:this.count=-1),this.count--,this.s}}class Ui extends xi{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Qa(this);const e=Ed(this.s);this.count=1,e&&(this.s=-this.s,this.count=D(this)+2)}return this.count--,this.s}}class ec extends xi{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Qa(this),n=e&1;this.diff=cn(e/2),this.count=1,n&&(this.count=D(this)+2)}return this.s+=this.diff,this.count--,this.s}}class _N{constructor(e){this.decoder=new Ui(e),this.str=lr(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const dt=()=>new Map,tc=t=>{const e=dt();return t.forEach((n,r)=>{e.set(r,n)}),e},fn=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},yN=(t,e)=>{const n=[];for(const[r,s]of t)n.push(e(s,r));return n},TN=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1};class SN{constructor(){this._observers=dt()}on(e,n){return fn(this._observers,e,or).add(n),n}once(e,n){const r=(...s)=>{this.off(e,r),n(...s)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return ln((this._observers.get(e)||dt()).values()).forEach(r=>r(...n))}destroy(){this._observers=dt()}}const AN=crypto.getRandomValues.bind(crypto),Cd=()=>AN(new Uint32Array(1))[0],wN="10000000-1000-4000-8000"+-1e11,RN=()=>wN.replace(/[018]/g,t=>(t^Cd()&15>>t/4).toString(16)),Id=t=>new Promise(t);Promise.all.bind(Promise);const Ld=t=>t===void 0?null:t;class vN{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let Od=new vN,NN=!0;try{typeof localStorage<"u"&&localStorage&&(Od=localStorage,NN=!1)}catch{}const CN=Od,IN=Object.assign,LN=Object.keys,ON=(t,e)=>{for(const n in t)e(t[n],n)},kd=t=>LN(t).length,kN=t=>{for(const e in t)return!1;return!0},bN=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},MN=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),xN=(t,e)=>t===e||kd(t)===kd(e)&&bN(t,(n,r)=>(n!==void 0||MN(e,r))&&e[r]===n),nc=(t,e,n=0)=>{try{for(;nt,PN=(t,e)=>e.includes(t);var bd={};const fs=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let Lt;const DN=()=>{if(Lt===void 0)if(fs){Lt=dt();const t=process.argv;let e=null;for(let n=0;n{if(t.length!==0){const[e,n]=t.split("=");Lt.set(`--${yd(e,"-")}`,n),Lt.set(`-${yd(e,"-")}`,n)}})):Lt=dt();return Lt},rc=t=>DN().has(t),sc=t=>Ld(fs?bd[t.toUpperCase().replaceAll("-","_")]:CN.getItem(t));(t=>rc("--"+t)||sc(t)!==null)("production");const Md=fs&&PN(bd.FORCE_COLOR,["true","1","2"]),FN=!rc("no-colors")&&(!fs||process.stdout.isTTY||Md)&&(!fs||rc("color")||Md||sc("COLORTERM")!==null||(sc("TERM")||"").includes("color")),$N=t=>new Uint8Array(t),BN=t=>{const e=$N(t.byteLength);return e.set(t),e};class GN{constructor(e,n){this.left=e,this.right=n}}const qt=(t,e)=>new GN(t,e);typeof DOMParser<"u"&&new DOMParser;const KN=t=>yN(t,(e,n)=>`${n}:${e};`).join(""),Xt=Symbol,xd=Xt(),Ud=Xt(),WN=Xt(),jN=Xt(),HN=Xt(),Pd=Xt(),VN=Xt(),Dd=Xt(),YN=Xt(),zN=t=>{var r;t.length===1&&((r=t[0])==null?void 0:r.constructor)===Function&&(t=t[0]());const e=[];let n=0;for(;n{var o;t.length===1&&((o=t[0])==null?void 0:o.constructor)===Function&&(t=t[0]());const e=[],n=[],r=dt();let s=[],i=0;for(;i0||l.length>0?(e.push("%c"+a),n.push(l)):e.push(a)}else break}}for(i>0&&(s=n,s.unshift(e.join("")));i{console.log(...XN(t)),QN.forEach(e=>e.print(t))},QN=or(),Fd=t=>({[Symbol.iterator](){return this},next:t}),ZN=(t,e)=>Fd(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),ic=(t,e)=>Fd(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class oc{constructor(e,n){this.clock=e,this.len=n}}class ds{constructor(){this.clients=new Map}}const $d=(t,e,n)=>e.clients.forEach((r,s)=>{const i=t.doc.store.clients.get(s);for(let o=0;o{let n=0,r=t.length-1;for(;n<=r;){const s=cn((n+r)/2),i=t[s],o=i.clock;if(o<=e){if(e{const n=t.clients.get(e.client);return n!==void 0&&eC(n,e.clock)!==null},ac=t=>{t.clients.forEach(e=>{e.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n=i.clock?s.len=xn(s.len,i.clock+i.len-s.clock):(r{const e=new ds;for(let n=0;n{if(!e.clients.has(s)){const i=r.slice();for(let o=n+1;o{fn(t.clients,e,()=>[]).push(new oc(n,r))},nC=()=>new ds,rC=t=>{const e=nC();return t.clients.forEach((n,r)=>{const s=[];for(let i=0;i0&&e.clients.set(r,s)}),e},ur=(t,e)=>{P(t.restEncoder,e.clients.size),ln(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),P(t.restEncoder,n);const s=r.length;P(t.restEncoder,s);for(let i=0;i{const e=new ds,n=D(t.restDecoder);for(let r=0;r0){const o=fn(e.clients,s,()=>[]);for(let a=0;a{const r=new ds,s=D(t.restDecoder);for(let i=0;i0){const i=new Pn;return P(i.restEncoder,0),ur(i,r),i.toUint8Array()}return null},Kd=Cd;class hr extends SN{constructor({guid:e=RN(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:a=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Kd(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new ep,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=Id(l=>{this.on("load",()=>{this.isLoaded=!0,l(this)})});const c=()=>Id(l=>{const u=h=>{(h===void 0||h===!0)&&(this.off("sync",u),l())};this.on("sync",u)});this.on("sync",l=>{l===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=l===void 0||l===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const e=this._item;e!==null&&!this.shouldLoad&&X(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ln(this.subdocs).map(e=>e.guid))}transact(e,n=null){return X(this,e,n)}get(e,n=we){const r=fn(this.share,e,()=>{const i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==we&&s!==n)if(s===we){const i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._length,this.share.set(e,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,gr)}getText(e=""){return this.get(e,Dn)}getMap(e=""){return this.get(e,mr)}getXmlElement(e=""){return this.get(e,_r)}getXmlFragment(e=""){return this.get(e,Fn)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){ln(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new hr({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,X(e.parent.doc,r=>{const s=n.doc;e.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Wd{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return D(this.restDecoder)}readDsLen(){return D(this.restDecoder)}}class jd extends Wd{readLeftID(){return G(D(this.restDecoder),D(this.restDecoder))}readRightID(){return G(D(this.restDecoder),D(this.restDecoder))}readClient(){return D(this.restDecoder)}readInfo(){return cr(this.restDecoder)}readString(){return lr(this.restDecoder)}readParentInfo(){return D(this.restDecoder)===1}readTypeRef(){return D(this.restDecoder)}readLen(){return D(this.restDecoder)}readAny(){return hs(this.restDecoder)}readBuf(){return BN(be(this.restDecoder))}readJSON(){return JSON.parse(lr(this.restDecoder))}readKey(){return lr(this.restDecoder)}}class sC{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=D(this.restDecoder),this.dsCurrVal}readDsLen(){const e=D(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class fr extends sC{constructor(e){super(e),this.keys=[],D(e),this.keyClockDecoder=new ec(be(e)),this.clientDecoder=new Ui(be(e)),this.leftClockDecoder=new ec(be(e)),this.rightClockDecoder=new ec(be(e)),this.infoDecoder=new Nd(be(e),cr),this.stringDecoder=new _N(be(e)),this.parentInfoDecoder=new Nd(be(e),cr),this.typeRefDecoder=new Ui(be(e)),this.lenDecoder=new Ui(be(e))}readLeftID(){return new dr(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new dr(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return hs(this.restDecoder)}readBuf(){return be(this.restDecoder)}readJSON(){return hs(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e{r=xn(r,e[0].id.clock);const s=Ot(e,r);P(t.restEncoder,e.length-s),t.writeClient(n),P(t.restEncoder,r);const i=e[s];i.write(t,r-i.id.clock);for(let o=s+1;o{const r=new Map;n.forEach((s,i)=>{_e(e,i)>s&&r.set(i,s)}),Fi(e).forEach((s,i)=>{n.has(i)||r.set(i,0)}),P(t.restEncoder,r.size),ln(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{iC(t,e.clients.get(s),s,i)})},oC=(t,e)=>{const n=dt(),r=D(t.restDecoder);for(let s=0;s{const r=[];let s=ln(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;const i=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f};let o=i();if(o===null)return null;const a=new ep,c=new Map,l=(f,p)=>{const E=c.get(f);(E==null||E>p)&&c.set(f,p)};let u=o.refs[o.i++];const h=new Map,d=()=>{for(const f of r){const p=f.id.client,E=n.get(p);E?(E.i--,a.clients.set(p,E.refs.slice(E.i)),n.delete(p),E.i=0,E.refs=[]):a.clients.set(p,[f]),s=s.filter(w=>w!==p)}r.length=0};for(;;){if(u.constructor!==tt){const p=fn(h,u.id.client,()=>_e(e,u.id.client))-u.id.clock;if(p<0)r.push(u),l(u.id.client,u.id.clock-1),d();else{const E=u.getMissing(t,e);if(E!==null){r.push(u);const w=n.get(E)||{refs:[],i:0};if(w.refs.length===w.i)l(E,_e(e,E)),d();else{u=w.refs[w.i++];continue}}else(p===0||p0)u=r.pop();else if(o!==null&&o.i0){const f=new Pn;return lc(f,a,new Map),P(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},cC=(t,e)=>lc(t,e.doc.store,e.beforeState),lC=(t,e,n,r=new fr(t))=>X(e,s=>{s.local=!1;let i=!1;const o=s.doc,a=o.store,c=oC(r,o),l=aC(s,a,c),u=a.pendingStructs;if(u){for(const[d,f]of u.missing)if(f<_e(a,d)){i=!0;break}if(l){for(const[d,f]of l.missing){const p=u.missing.get(d);(p==null||p>f)&&u.missing.set(d,f)}u.update=Bi([u.update,l.update])}}else a.pendingStructs=l;const h=Gd(r,s,a);if(a.pendingDs){const d=new fr(Un(a.pendingDs));D(d.restDecoder);const f=Gd(d,s,a);h&&f?a.pendingDs=Bi([h,f]):a.pendingDs=h||f}else a.pendingDs=h;if(i){const d=a.pendingStructs.update;a.pendingStructs=null,Yd(s.doc,d)}},n,!1),Yd=(t,e,n,r=fr)=>{const s=Un(e);lC(s,t,n,new r(s))},uC=(t,e,n)=>Yd(t,e,n,jd),hC=(t,e,n=new Map)=>{lc(t,e.store,n),ur(t,rC(e.store))},fC=(t,e=new Uint8Array([0]),n=new Pn)=>{const r=zd(e);hC(n,t,r);const s=[n.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(CC(t.store.pendingStructs.update,e)),s.length>1){if(n.constructor===ps)return vC(s.map((i,o)=>o===0?i:LC(i)));if(n.constructor===Pn)return Bi(s)}return s[0]},dC=(t,e)=>fC(t,e,new ps),pC=t=>{const e=new Map,n=D(t.restDecoder);for(let r=0;rpC(new Wd(Un(t))),qd=(t,e)=>(P(t.restEncoder,e.size),ln(e.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{P(t.restEncoder,n),P(t.restEncoder,r)}),t),gC=(t,e)=>qd(t,Fi(e.store)),mC=(t,e=new Vd)=>(t instanceof Map?qd(e,t):gC(e,t),e.toUint8Array()),EC=t=>mC(t,new Hd);class _C{constructor(){this.l=[]}}const Xd=()=>new _C,Jd=(t,e)=>t.l.push(e),Qd=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter(s=>e!==s),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Zd=(t,e,n)=>nc(t.l,[e,n]);class dr{constructor(e,n){this.client=e,this.clock=n}}const Di=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,G=(t,e)=>new dr(t,e),yC=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw It()},pr=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Bd(e.ds,t.id),uc=(t,e)=>{const n=fn(t.meta,uc,or),r=t.doc.store;n.has(e)||(e.sv.forEach((s,i)=>{s<_e(r,i)&&dn(t,G(i,s))}),$d(t,e.ds,s=>{}),n.add(e))};class ep{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Fi=t=>{const e=new Map;return t.clients.forEach((n,r)=>{const s=n[n.length-1];e.set(r,s.id.clock+s.length)}),e},_e=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},tp=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw It()}n.push(e)},Ot=(t,e)=>{let n=0,r=t.length-1,s=t[r],i=s.id.clock;if(i===e)return r;let o=cn(e/(i+s.length-1)*r);for(;n<=r;){if(s=t[o],i=s.id.clock,i<=e){if(e{const n=t.clients.get(e.client);return n[Ot(n,e.clock)]},fc=(t,e,n)=>{const r=Ot(e,n),s=e[r];return s.id.clock{const n=t.doc.store.clients.get(e.client);return n[fc(t,n,e.clock)]},np=(t,e,n)=>{const r=e.clients.get(n.client),s=Ot(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==et&&r.splice(s+1,0,Ji(t,i,n.clock-i.id.clock+1)),i},TC=(t,e,n)=>{const r=t.clients.get(e.id.client);r[Ot(r,e.id.clock)]=n},rp=(t,e,n,r,s)=>{if(r===0)return;const i=n+r;let o=fc(t,e,n),a;do a=e[o++],ie.deleteSet.clients.size===0&&!TN(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(ac(e.deleteSet),cC(t,e),ur(t,e.deleteSet),!0),ip=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&fn(t.changed,e,or).add(n)},$i=(t,e)=>{let n=t[e],r=t[e-1],s=e;for(;s>0;n=r,r=t[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof pe&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const i=e-s;return i&&t.splice(e+1-i,i),i},AC=(t,e,n)=>{for(const[r,s]of t.clients.entries()){const i=e.clients.get(r);for(let o=s.length-1;o>=0;o--){const a=s[o],c=a.clock+a.len;for(let l=Ot(i,a.clock),u=i[l];l{t.clients.forEach((n,r)=>{const s=e.clients.get(r);for(let i=n.length-1;i>=0;i--){const o=n[i],a=md(s.length-1,1+Ot(s,o.clock+o.len-1));for(let c=a,l=s[c];c>0&&l.id.clock>=o.clock;l=s[c])c-=1+$i(s,c)}})},op=(t,e)=>{if(ea.push(()=>{(l._item===null||!l._item.deleted)&&l._callObserver(n,c)})),a.push(()=>{n.changedParentTypes.forEach((c,l)=>{l._dEH.l.length>0&&(l._item===null||!l._item.deleted)&&(c=c.filter(u=>u.target._item===null||!u.target._item.deleted),c.forEach(u=>{u.currentTarget=l,u._path=null}),c.sort((u,h)=>u.path.length-h.path.length),Zd(l._dEH,c,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),nc(a,[]),n._needFormattingCleanup&&WC(n)}finally{r.gc&&AC(i,s,r.gcFilter),wC(i,s),n.afterState.forEach((u,h)=>{const d=n.beforeState.get(h)||0;if(d!==u){const f=s.clients.get(h),p=xn(Ot(f,d),1);for(let E=f.length-1;E>=p;)E-=1+$i(f,E)}});for(let u=o.length-1;u>=0;u--){const{client:h,clock:d}=o[u].id,f=s.clients.get(h),p=Ot(f,d);p+11||p>0&&$i(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(JN(Dd,xd,"[yjs] ",Ud,Pd,"Changed the client-id because another client seems to be using it."),r.clientID=Kd()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const u=new ps;sp(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const u=new Pn;sp(u,n)&&r.emit("updateV2",[u.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:c,subdocsRemoved:l}=n;(a.size>0||l.size>0||c.size>0)&&(a.forEach(u=>{u.clientID=r.clientID,u.collectionid==null&&(u.collectionid=r.collectionid),r.subdocs.add(u)}),l.forEach(u=>r.subdocs.delete(u)),r.emit("subdocs",[{loaded:c,added:a,removed:l},r,n]),l.forEach(u=>u.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):op(t,e+1)}}},X=(t,e,n=null,r=!0)=>{const s=t._transactionCleanups;let i=!1,o=null;t._transaction===null&&(i=!0,t._transaction=new SC(t,n,r),s.push(t._transaction),s.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(i){const a=t._transaction===s[0];t._transaction=null,a&&op(s,0)}}return o};function*RC(t){const e=D(t.restDecoder);for(let n=0;nBi(t,jd,ps),NC=(t,e)=>{if(t.constructor===et){const{client:n,clock:r}=t.id;return new et(G(n,r+e),t.length-e)}else if(t.constructor===tt){const{client:n,clock:r}=t.id;return new tt(G(n,r+e),t.length-e)}else{const n=t,{client:r,clock:s}=n.id;return new pe(G(r,s+e),null,G(r,s+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Bi=(t,e=fr,n=Pn)=>{if(t.length===1)return t[0];const r=t.map(u=>new e(Un(u)));let s=r.map(u=>new dc(u,!0)),i=null;const o=new n,a=new pc(o);for(;s=s.filter(d=>d.curr!==null),s.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const p=d.curr.id.clock-f.curr.id.clock;return p===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===tt?1:-1:p}else return f.curr.id.client-d.curr.id.client}),s.length!==0;){const u=s[0],h=u.curr.id.client;if(i!==null){let d=u.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=u.next(),f=!0;if(d===null||d.id.client!==h||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(h!==i.struct.id.client)pn(a,i.struct,i.offset),i={struct:d,offset:0},u.next();else if(i.struct.id.clock+i.struct.length0&&(i.struct.constructor===tt?i.struct.length-=p:d=NC(d,p)),i.struct.mergeWith(d)||(pn(a,i.struct,i.offset),i={struct:d,offset:0},u.next())}}else i={struct:u.curr,offset:0},u.next();for(let d=u.curr;d!==null&&d.id.client===h&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==tt;d=u.next())pn(a,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(pn(a,i.struct,i.offset),i=null),gc(a);const c=r.map(u=>cc(u)),l=tC(c);return ur(o,l),o.toUint8Array()},CC=(t,e,n=fr,r=Pn)=>{const s=zd(e),i=new r,o=new pc(i),a=new n(Un(t)),c=new dc(a,!1);for(;c.curr;){const u=c.curr,h=u.id.client,d=s.get(h)||0;if(c.curr.constructor===tt){c.next();continue}if(u.id.clock+u.length>d)for(pn(o,u,xn(d-u.id.clock,0)),c.next();c.curr&&c.curr.id.client===h;)pn(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===h&&c.curr.id.clock+c.curr.length<=d;)c.next()}gc(o);const l=cc(a);return ur(i,l),i.toUint8Array()},ap=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:ft(t.encoder.restEncoder)}),t.encoder.restEncoder=hn(),t.written=0)},pn=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&ap(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),P(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},gc=t=>{ap(t);const e=t.encoder.restEncoder;P(e,t.clientStructs.length);for(let n=0;n{const s=new n(Un(t)),i=new dc(s,!1),o=new r,a=new pc(o);for(let l=i.curr;l!==null;l=i.next())pn(a,e(l),0);gc(a);const c=cc(s);return ur(o,c),o.toUint8Array()},LC=t=>IC(t,UN,fr,ps),cp="You must not compute changes after the event-handler fired.";class Gi{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=OC(this.currentTarget,this.target))}deletes(e){return Bd(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw un(cp);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const i=n._map.get(s);let o,a;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))o="delete",a=Va(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",a=Va(c.content.getContent())):(o="add",a=void 0)}else if(this.deletes(i))o="delete",a=Va(i.content.getContent());else return;e.set(s,{action:o,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw un(cp);const n=this.target,r=or(),s=or(),i=[];if(e={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const c=()=>{a&&i.push(a)};for(let l=n._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((a===null||a.delete===void 0)&&(c(),a={delete:0}),a.delete+=l.length,s.add(l)):this.adds(l)?((a===null||a.insert===void 0)&&(c(),a={insert:[]}),a.insert=a.insert.concat(l.content.getContent()),r.add(l)):((a===null||a.retain===void 0)&&(c(),a={retain:0}),a.retain+=l.length);a!==null&&a.retain===void 0&&c()}this._changes=e}return e}}const OC=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let r=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)s.deleted||r++,s=s.right;n.unshift(r)}e=e._item.parent}return n},lp=80;let mc=0;class kC{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=mc++}}const bC=t=>{t.timestamp=mc++},up=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=mc++},MC=(t,e,n)=>{if(t.length>=lp){const r=t.reduce((s,i)=>s.timestamp{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((i,o)=>ki(e-i.index)e;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&ki(n.index-s){for(let r=t.length-1;r>=0;r--){const s=t[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){t.splice(r,1);continue}s.p=i,i.marker=!0}(e0&&e===s.index)&&(s.index=xn(e,s.index+n))}},Wi=(t,e,n)=>{const r=t,s=e.changedParentTypes;for(;fn(s,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;Zd(r._eH,n,e)};class we{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Xd(),this._dEH=Xd(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw Ct()}clone(){throw Ct()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Jd(this._eH,e)}observeDeep(e){Jd(this._dEH,e)}unobserve(e){Qd(this._eH,e)}unobserveDeep(e){Qd(this._dEH,e)}toJSON(){}}const hp=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const s=[];let i=t._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=e)e-=o.length;else{for(let a=e;a0;a++)s.push(o[a]),r--;e=0}}i=i.right}return s},fp=t=>{const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let s=0;s{let n=0,r=t._start;for(;r!==null;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let i=0;i{const n=[];return ms(t,(r,s)=>{n.push(e(r,s,t))}),n},xC=t=>{let e=t._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),r=0,e=e.right}const s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},pp=(t,e)=>{const n=Ki(t,e);let r=t._start;for(n!==null&&(r=n.p,e-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let s=n;const i=t.doc,o=i.clientID,a=i.store,c=n===null?e._start:n.right;let l=[];const u=()=>{l.length>0&&(s=new pe(G(o,_e(a,o)),s,s&&s.lastId,c,c&&c.id,e,null,new Bn(l)),s.integrate(t,0),l=[])};r.forEach(h=>{if(h===null)l.push(h);else switch(h.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(h);break;default:switch(u(),h.constructor){case Uint8Array:case ArrayBuffer:s=new pe(G(o,_e(a,o)),s,s&&s.lastId,c,c&&c.id,e,null,new Es(new Uint8Array(h))),s.integrate(t,0);break;case hr:s=new pe(G(o,_e(a,o)),s,s&&s.lastId,c,c&&c.id,e,null,new ys(h)),s.integrate(t,0);break;default:if(h instanceof we)s=new pe(G(o,_e(a,o)),s,s&&s.lastId,c,c&&c.id,e,null,new Jt(h)),s.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},gp=()=>un("Length exceeded!"),mp=(t,e,n,r)=>{if(n>e._length)throw gp();if(n===0)return e._searchMarker&&gs(e._searchMarker,n,r.length),ji(t,e,null,r);const s=n,i=Ki(e,n);let o=e._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let s=(e._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return ji(t,e,s,n)},Ep=(t,e,n,r)=>{if(r===0)return;const s=n,i=r,o=Ki(e,n);let a=e._start;for(o!==null&&(a=o.p,n-=o.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n0&&a!==null;)a.deleted||(r0)throw gp();e._searchMarker&&gs(e._searchMarker,s,-i+r)},Hi=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},Ec=(t,e,n,r)=>{const s=e._map.get(n)||null,i=t.doc,o=i.clientID;let a;if(r==null)a=new Bn([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:a=new Bn([r]);break;case Uint8Array:a=new Es(r);break;case hr:a=new ys(r);break;default:if(r instanceof we)a=new Jt(r);else throw new Error("Unexpected content type")}new pe(G(o,_e(i.store,o)),s,s&&s.lastId,null,null,e,n,a).integrate(t,0)},_c=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},_p=t=>{const e={};return t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},yp=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},PC=(t,e)=>{const n={};return t._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!e.sv.has(i.id.client)||i.id.clock>=(e.sv.get(i.id.client)||0));)i=i.left;i!==null&&pr(i,e)&&(n[s]=i.content.getContent()[i.length-1])}),n},Vi=t=>ZN(t.entries(),e=>!e[1].deleted);class DC extends Gi{constructor(e,n){super(e,n),this._transaction=n}}class gr extends we{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new gr;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gr}clone(){const e=new gr;return e.insert(0,this.toArray().map(n=>n instanceof we?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,n){super._callObserver(e,n),Wi(this,e,new DC(this,e))}insert(e,n){this.doc!==null?X(this.doc,r=>{mp(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?X(this.doc,n=>{UC(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?X(this.doc,r=>{Ep(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return pp(this,e)}toArray(){return fp(this)}slice(e=0,n=this.length){return hp(this,e,n)}toJSON(){return this.map(e=>e instanceof we?e.toJSON():e)}map(e){return dp(this,e)}forEach(e){ms(this,e)}[Symbol.iterator](){return xC(this)}_write(e){e.writeTypeRef(aI)}}const FC=t=>new gr;class $C extends Gi{constructor(e,n,r){super(e,n),this.keysChanged=r}}class mr extends we{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new mr}clone(){const e=new mr;return this.forEach((n,r)=>{e.set(r,n instanceof we?n.clone():n)}),e}_callObserver(e,n){Wi(this,e,new $C(this,e,n))}toJSON(){const e={};return this._map.forEach((n,r)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];e[r]=s instanceof we?s.toJSON():s}}),e}get size(){return[...Vi(this._map)].length}keys(){return ic(Vi(this._map),e=>e[0])}values(){return ic(Vi(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return ic(Vi(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((n,r)=>{n.deleted||e(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?X(this.doc,n=>{Hi(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?X(this.doc,r=>{Ec(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return _c(this,e)}has(e){return yp(this,e)}clear(){this.doc!==null?X(this.doc,e=>{this.forEach(function(n,r,s){Hi(e,s,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(cI)}}const BC=t=>new mr,gn=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&xN(t,e);class yc{constructor(e,n,r,s){this.left=e,this.right=n,this.index=r,this.currentAttributes=s}forward(){switch(this.right===null&&It(),this.right.content.constructor){case de:this.right.deleted||Er(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Tp=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case de:e.right.deleted||Er(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n{const s=new Map,i=r?Ki(e,n):null;if(i){const o=new yc(i.p.left,i.p,i.index,s);return Tp(t,o,n-i.index)}else{const o=new yc(null,e._start,0,s);return Tp(t,o,n)}},Sp=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===de&&gn(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=t.doc,i=s.clientID;r.forEach((o,a)=>{const c=n.left,l=n.right,u=new pe(G(i,_e(s.store,i)),c,c&&c.lastId,l,l&&l.id,e,null,new de(a,o));u.integrate(t,0),n.right=u,n.forward()})},Er=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},Ap=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===de&&gn(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},wp=(t,e,n,r)=>{const s=t.doc,i=s.clientID,o=new Map;for(const a in r){const c=r[a],l=n.currentAttributes.get(a)??null;if(!gn(l,c)){o.set(a,l);const{left:u,right:h}=n;n.right=new pe(G(i,_e(s.store,i)),u,u&&u.lastId,h,h&&h.id,e,null,new de(a,c)),n.right.integrate(t,0),n.forward()}}return o},Tc=(t,e,n,r,s)=>{n.currentAttributes.forEach((d,f)=>{s[f]===void 0&&(s[f]=null)});const i=t.doc,o=i.clientID;Ap(n,s);const a=wp(t,e,n,s),c=r.constructor===String?new kt(r):r instanceof we?new Jt(r):new $n(r);let{left:l,right:u,index:h}=n;e._searchMarker&&gs(e._searchMarker,n.index,c.getLength()),u=new pe(G(o,_e(i.store,o)),l,l&&l.lastId,u,u&&u.id,e,null,c),u.integrate(t,0),n.right=u,n.index=h,n.forward(),Sp(t,e,n,a)},Rp=(t,e,n,r,s)=>{const i=t.doc,o=i.clientID;Ap(n,s);const a=wp(t,e,n,s);e:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===de));){if(!n.right.deleted)switch(n.right.content.constructor){case de:{const{key:c,value:l}=n.right.content,u=s[c];if(u!==void 0){if(gn(u,l))a.delete(c);else{if(r===0)break e;a.set(c,l)}n.right.delete(t)}else n.currentAttributes.set(c,l);break}default:r0){let c="";for(;r>0;r--)c+=` -`;n.right=new pe(G(o,_e(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new kt(c)),n.right.integrate(t,0),n.forward()}Sp(t,e,n,a)},vp=(t,e,n,r,s)=>{let i=e;const o=dt();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===de){const l=i.content;o.set(l.key,l)}i=i.right}let a=0,c=!1;for(;e!==i;){if(n===e&&(c=!0),!e.deleted){const l=e.content;switch(l.constructor){case de:{const{key:u,value:h}=l,d=r.get(u)??null;(o.get(u)!==l||d===h)&&(e.delete(t),a++,!c&&(s.get(u)??null)===h&&d!==h&&(d===null?s.delete(u):s.set(u,d))),!c&&!e.deleted&&Er(s,l);break}}}e=e.right}return a},GC=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===de){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}},KC=t=>{let e=0;return X(t.doc,n=>{let r=t._start,s=t._start,i=dt();const o=tc(i);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case de:Er(o,s.content);break;default:e+=vp(n,r,s,i,o),i=tc(o),r=s;break}s=s.right}}),e},WC=t=>{const e=new Set,n=t.doc;for(const[r,s]of t.afterState.entries()){const i=t.beforeState.get(r)||0;s!==i&&rp(t,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===de&&o.constructor!==et&&e.add(o.parent)})}X(n,r=>{$d(t,t.deleteSet,s=>{if(s instanceof et||!s.parent._hasFormatting||e.has(s.parent))return;const i=s.parent;s.content.constructor===de?e.add(i):GC(r,s)});for(const s of e)KC(s)})},Np=(t,e,n)=>{const r=n,s=tc(e.currentAttributes),i=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Jt:case $n:case kt:n{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,n=[];X(e,r=>{const s=new Map,i=new Map;let o=this.target._start,a=null;const c={};let l="",u=0,h=0;const d=()=>{if(a!==null){let f=null;switch(a){case"delete":h>0&&(f={delete:h}),h=0;break;case"insert":(typeof l=="object"||l.length>0)&&(f={insert:l},s.size>0&&(f.attributes={},s.forEach((p,E)=>{p!==null&&(f.attributes[E]=p)}))),l="";break;case"retain":u>0&&(f={retain:u},kN(c)||(f.attributes=IN({},c))),u=0;break}f&&n.push(f),a=null}};for(;o!==null;){switch(o.content.constructor){case Jt:case $n:this.adds(o)?this.deletes(o)||(d(),a="insert",l=o.content.getContent()[0],d()):this.deletes(o)?(a!=="delete"&&(d(),a="delete"),h+=1):o.deleted||(a!=="retain"&&(d(),a="retain"),u+=1);break;case kt:this.adds(o)?this.deletes(o)||(a!=="insert"&&(d(),a="insert"),l+=o.content.str):this.deletes(o)?(a!=="delete"&&(d(),a="delete"),h+=o.length):o.deleted||(a!=="retain"&&(d(),a="retain"),u+=o.length);break;case de:{const{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){const E=s.get(f)??null;gn(E,p)?p!==null&&o.delete(r):(a==="retain"&&d(),gn(p,i.get(f)??null)?delete c[f]:c[f]=p)}}else if(this.deletes(o)){i.set(f,p);const E=s.get(f)??null;gn(E,p)||(a==="retain"&&d(),c[f]=E)}else if(!o.deleted){i.set(f,p);const E=c[f];E!==void 0&&(gn(E,p)?E!==null&&o.delete(r):(a==="retain"&&d(),p===null?delete c[f]:c[f]=p))}o.deleted||(a==="insert"&&d(),Er(s,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Dn extends we{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new Dn}clone(){const e=new Dn;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const r=new jC(this,e,n);Wi(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===kt&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?X(this.doc,r=>{const s=new yc(null,this._start,0,new Map);for(let i=0;i0)&&Tc(r,this,s,a,o.attributes||{})}else o.retain!==void 0?Rp(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Np(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,r){const s=[],i=new Map,o=this.doc;let a="",c=this._start;function l(){if(a.length>0){const h={};let d=!1;i.forEach((p,E)=>{d=!0,h[E]=p});const f={insert:a};d&&(f.attributes=h),s.push(f),a=""}}const u=()=>{for(;c!==null;){if(pr(c,e)||n!==void 0&&pr(c,n))switch(c.content.constructor){case kt:{const h=i.get("ychange");e!==void 0&&!pr(c,e)?(h===void 0||h.user!==c.id.client||h.type!=="removed")&&(l(),i.set("ychange",r?r("removed",c.id):{type:"removed"})):n!==void 0&&!pr(c,n)?(h===void 0||h.user!==c.id.client||h.type!=="added")&&(l(),i.set("ychange",r?r("added",c.id):{type:"added"})):h!==void 0&&(l(),i.delete("ychange")),a+=c.content.str;break}case Jt:case $n:{l();const h={insert:c.content.getContent()[0]};if(i.size>0){const d={};h.attributes=d,i.forEach((f,p)=>{d[p]=f})}s.push(h);break}case de:pr(c,e)&&(l(),Er(i,c.content));break}c=c.right}l()};return e||n?X(o,h=>{e&&uc(h,e),n&&uc(h,n),u()},"cleanup"):u(),s}insert(e,n,r){if(n.length<=0)return;const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,e,!r);r||(r={},o.currentAttributes.forEach((a,c)=>{r[c]=a})),Tc(i,this,o,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,e,!r);Tc(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(e,n,r||{}))}delete(e,n){if(n===0)return;const r=this.doc;r!==null?X(r,s=>{Np(s,Yi(s,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,r){if(n===0)return;const s=this.doc;s!==null?X(s,i=>{const o=Yi(i,this,e,!1);o.right!==null&&Rp(i,this,o,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?X(this.doc,n=>{Hi(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?X(this.doc,r=>{Ec(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return _c(this,e)}getAttributes(){return _p(this)}_write(e){e.writeTypeRef(lI)}}const HC=t=>new Dn;class Sc{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===_r||n.constructor===Fn)&&n._start!==null)e=n._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Fn extends we{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Fn}clone(){const e=new Fn;return e.insert(0,this.toArray().map(n=>n instanceof we?n.clone():n)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Sc(this,e)}querySelector(e){e=e.toUpperCase();const r=new Sc(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),ln(new Sc(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Wi(this,e,new zC(this,n,e))}toString(){return dp(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},r){const s=e.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),ms(this,i=>{s.insertBefore(i.toDOM(e,n,r),null)}),s}insert(e,n){this.doc!==null?X(this.doc,r=>{mp(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)X(this.doc,r=>{const s=e&&e instanceof we?e._item:e;ji(r,this,s,n)});else{const r=this._prelimContent,s=e===null?0:r.findIndex(i=>i===e)+1;if(s===0&&e!==null)throw un("Reference item not found");r.splice(s,0,...n)}}delete(e,n=1){this.doc!==null?X(this.doc,r=>{Ep(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return fp(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return pp(this,e)}slice(e=0,n=this.length){return hp(this,e,n)}forEach(e){ms(this,e)}_write(e){e.writeTypeRef(hI)}}const VC=t=>new Fn;class _r extends Fn{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,n){super._integrate(e,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new _r(this.nodeName)}clone(){const e=new _r(this.nodeName),n=this.getAttributes();return ON(n,(r,s)=>{typeof r=="string"&&e.setAttribute(s,r)}),e.insert(0,this.toArray().map(r=>r instanceof we?r.clone():r)),e}toString(){const e=this.getAttributes(),n=[],r=[];for(const a in e)r.push(a);r.sort();const s=r.length;for(let a=0;a0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?X(this.doc,n=>{Hi(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?X(this.doc,r=>{Ec(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return _c(this,e)}hasAttribute(e){return yp(this,e)}getAttributes(e){return e?PC(this,e):_p(this)}toDOM(e=document,n={},r){const s=e.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const a=i[o];typeof a=="string"&&s.setAttribute(o,a)}return ms(this,o=>{s.appendChild(o.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(uI),e.writeKey(this.nodeName)}}const YC=t=>new _r(t.readKey());class zC extends Gi{constructor(e,n,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class zi extends mr{constructor(e){super(),this.hookName=e}_copy(){return new zi(this.hookName)}clone(){const e=new zi(this.hookName);return this.forEach((n,r)=>{e.set(r,n)}),e}toDOM(e=document,n={},r){const s=n[this.hookName];let i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(fI),e.writeKey(this.hookName)}}const qC=t=>new zi(t.readKey());class qi extends Dn{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new qi}clone(){const e=new qi;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,r){const s=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(e=>{const n=[];for(const s in e.attributes){const i=[];for(const o in e.attributes[s])i.push({key:o,value:e.attributes[s][o]});i.sort((o,a)=>o.keys.nodeName=0;s--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(dI)}}const XC=t=>new qi;class Ac{constructor(e,n){this.id=e,this.length=n}get deleted(){throw Ct()}mergeWith(e){return!1}write(e,n,r){throw Ct()}integrate(e,n){throw Ct()}}const JC=0;class et extends Ac{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),tp(e.doc.store,this)}write(e,n){e.writeInfo(JC),e.writeLen(this.length-n)}getMissing(e,n){return null}}class Es{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Es(this.content)}splice(e){throw Ct()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const QC=t=>new Es(t.readBuf());class _s{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new _s(this.len)}splice(e){const n=new _s(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Pi(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const ZC=t=>new _s(t.readLen()),Cp=(t,e)=>new hr({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class ys{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ys(Cp(this.doc.guid,this.opts))}splice(e){throw Ct()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const eI=t=>new ys(Cp(t.readString(),t.readAny()));class $n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new $n(this.embed)}splice(e){throw Ct()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const tI=t=>new $n(t.readJSON());class de{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new de(this.key,this.value)}splice(e){throw Ct()}mergeWith(e){return!1}integrate(e,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const nI=t=>new de(t.readKey(),t.readJSON());class Xi{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xi(this.arr)}splice(e){const n=new Xi(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let s=n;s{const e=t.readLen(),n=[];for(let r=0;r{const e=t.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const iI=t=>new kt(t.readString()),oI=[FC,BC,HC,YC,VC,qC,XC],aI=0,cI=1,lI=2,uI=3,hI=4,fI=5,dI=6;class Jt{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Jt(this.type._copy())}splice(e){throw Ct()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const pI=t=>new Jt(oI[t.readTypeRef()](t)),Ji=(t,e,n)=>{const{client:r,clock:s}=e.id,i=new pe(G(r,s+n),e,G(r,s+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),e.redone!==null&&(i.redone=G(e.redone.client,e.redone.clock+n)),e.right=i,i.right!==null&&(i.right.left=i),t._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),e.length=n,i};class pe extends Ac{constructor(e,n,r,s,i,o,a,c){super(e,c.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=a,this.redone=null,this.content=c,this.info=this.content.isCountable()?gd:0}set marker(e){(this.info&ja)>0!==e&&(this.info^=ja)}get marker(){return(this.info&ja)>0}get keep(){return(this.info&pd)>0}set keep(e){this.keep!==e&&(this.info^=pd)}get countable(){return(this.info&gd)>0}get deleted(){return(this.info&Wa)>0}set deleted(e){this.deleted!==e&&(this.info^=Wa)}markDeleted(){this.info|=Wa}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_e(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_e(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===dr&&this.id.client!==this.parent.client&&this.parent.clock>=_e(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=np(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=dn(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===et||this.right&&this.right.constructor===et)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===pe&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===pe&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===dr){const r=hc(n,this.parent);r.constructor===et?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=np(e,e.doc.store,G(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Di(this.origin,s.origin)){if(s.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Pi(e.deleteSet,this.id.client,this.id.clock,this.length),ip(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw It();this.content.gc(e),n?TC(e,this,new et(this.id,this.length)):this.content=new _s(this.length)}write(e,n){const r=n>0?G(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Oi|(r===null?0:He)|(s===null?0:zt)|(i===null?0:os);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),s!==null&&e.writeRightID(s),r===null&&s===null){const a=this.parent;if(a._item!==void 0){const c=a._item;if(c===null){const l=yC(a);e.writeParentInfo(!0),e.writeString(l)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===dr?(e.writeParentInfo(!1),e.writeLeftID(a)):It();i!==null&&e.writeString(i)}this.content.write(e,n)}}const Ip=(t,e)=>gI[e&Oi](t),gI=[()=>{It()},ZC,rI,QC,iI,tI,nI,pI,sI,eI,()=>{It()}],mI=10;class tt extends Ac{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){It()}write(e,n){e.writeInfo(mI),P(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const Lp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Op="__ $YJS$ __";Lp[Op]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Lp[Op]=!0;const wc=0,kp=1,bp=2,EI=(t,e)=>{P(t,wc);const n=EC(e);Ne(t,n)},Mp=(t,e,n)=>{P(t,kp),Ne(t,dC(e,n))},_I=(t,e,n)=>Mp(e,n,be(t)),xp=(t,e,n)=>{try{uC(e,be(t),n)}catch(r){console.error("Caught error while handling a Yjs update",r)}},yI=(t,e)=>{P(t,bp),Ne(t,e)},TI=xp,SI=(t,e,n,r)=>{const s=D(t);switch(s){case wc:_I(t,e,n);break;case kp:xp(t,n,r);break;case bp:TI(t,n,r);break;default:throw new Error("Unknown message type")}return s},yr={},Rc={},vc={},Ts={},bt=wr("shared",["second"],t=>{switch(t.target){case"second":Object.keys(vc).forEach(e=>{const n=Ts[e];n===void 0?bt.emit("shared:join",e):n<10?Ts[e]=n+1:delete Ts[e]}),Object.keys(Rc).forEach(e=>{bt.emit("shared:active",e)});break;case"join":{const e=t.data,n=yr[e];if(n&&Rc[e]){bt.reply(t,"joinack",e);const r=hn();EI(r,n),bt.reply(t,"sync",Zi(e,r));const s=hn();Mp(s,n),bt.reply(t,"sync",Zi(e,s))}break}case"joinack":{const e=t.data;yr[e]&&vc[e]&&(Ts[e]=0);break}case"active":{const e=t.data;yr[e]&&vc[e]&&(Ts[e]=0);break}case"sync":{const[e,n,r]=t.data,s=yr[n];if(s&&e!==bt.id()){const i=Un(r),o=hn();if(SI(i,o,s,bt)===wc){const c=Zi(n,o);bt.emit("shared:sync",c)}}break}}});function AI(t){let e=yr[t];if(e)return e;yr[t]=e=new hr({guid:t});function n(r){const s=hn();yI(s,r),bt.emit("shared:sync",Zi(t,s))}return e.on("update",n),e.on("destroy",()=>{e==null||e.off("update",n)}),e}function Qi(t){return AI(t).getMap()}function Zi(t,e){const n=ft(e);return[bt.id()??"",t,n]}function Up(t,e){const n=t.get(e);return n!=null&&n.toJSON?n.toJSON():n}function Pp(t,e,n){typeof n=="string"?t.set(e,new Dn(n)):t.set(e,n)}function wI(t,e,n){console.info({guid:t,key:e,value:n}),Rc[t]=!0;const r=Qi(t);r.get(e)===void 0&&n!==void 0&&Pp(r,e,n)}function RI(t,e,n){const r=Qi(t),s=Up(r,e);(s===void 0||n!==s)&&Pp(r,e,n)}function vI(t,e,n){const r=Qi(t);function s(){n(Up(r,e))}function i(o){o.keysChanged.has(e)&&s()}return s(),r.observe(i),()=>{r.unobserve(i)}}function NI(t,e,n){const r=Qi(t);let s=r.get(e);function i(){n(s)}function o(c){c.keysChanged.has(e)&&s===void 0&&a(),s&&r.unobserve(o)}function a(){s=r.get(e),s?(s.observeDeep(i),i()):r.observe(o)}return a(),()=>{s?s.unobserveDeep(i):r.unobserve(o)}}const mn={};function Dp(t,e){return t.player=e,t.layers=[],t.layout=[],t.layoutreset=!0,t.layoutfocus="scroll",t}function Fp(t){t.text=[],Object.values(mn[t.id]??{}).forEach(e=>e==null?void 0:e()),mn[t.id]={}}function $p(t){const e=t.layout.find(n=>n.name===t.layoutfocus);if(!e){const n={id:Ut(),name:t.layoutfocus,edge:Ye.RIGHT,size:20,text:[]};return t.layout.push(n),t.layoutreset=!1,n}return e}const Nc={},CI=new Set(["hk","hotkey","rn","range","sl","select","nm","number","tx","text"]),II=new Set(["rn","range","sl","select","nm","number","tx","text"]),LI=new Set(["tx","text"]),OI={rn:1,range:1,sl:0,select:0,nm:0,number:0,tx:"",text:""};function Gn(t){let e=Nc[t];return y(e)?e:Nc[t]=e=Dp({},t)}function kI(){return Object.keys(Nc)}function bI(t){const e=Gn(t);e.layout=e.layout.filter(n=>n.edge!==Ye.SCROLL)}function MI(t,e,n){Object.values(mn).forEach(r=>{r[e]!==void 0&&RI(t.id(),e,n)})}function xI(t){const e=Gn(t.id());e.layout=e.layout.filter(n=>n.edge!==Ye.SCROLL||n.text.length>0)}function Cc(t,e,n,r,s){const i=Gn(t.id()),o=r,a=s||zv.capital(e),c=i.layout.find(l=>l.name===a);if(c)i.layoutreset=!0,i.layoutfocus=a,Fe(o)&&(c.size=o);else switch(n){case Ye.START:Dp(i,t.id());break;case Ye.LEFT:case Ye.RIGHT:case Ye.TOP:case Ye.BOTTOM:case Ye.SCROLL:const l={id:Ut(),name:a,edge:n,size:o??Rg[n],text:[]};i.layout.push(l),i.layoutfocus=a;break}}function UI(t,e){const n=Gn(t.id()),r=$p(n);n.layoutreset&&(n.layoutreset=!1,Fp(r)),r.text.push(e)}function PI(t,e,n,r){const s=Gn(t.id()),i=$p(s);s.layoutreset&&(s.layoutreset=!1,Fp(i));const o=n.toLowerCase(),a=[t.id(),e,...CI.has(o)?[o]:["hypertext",n],...r],c=a[2];if(II.has(c)){const l=`${a[3]??""}`;mn[i.id]=mn[i.id]??{};const u=t.get(l);mn[i.id][l]===void 0&&(wI(t.id(),l,u??OI[c]),LI.has(c)?mn[i.id][l]=NI(t.id(),l,h=>{if(h!==void 0){const d=h.toJSON();d!==t.get(l)&&t.set(l,d)}}):mn[i.id][l]=vI(t.id(),l,h=>{h!==void 0&&h!==t.get(l)&&t.set(l,h)}))}i.text.push(a)}const DI=fd({get(){return[!1,void 0]},set(t,e,n){return MI(t,e,n),[!1,void 0]},shouldtick(){},tick(t){var r,s;const e=V(t.id()),n=((r=e.target)==null?void 0:r.name)??((s=e.target)==null?void 0:s.kind)??"Scroll";Cc(t,"scroll",Ye.SCROLL,void 0,n)},tock(t){xI(t)}}).command("color",(t,e)=>{const n=V(t.id()),[r]=I({...n,chip:t,words:e},0,[C.COLOR]);return y(n.target)&&y(r)&&yo(n.target,r),0}).command("gadget",(t,e)=>{const r={...V(t.id()),chip:t,words:e},[s]=I(r,0,[C.STRING]),i=wg[s.toLowerCase()];if(i===Ye.SCROLL){const[,o,a]=I(r,0,[C.STRING,C.MAYBE_STRING,C.MAYBE_NUMBER]);Cc(t,s,i,a,o)}else{const[,o,a]=I(r,0,[C.STRING,C.MAYBE_NUMBER,C.MAYBE_STRING]);Cc(t,s,i,o,a)}return 0}).command("book",(t,e)=>{const n=V(t.id()),[r,s]=I({...n,chip:t,words:e},0,[C.STRING,C.STRING]),i=r.toLowerCase(),o=s.toLowerCase();switch(o){case"create":Zh(jh(i,[Rt("@board title",{board:zc(a=>a)}),Rt("@terrain dirt",{terrain:{char:176,bg:Q.BLACK,color:Q.DKYELLOW,collision:me.WALK}}),Rt("@terrain dirt2",{terrain:{char:176,bg:Q.BLACK,color:Q.DKGRAY,collision:me.WALK}}),Rt("@terrain wall",{terrain:{char:177,bg:Q.DKGREEN,color:Q.GREEN,collision:me.SOLID}}),Rt("@terrain wall2",{terrain:{char:176,bg:Q.DKGREEN,color:Q.GREEN,collision:me.SOLID}})]));break;default:console.info("book",{ltarget:i,laction:o});break}return 0}).command("frame",(t,e)=>{var c;const n=V(t.id()),[r,s,i]=I({...n,chip:t,words:e},0,[C.STRING,C.MAYBE_STRING,C.MAYBE_STRING]),o=((c=n.board)==null?void 0:c.id)??"",a=r.toLowerCase();if(a==="reset")Qh(o);else if(y(s)&&y(i)){const l=s.toLowerCase();switch(l){case"edit":vR(o,a,i);break;case"view":RR(o,a,i);break;default:console.info("frame",{ltype:l,ltarget:a,maybeboard:i});break}}return 0});function Bp(t,e,n,r){if(!y(t)||!y(e)||!y(n))return;const[s,i]=n,o=Hh(t,s);y(o)&&(om(e,r.x,r.y,s),yo(sm(e,r.x,r.y),i));const a=Na(t,n[0]);y(a)&&y(a.name)&&(am(e,r.x,r.y,a),yo(a,i))}const Gp=new Set(["cycle","player","sender","inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu","data"]),FI=new Set(["inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu"]);function $I(t){const e=rf[t];if(y(e))return e;const n=cf[t];if(y(n))return n;const r=uf[t];if(y(r))return r;const s=Sf[t];if(y(s))return s}const BI=["NORTH","SOUTH","WEST","EAST"];function GI(t){const e=V(t.id??"");if(e.inputcurrent!==void 0)return;const[n=ce.NONE]=e.inputqueue;t.stats===void 0&&(t.stats={}),t.stats.inputmove=[],t.stats.inputok=0,t.stats.inputcancel=0,t.stats.inputmenu=0;const r=e.inputmods[n];switch(t.stats.inputalt=r&vg?1:0,t.stats.inputctrl=r&Ng?1:0,t.stats.inputshift=r&Cg?1:0,n){case ce.MOVE_UP:case ce.MOVE_DOWN:case ce.MOVE_LEFT:case ce.MOVE_RIGHT:t.stats.inputmove=[BI[n-ce.MOVE_UP]];break;case ce.OK_BUTTON:t.stats.inputok=1;break;case ce.CANCEL_BUTTON:t.stats.inputcancel=1;break;case ce.MENU_BUTTON:t.stats.inputmenu=1;break}e.inputcurrent=n,e.inputqueue.delete(n)}function eo(t,e,n,r){const s=le(e)?e:e.id,i=le(n)?n:n.id;y(s)&&y(i)&&t.send(i,r,s)}function Kp(t,e,n,r,s){const i=yR(e,n,r,s);return y(i)&&(r.kind==="player"?(eo(t,i,t.id(),"thud"),eo(t,t.id(),i,"touch")):(eo(t,i,t.id(),"thud"),eo(t,t.id(),i,"bump"))),!y(i)}function Wp(t,e){if(le(t)){const n=t.toLowerCase();switch(n){case"edit":return[n,e+1]}}return[void 0,e]}function jp(t,e,n){let r;const s=pi((e==null?void 0:e.id)??"");switch(n){case"edit":{r=s.find(a=>a.type===Jr.EDIT);break}}const i=r?Qr((r==null?void 0:r.book)??""):t,o=r?tr(i,(r==null?void 0:r.board)??""):e;return{maybebook:i,maybeboard:o}}const KI={zzt:fd({get(t,e){var o;const n=$I(e);if(y(n))return[!0,n];const r=V(t.id());if(r.target){FI.has(e)&&GI(r.target);const a=(o=r.target.stats)==null?void 0:o[e];if(y(a)||Gp.has(e))return[!0,a]}const s=r.board?So(r.board,r.target):void 0,i=gR(r.book,(s==null?void 0:s.id)??"",e);return[y(i),i]},set(t,e,n){var i,o;const r=V(t.id());if(y(r.target)&&(y((o=(i=r.target)==null?void 0:i.stats)==null?void 0:o[e])||Gp.has(e)))return r.target.stats||(r.target.stats={}),r.target.stats[e]=n,[!0,n];const s=r.board?So(r.board,r.target):void 0;return mR(r.book,(s==null?void 0:s.id)??"",e,n),[!0,n]},shouldtick(t){var n,r,s,i;const e=V(t.id());if((r=(n=e.target)==null?void 0:n.stats)!=null&&r.stepx||(i=(s=e.target)==null?void 0:s.stats)!=null&&i.stepy){const o={x:(e.target.x??0)+(e.target.stats.stepx??0),y:(e.target.y??0)+(e.target.stats.stepy??0)};Kp(t,e.book,e.board,e.target,o)}},tick(){},tock(){}}).command("become",(t,e)=>(console.info(e),0)).command("bind",(t,e)=>(console.info(e),0)).command("change",(t,e)=>{const n=V(t.id()),[r,s]=Wp(e[0],0),[i,o]=I({...n,chip:t,words:e},s,[C.KIND,C.KIND]),{maybebook:a,maybeboard:c}=jp(n.book,n.board,r);Ia(a,c);const l=Oa(i)??"",u=Eo(c,l),h=Qg(u,i),d=Oa(o),f=yf(o),p=Tf(o);return console.info({maybebook:a,maybeboard:c,targetname:l,boardelements:u,targetelements:h,intoname:d,intocolor:f,intobg:p}),h.forEach(E=>{if(Xr(a,E)===d)y(f)&&(E.color=f),y(p)&&(E.bg=p);else{if(y(E.id))switch(r){case"edit":qh(a,c,E),To(c,E.id);break;default:zh(a,c,E,t.timestamp());break}sn(E)&&Bp(a,c,o,E)}}),0}).command("char",(t,e)=>{const n=V(t.id()),[r]=I({...n,chip:t,words:e},0,[C.NUMBER]);return y(n.target)&&(n.target.char=r),0}).command("clear",(t,e)=>{const n=Yt(e[0]);return t.set(n,void 0),0}).command("cycle",(t,e)=>{const n=V(t.id()),[r]=I({...n,chip:t,words:e},0,[C.NUMBER]);return t.cycle(io(Math.round(r),1,255)),0}).command("die",t=>{const e=V(t.id());return zh(e.book,e.board,e.target,t.timestamp()),t.endofprogram(),0}).command("end",t=>(t.endofprogram(),0)).command("endgame",t=>(t.set("health",0),0)).command("give",(t,e)=>{const n=V(t.id()),[r,s,i]=I({...n,chip:t,words:e},0,[C.STRING,C.MAYBE_NUMBER]),o=t.get(r),a=Fe(o)?o:0,c=s??1;if(!Fe(c))return 0;const l=o===void 0?1:0;return l&&i{const n=V(t.id());if(!y(n.target))return 0;let r=0,s=1;const[i,o]=Re({...n,chip:t,words:e},0);for(Fe(i)&&(r=o,s=io(Math.round(i),1,1024));s>0;){const[l]=I({...n,chip:t,words:e},r,[C.DIR]);Kp(t,n.book,n.board,n.target,l)?--s:s=-1}const a=n.target.x,c=n.target.y;return n.target.x===a&&n.target.y===c?1:0}).command("idle",t=>(t.yield(),0)).command("lock",t=>(t.lock(t.id()),0)).command("play",(t,e)=>(console.info({chip:t,play:e}),0)).command("put",(t,e)=>{const n=V(t.id()),[r,s]=Wp(e[0],0),[i,o]=I({...n,chip:t,words:e},s,[C.DIR,C.KIND]),{maybebook:a,maybeboard:c}=jp(n.book,n.board,r);return Ia(a,c),Bp(a,c,o,i),0}).command("restore",(t,e)=>(t.restore(Yt(e[0])),0)).command("send",(t,e)=>{var h,d;const n=V(t.id()),[r,s]=I({...n,chip:t,words:e},0,[C.STRING,C.ANY]),[i,o]=r.split(":"),a=y(o)?i:"self",c=o??i;function l(f){f.forEach(p=>{y(p.id)&&t.send(p.id,c,s)})}const u=a.toLowerCase();switch(u){case"all":for(const f of Object.keys(((h=n.board)==null?void 0:h.objects)??{}))t.send(f,c,s);break;case"self":t.send(t.id(),c,s);break;case"others":for(const f of Object.keys(((d=n.board)==null?void 0:d.objects)??{}))f!==t.id()&&t.send(f,c,s);break;case"player":break;default:{l(_o(n.board,[a]));const f=t.get(u);Array.isArray(f)?l(_o(n.board,f)):l(_o(n.board,[f]));break}}return 0}).command("set",(t,e)=>{const n=V(t.id()),[r,s]=I({...n,chip:t,words:e},0,[C.STRING,C.ANY]);return t.set(r,s),0}).command("shoot",(t,e)=>{const n=V(t.id()),[r,s]=I({...n,chip:t,words:e},0,[C.DIR,C.MAYBE_KIND]);return console.info({dir:r,maybekind:s}),0}).command("take",(t,e)=>{const n=V(t.id()),[r,s,i]=I({...n,chip:t,words:e},0,[C.STRING,C.MAYBE_NUMBER]),o=t.get(r),a=s??1;if(!Fe(o))return 1;const c=o-a;return c<0?(i{const n=V(t.id());return I({...n,chip:t,words:e},0,[C.DIR,C.MAYBE_KIND]),0}).command("try",(t,e)=>{const n=V(t.id()),[,r]=I({...n,chip:t,words:e},0,[C.DIR]);return t.command("go",...e.slice(0,r))&&r(t.unlock(),0)).command("walk",(t,e)=>{var s;const n=V(t.id()),[r]=I({...n,chip:t,words:e},0,[C.DIR]);return y((s=n.target)==null?void 0:s.stats)&&(n.target.stats.stepx=r.x-(n.target.x??0),n.target.stats.stepy=r.y-(n.target.y??0)),0}).command("zap",(t,e)=>(t.zap(Yt(e[0])),0)).command("stat",(t,e)=>{const n=V(t.id());return n.target&&(n.target.name=e.map(Yt).join(" ")),0}).command("text",(t,e)=>{const n=e.map(Yt).join("");return UI(t,n),0}).command("hyperlink",(t,e)=>{const[n,r,...s]=e,i=Yt(n),o=Yt(r);return PI(t,i,o,s),0}),zss:DI};function WI(t){Object.values(KI).forEach(e=>{t.install(e)})}function Ic(t){if(!t||t.type===void 0)return;const e=[{start:t.startOffset,end:t.endOffset||0}];return Object.keys(t).forEach(n=>{if(n!=="parent"){const r=t[n];Array.isArray(r)?r.forEach(s=>{e.push(Ic(s))}):e.push(Ic(r))}}),t.range={start:Math.min(...e.filter(n=>n).map(n=>(n==null?void 0:n.start)||0)),end:Math.max(...e.filter(n=>n).map(n=>(n==null?void 0:n.end)||0))},t.range}function jI(t){const e=wa(`${t} -`);if(e.errors.length>0)return{errors:e.errors,tokens:[]};is.input=e.tokens;const n=is.program();if(is.errors.length>0)return{tokens:e.tokens,errors:is.errors};const r=Dv.visit(n);return r?(Ic(r),{tokens:e.tokens,cst:n,ast:r}):{tokens:e.tokens,cst:n,errors:["no ast output"]}}const Lc=Object.getPrototypeOf(function*(){}).constructor;function HI(t){const e=jI(t);if(e.errors&&e.errors.length>0)return e;if(!e.ast)return{...e,errors:["no ast output"]};const n=Wv(e.ast);if(n.code){oR&&console.info(n.code);try{return{...e,...n,source:n.code,code:new Lc("api",n.code)}}catch(r){return{errors:[{message:r.message}],source:"there was an error",code:new Lc("api"," ")}}}return{...e,...n,source:"there was an error",code:new Lc("api"," ")}}function VI(){const t={},e={};function n(s){const i=t[s];if(i)return i;const o=HI(s);return t[s]=o,o}return{ids(){return Object.keys(e)},has(s){return y(e[s])},halt(s){const i=e[s];return i&&delete e[s],!!i},tick(s,i){var a;let o=e[s];if(!y(e[s])){const c=n(i);if((a=c.errors)!=null&&a.length)return console.error(c.errors),console.info(c.tokens),e[s]=null,!1;o=e[s]=Vv(s,c),WI(o)}return!!(o!=null&&o.tick())},message(s){const{target:i,path:o}=Pc(s.target),a=e[i];y(a)&&a.message({...s,target:o})}}}const YI=Uc(so.numbers,4),zI=Uc(`${so.numbers}${so.lowercase}`,16),Hp=`pid_${YI()}_${zI()}`;wR(Hp);const Vp=VI(),qI=32*15,Tr={},XI=wr("vm",["login","tick","tock"],t=>{switch(t.target){case"login":t.player&&(Tr[t.player]=0,NR(t.player));break;case"tick":IR(Vp,t.data);break;case"tock":Object.keys(Tr).forEach(e=>{++Tr[e],Tr[e]>qI&&(delete Tr[e],CR(e))});break;case"doot":t.player&&(Tr[t.player]=0);break;case"input":if(t.player){const e=V(t.player),[n=ce.NONE,r=0]=t.data??{};e.inputqueue.add(n),e.inputmods[n]=r}break;default:Vp.message(t);break}});function JI(){Zh(_i),XI.emit("ready",void 0,Hp)}const Oc=wr("clock",[],()=>{});let kc=0,Yp=performance.now(),bc=0,to=0;function QI(){Oc.emit("tick",to),Oc.emit("tock",to),++bc,++to,bc>=wo&&(bc%=wo,Oc.emit("second",to))}function zp(){const t=performance.now(),e=t-Yp;kc+=e,kc>=Ao&&(kc%=Ao,QI()),Yp=t,setTimeout(zp)}zp();const qp={},Xp=wr("gadgetserver",["tock"],t=>{switch(t.target){case"tock":kI().forEach(e=>{const n=Gn(e);n.layers=OR(e);const r=go(qp[e]??{},n);r.length&&(qp[e]=Ie(n),Xp.emit("gadgetclient:patch",r,e))});break;case"desync":if(t.player){const e=Gn(t.player);Xp.emit("gadgetclient:reset",e,t.player)}break;case"clearscroll":t.player&&bI(t.player);break}}),ZI=lg(t=>postMessage(t));onmessage=function(e){ZI(e.data)},queueMicrotask(JI)})(); diff --git a/index.html b/index.html index 0d2683c7a..c9c9fbbbd 100644 --- a/index.html +++ b/index.html @@ -3,11 +3,11 @@ - ZZS - main:0.2.1:cab08f3b1ebc108a4629bb4904e63ccbbafc54a1 + ZZS - main:0.2.2:9b88f8ce2ee656d2b45fdd98977515a61ee80f22 - +