From 09806b35e01c7d03786b345fb9bd9df9ce2a9c63 Mon Sep 17 00:00:00 2001 From: goldbuick Date: Wed, 24 Apr 2024 23:34:56 +0000 Subject: [PATCH] Build: (cab08f3) ci: version bump to v0.2.1 --- .../{index-DLIdVy47.js => index-DJ8TvcxU.js} | 4 +- ...tance-DKZTTE2Z.js => instance-LD1NVfuA.js} | 120 +++++++++--------- index.html | 4 +- 3 files changed, 64 insertions(+), 64 deletions(-) rename assets/{index-DLIdVy47.js => index-DJ8TvcxU.js} (99%) rename assets/{instance-DKZTTE2Z.js => instance-LD1NVfuA.js} (58%) diff --git a/assets/index-DLIdVy47.js b/assets/index-DJ8TvcxU.js similarity index 99% rename from assets/index-DLIdVy47.js rename to assets/index-DJ8TvcxU.js index 0585927f0..ea6e00d4a 100644 --- a/assets/index-DLIdVy47.js +++ b/assets/index-DJ8TvcxU.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-DKZTTE2Z.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-LD1NVfuA.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.0",ZSS_COMMIT_HASH:"608ab91a482ca58177dcf8d6ffc691aa5e224607",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.0",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.0",ZSS_COMMIT_HASH:"608ab91a482ca58177dcf8d6ffc691aa5e224607",ZSS_COMMIT_MESSAGE:"ci: version bump to v0.2.0",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.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+=` `;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-DKZTTE2Z.js b/assets/instance-LD1NVfuA.js similarity index 58% rename from assets/instance-DKZTTE2Z.js rename to assets/instance-LD1NVfuA.js index cd1bf6bc4..f37a1c3ec 100644 --- a/assets/instance-DKZTTE2Z.js +++ b/assets/instance-LD1NVfuA.js @@ -1,72 +1,72 @@ -var ZC=Object.defineProperty;var eL=(xt,De,_n)=>De in xt?ZC(xt,De,{enumerable:!0,configurable:!0,writable:!0,value:_n}):xt[De]=_n;var U=(xt,De,_n)=>(eL(xt,typeof De!="symbol"?De+"":De,_n),_n);(function(){"use strict";const xt=new Set,De={emit(t,e,n,r){De.invoke(sg(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 tg=t=>crypto.getRandomValues(new Uint8Array(t)),ng=(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}}},Mc=(t,e=21)=>ng(t,e,tg),rg=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=_n[n[t]&63];return e};function Ut(){return rg()}function sg(t,e,n,r){return{id:Ut(),target:t,sender:e,data:n,player:r}}function xc(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}=xc(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 ig(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 og(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 Uc="abcdefghijklmnopqrstuvwxyz",Pc="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Dc="0123456789",ag="346789ABCDEFGHJKLMNPQRTUVWXYabcdefghijkmnpqrtwxyz",cg="6789BCDFGHJKLMNPQRTWbcdfghjkmnpqrtwz";const lg=Dc,ug=Uc,hg=Pc;var fg=lg+ug+hg,so={lowercase:Uc,uppercase:Pc,numbers:Dc,nolookalikes:ag,nolookalikesSafe:cg,alphanumeric:fg};const Fc=32,dg=33;function Rs(t,e){return new Array(t).fill(e)}function pg(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 gg(t,e,n,r=1,s=15){return{id:`sprites:${t}:${e}:${n}`,x:0,y:0,char:r,color:s,bg:Fc}}function mg(t,e){return{id:`sprites:${t}:${e}`,type:2,sprites:[]}}function Eg(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 _g(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 yg={start:0,left:1,right:2,top:3,bottom:4,scroll:5},Tg={0:1,1:20,2:20,3:1,4:1,5:40},Sg=1,Ag=16,wg=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||{}),$c={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}})})($c);var Rg=$c.exports,vg=ro(Rg);const Ng=vg("089fad0j9awfem09wavefc09uwaef");function io(t,e,n){return Math.max(e,Math.min(n,t))}function Ig(){return Ng()}function Wn(t,e){const n=Math.min(t,e),s=Math.max(t,e)-n+1;return n+Math.floor(Ig()*s)}/*! +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 Cg=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)}}(),Lg=Object.prototype.hasOwnProperty;function oo(t,e){return Lg.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 Bc(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=kg[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=Wc([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 Wc(t,e,n){try{if(!Array.isArray(t))throw new te("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)uo(Ce(e),Ce(t),n||!0);else{n=n||Ns;for(var r=0;r=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:Ce(u)}),n.push({op:"replace",path:r+"/"+yn(l),value:Ce(h)}))}else Array.isArray(t)===Array.isArray(e)?(s&&n.push({op:"test",path:r+"/"+yn(l),value:Ce(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 zg(t,e){const n=Ca(e),r=Ef(e),s=_f(e);return t.filter(i=>!(y(n)&&Jg(i)!==n||y(r)&&Qg(i)!==r||y(s)&&Zg(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 tm(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 nm(t,e,n,r){tm(t,e,n,{kind:r})}function Yc(t,e){if(!y(t)||!y(e))return;const n={...e,id:e.id??Ut()};return t.objects[n.id]=n,n}function rm(t,e,n,r){return console.info({kind:r}),{}}function zc(t,e){if(t)return t.objects[e]}function Ft(t,e){switch(e){case $.NORTH:--t.y;break;case $.SOUTH:++t.y;break;case $.WEST:--t.x;break;case $.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>=Hm)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}function qm(t){return function(){return t}}var Cs=function(){try{var t=An(Object,"defineProperty");return t({},"",{}),t}catch{}}(),Xm=Cs?function(t,e){return Cs(t,"toString",{configurable:!0,enumerable:!1,value:qm(e),writable:!0})}:Vn,Jm=Xm,Qm=zm(Jm);function ol(t,e){for(var n=-1,r=t==null?0:t.length;++n-1}var tE=9007199254740991,nE=/^(?:0|[1-9]\d*)$/;function Ls(t,e){var n=typeof t;return e=e??tE,!!e&&(n=="number"||n!="symbol"&&nE.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=oE}function mt(t){return t!=null&&Co(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)?Cr(n[e],t):!1}function aE(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 S_(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):xo(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 F_=_l(Object.getPrototypeOf,Object),Sl=F_;function Al(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&yT?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=hS&&(i=Go,o=!1,e=new qn(e));e:for(;++s-1?s[i?e[o]:o]:void 0}}var ES=Math.max;function _S(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var s=n==null?0:Ir(n);return s<0&&(s=ES(r+s,0)),al(t,_t(e),s)}var Jn=mS(_S);function at(t){return t&&t.length?t[0]:void 0}function yS(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:yS;return n(t,_t(e))}function Je(t,e){return Ds(L(t,e),1)}var TS=Object.prototype,SS=TS.hasOwnProperty,AS=lS(function(t,e,n){SS.call(t,n)?t[n].push(e):No(t,n,[e])}),wS=Object.prototype,RS=wS.hasOwnProperty;function vS(t,e){return t!=null&&RS.call(t,e)}function k(t,e){return t!=null&&Ql(t,e,vS)}var NS="[object String]";function Me(t){return typeof t=="string"||!W(t)&&st(t)&&en(t)==NS}function IS(t,e){return Nr(e,function(n){return t[n]})}function ue(t){return t==null?[]:IS(t,$e(t))}var CS=Math.max;function Le(t,e,n,r){t=mt(t)?t:ue(t),n=n&&!r?Ir(n):0;var s=t.length;return n<0&&(n=CS(s+n,0)),Me(t)?n<=s&&t.indexOf(e,n)>-1:!!s&&vo(t,e,n)>-1}var LS=Math.max;function ru(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var s=n==null?0:Ir(n);return s<0&&(s=LS(r+s,0)),vo(t,e,s)}var OS="[object Map]",kS="[object Set]",bS=Object.prototype,MS=bS.hasOwnProperty;function z(t){if(t==null)return!0;if(mt(t)&&(W(t)||typeof t=="string"||typeof t.splice=="function"||kr(t)||Oo(t)||bs(t)))return!t.length;var e=zn(t);if(e==OS||e==kS)return!t.size;if(Or(t))return!yl(t).length;for(var n in t)if(MS.call(t,n))return!1;return!0}var xS="[object RegExp]";function US(t){return st(t)&&en(t)==xS}var su=tn&&tn.isRegExp,Kt=su?br(su):US;function Wt(t){return t===void 0}var PS="Expected a function";function DS(t){if(typeof t!="function")throw new TypeError(PS);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 FS(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=jS){var l=e?null:WS(t);if(l)return Ko(l);o=!1,s=Go,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 he 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 zS(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 he)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:VS(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 he: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 qS(t){return t instanceof xe||t instanceof Ue||t instanceof he||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 he||t instanceof lt?!0:t instanceof ut?iu(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 XS(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 he)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 he)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=lu(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=lu(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 lu(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 ZS(t);if(qS(t))return JS(t);if(XS(t))return QS(t);throw Error("non exhaustive match")}function JS(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 Vo(e)}function QS(t){const e=L(t.definition,n=>$r(n));return Vo(it(e))}function ZS(t){return[t.terminalType]}const uu="_~IN~_";class eA 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=nA(e.referencedRule,e.idx)+this.topProd.name,i=n.concat(r),o=new xe({definition:i}),a=$r(o);this.follows[s]=a}}function tA(t){const e={};return b(t,n=>{const r=new eA(n).startWalking();Be(e,r)}),e}function nA(t,e){return t.name+e+uu}function M(t){return t.charCodeAt(0)}function zo(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 rA(){throw Error("Internal Error - Should never get here!")}function hu(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 fu=[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")],sA=/[0-9a-fA-F]/,zs=/[0-9]/,iA=/[1-9]/;class oA{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 rA()}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=fu;break;case"S":e=fu,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(` + */var ho=new WeakMap,Fg=function(){function t(e){this.observers=new Map,this.obj=e}return t}(),$g=function(){function t(e,n){this.callback=e,this.observer=n}return t}();function Bg(t){return ho.get(t)}function Gg(t,e){return t.observers.get(e)}function Kg(t,e){t.observers.delete(e.callback)}function Wg(t,e){e.unobserve()}function jg(t,e){var n=[],r,s=Bg(t);if(!s)s=new Fg(t),ho.set(t,s);else{var i=Gg(s,e);r=i&&i.observer}if(r)return r;if(r={},s.value=Ie(t),e){r.callback=e,r.next=null;var o=function(){fo(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(){fo(r),clearTimeout(r.next),Kg(s,r),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},s.observers.set(e,new $g(e,r)),r}function fo(t,e){e===void 0&&(e=!1);var n=ho.get(t.object);po(n.value,t.object,t.patches,"",e),t.patches.length&&uo(n.value,t.patches);var r=t.patches;return r.length>0&&(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,hu(r)&&this.isRangeDash()){this.consumeChar("-");const s=this.classAtom();if(s.type,hu(s)){if(s.value=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(e){return{begin:e,end:this.idx}}}class qo{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 aA=new oA;function Xs(t){const e=t.toString();if(qs.hasOwnProperty(e))return qs[e];{const n=aA.pattern(e);return qs[e]=n,n}}function cA(){qs={}}const du="Complement Sets are not supported for first char optimization",Js=`Unable to use "first char" lexer optimizations: -`;function lA(t,e=!1){try{const n=Xs(t);return Xo(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===du)e&&ou(`${Js} Unable to optimize: < ${t.toString()} > +`:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}parseHexDigits(e){let n="";for(let s=0;s=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.`),Yo(`${Js} + 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 Xo(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":Xo(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"&&Jo(o)===!1||o.type!=="Group"&&a===!1)break}break;default:throw Error("non exhaustive match!")}return ue(e)}function Qs(t,e,n){const r=nn(t);e[r]=r,n===!0&&uA(t,e)}function uA(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 pu(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 Jo(t){const e=t.quantifier;return e&&e.atLeast===0?!0:t.value?W(t.value)?ot(t.value,Jo):Jo(t.value):!1}class hA extends qo{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?pu(e,this.targetCharCodes)===void 0&&(this.found=!0):pu(e,this.targetCharCodes)!==void 0&&(this.found=!0)}}function Qo(t,e){if(e instanceof RegExp){const n=Xs(e),r=new hA(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 gu=typeof new RegExp("(?:)").sticky=="boolean";function fA(t,e){e=Ho(e,{useSticky:gu,debug:!1,safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",` -`],tracer:(R,_)=>_()});const n=e.tracer;n("initCharCodeToOptimizedIndexMap",()=>{UA()});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?Eu(_):mu(_)}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?Eu(T):mu(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=>ru(r,T)):[ru(r,_)]}),l=L(r,R=>R.PUSH_MODE),u=L(r,R=>k(R,"POP_MODE"))});let h;n("Line Terminator Handling",()=>{const R=Tu(e.lineTerminatorCharacters);h=L(r,_=>!1),e.positionTracking!=="onlyOffset"&&(h=L(r,_=>k(_,"LINE_BREAKS")?!!_.LINE_BREAKS:yu(_,R)===!1&&Qo(R,_.PATTERN)))});let d,f,p,E;n("Misc Mapping #2",()=>{d=L(r,_u),f=L(i,bA),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);Zo(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,Zo(R,S,E[N]))})}else if(Kt(_.PATTERN))if(_.PATTERN.unicode)w=!1,e.ensureOptimizations&&Yo(`${Js} Unable to analyze < ${_.PATTERN.toString()} > pattern. + 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=lA(_.PATTERN,e.ensureOptimizations);z(T)&&(w=!1),b(T,m=>{Zo(R,m,E[N])})}else e.ensureOptimizations&&Yo(`${Js} TokenType: <${_.name}> is using a custom token pattern without providing parameter. + 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 dA(t,e){let n=[];const r=gA(t);n=n.concat(r.errors);const s=mA(r.valid),i=s.valid;return n=n.concat(s.errors),n=n.concat(pA(i)),n=n.concat(RA(i)),n=n.concat(vA(i,e)),n=n.concat(NA(i)),n}function pA(t){let e=[];const n=Xe(t,r=>Kt(r[Nn]));return e=e.concat(_A(n)),e=e.concat(SA(n)),e=e.concat(AA(n)),e=e.concat(wA(n)),e=e.concat(yA(n)),e}function gA(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 mA(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 EA=/[^\\][$]/;function _A(t){class e extends qo{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 EA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: + 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 yA(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 TA=/[^\\[][\^]|^\^/;function SA(t){class e extends qo{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 TA.test(i.source)}});return L(n,s=>({message:`Unexpected RegExp Anchor Error: + 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 AA(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 wA(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 RA(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 vA(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 NA(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)&&CA(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. + 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 IA(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 CA(t){return Jn([".","\\","[","]","|","^","$","(",")","?","*","+","{"],n=>t.source.indexOf(n)!==-1)===void 0}function mu(t){const e=t.ignoreCase?"i":"";return new RegExp(`^(?:${t.source})`,e)}function Eu(t){const e=t.ignoreCase?"iy":"y";return new RegExp(`${t.source}`,e)}function LA(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 +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 OA(t,e,n){const r=[];let s=!1;const i=Dr(it(ue(t.modes))),o=Ks(i,c=>c[Nn]===ge.NA),a=Tu(n);return e&&b(o,c=>{const l=yu(c,a);if(l!==!1){const h={message:xA(c,l),type:l.issue,tokenType:c};r.push(h)}else k(c,"LINE_BREAKS")?c.LINE_BREAKS===!0&&(s=!0):Qo(a,c.PATTERN)&&(s=!0)}),e&&!s&&r.push({message:`Warning: No LINE_BREAKS Found. +`,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 kA(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 _u(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 bA(t){return Me(t)&&t.length===1?t.charCodeAt(0):!1}const MA={test:function(t){const e=t.length;for(let n=this.lastIndex;n{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 Tu(t){return L(t,n=>Me(n)?n.charCodeAt(0):n)}function Zo(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 Su=1;const Au={};function jr(t){const e=PA(t);DA(e),$A(e),FA(e),b(e,n=>{n.isParent=n.categoryMatches.length>0})}function PA(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 DA(t){b(t,e=>{Ru(e)||(Au[Su]=e,e.tokenTypeIdx=Su++),vu(e)&&!W(e.CATEGORIES)&&(e.CATEGORIES=[e.CATEGORIES]),vu(e)||(e.CATEGORIES=[]),BA(e)||(e.categoryMatches=[]),GA(e)||(e.categoryMatchesMap={})})}function FA(t){b(t,e=>{e.categoryMatches=[],b(e.categoryMatchesMap,(n,r)=>{e.categoryMatches.push(Au[r].tokenTypeIdx)})})}function $A(t){b(t,e=>{wu([],e)})}function wu(t,e){b(t,n=>{e.categoryMatchesMap[n.tokenTypeIdx]=!0}),b(e.CATEGORIES,n=>{const r=t.concat(e);Le(r,n)||wu(r,n)})}function Ru(t){return k(t,"tokenTypeIdx")}function vu(t){return k(t,"CATEGORIES")}function BA(t){return k(t,"categoryMatches")}function GA(t){return k(t,"categoryMatchesMap")}function KA(t){return k(t,"tokenTypeIdx")}const WA={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:WA,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}=au(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=MA;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(LA(s,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(OA(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(dA(a,o))}),z(this.lexerDefinitionErrors)){jr(a);let l;this.TRACE_INIT("analyzeTokenTypes",()=>{l=fA(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(`----------------------- + 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=>{ou(a.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(gu?(this.chopInput=Vn,this.match=this.matchWithTest):(this.updateLastIndex=le,this.match=this.matchWithExec),i&&(this.handleModes=le),this.trackStartLines===!1&&(this.computeNewColumn=Vn),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=le),/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. +`+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",()=>{cA()}),this.TRACE_INIT("toFastProperties",()=>{cu(this)})})}tokenize(e,n=this.defaultMode){if(!z(this.lexerDefinitionErrors)){const s=L(this.lexerDefinitionErrors,i=>i.message).join(`----------------------- + 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=kA(this.emptyGroups),Sr=this.trackStartLines,Te=this.config.lineTerminatorsPattern;let Mt=0,nt=[],Ss=[];const no=[],Yp=[];Object.freeze(Yp);let As;function zp(){return nt}function qp(Ie){const rt=nn(Ie),Ar=Ss[rt];return Ar===void 0?Yp:Ar}const QC=Ie=>{if(no.length===1&&Ie.tokenType.PUSH_MODE===void 0){const rt=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(Ie);S.push({offset:Ie.startOffset,line:Ie.startLine,column:Ie.startColumn,length:Ie.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=qp:As=zp}};function Xp(Ie){no.push(Ie),Ss=this.charCodeToPatternIdxToConfig[Ie],nt=this.patternIdxToConfig[Ie],Mt=nt.length,Mt=nt.length;const rt=this.canModeBeOptimized[Ie]&&this.config.safeMode===!1;Ss&&rt?As=qp:As=zp}Xp.call(this,n);let pt;const Jp=this.config.recoveryEnabled;for(;N<_;){c=null;const Ie=R.charCodeAt(N),rt=As(Ie),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,QC,Xp,p)}else{const Ve=N,Qt=v,En=j;let Zt=Jp===!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=` +`+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(Uu);const YA={buildRuleNotFoundError(t,e){return"Invalid grammar, reference to a rule which is not defined: ->"+e.nonTerminalName+`<- -inside top level rule: ->`+t.name+"<-"}},Cn={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}<-`:""} + <${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,` @@ -90,35 +90,35 @@ 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 zA(t,e){const n=new qA(t,e);return n.resolveRefs(),n.errors}class qA extends Zn{constructor(e,n){super(),this.nameToTopRule=e,this.errMsgProvider=n,this.errors=[]}resolveRefs(){b(ue(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 XA 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 JA extends XA{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 QA 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 Pu 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 ZA 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 Du 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 ea(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=ea(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 Fu(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(ew(A,p,E,w));else throw Error("non exhaustive match")}return u}function ew(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 $u(t){if(t instanceof Ue||t==="Option")return re.OPTION;if(t instanceof he||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 tw(t,e,n,r,s,i){const o=na(t,e,n),a=Wu(o)?ti:Wr;return i(o,r,a,s)}function nw(t,e,n,r,s,i){const o=ra(t,e,s,n),a=Wu(o)?ti:Wr;return i(o[0],a,r)}function rw(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;iea([o],1)),r=Gu(n.length),s=L(n,o=>{const a={};return b(o,c=>{const l=ta(c.partialPath);b(l,u=>{a[u]=!0})}),a});let i=n;for(let o=1;o<=e;o++){const a=i;i=Gu(a.length);for(let c=0;c{const A=ta(w.partialPath);b(A,R=>{s[c][R]=!0})})}}}}return r}function na(t,e,n,r){const s=new Bu(t,re.ALTERNATION,r);return e.accept(s),Ku(s.result,n)}function ra(t,e,n,r){const s=new Bu(t,n);e.accept(s);const i=s.result,a=new iw(e,t,n).startWalking(),c=new xe({definition:i}),l=new xe({definition:a});return Ku([c,l],r)}function sa(t,e){e:for(let n=0;n{const s=e[r];return n===s||s.categoryMatchesMap[n.tokenTypeIdx]})}function Wu(t){return ot(t,e=>ot(e,n=>ot(n,r=>z(r.categoryMatches))))}function cw(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 lw(t,e,n,r){const s=Je(t,c=>uw(c,n)),i=Aw(t,e,n),o=Je(t,c=>_w(c,n)),a=Je(t,c=>dw(c,t,r,n));return s.concat(i,o,a)}function uw(t,e){const n=new fw;t.accept(n);const r=n.allProductions,s=AS(r,hw),i=ct(s,a=>a.length>1);return L(ue(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=ju(c);return d&&(h.parameter=d),h})}function hw(t){return`${At(t)}_#_${t.idx}_#_${ju(t)}`}function ju(t){return t instanceof Z?t.terminalType.name:t instanceof Ke?t.nonTerminalName:""}class fw 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 dw(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 pw(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 Hu(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),Hu(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 he)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 ia extends Zn{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}}function gw(t,e){const n=new ia;t.accept(n);const r=n.alternations;return Je(r,i=>{const o=Fr(i.definition);return Je(o,(a,c)=>{const l=Fu([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 mw(t,e,n){const r=new ia;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=na(a,t,c,o),u=Tw(l,o,t,n),h=Sw(l,o,t,n);return u.concat(h)})}class Ew 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 _w(t,e){const n=new ia;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 yw(t,e,n){const r=[];return b(t,s=>{const i=new Ew;s.accept(i);const o=i.allProductions;b(o,a=>{const c=$u(a),l=a.maxLookahead||e,u=a.idx,d=ra(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 Tw(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&&sa(d,u)&&e.definition[f].ignoreAmbiguities!==!0&&h.push(f)}),h.length>1&&!sa(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 Sw(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 Aw(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 ww(t){const e=Ho(t,{errMsgProvider:YA}),n={};return b(t.rules,r=>{n[r.name]=r}),zA(n,e.errMsgProvider)}function Rw(t){return t=Ho(t,{errMsgProvider:Cn}),lw(t.rules,t.tokenTypes,t.errMsgProvider,t.grammarName)}const Vu="MismatchedTokenException",Yu="NoViableAltException",zu="EarlyExitException",qu="NotAllInputParsedException",Xu=[Vu,Yu,zu,qu];Object.freeze(Xu);function ii(t){return Le(Xu,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 Ju extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Vu}}class vw extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Yu}}class Nw extends oi{constructor(e,n){super(e,n),this.name=qu}}class Iw extends oi{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=zu}}const oa={},Qu="InRuleRecoveryException";class Cw extends Error{constructor(e){super(e),this.name=Qu}}class Lw{initRecoverable(e){this.firstAfterRepMap={},this.resyncFollows={},this.recoveryEnabled=k(e,"recoveryEnabled")?e.recoveryEnabled:jt.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=Ow)}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 Ju(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 Cw("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=>VA(n,i));if(s!==void 0)return s;n=this.LA(r),r++}}getCurrFollowKey(){if(this.RULE_STACK.length===1)return oa;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?oa:{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===oa)return[In];const n=e.ruleName+e.idxInCallingRule+uu+e.inRule;return this.resyncFollows[n]}addToResyncTokens(e,n){return this.tokenMatcher(e,In)||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 Ow(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=In,u=1),!(l===void 0||u===void 0)&&this.shouldInRepetitionRecoveryBeTried(l,u,o)&&this.tryInRepetitionRecovery(t,e,n,l)}const kw=4,rn=8,Zu=1<Hu(n,n,Cn))}validateEmptyOrAlternatives(e){return Je(e,n=>gw(n,Cn))}validateAmbiguousAlternationAlternatives(e,n){return Je(e,r=>mw(r,n,Cn))}validateSomeNonEmptyLookaheadPath(e,n){return yw(e,n,Cn)}buildLookaheadForAlternation(e){return tw(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,rw)}buildLookaheadForOptional(e){return nw(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,$u(e.prodType),sw)}}class Mw{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 bw({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}=Uw(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=ua(this.fullRuleNameToShort[n.name],Zu,l.idx);this.setLaFuncCache(d,h)})}),b(s,l=>{this.computeLookaheadFunc(n,l.idx,aa,"Repetition",l.maxLookahead,At(l))}),b(i,l=>{this.computeLookaheadFunc(n,l.idx,eh,"Option",l.maxLookahead,At(l))}),b(o,l=>{this.computeLookaheadFunc(n,l.idx,ca,"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,la,"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=ua(this.fullRuleNameToShort[e.name],r,n);this.setLaFuncCache(c,a)})}getKeyForAutomaticLookahead(e,n){const r=this.getLastExplicitRuleShortName();return ua(r,e,n)}getLaFuncFromCache(e){return this.lookAheadFuncsCache.get(e)}setLaFuncCache(e,n){this.lookAheadFuncsCache.set(e,n)}}class xw 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 xw;function Uw(t){ci.reset(),t.accept(ci);const e=ci.dslMethods;return ci.reset(),e}function th(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}>: +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 Gw(t,e,n){const r=function(){};rh(r,t+"BaseSemanticsWithDefaults");const s=Object.create(n.prototype);return b(e,i=>{s[i]=$w}),r.prototype=s,r.prototype.constructor=r,r}var ha;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(ha||(ha={}));function Kw(t,e){return Ww(t,e)}function Ww(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:ha.MISSING_METHOD,methodName:s}));return Dr(r)}class jw{initTreeBuilder(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=k(e,"nodeLocationTracking")?e.nodeLocationTracking:jt.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=le,this.cstFinallyStateUpdate=le,this.cstPostTerminal=le,this.cstPostNonTerminal=le,this.cstPostRule=le;else if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=nh,this.setNodeLocationFromNode=nh,this.cstPostRule=le,this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=le,this.setNodeLocationFromNode=le,this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=th,this.setNodeLocationFromNode=th,this.cstPostRule=le,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=le,this.setNodeLocationFromNode=le,this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=le,this.setNodeLocationFromNode=le,this.cstPostRule=le,this.setInitialNodeLocation=le;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];Pw(r,n,e),this.setNodeLocationFromToken(r.location,n)}cstPostNonTerminal(e,n){const r=this.CST_STACK[this.CST_STACK.length-1];Dw(r,n,e),this.setNodeLocationFromNode(r.location,e.location)}getBaseCstVisitorConstructor(){if(Wt(this.baseCstVisitorConstructor)){const e=Bw(this.className,$e(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(Wt(this.baseCstVisitorWithDefaultsConstructor)){const e=Gw(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 Hw{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 Vw{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:Cn.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=pw(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 zS(ue(this.gastProductionsCache))}}class Yw{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. + `)}`)}}};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(ue(e.modes)),KA)){const i=it(ue(e.modes)),o=Vo(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=In;const r=k(e,"modes")?it(ue(e.modes)):ue(e),s=ot(r,i=>z(i.categoryMatches));this.tokenMatcher=s?ti:Wr,jr(ue(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(ca,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,ca,e,ZA)}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,Du],a,ai,e,Du)}else throw this.raiseEarlyExitException(e,re.REPETITION_MANDATORY_WITH_SEPARATOR,n.ERR_MSG)}manyInternal(e,n){const r=this.getKeyForAutomaticLookahead(aa,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,aa,e,QA,o)}manySepFirstInternal(e,n){const r=this.getKeyForAutomaticLookahead(la,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,Pu],a,la,e,Pu)}}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(Zu,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 Nw(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 Ju(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===Qu?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),In)}reset(){this.resetLexerState(),this.subruleIdx=0,this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK=[],this.CST_STACK=[],this.RULE_OCCURRENCE_STACK=[]}}class zw{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=ra(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 Iw(l,this.LA(1),this.LA(0)))}raiseNoAltException(e,n){const r=this.getCurrRuleFullName(),s=this.getGAstProductions()[r],i=na(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 vw(c,this.LA(1),a))}}class qw{initContentAssist(){}computeContentAssist(e,n){const r=this.gastProductionsCache[e];if(Wt(r))throw Error(`Rule ->${e}<- does not exist in this grammar.`);return Fu([r],n,this.tokenMatcher,this.maxLookahead)}getNextPossibleTokenTypes(e){const n=at(e.ruleStack),s=this.getGAstProductions()[n];return new JA(s,e).startWalking()}}const li={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(li);const sh=!0,ih=Math.pow(2,rn)-1,oh=x({name:"RECORDING_PHASE_TOKEN",pattern:ge.NA});jr([oh]);const ah=ni(oh,`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(ah);const Xw={name:`This CSTNode indicates the Parser is in Recording Phase - See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class Jw{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+` + 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,sh)}manyInternalRecord(e,n){Yr.call(this,he,n,e)}manySepFirstInternalRecord(e,n){Yr.call(this,lt,n,e,sh)}orInternalRecord(e,n){return Qw.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?Xw:li}consumeInternalRecord(e,n,r){if(ui(n),!Ru(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),ah}}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 Qw(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=iu(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 ch(t){return t===0?"":`${t}`}function ui(t){if(t<0||t>ih){const e=new Error(`Invalid DSL Method idx value: <${t}> - Idx value must be a none negative value smaller than ${ih+1}`);throw e.KNOWN_RECORDER_ERROR=!0,e}}class Zw{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}=au(n),o=s>10?console.warn:console.log;return this.traceInitIndent time: ${s}ms`),this.traceInitIndent--,i}else return n()}}function eR(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(In,"",NaN,NaN,NaN,NaN,NaN,NaN);Object.freeze(hi);const jt=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:Uu,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",()=>{cu(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=ww({rules:ue(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT("Grammar Validations",()=>{if(z(r)&&this.skipValidations===!1){const s=Rw({rules:ue(this.gastProductionsCache),tokenTypes:ue(this.tokensMap),errMsgProvider:Cn,grammarName:n}),i=cw({lookaheadStrategy:this.lookaheadStrategy,rules:ue(this.gastProductionsCache),tokenTypes:ue(this.tokensMap),grammarName:n});this.definitionErrors=this.definitionErrors.concat(s,i)}}),z(this.definitionErrors)&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{const s=tA(ue(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:ue(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(ue(this.gastProductionsCache))})),!zr.DEFER_DEFINITION_ERRORS_HANDLING&&!z(this.definitionErrors))throw e=L(this.definitionErrors,s=>s.message),new Error(`Parser Definition Errors detected: + 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,eR(zr,[Lw,Mw,jw,Hw,Yw,Vw,zw,qw,Jw,Zw]);class tR 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 nR=!!JSON.parse("false"),fa=mo(32,126).map(t=>String.fromCharCode(t)),qr=x({name:"Newline",line_breaks:!0,start_chars_hint:[` -`,"\r"],pattern:/\n|\r\n?/}),rR=x({name:"Whitespace",pattern:/ +/,group:ge.SKIPPED}),sR=x({name:"Whitespace",pattern:/\s+/,line_breaks:!0,group:ge.SKIPPED}),da=x({name:"Stat",pattern:/@.*/,start_chars_hint:["@"]}),ht=x({name:"Command",pattern:/#/,start_chars_hint:["#"]});let lh=!1;function iR(t,e,n){if(!lh)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)}),hh=x({name:"Comment",pattern:/'.*/,start_chars_hint:["'"]}),fh=x({name:"Label",pattern:/:[^;:\n]*/,start_chars_hint:[":"]}),dh=x({name:"HyperLink",pattern:/!/,start_chars_hint:["!"]}),ph=x({name:"HyperLinkText",pattern:/;[^;\n]*/,start_chars_hint:[";"]}),We=x({name:"StringLiteral",pattern:/[^-0-9"!;@#/?\s]+[^-"!;@#/?\s]*/,start_chars_hint:fa}),gh=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),mh=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 Eh=x({name:"IsEq",pattern:/=|is|eq|equal/,longer_alt:We}),_h=x({name:"IsNotEq",pattern:/!=|not ?eq|not ?equal/,longer_alt:We}),yh=x({name:"IsLessThan",pattern:/<|below/,longer_alt:We}),Th=x({name:"IsGreaterThan",pattern:/>|above/,longer_alt:We}),Sh=x({name:"IsLessThanOrEqual",pattern:/<=|below ?or ?eq|below ?or ?equal/,longer_alt:We}),Ah=x({name:"IsGreaterThanOrEqual",pattern:/>=|above ?or ?eq|above ?or ?equal/,longer_alt:We}),pa=x({name:"Or",pattern:/or/i,longer_alt:We}),ga=x({name:"Not",pattern:/not/i,longer_alt:We}),ma=x({name:"And",pattern:/and/i,longer_alt:We}),Ea=x({name:"Plus",pattern:/\+/}),_a=x({name:"Minus",pattern:/-/}),wh=x({name:"Power",pattern:/\*\*/}),Rh=x({name:"Multiply",pattern:/\*/}),ya=x({name:"Divide",pattern:/\//}),vh=x({name:"ModDivide",pattern:/%/}),Nh=x({name:"FloorDivide",pattern:/%%/}),Ih=x({name:"Query",pattern:/\?/}),Ch=x({name:"LParen",pattern:/\(/,push_mode:"ignore_newlines"}),Lh=x({name:"RParen",pattern:/\)/,pop_mode:!0}),Oh=x({name:"play",pattern:/play .*/,start_chars_hint:fa,longer_alt:We}),Ta=Qe("if"),Ln=Qe("do"),Sa=Qe("else"),kh=Qe("endif"),bh=Qe("while"),Mh=Qe("endwhile"),xh=Qe("repeat"),Uh=Qe("endrepeat"),Ph=Qe("read"),Dh=Qe("endread"),Fh=Qe("break"),$h=Qe("continue");function Bh(t){return[...t,Eh,_h,Sh,yh,Ah,Th,pa,ga,ma,Ea,_a,wh,Rh,ya,Nh,vh,Ih,Ch,Lh,gh,We,mh]}const Gh=Bh([uh,da,Oh,ht,hh,fh,dh,ph,qr,rR,Ta,Ln,Sa,kh,bh,Mh,xh,Uh,Ph,Dh,Fh,$h]),oR=new ge({defaultMode:"use_newlines",modes:{use_newlines:Gh,ignore_newlines:Bh([sR])}},{skipValidations:!wt,ensureOptimizations:wt});function Aa(t){lh=!0;const e=oR.tokenize(t||` + 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 aR(t){return t.map(e=>e.image)}function cR(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]=aR(s??[])}break}}function Kh(t){var n;if(!y(t))return{};if(y((n=t.stats)==null?void 0:n.type))return t.stats;t.stats={};const e=Aa(t.code);for(let r=0;rlR(i)===e&&(i.id===n||r===uR(i)))}function Ra(t,e,n){const r=wa(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 va(t,e){const n=e??"",r=wa(t,je.OBJECT,n),s=Ra(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=va(t,e.kind)),e.kinddata}function jh(t,e){const n=e??"",r=wa(t,je.TERRAIN,n),s=Ra(t,je.TERRAIN,n);return y(r)?{...s,name:n,code:r.code}:void 0}function Na(t,e){if(y(e)&&y(e.kind))return y(e.kinddata)||(e.kinddata=jh(t,e.kind)),e.kinddata}function tr(t,e){return Ra(t,je.BOARD,e)}function Hh(t,e){if(t)return t.flags[e]=t.flags[e]??{},t.flags[e]}function hR(t,e,n){const r=Hh(t,e);return r==null?void 0:r[n]}function fR(t,e,n,r){const s=Hh(t,e);return s&&(s[n]=r),r}function Vh(t,e){return tr(t,(t==null?void 0:t.players[e])??"")}function dR(t,e,n){y(t)&&y(tr(t,n))&&(t.players[e]=n)}function pR(t){return Vg(Object.values((t==null?void 0:t.players)??[])).map(e=>tr(t,e)).filter(y)}function gR(t,e,n,r){const s=zc(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=zc(e,e.lookup[i]??"");if(y(c))return{...c};const l=e.terrain[i];if(y(l)){const u=Na(t,l),h=l.collision??(u==null?void 0:u.collision)??me.WALK;if(Yg(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=Na(t,e);return((e==null?void 0:e.name)??(n==null?void 0:n.name)??"terrain").toLowerCase()}function mR(t,e){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 Yh(t,e,n,r){Xr(t,n)!=="player"&&ER(t,e,n,r)}function ER(t,e,n,r){var s,i;if(y(t)&&y(e)&&y(n==null?void 0:n.id)&&y(n.x)&&y(n.y)){if(n.removed=r,y(e.lookup)){const a=n.x+n.y*e.width;((s=e.lookup)==null?void 0:s[a])===n.id&&delete e.lookup[a]}const o=Xr(t,n);y((i=e.named)==null?void 0:i[o])&&e.named[o].delete(n.id)}}function _R(t,e,n){if(!y(t)||!y(e))return;const r=Object.values(e.objects);for(let s=0;sAo*5&&qc(e,i.id)}}function yR(t,e,n,r){if(!y(t)||!y(e))return;mR(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 zh(t){return{id:Ut(),type:t}}function qh(t,e){const n=zh(0);return n.book=t,n.board=e,n}function TR(t,e){const n=zh(1);return n.book=t,n.board=e,n}const Ht={defaultplayer:"",books:new Map,chips:new Map,frames:new Map};function SR(t){Ht.defaultplayer=t}function Xh(t){const e=[qh(void 0,void 0)];return Ht.frames.set(t,e),e}function AR(t,e,n){const r=pi(t);y(r)&&r.push(qh(e,n))}function wR(t,e,n){const r=pi(t);y(r)&&r.push(TR(e,n))}function pi(t){return Ht.frames.get(t)??Xh(t)}function Qr(t){const e=t.toLowerCase();return Ht.books.get(t)??[...Ht.books.values()].find(n=>n.name.toLowerCase()===e)}function Jh(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 Qh="player",Zh="title";function RR(t){const e=Qr(_i.name),n=tr(e,Zh),r=va(e,Qh);if(y(n)&&y(r)){const s=Yc(n,{id:t,x:0,y:0,kind:Qh,stats:{player:t}});y(s==null?void 0:s.id)&&dR(e,t,Zh)}}function vR(t){Ht.books.forEach(e=>qc(Vh(e,t),t))}function NR(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);pR(r).forEach(s=>yR(r,s,e,n))}function IR(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=pg(t,o++,c,l,u);i.push(h);const d=Eg(t,o++,c,l);i.push(d);const f=o++,p=mg(t,f);i.push(p);const E=_g(t,o++);s&&i.push(E),r.terrain.forEach((A,R)=>{if(A){const _=Na(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=gg(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 ef(t){switch(t.type){case Jr.EDIT:return 1;case Jr.VIEW:return 2}return 0}function CR(t){const e=Qr(_i.name),n=Vh(e,t),r=[];if(!y(e)||!y(n))return r;let s=0;return pi(n.id??"").toSorted((o,a)=>ef(o)-ef(a)).forEach(o=>{const a=Qr(o.book??"")??e,c=tr(a,o.board??"")??n;if(y(a)&&y(c)){const l=IR(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=Fc]="CLEAR",t[t.SHADOW=dg]="SHADOW",t))(Q||{}),$=(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[t.EDIT=16]="EDIT",t))($||{}),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 tf={terrain:"TERRAIN",object:"OBJECT"};function on(t){return Pt(t)&&nf(t[0])}function nf(t){return y(gi[t])&&pe(t)}function rf(t){if(pe(t))return tf[t.toLowerCase()]}function sf(t){if(on(t))return t;if(nf(t))return[t];const e=rf(t);if(y(e))return[e]}function mi(t,e){const n=t.words[e],r=sf(n);if(on(r))return[r,e+1];const[s,i]=Re(t,e),o=sf(s);return on(o)?[o,i]:[void 0,e]}const of={solid:"SOLID",walk:"WALK",swim:"SWIM",bullet:"BULLET",walkable:"WALK",swimmable:"SWIM"};function On(t){return Pt(t)&&Ia(t[0])}function Ia(t){return y(me[t])&&pe(t)}function LR(t){if(pe(t))return of[t.toLowerCase()]}function af(t,e){const n=t.words[e];if(On(n))return[n,e+1];if(Ia(n))return[[n],e+1];const[r,s]=Re(t,e);return On(r)?[r,s]:Ia(r)?[[r],s]:[void 0,e]}const cf={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)&&uf(t[0])}function lf(t){return Ze(t)&&t[0].startsWith("ON")}function uf(t){return y(Q[t])&&pe(t)}function hf(t){if(pe(t))return cf[t.toLowerCase()]}function ff(t){return t.map(e=>Q[e]).find(e=>y(e)&&e<16)}function df(t){return t.map(e=>Q[e]).find(e=>y(e)&&e>=16)}function pf(t){if(Ze(t))return t;if(uf(t))return[t];const e=hf(t);if(y(e))return[e]}function gf(t,e){const n=t.words[e],r=pf(n);if(Ze(r))return[r,e+1];const[s,i]=Re(t,e),o=pf(s);return Ze(o)?[o,i]:[void 0,e]}function Ei(t,e){const n=[];let r=e;const[s,i]=gf(t,e);if(Ze(s)&&(n.push(...s),r=i),Ze(n)&&!lf(n)){const[o,a]=gf(t,i);lf(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 mf(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 pe(i)?[[i,r],o]:[void 0,e]}function Ca(t){if(!rr(t))return;const[e]=t;return e}function Ef(t){if(!rr(t))return;const[,e]=t,n=y(e)?ff(e):void 0;return y(n)?n:void 0}function _f(t){if(!rr(t))return;const[,e]=t,n=y(e)?df(e):void 0;return y(n)?n:void 0}const yf={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)&&Tf(t[0])}function Tf(t){return y($[t])&&pe(t)}function Sf(t){if(pe(t))return yf[t.toLowerCase()]}function Af(t){if(Vt(t))return t;if(Tf(t))return[t];const e=Sf(t);if(y(e))return[e]}function wf(t,e){const n=t.words[e],r=Af(n);if(Vt(r))return[r,e+1];const[s,i]=Re(t,e),o=Af(s);return Vt(o)?[o,i]:[void 0,e]}function La(t,e){const n=[];let[r,s]=wf(t,e);for(;Vt(r);){n.push(...r);const[i,o]=wf(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(rf(r)){const[s,i]=mi(t,e);if(y(s))return[s,i]}if(LR(r)){const[s,i]=af(t,e);if(y(s))return[s,i]}if(hf(r)){const[s,i]=Ei(t,e);if(y(s))return[s,i]}if(pe(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(Sf(r)){const[s,i]=La(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(pe(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]=C(t,e+1,[5]);return[Math.abs(i),o]}case"ceil":{const[i,o]=C(t,e+1,[5]);return[Math.ceil(i),o]}case"floor":{const[i,o]=C(t,e+1,[5]);return[Math.floor(i),o]}case"round":{const[i,o]=C(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))(I||{});function ve(t,e){throw new Error(`Invalid arg, expected: ${t} but got ${JSON.stringify(e)}`)}function C(t,e,n){const r=[];let s=e;for(let i=0;i(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++)Yc(t,{x:Wn(0,t.width-1),y:Wn(0,t.height-1),kind:"spin"});return t})}),Rt(OR,{object:{char:219,color:Q.WHITE,bg:Q.CLEAR}}),Rt(kR,{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 Rf={exports:{}},Oa={exports:{}},vf;function bR(){return vf||(vf=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{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(` @@ -238,7 +238,7 @@ $3 Here is some test text and yeah! $3 `).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)}}})})(Rf);var MR=Rf.exports,xR=ro(MR),Nf={},If={},Cf={};const Lf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");Cf.encode=function(t){if(0<=t&&t>>=Of,s>0&&(r|=DR),n+=UR.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 ka={};let $R=class Zp{constructor(){this._array=[],this._set=new Map}static fromArray(e,n){const r=new Zp;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||Mf.compareByGeneratedPositionsInflated(t,e)<=0}let GR=class{constructor(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}unsortedForEach(e,n){this._array.forEach(e,n)}add(e){BR(this._last,e)?(this._last=e,this._array.push(e)):(this._sorted=!1,this._array.push(e))}toArray(){return this._sorted||(this._array.sort(Mf.compareByGeneratedPositionsInflated),this._sorted=!0),this._array}};bf.MappingList=GR;const es=If,ae=Zr,yi=ka.ArraySet,KR=bf.MappingList;let xf=class eg{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 KR,this._sourcesContents=null}static fromSourceMap(e){const n=e.sourceRoot,r=new eg({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())}};xf.prototype._version=3,Nf.SourceMapGenerator=xf;var Uf={};(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}})(Uf);var ts={exports:{}},WR={},jR=Object.freeze({__proto__:null,default:WR}),Pf=og(jR);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=Pf,e=Pf;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 Df=ts.exports;const HR=Df;function VR(){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 YR=function(){if(ns)return ns;const e=[];return ns=HR().then(n=>WebAssembly.instantiate(n,{env:{mapping_callback(r,s,i,o,a,c,l,u,h,d){const f=new VR;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,ba=Uf,Ti=ka.ArraySet,zR=Df,qR=YR,Ma=Symbol("smcInternal");class se{constructor(e,n){return e==Ma?Promise.resolve(this):JR(e,n)}static initialize(e){zR.initialize(e["lib/mappings.wasm"])}static fromSourceMap(e,n){return QR(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(Ma).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,qR().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 XR extends se{constructor(e,n){return super(Ma).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,ba.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;r/,"$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)),Sv=x({name:"Whitespace",pattern:/ +/}),Av=x({name:"WhitespaceSkipped",pattern:/ +/,group:ge.SKIPPED}),Xf=x({name:"StringLiteral",pattern:/[^ $]+/,start_chars_hint:Tv}),Jf=x({name:"StringLiteralDouble",pattern:/"(?:[^\\"]|\\(?:[^\n\r]|u[0-9a-fA-F]{4}))*"/}),$a=x({name:"MaybeFlag",pattern:/\$[^ $]+/}),Qf=x({name:"NumberLiteral",pattern:/\$-?(\d*\.)?\d+([eE][+-]?\d+)?[jJ]?[lL]?\+?/}),Zf=x({name:"ContinueLine",pattern:/\\/});function ed(t,e=""){return x({name:e||t,pattern:new RegExp(t.toLowerCase(),"i")})}const td=[["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"]],nd=td.map(([t,e])=>ed(`\\$(${t})`,e||t)),rd=[...td.map(([t,e])=>ed(`\\$on(${t})`,`on${e||t}`))],wv=[Sv,Zf,...nd,...rd,Jf,Xf,Qf,$a],Rv=new ge(wv,{skipValidations:!wt,ensureOptimizations:wt}),vv=new ge([Av,Zf,...nd,...rd,Jf,Xf,Qf,$a],{skipValidations:!wt,ensureOptimizations:wt});function Nv(t,e=!1){return e?vv.tokenize(t):Rv.tokenize(t)}function Iv(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:[]}}yv.createContext(Iv(1,1,15,1));let Cv=0,sd=0;const id=wt,Lv=["Command","lines"];class Ov extends tR{constructor(){super(Gh,{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(da)}));U(this,"text",this.RULED("text",()=>{this.CONSUME(uh)}));U(this,"label",this.RULED("label",()=>{this.CONSUME(fh)}));U(this,"comment",this.RULED("comment",()=>{this.CONSUME(hh)}));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(dh),this.SUBRULE(this.words),this.CONSUME(ph)}));U(this,"Short_go",this.RULED("Short_go",()=>{this.CONSUME(ya),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(Oh)}));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(Ta),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(Sa),this.CONSUME(Ta),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(Sa),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(kh)}));U(this,"Command_while",this.RULED("Command_while",()=>{this.CONSUME(ht),this.CONSUME(bh),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(Mh)}}])})}));U(this,"Command_repeat",this.RULED("Command_repeat",()=>{this.CONSUME(ht),this.CONSUME(xh),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(Uh)}}])})}));U(this,"Command_read",this.RULED("Command_read",()=>{this.CONSUME(ht),this.CONSUME(Ph),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(Dh)}}])})}));U(this,"Command_break",this.RULED("Command_break",()=>{this.CONSUME(Fh)}));U(this,"Command_continue",this.RULED("Command_continue",()=>{this.CONSUME($h)}));U(this,"expr",this.RULED("expr",()=>{this.SUBRULE1(this.and_test),this.MANY(()=>{this.CONSUME(pa),this.SUBRULE2(this.and_test)})}));U(this,"and_test",this.RULED("and_test",()=>{this.SUBRULE1(this.not_test),this.MANY(()=>{this.CONSUME(ma),this.SUBRULE2(this.not_test)})}));U(this,"not_test",this.RULED("not_test",()=>{this.OR([{ALT:()=>{this.CONSUME(ga),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(Eh)},{ALT:()=>this.CONSUME(_h)},{ALT:()=>this.CONSUME(yh)},{ALT:()=>this.CONSUME(Th)},{ALT:()=>this.CONSUME(Sh)},{ALT:()=>this.CONSUME(Ah)}])}));U(this,"expr_value",this.RULED("expr_value",()=>{this.SUBRULE1(this.and_test_value),this.MANY(()=>{this.CONSUME(pa),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(ma),this.SUBRULE2(this.not_test_value)})}));U(this,"not_test_value",this.RULED("not_test_value",()=>{this.OR([{ALT:()=>{this.CONSUME(ga),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(Ea)},{ALT:()=>this.CONSUME(_a)}]),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(Rh)},{ALT:()=>this.CONSUME(ya)},{ALT:()=>this.CONSUME(vh)},{ALT:()=>this.CONSUME(Nh)}]),this.SUBRULE(this.factor)}));U(this,"factor",this.RULED("factor",()=>{this.OR1([{ALT:()=>{this.OR2([{ALT:()=>this.CONSUME(Ea)},{ALT:()=>this.CONSUME(_a)}]),this.SUBRULE(this.factor)}},{ALT:()=>this.SUBRULE(this.power)}])}));U(this,"power",this.RULED("power",()=>{this.SUBRULE(this.token),this.OPTION(()=>{this.CONSUME(wh),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(gh)},{ALT:()=>this.CONSUME(We)},{ALT:()=>this.CONSUME(mh)},{ALT:()=>{this.CONSUME(Ch),this.SUBRULE(this.expr),this.CONSUME(Lh)}}])}));this.performSelfAnalysis()}PEEK(n,r,...s){console.info(n,s.map(i=>[i.image,i.tokenType]),r)}RULED(n,r,s){const i=Lv.some(o=>n.includes(o));return this.RULE(n,()=>{const o=Cv++,a=sd++,c=a.toString().padStart(3),l=" ".repeat(a),u=i?"font-weight: bold;":"";if(id&&!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(),id&&!this.RECORDING_PHASE&&console.info(`${c}%c${l}< ${n} ${o}`,u),sd--},s)}}const is=new Ov,kv=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 nL(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 od(t,e){return F(t,{type:7,literal:1,value:e})}function bv(t){return!!(t!=null&&t.tokenType)}function Mv(t){const e=Object.values(t).flat().filter(n=>!!n).map(n=>n&&bv(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,...Mv(t)}}class xv extends kv{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:[od(e,"play"),od(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 Uv=new xv,Pe={internal:0,labels:{},labelIndex:0},Ni="if (api.hm()) { continue zss; }",ad=`if (api.sy()) { yield 1; ${Ni} };`,Ii=`yield 1; ${Ni}`,Ci="zss.js";function oe(t,e){return new rv(t.startLine||1,t.startColumn||1,Ci,e)}function Ba(t){return t.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}function Pv(t){return`'${Ba(t)}'`}function Li(t){if(t.startsWith('"'))return Li(t.substring(1,t.length-1));const e=Nv(t);return e.errors.length?t:`'${e.tokens.map(r=>r.tokenType===$a?`', api.group('${Ba(r.image.substring(1))}'), '`:Ba(r.image)).join("")}'`}function Nt(t){return t.filter(e=>e!==void 0).map(H)}function cd(t){return oe(t,"")}function Dv(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}(`,...Dv(n,", "),")"])}function Fv(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 ld(t,e,n,r){return e.prepend(`api.${n}(`),e.add([H(r),")"])}function $v(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 ld(t,e,"opUniPlus",t.rhs);case vt.UNI_MINUS:return ld(t,e,"opUniMinus",t.rhs)}return oe(t,"")}function Bv(t){if(t.type===q.OPERATOR){const e=t.lhs?H(t.lhs):oe(t,"");return t.items.forEach(n=>$v(n,e)),e}return oe(t,"")}function H(t){switch(t.type){case q.PROGRAM:return oe(t,[`try { // first-line + */var ss=Symbol.for("react.element"),ov=Symbol.for("react.portal"),av=Symbol.for("react.fragment"),cv=Symbol.for("react.strict_mode"),lv=Symbol.for("react.profiler"),uv=Symbol.for("react.provider"),hv=Symbol.for("react.context"),fv=Symbol.for("react.forward_ref"),dv=Symbol.for("react.suspense"),pv=Symbol.for("react.memo"),gv=Symbol.for("react.lazy"),Kf=Symbol.iterator;function mv(t){return t===null||typeof t!="object"?null:(t=Kf&&t[Kf]||t["@@iterator"],typeof t=="function"?t:null)}var Wf={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},jf=Object.assign,Hf={};function ir(t,e,n){this.props=t,this.context=e,this.refs=Hf,this.updater=n||Wf}ir.prototype.isReactComponent={},ir.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},ir.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function Vf(){}Vf.prototype=ir.prototype;function Pa(t,e,n){this.props=t,this.context=e,this.refs=Hf,this.updater=n||Wf}var Da=Pa.prototype=new Vf;Da.constructor=Pa,jf(Da,ir.prototype),Da.isPureReactComponent=!0;var Yf=Array.isArray,zf=Object.prototype.hasOwnProperty,Fa={current:null},qf={key:!0,ref:!0,__self:!0,__source:!0};function Xf(t,e,n){var r,s={},i=null,o=null;if(e!=null)for(r in e.ref!==void 0&&(o=e.ref),e.key!==void 0&&(i=""+e.key),e)zf.call(e,r)&&!qf.hasOwnProperty(r)&&(s[r]=e[r]);var a=arguments.length-2;if(a===1)s.children=n;else if(1String.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: @@ -255,7 +255,7 @@ $3 Here is some test text and yeah! $3 `,...t.lines.map(e=>[H(e),` `]).flat(),`} `,`api.endofprogram(); -`,`while(true) { ${Ii} } +`,`while(true) { ${Ci} } `,`} `,`} catch (e) { `,`console.error(e); @@ -265,14 +265,14 @@ $3 Here is some test text and yeah! $3 `,`err.meta = { line: source.line, column: source.column }; `,`throw err; `,`} -`,`//# sourceURL=${Ci}`]);case q.LITERAL:switch(t.literal){case vi.NUMBER:return oe(t,`${t.value}`);case vi.STRING:return oe(t,Pv(t.value));case vi.TEMPLATE:return oe(t,Li(t.value))}return cd(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)]),`) { ${Ii} }; - ${ad} ${Ni}`]);case q.COMMAND:return oe(t,["while (",ee(t,"command",Nt(t.words)),`) { ${Ii} }; - ${ad} ${Ni}`]);case q.IF:{const e=oe(t,["if (",ee(t,`${t.method}`,Nt(t.words)),`) { +`,`//# 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)),`) { ${Ii} };`]),t.lines&&t.lines.forEach(n=>e.add([H(n),` +`);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)]),`; @@ -283,8 +283,8 @@ 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 Fv(t);case q.OPERATOR:return Bv(t);case q.EXPR:return ee(t,"expr",t.words.map(H));default:return console.error("",t),cd(t)}}function Gv(t){return Pe.internal=0,Pe.labels={restart:[1]},Pe.labelIndex=2,{...H(t).toStringWithSourceMap({file:`${Ci}.map`}),...Pe}}const Kv=64;function Wv(t){return Array.isArray(t)?t.length>0?1:0:t??0}function Yt(t){return`${t??""}`}function jv(t,e){var N;const n=Wg(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;mKv},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===Ci);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]=C(m,0,[I.ANY]),v=Wv(g);return v&&S0,S=c[T];return g&&S&&_.command(...S),g},readStart(T,m){if(!pe(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]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return g<=S?1:0},isGreaterThanOrEq(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return g>=S?1:0},opPlus(T,m){const[g]=C(K(_,[T]),0,[I.ANY]),[S]=C(K(_,[m]),0,[I.ANY]);return g+S},opMinus(T,m){const[g]=C(K(_,[T]),0,[I.ANY]),[S]=C(K(_,[m]),0,[I.ANY]);return g-S},opPower(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return Math.pow(g,S)},opMultiply(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return g*S},opDivide(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return g/S},opModDivide(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return g%S},opFloorDivide(T,m){const[g]=C(K(_,[T]),0,[I.NUMBER]),[S]=C(K(_,[m]),0,[I.NUMBER]);return Math.floor(g/S)},opUniPlus(T){const[m]=C(K(_,[T]),0,[I.NUMBER]);return+m},opUniMinus(T){const[m]=C(K(_,[T]),0,[I.NUMBER]);return-m}};return r=(N=e.code)==null?void 0:N.call(e,_),_}function ud(t){const e={},n={...t,getcommand(r){return e[r]},command(r,s){return e[r]=s,n}};return n}var hd={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,gd=t=>t!==0?t<0:1/t<0,md=Number.MAX_SAFE_INTEGER,zv=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&cn(t)===t),or=()=>new Set,ja=t=>t[t.length-1],qv=(t,e)=>{for(let n=0;nt.toLowerCase(),Qv=/^\s*/g,Zv=t=>t.replace(Qv,""),eN=/([A-Z])/g,Ed=(t,e)=>Zv(t.replace(eN,n=>`${e}${Jv(n)}`)),tN=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let s=0;sas.encode(t):tN;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),It=()=>{throw un("Method unimplemented")},Ct=()=>{throw un("Unexpected case")};class ls{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const hn=()=>new ls,rN=t=>{let e=t.cpos;for(let n=0;n{const e=new Uint8Array(rN(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},Ha=Ee,P=(t,e)=>{for(;e>Mn;)Ee(t,He|Mn&e),e=cn(e/128);Ee(t,Mn&e)},Va=(t,e)=>{const n=gd(e);for(n&&(e=-e),Ee(t,(e>Wa?He:0)|(n?zt:0)|Wa&e),e=cn(e/64);e>0;)Ee(t,(e>Mn?He:0)|Mn&e),e=cn(e/128)},Ya=new Uint8Array(3e4),iN=Ya.length/3,oN=(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=pd(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)},za=(t,e)=>{sN(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},cN=(t,e)=>za(t,4).setFloat32(0,e,!1),lN=(t,e)=>za(t,8).setFloat64(0,e,!1),uN=(t,e)=>za(t,8).setBigInt64(0,e,!1),_d=new DataView(new ArrayBuffer(4)),hN=t=>(_d.setFloat32(0,t),_d.getFloat32(0)===t),us=(t,e)=>{switch(typeof e){case"string":Ee(t,119),ar(t,e);break;case"number":zv(e)&&ki(e)<=Yv?(Ee(t,125),Va(t,e)):hN(e)?(Ee(t,124),cN(t,e)):(Ee(t,123),lN(t,e));break;case"bigint":Ee(t,122),uN(t,e);break;case"object":if(e===null)Ee(t,126);else if(Xv(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 Td=t=>{t.count>0&&(Va(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++:(Td(this),this.count=1,this.s=e)}toUint8Array(){return Td(this),ft(this.encoder)}}const Sd=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Va(t.encoder,e),t.count>1&&P(t.encoder,t.count-2)}};class qa{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++):(Sd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Sd(this),ft(this.encoder)}}class fN{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 Ad=un("Unexpected end of array"),wd=un("Integer out of Range");class xi{constructor(e){this.arr=e,this.pos=0}}const Un=t=>new xi(t),dN=t=>t.pos!==t.arr.length,pN=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},be=t=>pN(t,D(t)),cr=t=>t.arr[t.pos++],D=t=>{let e=0,n=1;const r=t.arr.length;for(;t.posmd)throw wd}throw Ad},Xa=t=>{let e=t.arr[t.pos++],n=e&Wa,r=64;const s=(e&zt)>0?-1:1;if(!(e&He))return s*n;const i=t.arr.length;for(;t.posmd)throw wd}throw Ad},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))}},Ja=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},gN=[t=>{},t=>null,Xa,t=>Ja(t,4).getFloat32(0,!1),t=>Ja(t,8).getFloat64(0,!1),t=>Ja(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;rgN[127-cr(t)](t);class Rd 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),dN(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=Xa(this);const e=gd(this.s);this.count=1,e&&(this.s=-this.s,this.count=D(this)+2)}return this.count--,this.s}}class Qa extends xi{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Xa(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 mN{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,Za=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},EN=(t,e)=>{const n=[];for(const[r,s]of t)n.push(e(s,r));return n},_N=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1};class yN{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 TN=crypto.getRandomValues.bind(crypto),vd=()=>TN(new Uint32Array(1))[0],SN="10000000-1000-4000-8000"+-1e11,AN=()=>SN.replace(/[018]/g,t=>(t^vd()&15>>t/4).toString(16)),Nd=t=>new Promise(t);Promise.all.bind(Promise);const Id=t=>t===void 0?null:t;class wN{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let Cd=new wN,RN=!0;try{typeof localStorage<"u"&&localStorage&&(Cd=localStorage,RN=!1)}catch{}const vN=Cd,NN=Object.assign,IN=Object.keys,CN=(t,e)=>{for(const n in t)e(t[n],n)},Ld=t=>IN(t).length,LN=t=>{for(const e in t)return!1;return!0},ON=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},kN=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),bN=(t,e)=>t===e||Ld(t)===Ld(e)&&ON(t,(n,r)=>(n!==void 0||kN(e,r))&&e[r]===n),ec=(t,e,n=0)=>{try{for(;nt,xN=(t,e)=>e.includes(t);var Od={};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 UN=()=>{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(`--${Ed(e,"-")}`,n),Lt.set(`-${Ed(e,"-")}`,n)}})):Lt=dt();return Lt},tc=t=>UN().has(t),nc=t=>Id(fs?Od[t.toUpperCase().replaceAll("-","_")]:vN.getItem(t));(t=>tc("--"+t)||nc(t)!==null)("production");const kd=fs&&xN(Od.FORCE_COLOR,["true","1","2"]),PN=!tc("no-colors")&&(!fs||process.stdout.isTTY||kd)&&(!fs||tc("color")||kd||nc("COLORTERM")!==null||(nc("TERM")||"").includes("color")),DN=t=>new Uint8Array(t),FN=t=>{const e=DN(t.byteLength);return e.set(t),e};class $N{constructor(e,n){this.left=e,this.right=n}}const qt=(t,e)=>new $N(t,e);typeof DOMParser<"u"&&new DOMParser;const BN=t=>EN(t,(e,n)=>`${n}:${e};`).join(""),Xt=Symbol,bd=Xt(),Md=Xt(),GN=Xt(),KN=Xt(),WN=Xt(),xd=Xt(),jN=Xt(),Ud=Xt(),HN=Xt(),VN=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(...zN(t)),XN.forEach(e=>e.print(t))},XN=or(),Pd=t=>({[Symbol.iterator](){return this},next:t}),JN=(t,e)=>Pd(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),rc=(t,e)=>Pd(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class sc{constructor(e,n){this.clock=e,this.len=n}}class ds{constructor(){this.clients=new Map}}const Dd=(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&&QN(n,e.clock)!==null},ic=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 sc(n,r))},eI=()=>new ds,tI=t=>{const e=eI();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},Bd=vd;class hr extends yN{constructor({guid:e=AN(),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=Bd(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new Qd,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=Nd(l=>{this.on("load",()=>{this.isLoaded=!0,l(this)})});const c=()=>Nd(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 Gd{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return D(this.restDecoder)}readDsLen(){return D(this.restDecoder)}}class Kd extends Gd{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 FN(be(this.restDecoder))}readJSON(){return JSON.parse(lr(this.restDecoder))}readKey(){return lr(this.restDecoder)}}class nI{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 nI{constructor(e){super(e),this.keys=[],D(e),this.keyClockDecoder=new Qa(be(e)),this.clientDecoder=new Ui(be(e)),this.leftClockDecoder=new Qa(be(e)),this.rightClockDecoder=new Qa(be(e)),this.infoDecoder=new Rd(be(e),cr),this.stringDecoder=new mN(be(e)),this.parentInfoDecoder=new Rd(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])=>{rI(t,e.clients.get(s),s,i)})},sI=(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 Qd,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 ac(f,a,new Map),P(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},oI=(t,e)=>ac(t,e.doc.store,e.beforeState),aI=(t,e,n,r=new fr(t))=>X(e,s=>{s.local=!1;let i=!1;const o=s.doc,a=o.store,c=sI(r,o),l=iI(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=$d(r,s,a);if(a.pendingDs){const d=new fr(Un(a.pendingDs));D(d.restDecoder);const f=$d(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,Hd(s.doc,d)}},n,!1),Hd=(t,e,n,r=fr)=>{const s=Un(e);aI(s,t,n,new r(s))},cI=(t,e,n)=>Hd(t,e,n,Kd),lI=(t,e,n=new Map)=>{ac(t,e.store,n),ur(t,tI(e.store))},uI=(t,e=new Uint8Array([0]),n=new Pn)=>{const r=Vd(e);lI(n,t,r);const s=[n.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(vI(t.store.pendingStructs.update,e)),s.length>1){if(n.constructor===ps)return wI(s.map((i,o)=>o===0?i:II(i)));if(n.constructor===Pn)return Bi(s)}return s[0]},hI=(t,e)=>uI(t,e,new ps),fI=t=>{const e=new Map,n=D(t.restDecoder);for(let r=0;rfI(new Gd(Un(t))),Yd=(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),dI=(t,e)=>Yd(t,Fi(e.store)),pI=(t,e=new jd)=>(t instanceof Map?Yd(e,t):dI(e,t),e.toUint8Array()),gI=t=>pI(t,new Wd);class mI{constructor(){this.l=[]}}const zd=()=>new mI,qd=(t,e)=>t.l.push(e),Xd=(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.")},Jd=(t,e,n)=>ec(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),EI=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw Ct()},pr=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Fd(e.ds,t.id),cc=(t,e)=>{const n=fn(t.meta,cc,or),r=t.doc.store;n.has(e)||(e.sv.forEach((s,i)=>{s<_e(r,i)&&dn(t,G(i,s))}),Dd(t,e.ds,s=>{}),n.add(e))};class Qd{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},Zd=(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 Ct()}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)]},uc=(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[uc(t,n,e.clock)]},ep=(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},_I=(t,e,n)=>{const r=t.clients.get(e.id.client);r[Ot(r,e.id.clock)]=n},tp=(t,e,n,r,s)=>{if(r===0)return;const i=n+r;let o=uc(t,e,n),a;do a=e[o++],ie.deleteSet.clients.size===0&&!_N(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(ic(e.deleteSet),oI(t,e),ur(t,e.deleteSet),!0),rp=(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 de&&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},TI=(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=pd(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)}})},sp=(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),Jd(l._dEH,c,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),ec(a,[]),n._needFormattingCleanup&&GI(n)}finally{r.gc&&TI(i,s,r.gcFilter),SI(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)&&(qN(Ud,bd,"[yjs] ",Md,xd,"Changed the client-id because another client seems to be using it."),r.clientID=Bd()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const u=new ps;np(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const u=new Pn;np(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])):sp(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 yI(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&&sp(s,0)}}return o};function*AI(t){const e=D(t.restDecoder);for(let n=0;nBi(t,Kd,ps),RI=(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 de(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 hc(u,!0)),i=null;const o=new n,a=new fc(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=RI(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),dc(a);const c=r.map(u=>oc(u)),l=ZN(c);return ur(o,l),o.toUint8Array()},vI=(t,e,n=fr,r=Pn)=>{const s=Vd(e),i=new r,o=new fc(i),a=new n(Un(t)),c=new hc(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()}dc(o);const l=oc(a);return ur(i,l),i.toUint8Array()},ip=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&&ip(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++},dc=t=>{ip(t);const e=t.encoder.restEncoder;P(e,t.clientStructs.length);for(let n=0;n{const s=new n(Un(t)),i=new hc(s,!1),o=new r,a=new fc(o);for(let l=i.curr;l!==null;l=i.next())pn(a,e(l),0);dc(a);const c=oc(s);return ur(o,c),o.toUint8Array()},II=t=>NI(t,MN,fr,ps),op="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=CI(this.currentTarget,this.target))}deletes(e){return Fd(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw un(op);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=ja(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",a=ja(c.content.getContent())):(o="add",a=void 0)}else if(this.deletes(i))o="delete",a=ja(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(op);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 CI=(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},ap=80;let pc=0;class LI{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=pc++}}const OI=t=>{t.timestamp=pc++},cp=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=pc++},kI=(t,e,n)=>{if(t.length>=ap){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;Jd(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=zd(),this._dEH=zd(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw It()}clone(){throw It()}_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){qd(this._eH,e)}observeDeep(e){qd(this._dEH,e)}unobserve(e){Xd(this._eH,e)}unobserveDeep(e){Xd(this._dEH,e)}toJSON(){}}const lp=(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},up=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},bI=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}}}},fp=(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 de(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 de(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 de(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 de(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()},dp=()=>un("Length exceeded!"),pp=(t,e,n,r)=>{if(n>e._length)throw dp();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)},gp=(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 dp();e._searchMarker&&gs(e._searchMarker,s,-i+r)},Hi=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},gc=(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 de(G(o,_e(i.store,o)),s,s&&s.lastId,null,null,e,n,a).integrate(t,0)},mc=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},mp=t=>{const e={};return t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},Ep=(t,e)=>{const n=t._map.get(e);return n!==void 0&&!n.deleted},xI=(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=>JN(t.entries(),e=>!e[1].deleted);class UI 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 UI(this,e))}insert(e,n){this.doc!==null?X(this.doc,r=>{pp(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?X(this.doc,n=>{MI(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?X(this.doc,r=>{gp(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return fp(this,e)}toArray(){return up(this)}slice(e=0,n=this.length){return lp(this,e,n)}toJSON(){return this.map(e=>e instanceof we?e.toJSON():e)}map(e){return hp(this,e)}forEach(e){ms(this,e)}[Symbol.iterator](){return bI(this)}_write(e){e.writeTypeRef(iC)}}const PI=t=>new gr;class DI 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 DI(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 rc(Vi(this._map),e=>e[0])}values(){return rc(Vi(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return rc(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=>{gc(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return mc(this,e)}has(e){return Ep(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(oC)}}const FI=t=>new mr,gn=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&bN(t,e);class Ec{constructor(e,n,r,s){this.left=e,this.right=n,this.index=r,this.currentAttributes=s}forward(){switch(this.right===null&&Ct(),this.right.content.constructor){case fe: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 _p=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case fe: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 Ec(i.p.left,i.p,i.index,s);return _p(t,o,n-i.index)}else{const o=new Ec(null,e._start,0,s);return _p(t,o,n)}},yp=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===fe&&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 de(G(i,_e(s.store,i)),c,c&&c.lastId,l,l&&l.id,e,null,new fe(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)},Tp=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===fe&&gn(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},Sp=(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 de(G(i,_e(s.store,i)),u,u&&u.lastId,h,h&&h.id,e,null,new fe(a,c)),n.right.integrate(t,0),n.forward()}}return o},_c=(t,e,n,r,s)=>{n.currentAttributes.forEach((d,f)=>{s[f]===void 0&&(s[f]=null)});const i=t.doc,o=i.clientID;Tp(n,s);const a=Sp(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 de(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(),yp(t,e,n,a)},Ap=(t,e,n,r,s)=>{const i=t.doc,o=i.clientID;Tp(n,s);const a=Sp(t,e,n,s);e:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===fe));){if(!n.right.deleted)switch(n.right.content.constructor){case fe:{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 de(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()}yp(t,e,n,a)},wp=(t,e,n,r,s)=>{let i=e;const o=dt();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===fe){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 fe:{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},$I=(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===fe){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}},BI=t=>{let e=0;return X(t.doc,n=>{let r=t._start,s=t._start,i=dt();const o=Za(i);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case fe:Er(o,s.content);break;default:e+=wp(n,r,s,i,o),i=Za(o),r=s;break}s=s.right}}),e},GI=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&&tp(t,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===fe&&o.constructor!==et&&e.add(o.parent)})}X(n,r=>{Dd(t,t.deleteSet,s=>{if(s instanceof et||!s.parent._hasFormatting||e.has(s.parent))return;const i=s.parent;s.content.constructor===fe?e.add(i):$I(r,s)});for(const s of e)BI(s)})},Rp=(t,e,n)=>{const r=n,s=Za(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},LN(c)||(f.attributes=NN({},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 fe:{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 KI(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 Ec(null,this._start,0,new Map);for(let i=0;i0)&&_c(r,this,s,a,o.attributes||{})}else o.retain!==void 0?Ap(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Rp(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 fe:pr(c,e)&&(l(),Er(i,c.content));break}c=c.right}l()};return e||n?X(o,h=>{e&&cc(h,e),n&&cc(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})),_c(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);_c(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=>{Rp(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&&Ap(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=>{gc(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return mc(this,e)}getAttributes(){return mp(this)}_write(e){e.writeTypeRef(aC)}}const WI=t=>new Dn;class yc{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 yc(this,e)}querySelector(e){e=e.toUpperCase();const r=new yc(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),ln(new yc(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Wi(this,e,new VI(this,n,e))}toString(){return hp(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=>{pp(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=>{gp(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return up(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return fp(this,e)}slice(e=0,n=this.length){return lp(this,e,n)}forEach(e){ms(this,e)}_write(e){e.writeTypeRef(lC)}}const jI=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 CN(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=>{gc(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return mc(this,e)}hasAttribute(e){return Ep(this,e)}getAttributes(e){return e?xI(this,e):mp(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(cC),e.writeKey(this.nodeName)}}const HI=t=>new _r(t.readKey());class VI 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(uC),e.writeKey(this.hookName)}}const YI=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(hC)}}const zI=t=>new qi;class Tc{constructor(e,n){this.id=e,this.length=n}get deleted(){throw It()}mergeWith(e){return!1}write(e,n,r){throw It()}integrate(e,n){throw It()}}const qI=0;class et extends Tc{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),Zd(e.doc.store,this)}write(e,n){e.writeInfo(qI),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 It()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const XI=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 JI=t=>new _s(t.readLen()),vp=(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(vp(this.doc.guid,this.opts))}splice(e){throw It()}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 QI=t=>new ys(vp(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 It()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const ZI=t=>new $n(t.readJSON());class fe{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new fe(this.key,this.value)}splice(e){throw It()}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 eC=t=>new fe(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 rC=t=>new kt(t.readString()),sC=[PI,FI,WI,HI,jI,YI,zI],iC=0,oC=1,aC=2,cC=3,lC=4,uC=5,hC=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 It()}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 fC=t=>new Jt(sC[t.readTypeRef()](t)),Ji=(t,e,n)=>{const{client:r,clock:s}=e.id,i=new de(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 de extends Tc{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()?dd:0}set marker(e){(this.info&Ka)>0!==e&&(this.info^=Ka)}get marker(){return(this.info&Ka)>0}get keep(){return(this.info&fd)>0}set keep(e){this.keep!==e&&(this.info^=fd)}get countable(){return(this.info&dd)>0}get deleted(){return(this.info&Ga)>0}set deleted(e){this.deleted!==e&&(this.info^=Ga)}markDeleted(){this.info|=Ga}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=ep(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===de&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===de&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===dr){const r=lc(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=ep(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),rp(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw Ct();this.content.gc(e),n?_I(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=EI(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)):Ct();i!==null&&e.writeString(i)}this.content.write(e,n)}}const Np=(t,e)=>dC[e&Oi](t),dC=[()=>{Ct()},JI,tC,XI,rC,ZI,eC,fC,nC,QI,()=>{Ct()}],pC=10;class tt extends Tc{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){Ct()}write(e,n){e.writeInfo(pC),P(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const Ip=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Cp="__ $YJS$ __";Ip[Cp]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Ip[Cp]=!0;const Sc=0,Lp=1,Op=2,gC=(t,e)=>{P(t,Sc);const n=gI(e);Ne(t,n)},kp=(t,e,n)=>{P(t,Lp),Ne(t,hI(e,n))},mC=(t,e,n)=>kp(e,n,be(t)),bp=(t,e,n)=>{try{cI(e,be(t),n)}catch(r){console.error("Caught error while handling a Yjs update",r)}},EC=(t,e)=>{P(t,Op),Ne(t,e)},_C=bp,yC=(t,e,n,r)=>{const s=D(t);switch(s){case Sc:mC(t,e,n);break;case Lp:bp(t,n,r);break;case Op:_C(t,n,r);break;default:throw new Error("Unknown message type")}return s},yr={},Ac={},wc={},Ts={},bt=wr("shared",["second"],t=>{switch(t.target){case"second":Object.keys(wc).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(Ac).forEach(e=>{bt.emit("shared:active",e)});break;case"join":{const e=t.data,n=yr[e];if(n&&Ac[e]){bt.reply(t,"joinack",e);const r=hn();gC(r,n),bt.reply(t,"sync",Zi(e,r));const s=hn();kp(s,n),bt.reply(t,"sync",Zi(e,s))}break}case"joinack":{const e=t.data;yr[e]&&wc[e]&&(Ts[e]=0);break}case"active":{const e=t.data;yr[e]&&wc[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(yC(i,o,s,bt)===Sc){const c=Zi(n,o);bt.emit("shared:sync",c)}}break}}});function TC(t){let e=yr[t];if(e)return e;yr[t]=e=new hr({guid:t});function n(r){const s=hn();EC(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 TC(t).getMap()}function Zi(t,e){const n=ft(e);return[bt.id()??"",t,n]}function Mp(t,e){const n=t.get(e);return n!=null&&n.toJSON?n.toJSON():n}function xp(t,e,n){typeof n=="string"?t.set(e,new Dn(n)):t.set(e,n)}function SC(t,e,n){console.info({guid:t,key:e,value:n}),Ac[t]=!0;const r=Qi(t);r.get(e)===void 0&&n!==void 0&&xp(r,e,n)}function AC(t,e,n){const r=Qi(t),s=Mp(r,e);(s===void 0||n!==s)&&xp(r,e,n)}function wC(t,e,n){const r=Qi(t);function s(){n(Mp(r,e))}function i(o){o.keysChanged.has(e)&&s()}return s(),r.observe(i),()=>{r.unobserve(i)}}function RC(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 Up(t,e){return t.player=e,t.layers=[],t.layout=[],t.layoutreset=!0,t.layoutfocus="scroll",t}function Pp(t){t.text=[],Object.values(mn[t.id]??{}).forEach(e=>e==null?void 0:e()),mn[t.id]={}}function Dp(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 Rc={},vC=new Set(["hk","hotkey","rn","range","sl","select","nm","number","tx","text"]),NC=new Set(["rn","range","sl","select","nm","number","tx","text"]),IC=new Set(["tx","text"]),CC={rn:1,range:1,sl:0,select:0,nm:0,number:0,tx:"",text:""};function Gn(t){let e=Rc[t];return y(e)?e:Rc[t]=e=Up({},t)}function LC(){return Object.keys(Rc)}function OC(t){const e=Gn(t);e.layout=e.layout.filter(n=>n.edge!==Ye.SCROLL)}function kC(t,e,n){Object.values(mn).forEach(r=>{r[e]!==void 0&&AC(t.id(),e,n)})}function bC(t){const e=Gn(t.id());e.layout=e.layout.filter(n=>n.edge!==Ye.SCROLL||n.text.length>0)}function vc(t,e,n,r,s){const i=Gn(t.id()),o=r,a=s||Vv.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:Up(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??Tg[n],text:[]};i.layout.push(l),i.layoutfocus=a;break}}function MC(t,e){const n=Gn(t.id()),r=Dp(n);n.layoutreset&&(n.layoutreset=!1,Pp(r)),r.text.push(e)}function xC(t,e,n,r){const s=Gn(t.id()),i=Dp(s);s.layoutreset&&(s.layoutreset=!1,Pp(i));const o=n.toLowerCase(),a=[t.id(),e,...vC.has(o)?[o]:["hypertext",n],...r],c=a[2];if(NC.has(c)){const l=`${a[3]??""}`;mn[i.id]=mn[i.id]??{};const u=t.get(l);mn[i.id][l]===void 0&&(SC(t.id(),l,u??CC[c]),IC.has(c)?mn[i.id][l]=RC(t.id(),l,h=>{if(h!==void 0){const d=h.toJSON();d!==t.get(l)&&t.set(l,d)}}):mn[i.id][l]=wC(t.id(),l,h=>{h!==void 0&&h!==t.get(l)&&t.set(l,h)}))}i.text.push(a)}const UC=ud({get(){return[!1,void 0]},set(t,e,n){return kC(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";vc(t,"scroll",Ye.SCROLL,void 0,n)},tock(t){bC(t)}}).command("color",(t,e)=>{const n=V(t.id()),[r]=C({...n,chip:t,words:e},0,[I.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]=C(r,0,[I.STRING]),i=yg[s.toLowerCase()];if(i===Ye.SCROLL){const[,o,a]=C(r,0,[I.STRING,I.MAYBE_STRING,I.MAYBE_NUMBER]);vc(t,s,i,a,o)}else{const[,o,a]=C(r,0,[I.STRING,I.MAYBE_NUMBER,I.MAYBE_STRING]);vc(t,s,i,o,a)}return 0}).command("book",(t,e)=>{const n=V(t.id()),[r,s]=C({...n,chip:t,words:e},0,[I.STRING,I.STRING]),i=r.toLowerCase(),o=s.toLowerCase();switch(o){case"create":Jh(Wh(i,[Rt("@board title",{board:Vc(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]=C({...n,chip:t,words:e},0,[I.STRING,I.MAYBE_STRING,I.MAYBE_STRING]),o=((c=n.board)==null?void 0:c.id)??"",a=r.toLowerCase();if(a==="reset")Xh(o);else if(y(s)&&y(i)){const l=s.toLowerCase();switch(l){case"edit":wR(o,a,i);break;case"view":AR(o,a,i);break;default:console.info("frame",{ltype:l,ltarget:a,maybeboard:i});break}}return 0});function Fp(t,e,n,r){if(!t||!e)return;const[s,i]=r,o=jh(t,s);y(o)&&(nm(e,n.x,n.y,s),yo(em(e,n.x,n.y),i));const a=va(t,r[0]);y(a)&&y(a.name)&&(rm(e,n.x,n.y,a),yo(a,i))}const $p=new Set(["cycle","player","sender","inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu","data"]),PC=new Set(["inputmove","inputalt","inputctrl","inputshift","inputok","inputcancel","inputmenu"]);function DC(t){const e=tf[t];if(y(e))return e;const n=of[t];if(y(n))return n;const r=cf[t];if(y(r))return r;const s=yf[t];if(y(s))return s}const FC=["NORTH","SOUTH","WEST","EAST"];function $C(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&Sg?1:0,t.stats.inputctrl=r&Ag?1:0,t.stats.inputshift=r&wg?1:0,n){case ce.MOVE_UP:case ce.MOVE_DOWN:case ce.MOVE_LEFT:case ce.MOVE_RIGHT:t.stats.inputmove=[FC[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=pe(e)?e:e.id,i=pe(n)?n:n.id;y(s)&&y(i)&&t.send(i,r,s)}function Bp(t,e,n,r,s){const i=gR(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)}const BC={zzt:ud({get(t,e){var o;const n=DC(e);if(y(n))return[!0,n];const r=V(t.id());if(r.target){PC.has(e)&&$C(r.target);const a=(o=r.target.stats)==null?void 0:o[e];if(y(a)||$p.has(e))return[!0,a]}const s=r.board?To(r.board,r.target):void 0,i=hR(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])||$p.has(e)))return r.target.stats||(r.target.stats={}),r.target.stats[e]=n,[!0,n];const s=r.board?To(r.board,r.target):void 0;return fR(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)};Bp(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]=C({...n,chip:t,words:e},0,[I.KIND,I.KIND]),i=Ca(r)??"",o=Eo(n.board,i);return zg(o,r).forEach(c=>{const l=Ca(s);if(Xr(n.book,c)===l){const u=Ef(s);y(u)&&(c.color=u);const h=_f(s);y(h)&&(c.bg=h)}else y(c.id)&&Yh(n.book,n.board,c,t.timestamp()),sn(c)&&Fp(n.book,n.board,c,s)}),0}).command("char",(t,e)=>{const n=V(t.id()),[r]=C({...n,chip:t,words:e},0,[I.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]=C({...n,chip:t,words:e},0,[I.NUMBER]);return t.cycle(io(Math.round(r),1,255)),0}).command("die",t=>{const e=V(t.id());return Yh(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]=C({...n,chip:t,words:e},0,[I.STRING,I.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]=C({...n,chip:t,words:e},r,[I.DIR]);Bp(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)=>{var l;const n=V(t.id()),[r,s]=C({...n,chip:t,words:e},0,[I.DIR,I.KIND]);let i;const o=pi(((l=n.board)==null?void 0:l.id)??"");switch(r.frame){case"edit":{i=o.find(u=>u.type===Jr.EDIT);break}}const a=i?Qr((i==null?void 0:i.book)??""):n.book,c=i?tr(a,(i==null?void 0:i.board)??""):n.board;return Fp(a,c,r,s),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]=C({...n,chip:t,words:e},0,[I.STRING,I.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]=C({...n,chip:t,words:e},0,[I.STRING,I.ANY]);return t.set(r,s),0}).command("shoot",(t,e)=>{const n=V(t.id()),[r,s]=C({...n,chip:t,words:e},0,[I.DIR,I.MAYBE_KIND]);return console.info({dir:r,maybekind:s}),0}).command("take",(t,e)=>{const n=V(t.id()),[r,s,i]=C({...n,chip:t,words:e},0,[I.STRING,I.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 C({...n,chip:t,words:e},0,[I.DIR,I.MAYBE_KIND]),0}).command("try",(t,e)=>{const n=V(t.id()),[,r]=C({...n,chip:t,words:e},0,[I.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]=C({...n,chip:t,words:e},0,[I.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 MC(t,n),0}).command("hyperlink",(t,e)=>{const[n,r,...s]=e,i=Yt(n),o=Yt(r);return xC(t,i,o,s),0}),zss:UC};function GC(t){Object.values(BC).forEach(e=>{t.install(e)})}function Nc(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(Nc(s))}):e.push(Nc(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 KC(t){const e=Aa(`${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=Uv.visit(n);return r?(Nc(r),{tokens:e.tokens,cst:n,ast:r}):{tokens:e.tokens,cst:n,errors:["no ast output"]}}const Ic=Object.getPrototypeOf(function*(){}).constructor;function WC(t){const e=KC(t);if(e.errors&&e.errors.length>0)return e;if(!e.ast)return{...e,errors:["no ast output"]};const n=Gv(e.ast);if(n.code){nR&&console.info(n.code);try{return{...e,...n,source:n.code,code:new Ic("api",n.code)}}catch(r){return{errors:[{message:r.message}],source:"there was an error",code:new Ic("api"," ")}}}return{...e,...n,source:"there was an error",code:new Ic("api"," ")}}function jC(){const t={},e={};function n(s){const i=t[s];if(i)return i;const o=WC(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]=jv(s,c),GC(o)}return!!(o!=null&&o.tick())},message(s){const{target:i,path:o}=xc(s.target),a=e[i];y(a)&&a.message({...s,target:o})}}}const HC=Mc(so.numbers,4),VC=Mc(`${so.numbers}${so.lowercase}`,16),Gp=`pid_${HC()}_${VC()}`;SR(Gp);const Kp=jC(),YC=32*15,Tr={},zC=wr("vm",["login","tick","tock"],t=>{switch(t.target){case"login":t.player&&(Tr[t.player]=0,RR(t.player));break;case"tick":NR(Kp,t.data);break;case"tock":Object.keys(Tr).forEach(e=>{++Tr[e],Tr[e]>YC&&(delete Tr[e],vR(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:Kp.message(t);break}});function qC(){Jh(_i),zC.emit("ready",void 0,Gp)}const Cc=wr("clock",[],()=>{});let Lc=0,Wp=performance.now(),Oc=0,to=0;function XC(){Cc.emit("tick",to),Cc.emit("tock",to),++Oc,++to,Oc>=Ao&&(Oc%=Ao,Cc.emit("second",to))}function jp(){const t=performance.now(),e=t-Wp;Lc+=e,Lc>=So&&(Lc%=So,XC()),Wp=t,setTimeout(jp)}jp();const Hp={},Vp=wr("gadgetserver",["tock"],t=>{switch(t.target){case"tock":LC().forEach(e=>{const n=Gn(e);n.layers=CR(e);const r=go(Hp[e]??{},n);r.length&&(Hp[e]=Ce(n),Vp.emit("gadgetclient:patch",r,e))});break;case"desync":if(t.player){const e=Gn(t.player);Vp.emit("gadgetclient:reset",e,t.player)}break;case"clearscroll":t.player&&OC(t.player);break}}),JC=ig(t=>postMessage(t));onmessage=function(e){JC(e.data)},queueMicrotask(qC)})(); +`);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 5ab2f4a83..0d2683c7a 100644 --- a/index.html +++ b/index.html @@ -3,11 +3,11 @@ - ZZS - main:0.2.0:608ab91a482ca58177dcf8d6ffc691aa5e224607 + ZZS - main:0.2.1:cab08f3b1ebc108a4629bb4904e63ccbbafc54a1 - +