@croquet/croquet
Version:
Multiuser for Static Web Apps by Running Server Code in Synced Client VMs
8 lines (7 loc) • 305 kB
JavaScript
/**
* Copyright Croquet Labs 2025
* Bundle of @croquet/croquet
* Date: 2025-06-09
* Version: 2.0.4
*/
"use strict";var e=require("minimist"),t=require("fast-json-stable-stringify"),s=require("fastpriorityqueue");function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var n=i(require("ws")),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var a,l={exports:{}};a||(a=1,function(e){var t=function(e){var t,s=Object.prototype,i=s.hasOwnProperty,n=Object.defineProperty||function(e,t,s){e[t]=s.value},r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",l=r.toStringTag||"@@toStringTag";function c(e,t,s){return Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,s){return e[t]=s}}function d(e,t,s,i){var r=t&&t.prototype instanceof y?t:y,o=Object.create(r.prototype),a=new k(i||[]);return n(o,"_invoke",{value:x(e,s,a)}),o}function h(e,t,s){try{return{type:"normal",arg:e.call(t,s)}}catch(e){return{type:"throw",arg:e}}}e.wrap=d;var u="suspendedStart",m="suspendedYield",p="executing",b="completed",f={};function y(){}function g(){}function Z(){}var X={};c(X,o,(function(){return this}));var w=Object.getPrototypeOf,G=w&&w(w(V([])));G&&G!==s&&i.call(G,o)&&(X=G);var v=Z.prototype=y.prototype=Object.create(X);function L(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function S(e,t){function s(n,r,o,a){var l=h(e[n],e,r);if("throw"!==l.type){var c=l.arg,d=c.value;return d&&"object"==typeof d&&i.call(d,"__await")?t.resolve(d.__await).then((function(e){s("next",e,o,a)}),(function(e){s("throw",e,o,a)})):t.resolve(d).then((function(e){c.value=e,o(c)}),(function(e){return s("throw",e,o,a)}))}a(l.arg)}var r;n(this,"_invoke",{value:function(e,i){function n(){return new t((function(t,n){s(e,i,t,n)}))}return r=r?r.then(n,n):n()}})}function x(e,s,i){var n=u;return function(r,o){if(n===p)throw new Error("Generator is already running");if(n===b){if("throw"===r)throw o;return{value:t,done:!0}}for(i.method=r,i.arg=o;;){var a=i.delegate;if(a){var l=W(a,i);if(l){if(l===f)continue;return l}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(n===u)throw n=b,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);n=p;var c=h(e,s,i);if("normal"===c.type){if(n=i.done?b:m,c.arg===f)continue;return{value:c.arg,done:i.done}}"throw"===c.type&&(n=b,i.method="throw",i.arg=c.arg)}}}function W(e,s){var i=s.method,n=e.iterator[i];if(n===t)return s.delegate=null,"throw"===i&&e.iterator.return&&(s.method="return",s.arg=t,W(e,s),"throw"===s.method)||"return"!==i&&(s.method="throw",s.arg=new TypeError("The iterator does not provide a '"+i+"' method")),f;var r=h(n,e.iterator,s.arg);if("throw"===r.type)return s.method="throw",s.arg=r.arg,s.delegate=null,f;var o=r.arg;return o?o.done?(s[e.resultName]=o.value,s.next=e.nextLoc,"return"!==s.method&&(s.method="next",s.arg=t),s.delegate=null,f):o:(s.method="throw",s.arg=new TypeError("iterator result is not an object"),s.delegate=null,f)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function V(e){if(null!=e){var s=e[o];if(s)return s.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function s(){for(;++n<e.length;)if(i.call(e,n))return s.value=e[n],s.done=!1,s;return s.value=t,s.done=!0,s};return r.next=r}}throw new TypeError(typeof e+" is not iterable")}return g.prototype=Z,n(v,"constructor",{value:Z,configurable:!0}),n(Z,"constructor",{value:g,configurable:!0}),g.displayName=c(Z,l,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,Z):(e.__proto__=Z,c(e,l,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},L(S.prototype),c(S.prototype,a,(function(){return this})),e.AsyncIterator=S,e.async=function(t,s,i,n,r){void 0===r&&(r=Promise);var o=new S(d(t,s,i,n),r);return e.isGeneratorFunction(s)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},L(v),c(v,l,"Generator"),c(v,o,(function(){return this})),c(v,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),s=[];for(var i in t)s.push(i);return s.reverse(),function e(){for(;s.length;){var i=s.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},e.values=V,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(C),!e)for(var s in this)"t"===s.charAt(0)&&i.call(this,s)&&!isNaN(+s.slice(1))&&(this[s]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var s=this;function n(i,n){return a.type="throw",a.arg=e,s.next=i,n&&(s.method="next",s.arg=t),!!n}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var l=i.call(o,"catchLoc"),c=i.call(o,"finallyLoc");if(l&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(l){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var s=this.tryEntries.length-1;s>=0;--s){var n=this.tryEntries[s];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var r=n;break}}r&&("break"===e||"continue"===e)&&r.tryLoc<=t&&t<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=e,o.arg=t,r?(this.method="next",this.next=r.finallyLoc,f):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var s=this.tryEntries[t];if(s.finallyLoc===e)return this.complete(s.completion,s.afterLoc),C(s),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var s=this.tryEntries[t];if(s.tryLoc===e){var i=s.completion;if("throw"===i.type){var n=i.arg;C(s)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(e,s,i){return this.delegate={iterator:V(e),resultName:s,nextLoc:i},"next"===this.method&&(this.arg=t),f}},e}(e.exports);try{globalThis.regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(l));const c=e(process.argv.slice(2));const d=new class{constructor(){!function(e){for(const t of Object.keys(c)){if("_"===t)continue;let s=c[t];"string"==typeof s&&"["===s[0]&&(s=s.slice(1,-1).split(",")),e[t]=s}}(this)}has(e,t,s){"boolean"!=typeof s&&(s=this.isHost(s));const i=this[e];if("string"!=typeof i)return s;const n=i.split(",");return!0===s&&(t=`no${t}`),t.endsWith("s")&&(t=t.slice(0,-1)),n.includes(t)||n.includes(`${t}s`)?!s:s}isHost(e){return"localhost"===e}isLocalhost(){return this.isHost("localhost")}};var h={exports:{}};var u,m={exports:{}};function p(){return u||(u=1,m.exports=(e=e||function(e,t){var s;if("undefined"!=typeof window&&window.crypto&&(s=window.crypto),"undefined"!=typeof self&&self.crypto&&(s=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(s=globalThis.crypto),!s&&"undefined"!=typeof window&&window.msCrypto&&(s=window.msCrypto),!s&&void 0!==r&&r.crypto&&(s=r.crypto),!s)try{s=require("crypto")}catch(e){}var i=function(){if(s){if("function"==typeof s.getRandomValues)try{return s.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof s.randomBytes)try{return s.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},n=Object.create||function(){function e(){}return function(t){var s;return e.prototype=t,s=new e,e.prototype=null,s}}(),o={},a=o.lib={},l=a.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},c=a.WordArray=l.extend({init:function(e,s){e=this.words=e||[],this.sigBytes=s!=t?s:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,s=e.words,i=this.sigBytes,n=e.sigBytes;if(this.clamp(),i%4)for(var r=0;r<n;r++){var o=s[r>>>2]>>>24-r%4*8&255;t[i+r>>>2]|=o<<24-(i+r)%4*8}else for(var a=0;a<n;a+=4)t[i+a>>>2]=s[a>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],s=0;s<e;s+=4)t.push(i());return new c.init(t,e)}}),d=o.enc={},h=d.Hex={stringify:function(e){for(var t=e.words,s=e.sigBytes,i=[],n=0;n<s;n++){var r=t[n>>>2]>>>24-n%4*8&255;i.push((r>>>4).toString(16)),i.push((15&r).toString(16))}return i.join("")},parse:function(e){for(var t=e.length,s=[],i=0;i<t;i+=2)s[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new c.init(s,t/2)}},u=d.Latin1={stringify:function(e){for(var t=e.words,s=e.sigBytes,i=[],n=0;n<s;n++){var r=t[n>>>2]>>>24-n%4*8&255;i.push(String.fromCharCode(r))}return i.join("")},parse:function(e){for(var t=e.length,s=[],i=0;i<t;i++)s[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new c.init(s,t)}},m=d.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new c.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=m.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s,i=this._data,n=i.words,r=i.sigBytes,o=this.blockSize,a=r/(4*o),l=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,d=e.min(4*l,r);if(l){for(var h=0;h<l;h+=o)this._doProcessBlock(n,h);s=n.splice(0,l),i.sigBytes-=d}return new c.init(s,d)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});a.Hasher=p.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){p.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,s){return new e.init(s).finalize(t)}},_createHmacHelper:function(e){return function(t,s){return new b.HMAC.init(e,s).finalize(t)}}});var b=o.algo={};return o}(Math),e)),m.exports;var e}var b;var f,y,g=(b||(b=1,h.exports=(f=p(),function(){if("function"==typeof ArrayBuffer){var e=f.lib.WordArray,t=e.init,s=e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var s=e.byteLength,i=[],n=0;n<s;n++)i[n>>>2]|=e[n]<<24-n%4*8;t.call(this,i,s)}else t.apply(this,arguments)};s.prototype=e}}(),f.lib.WordArray)),h.exports),Z=o(g),X={exports:{}};function w(){return y||(y=1,X.exports=function(e){return function(t){var s=e,i=s.lib,n=i.WordArray,r=i.Hasher,o=s.algo,a=[],l=[];!function(){function e(e){for(var s=t.sqrt(e),i=2;i<=s;i++)if(!(e%i))return!1;return!0}function s(e){return 4294967296*(e-(0|e))|0}for(var i=2,n=0;n<64;)e(i)&&(n<8&&(a[n]=s(t.pow(i,.5))),l[n]=s(t.pow(i,1/3)),n++),i++}();var c=[],d=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,i=s[0],n=s[1],r=s[2],o=s[3],a=s[4],d=s[5],h=s[6],u=s[7],m=0;m<64;m++){if(m<16)c[m]=0|e[t+m];else{var p=c[m-15],b=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,f=c[m-2],y=(f<<15|f>>>17)^(f<<13|f>>>19)^f>>>10;c[m]=b+c[m-7]+y+c[m-16]}var g=i&n^i&r^n&r,Z=(i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22),X=u+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&d^~a&h)+l[m]+c[m];u=h,h=d,d=a,a=o+X|0,o=r,r=n,n=i,i=X+(Z+g)|0}s[0]=s[0]+i|0,s[1]=s[1]+n|0,s[2]=s[2]+r|0,s[3]=s[3]+o|0,s[4]=s[4]+a|0,s[5]=s[5]+d|0,s[6]=s[6]+h|0,s[7]=s[7]+u|0},_doFinalize:function(){var e=this._data,s=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return s[n>>>5]|=128<<24-n%32,s[14+(n+64>>>9<<4)]=t.floor(i/4294967296),s[15+(n+64>>>9<<4)]=i,e.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});s.SHA256=r._createHelper(d),s.HmacSHA256=r._createHmacHelper(d)}(Math),e.SHA256}(p())),X.exports}var G=o(w());let v;function L(e){const t=e.sigBytes,s=e.words,i=new Uint8Array(t);let n=0,r=0;for(;n<t;){const e=s[r++];if(i[n++]=(4278190080&e)>>>24,n===t)break;if(i[n++]=(16711680&e)>>>16,n===t)break;if(i[n++]=(65280&e)>>>8,n===t)break;i[n++]=255&e}return i}function S(e){function t(e){const t=e.indexOf("{"),s=e.lastIndexOf("}");if(-1===t||-1===s||s<t)return e;const i=e.slice(0,t).replace(/\s+/g," ").replace(/\s\(/,"("),n=e.slice(t+1,s);return`${i.trim()}{${n.trim()}}`}let s=t(""+e);if(!s.startsWith("class")){const i=e.prototype;i&&(s+=Object.getOwnPropertyNames(i).map((e=>`${e}:${t(""+i[e])}`)).join(""))}return s}function x(e){return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function W(){return d.has("debug","hashing",!1)}v=globalThis.crypto&&globalThis.crypto.subtle&&"function"==typeof globalThis.crypto.subtle.digest?globalThis.crypto.subtle.digest.bind(globalThis.crypto.subtle):(e,t)=>{if("SHA-256"!==e)throw Error(`${K.libName}: only SHA-256 available`);const s=Z.create(t);return L(G(s)).buffer};let T={};const C=new TextEncoder;async function k(e){const t=C.encode(e),s=await async function(e){return 0===e.length?"47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU":x(await v("SHA-256",e))}(t);return T[s]={string:e,buffer:t},s}const V=[],I={};const P=new Set;function R(e,t={}){return e&&K.showMessage(e,{...t,level:"warning"})}function Y(e,t={}){return e&&K.showMessage(e,{...t,level:"status"})}function M(e,t,s="error"){console.error(`Error during ${e}`,t);const i=(t.stack||"").split("\n").filter((e=>!e.match(/croquet-.*\.min.js/))).join("\n");K.showMessage(`Error during ${e}: ${t.message}\n\n${i}`,{level:s,duration:"error"===s?1e4:void 0,stopOnFocus:!0})}const K={get libName(){return globalThis.__MULTISYNQ__?"Multisynq":"Croquet"},sessionURL:null,root:!1,sync:!1,messages:!1,badge:!1,stats:!1,qrcode:!1,makeWidgetDock(){},makeSessionWidgets(){},makeQRCanvas:()=>null,clearSessionMoniker(){},showSyncWait(e){},messageFunction:function(e,t={}){const s=t.level;console.log(`${"status"===s?"":s+": "} ${e}`)},showMessage:(e,t={})=>d.nomessages||!1===K.root||!1===K.messages||!K.messageFunction?("warning"===t.level&&console.warn(e),"error"===t.level&&console.error(e),null):K.messageFunction(e,t),isCroquetHost:e=>e.endsWith("croquet.io")||["localhost","127.0.0.1","[::1]"].includes(e)||e.endsWith("ngrok.io"),referrerURL:()=>"http://localhost/node.html",autoSession(e={key:"q"}){"string"==typeof e&&(e={key:e}),e||(e={});const t=e.key||"q";let s=d[t]||"";if(s)try{s=decodeURIComponent(s)}catch(e){}else s=Math.floor(Math.random()*36**10).toString(36),console.warn(`no ${K.libName} session name provided, using "${s}"`);d.has("debug","session")&&console.log(`${K.libName}.App.autoSession: "${s}"`);const i=Promise.resolve(s);return i[Symbol.toPrimitive]=()=>(console.warn(`Deprecated: ${K.libName}.App.autoSession() return value used directly. It returns a promise now!`),s),i},autoPassword(e={key:"pw"}){const t=e.key||"pw";let s=d[t]||"";if(!s){const e=require("crypto").randomBytes(16);s=x(e),console.warn(`no ${K.libName} session password provided, using "${s}"`)}d.has("debug","session")&&console.log(`${K.libName}.App.autoPassword: "${s}"`);const i=Promise.resolve(s);return i[Symbol.toPrimitive]=()=>(console.warn(`Deprecated: ${K.libName}.App.autoPassword() return value used directly. It returns a promise now!`),s),i}},H="#__vote";function N(e,t,s=null){let i="none";for(const n of["immediate","queued","oncePerFrame","oncePerFrameWhileSynced"])for(const r of e[n])r.for===t?null===s||r.unbound===s?e[n].delete(r):i="subscriber":"none"===i&&(i="others");return i}const z=globalThis.CROQUETVD=new class{constructor(){this.subscriptions={},this.subscribers=new Map,this.genericSubscriptions=!1,this.queuedEvents=[],this.perFrameEvents=new Map,this.perSyncedFrameEvents=new Map,this.subscriberIds=0,this.currentEvent=void 0,this.currentEventFromModel=!1}register(e){return"V"+ ++this.subscriberIds}deregister(e){}addSubscription(e,t,s,i,n){if(e.includes(":"))throw Error(`Invalid subscription scope "${e}" (must not contain ':')`);if("vote"===n)return void this.addSubscription(e,t+H,s,i,"immediate");"*"!==e&&"*"!==t||(this.genericSubscriptions=!0);const r=e+":"+t,o=i;o.for=s;let a=this.subscriptions[r];if(a||(a=this.subscriptions[r]={immediate:new Set,queued:new Set,oncePerFrame:new Set,oncePerFrameWhileSynced:new Set}),!a[n])throw Error(`Unknown subscribe() option: handling="${n}"`);a[n].add(o);let l=this.subscribers.get(s);l||this.subscribers.set(s,l=new Set),l.add(r)}removeSubscription(e,t,s,i=null){const n=e+":"+t,r=this.subscriptions[n];if(r){const e=N(r,s,i);if("none"===e&&delete this.subscriptions[n],"subscriber"!==e){const e=this.subscribers.get(s);e&&(e.delete(n),0===e.size&&this.subscribers.delete(s))}}t.endsWith(H)||this.removeSubscription(e,t+H,s)}removeAllSubscriptionsFor(e){const t=this.subscribers.get(e);if(t){for(const s of t){const t=this.subscriptions[s];if(t){"none"===N(t,e)&&delete this.subscriptions[s]}else console.error(`${K.libName}: topic ${s} not found in subscriptions table for ${e} during removeAllSubscriptionsFor()`)}this.subscribers.delete(e)}}subscriptionsFor(e){const t=this.subscriptions[e];if(!t&&!this.genericSubscriptions)return null;const s=[];let i=!!t;if(this.genericSubscriptions){const[t,n]=e.split(":");if(!(t.startsWith("__")&&t.endsWith("__")||n.startsWith("__")&&n.endsWith("__")))for(const e of["*:*",t+":*","*:"+n]){const t=this.subscriptions[e];t&&(s.push([t,e]),!i&&this.hasUserSubcription(t)&&(i=!0))}const r=!i;if(r)for(const e of s)e.push(r)}return t&&s.push([t,e]),0===s.length?null:s}hasUserSubcription(e){for(const t of["immediate","queued","oncePerFrame","oncePerFrameWhileSynced"])for(const s of e[t])if(!s.unbound.__CROQUET__)return!0;return!1}handleEvent(e,t,s=null){const i=this.subscriptionsFor(e);if(!i)return;const n=!!s;let r=0,o=0,a=0;for(const[l,c,d]of i)r+=l.queued.size,o+=l.oncePerFrame.size,a+=l.oncePerFrameWhileSynced.size,l.immediate.size>0&&(s||(s=e=>e()),s((()=>{for(const s of l.immediate){const i=this.currentEvent,r=this.currentEventFromModel,o=this.currentEventOnlyGeneric;this.currentEvent=e,this.currentEventFromModel=n,this.currentEventOnlyGeneric=d;try{s(t)}catch(e){console.error(e),console.warn(`${K.libName}: error "${e.message}" in "immediate" subscription ${c}`)}this.currentEvent=i,this.currentEventFromModel=r,this.currentEventOnlyGeneric=o}})));r>0&&this.queuedEvents.push({topic:e,data:t,fromModel:n}),o>0&&this.perFrameEvents.set(e,{data:t,fromModel:n}),a>0&&this.perSyncedFrameEvents.set(e,{data:t,fromModel:n})}processFrameEvents(e,t){let s=0;const i=(e,t,i,n)=>{const r=this.subscriptionsFor(t);if(!r)return;const o=this.currentEvent,a=this.currentEventFromModel;this.currentEvent=t,this.currentEventFromModel=n;for(const[n,o,a]of r){const r=this.currentEventOnlyGeneric;this.currentEventOnlyGeneric=a;for(const r of n[e]){try{r(i)}catch(s){console.error(s),console.warn(`${K.libName}: error "${s.message}" in "${e}" subscription ${t}`)}s++}this.currentEventOnlyGeneric=r}this.currentEvent=o,this.currentEventFromModel=a};for(const{topic:e,data:t,fromModel:s}of this.queuedEvents)i("queued",e,t,s);if(this.queuedEvents.length=0,e){for(const[e,{data:t,fromModel:s}]of this.perFrameEvents)i("oncePerFrame",e,t,s);if(this.perFrameEvents.clear(),t){for(const[e,{data:t,fromModel:s}]of this.perSyncedFrameEvents)i("oncePerFrameWhileSynced",e,t,s);this.perSyncedFrameEvents.clear()}for(const{topic:e,data:t,fromModel:s}of this.queuedEvents)i("queued",e,t,s);this.queuedEvents.length=0}return s}};let F={get subscribe(){return F={subscribe:d.has("debug","subscribe",!1)},F.subscribe}};class j{constructor(e){this.vm=e}register(e){return this.vm.registerModel(e)}deregister(e){this.vm.deregisterModel(e.id)}publish(e,t,s){this.vm.publishFromModel(s,e,t)}subscribe(e,t,s,i){return F.subscribe&&console.log(`Model.subscribe("${t}:${s}", ${e} ${(""+i).replace(/\([\s\S]*/,"")})`),this.vm.addSubscription(e,t,s,i)}unsubscribe(e,t,s,i="*"){F.subscribe&&console.log(`Model.unsubscribe(${t}:${s}", ${e} ${(""+i).replace(/\([\s\S]*/,"")})`),this.vm.removeSubscription(e,t,s,i)}unsubscribeAll(e){F.subscribe&&console.log(`Model.unsubscribeAll(${e} ${e.id})`),this.vm.removeAllSubscriptionsFor(e)}future(e,t,s,i){if(J&&J.equal(this))return this.vm.future(e,t,s,i);throw Error(`Model.future() called from outside: ${e}`)}cancelFuture(e,t){if(J&&J.equal(this))return this.vm.cancelFuture(e,t);throw Error(`Model.cancelFuture() called from outside: ${e}`)}random(){return this.vm.random()}now(){return this.vm.time}equal(e){return e instanceof j&&e.vm===this.vm}isViewRealm(){return!1}}class _{constructor(e){this.vd=z,this.vm=e,this.controller=e.controller}valid(){return this.vm===this.controller.vm}register(e){return z.register(e)}deregister(e){z.deregister(e)}publish(e,t,s){this.vm.publishFromView(s,e,t)}subscribe(e,t,s,i,n="queued"){F.subscribe&&console.log(`View[${t}].subscribe("${i}:${e}" ${s?s.name||(""+s).replace(/\([\s\S]*/,""):""+s} [${n}])`),z.addSubscription(i,e,t,s,n)}unsubscribe(e,t,s=null,i){F.subscribe&&console.log(`View[${t}].unsubscribe("${i}:${e}" ${s?s.name||(""+s).replace(/\([\s\S]*/,""):"*"})`),z.removeSubscription(i,e,t,s)}unsubscribeAll(e){F.subscribe&&console.log(`View[${e}].unsubscribeAll()`),z.removeAllSubscriptionsFor(e)}future(e,t){const s=this.vm;return new Proxy(e,{get(i,n){if("function"==typeof e[n]){return new Proxy(e[n],{apply(i,r,o){setTimeout((()=>{e.id&&E(s,(()=>e[n](...o)),!0)}),t)}})}throw Error("Tried to call "+n+"() on future of "+Object.getPrototypeOf(e).constructor.name+" which is not a function")}})}random(){return Math.random()}now(){return this.vm.time}externalNow(){return this.controller.reflectorTime}extrapolatedNow(){return this.controller.extrapolatedTime}isSynced(){return!!this.controller.synced}equal(e){return e instanceof _&&e.vm===this.vm}isViewRealm(){return!0}}let J=null;function U(e="Tried to execute code that requires realm outside of realm."){if(!J&&e)throw Error(e);return J}function Q(e,t){if(null!==J)throw Error("Can't switch realms from inside realm");try{return J=new j(e),t()}finally{J=null}}function E(e,t,s=!1){if(null!==J&&!s)throw Error("Can't switch realms from inside realm");const i=J;try{return J=new _(e),t()}finally{J=i}}var D=256,O=Math.pow(D,6),B=Math.pow(2,52),$=2*B,A=255;function q(e,t){var s=[];if((t=t||{}).entropy)throw new Error("this version of seedrandom does not support entropy");if(null==e&&!t.state)throw new Error("this version of seedrandom requires a seed");!function(e,t){var s,i=e+"",n=0;for(;n<i.length;)t[A&n]=A&(s^=19*t[A&n])+i.charCodeAt(n++);return r=t,String.fromCharCode.apply(0,r);var r}(se(e,3),s);var i=new ee(s),n=function(){for(var e=i.g(6),t=O,s=0;e<B;)e=(e+s)*D,t*=D,s=i.g(1);for(;e>=$;)e/=2,t/=2,s>>>=1;return(e+s)/t};return n.int32=function(){return 0|i.g(4)},n.quick=function(){return i.g(4)/4294967296},n.double=n,(t.pass||function(e,t){return t&&(t.S&&te(t,i),e.state=function(){return te(i,{})}),e})(n,t.state)}function ee(e){var t,s=e.length,i=this,n=0,r=i.i=i.j=0,o=i.S=[];for(s||(e=[s++]);n<D;)o[n]=n++;for(n=0;n<D;n++)o[n]=o[r=A&r+e[n%s]+(t=o[n])],o[r]=t;(i.g=function(e){for(var t,s=0,n=i.i,r=i.j,o=i.S;e--;)t=o[n=A&n+1],s=s*D+o[A&(o[n]=o[r=A&r+t])+(o[r]=t)];return i.i=n,i.j=r,s})(D)}function te(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function se(e,t){var s,i=[],n=typeof e;if(t&&"object"==n)for(s in e)try{i.push(se(e[s],t-1))}catch(e){}return i.length?i:"string"==n?e:e+"\0"}var ie=function(e){return e!=e},ne=Math.sqrt,re=.7853981633974483;var oe=function(e){var t,s;return 0===e?.16666666666666713:((e<0?-e:e)<=1?(t=e*(19.562619833175948+e*(e*(5.444622390564711+e*(.004253011369004428*e-.6019598008014124))-16.262479672107002))-8.198089802484825,s=e*(139.51056146574857+e*(e*(70.49610280856842+e*(1*e-14.740913729888538))-147.1791292232726))-49.18853881490881):(t=.004253011369004428+(e=1/e)*(e*(5.444622390564711+e*(e*(19.562619833175948+-8.198089802484825*e)-16.262479672107002))-.6019598008014124),s=1+e*(e*(70.49610280856842+e*(e*(139.51056146574857+-49.18853881490881*e)-147.1791292232726))-14.740913729888538)),t/s)};var ae=function(e){var t,s;return 0===e?.08333333333333809:((e<0?-e:e)<=1?(t=28.536655482610616+e*(e*(6.968710824104713+e*(.002967721961301243*e-.5634242780008963))-25.56901049652825),s=342.43986579130785+e*(e*(147.0656354026815+e*(1*e-21.947795316429207))-383.8770957603691)):(t=.002967721961301243+(e=1/e)*(e*(6.968710824104713+e*(28.536655482610616*e-25.56901049652825))-.5634242780008963),s=1+e*(e*(147.0656354026815+e*(342.43986579130785*e-383.8770957603691))-21.947795316429207)),t/s)};var le=function(e){var t,s,i,n,r;if(ie(e))return NaN;if(e>0?i=e:(t=!0,i=-e),i>1)return NaN;if(i>.625)n=(s=1-i)*ae(s),s=ne(s+s),r=re-s,r-=s=s*n-6123233995736766e-32,r+=re;else{if(i<1e-8)return e;r=i*(r=(s=i*i)*oe(s))+i}return t?-r:r};var ce=function(e){var t;return ie(e)||e<-1||e>1?NaN:e>.5?2*le(ne(.5-.5*e)):(t=re-le(e),t+=6123233995736766e-32,t+=re)};var de=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var he=function(){return de&&"symbol"==typeof Symbol.toStringTag},ue=Object.prototype.toString;var me=function(e){return ue.call(e)},pe=Object.prototype.hasOwnProperty;var be=function(e,t){return null!=e&&pe.call(e,t)},fe="function"==typeof Symbol?Symbol.toStringTag:"";var ye=function(e){var t,s,i;if(null==e)return ue.call(e);s=e[fe],t=be(e,fe);try{e[fe]=void 0}catch(t){return ue.call(e)}return i=ue.call(e),t?e[fe]=s:delete e[fe],i},ge=he()?ye:me,Ze="function"==typeof Uint32Array;var Xe=function(e){return Ze&&e instanceof Uint32Array||"[object Uint32Array]"===ge(e)},we=4294967295,Ge="function"==typeof Uint32Array?Uint32Array:null;var ve=function(){var e,t;if("function"!=typeof Ge)return!1;try{t=new Ge(t=[1,3.14,-3.14,we+1,we+2]),e=Xe(t)&&1===t[0]&&3===t[1]&&t[2]===we-2&&0===t[3]&&1===t[4]}catch(t){e=!1}return e},Le="function"==typeof Uint32Array?Uint32Array:null;var Se=function(){throw new Error("not implemented")},xe=ve()?Le:Se,We="function"==typeof Float64Array;var Te=function(e){return We&&e instanceof Float64Array||"[object Float64Array]"===ge(e)},Ce="function"==typeof Float64Array?Float64Array:null;var ke=function(){var e,t;if("function"!=typeof Ce)return!1;try{t=new Ce([1,3.14,-3.14,NaN]),e=Te(t)&&1===t[0]&&3.14===t[1]&&-3.14===t[2]&&t[3]!=t[3]}catch(t){e=!1}return e},Ve="function"==typeof Float64Array?Float64Array:null;var Ie=function(){throw new Error("not implemented")},Pe=ke()?Ve:Ie,Re="function"==typeof Uint8Array;var Ye=function(e){return Re&&e instanceof Uint8Array||"[object Uint8Array]"===ge(e)},Me="function"==typeof Uint8Array?Uint8Array:null;var Ke=function(){var e,t;if("function"!=typeof Me)return!1;try{t=new Me(t=[1,3.14,-3.14,256,257]),e=Ye(t)&&1===t[0]&&3===t[1]&&253===t[2]&&0===t[3]&&1===t[4]}catch(t){e=!1}return e},He="function"==typeof Uint8Array?Uint8Array:null;var Ne=function(){throw new Error("not implemented")},ze=Ke()?He:Ne,Fe="function"==typeof Uint16Array;var je=function(e){return Fe&&e instanceof Uint16Array||"[object Uint16Array]"===ge(e)},_e="function"==typeof Uint16Array?Uint16Array:null;var Je=function(){var e,t;if("function"!=typeof _e)return!1;try{t=new _e(t=[1,3.14,-3.14,65536,65537]),e=je(t)&&1===t[0]&&3===t[1]&&65533===t[2]&&0===t[3]&&1===t[4]}catch(t){e=!1}return e},Ue="function"==typeof Uint16Array?Uint16Array:null;var Qe,Ee=function(){throw new Error("not implemented")},De={uint16:Je()?Ue:Ee,uint8:ze};(Qe=new De.uint16(1))[0]=4660;var Oe=52===new De.uint8(Qe.buffer)[0],Be=!0===Oe?1:0,$e=new Pe(1),Ae=new xe($e.buffer);var qe=function(e){return $e[0]=e,Ae[Be]},et=!0===Oe?1:0,tt=new Pe(1),st=new xe(tt.buffer);var it=function(e,t){return tt[0]=e,st[et]=t>>>0,tt[0]},nt=it,rt=Number.POSITIVE_INFINITY,ot=Number.NEGATIVE_INFINITY,at=1023;var lt=function(e){return 0===e?.6666666666666735:.6666666666666735+e*(.3999999999940942+e*(.2857142874366239+e*(.22222198432149784+e*(.1818357216161805+e*(.15313837699209373+.14798198605116586*e)))))},ct=.6931471803691238,dt=1.9082149292705877e-10;var ht=function(e){var t,s,i,n,r,o,a,l,c,d;if(e<-1||ie(e))return NaN;if(-1===e)return ot;if(e===rt)return e;if(0===e)return e;if(d=1,(i=e<0?-e:e)<.41421356237309503){if(i<1.862645149230957e-9)return i<5551115123125783e-32?e:e-e*e*.5;e>-.2928932188134525&&(d=0,n=e,s=1)}return 0!==d&&(i<9007199254740992?(r=(d=((s=qe(c=1+e))>>20)-at)>0?1-(c-e):e-(c-1),r/=c):(d=((s=qe(c=e))>>20)-at,r=0),(s&=1048575)<434334?c=nt(c,1072693248|s):(d+=1,c=nt(c,1071644672|s),s=1048576-s>>2),n=c-1),t=.5*n*n,0===s?0===n?d*ct+(r+=d*dt):d*ct-((l=t*(1-.6666666666666666*n))-(d*dt+r)-n):(l=(a=(o=n/(2+n))*o)*lt(a),0===d?n-(t-o*(t+l)):d*ct-(t-(o*(t+l)+(d*dt+r))-n))},ut=.6931471805599453;var mt=function(e){return 0===e?.3999999999940942:.3999999999940942+e*(.22222198432149784+.15313837699209373*e)};var pt=function(e){return 0===e?.6666666666666735:.6666666666666735+e*(.2857142874366239+e*(.1818357216161805+.14798198605116586*e))},bt=.6931471803691238,ft=1.9082149292705877e-10,yt=1048575;var gt=function(e){var t,s,i,n,r,o,a,l,c,d,h;return 0===e?ot:ie(e)||e<0?NaN:(n=0,(s=qe(e))<1048576&&(n-=54,s=qe(e*=0x40000000000000)),s>=2146435072?e+e:(n+=(s>>20)-at|0,n+=(a=(s&=yt)+614244&1048576)>>20,o=(e=nt(e,s|1072693248^a))-1,(yt&2+s)<3?0===o?0===n?0:n*bt+n*ft:(r=o*o*(.5-.3333333333333333*o),0===n?o-r:n*bt-(r-n*ft-o)):(a=s-398458|0,l=440401-s|0,i=(d=(h=(c=o/(2+o))*c)*h)*mt(d),r=h*pt(d)+i,(a|=l)>0?(t=.5*o*o,0===n?o-(t-c*(t+r)):n*bt-(t-(c*(t+r)+n*ft)-o)):0===n?o-c*(o-r):n*bt-(c*(o-r)-n*ft-o))))};var Zt=function(e){var t;return ie(e)||e<1?NaN:1===e?0:e>=268435456?gt(e)+ut:e>2?gt(2*e-1/(e+ne(e*e-1))):ht((t=e-1)+ne(2*t+t*t))};var Xt=function(e){return e===rt||e===ot},wt=1/(1<<28);var Gt=function(e){var t,s,i;return ie(e)||Xt(e)?e:(e<0&&(e=-e,t=!0),i=e<wt?e:e>268435456?gt(e)+ut:e>2?gt(2*e+1/(ne(e*e+1)+e)):ht(e+(s=e*e)/(1+ne(1+s))),t?-i:i)},vt=1.5707963267948966;var Lt=function(e){return 0===e?-64.85021904942025:e*(e*(e*(-.8750608600031904*e-16.157537187333652)-75.00855792314705)-122.88666844901361)-64.85021904942025};var St=function(e){return 0===e?194.5506571482614:194.5506571482614+e*(485.3903996359137+e*(432.88106049129027+e*(165.02700983169885+e*(24.858464901423062+1*e))))},xt=6123233995736766e-32;var Wt=function(e){var t,s,i,n;return ie(e)||0===e?e:e===rt?vt:e===ot?-1.5707963267948966:(e<0&&(s=!0,e=-e),t=0,e>2.414213562373095?(i=vt,t=1,e=-1/e):e<=.66?i=0:(i=re,t=2,e=(e-1)/(e+1)),n=e*(n=(n=e*e)*Lt(n)/St(n))+e,2===t?n+=.5*xt:1===t&&(n+=xt),i+=n,s?-i:i)},Tt=1/(1<<28);var Ct,kt,Vt=function(e){var t,s;return ie(e)||e<-1||e>1?NaN:1===e?rt:-1===e?ot:(e<0&&(t=!0,e=-e),e<Tt?t?-e:e:(s=e<.5?.5*ht((s=e+e)+s*e/(1-e)):.5*ht((e+e)/(1-e)),t?-s:s))};!0===Oe?(Ct=1,kt=0):(Ct=0,kt=1);var It={HIGH:Ct,LOW:kt},Pt=new Pe(1),Rt=new xe(Pt.buffer),Yt=It.HIGH,Mt=It.LOW;var Kt=function(e,t){return Pt[0]=t,e[0]=Rt[Yt],e[1]=Rt[Mt],e};var Ht,Nt,zt=function(e,t){return 1===arguments.length?Kt([0,0],e):Kt(e,t)};!0===Oe?(Ht=1,Nt=0):(Ht=0,Nt=1);var Ft={HIGH:Ht,LOW:Nt},jt=new Pe(1),_t=new xe(jt.buffer),Jt=Ft.HIGH,Ut=Ft.LOW;var Qt=function(e,t){return _t[Jt]=e,_t[Ut]=t,jt[0]},Et=Qt,Dt=[0,0];var Ot=function(e,t){var s,i;return zt(Dt,e),s=Dt[0],s&=2147483647,i=qe(t),Et(s|=i&=2147483648,Dt[1])};var Bt=function(e){return!!(qe(e)>>>31)},$t=3.141592653589793;var At=function(e,t){var s;return ie(t)||ie(e)?NaN:Xt(t)?t===rt?Xt(e)?Ot($t/4,e):Ot(0,e):Xt(e)?Ot(3*$t/4,e):Ot($t,e):Xt(e)?Ot($t/2,e):0===e?t>=0&&!Bt(t)?Ot(0,e):Ot($t,e):0===t?Ot($t/2,e):(s=Wt(e/t),t<0?s<=0?s+$t:s-$t:s)},qt=22250738585072014e-324;var es=function(e){return 0===e?1.87595182427177:1.87595182427177+e*(e*(1.6214297201053545+e*(.14599619288661245*e-.758397934778766))-1.8849797954337717)},ts=2147483647;var ss=function(e){var t,s,i,n,r;return ie(e)||Xt(e)||0===e?e:(s=-2147483648&(i=qe(e)),i&=ts,r=0,e<qt?(r=0x40000000000000,t=qe(r*=e),r=Et(s|(t=(t&ts)/3+696219795),0)):r=nt(r,s|(t=i/3+715094163)),r*=es(n=r*r*(r/e)),t=qe(r),r=Et(t+1,0),r+=r*(n=((n=e/(r*r))-r)/(r+r+n)))},is=ss;var ns=function(e){return 0===e?.0416666666666666:.0416666666666666+e*(2480158728947673e-20*e-.001388888888887411)};var rs=function(e){return 0===e?-2.7557314351390663e-7:e*(2.087572321298175e-9+-11359647557788195e-27*e)-2.7557314351390663e-7};var os=function(e,t){var s,i,n,r;return n=(r=e*e)*r,i=r*ns(r),i+=n*n*rs(r),(n=1-(s=.5*r))+(1-n-s+(r*i-e*t))},as=-.16666666666666632;var ls=function(e,t){var s,i,n;return s=.00833333333332249+(n=e*e)*(27557313707070068e-22*n-.0001984126982985795)+n*(n*n)*(1.58969099521155e-10*n-2.5050760253406863e-8),i=n*e,0===t?e+i*(as+n*s):e-(n*(.5*t-i*s)-t-i*as)},cs=!0===Oe?0:1,ds=new Pe(1),hs=new xe(ds.buffer);var us=function(e){return ds[0]=e,hs[cs]},ms=Math.floor;var ps=function(e){return e<0?-e:0===e?0:e};var bs=function(e,t){return ie(t)||Xt(t)?(e[0]=t,e[1]=0,e):0!==t&&ps(t)<qt?(e[0]=4503599627370496*t,e[1]=-52,e):(e[0]=t,e[1]=0,e)};var fs=function(e,t){return 1===arguments.length?bs([0,0],e):bs(e,t)};var ys=function(e){var t=qe(e);return(t=(2146435072&t)>>>20)-at|0},gs=ys,Zs=[0,0],Xs=[0,0];var ws=function(e,t){var s,i;return 0===e||ie(e)||Xt(e)?e:(fs(Zs,e),t+=Zs[1],(t+=gs(e=Zs[0]))<-1074?Ot(0,e):t>1023?e<0?ot:rt:(t<=-1023?(t+=52,i=2220446049250313e-31):i=1,zt(Xs,e),s=Xs[0],s&=2148532223,i*Et(s|=t+at<<20,Xs[1])))},Gs=ws,vs=[10680707,7228996,1387004,2578385,16069853,12639074,9804092,4427841,16666979,11263675,12935607,2387514,4345298,14681673,3074569,13734428,16653803,1880361,10960616,8533493,3062596,8710556,7349940,6258241,3772886,3769171,3798172,8675211,12450088,3874808,9961438,366607,15675153,9132554,7151469,3571407,2607881,12013382,4155038,6285869,7677882,13102053,15825725,473591,9065106,15363067,6271263,9264392,5636912,4652155,7056368,13614112,10155062,1944035,9527646,15080200,6658437,6231200,6832269,16767104,5075751,3212806,1398474,7579849,6349435,12618859],Ls=[1.570796251296997,7.549789415861596e-8,5390302529957765e-30,3282003415807913e-37,1270655753080676e-44,12293330898111133e-52,27337005381646456e-60,21674168387780482e-67],Ss=16777216,xs=5.960464477539063e-8,Ws=Vs(new Array(20)),Ts=Vs(new Array(20)),Cs=Vs(new Array(20)),ks=Vs(new Array(20));function Vs(e){var t,s=e.length;for(t=0;t<s;t++)e[t]=0;return e}function Is(e,t,s,i,n,r,o,a,l){var c,d,h,u,m,p,b,f,y;for(u=r,y=i[s],f=s,m=0;f>0;m++)d=xs*y|0,ks[m]=y-Ss*d|0,y=i[f-1]+d,f-=1;if(y=Gs(y,n),y-=8*ms(.125*y),y-=b=0|y,h=0,n>0?(b+=m=ks[s-1]>>24-n,ks[s-1]-=m<<24-n,h=ks[s-1]>>23-n):0===n?h=ks[s-1]>>23:y>=.5&&(h=2),h>0){for(b+=1,c=0,m=0;m<s;m++)f=ks[m],0===c?0!==f&&(c=1,ks[m]=16777216-f):ks[m]=16777215-f;if(n>0)switch(n){case 1:ks[s-1]&=8388607;break;case 2:ks[s-1]&=4194303}2===h&&(y=1-y,0!==c&&(y-=Gs(1,n)))}if(0===y){for(f=0,m=s-1;m>=r;m--)f|=ks[m];if(0===f){for(p=1;0===ks[r-p];p++);for(m=s+1;m<=s+p;m++){for(l[a+m]=vs[o+m],d=0,f=0;f<=a;f++)d+=e[f]*l[a+(m-f)];i[m]=d}return Is(e,t,s+=p,i,n,r,o,a,l)}}if(0===y)for(s-=1,n-=24;0===ks[s];)s-=1,n-=24;else(y=Gs(y,-n))>=Ss?(d=xs*y|0,ks[s]=y-Ss*d|0,n+=24,ks[s+=1]=d):ks[s]=0|y;for(d=Gs(1,n),m=s;m>=0;m--)i[m]=d*ks[m],d*=xs;for(m=s;m>=0;m--){for(d=0,p=0;p<=u&&p<=s-m;p++)d+=Ls[p]*i[m+p];Cs[s-m]=d}for(d=0,m=s;m>=0;m--)d+=Cs[m];for(t[0]=0===h?d:-d,d=Cs[0]-d,m=1;m<=s;m++)d+=Cs[m];return t[1]=0===h?d:-d,7&b}var Ps=function(e,t,s,i){var n,r,o,a,l,c,d;for((r=(s-3)/24|0)<0&&(r=0),a=s-24*(r+1),c=r-(o=i-1),d=o+4,l=0;l<=d;l++)Ws[l]=c<0?0:vs[c],c+=1;for(l=0;l<=4;l++){for(n=0,c=0;c<=o;c++)n+=e[c]*Ws[o+(l-c)];Ts[l]=n}return Is(e,t,4,Ts,a,4,r,o,Ws)},Rs=Math.round;var Ys=function(e,t,s){var i,n,r,o,a;return r=e-1.5707963267341256*(i=Rs(.6366197723675814*e)),o=6077100506506192e-26*i,a=t>>20,s[0]=r-o,a-(qe(s[0])>>20&2047)>16&&(o=20222662487959506e-37*i-((n=r)-(r=n-(o=6077100506303966e-26*i))-o),s[0]=r-o,a-(qe(s[0])>>20&2047)>49&&(o=84784276603689e-45*i-((n=r)-(r=n-(o=20222662487111665e-37*i))-o),s[0]=r-o)),s[1]=r-s[0]-o,i},Ms=1.5707963267341256,Ks=6077100506506192e-26,Hs=2*Ks,Ns=3*Ks,zs=4*Ks,Fs=new Array(3),js=new Array(2);var _s=function(e,t){var s,i,n,r,o,a,l;if((n=2147483647&qe(e))<=1072243195)return t[0]=e,t[1]=0,0;if(n<=1074752122)return 598523==(1048575&n)?Ys(e,n,t):n<=1073928572?e>0?(l=e-Ms,t[0]=l-Ks,t[1]=l-t[0]-Ks,1):(l=e+Ms,t[0]=l+Ks,t[1]=l-t[0]+Ks,-1):e>0?(l=e-2*Ms,t[0]=l-Hs,t[1]=l-t[0]-Hs,2):(l=e+2*Ms,t[0]=l+Hs,t[1]=l-t[0]+Hs,-2);if(n<=1075594811)return n<=1075183036?1074977148===n?Ys(e,n,t):e>0?(l=e-3*Ms,t[0]=l-Ns,t[1]=l-t[0]-Ns,3):(l=e+3*Ms,t[0]=l+Ns,t[1]=l-t[0]+Ns,-3):1075388923===n?Ys(e,n,t):e>0?(l=e-4*Ms,t[0]=l-zs,t[1]=l-t[0]-zs,4):(l=e+4*Ms,t[0]=l+zs,t[1]=l-t[0]+zs,-4);if(n<1094263291)return Ys(e,n,t);if(n>=2146435072)return t[0]=NaN,t[1]=NaN,0;for(s=us(e),l=Et(n-((i=(n>>20)-1046)<<20),s),o=0;o<2;o++)Fs[o]=0|l,l=16777216*(l-Fs[o]);for(Fs[2]=l,r=3;0===Fs[r-1];)r-=1;return a=Ps(Fs,js,i,r),e<0?(t[0]=-js[0],t[1]=-js[1],-a):(t[0]=js[0],t[1]=js[1],a)},Js=_s,Us=[0,0];var Qs=function(e){var t;if(t=qe(e),(t&=2147483647)<=1072243195)return t<1044381696?1:os(e,0);if(t>=2146435072)return NaN;switch(3&Js(e,Us)){case 0:return os(Us[0],Us[1]);case 1:return-ls(Us[0],Us[1]);case 2:return-os(Us[0],Us[1]);default:return ls(Us[0],Us[1])}},Es=Math.ceil;var Ds=function(e){return e<0?Es(e):ms(e)};var Os=function(e){return 0===e?.16666666666666602:.16666666666666602+e*(e*(6613756321437934e-20+e*(4.1381367970572385e-8*e-16533902205465252e-22))-.0027777777777015593)};var Bs=function(e,t,s){var i,n,r;return r=(i=e-t)-(n=i*i)*Os(n),Gs(1-(t-i*r/(2-r)-e),s)},$s=1.4426950408889634,As=1/(1<<28);var qs=function(e){var t;return ie(e)||e===rt?e:e===ot?0:e>709.782712893384?rt:e<-745.1332191019411?0:e>-3.725290298461914e-9&&e<As?1+e:(t=Ds(e<0?$s*e-.5:$s*e+.5),Bs(e-.6931471803691238*t,1.9082149292705877e-10*t,t))};var ei=function(e){return ie(e)?e:(e<0&&(e=-e),e>21?qs(e)/2:(qs(e)+qs(-e))/2)};var ti=function(e){return 0===e?-.03333333333333313:e*(.0015873015872548146+e*(e*(4008217827329362e-21+-2.0109921818362437e-7*e)-793650757867488e-19))-.03333333333333313},si=.6931471803691238,ii=1.9082149292705877e-10,ni=1.4426950408889634;var ri=function(e){var t,s,i,n,r,o,a,l,c,d,h,u;if(e===rt||ie(e))return e;if(e===ot)return-1;if(0===e)return e;if(e<0?(s=!0,a=-e):(s=!1,a=e),a>=38.816242111356935){if(s)return-1;if(a>=709.782712893384)return rt}if(r=0|qe(a),a>.34657359027997264)a<1.0397207708399179?s?(i=e+si,n=-1.9082149292705877e-10,u=-1):(i=e-si,n=ii,u=1):(u=s?ni*e-.5:ni*e+.5,i=e-(d=u|=0)*si,n=d*ii),c=i-(e=i-n)-n;else{if(r<1016070144)return e;u=0}return h=(l=e*(t=.5*e))*(((o=1+l*ti(l))-(d=3-o*t))/(6-e*d)),0===u?e-(e*h-l):(h=e*(h-c)-c,h-=l,-1===u?.5*(e-h)-.5:1===u?e<-.25?-2*(h-(e+.5)):1+2*(e-h):u<=-2||u>56?(i=qe(a=1-(h-e))+(u<<20)|0,(a=nt(a,i))-1):(d=1,u<20?a=(d=nt(d,i=1072693248-(2097152>>u)|0))-(h-e):(a=e-(h+(d=nt(d,i=at-u<<20))),a+=1),i=qe(a)+(u<<20)|0,nt(a,i)))},oi=!0===Oe?0:1,ai=new Pe(1),li=new xe(ai.buffer);var ci=function(e,t){return ai[0]=e,li[oi]=t>>>0,ai[0]},di=ci;var hi=function(e){return 0===e?.3999999999940942:.3999999999940942+e*(.22222198432149784+.15313837699209373*e)};var ui=function(e){return 0===e?.6666666666666735:.6666666666666735+e*(.2857142874366239+e*(.1818357216161805+.14798198605116586*e))},mi=1048575;var pi=function(e){var t,s,i,n,r,o,a,l,c,d;return i=qe(e),n=e-1,(mi&2+i)<3?0===n?0:n*n*(.3333333333333333*n-.5):(c=(i&=mi)-398458|0,d=440401-i|0,s=(l=(o=(r=n/(2+n))*r)*o)*hi(l),a=o*ui(l)+s,(c|=d)>0?r*((t=.5*n*n)+a)-t:r*(a-n))},bi=.4342944818781689;var fi=function(e){var t,s,i,n,r,o,a;return ie(e)||e<0?NaN:0===e?ot:(r=0,(s=qe(e))<1048576&&(r-=54,s=qe(e*=0x40000000000000)),s>=2146435072?e+e:(r+=(s>>20)-at|0,e=nt(e,(s&=1048575)|1072693248^(n=s+614244&1048576)),o=r+=n>>20,i=pi(e),a=3694239077158931e-28*o+25082946711645275e-27*((e-=1)+i),(a+=(e-(t=di(e,0))+i)*bi+t*bi)+.30102999566361177*o))};var yi=function(e){return 0===e?.3999999999940942:.3999999999940942+e*(.22222198432149784+.15313837699209373*e)};var gi=function(e){return 0===e?.6666666666666735:.6666666666666735+e*(.2857142874366239+e*(.1818357216161805+.14798198605116586*e))},Zi=1048575;var Xi=function(e){var t,s,i,n,r,o,a,l,c,d;return i=qe(e),n=e-1,(Zi&2+i)<3?0===n?0:n*n*(.3333333333333333*n-.5):(c=(i&=Zi)-398458|0,d=440401-i|0,s=(l=(o=(r=n/(2+n))*r)*o)*yi(l),a=o*gi(l)+s,(c|=d)>0?r*((t=.5*n*n)+a)-t:r*(a-n))},wi=1.4426950407214463,Gi=[0,0];var vi=function(e){var t,s,i,n,r;if(ie(e)||e<0)return NaN;if(zt(Gi,e),r=0,(s=Gi[0])<1048576){if(!(2147483647&s|Gi[1]))return ot;r-=54,s=qe(e*=0x40000000000000)}return s>=2146435072?e+e:(r+=(s>>20)-at|0,e=nt(e,(s&=1048575)|1072693248^(n=s+614244&1048576)),r+=n>>20,i=Xi(e),1.6751713164886512e-10*((e-=1)+i)+(e-(t=di(e,0))+i)*wi+t*wi+r)},Li=[0,0];var Si=function(e){var t;if(t=qe(e),(t&=2147483647)<=1072243195)return t<1045430272?e:ls(e,0);if(t>=2146435072)return NaN;switch(3&Js(e,Li)){case 0:return ls(Li[0],Li[1]);case 1:return os(Li[0],Li[1]);case 2:return-ls(Li[0],Li[1]);default:return-os(Li[0],Li[1])}};var xi=function(e){var t,s;return 0===e?.16666666666666666:((e<0?-e:e)<=1?(t=e*(e*(-.789474443963537*e-163.72585752598383)-11561.443576500522)-351754.9648081514,s=e*(36157.827983443196+e*(1*e-277.7110814206028))-2110529.7888489086):(t=(e=1/e)*(e*(-351754.9648081514*e-11561.443576500522)-163.72585752598383)-.789474443963537,s=1+e*(e*(36157.827983443196+-2110529.7888489086*e)-277.7110814206028)),t/s)},Wi=709.782712893384,Ti=Wi+ut,Ci=Wi-ut;var ki=function(e){var t;return 0===e?e:(t=ps(e),e>Ti||e<-709.089565712824?e>0?rt:ot:t>1?t>=Ci?(t=qs(.5*t),t*=.5*t,e<0&&(t=-t),t):(t=.5*(t=qs(t))-.5/t,e<0&&(t=-t),t):e+e*(t*=t)*xi(t))};var Vi=function(e){return 0===e?.13333333333320124:.13333333333320124+e*(.021869488294859542+e*(.0035920791075913124+e*(.0005880412408202641+e*(7817944429395571e-20+-18558637485527546e-21*e))))};var Ii=function(e){return 0===e?.05396825397622605:.05396825397622605+e*(.0088632398235993+e*(.0014562094543252903+e*(.0002464631348184699+e*(7140724913826082e-20+2590730518636337e-20*e))))};var Pi=function(e,t,s){var i,n,r,o,a,l,c,d,h;return(n=2147483647&(i=qe(e)))>=1072010280&&(e<0&&(e=-e,t=-t),e=(h=.7853981633974483-e)+(d=3061616997868383e-32-t),t=0),o=t+(h=e*e)*((a=h*e)*((o=Vi(d=h*h))+(c=h*Ii(d)))+t),d=e+(o+=.3333333333333341*a),n>=1072010280?(1-(i>>30&2))*((c=s)-2*(e-(d*d/(d+c)-o))):1===s?d:(di(h=d,0),c=o-(h-e),di(l=r=-1/d,0),l+r*((a=1+l*h)+l*c))},Ri=[0,0];var Yi=function(e){var t,s;return t=qe(e),(t&=2147483647)<=1072243195?t<1044381696?e:Pi(e,0,1):t>=2146435072?NaN:(s=Js(e,Ri),Pi(Ri[0],Ri[1],1-((1&s)<<1)))};var Mi=function(e){var t,s;return 0===e?-.3333333333333332:((e<0?-e:e)<=1?(t=e*(e*(0*e-.9643991794250523)-99.28772310019185)-1614.6876844170845,s=4844.063053251255+e*(2235.4883906010045+e*(112.81167849163293+1*e))):(t=0+(e=1/e)*(e*(-1614.6876844170845*e-99.28772310019185)-.9643991794250523),s=1+e*(112.81167849163293+e*(2235.4883906010045+4844.063053251255*e))),t/s)};var Ki=function(e){var t,s;if((s=ps(e))>44.014845965556525)return e<0?-1:1;if(s>=.625)s=1-2/((t=qs(2*s))+1),e<0&&(s=-s);else{if(0===e)return e;s=e+e*(t=e*e)*Mi(t)}return s};void 0===globalThis.CroquetMath&&(globalThis.CroquetMath={}),Object.assign(globalThis.CroquetMath,{acos:ce,acosh:Zt,asin:le,asinh:Gt,atan:Wt,atanh:Vt,atan2:At,cbrt:is,cos:Qs,cosh:ei,exp:qs,expm1:ri,log:gt,log1p:ht,log10:fi,log2:vi,sin:Si,sinh:ki,tan:Yi,tanh:Ki});const Hi=Math.pow;function Ni(e){return e===1/0||e===-1/0}globalThis.CroquetMath.pow=(e,t)=>{if(isNaN(e)||isNaN(t))return NaN;if(Ni(e)||Ni(t))return Hi(e,t);if(0===e||0===t)return Hi(e,t);if(e<0&&!function(e){return Number.isInteger(e)}(t))return NaN;if(1===t)return e;if(2===t)return e*e;if(3===t)return e*e*e;if(4===t)return e*e*e*e;let s=1;e<0&&(e*=-1,s=Hi(-1,t));return globalThis.CroquetMath.exp(globalThis.CroquetMath.log(e)*t)*s};class zi extends s{poll(){const e=super.poll();return this.array[this.size]=null,e}asArray(){const e=[];return this.forEach((t=>e.push(t))),e}asUnsortedArray(){return this.array.slice(0,this.size)}}let Fi=!1,ji=Ji(0),_i={};function Ji(e){return{start:e,total:0,items:{},users:0,backlog:0,network:0,latency:0,activity:1e3,connected:Fi}}const Ui=[],Qi={},Ei={animationFrame(e,t={}){!function(e){ji.total=e-ji.start}(e),ji=Ji(e);for(const[e,s]of Object.entries(t))this[e](s)},begin(e){const t=performance.now();ji.items[e]=(ji.items[e]||0)-t;const s=Ui[Ui.length-1];return s&&(ji.items[s]+=t),Ui.push(e),t},end(e){const t=performance.now();ji.items[e]+=t;const s=Ui.pop();if(s!==e)throw Error(`Unmatched stats calls: expected end("${s}"), got end("${e}")`);const i=Ui[Ui.length-1];return i&&(ji.items[i]-=t),t},backlog(e){ji.backlog=Math.max(e,ji.backlog)},starvation(e){ji.network=e},latency(e){ji.latency=e},activity(e){ji.activity=e},users(e){ji.users=e},connected(e){ji.connected=Fi=e},networkTraffic:Qi,addNetworkTraffic(e,t,s=!1){Qi[e]=(Qi[e]||0)+t,s&&(Qi[`audit_${e}`]=(Qi[`audit_${e}`]||0)+t)},resetAuditStats(){for(const e in Qi)e.startsWith("audit_")&&(Qi[e]=0)},perSecondTally(e={}){if(globalThis.logMessageStats)for(const[t,s]of Object.entries(e))_i[t]=(_i[t]||0)+s},stepSession(e,t=!1){const s=Math.floor(Date.now()/1e3);if(!globalThis.logMessageStats)return _i={second:s},null;let i=null;if(s!==_i.second){if(_i.second&&t&&(_i.requestedMessages||_i.sentMessagesTotal)){i={..._i};const e=s-_i.second;1!==e&&(i.sampleSeconds=e),i.sentBundles&&(i.averageDelay=Math.round(10*i.sendDelay/i.sentMessagesTotal)/10,i.averageBundlePayload=Math.round(i.sentBundlePayload/i.sentBundles)),delete i.second,delete i.sendDelay,delete i.sentBundlePayload}_i={second:s}}return i}};var Di,Oi={exports:{}};function Bi(){return Di||(Di=1,Oi.exports=function(e){return function(){var t=e,s=t.lib.WordArray;function i(e,t,i){for(var n=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2|i[e.charCodeAt(o)]>>>6-o%4*2;n[r>>>2]|=a<<24-r%4*8,r++}return s.create(n,r)}t.enc.Base64={stringify:function(e){var t=e.words,s=e.sigBytes,i=this._map;e.clamp();for(var n=[],r=0;r<s;r+=3)for(var o=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;a<4&&r+.75*a<s;a++)n.push(i.charAt(o>>>6*(3-a)&63));var l=i.charAt(64);if(l)for(;n.length%4;)n.push(l);return n.join("")},parse:function(e){var t=e.length,s=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var r=0;r<s.length;r++)n[s.charCodeAt(r)]=r}var o=s.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return i(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),e.enc.Base64}(p())),Oi.exports}var $i,Ai=o(Bi()),qi=p(),en={exports:{}};var tn,sn=($i||($i=1,en.exports=function(e){return e.enc.Utf8}(p())),en.exports),nn=o(sn),rn={exports:{}},on={exports:{}};function an(){return tn||(tn=1,on.exports=function(e){!function(){var t=e,s=t.lib.Base,i=t.enc.Utf8;t.algo.HMAC=s.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=i.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),o=this._iKey=t.clone(),a=r.words,l=o.words,c=0;c<s;c++)a[c]^=1549556828,l[c]^=909522486;r.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,s=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(s))}})}()}(p())),on.exports}var ln;var cn,dn=(ln||(ln=1,rn.exports=function(e){return function(){var t=e,s=t.lib,i=s.Base,n=s.WordArray,r=t.algo,o=r.SHA256,a=r.HMAC,l=r.PBKDF2=i.extend({cfg:i.extend({keySize:4,hasher:o,iterations:25e4}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=this.cfg,i=a.create(s.hasher,e),r=n.create(),o=n.create([1]),l=r.words,c=o.words,d=s.keySize,h=s.iterations;l.length<d;){var u=i.update(t).finalize(o);i.reset();for(var m=u.words,p=m.length,b=u,f=1;f<h;f++){b=i.finalize(b),i.reset();for(var y=b.words,g=0;g<p;g++)m[g]^=y[g]}r.concat(u),c[0]++}return r.sigBytes=4*d,r}});t.PBKDF2=function(e,t,s){return l.create(s).compute(e,t)}}(),e.PBKDF2}(p(),w(),an())),rn.exports),hn=o(dn),un={exports:{}},mn={exports:{}};function pn(){return cn||(cn=1,mn.exports=function(e){return function(t){var s=e,i=s.lib,n=i.WordArray,r=i.Hasher,o=s.algo,a=[];!function(){for(var e=0;e<64;e++)a[e]=429496