@clockworkdog/cogs-client 3.0.0-alpha.5 → 3.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(T,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(T=typeof globalThis<"u"?globalThis:T||self,q(T.COGS={}))})(this,function(T){"use strict";var q=(e=>(e.Setup="setup",e.Preshow="pre-show",e.InProgress="in progress",e.Finished="finished",e))(q||{});/*! *****************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
4
|
this file except in compliance with the License. You may obtain a copy of the
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
13
|
and limitations under the License.
|
|
14
|
-
***************************************************************************** */var Se=function(e,t){return Se=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var
|
|
14
|
+
***************************************************************************** */var Se=function(e,t){return Se=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var r in o)o.hasOwnProperty(r)&&(n[r]=o[r])},Se(e,t)};function He(e,t){Se(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function dn(e){var t=typeof Symbol=="function"&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function pn(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var o=n.call(e),r,a=[],c;try{for(;(t===void 0||t-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(l){c={error:l}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(c)throw c.error}}return a}function fn(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(pn(arguments[t]));return e}var Je=function(){function e(t,n){this.target=n,this.type=t}return e}(),hn=function(e){He(t,e);function t(n,o){var r=e.call(this,"error",o)||this;return r.message=n.message,r.error=n,r}return t}(Je),_n=function(e){He(t,e);function t(n,o,r){n===void 0&&(n=1e3),o===void 0&&(o="");var a=e.call(this,"close",r)||this;return a.wasClean=!0,a.code=n,a.reason=o,a}return t}(Je);/*!
|
|
15
15
|
* Reconnecting WebSocket
|
|
16
16
|
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|
|
17
17
|
* https://github.com/pladaria/reconnecting-websocket
|
|
18
18
|
* License MIT
|
|
19
|
-
*/var _n=function(){if(typeof WebSocket<"u")return WebSocket},mn=function(e){return typeof e<"u"&&!!e&&e.CLOSING===2},F={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},vn=function(){function e(t,n,o){var i=this;o===void 0&&(o={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(a){i._debug("open event");var c=i._options.minUptime,l=c===void 0?F.minUptime:c;clearTimeout(i._connectTimeout),i._uptimeTimeout=setTimeout(function(){return i._acceptOpen()},l),i._ws.binaryType=i._binaryType,i._messageQueue.forEach(function(p){return i._ws.send(p)}),i._messageQueue=[],i.onopen&&i.onopen(a),i._listeners.open.forEach(function(p){return i._callEventListener(a,p)})},this._handleMessage=function(a){i._debug("message event"),i.onmessage&&i.onmessage(a),i._listeners.message.forEach(function(c){return i._callEventListener(a,c)})},this._handleError=function(a){i._debug("error event",a.message),i._disconnect(void 0,a.message==="TIMEOUT"?"timeout":void 0),i.onerror&&i.onerror(a),i._debug("exec error listeners"),i._listeners.error.forEach(function(c){return i._callEventListener(a,c)}),i._connect()},this._handleClose=function(a){i._debug("close event"),i._clearTimeouts(),i._shouldReconnect&&i._connect(),i.onclose&&i.onclose(a),i._listeners.close.forEach(function(c){return i._callEventListener(a,c)})},this._url=t,this._protocols=n,this._options=o,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(t){this._binaryType=t,this._ws&&(this._ws.binaryType=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){var t=this._messageQueue.reduce(function(n,o){return typeof o=="string"?n+=o.length:o instanceof Blob?n+=o.size:n+=o.byteLength,n},0);return t+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(t,n){if(t===void 0&&(t=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(t,n)},e.prototype.reconnect=function(t,n){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(t,n),this._connect())},e.prototype.send=function(t){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",t),this._ws.send(t);else{var n=this._options.maxEnqueuedMessages,o=n===void 0?F.maxEnqueuedMessages:n;this._messageQueue.length<o&&(this._debug("enqueue",t),this._messageQueue.push(t))}},e.prototype.addEventListener=function(t,n){this._listeners[t]&&this._listeners[t].push(n)},e.prototype.dispatchEvent=function(t){var n,o,i=this._listeners[t.type];if(i)try{for(var a=ln(i),c=a.next();!c.done;c=a.next()){var l=c.value;this._callEventListener(t,l)}}catch(p){n={error:p}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}return!0},e.prototype.removeEventListener=function(t,n){this._listeners[t]&&(this._listeners[t]=this._listeners[t].filter(function(o){return o!==n}))},e.prototype._debug=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this._options.debug&&console.log.apply(console,pn(["RWS>"],t))},e.prototype._getNextDelay=function(){var t=this._options,n=t.reconnectionDelayGrowFactor,o=n===void 0?F.reconnectionDelayGrowFactor:n,i=t.minReconnectionDelay,a=i===void 0?F.minReconnectionDelay:i,c=t.maxReconnectionDelay,l=c===void 0?F.maxReconnectionDelay:c,p=0;return this._retryCount>0&&(p=a*Math.pow(o,this._retryCount-1),p>l&&(p=l)),this._debug("next delay",p),p},e.prototype._wait=function(){var t=this;return new Promise(function(n){setTimeout(n,t._getNextDelay())})},e.prototype._getNextUrl=function(t){if(typeof t=="string")return Promise.resolve(t);if(typeof t=="function"){var n=t();if(typeof n=="string")return Promise.resolve(n);if(n.then)return n}throw Error("Invalid URL")},e.prototype._connect=function(){var t=this;if(!(this._connectLock||!this._shouldReconnect)){this._connectLock=!0;var n=this._options,o=n.maxRetries,i=o===void 0?F.maxRetries:o,a=n.connectionTimeout,c=a===void 0?F.connectionTimeout:a,l=n.WebSocket,p=l===void 0?_n():l;if(this._retryCount>=i){this._debug("max retries reached",this._retryCount,">=",i);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!mn(p))throw Error("No valid WebSocket class provided");this._wait().then(function(){return t._getNextUrl(t._url)}).then(function(h){t._closeCalled||(t._debug("connect",{url:h,protocols:t._protocols}),t._ws=t._protocols?new p(h,t._protocols):new p(h),t._ws.binaryType=t._binaryType,t._connectLock=!1,t._addListeners(),t._connectTimeout=setTimeout(function(){return t._handleTimeout()},c))})}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new fn(Error("TIMEOUT"),this))},e.prototype._disconnect=function(t,n){if(t===void 0&&(t=1e3),this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(t,n),this._handleClose(new hn(t,n,this))}catch{}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(t,n){"handleEvent"in n?n.handleEvent(t):n(t)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();const Je=12095;function Ye(e){const t=typeof window<"u"?window.location:void 0,n=`/assets/${encodeURIComponent(e)}`;return`${t?.protocol}//${t?.hostname}:${Je}${n}`}async function gn(e){const t=await fetch(e);return URL.createObjectURL(new Blob([await t.arrayBuffer()]))}class yn{_items;#e=new EventTarget;constructor(t){this._items={...t}}handleDataStoreItemsMessage(t){this._items={...this._items,...t.items},Object.entries(t.items).forEach(([n,o])=>{this.dispatchEvent(new Ae(n,o))}),this.dispatchEvent(new Te(t.items))}get items(){return this._items}getItem(t){return this._items[t]}setItems(t){return this._items={...this._items,...t},Object.entries(t).forEach(([n,o])=>{this.dispatchEvent(new Ae(n,o))}),this.dispatchEvent(new Te(t)),this}addEventListener(t,n,o){this.#e.addEventListener(t,n,o)}removeEventListener(t,n,o){this.#e.removeEventListener(t,n,o)}dispatchEvent(t){this.#e.dispatchEvent(t)}}class Ae extends Event{constructor(t,n){super("item"),this.key=t,this.value=n}_cogsConnectionEventType="item"}class Te extends Event{constructor(t){super("items"),this.items=t}_cogsConnectionEventType="item"}const oe=globalThis.Date;function bn(e){const t=e-oe.now();function n(...i){return i.length===0?new oe(n.now()):new oe(...i)}const o=Object.getOwnPropertyDescriptors(oe);Object.defineProperties(n,o),n.now=function(){return oe.now()+t},globalThis.Date=n}let wn=0;function En(){return++wn}const kn=5,Cn=1e4;function Sn({interval:e,send:t,onChange:n=bn,syncSampleSize:o=kn,syncRequestTimeout:i=Cn}){const a={};async function c(){const y=[];for(let s=0;s<o;s++){const u=new Promise(d=>{const f=En(),v=Date.now(),_=performance.now();t({timesync:{id:f}});const w=(E,k)=>d({sentAt:_,receivedAt:E,serverNow:k,clientNow:v});a[f]={complete:w},setTimeout(()=>d(null),i)});y.push(u),await u}const g=(await Promise.all(y)).filter(s=>s!==null),r=An(g);isNaN(r)||n(Date.now()+r)}const l=y=>{const g=performance.now(),r=a[y.timesync.id];r&&r.complete(g,y.timesync.now)};c();const p=setInterval(c,e);return{receive:l,destroy:()=>{clearInterval(p)}}}function An(e){return e.map(({sentAt:t,receivedAt:n,clientNow:o,serverNow:i})=>{const a=(n-t)/2;return i-o-a}).reduce((t,n)=>t+n,0)/e.length}class Tn{constructor(t,{hostname:n=document.location.hostname,port:o=Je}={},i,a){this.manifest=t,this.currentState={...i},this.store=new yn(a??{});const{useReconnectingWebsocket:c,path:l,pathParams:p}=zn(document.location.href);this.urlParams=new URLSearchParams(p),this.urlParams.set("screenWidth",window.screen.width.toString()),this.urlParams.set("screenHeight",window.screen.height.toString()),this.urlParams.set("screenPixelRatio",window.devicePixelRatio.toString());const h=`ws://${n}:${o}${l}?${this.urlParams}`;this.websocket=c?new vn(h):new WebSocket(h);let y;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new Qe),this.setState(this.currentState),y=Sn({interval:6e4,send:g=>{this.websocket.send(JSON.stringify(g))}})},this.websocket.addEventListener("message",({data:g})=>{try{const r=JSON.parse(g);if(typeof r=="object"&&r!==null&&"timesync"in r){const s=r;y?.receive(s)}}catch(r){console.error(r)}}),this.websocket.onclose=()=>{y?.destroy(),this.dispatchEvent(new Xe)},this.websocket.addEventListener("message",({data:g})=>{try{const r=JSON.parse(g);try{if(r.config)this.currentConfig=r.config,this.dispatchEvent(new tt(this.currentConfig));else if(r.updates)this.currentState={...this.currentState,...r.updates},this.dispatchEvent(new nt(r.updates));else if(r.event&&r.event.key)this.dispatchEvent(new ot(r.event.key,r.event.value));else if(typeof r.message=="object"){const s=r.message;switch(s.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:s.durationMillis,ticking:s.ticking};break;case"show_phase":this._showPhase=s.phase,this.dispatchEvent(new it(s.phase));break;case"media_config_update":this._mediaConfig=s;for(const u of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])s[u]?this.urlParams.set(u,"true"):this.urlParams.delete(u);this.dispatchEvent(new rt(s));break;case"data_store_items":this.store.handleDataStoreItemsMessage(s);break}this.dispatchEvent(new et(s))}}catch(s){console.warn("Error handling data",g,s)}}catch(r){console.error("Unable to parse incoming data from server",g,r)}}),this.store.addEventListener("items",g=>{this.sendDataStoreItems(g.items)});{const g=async()=>{if(navigator.mediaDevices){const r=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:s})=>s==="audiooutput");this.sendAudioOutputs(r),this.audioOutputs=r}};this.eventTarget.addEventListener("open",g),navigator.mediaDevices?.addEventListener("devicechange",g),g()}}websocket;eventTarget=new EventTarget;currentConfig={};get config(){return{...this.currentConfig}}currentState={};get state(){return{...this.currentState}}_showPhase=q.Setup;get showPhase(){return this._showPhase}_timerState=null;get timerState(){return this._timerState?{...this._timerState}:null}_mediaConfig=null;get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(t){return`${Ye(t)}?${this.urlParams?.toString()??""}`}audioOutputs=void 0;_selectedAudioOutput="";get selectedAudioOutput(){return this._selectedAudioOutput}store;urlParams;get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(t,...[n]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:t,value:n}}))}setState(t){this.currentState={...this.currentState,...t},this.isConnected&&this.websocket.send(JSON.stringify({updates:t}))}getAudioSinkId(t){return t?this.audioOutputs?.find(({label:n})=>n===t)?.deviceId:""}sendInitialMediaClipStates(t){this.isConnected&&this.websocket.send(JSON.stringify({allMediaClipStates:t}))}sendMediaClipState(t){this.isConnected&&this.websocket.send(JSON.stringify({mediaClipState:t}))}sendAudioOutputs(t){this.isConnected&&this.websocket.send(JSON.stringify({audioOutputs:t}))}sendDataStoreItems(t){this.isConnected&&this.websocket.send(JSON.stringify({dataStoreItems:t}))}setPluginWindowVisible(t){this.isConnected&&this.websocket.send(JSON.stringify({window:{visible:t}}))}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t){this.eventTarget.dispatchEvent(t)}}function zn(e){const t=new URL(e),n=new URLSearchParams(t.searchParams),o=n.get("local_id"),i=n.get("simulator")==="true",a=n.get("display")??"",c=t.pathname.startsWith("/plugin/")?decodeURIComponent(t.pathname.split("/")[2]):void 0;if(o){const l=n.get("t")??"";return n.delete("local_id"),{path:`/local/${encodeURIComponent(o)}`,pathParams:new URLSearchParams({t:l}),useReconnectingWebsocket:!0}}else if(i){const l=n.get("name")??"";return n.delete("simulator"),n.delete("name"),{path:`/simulator/${encodeURIComponent(l)}`,pathParams:n,useReconnectingWebsocket:!0}}else if(a){const l=n.get("displayIdIndex")??"";return n.delete("display"),n.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(a)}/${encodeURIComponent(l)}`}}else{if(c)return{path:`/plugin/${encodeURIComponent(c)}`,useReconnectingWebsocket:!0};{const l=n.get("serial")??"";return n.delete("serial"),{path:`/client/${encodeURIComponent(l)}`,pathParams:n}}}}class Qe extends Event{_cogsConnectionEventType="open";constructor(){super("open")}}class Xe extends Event{_cogsConnectionEventType="close";constructor(){super("close")}}class et extends Event{constructor(t){super("message"),this.message=t}_cogsConnectionEventType="message"}class tt extends Event{constructor(t){super("config"),this.config=t}_cogsConnectionEventType="config"}class nt extends Event{constructor(t){super("state"),this.state=t}_cogsConnectionEventType="state"}class ot extends Event{constructor(t,n){super("event"),this.name=t,this.value=n}_cogsConnectionEventType="event"}class rt extends Event{constructor(t){super("mediaConfig"),this.mediaConfig=t}_cogsConnectionEventType="mediaConfig"}class it extends Event{constructor(t){super("showPhase"),this.showPhase=t}_cogsConnectionEventType="showPhase"}function m(e,t,n){function o(l,p){if(l._zod||Object.defineProperty(l,"_zod",{value:{def:p,constr:c,traits:new Set},enumerable:!1}),l._zod.traits.has(e))return;l._zod.traits.add(e),t(l,p);const h=c.prototype,y=Object.keys(h);for(let g=0;g<y.length;g++){const r=y[g];r in l||(l[r]=h[r].bind(l))}}const i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function c(l){var p;const h=n?.Parent?new a:this;o(h,l),(p=h._zod).deferred??(p.deferred=[]);for(const y of h._zod.deferred)y();return h}return Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:l=>n?.Parent&&l instanceof n.Parent?!0:l?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class K extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class st extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const at={};function N(e){return at}function In(e){const t=Object.values(e).filter(o=>typeof o=="number");return Object.entries(e).filter(([o,i])=>t.indexOf(+o)===-1).map(([o,i])=>i)}function ze(e,t){return typeof t=="bigint"?t.toString():t}function Ie(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function $e(e){return e==null}function Oe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function $n(e,t){const n=(e.toString().split(".")[1]||"").length,o=t.toString();let i=(o.split(".")[1]||"").length;if(i===0&&/\d?e-\d?/.test(o)){const p=o.match(/\d?e-(\d?)/);p?.[1]&&(i=Number.parseInt(p[1]))}const a=n>i?n:i,c=Number.parseInt(e.toFixed(a).replace(".","")),l=Number.parseInt(t.toFixed(a).replace(".",""));return c%l/10**a}const ut=Symbol("evaluating");function C(e,t,n){let o;Object.defineProperty(e,t,{get(){if(o!==ut)return o===void 0&&(o=ut,o=n()),o},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}function U(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function V(...e){const t={};for(const n of e){const o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function ct(e){return JSON.stringify(e)}function On(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const lt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Zn=Ie(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function H(e){if(ue(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ue(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function dt(e){return H(e)?{...e}:Array.isArray(e)?[...e]:e}const Pn=new Set(["string","number","symbol"]);function J(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(e,t,n){const o=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(o._zod.parent=e),o}function b(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function xn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Ln={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Rn(e,t){const n=e._zod.def,o=V(e._zod.def,{get shape(){const i={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(i[a]=n.shape[a])}return U(this,"shape",i),i},checks:[]});return D(e,o)}function jn(e,t){const n=e._zod.def,o=V(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete i[a]}return U(this,"shape",i),i},checks:[]});return D(e,o)}function Nn(e,t){if(!H(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const i=V(e._zod.def,{get shape(){const a={...e._zod.def.shape,...t};return U(this,"shape",a),a},checks:[]});return D(e,i)}function Dn(e,t){if(!H(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const o={...e._zod.def.shape,...t};return U(this,"shape",o),o},checks:e._zod.def.checks};return D(e,n)}function Mn(e,t){const n=V(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t._zod.def.shape};return U(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return D(e,n)}function Fn(e,t,n){const o=V(t._zod.def,{get shape(){const i=t._zod.def.shape,a={...i};if(n)for(const c in n){if(!(c in i))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(a[c]=e?new e({type:"optional",innerType:i[c]}):i[c])}else for(const c in i)a[c]=e?new e({type:"optional",innerType:i[c]}):i[c];return U(this,"shape",a),a},checks:[]});return D(t,o)}function Un(e,t,n){const o=V(t._zod.def,{get shape(){const i=t._zod.def.shape,a={...i};if(n)for(const c in n){if(!(c in a))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(a[c]=new e({type:"nonoptional",innerType:i[c]}))}else for(const c in i)a[c]=new e({type:"nonoptional",innerType:i[c]});return U(this,"shape",a),a},checks:[]});return D(t,o)}function Y(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function B(e,t){return t.map(n=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function ce(e){return typeof e=="string"?e:e?.message}function M(e,t,n){const o={...e,path:e.path??[]};if(!e.message){const i=ce(e.inst?._zod.def?.error?.(e))??ce(t?.error?.(e))??ce(n.customError?.(e))??ce(n.localeError?.(e))??"Invalid input";o.message=i}return delete o.inst,delete o.continue,t?.reportInput||delete o.input,o}function Ze(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function re(...e){const[t,n,o]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:o}:{...t}}const pt=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ze,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ft=m("$ZodError",pt),ht=m("$ZodError",pt,{Parent:Error});function Vn(e,t=n=>n.message){const n={},o=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):o.push(t(i));return{formErrors:o,fieldErrors:n}}function Bn(e,t=n=>n.message){const n={_errors:[]},o=i=>{for(const a of i.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(c=>o({issues:c}));else if(a.code==="invalid_key")o({issues:a.issues});else if(a.code==="invalid_element")o({issues:a.issues});else if(a.path.length===0)n._errors.push(t(a));else{let c=n,l=0;for(;l<a.path.length;){const p=a.path[l];l===a.path.length-1?(c[p]=c[p]||{_errors:[]},c[p]._errors.push(t(a))):c[p]=c[p]||{_errors:[]},c=c[p],l++}}};return o(e),n}const Pe=e=>(t,n,o,i)=>{const a=o?Object.assign(o,{async:!1}):{async:!1},c=t._zod.run({value:n,issues:[]},a);if(c instanceof Promise)throw new K;if(c.issues.length){const l=new(i?.Err??e)(c.issues.map(p=>M(p,a,N())));throw lt(l,i?.callee),l}return c.value},xe=e=>async(t,n,o,i)=>{const a=o?Object.assign(o,{async:!0}):{async:!0};let c=t._zod.run({value:n,issues:[]},a);if(c instanceof Promise&&(c=await c),c.issues.length){const l=new(i?.Err??e)(c.issues.map(p=>M(p,a,N())));throw lt(l,i?.callee),l}return c.value},le=e=>(t,n,o)=>{const i=o?{...o,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new K;return a.issues.length?{success:!1,error:new(e??ft)(a.issues.map(c=>M(c,i,N())))}:{success:!0,data:a.value}},Gn=le(ht),de=e=>async(t,n,o)=>{const i=o?Object.assign(o,{async:!0}):{async:!0};let a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(c=>M(c,i,N())))}:{success:!0,data:a.value}},Wn=de(ht),qn=e=>(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Pe(e)(t,n,i)},Kn=e=>(t,n,o)=>Pe(e)(t,n,o),Hn=e=>async(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return xe(e)(t,n,i)},Jn=e=>async(t,n,o)=>xe(e)(t,n,o),Yn=e=>(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return le(e)(t,n,i)},Qn=e=>(t,n,o)=>le(e)(t,n,o),Xn=e=>async(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return de(e)(t,n,i)},eo=e=>async(t,n,o)=>de(e)(t,n,o),to=/^[cC][^\s-]{8,}$/,no=/^[0-9a-z]+$/,oo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ro=/^[0-9a-vA-V]{20}$/,io=/^[A-Za-z0-9]{27}$/,so=/^[a-zA-Z0-9_-]{21}$/,ao=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,uo=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,_t=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,co=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,lo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function po(){return new RegExp(lo,"u")}const fo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ho=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,_o=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,mo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,vo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,mt=/^[A-Za-z0-9_-]*$/,go=/^\+(?:[0-9]){6,14}[0-9]$/,vt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",yo=new RegExp(`^${vt}$`);function gt(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function bo(e){return new RegExp(`^${gt(e)}$`)}function wo(e){const t=gt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const o=`${t}(?:${n.join("|")})`;return new RegExp(`^${vt}T(?:${o})$`)}const Eo=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},ko=/^-?\d+$/,Co=/^-?\d+(?:\.\d+)?/,So=/^null$/i,Ao=/^[^A-Z]*$/,To=/^[^a-z]*$/,Z=m("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),yt={number:"number",bigint:"bigint",object:"date"},bt=m("$ZodCheckLessThan",(e,t)=>{Z.init(e,t);const n=yt[typeof t.value];e._zod.onattach.push(o=>{const i=o._zod.bag,a=(t.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<a&&(t.inclusive?i.maximum=t.value:i.exclusiveMaximum=t.value)}),e._zod.check=o=>{(t.inclusive?o.value<=t.value:o.value<t.value)||o.issues.push({origin:n,code:"too_big",maximum:t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),wt=m("$ZodCheckGreaterThan",(e,t)=>{Z.init(e,t);const n=yt[typeof t.value];e._zod.onattach.push(o=>{const i=o._zod.bag,a=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>a&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=o=>{(t.inclusive?o.value>=t.value:o.value>t.value)||o.issues.push({origin:n,code:"too_small",minimum:t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),zo=m("$ZodCheckMultipleOf",(e,t)=>{Z.init(e,t),e._zod.onattach.push(n=>{var o;(o=n._zod.bag).multipleOf??(o.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):$n(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Io=m("$ZodCheckNumberFormat",(e,t)=>{Z.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),o=n?"int":"number",[i,a]=Ln[t.format];e._zod.onattach.push(c=>{const l=c._zod.bag;l.format=t.format,l.minimum=i,l.maximum=a,n&&(l.pattern=ko)}),e._zod.check=c=>{const l=c.value;if(n){if(!Number.isInteger(l)){c.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?c.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,continue:!t.abort}):c.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,continue:!t.abort});return}}l<i&&c.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),l>a&&c.issues.push({origin:"number",input:l,code:"too_big",maximum:a,inst:e})}}),$o=m("$ZodCheckMaxLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!$e(i)&&i.length!==void 0}),e._zod.onattach.push(o=>{const i=o._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(o._zod.bag.maximum=t.maximum)}),e._zod.check=o=>{const i=o.value;if(i.length<=t.maximum)return;const c=Ze(i);o.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),Oo=m("$ZodCheckMinLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!$e(i)&&i.length!==void 0}),e._zod.onattach.push(o=>{const i=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(o._zod.bag.minimum=t.minimum)}),e._zod.check=o=>{const i=o.value;if(i.length>=t.minimum)return;const c=Ze(i);o.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),Zo=m("$ZodCheckLengthEquals",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!$e(i)&&i.length!==void 0}),e._zod.onattach.push(o=>{const i=o._zod.bag;i.minimum=t.length,i.maximum=t.length,i.length=t.length}),e._zod.check=o=>{const i=o.value,a=i.length;if(a===t.length)return;const c=Ze(i),l=a>t.length;o.issues.push({origin:c,...l?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),pe=m("$ZodCheckStringFormat",(e,t)=>{var n,o;Z.init(e,t),e._zod.onattach.push(i=>{const a=i._zod.bag;a.format=t.format,t.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(o=e._zod).check??(o.check=()=>{})}),Po=m("$ZodCheckRegex",(e,t)=>{pe.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),xo=m("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Ao),pe.init(e,t)}),Lo=m("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=To),pe.init(e,t)}),Ro=m("$ZodCheckIncludes",(e,t)=>{Z.init(e,t);const n=J(t.includes),o=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push(i=>{const a=i._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(o)}),e._zod.check=i=>{i.value.includes(t.includes,t.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:i.value,inst:e,continue:!t.abort})}}),jo=m("$ZodCheckStartsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`^${J(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=o=>{o.value.startsWith(t.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),No=m("$ZodCheckEndsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`.*${J(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=o=>{o.value.endsWith(t.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}}),Do=m("$ZodCheckOverwrite",(e,t)=>{Z.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Mo{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const o=t.split(`
|
|
20
|
-
`).filter(c=>c),
|
|
21
|
-
`))}}const
|
|
19
|
+
*/var mn=function(){if(typeof WebSocket<"u")return WebSocket},vn=function(e){return typeof e<"u"&&!!e&&e.CLOSING===2},F={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},gn=function(){function e(t,n,o){var r=this;o===void 0&&(o={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(a){r._debug("open event");var c=r._options.minUptime,l=c===void 0?F.minUptime:c;clearTimeout(r._connectTimeout),r._uptimeTimeout=setTimeout(function(){return r._acceptOpen()},l),r._ws.binaryType=r._binaryType,r._messageQueue.forEach(function(p){return r._ws.send(p)}),r._messageQueue=[],r.onopen&&r.onopen(a),r._listeners.open.forEach(function(p){return r._callEventListener(a,p)})},this._handleMessage=function(a){r._debug("message event"),r.onmessage&&r.onmessage(a),r._listeners.message.forEach(function(c){return r._callEventListener(a,c)})},this._handleError=function(a){r._debug("error event",a.message),r._disconnect(void 0,a.message==="TIMEOUT"?"timeout":void 0),r.onerror&&r.onerror(a),r._debug("exec error listeners"),r._listeners.error.forEach(function(c){return r._callEventListener(a,c)}),r._connect()},this._handleClose=function(a){r._debug("close event"),r._clearTimeouts(),r._shouldReconnect&&r._connect(),r.onclose&&r.onclose(a),r._listeners.close.forEach(function(c){return r._callEventListener(a,c)})},this._url=t,this._protocols=n,this._options=o,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(t){this._binaryType=t,this._ws&&(this._ws.binaryType=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){var t=this._messageQueue.reduce(function(n,o){return typeof o=="string"?n+=o.length:o instanceof Blob?n+=o.size:n+=o.byteLength,n},0);return t+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(t,n){if(t===void 0&&(t=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===this.CLOSED){this._debug("close: already closed");return}this._ws.close(t,n)},e.prototype.reconnect=function(t,n){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(t,n),this._connect())},e.prototype.send=function(t){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",t),this._ws.send(t);else{var n=this._options.maxEnqueuedMessages,o=n===void 0?F.maxEnqueuedMessages:n;this._messageQueue.length<o&&(this._debug("enqueue",t),this._messageQueue.push(t))}},e.prototype.addEventListener=function(t,n){this._listeners[t]&&this._listeners[t].push(n)},e.prototype.dispatchEvent=function(t){var n,o,r=this._listeners[t.type];if(r)try{for(var a=dn(r),c=a.next();!c.done;c=a.next()){var l=c.value;this._callEventListener(t,l)}}catch(p){n={error:p}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}return!0},e.prototype.removeEventListener=function(t,n){this._listeners[t]&&(this._listeners[t]=this._listeners[t].filter(function(o){return o!==n}))},e.prototype._debug=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this._options.debug&&console.log.apply(console,fn(["RWS>"],t))},e.prototype._getNextDelay=function(){var t=this._options,n=t.reconnectionDelayGrowFactor,o=n===void 0?F.reconnectionDelayGrowFactor:n,r=t.minReconnectionDelay,a=r===void 0?F.minReconnectionDelay:r,c=t.maxReconnectionDelay,l=c===void 0?F.maxReconnectionDelay:c,p=0;return this._retryCount>0&&(p=a*Math.pow(o,this._retryCount-1),p>l&&(p=l)),this._debug("next delay",p),p},e.prototype._wait=function(){var t=this;return new Promise(function(n){setTimeout(n,t._getNextDelay())})},e.prototype._getNextUrl=function(t){if(typeof t=="string")return Promise.resolve(t);if(typeof t=="function"){var n=t();if(typeof n=="string")return Promise.resolve(n);if(n.then)return n}throw Error("Invalid URL")},e.prototype._connect=function(){var t=this;if(!(this._connectLock||!this._shouldReconnect)){this._connectLock=!0;var n=this._options,o=n.maxRetries,r=o===void 0?F.maxRetries:o,a=n.connectionTimeout,c=a===void 0?F.connectionTimeout:a,l=n.WebSocket,p=l===void 0?mn():l;if(this._retryCount>=r){this._debug("max retries reached",this._retryCount,">=",r);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!vn(p))throw Error("No valid WebSocket class provided");this._wait().then(function(){return t._getNextUrl(t._url)}).then(function(f){t._closeCalled||(t._debug("connect",{url:f,protocols:t._protocols}),t._ws=t._protocols?new p(f,t._protocols):new p(f),t._ws.binaryType=t._binaryType,t._connectLock=!1,t._addListeners(),t._connectTimeout=setTimeout(function(){return t._handleTimeout()},c))})}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new hn(Error("TIMEOUT"),this))},e.prototype._disconnect=function(t,n){if(t===void 0&&(t=1e3),this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(t,n),this._handleClose(new _n(t,n,this))}catch{}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(t,n){"handleEvent"in n?n.handleEvent(t):n(t)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();const Ye=12095;function Qe(e){const t=typeof window<"u"?window.location:void 0,n=`/assets/${encodeURIComponent(e)}`;return`${t?.protocol}//${t?.hostname}:${Ye}${n}`}async function yn(e){const t=await fetch(e);return URL.createObjectURL(new Blob([await t.arrayBuffer()]))}class bn{_items;#e=new EventTarget;constructor(t){this._items={...t}}handleDataStoreItemsMessage(t){this._items={...this._items,...t.items},Object.entries(t.items).forEach(([n,o])=>{this.dispatchEvent(new Te(n,o))}),this.dispatchEvent(new Ae(t.items))}get items(){return this._items}getItem(t){return this._items[t]}setItems(t){return this._items={...this._items,...t},Object.entries(t).forEach(([n,o])=>{this.dispatchEvent(new Te(n,o))}),this.dispatchEvent(new Ae(t)),this}addEventListener(t,n,o){this.#e.addEventListener(t,n,o)}removeEventListener(t,n,o){this.#e.removeEventListener(t,n,o)}dispatchEvent(t){this.#e.dispatchEvent(t)}}class Te extends Event{constructor(t,n){super("item"),this.key=t,this.value=n}_cogsConnectionEventType="item"}class Ae extends Event{constructor(t){super("items"),this.items=t}_cogsConnectionEventType="item"}const oe=globalThis.Date;function wn(e){const t=e-oe.now();function n(...r){return r.length===0?new oe(n.now()):new oe(...r)}const o=Object.getOwnPropertyDescriptors(oe);Object.defineProperties(n,o),n.now=function(){return oe.now()+t},globalThis.Date=n}let En=0;function kn(){return++En}const Cn=5,Sn=1e4;function Tn({interval:e,send:t,onChange:n=wn,syncSampleSize:o=Cn,syncRequestTimeout:r=Sn}){const a={};async function c(){const y=[];for(let s=0;s<o;s++){const u=new Promise(d=>{const h=kn(),v=Date.now(),_=performance.now();t({timesync:{id:h}});const w=(E,k)=>d({sentAt:_,receivedAt:E,serverNow:k,clientNow:v});a[h]={complete:w},setTimeout(()=>d(null),r)});y.push(u),await u}const g=(await Promise.all(y)).filter(s=>s!==null),i=An(g);isNaN(i)||n(Date.now()+i)}const l=y=>{const g=performance.now(),i=a[y.timesync.id];i&&i.complete(g,y.timesync.now)};c();const p=setInterval(c,e);return{receive:l,destroy:()=>{clearInterval(p)}}}function An(e){return e.map(({sentAt:t,receivedAt:n,clientNow:o,serverNow:r})=>{const a=(n-t)/2;return r-o-a}).reduce((t,n)=>t+n,0)/e.length}class zn{constructor(t,{hostname:n=document.location.hostname,port:o=Ye}={},r,a){this.manifest=t,this.currentState={...r},this.store=new bn(a??{});const{useReconnectingWebsocket:c,path:l,pathParams:p}=In(document.location.href);this.urlParams=new URLSearchParams(p),this.urlParams.set("screenWidth",window.screen.width.toString()),this.urlParams.set("screenHeight",window.screen.height.toString()),this.urlParams.set("screenPixelRatio",window.devicePixelRatio.toString());const f=`ws://${n}:${o}${l}?${this.urlParams}`;this.websocket=c?new gn(f):new WebSocket(f);let y;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new Xe),this.setState(this.currentState),y=Tn({interval:6e4,send:g=>{this.websocket.send(JSON.stringify(g))}})},this.websocket.addEventListener("message",({data:g})=>{try{const i=JSON.parse(g);if(typeof i=="object"&&i!==null&&"timesync"in i){const s=i;y?.receive(s)}}catch(i){console.error(i)}}),this.websocket.onclose=()=>{y?.destroy(),this.dispatchEvent(new et)},this.websocket.addEventListener("message",({data:g})=>{try{const i=JSON.parse(g);try{if(i.config)this.currentConfig=i.config,this.dispatchEvent(new nt(this.currentConfig));else if(i.updates)this.currentState={...this.currentState,...i.updates},this.dispatchEvent(new ot(i.updates));else if(i.event&&i.event.key)this.dispatchEvent(new it(i.event.key,i.event.value));else if(typeof i.message=="object"){const s=i.message;switch(s.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:s.durationMillis,ticking:s.ticking};break;case"show_phase":this._showPhase=s.phase,this.dispatchEvent(new st(s.phase));break;case"media_config_update":this._mediaConfig=s;for(const u of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])s[u]?this.urlParams.set(u,"true"):this.urlParams.delete(u);this.dispatchEvent(new rt(s));break;case"data_store_items":this.store.handleDataStoreItemsMessage(s);break}this.dispatchEvent(new tt(s))}}catch(s){console.warn("Error handling data",g,s)}}catch(i){console.error("Unable to parse incoming data from server",g,i)}}),this.store.addEventListener("items",g=>{this.sendDataStoreItems(g.items)});{const g=async()=>{if(navigator.mediaDevices){const i=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:s})=>s==="audiooutput");this.sendAudioOutputs(i),this.audioOutputs=i}};this.eventTarget.addEventListener("open",g),navigator.mediaDevices?.addEventListener("devicechange",g),g()}}websocket;eventTarget=new EventTarget;currentConfig={};get config(){return{...this.currentConfig}}currentState={};get state(){return{...this.currentState}}_showPhase=q.Setup;get showPhase(){return this._showPhase}_timerState=null;get timerState(){return this._timerState?{...this._timerState}:null}_mediaConfig=null;get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(t){return`${Qe(t)}?${this.urlParams?.toString()??""}`}audioOutputs=void 0;_selectedAudioOutput="";get selectedAudioOutput(){return this._selectedAudioOutput}store;urlParams;get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(t,...[n]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:t,value:n}}))}setState(t){this.currentState={...this.currentState,...t},this.isConnected&&this.websocket.send(JSON.stringify({updates:t}))}getAudioSinkId(t){return t?this.audioOutputs?.find(({label:n})=>n===t)?.deviceId:""}sendInitialMediaClipStates(t){this.isConnected&&this.websocket.send(JSON.stringify({allMediaClipStates:t}))}sendMediaClipState(t){this.isConnected&&this.websocket.send(JSON.stringify({mediaClipState:t}))}sendAudioOutputs(t){this.isConnected&&this.websocket.send(JSON.stringify({audioOutputs:t}))}sendDataStoreItems(t){this.isConnected&&this.websocket.send(JSON.stringify({dataStoreItems:t}))}setPluginWindowVisible(t){this.isConnected&&this.websocket.send(JSON.stringify({window:{visible:t}}))}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t){this.eventTarget.dispatchEvent(t)}}function In(e){const t=new URL(e),n=new URLSearchParams(t.searchParams),o=n.get("local_id"),r=n.get("simulator")==="true",a=n.get("display")??"",c=t.pathname.startsWith("/plugin/")?decodeURIComponent(t.pathname.split("/")[2]):void 0;if(o){const l=n.get("t")??"";return n.delete("local_id"),{path:`/local/${encodeURIComponent(o)}`,pathParams:new URLSearchParams({t:l}),useReconnectingWebsocket:!0}}else if(r){const l=n.get("name")??"";return n.delete("simulator"),n.delete("name"),{path:`/simulator/${encodeURIComponent(l)}`,pathParams:n,useReconnectingWebsocket:!0}}else if(a){const l=n.get("displayIdIndex")??"";return n.delete("display"),n.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(a)}/${encodeURIComponent(l)}`}}else{if(c)return{path:`/plugin/${encodeURIComponent(c)}`,useReconnectingWebsocket:!0};{const l=n.get("serial")??"";return n.delete("serial"),{path:`/client/${encodeURIComponent(l)}`,pathParams:n}}}}class Xe extends Event{_cogsConnectionEventType="open";constructor(){super("open")}}class et extends Event{_cogsConnectionEventType="close";constructor(){super("close")}}class tt extends Event{constructor(t){super("message"),this.message=t}_cogsConnectionEventType="message"}class nt extends Event{constructor(t){super("config"),this.config=t}_cogsConnectionEventType="config"}class ot extends Event{constructor(t){super("state"),this.state=t}_cogsConnectionEventType="state"}class it extends Event{constructor(t,n){super("event"),this.name=t,this.value=n}_cogsConnectionEventType="event"}class rt extends Event{constructor(t){super("mediaConfig"),this.mediaConfig=t}_cogsConnectionEventType="mediaConfig"}class st extends Event{constructor(t){super("showPhase"),this.showPhase=t}_cogsConnectionEventType="showPhase"}function m(e,t,n){function o(l,p){if(l._zod||Object.defineProperty(l,"_zod",{value:{def:p,constr:c,traits:new Set},enumerable:!1}),l._zod.traits.has(e))return;l._zod.traits.add(e),t(l,p);const f=c.prototype,y=Object.keys(f);for(let g=0;g<y.length;g++){const i=y[g];i in l||(l[i]=f[i].bind(l))}}const r=n?.Parent??Object;class a extends r{}Object.defineProperty(a,"name",{value:e});function c(l){var p;const f=n?.Parent?new a:this;o(f,l),(p=f._zod).deferred??(p.deferred=[]);for(const y of f._zod.deferred)y();return f}return Object.defineProperty(c,"init",{value:o}),Object.defineProperty(c,Symbol.hasInstance,{value:l=>n?.Parent&&l instanceof n.Parent?!0:l?._zod?.traits?.has(e)}),Object.defineProperty(c,"name",{value:e}),c}class K extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class at extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const ut={};function N(e){return ut}function $n(e){const t=Object.values(e).filter(o=>typeof o=="number");return Object.entries(e).filter(([o,r])=>t.indexOf(+o)===-1).map(([o,r])=>r)}function ze(e,t){return typeof t=="bigint"?t.toString():t}function Ie(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function $e(e){return e==null}function Oe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function On(e,t){const n=(e.toString().split(".")[1]||"").length,o=t.toString();let r=(o.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(o)){const p=o.match(/\d?e-(\d?)/);p?.[1]&&(r=Number.parseInt(p[1]))}const a=n>r?n:r,c=Number.parseInt(e.toFixed(a).replace(".","")),l=Number.parseInt(t.toFixed(a).replace(".",""));return c%l/10**a}const ct=Symbol("evaluating");function C(e,t,n){let o;Object.defineProperty(e,t,{get(){if(o!==ct)return o===void 0&&(o=ct,o=n()),o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function U(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function V(...e){const t={};for(const n of e){const o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function lt(e){return JSON.stringify(e)}function Zn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const dt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ce(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Pn=Ie(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function H(e){if(ce(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ce(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function pt(e){return H(e)?{...e}:Array.isArray(e)?[...e]:e}const xn=new Set(["string","number","symbol"]);function J(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(e,t,n){const o=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(o._zod.parent=e),o}function b(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Ln(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Rn={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function jn(e,t){const n=e._zod.def,o=V(e._zod.def,{get shape(){const r={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(r[a]=n.shape[a])}return U(this,"shape",r),r},checks:[]});return D(e,o)}function Nn(e,t){const n=e._zod.def,o=V(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete r[a]}return U(this,"shape",r),r},checks:[]});return D(e,o)}function Dn(e,t){if(!H(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const r=V(e._zod.def,{get shape(){const a={...e._zod.def.shape,...t};return U(this,"shape",a),a},checks:[]});return D(e,r)}function Mn(e,t){if(!H(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const o={...e._zod.def.shape,...t};return U(this,"shape",o),o},checks:e._zod.def.checks};return D(e,n)}function Fn(e,t){const n=V(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t._zod.def.shape};return U(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return D(e,n)}function Un(e,t,n){const o=V(t._zod.def,{get shape(){const r=t._zod.def.shape,a={...r};if(n)for(const c in n){if(!(c in r))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(a[c]=e?new e({type:"optional",innerType:r[c]}):r[c])}else for(const c in r)a[c]=e?new e({type:"optional",innerType:r[c]}):r[c];return U(this,"shape",a),a},checks:[]});return D(t,o)}function Vn(e,t,n){const o=V(t._zod.def,{get shape(){const r=t._zod.def.shape,a={...r};if(n)for(const c in n){if(!(c in a))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(a[c]=new e({type:"nonoptional",innerType:r[c]}))}else for(const c in r)a[c]=new e({type:"nonoptional",innerType:r[c]});return U(this,"shape",a),a},checks:[]});return D(t,o)}function Y(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function B(e,t){return t.map(n=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function le(e){return typeof e=="string"?e:e?.message}function M(e,t,n){const o={...e,path:e.path??[]};if(!e.message){const r=le(e.inst?._zod.def?.error?.(e))??le(t?.error?.(e))??le(n.customError?.(e))??le(n.localeError?.(e))??"Invalid input";o.message=r}return delete o.inst,delete o.continue,t?.reportInput||delete o.input,o}function Ze(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function ie(...e){const[t,n,o]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:o}:{...t}}const ft=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ze,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ht=m("$ZodError",ft),_t=m("$ZodError",ft,{Parent:Error});function Bn(e,t=n=>n.message){const n={},o=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):o.push(t(r));return{formErrors:o,fieldErrors:n}}function Gn(e,t=n=>n.message){const n={_errors:[]},o=r=>{for(const a of r.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(c=>o({issues:c}));else if(a.code==="invalid_key")o({issues:a.issues});else if(a.code==="invalid_element")o({issues:a.issues});else if(a.path.length===0)n._errors.push(t(a));else{let c=n,l=0;for(;l<a.path.length;){const p=a.path[l];l===a.path.length-1?(c[p]=c[p]||{_errors:[]},c[p]._errors.push(t(a))):c[p]=c[p]||{_errors:[]},c=c[p],l++}}};return o(e),n}const Pe=e=>(t,n,o,r)=>{const a=o?Object.assign(o,{async:!1}):{async:!1},c=t._zod.run({value:n,issues:[]},a);if(c instanceof Promise)throw new K;if(c.issues.length){const l=new(r?.Err??e)(c.issues.map(p=>M(p,a,N())));throw dt(l,r?.callee),l}return c.value},xe=e=>async(t,n,o,r)=>{const a=o?Object.assign(o,{async:!0}):{async:!0};let c=t._zod.run({value:n,issues:[]},a);if(c instanceof Promise&&(c=await c),c.issues.length){const l=new(r?.Err??e)(c.issues.map(p=>M(p,a,N())));throw dt(l,r?.callee),l}return c.value},de=e=>(t,n,o)=>{const r=o?{...o,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},r);if(a instanceof Promise)throw new K;return a.issues.length?{success:!1,error:new(e??ht)(a.issues.map(c=>M(c,r,N())))}:{success:!0,data:a.value}},Wn=de(_t),pe=e=>async(t,n,o)=>{const r=o?Object.assign(o,{async:!0}):{async:!0};let a=t._zod.run({value:n,issues:[]},r);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(c=>M(c,r,N())))}:{success:!0,data:a.value}},qn=pe(_t),Kn=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Pe(e)(t,n,r)},Hn=e=>(t,n,o)=>Pe(e)(t,n,o),Jn=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return xe(e)(t,n,r)},Yn=e=>async(t,n,o)=>xe(e)(t,n,o),Qn=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return de(e)(t,n,r)},Xn=e=>(t,n,o)=>de(e)(t,n,o),eo=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return pe(e)(t,n,r)},to=e=>async(t,n,o)=>pe(e)(t,n,o),no=/^[cC][^\s-]{8,}$/,oo=/^[0-9a-z]+$/,io=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ro=/^[0-9a-vA-V]{20}$/,so=/^[A-Za-z0-9]{27}$/,ao=/^[a-zA-Z0-9_-]{21}$/,uo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,co=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,mt=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,lo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,po="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function fo(){return new RegExp(po,"u")}const ho=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,_o=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mo=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,vo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,go=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,vt=/^[A-Za-z0-9_-]*$/,yo=/^\+(?:[0-9]){6,14}[0-9]$/,gt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",bo=new RegExp(`^${gt}$`);function yt(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function wo(e){return new RegExp(`^${yt(e)}$`)}function Eo(e){const t=yt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const o=`${t}(?:${n.join("|")})`;return new RegExp(`^${gt}T(?:${o})$`)}const ko=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Co=/^-?\d+$/,So=/^-?\d+(?:\.\d+)?/,To=/^null$/i,Ao=/^[^A-Z]*$/,zo=/^[^a-z]*$/,Z=m("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),bt={number:"number",bigint:"bigint",object:"date"},wt=m("$ZodCheckLessThan",(e,t)=>{Z.init(e,t);const n=bt[typeof t.value];e._zod.onattach.push(o=>{const r=o._zod.bag,a=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<a&&(t.inclusive?r.maximum=t.value:r.exclusiveMaximum=t.value)}),e._zod.check=o=>{(t.inclusive?o.value<=t.value:o.value<t.value)||o.issues.push({origin:n,code:"too_big",maximum:t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Et=m("$ZodCheckGreaterThan",(e,t)=>{Z.init(e,t);const n=bt[typeof t.value];e._zod.onattach.push(o=>{const r=o._zod.bag,a=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>a&&(t.inclusive?r.minimum=t.value:r.exclusiveMinimum=t.value)}),e._zod.check=o=>{(t.inclusive?o.value>=t.value:o.value>t.value)||o.issues.push({origin:n,code:"too_small",minimum:t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Io=m("$ZodCheckMultipleOf",(e,t)=>{Z.init(e,t),e._zod.onattach.push(n=>{var o;(o=n._zod.bag).multipleOf??(o.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):On(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),$o=m("$ZodCheckNumberFormat",(e,t)=>{Z.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),o=n?"int":"number",[r,a]=Rn[t.format];e._zod.onattach.push(c=>{const l=c._zod.bag;l.format=t.format,l.minimum=r,l.maximum=a,n&&(l.pattern=Co)}),e._zod.check=c=>{const l=c.value;if(n){if(!Number.isInteger(l)){c.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?c.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,continue:!t.abort}):c.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,continue:!t.abort});return}}l<r&&c.issues.push({origin:"number",input:l,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort}),l>a&&c.issues.push({origin:"number",input:l,code:"too_big",maximum:a,inst:e})}}),Oo=m("$ZodCheckMaxLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!$e(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(o._zod.bag.maximum=t.maximum)}),e._zod.check=o=>{const r=o.value;if(r.length<=t.maximum)return;const c=Ze(r);o.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Zo=m("$ZodCheckMinLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!$e(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(o._zod.bag.minimum=t.minimum)}),e._zod.check=o=>{const r=o.value;if(r.length>=t.minimum)return;const c=Ze(r);o.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Po=m("$ZodCheckLengthEquals",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!$e(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=o=>{const r=o.value,a=r.length;if(a===t.length)return;const c=Ze(r),l=a>t.length;o.issues.push({origin:c,...l?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),fe=m("$ZodCheckStringFormat",(e,t)=>{var n,o;Z.init(e,t),e._zod.onattach.push(r=>{const a=r._zod.bag;a.format=t.format,t.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(o=e._zod).check??(o.check=()=>{})}),xo=m("$ZodCheckRegex",(e,t)=>{fe.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Lo=m("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Ao),fe.init(e,t)}),Ro=m("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=zo),fe.init(e,t)}),jo=m("$ZodCheckIncludes",(e,t)=>{Z.init(e,t);const n=J(t.includes),o=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push(r=>{const a=r._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(o)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),No=m("$ZodCheckStartsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`^${J(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.startsWith(t.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),Do=m("$ZodCheckEndsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`.*${J(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.endsWith(t.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}}),Mo=m("$ZodCheckOverwrite",(e,t)=>{Z.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Fo{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const o=t.split(`
|
|
20
|
+
`).filter(c=>c),r=Math.min(...o.map(c=>c.length-c.trimStart().length)),a=o.map(c=>c.slice(r)).map(c=>" ".repeat(this.indent*2)+c);for(const c of a)this.content.push(c)}compile(){const t=Function,n=this?.args,r=[...(this?.content??[""]).map(a=>` ${a}`)];return new t(...n,r.join(`
|
|
21
|
+
`))}}const Uo={major:4,minor:1,patch:13},S=m("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Uo;const o=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&o.unshift(e);for(const r of o)for(const a of r._zod.onattach)a(e);if(o.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const r=(c,l,p)=>{let f=Y(c),y;for(const g of l){if(g._zod.def.when){if(!g._zod.def.when(c))continue}else if(f)continue;const i=c.issues.length,s=g._zod.check(c);if(s instanceof Promise&&p?.async===!1)throw new K;if(y||s instanceof Promise)y=(y??Promise.resolve()).then(async()=>{await s,c.issues.length!==i&&(f||(f=Y(c,i)))});else{if(c.issues.length===i)continue;f||(f=Y(c,i))}}return y?y.then(()=>c):c},a=(c,l,p)=>{if(Y(c))return c.aborted=!0,c;const f=r(l,o,p);if(f instanceof Promise){if(p.async===!1)throw new K;return f.then(y=>e._zod.parse(y,p))}return e._zod.parse(f,p)};e._zod.run=(c,l)=>{if(l.skipChecks)return e._zod.parse(c,l);if(l.direction==="backward"){const f=e._zod.parse({value:c.value,issues:[]},{...l,skipChecks:!0});return f instanceof Promise?f.then(y=>a(y,c,l)):a(f,c,l)}const p=e._zod.parse(c,l);if(p instanceof Promise){if(l.async===!1)throw new K;return p.then(f=>r(f,o,l))}return r(p,o,l)}}e["~standard"]={validate:r=>{try{const a=Wn(e,r);return a.success?{value:a.data}:{issues:a.error?.issues}}catch{return qn(e,r).then(c=>c.success?{value:c.data}:{issues:c.error?.issues})}},vendor:"zod",version:1}}),Le=m("$ZodString",(e,t)=>{S.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??ko(e._zod.bag),e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),A=m("$ZodStringFormat",(e,t)=>{fe.init(e,t),Le.init(e,t)}),Vo=m("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=co),A.init(e,t)}),Bo=m("$ZodUUID",(e,t)=>{if(t.version){const o={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(o===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=mt(o))}else t.pattern??(t.pattern=mt());A.init(e,t)}),Go=m("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=lo),A.init(e,t)}),Wo=m("$ZodURL",(e,t)=>{A.init(e,t),e._zod.check=n=>{try{const o=n.value.trim(),r=new URL(o);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(r.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=r.href:n.value=o;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),qo=m("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=fo()),A.init(e,t)}),Ko=m("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=ao),A.init(e,t)}),Ho=m("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=no),A.init(e,t)}),Jo=m("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=oo),A.init(e,t)}),Yo=m("$ZodULID",(e,t)=>{t.pattern??(t.pattern=io),A.init(e,t)}),Qo=m("$ZodXID",(e,t)=>{t.pattern??(t.pattern=ro),A.init(e,t)}),Xo=m("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=so),A.init(e,t)}),ei=m("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Eo(t)),A.init(e,t)}),ti=m("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=bo),A.init(e,t)}),ni=m("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=wo(t)),A.init(e,t)}),oi=m("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=uo),A.init(e,t)}),ii=m("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ho),A.init(e,t),e._zod.bag.format="ipv4"}),ri=m("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=_o),A.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),si=m("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=mo),A.init(e,t)}),ai=m("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=vo),A.init(e,t),e._zod.check=n=>{const o=n.value.split("/");try{if(o.length!==2)throw new Error;const[r,a]=o;if(!a)throw new Error;const c=Number(a);if(`${c}`!==a)throw new Error;if(c<0||c>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function kt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const ui=m("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=go),A.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{kt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function ci(e){if(!vt.test(e))return!1;const t=e.replace(/[-_]/g,o=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return kt(n)}const li=m("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=vt),A.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{ci(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),di=m("$ZodE164",(e,t)=>{t.pattern??(t.pattern=yo),A.init(e,t)});function pi(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[o]=n;if(!o)return!1;const r=JSON.parse(atob(o));return!("typ"in r&&r?.typ!=="JWT"||!r.alg||t&&(!("alg"in r)||r.alg!==t))}catch{return!1}}const fi=m("$ZodJWT",(e,t)=>{A.init(e,t),e._zod.check=n=>{pi(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Ct=m("$ZodNumber",(e,t)=>{S.init(e,t),e._zod.pattern=e._zod.bag.pattern??So,e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const r=n.value;if(typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r))return n;const a=typeof r=="number"?Number.isNaN(r)?"NaN":Number.isFinite(r)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:r,inst:e,...a?{received:a}:{}}),n}}),hi=m("$ZodNumberFormat",(e,t)=>{$o.init(e,t),Ct.init(e,t)}),_i=m("$ZodNull",(e,t)=>{S.init(e,t),e._zod.pattern=To,e._zod.values=new Set([null]),e._zod.parse=(n,o)=>{const r=n.value;return r===null||n.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),n}}),mi=m("$ZodUnknown",(e,t)=>{S.init(e,t),e._zod.parse=n=>n}),vi=m("$ZodNever",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function St(e,t,n){e.issues.length&&t.issues.push(...B(n,e.issues)),t.value[n]=e.value}const gi=m("$ZodArray",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);const a=[];for(let c=0;c<r.length;c++){const l=r[c],p=t.element._zod.run({value:l,issues:[]},o);p instanceof Promise?a.push(p.then(f=>St(f,n,c))):St(p,n,c)}return a.length?Promise.all(a).then(()=>n):n}});function he(e,t,n,o){e.issues.length&&t.issues.push(...B(n,e.issues)),e.value===void 0?n in o&&(t.value[n]=void 0):t.value[n]=e.value}function Tt(e){const t=Object.keys(e.shape);for(const o of t)if(!e.shape?.[o]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${o}": expected a Zod schema`);const n=Ln(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function At(e,t,n,o,r,a){const c=[],l=r.keySet,p=r.catchall._zod,f=p.def.type;for(const y in t){if(l.has(y))continue;if(f==="never"){c.push(y);continue}const g=p.run({value:t[y],issues:[]},o);g instanceof Promise?e.push(g.then(i=>he(i,n,y,t))):he(g,n,y,t)}return c.length&&n.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const yi=m("$ZodObject",(e,t)=>{if(S.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const l=t.shape;Object.defineProperty(t,"shape",{get:()=>{const p={...l};return Object.defineProperty(t,"shape",{value:p}),p}})}const o=Ie(()=>Tt(t));C(e._zod,"propValues",()=>{const l=t.shape,p={};for(const f in l){const y=l[f]._zod;if(y.values){p[f]??(p[f]=new Set);for(const g of y.values)p[f].add(g)}}return p});const r=ce,a=t.catchall;let c;e._zod.parse=(l,p)=>{c??(c=o.value);const f=l.value;if(!r(f))return l.issues.push({expected:"object",code:"invalid_type",input:f,inst:e}),l;l.value={};const y=[],g=c.shape;for(const i of c.keys){const u=g[i]._zod.run({value:f[i],issues:[]},p);u instanceof Promise?y.push(u.then(d=>he(d,l,i,f))):he(u,l,i,f)}return a?At(y,f,l,p,o.value,e):y.length?Promise.all(y).then(()=>l):l}}),bi=m("$ZodObjectJIT",(e,t)=>{yi.init(e,t);const n=e._zod.parse,o=Ie(()=>Tt(t)),r=i=>{const s=new Fo(["shape","payload","ctx"]),u=o.value,d=w=>{const E=lt(w);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};s.write("const input = payload.value;");const h=Object.create(null);let v=0;for(const w of u.keys)h[w]=`key_${v++}`;s.write("const newResult = {};");for(const w of u.keys){const E=h[w],k=lt(w);s.write(`const ${E} = ${d(w)};`),s.write(`
|
|
22
22
|
if (${E}.issues.length) {
|
|
23
23
|
payload.issues = payload.issues.concat(${E}.issues.map(iss => ({
|
|
24
24
|
...iss,
|
|
@@ -35,4 +35,4 @@
|
|
|
35
35
|
newResult[${k}] = ${E}.value;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
`)}s.write("payload.value = newResult;"),s.write("return payload;");const _=s.compile();return(w,E)=>_(r,w,E)};let a;const c=ue,l=!at.jitless,h=l&&Zn.value,y=t.catchall;let g;e._zod.parse=(r,s)=>{g??(g=o.value);const u=r.value;return c(u)?l&&h&&s?.async===!1&&s.jitless!==!0?(a||(a=i(t.shape)),r=a(r,s),y?At([],u,r,s,g,e):r):n(r,s):(r.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),r)}});function Tt(e,t,n,o){for(const a of e)if(a.issues.length===0)return t.value=a.value,t;const i=e.filter(a=>!Y(a));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(a=>a.issues.map(c=>M(c,o,N())))}),t)}const br=m("$ZodUnion",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.options.some(i=>i._zod.optin==="optional")?"optional":void 0),C(e._zod,"optout",()=>t.options.some(i=>i._zod.optout==="optional")?"optional":void 0),C(e._zod,"values",()=>{if(t.options.every(i=>i._zod.values))return new Set(t.options.flatMap(i=>Array.from(i._zod.values)))}),C(e._zod,"pattern",()=>{if(t.options.every(i=>i._zod.pattern)){const i=t.options.map(a=>a._zod.pattern);return new RegExp(`^(${i.map(a=>Oe(a.source)).join("|")})$`)}});const n=t.options.length===1,o=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return o(i,a);let c=!1;const l=[];for(const p of t.options){const h=p._zod.run({value:i.value,issues:[]},a);if(h instanceof Promise)l.push(h),c=!0;else{if(h.issues.length===0)return h;l.push(h)}}return c?Promise.all(l).then(p=>Tt(p,i,e,a)):Tt(l,i,e,a)}}),wr=m("$ZodIntersection",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const i=n.value,a=t.left._zod.run({value:i,issues:[]},o),c=t.right._zod.run({value:i,issues:[]},o);return a instanceof Promise||c instanceof Promise?Promise.all([a,c]).then(([p,h])=>zt(n,p,h)):zt(n,a,c)}});function Re(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(H(e)&&H(t)){const n=Object.keys(t),o=Object.keys(e).filter(a=>n.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Re(e[a],t[a]);if(!c.valid)return{valid:!1,mergeErrorPath:[a,...c.mergeErrorPath]};i[a]=c.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let o=0;o<e.length;o++){const i=e[o],a=t[o],c=Re(i,a);if(!c.valid)return{valid:!1,mergeErrorPath:[o,...c.mergeErrorPath]};n.push(c.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function zt(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Y(e))return e;const o=Re(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Er=m("$ZodTuple",(e,t)=>{S.init(e,t);const n=t.items;e._zod.parse=(o,i)=>{const a=o.value;if(!Array.isArray(a))return o.issues.push({input:a,inst:e,expected:"tuple",code:"invalid_type"}),o;o.value=[];const c=[],l=[...n].reverse().findIndex(y=>y._zod.optin!=="optional"),p=l===-1?0:n.length-l;if(!t.rest){const y=a.length>n.length,g=a.length<p-1;if(y||g)return o.issues.push({...y?{code:"too_big",maximum:n.length}:{code:"too_small",minimum:n.length},input:a,inst:e,origin:"array"}),o}let h=-1;for(const y of n){if(h++,h>=a.length&&h>=p)continue;const g=y._zod.run({value:a[h],issues:[]},i);g instanceof Promise?c.push(g.then(r=>he(r,o,h))):he(g,o,h)}if(t.rest){const y=a.slice(n.length);for(const g of y){h++;const r=t.rest._zod.run({value:g,issues:[]},i);r instanceof Promise?c.push(r.then(s=>he(s,o,h))):he(r,o,h)}}return c.length?Promise.all(c).then(()=>o):o}});function he(e,t,n){e.issues.length&&t.issues.push(...B(n,e.issues)),t.value[n]=e.value}const kr=m("$ZodRecord",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const i=n.value;if(!H(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const a=[],c=t.keyType._zod.values;if(c){n.value={};const l=new Set;for(const h of c)if(typeof h=="string"||typeof h=="number"||typeof h=="symbol"){l.add(typeof h=="number"?h.toString():h);const y=t.valueType._zod.run({value:i[h],issues:[]},o);y instanceof Promise?a.push(y.then(g=>{g.issues.length&&n.issues.push(...B(h,g.issues)),n.value[h]=g.value})):(y.issues.length&&n.issues.push(...B(h,y.issues)),n.value[h]=y.value)}let p;for(const h in i)l.has(h)||(p=p??[],p.push(h));p&&p.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:p})}else{n.value={};for(const l of Reflect.ownKeys(i)){if(l==="__proto__")continue;const p=t.keyType._zod.run({value:l,issues:[]},o);if(p instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(p.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map(y=>M(y,o,N())),input:l,path:[l],inst:e}),n.value[p.value]=p.value;continue}const h=t.valueType._zod.run({value:i[l],issues:[]},o);h instanceof Promise?a.push(h.then(y=>{y.issues.length&&n.issues.push(...B(l,y.issues)),n.value[p.value]=y.value})):(h.issues.length&&n.issues.push(...B(l,h.issues)),n.value[p.value]=h.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Cr=m("$ZodEnum",(e,t)=>{S.init(e,t);const n=In(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter(i=>Pn.has(typeof i)).map(i=>typeof i=="string"?J(i):i.toString()).join("|")})$`),e._zod.parse=(i,a)=>{const c=i.value;return o.has(c)||i.issues.push({code:"invalid_value",values:n,input:c,inst:e}),i}}),Sr=m("$ZodLiteral",(e,t)=>{if(S.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(o=>typeof o=="string"?J(o):o?J(o.toString()):String(o)).join("|")})$`),e._zod.parse=(o,i)=>{const a=o.value;return n.has(a)||o.issues.push({code:"invalid_value",values:t.values,input:a,inst:e}),o}}),Ar=m("$ZodTransform",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new st(e.constructor.name);const i=t.transform(n.value,n);if(o.async)return(i instanceof Promise?i:Promise.resolve(i)).then(c=>(n.value=c,n));if(i instanceof Promise)throw new K;return n.value=i,n}});function It(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Tr=m("$ZodOptional",(e,t)=>{S.init(e,t),e._zod.optin="optional",e._zod.optout="optional",C(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),C(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Oe(n.source)})?$`):void 0}),e._zod.parse=(n,o)=>{if(t.innerType._zod.optin==="optional"){const i=t.innerType._zod.run(n,o);return i instanceof Promise?i.then(a=>It(a,n.value)):It(i,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,o)}}),zr=m("$ZodNullable",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.innerType._zod.optin),C(e._zod,"optout",()=>t.innerType._zod.optout),C(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Oe(n.source)}|null)$`):void 0}),C(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,o)=>n.value===null?n:t.innerType._zod.run(n,o)}),Ir=m("$ZodDefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)return n.value=t.defaultValue,n;const i=t.innerType._zod.run(n,o);return i instanceof Promise?i.then(a=>$t(a,t)):$t(i,t)}});function $t(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const $r=m("$ZodPrefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>(o.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,o))}),Or=m("$ZodNonOptional",(e,t)=>{S.init(e,t),C(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(o=>o!==void 0)):void 0}),e._zod.parse=(n,o)=>{const i=t.innerType._zod.run(n,o);return i instanceof Promise?i.then(a=>Ot(a,e)):Ot(i,e)}});function Ot(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Zr=m("$ZodCatch",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.innerType._zod.optin),C(e._zod,"optout",()=>t.innerType._zod.optout),C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);const i=t.innerType._zod.run(n,o);return i instanceof Promise?i.then(a=>(n.value=a.value,a.issues.length&&(n.value=t.catchValue({...n,error:{issues:a.issues.map(c=>M(c,o,N()))},input:n.value}),n.issues=[]),n)):(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(a=>M(a,o,N()))},input:n.value}),n.issues=[]),n)}}),Pr=m("$ZodPipe",(e,t)=>{S.init(e,t),C(e._zod,"values",()=>t.in._zod.values),C(e._zod,"optin",()=>t.in._zod.optin),C(e._zod,"optout",()=>t.out._zod.optout),C(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,o)=>{if(o.direction==="backward"){const a=t.out._zod.run(n,o);return a instanceof Promise?a.then(c=>_e(c,t.in,o)):_e(a,t.in,o)}const i=t.in._zod.run(n,o);return i instanceof Promise?i.then(a=>_e(a,t.out,o)):_e(i,t.out,o)}});function _e(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const xr=m("$ZodReadonly",(e,t)=>{S.init(e,t),C(e._zod,"propValues",()=>t.innerType._zod.propValues),C(e._zod,"values",()=>t.innerType._zod.values),C(e._zod,"optin",()=>t.innerType?._zod?.optin),C(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);const i=t.innerType._zod.run(n,o);return i instanceof Promise?i.then(Zt):Zt(i)}});function Zt(e){return e.value=Object.freeze(e.value),e}const Lr=m("$ZodCustom",(e,t)=>{Z.init(e,t),S.init(e,t),e._zod.parse=(n,o)=>n,e._zod.check=n=>{const o=n.value,i=t.fn(o);if(i instanceof Promise)return i.then(a=>Pt(a,n,o,e));Pt(i,n,o,e)}});function Pt(e,t,n,o){if(!e){const i={code:"custom",input:n,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};o._zod.def.params&&(i.params=o._zod.def.params),t.issues.push(re(i))}}var xt;class Rr{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const o=n[0];if(this._map.set(t,o),o&&typeof o=="object"&&"id"in o){if(this._idmap.has(o.id))throw new Error(`ID ${o.id} already exists in the registry`);this._idmap.set(o.id,t)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const o={...this.get(n)??{}};delete o.id;const i={...o,...this._map.get(t)};return Object.keys(i).length?i:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function jr(){return new Rr}(xt=globalThis).__zod_globalRegistry??(xt.__zod_globalRegistry=jr());const me=globalThis.__zod_globalRegistry;function Nr(e,t){return new e({type:"string",...b(t)})}function Dr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...b(t)})}function Lt(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...b(t)})}function Mr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...b(t)})}function Fr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...b(t)})}function Ur(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...b(t)})}function Vr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...b(t)})}function Br(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...b(t)})}function Gr(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...b(t)})}function Wr(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...b(t)})}function qr(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...b(t)})}function Kr(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...b(t)})}function Hr(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...b(t)})}function Jr(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...b(t)})}function Yr(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...b(t)})}function Qr(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...b(t)})}function Xr(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...b(t)})}function ei(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...b(t)})}function ti(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...b(t)})}function ni(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...b(t)})}function oi(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...b(t)})}function ri(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...b(t)})}function ii(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...b(t)})}function si(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...b(t)})}function ai(e,t){return new e({type:"string",format:"date",check:"string_format",...b(t)})}function ui(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...b(t)})}function ci(e,t){return new e({type:"string",format:"duration",check:"string_format",...b(t)})}function li(e,t){return new e({type:"number",checks:[],...b(t)})}function di(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...b(t)})}function pi(e,t){return new e({type:"null",...b(t)})}function fi(e){return new e({type:"unknown"})}function hi(e,t){return new e({type:"never",...b(t)})}function Rt(e,t){return new bt({check:"less_than",...b(t),value:e,inclusive:!1})}function je(e,t){return new bt({check:"less_than",...b(t),value:e,inclusive:!0})}function jt(e,t){return new wt({check:"greater_than",...b(t),value:e,inclusive:!1})}function Ne(e,t){return new wt({check:"greater_than",...b(t),value:e,inclusive:!0})}function Nt(e,t){return new zo({check:"multiple_of",...b(t),value:e})}function Dt(e,t){return new $o({check:"max_length",...b(t),maximum:e})}function ve(e,t){return new Oo({check:"min_length",...b(t),minimum:e})}function Mt(e,t){return new Zo({check:"length_equals",...b(t),length:e})}function _i(e,t){return new Po({check:"string_format",format:"regex",...b(t),pattern:e})}function mi(e){return new xo({check:"string_format",format:"lowercase",...b(e)})}function vi(e){return new Lo({check:"string_format",format:"uppercase",...b(e)})}function gi(e,t){return new Ro({check:"string_format",format:"includes",...b(t),includes:e})}function yi(e,t){return new jo({check:"string_format",format:"starts_with",...b(t),prefix:e})}function bi(e,t){return new No({check:"string_format",format:"ends_with",...b(t),suffix:e})}function Q(e){return new Do({check:"overwrite",tx:e})}function wi(e){return Q(t=>t.normalize(e))}function Ei(){return Q(e=>e.trim())}function ki(){return Q(e=>e.toLowerCase())}function Ci(){return Q(e=>e.toUpperCase())}function Si(){return Q(e=>On(e))}function Ai(e,t,n){return new e({type:"array",element:t,...b(n)})}function Ti(e,t,n){return new e({type:"custom",check:"custom",fn:t,...b(n)})}function zi(e){const t=Ii(n=>(n.addIssue=o=>{if(typeof o=="string")n.issues.push(re(o,n.value,t._zod.def));else{const i=o;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=t),i.continue??(i.continue=!t._zod.def.abort),n.issues.push(re(i))}},e(n.value,n)));return t}function Ii(e,t){const n=new Z({check:"custom",...b(t)});return n._zod.check=e,n}const $i=m("ZodISODateTime",(e,t)=>{Xo.init(e,t),O.init(e,t)});function Oi(e){return si($i,e)}const Zi=m("ZodISODate",(e,t)=>{er.init(e,t),O.init(e,t)});function Pi(e){return ai(Zi,e)}const xi=m("ZodISOTime",(e,t)=>{tr.init(e,t),O.init(e,t)});function Li(e){return ui(xi,e)}const Ri=m("ZodISODuration",(e,t)=>{nr.init(e,t),O.init(e,t)});function ji(e){return ci(Ri,e)}const P=m("ZodError",(e,t)=>{ft.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Bn(e,n)},flatten:{value:n=>Vn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ze,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ze,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Ni=Pe(P),Di=xe(P),Mi=le(P),Fi=de(P),Ui=qn(P),Vi=Kn(P),Bi=Hn(P),Gi=Jn(P),Wi=Yn(P),qi=Qn(P),Ki=Xn(P),Hi=eo(P),$=m("ZodType",(e,t)=>(S.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(V(t,{checks:[...t.checks??[],...n.map(o=>typeof o=="function"?{_zod:{check:o,def:{check:"custom"},onattach:[]}}:o)]})),e.clone=(n,o)=>D(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Ni(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Mi(e,n,o),e.parseAsync=async(n,o)=>Di(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Fi(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Ui(e,n,o),e.decode=(n,o)=>Vi(e,n,o),e.encodeAsync=async(n,o)=>Bi(e,n,o),e.decodeAsync=async(n,o)=>Gi(e,n,o),e.safeEncode=(n,o)=>Wi(e,n,o),e.safeDecode=(n,o)=>qi(e,n,o),e.safeEncodeAsync=async(n,o)=>Ki(e,n,o),e.safeDecodeAsync=async(n,o)=>Hi(e,n,o),e.refine=(n,o)=>e.check(Gs(n,o)),e.superRefine=n=>e.check(Ws(n)),e.overwrite=n=>e.check(Q(n)),e.optional=()=>qt(e),e.nullable=()=>Kt(e),e.nullish=()=>qt(Kt(e)),e.nonoptional=n=>Ns(e,n),e.array=()=>ws(e),e.or=n=>G([e,n]),e.and=n=>Ss(e,n),e.transform=n=>Jt(e,Zs(n)),e.default=n=>Ls(e,n),e.prefault=n=>js(e,n),e.catch=n=>Ms(e,n),e.pipe=n=>Jt(e,n),e.readonly=()=>Vs(e),e.describe=n=>{const o=e.clone();return me.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return me.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return me.get(e);const o=e.clone();return me.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Ft=m("_ZodString",(e,t)=>{Le.init(e,t),$.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...o)=>e.check(_i(...o)),e.includes=(...o)=>e.check(gi(...o)),e.startsWith=(...o)=>e.check(yi(...o)),e.endsWith=(...o)=>e.check(bi(...o)),e.min=(...o)=>e.check(ve(...o)),e.max=(...o)=>e.check(Dt(...o)),e.length=(...o)=>e.check(Mt(...o)),e.nonempty=(...o)=>e.check(ve(1,...o)),e.lowercase=o=>e.check(mi(o)),e.uppercase=o=>e.check(vi(o)),e.trim=()=>e.check(Ei()),e.normalize=(...o)=>e.check(wi(...o)),e.toLowerCase=()=>e.check(ki()),e.toUpperCase=()=>e.check(Ci()),e.slugify=()=>e.check(Si())}),Ji=m("ZodString",(e,t)=>{Le.init(e,t),Ft.init(e,t),e.email=n=>e.check(Dr(Yi,n)),e.url=n=>e.check(Br(Qi,n)),e.jwt=n=>e.check(ii(fs,n)),e.emoji=n=>e.check(Gr(Xi,n)),e.guid=n=>e.check(Lt(Ut,n)),e.uuid=n=>e.check(Mr(ge,n)),e.uuidv4=n=>e.check(Fr(ge,n)),e.uuidv6=n=>e.check(Ur(ge,n)),e.uuidv7=n=>e.check(Vr(ge,n)),e.nanoid=n=>e.check(Wr(es,n)),e.guid=n=>e.check(Lt(Ut,n)),e.cuid=n=>e.check(qr(ts,n)),e.cuid2=n=>e.check(Kr(ns,n)),e.ulid=n=>e.check(Hr(os,n)),e.base64=n=>e.check(ni(ls,n)),e.base64url=n=>e.check(oi(ds,n)),e.xid=n=>e.check(Jr(rs,n)),e.ksuid=n=>e.check(Yr(is,n)),e.ipv4=n=>e.check(Qr(ss,n)),e.ipv6=n=>e.check(Xr(as,n)),e.cidrv4=n=>e.check(ei(us,n)),e.cidrv6=n=>e.check(ti(cs,n)),e.e164=n=>e.check(ri(ps,n)),e.datetime=n=>e.check(Oi(n)),e.date=n=>e.check(Pi(n)),e.time=n=>e.check(Li(n)),e.duration=n=>e.check(ji(n))});function X(e){return Nr(Ji,e)}const O=m("ZodStringFormat",(e,t)=>{T.init(e,t),Ft.init(e,t)}),Yi=m("ZodEmail",(e,t)=>{Bo.init(e,t),O.init(e,t)}),Ut=m("ZodGUID",(e,t)=>{Uo.init(e,t),O.init(e,t)}),ge=m("ZodUUID",(e,t)=>{Vo.init(e,t),O.init(e,t)}),Qi=m("ZodURL",(e,t)=>{Go.init(e,t),O.init(e,t)}),Xi=m("ZodEmoji",(e,t)=>{Wo.init(e,t),O.init(e,t)}),es=m("ZodNanoID",(e,t)=>{qo.init(e,t),O.init(e,t)}),ts=m("ZodCUID",(e,t)=>{Ko.init(e,t),O.init(e,t)}),ns=m("ZodCUID2",(e,t)=>{Ho.init(e,t),O.init(e,t)}),os=m("ZodULID",(e,t)=>{Jo.init(e,t),O.init(e,t)}),rs=m("ZodXID",(e,t)=>{Yo.init(e,t),O.init(e,t)}),is=m("ZodKSUID",(e,t)=>{Qo.init(e,t),O.init(e,t)}),ss=m("ZodIPv4",(e,t)=>{or.init(e,t),O.init(e,t)}),as=m("ZodIPv6",(e,t)=>{rr.init(e,t),O.init(e,t)}),us=m("ZodCIDRv4",(e,t)=>{ir.init(e,t),O.init(e,t)}),cs=m("ZodCIDRv6",(e,t)=>{sr.init(e,t),O.init(e,t)}),ls=m("ZodBase64",(e,t)=>{ar.init(e,t),O.init(e,t)}),ds=m("ZodBase64URL",(e,t)=>{cr.init(e,t),O.init(e,t)}),ps=m("ZodE164",(e,t)=>{lr.init(e,t),O.init(e,t)}),fs=m("ZodJWT",(e,t)=>{pr.init(e,t),O.init(e,t)}),Vt=m("ZodNumber",(e,t)=>{kt.init(e,t),$.init(e,t),e.gt=(o,i)=>e.check(jt(o,i)),e.gte=(o,i)=>e.check(Ne(o,i)),e.min=(o,i)=>e.check(Ne(o,i)),e.lt=(o,i)=>e.check(Rt(o,i)),e.lte=(o,i)=>e.check(je(o,i)),e.max=(o,i)=>e.check(je(o,i)),e.int=o=>e.check(Bt(o)),e.safe=o=>e.check(Bt(o)),e.positive=o=>e.check(jt(0,o)),e.nonnegative=o=>e.check(Ne(0,o)),e.negative=o=>e.check(Rt(0,o)),e.nonpositive=o=>e.check(je(0,o)),e.multipleOf=(o,i)=>e.check(Nt(o,i)),e.step=(o,i)=>e.check(Nt(o,i)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function x(e){return li(Vt,e)}const hs=m("ZodNumberFormat",(e,t)=>{fr.init(e,t),Vt.init(e,t)});function Bt(e){return di(hs,e)}const _s=m("ZodNull",(e,t)=>{hr.init(e,t),$.init(e,t)});function ms(e){return pi(_s,e)}const vs=m("ZodUnknown",(e,t)=>{_r.init(e,t),$.init(e,t)});function Gt(){return fi(vs)}const gs=m("ZodNever",(e,t)=>{mr.init(e,t),$.init(e,t)});function ys(e){return hi(gs,e)}const bs=m("ZodArray",(e,t)=>{vr.init(e,t),$.init(e,t),e.element=t.element,e.min=(n,o)=>e.check(ve(n,o)),e.nonempty=n=>e.check(ve(1,n)),e.max=(n,o)=>e.check(Dt(n,o)),e.length=(n,o)=>e.check(Mt(n,o)),e.unwrap=()=>e.element});function ws(e,t){return Ai(bs,e,t)}const Es=m("ZodObject",(e,t)=>{yr.init(e,t),$.init(e,t),C(e,"shape",()=>t.shape),e.keyof=()=>Is(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Gt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Gt()}),e.strict=()=>e.clone({...e._zod.def,catchall:ys()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>Nn(e,n),e.safeExtend=n=>Dn(e,n),e.merge=n=>Mn(e,n),e.pick=n=>Rn(e,n),e.omit=n=>jn(e,n),e.partial=(...n)=>Fn(Wt,e,n[0]),e.required=(...n)=>Un(Ht,e,n[0])});function z(e,t){const n={type:"object",shape:e??{},...b(t)};return new Es(n)}const ks=m("ZodUnion",(e,t)=>{br.init(e,t),$.init(e,t),e.options=t.options});function G(e,t){return new ks({type:"union",options:e,...b(t)})}const Cs=m("ZodIntersection",(e,t)=>{wr.init(e,t),$.init(e,t)});function Ss(e,t){return new Cs({type:"intersection",left:e,right:t})}const As=m("ZodTuple",(e,t)=>{Er.init(e,t),$.init(e,t),e.rest=n=>e.clone({...e._zod.def,rest:n})});function L(e,t,n){const o=t instanceof S,i=o?n:t,a=o?t:null;return new As({type:"tuple",items:e,rest:a,...b(i)})}const Ts=m("ZodRecord",(e,t)=>{kr.init(e,t),$.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function zs(e,t,n){return new Ts({type:"record",keyType:e,valueType:t,...b(n)})}const De=m("ZodEnum",(e,t)=>{Cr.init(e,t),$.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(o,i)=>{const a={};for(const c of o)if(n.has(c))a[c]=t.entries[c];else throw new Error(`Key ${c} not found in enum`);return new De({...t,checks:[],...b(i),entries:a})},e.exclude=(o,i)=>{const a={...t.entries};for(const c of o)if(n.has(c))delete a[c];else throw new Error(`Key ${c} not found in enum`);return new De({...t,checks:[],...b(i),entries:a})}});function Is(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(o=>[o,o])):e;return new De({type:"enum",entries:n,...b(t)})}const $s=m("ZodLiteral",(e,t)=>{Sr.init(e,t),$.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function j(e,t){return new $s({type:"literal",values:Array.isArray(e)?e:[e],...b(t)})}const Os=m("ZodTransform",(e,t)=>{Ar.init(e,t),$.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new st(e.constructor.name);n.addIssue=a=>{if(typeof a=="string")n.issues.push(re(a,n.value,t));else{const c=a;c.fatal&&(c.continue=!1),c.code??(c.code="custom"),c.input??(c.input=n.value),c.inst??(c.inst=e),n.issues.push(re(c))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(a=>(n.value=a,n)):(n.value=i,n)}});function Zs(e){return new Os({type:"transform",transform:e})}const Wt=m("ZodOptional",(e,t)=>{Tr.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function qt(e){return new Wt({type:"optional",innerType:e})}const Ps=m("ZodNullable",(e,t)=>{zr.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Kt(e){return new Ps({type:"nullable",innerType:e})}const xs=m("ZodDefault",(e,t)=>{Ir.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ls(e,t){return new xs({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():dt(t)}})}const Rs=m("ZodPrefault",(e,t)=>{$r.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function js(e,t){return new Rs({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():dt(t)}})}const Ht=m("ZodNonOptional",(e,t)=>{Or.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ns(e,t){return new Ht({type:"nonoptional",innerType:e,...b(t)})}const Ds=m("ZodCatch",(e,t)=>{Zr.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Ms(e,t){return new Ds({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Fs=m("ZodPipe",(e,t)=>{Pr.init(e,t),$.init(e,t),e.in=t.in,e.out=t.out});function Jt(e,t){return new Fs({type:"pipe",in:e,out:t})}const Us=m("ZodReadonly",(e,t)=>{xr.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Vs(e){return new Us({type:"readonly",innerType:e})}const Bs=m("ZodCustom",(e,t)=>{Lr.init(e,t),$.init(e,t)});function Gs(e,t={}){return Ti(Bs,e,t)}function Ws(e){return zi(e)}const ye=z({t:x().gte(0),rate:x().gte(0)}),ee=z({opacity:x().gte(0).lte(1),zIndex:x()}),te=z({volume:x().gte(0).lte(1)}),qs=z({type:j("image"),file:X(),fit:G([j("contain"),j("cover"),j("none")])}),Ks=z({type:j("audio"),file:X(),audioOutput:X()}),Hs=z({type:j("video"),file:X(),audioOutput:X(),fit:G([j("contain"),j("cover"),j("none")])}),Me=L([x(),ms()]),Js=L([x(),z({set:z({...ee.shape}).partial()}).partial()]),Ys=L([x(),z({set:z({...ee.shape}).partial(),lerp:z({...ee.shape}).partial()}).partial()]),Qs=L([x(),z({set:z({...ye.shape,...te.shape}).partial()}).partial()]),Xs=L([x(),z({set:z({...ye.shape,...te.shape}).partial(),lerp:z({...te.shape}).partial()}).partial()]),ea=L([x(),z({set:z({...ye.shape,...te.shape,...ee.shape}).partial()}).partial()]),ta=L([x(),z({set:z({...ye.shape,...te.shape,...ee.shape}).partial(),lerp:z({...te.shape,...ee.shape}).partial()}).partial()]),na=z({...qs.shape,keyframes:L([Ys],G([Js,Me]))}),oa=z({...Ks.shape,keyframes:L([Xs],G([Qs,Me]))}),ra=z({...Hs.shape,keyframes:L([ta],G([ea,Me]))}),ia=zs(X(),G([na,oa,ra])),be={opacity:1,zIndex:0},we={t:0,rate:1,volume:1},ie={t:0,rate:1,volume:1,opacity:1,zIndex:0},sa=Object.freeze(Object.defineProperty({__proto__:null,MediaSurfaceStateSchema:ia,defaultAudioOptions:we,defaultImageOptions:be,defaultVideoOptions:ie},Symbol.toStringTag,{value:"Module"}));var Fe={},Yt;function aa(){return Yt||(Yt=1,function(e){var t={};/*! howler.js v2.2.1 | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */(function(){var n=function(){this.init()};n.prototype={init:function(){var r=this||o;return r._counter=1e3,r._html5AudioPool=[],r.html5PoolSize=10,r._codecs={},r._howls=[],r._muted=!1,r._volume=1,r._canPlayEvent="canplaythrough",r._navigator=typeof window<"u"&&window.navigator?window.navigator:null,r.masterGain=null,r.noAudio=!1,r.usingWebAudio=!0,r.autoSuspend=!0,r.ctx=null,r.autoUnlock=!0,r._setup(),r},volume:function(r){var s=this||o;if(r=parseFloat(r),s.ctx||g(),r!==void 0&&r>=0&&r<=1){if(s._volume=r,s._muted)return s;s.usingWebAudio&&s.masterGain.gain.setValueAtTime(r,o.ctx.currentTime);for(var u=0;u<s._howls.length;u++)if(!s._howls[u]._webAudio)for(var d=s._howls[u]._getSoundIds(),f=0;f<d.length;f++){var v=s._howls[u]._soundById(d[f]);v&&v._node&&(v._node.volume=v._volume*r)}return s}return s._volume},mute:function(r){var s=this||o;s.ctx||g(),s._muted=r,s.usingWebAudio&&s.masterGain.gain.setValueAtTime(r?0:s._volume,o.ctx.currentTime);for(var u=0;u<s._howls.length;u++)if(!s._howls[u]._webAudio)for(var d=s._howls[u]._getSoundIds(),f=0;f<d.length;f++){var v=s._howls[u]._soundById(d[f]);v&&v._node&&(v._node.muted=!!r||v._muted)}return s},stop:function(){for(var r=this||o,s=0;s<r._howls.length;s++)r._howls[s].stop();return r},unload:function(){for(var r=this||o,s=r._howls.length-1;s>=0;s--)r._howls[s].unload();return r.usingWebAudio&&r.ctx&&r.ctx.close!==void 0&&(r.ctx.close(),r.ctx=null,g()),r},codecs:function(r){return(this||o)._codecs[r.replace(/^x-/,"")]},_setup:function(){var r=this||o;if(r.state=r.ctx&&r.ctx.state||"suspended",r._autoSuspend(),!r.usingWebAudio)if(typeof Audio<"u")try{var s=new Audio;s.oncanplaythrough===void 0&&(r._canPlayEvent="canplay")}catch{r.noAudio=!0}else r.noAudio=!0;try{var s=new Audio;s.muted&&(r.noAudio=!0)}catch{}return r.noAudio||r._setupCodecs(),r},_setupCodecs:function(){var r=this||o,s=null;try{s=typeof Audio<"u"?new Audio:null}catch{return r}if(!s||typeof s.canPlayType!="function")return r;var u=s.canPlayType("audio/mpeg;").replace(/^no$/,""),d=r._navigator&&r._navigator.userAgent.match(/OPR\/([0-6].)/g),f=d&&parseInt(d[0].split("/")[1],10)<33;return r._codecs={mp3:!(f||!u&&!s.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!u,opus:!!s.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!s.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!s.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(s.canPlayType('audio/wav; codecs="1"')||s.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!s.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!s.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(s.canPlayType("audio/x-m4a;")||s.canPlayType("audio/m4a;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(s.canPlayType("audio/x-m4b;")||s.canPlayType("audio/m4b;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(s.canPlayType("audio/x-mp4;")||s.canPlayType("audio/mp4;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!s.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),webm:!!s.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),dolby:!!s.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(s.canPlayType("audio/x-flac;")||s.canPlayType("audio/flac;")).replace(/^no$/,"")},r},_unlockAudio:function(){var r=this||o;if(!r._audioUnlocked&&r.ctx){r._audioUnlocked=!1,r.autoUnlock=!1,r._mobileUnloaded||r.ctx.sampleRate===44100||(r._mobileUnloaded=!0,r.unload()),r._scratchBuffer=r.ctx.createBuffer(1,1,22050);var s=function(u){for(;r._html5AudioPool.length<r.html5PoolSize;)try{var d=new Audio;d._unlocked=!0,r._releaseHtml5Audio(d)}catch{r.noAudio=!0;break}for(var f=0;f<r._howls.length;f++)if(!r._howls[f]._webAudio)for(var v=r._howls[f]._getSoundIds(),_=0;_<v.length;_++){var w=r._howls[f]._soundById(v[_]);w&&w._node&&!w._node._unlocked&&(w._node._unlocked=!0,w._node.load())}r._autoResume();var E=r.ctx.createBufferSource();E.buffer=r._scratchBuffer,E.connect(r.ctx.destination),E.start===void 0?E.noteOn(0):E.start(0),typeof r.ctx.resume=="function"&&r.ctx.resume(),E.onended=function(){E.disconnect(0),r._audioUnlocked=!0,document.removeEventListener("touchstart",s,!0),document.removeEventListener("touchend",s,!0),document.removeEventListener("click",s,!0);for(var k=0;k<r._howls.length;k++)r._howls[k]._emit("unlock")}};return document.addEventListener("touchstart",s,!0),document.addEventListener("touchend",s,!0),document.addEventListener("click",s,!0),r}},_obtainHtml5Audio:function(){var r=this||o;if(r._html5AudioPool.length)return r._html5AudioPool.pop();var s=new Audio().play();return s&&typeof Promise<"u"&&(s instanceof Promise||typeof s.then=="function")&&s.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(r){var s=this||o;return r._unlocked&&s._html5AudioPool.push(r),s},_autoSuspend:function(){var r=this;if(r.autoSuspend&&r.ctx&&r.ctx.suspend!==void 0&&o.usingWebAudio){for(var s=0;s<r._howls.length;s++)if(r._howls[s]._webAudio){for(var u=0;u<r._howls[s]._sounds.length;u++)if(!r._howls[s]._sounds[u]._paused)return r}return r._suspendTimer&&clearTimeout(r._suspendTimer),r._suspendTimer=setTimeout(function(){if(r.autoSuspend){r._suspendTimer=null,r.state="suspending";var d=function(){r.state="suspended",r._resumeAfterSuspend&&(delete r._resumeAfterSuspend,r._autoResume())};r.ctx.suspend().then(d,d)}},3e4),r}},_autoResume:function(){var r=this;if(r.ctx&&r.ctx.resume!==void 0&&o.usingWebAudio)return r.state==="running"&&r.ctx.state!=="interrupted"&&r._suspendTimer?(clearTimeout(r._suspendTimer),r._suspendTimer=null):r.state==="suspended"||r.state==="running"&&r.ctx.state==="interrupted"?(r.ctx.resume().then(function(){r.state="running";for(var s=0;s<r._howls.length;s++)r._howls[s]._emit("resume")}),r._suspendTimer&&(clearTimeout(r._suspendTimer),r._suspendTimer=null)):r.state==="suspending"&&(r._resumeAfterSuspend=!0),r}};var o=new n,i=function(r){var s=this;if(!r.src||r.src.length===0)return void console.error("An array of source files must be passed with any new Howl.");s.init(r)};i.prototype={init:function(r){var s=this;return o.ctx||g(),s._autoplay=r.autoplay||!1,s._format=typeof r.format!="string"?r.format:[r.format],s._html5=r.html5||!1,s._muted=r.mute||!1,s._loop=r.loop||!1,s._pool=r.pool||5,s._preload=typeof r.preload!="boolean"&&r.preload!=="metadata"||r.preload,s._rate=r.rate||1,s._sprite=r.sprite||{},s._src=typeof r.src!="string"?r.src:[r.src],s._volume=r.volume!==void 0?r.volume:1,s._xhr={method:r.xhr&&r.xhr.method?r.xhr.method:"GET",headers:r.xhr&&r.xhr.headers?r.xhr.headers:null,withCredentials:!(!r.xhr||!r.xhr.withCredentials)&&r.xhr.withCredentials},s._duration=0,s._state="unloaded",s._sounds=[],s._endTimers={},s._queue=[],s._playLock=!1,s._onend=r.onend?[{fn:r.onend}]:[],s._onfade=r.onfade?[{fn:r.onfade}]:[],s._onload=r.onload?[{fn:r.onload}]:[],s._onloaderror=r.onloaderror?[{fn:r.onloaderror}]:[],s._onplayerror=r.onplayerror?[{fn:r.onplayerror}]:[],s._onpause=r.onpause?[{fn:r.onpause}]:[],s._onplay=r.onplay?[{fn:r.onplay}]:[],s._onstop=r.onstop?[{fn:r.onstop}]:[],s._onmute=r.onmute?[{fn:r.onmute}]:[],s._onvolume=r.onvolume?[{fn:r.onvolume}]:[],s._onrate=r.onrate?[{fn:r.onrate}]:[],s._onseek=r.onseek?[{fn:r.onseek}]:[],s._onunlock=r.onunlock?[{fn:r.onunlock}]:[],s._onresume=[],s._webAudio=o.usingWebAudio&&!s._html5,o.ctx!==void 0&&o.ctx&&o.autoUnlock&&o._unlockAudio(),o._howls.push(s),s._autoplay&&s._queue.push({event:"play",action:function(){s.play()}}),s._preload&&s._preload!=="none"&&s.load(),s},load:function(){var r=this,s=null;if(o.noAudio)return void r._emit("loaderror",null,"No audio support.");typeof r._src=="string"&&(r._src=[r._src]);for(var u=0;u<r._src.length;u++){var d,f;if(r._format&&r._format[u])d=r._format[u];else{if(typeof(f=r._src[u])!="string"){r._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}d=/^data:audio\/([^;,]+);/i.exec(f),d||(d=/\.([^.]+)$/.exec(f.split("?",1)[0])),d&&(d=d[1].toLowerCase())}if(d||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),d&&o.codecs(d)){s=r._src[u];break}}return s?(r._src=s,r._state="loading",window.location.protocol==="https:"&&s.slice(0,5)==="http:"&&(r._html5=!0,r._webAudio=!1),new a(r),r._webAudio&&l(r),r):void r._emit("loaderror",null,"No codec support for selected audio sources.")},play:function(r,s){var u=this,d=null;if(typeof r=="number")d=r,r=null;else{if(typeof r=="string"&&u._state==="loaded"&&!u._sprite[r])return null;if(r===void 0&&(r="__default",!u._playLock)){for(var f=0,v=0;v<u._sounds.length;v++)u._sounds[v]._paused&&!u._sounds[v]._ended&&(f++,d=u._sounds[v]._id);f===1?r=null:d=null}}var _=d?u._soundById(d):u._inactiveSound();if(!_)return null;if(d&&!r&&(r=_._sprite||"__default"),u._state!=="loaded"){_._sprite=r,_._ended=!1;var w=_._id;return u._queue.push({event:"play",action:function(){u.play(w)}}),w}if(d&&!_._paused)return s||u._loadQueue("play"),_._id;u._webAudio&&o._autoResume();var E=Math.max(0,_._seek>0?_._seek:u._sprite[r][0]/1e3),k=Math.max(0,(u._sprite[r][0]+u._sprite[r][1])/1e3-E),R=1e3*k/Math.abs(_._rate),W=u._sprite[r][0]/1e3,Ce=(u._sprite[r][0]+u._sprite[r][1])/1e3;_._sprite=r,_._ended=!1;var qe=function(){_._paused=!1,_._seek=E,_._start=W,_._stop=Ce,_._loop=!(!_._loop&&!u._sprite[r][2])};if(E>=Ce)return void u._ended(_);var I=_._node;if(u._webAudio){var an=function(){u._playLock=!1,qe(),u._refreshBuffer(_);var ne=_._muted||u._muted?0:_._volume;I.gain.setValueAtTime(ne,o.ctx.currentTime),_._playStart=o.ctx.currentTime,I.bufferSource.start===void 0?_._loop?I.bufferSource.noteGrainOn(0,E,86400):I.bufferSource.noteGrainOn(0,E,k):_._loop?I.bufferSource.start(0,E,86400):I.bufferSource.start(0,E,k),R!==1/0&&(u._endTimers[_._id]=setTimeout(u._ended.bind(u,_),R)),s||setTimeout(function(){u._emit("play",_._id),u._loadQueue()},0)};o.state==="running"&&o.ctx.state!=="interrupted"?an():(u._playLock=!0,u.once("resume",an),u._clearTimer(_._id))}else{var un=function(){I.currentTime=E,I.muted=_._muted||u._muted||o._muted||I.muted,I.volume=_._volume*o.volume(),I.playbackRate=_._rate;try{var ne=I.play();if(ne&&typeof Promise<"u"&&(ne instanceof Promise||typeof ne.then=="function")?(u._playLock=!0,qe(),ne.then(function(){u._playLock=!1,I._unlocked=!0,s||(u._emit("play",_._id),u._loadQueue())}).catch(function(){u._playLock=!1,u._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."),_._ended=!0,_._paused=!0})):s||(u._playLock=!1,qe(),u._emit("play",_._id),u._loadQueue()),I.playbackRate=_._rate,I.paused)return void u._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");r!=="__default"||_._loop?u._endTimers[_._id]=setTimeout(u._ended.bind(u,_),R):(u._endTimers[_._id]=function(){u._ended(_),I.removeEventListener("ended",u._endTimers[_._id],!1)},I.addEventListener("ended",u._endTimers[_._id],!1))}catch($a){u._emit("playerror",_._id,$a)}};I.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(I.src=u._src,I.load());var Ia=window&&window.ejecta||!I.readyState&&o._navigator.isCocoonJS;if(I.readyState>=3||Ia)un();else{u._playLock=!0;var cn=function(){un(),I.removeEventListener(o._canPlayEvent,cn,!1)};I.addEventListener(o._canPlayEvent,cn,!1),u._clearTimer(_._id)}}return _._id},pause:function(r){var s=this;if(s._state!=="loaded"||s._playLock)return s._queue.push({event:"pause",action:function(){s.pause(r)}}),s;for(var u=s._getSoundIds(r),d=0;d<u.length;d++){s._clearTimer(u[d]);var f=s._soundById(u[d]);if(f&&!f._paused&&(f._seek=s.seek(u[d]),f._rateSeek=0,f._paused=!0,s._stopFade(u[d]),f._node))if(s._webAudio){if(!f._node.bufferSource)continue;f._node.bufferSource.stop===void 0?f._node.bufferSource.noteOff(0):f._node.bufferSource.stop(0),s._cleanBuffer(f._node)}else isNaN(f._node.duration)&&f._node.duration!==1/0||f._node.pause();arguments[1]||s._emit("pause",f?f._id:null)}return s},stop:function(r,s){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"stop",action:function(){u.stop(r,s)}}),u;for(var d=u._getSoundIds(r),f=0;f<d.length;f++){u._clearTimer(d[f]);var v=u._soundById(d[f]);v&&(v._seek=v._start||0,v._rateSeek=0,v._paused=!0,v._ended=!0,u._stopFade(d[f]),v._node&&(u._webAudio?v._node.bufferSource&&(v._node.bufferSource.stop===void 0?v._node.bufferSource.noteOff(0):v._node.bufferSource.stop(0),u._cleanBuffer(v._node)):isNaN(v._node.duration)&&v._node.duration!==1/0||(v._node.currentTime=v._start||0,v._node.pause(),v._node.duration===1/0&&u._clearSound(v._node))),s||u._emit("stop",v._id))}return u},mute:function(r,s){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"mute",action:function(){u.mute(r,s)}}),u;if(s===void 0){if(typeof r!="boolean")return u._muted;u._muted=r}for(var d=u._getSoundIds(s),f=0;f<d.length;f++){var v=u._soundById(d[f]);v&&(v._muted=r,v._interval&&u._stopFade(v._id),u._webAudio&&v._node?v._node.gain.setValueAtTime(r?0:v._volume,o.ctx.currentTime):v._node&&(v._node.muted=!!o._muted||r),u._emit("mute",v._id))}return u},volume:function(){var r,s,u=this,d=arguments;if(d.length===0)return u._volume;d.length===1||d.length===2&&d[1]===void 0?u._getSoundIds().indexOf(d[0])>=0?s=parseInt(d[0],10):r=parseFloat(d[0]):d.length>=2&&(r=parseFloat(d[0]),s=parseInt(d[1],10));var f;if(!(r!==void 0&&r>=0&&r<=1))return f=s?u._soundById(s):u._sounds[0],f?f._volume:0;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"volume",action:function(){u.volume.apply(u,d)}}),u;s===void 0&&(u._volume=r),s=u._getSoundIds(s);for(var v=0;v<s.length;v++)(f=u._soundById(s[v]))&&(f._volume=r,d[2]||u._stopFade(s[v]),u._webAudio&&f._node&&!f._muted?f._node.gain.setValueAtTime(r,o.ctx.currentTime):f._node&&!f._muted&&(f._node.volume=r*o.volume()),u._emit("volume",f._id));return u},fade:function(r,s,u,d){var f=this;if(f._state!=="loaded"||f._playLock)return f._queue.push({event:"fade",action:function(){f.fade(r,s,u,d)}}),f;r=Math.min(Math.max(0,parseFloat(r)),1),s=Math.min(Math.max(0,parseFloat(s)),1),u=parseFloat(u),f.volume(r,d);for(var v=f._getSoundIds(d),_=0;_<v.length;_++){var w=f._soundById(v[_]);if(w){if(d||f._stopFade(v[_]),f._webAudio&&!w._muted){var E=o.ctx.currentTime,k=E+u/1e3;w._volume=r,w._node.gain.setValueAtTime(r,E),w._node.gain.linearRampToValueAtTime(s,k)}f._startFadeInterval(w,r,s,u,v[_],d===void 0)}}return f},_startFadeInterval:function(r,s,u,d,f,v){var _=this,w=s,E=u-s,k=Math.abs(E/.01),R=Math.max(4,k>0?d/k:d),W=Date.now();r._fadeTo=u,r._interval=setInterval(function(){var Ce=(Date.now()-W)/d;W=Date.now(),w+=E*Ce,w=Math.round(100*w)/100,w=E<0?Math.max(u,w):Math.min(u,w),_._webAudio?r._volume=w:_.volume(w,r._id,!0),v&&(_._volume=w),(u<s&&w<=u||u>s&&w>=u)&&(clearInterval(r._interval),r._interval=null,r._fadeTo=null,_.volume(u,r._id),_._emit("fade",r._id))},R)},_stopFade:function(r){var s=this,u=s._soundById(r);return u&&u._interval&&(s._webAudio&&u._node.gain.cancelScheduledValues(o.ctx.currentTime),clearInterval(u._interval),u._interval=null,s.volume(u._fadeTo,r),u._fadeTo=null,s._emit("fade",r)),s},loop:function(){var r,s,u,d=this,f=arguments;if(f.length===0)return d._loop;if(f.length===1){if(typeof f[0]!="boolean")return!!(u=d._soundById(parseInt(f[0],10)))&&u._loop;r=f[0],d._loop=r}else f.length===2&&(r=f[0],s=parseInt(f[1],10));for(var v=d._getSoundIds(s),_=0;_<v.length;_++)(u=d._soundById(v[_]))&&(u._loop=r,d._webAudio&&u._node&&u._node.bufferSource&&(u._node.bufferSource.loop=r,r&&(u._node.bufferSource.loopStart=u._start||0,u._node.bufferSource.loopEnd=u._stop)));return d},rate:function(){var r,s,u=this,d=arguments;if(d.length===0)s=u._sounds[0]._id;else if(d.length===1){var f=u._getSoundIds(),v=f.indexOf(d[0]);v>=0?s=parseInt(d[0],10):r=parseFloat(d[0])}else d.length===2&&(r=parseFloat(d[0]),s=parseInt(d[1],10));var _;if(typeof r!="number")return _=u._soundById(s),_?_._rate:u._rate;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"rate",action:function(){u.rate.apply(u,d)}}),u;s===void 0&&(u._rate=r),s=u._getSoundIds(s);for(var w=0;w<s.length;w++)if(_=u._soundById(s[w])){u.playing(s[w])&&(_._rateSeek=u.seek(s[w]),_._playStart=u._webAudio?o.ctx.currentTime:_._playStart),_._rate=r,u._webAudio&&_._node&&_._node.bufferSource?_._node.bufferSource.playbackRate.setValueAtTime(r,o.ctx.currentTime):_._node&&(_._node.playbackRate=r);var E=u.seek(s[w]),k=(u._sprite[_._sprite][0]+u._sprite[_._sprite][1])/1e3-E,R=1e3*k/Math.abs(_._rate);!u._endTimers[s[w]]&&_._paused||(u._clearTimer(s[w]),u._endTimers[s[w]]=setTimeout(u._ended.bind(u,_),R)),u._emit("rate",_._id)}return u},seek:function(){var r,s,u=this,d=arguments;if(d.length===0)s=u._sounds[0]._id;else if(d.length===1){var f=u._getSoundIds(),v=f.indexOf(d[0]);v>=0?s=parseInt(d[0],10):u._sounds.length&&(s=u._sounds[0]._id,r=parseFloat(d[0]))}else d.length===2&&(r=parseFloat(d[0]),s=parseInt(d[1],10));if(s===void 0)return u;if(typeof r=="number"&&(u._state!=="loaded"||u._playLock))return u._queue.push({event:"seek",action:function(){u.seek.apply(u,d)}}),u;var _=u._soundById(s);if(_){if(!(typeof r=="number"&&r>=0)){if(u._webAudio){var w=u.playing(s)?o.ctx.currentTime-_._playStart:0,E=_._rateSeek?_._rateSeek-_._seek:0;return _._seek+(E+w*Math.abs(_._rate))}return _._node.currentTime}var k=u.playing(s);k&&u.pause(s,!0),_._seek=r,_._ended=!1,u._clearTimer(s),u._webAudio||!_._node||isNaN(_._node.duration)||(_._node.currentTime=r);var R=function(){u._emit("seek",s),k&&u.play(s,!0)};if(k&&!u._webAudio){var W=function(){u._playLock?setTimeout(W,0):R()};setTimeout(W,0)}else R()}return u},playing:function(r){var s=this;if(typeof r=="number"){var u=s._soundById(r);return!!u&&!u._paused}for(var d=0;d<s._sounds.length;d++)if(!s._sounds[d]._paused)return!0;return!1},duration:function(r){var s=this,u=s._duration,d=s._soundById(r);return d&&(u=s._sprite[d._sprite][1]/1e3),u},state:function(){return this._state},unload:function(){for(var r=this,s=r._sounds,u=0;u<s.length;u++)s[u]._paused||r.stop(s[u]._id),r._webAudio||(r._clearSound(s[u]._node),s[u]._node.removeEventListener("error",s[u]._errorFn,!1),s[u]._node.removeEventListener(o._canPlayEvent,s[u]._loadFn,!1),s[u]._node.removeEventListener("ended",s[u]._endFn,!1),o._releaseHtml5Audio(s[u]._node)),delete s[u]._node,r._clearTimer(s[u]._id);var d=o._howls.indexOf(r);d>=0&&o._howls.splice(d,1);var f=!0;for(u=0;u<o._howls.length;u++)if(o._howls[u]._src===r._src||r._src.indexOf(o._howls[u]._src)>=0){f=!1;break}return c&&f&&delete c[r._src],o.noAudio=!1,r._state="unloaded",r._sounds=[],r=null,null},on:function(r,s,u,d){var f=this,v=f["_on"+r];return typeof s=="function"&&v.push(d?{id:u,fn:s,once:d}:{id:u,fn:s}),f},off:function(r,s,u){var d=this,f=d["_on"+r],v=0;if(typeof s=="number"&&(u=s,s=null),s||u)for(v=0;v<f.length;v++){var _=u===f[v].id;if(s===f[v].fn&&_||!s&&_){f.splice(v,1);break}}else if(r)d["_on"+r]=[];else{var w=Object.keys(d);for(v=0;v<w.length;v++)w[v].indexOf("_on")===0&&Array.isArray(d[w[v]])&&(d[w[v]]=[])}return d},once:function(r,s,u){var d=this;return d.on(r,s,u,1),d},_emit:function(r,s,u){for(var d=this,f=d["_on"+r],v=f.length-1;v>=0;v--)f[v].id&&f[v].id!==s&&r!=="load"||(setTimeout((function(_){_.call(this,s,u)}).bind(d,f[v].fn),0),f[v].once&&d.off(r,f[v].fn,f[v].id));return d._loadQueue(r),d},_loadQueue:function(r){var s=this;if(s._queue.length>0){var u=s._queue[0];u.event===r&&(s._queue.shift(),s._loadQueue()),r||u.action()}return s},_ended:function(r){var s=this,u=r._sprite;if(!s._webAudio&&r._node&&!r._node.paused&&!r._node.ended&&r._node.currentTime<r._stop)return setTimeout(s._ended.bind(s,r),100),s;var d=!(!r._loop&&!s._sprite[u][2]);if(s._emit("end",r._id),!s._webAudio&&d&&s.stop(r._id,!0).play(r._id),s._webAudio&&d){s._emit("play",r._id),r._seek=r._start||0,r._rateSeek=0,r._playStart=o.ctx.currentTime;var f=1e3*(r._stop-r._start)/Math.abs(r._rate);s._endTimers[r._id]=setTimeout(s._ended.bind(s,r),f)}return s._webAudio&&!d&&(r._paused=!0,r._ended=!0,r._seek=r._start||0,r._rateSeek=0,s._clearTimer(r._id),s._cleanBuffer(r._node),o._autoSuspend()),s._webAudio||d||s.stop(r._id,!0),s},_clearTimer:function(r){var s=this;if(s._endTimers[r]){if(typeof s._endTimers[r]!="function")clearTimeout(s._endTimers[r]);else{var u=s._soundById(r);u&&u._node&&u._node.removeEventListener("ended",s._endTimers[r],!1)}delete s._endTimers[r]}return s},_soundById:function(r){for(var s=this,u=0;u<s._sounds.length;u++)if(r===s._sounds[u]._id)return s._sounds[u];return null},_inactiveSound:function(){var r=this;r._drain();for(var s=0;s<r._sounds.length;s++)if(r._sounds[s]._ended)return r._sounds[s].reset();return new a(r)},_drain:function(){var r=this,s=r._pool,u=0,d=0;if(!(r._sounds.length<s)){for(d=0;d<r._sounds.length;d++)r._sounds[d]._ended&&u++;for(d=r._sounds.length-1;d>=0;d--){if(u<=s)return;r._sounds[d]._ended&&(r._webAudio&&r._sounds[d]._node&&r._sounds[d]._node.disconnect(0),r._sounds.splice(d,1),u--)}}},_getSoundIds:function(r){var s=this;if(r===void 0){for(var u=[],d=0;d<s._sounds.length;d++)u.push(s._sounds[d]._id);return u}return[r]},_refreshBuffer:function(r){var s=this;return r._node.bufferSource=o.ctx.createBufferSource(),r._node.bufferSource.buffer=c[s._src],r._panner?r._node.bufferSource.connect(r._panner):r._node.bufferSource.connect(r._node),r._node.bufferSource.loop=r._loop,r._loop&&(r._node.bufferSource.loopStart=r._start||0,r._node.bufferSource.loopEnd=r._stop||0),r._node.bufferSource.playbackRate.setValueAtTime(r._rate,o.ctx.currentTime),s},_cleanBuffer:function(r){var s=this,u=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(o._scratchBuffer&&r.bufferSource&&(r.bufferSource.onended=null,r.bufferSource.disconnect(0),u))try{r.bufferSource.buffer=o._scratchBuffer}catch{}return r.bufferSource=null,s},_clearSound:function(r){/MSIE |Trident\//.test(o._navigator&&o._navigator.userAgent)||(r.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var a=function(r){this._parent=r,this.init()};a.prototype={init:function(){var r=this,s=r._parent;return r._muted=s._muted,r._loop=s._loop,r._volume=s._volume,r._rate=s._rate,r._seek=0,r._paused=!0,r._ended=!0,r._sprite="__default",r._id=++o._counter,s._sounds.push(r),r.create(),r},create:function(){var r=this,s=r._parent,u=o._muted||r._muted||r._parent._muted?0:r._volume;return s._webAudio?(r._node=o.ctx.createGain===void 0?o.ctx.createGainNode():o.ctx.createGain(),r._node.gain.setValueAtTime(u,o.ctx.currentTime),r._node.paused=!0,r._node.connect(o.masterGain)):o.noAudio||(r._node=o._obtainHtml5Audio(),r._errorFn=r._errorListener.bind(r),r._node.addEventListener("error",r._errorFn,!1),r._loadFn=r._loadListener.bind(r),r._node.addEventListener(o._canPlayEvent,r._loadFn,!1),r._endFn=r._endListener.bind(r),r._node.addEventListener("ended",r._endFn,!1),r._node.src=s._src,r._node.preload=s._preload===!0?"auto":s._preload,r._node.volume=u*o.volume(),r._node.load()),r},reset:function(){var r=this,s=r._parent;return r._muted=s._muted,r._loop=s._loop,r._volume=s._volume,r._rate=s._rate,r._seek=0,r._rateSeek=0,r._paused=!0,r._ended=!0,r._sprite="__default",r._id=++o._counter,r},_errorListener:function(){var r=this;r._parent._emit("loaderror",r._id,r._node.error?r._node.error.code:0),r._node.removeEventListener("error",r._errorFn,!1)},_loadListener:function(){var r=this,s=r._parent;s._duration=Math.ceil(10*r._node.duration)/10,Object.keys(s._sprite).length===0&&(s._sprite={__default:[0,1e3*s._duration]}),s._state!=="loaded"&&(s._state="loaded",s._emit("load"),s._loadQueue()),r._node.removeEventListener(o._canPlayEvent,r._loadFn,!1)},_endListener:function(){var r=this,s=r._parent;s._duration===1/0&&(s._duration=Math.ceil(10*r._node.duration)/10,s._sprite.__default[1]===1/0&&(s._sprite.__default[1]=1e3*s._duration),s._ended(r)),r._node.removeEventListener("ended",r._endFn,!1)}};var c={},l=function(r){var s=r._src;if(c[s])return r._duration=c[s].duration,void y(r);if(/^data:[^;]+;base64,/.test(s)){for(var u=atob(s.split(",")[1]),d=new Uint8Array(u.length),f=0;f<u.length;++f)d[f]=u.charCodeAt(f);h(d.buffer,r)}else{var v=new XMLHttpRequest;v.open(r._xhr.method,s,!0),v.withCredentials=r._xhr.withCredentials,v.responseType="arraybuffer",r._xhr.headers&&Object.keys(r._xhr.headers).forEach(function(_){v.setRequestHeader(_,r._xhr.headers[_])}),v.onload=function(){var _=(v.status+"")[0];if(_!=="0"&&_!=="2"&&_!=="3")return void r._emit("loaderror",null,"Failed loading audio file with status: "+v.status+".");h(v.response,r)},v.onerror=function(){r._webAudio&&(r._html5=!0,r._webAudio=!1,r._sounds=[],delete c[s],r.load())},p(v)}},p=function(r){try{r.send()}catch{r.onerror()}},h=function(r,s){var u=function(){s._emit("loaderror",null,"Decoding audio data failed.")},d=function(f){f&&s._sounds.length>0?(c[s._src]=f,y(s,f)):u()};typeof Promise<"u"&&o.ctx.decodeAudioData.length===1?o.ctx.decodeAudioData(r).then(d).catch(u):o.ctx.decodeAudioData(r,d,u)},y=function(r,s){s&&!r._duration&&(r._duration=s.duration),Object.keys(r._sprite).length===0&&(r._sprite={__default:[0,1e3*r._duration]}),r._state!=="loaded"&&(r._state="loaded",r._emit("load"),r._loadQueue())},g=function(){if(o.usingWebAudio){try{typeof AudioContext<"u"?o.ctx=new AudioContext:typeof webkitAudioContext<"u"?o.ctx=new webkitAudioContext:o.usingWebAudio=!1}catch{o.usingWebAudio=!1}o.ctx||(o.usingWebAudio=!1);var r=/iP(hone|od|ad)/.test(o._navigator&&o._navigator.platform),s=o._navigator&&o._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),u=s?parseInt(s[1],10):null;if(r&&u&&u<9){var d=/safari/.test(o._navigator&&o._navigator.userAgent.toLowerCase());o._navigator&&!d&&(o.usingWebAudio=!1)}o.usingWebAudio&&(o.masterGain=o.ctx.createGain===void 0?o.ctx.createGainNode():o.ctx.createGain(),o.masterGain.gain.setValueAtTime(o._muted?0:o._volume,o.ctx.currentTime),o.masterGain.connect(o.ctx.destination)),o._setup()}};e.Howler=o,e.Howl=i,typeof t<"u"?(t.HowlerGlobal=n,t.Howler=o,t.Howl=i,t.Sound=a):typeof window<"u"&&(window.HowlerGlobal=n,window.Howler=o,window.Howl=i,window.Sound=a)})()}(Fe)),Fe}var Qt=aa();const ua=typeof navigator<"u"&&typeof navigator.standalone<"u";class ca{constructor(t){this.cogsConnection=t,this.addEventListener("audioClipState",({detail:o})=>{t.sendMediaClipState(o)}),t.addEventListener("message",({message:o})=>{switch(o.type){case"media_config_update":if(this.globalVolume!==o.globalVolume&&this.setGlobalVolume(o.globalVolume),o.audioOutput!==void 0){const i=t.getAudioSinkId(o.audioOutput);this.setAudioSink(i??"")}this.updateConfig(o.files);break;case"audio_play":this.playAudioClip(o.file,{playId:o.playId,volume:o.volume,loop:!!o.loop,fade:o.fade});break;case"audio_pause":this.pauseAudioClip(o.file,{fade:o.fade});break;case"audio_stop":o.file?this.stopAudioClip(o.file,{fade:o.fade}):this.stopAllAudioClips({fade:o.fade});break;case"audio_set_clip_volume":this.setAudioClipVolume(o.file,{volume:o.volume,fade:o.fade});break}});const n=()=>{const o=Object.entries(this.audioClipPlayers).map(([i,a])=>{const c=Object.values(a.activeClips),l=c.some(({state:p})=>p.type==="playing"||p.type==="pausing"||p.type==="stopping"||p.type==="play_requested"||p.type==="pause_requested"||p.type==="stop_requested")?"playing":c.some(({state:p})=>p.type==="paused")?"paused":"stopped";return[i,l]});t.sendInitialMediaClipStates({mediaType:"audio",files:o})};t.addEventListener("open",n),n()}eventTarget=new EventTarget;globalVolume=1;audioClipPlayers={};sinkId="";setGlobalVolume(t){this.globalVolume=t,Qt.Howler.volume(t),this.notifyStateListeners()}playAudioClip(t,{playId:n,volume:o,fade:i,loop:a}){t in this.audioClipPlayers||(this.audioClipPlayers[t]=this.createClip(t,{preload:!1,ephemeral:!0})),this.updateAudioClipPlayer(t,c=>{const l=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="paused").map(([g])=>parseInt(g)),p=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="pausing").map(([g])=>parseInt(g));l.forEach(g=>{c.player.play(g)});const h=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="pause_requested").map(([g])=>parseInt(g)),y=l.length>0||p.length>0||h.length>0?[]:[c.player.play()];return p.forEach(g=>{c.player.off("fade",void 0,g),c.player.loop(a,g),this.updateActiveAudioClip(t,g,r=>({...r,state:{type:"playing"}})),se(i)?ae(c.player,o,i*1e3,g):Ve(c.player,o,g)}),[...l,...h,...y].forEach(g=>{c.player.loop(a,g),c.player.off("play",void 0,g),c.player.off("pause",void 0,g),c.player.off("fade",void 0,g),c.player.off("end",void 0,g),c.player.off("stop",void 0,g),c.player.once("play",()=>{Ue(c.player,this.sinkId)}),c.player.once("stop",()=>this.handleStoppedClip(t,n,g),g),c.player.on("end",()=>{c.activeClips[g]?.loop||this.handleStoppedClip(t,n,g)},g);const r={playId:n,state:{type:"play_requested"},loop:a,volume:o};c.player.once("play",()=>{const s=c.activeClips[g]?.state;s?.type==="pause_requested"?this.pauseAudioClip(t,{fade:s.fade},g,!0):s?.type==="stop_requested"?this.stopAudioClip(t,{fade:s.fade},g,!0):this.updateActiveAudioClip(t,g,u=>({...u,state:{type:"playing"}}))},g),se(i)?(c.player.volume(0,g),c.player.mute(!1,g),c.player.once("play",()=>{ae(c.player,o,i*1e3,g)},g)):Ve(c.player,o,g),c.activeClips={...c.activeClips,[g]:r}}),c}),this.notifyClipStateListeners(n,t,"playing")}pauseAudioClip(t,{fade:n},o,i){Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,a=>(a.activeClips=Object.fromEntries(Object.entries(a.activeClips).map(([c,l])=>{const p=parseInt(c);return(o===void 0||o===p)&&(i&&l.state.type==="pause_requested"||l.state.type==="playing"||l.state.type==="pausing"?se(n)?(a.player.once("fade",h=>{a.player.pause(h),this.updateActiveAudioClip(t,h,y=>({...y,state:{type:"paused"}})),this.notifyClipStateListeners(l.playId,t,"paused")},p),ae(a.player,0,n*1e3,p),l.state={type:"pausing"}):(a.player.pause(p),l.state={type:"paused"},this.notifyClipStateListeners(l.playId,t,"paused")):(l.state.type==="play_requested"||l.state.type==="pause_requested")&&(l.state={type:"pause_requested",fade:n})),[c,l]})),a))}stopAudioClip(t,{fade:n},o,i){la("Stop audio clip",{activeClips:this.audioClipPlayers[t]?.activeClips}),Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,a=>(a.activeClips=Object.fromEntries(Object.entries(a.activeClips).map(([c,l])=>{const p=parseInt(c);return(o===void 0||o===p)&&(i&&l.state.type==="stop_requested"||l.state.type==="playing"||l.state.type==="pausing"||l.state.type==="paused"||l.state.type==="stopping"?se(n)&&l.state.type!=="paused"?(a.player.off("fade",p),ae(a.player,0,n*1e3,p),a.player.once("fade",h=>{a.player.loop(!1,h),a.player.stop(h)},p),l.state={type:"stopping"}):(a.player.loop(!1,p),a.player.stop(p)):(l.state.type==="play_requested"||l.state.type==="pause_requested"||l.state.type==="stop_requested")&&(l.state={type:"stop_requested",fade:n})),[c,l]})),a))}stopAllAudioClips(t){Object.keys(this.audioClipPlayers).forEach(n=>{this.stopAudioClip(n,t)})}setAudioClipVolume(t,{volume:n,fade:o}){if(!(n>=0&&n<=1)){console.warn("Invalid volume",n);return}Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,i=>(i.activeClips=Object.fromEntries(Object.entries(i.activeClips).map(([a,c])=>{if(c.state.type!=="pausing"&&c.state.type!=="stopping"){const l=parseInt(a);return se(o)?ae(i.player,n,o*1e3,l):Ve(i.player,n,l),[a,{...c,volume:n}]}else return[a,c]})),i))}handleStoppedClip(t,n,o){this.updateAudioClipPlayer(t,i=>(delete i.activeClips[o],i)),this.notifyClipStateListeners(n,t,"stopped")}updateActiveAudioClip(t,n,o){this.updateAudioClipPlayer(t,i=>n in i.activeClips?{...i,activeClips:{...i.activeClips,[n]:o(i.activeClips[n])}}:i)}updateAudioClipPlayer(t,n){t in this.audioClipPlayers&&(this.audioClipPlayers={...this.audioClipPlayers,[t]:n(this.audioClipPlayers[t])});const o=this.audioClipPlayers[t];o&&Object.keys(o.activeClips??{}).length===0&&o.config.ephemeral&&(o.player.unload(),delete this.audioClipPlayers[t]),this.notifyStateListeners()}setAudioSink(t){for(const n of Object.values(this.audioClipPlayers))Ue(n.player,t);this.sinkId=t}updateConfig(t){const n=Object.fromEntries(Object.entries(t).filter(i=>{const a=i[1].type;return a==="audio"||!a})),o=this.audioClipPlayers;this.audioClipPlayers=(()=>{const i={...o};return Object.keys(o).filter(p=>!(p in n)&&!o[p].config.ephemeral).forEach(p=>{o[p].player.unload(),delete i[p]}),Object.entries(n).filter(([p])=>!o[p]).forEach(([p,h])=>{i[p]=this.createClip(p,{...h,ephemeral:!1})}),Object.keys(o).filter(p=>p in n).forEach(p=>{i[p]=this.updatedClip(p,i[p],{...n[p],ephemeral:!1})}),i})(),this.notifyStateListeners()}notifyStateListeners(){const t=Object.entries(this.audioClipPlayers).reduce((i,[a,c])=>(i[a]={config:{preload:c.config.preload,ephemeral:c.config.ephemeral},activeClips:c.activeClips},i),{}),n=Object.values(this.audioClipPlayers).some(({activeClips:i})=>Object.values(i).some(a=>a.state.type==="playing"||a.state.type==="pausing"||a.state.type==="stopping")),o={globalVolume:this.globalVolume,isPlaying:n,clips:t};this.dispatchEvent("state",o)}notifyClipStateListeners(t,n,o){this.dispatchEvent("audioClipState",{mediaType:"audio",playId:t,file:n,status:o})}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t,n){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:n}))}createPlayer(t,n){const o=new Qt.Howl({src:this.cogsConnection.getAssetUrl(t),autoplay:!1,loop:!1,volume:1,html5:!0,preload:n.preload});return Ue(o,this.sinkId),o}createClip(t,n){return{config:n,player:this.createPlayer(t,n),activeClips:{}}}updatedClip(t,n,o){const i={...n,config:o};return n.config.preload!==o.preload&&(i.player.unload(),i.player=this.createPlayer(t,o)),i}}function la(...e){}function se(e){return!ua&&typeof e=="number"&&!isNaN(e)&&e>0}function Ue(e,t){t!==void 0&&(e._html5?e._sounds?.forEach(n=>{n._node?.setSinkId?.(t)}):console.warn("Cannot set sink ID: web audio not supported",e))}function Ve(e,t,n){e.volume(t,n),e.mute(t===0,n)}function ae(e,t,n,o){e.fade(e.volume(o),t,n,o)}var Be=(e=>(e.Paused="paused",e.Playing="playing",e))(Be||{});class da{constructor(t,n=document.body){this.cogsConnection=t,this.parentElement=n,this.addEventListener("videoClipState",({detail:i})=>{t.sendMediaClipState(i)}),t.addEventListener("message",({message:i})=>{switch(i.type){case"media_config_update":if(this.setGlobalVolume(i.globalVolume),i.audioOutput!==void 0){const a=t.getAudioSinkId(i.audioOutput);this.setAudioSink(a??"")}this.updateConfig(i.files);break;case"video_play":this.playVideoClip(i.file,{playId:i.playId,volume:i.volume,loop:!!i.loop,fit:i.fit});break;case"video_pause":this.pauseVideoClip();break;case"video_stop":this.stopVideoClip();break;case"video_set_volume":this.setVideoClipVolume({volume:i.volume});break;case"video_set_fit":this.setVideoClipFit({fit:i.fit});break}});const o=()=>{const i=Object.entries(this.videoClipPlayers).map(([a,c])=>{const l=c.videoElement.paused?c.videoElement.currentTime===0||c.videoElement.currentTime===c.videoElement.duration?"paused":"stopped":"playing";return[a,l]});t.sendInitialMediaClipStates({mediaType:"video",files:i})};t.addEventListener("open",o),o()}eventTarget=new EventTarget;globalVolume=1;videoClipPlayers={};activeClip;pendingClip;parentElement;sinkId="";setParentElement(t){this.parentElement=t,Object.values(this.videoClipPlayers).forEach(n=>{t.appendChild(n.videoElement)})}resetParentElement(){this.setParentElement(document.body)}setGlobalVolume(t){Object.values(this.videoClipPlayers).forEach(n=>{Ee(n.videoElement,n.volume*t)}),this.globalVolume=t,this.notifyStateListeners()}playVideoClip(t,{playId:n,volume:o,loop:i,fit:a}){this.videoClipPlayers[t]||(this.videoClipPlayers[t]=this.createClipPlayer(t,{preload:"none",ephemeral:!0,fit:a})),this.pendingClip&&this.updateVideoClipPlayer(this.pendingClip.path,c=>(c.videoElement.load(),c)),this.activeClip?.path!==t&&(this.pendingClip={path:t,playId:n,actionOncePlaying:"play"}),this.updateVideoClipPlayer(t,c=>(c.volume=o,Ee(c.videoElement,o*this.globalVolume),c.videoElement.loop=i,c.videoElement.style.objectFit=a,c.videoElement.currentTime===c.videoElement.duration&&(c.videoElement.currentTime=0),c.videoElement.play(),this.activeClip||(c.videoElement.style.display="block"),c))}pauseVideoClip(){if(this.pendingClip&&(this.pendingClip.actionOncePlaying="pause"),this.activeClip){const{playId:t,path:n}=this.activeClip;this.updateVideoClipPlayer(n,o=>(o.videoElement?.pause(),o)),this.notifyClipStateListeners(t,n,"paused")}}stopVideoClip(){this.pendingClip&&(this.pendingClip.actionOncePlaying="stop"),this.activeClip&&this.handleStoppedClip(this.activeClip.path)}setVideoClipVolume({volume:t}){const n=this.pendingClip??this.activeClip??void 0;if(n){if(!(t>=0&&t<=1)){console.warn("Invalid volume",t);return}this.updateVideoClipPlayer(n.path,o=>(o.videoElement&&(o.volume=t,Ee(o.videoElement,t*this.globalVolume)),o))}}setVideoClipFit({fit:t}){const n=this.pendingClip??this.activeClip??void 0;n&&this.updateVideoClipPlayer(n.path,o=>(o.videoElement&&(o.videoElement.style.objectFit=t),o))}handleStoppedClip(t){if(!this.activeClip||this.activeClip.path!==t)return;const n=this.activeClip.playId;this.videoClipPlayers[this.activeClip.path]?.config.ephemeral&&this.unloadClip(t),this.activeClip=void 0,this.updateVideoClipPlayer(t,o=>(o.videoElement.pause(),o.videoElement.currentTime=0,o.videoElement.style.display="none",o)),this.notifyClipStateListeners(n,t,"stopped")}updateVideoClipPlayer(t,n){if(this.videoClipPlayers[t]){const o=n(this.videoClipPlayers[t]);o?this.videoClipPlayers[t]=o:delete this.videoClipPlayers[t],this.notifyStateListeners()}}setAudioSink(t){for(const n of Object.values(this.videoClipPlayers))en(n,t);this.sinkId=t}updateConfig(t){const n=Object.fromEntries(Object.entries(t).filter(([,{type:i}])=>i==="video"||!i)),o=this.videoClipPlayers;this.videoClipPlayers=(()=>{const i={...o};return Object.keys(o).filter(p=>!(p in n)).forEach(p=>{this.activeClip?.path===p&&o[p]?.config.ephemeral===!1?this.updateVideoClipPlayer(p,h=>(h.config={...h.config,ephemeral:!0},h)):(this.unloadClip(p),delete i[p])}),Object.entries(n).filter(([p])=>!o[p]).forEach(([p,h])=>{i[p]=this.createClipPlayer(p,{...h,preload:Xt(h.preload),ephemeral:!1,fit:"contain"})}),Object.entries(o).filter(([p])=>p in n).forEach(([p,h])=>{h.config.preload!==n[p].preload&&this.updateVideoClipPlayer(p,y=>(y.config={...y.config,preload:Xt(n[p].preload),ephemeral:!1},y.videoElement.preload=y.config.preload,y))}),i})(),this.notifyStateListeners()}notifyStateListeners(){const t={globalVolume:this.globalVolume,isPlaying:this.activeClip?!this.videoClipPlayers[this.activeClip.path].videoElement?.paused:!1,clips:{...this.videoClipPlayers},activeClip:this.activeClip?{path:this.activeClip.path,state:this.videoClipPlayers[this.activeClip.path].videoElement?.paused?Be.Paused:Be.Playing,loop:this.videoClipPlayers[this.activeClip.path].videoElement?.loop??!1,volume:this.videoClipPlayers[this.activeClip.path].videoElement?.muted?0:this.videoClipPlayers[this.activeClip.path].videoElement?.volume??0}:void 0};this.dispatchEvent("state",t)}notifyClipStateListeners(t,n,o){this.dispatchEvent("videoClipState",{playId:t,mediaType:"video",file:n,status:o})}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t,n){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:n}))}createVideoElement(t,n,{volume:o}){const i=document.createElement("video");return i.playsInline=!0,i.src=this.cogsConnection.getAssetUrl(t),i.autoplay=!1,i.loop=!1,Ee(i,o*this.globalVolume),i.preload=n.preload,i.addEventListener("playing",()=>{if(this.pendingClip?.path===t){switch(this.pendingClip.actionOncePlaying){case"play":{i.style.display="block",this.notifyClipStateListeners(this.pendingClip.playId,t,"playing");break}case"pause":{i.style.display="block",i.pause(),this.notifyClipStateListeners(this.pendingClip.playId,t,"paused");break}case"stop":{i.pause(),this.notifyClipStateListeners(this.pendingClip.playId,t,"stopped");break}}this.activeClip&&this.handleStoppedClip(this.activeClip.path),this.activeClip=this.pendingClip,this.pendingClip=void 0}else this.activeClip?.path===t?this.notifyClipStateListeners(this.activeClip.playId,t,"playing"):i.pause()}),i.addEventListener("ended",()=>{!this.pendingClip&&!i.loop&&this.handleStoppedClip(t)}),i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.width="100%",i.style.height="100%",i.style.objectFit=n.fit,i.style.display="none",this.parentElement.appendChild(i),i}createClipPlayer(t,n){const i={config:n,videoElement:this.createVideoElement(t,n,{volume:1}),volume:1};return en(i,this.sinkId),i}unloadClip(t){if(this.activeClip?.path===t){const n=this.activeClip.playId;this.activeClip=void 0,this.notifyClipStateListeners(n,t,"stopped")}this.videoClipPlayers[t]?.videoElement.remove(),this.updateVideoClipPlayer(t,()=>null)}}function Xt(e){return typeof e=="string"?e:e?"auto":"none"}function en(e,t){t!==void 0&&typeof e.videoElement.setSinkId=="function"&&e.videoElement.setSinkId(t)}function Ee(e,t){e.volume=t,e.muted=t===0}function ke(e,t){switch(e.type){case"image":{if(e.keyframes[0][0]>t)return;const o=e.keyframes.filter(a=>a[1]!==null),i=Ge(o,t);return{...be,...i}}case"audio":{const n=e.keyframes.filter(a=>a[1]!==null),o=tn(n,t);if(!o)return;const i=Ge(n,t);return{...we,...i,...o}}case"video":{const n=e.keyframes.filter(a=>a[1]!==null),o=tn(n,t);if(!o)return;const i=Ge(n,t);return{...ie,...i,...o}}}}function Ge(e,t){const n={};for(const[i,a]of e)i<=t?(Object.entries(a.lerp??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[i,l]}),Object.entries(a.set??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[i,l]})):Object.entries(a.lerp??{}).forEach(([c,l])=>{n[c]??={},n[c].after===void 0&&(n[c].after=[i,l])});const o={};return Object.entries(n).forEach(([i,{before:a,after:c}])=>{if(c===void 0&&a){o[i]=a[1];return}if(a&&c&&a[0]===c[0]){o[i]=c[1];return}if(a&&typeof a[1]=="number"&&c&&typeof c[1]=="number"){o[i]=a[1]+(t-a[0])*(c[1]-a[1])/(c[0]-a[0]);return}}),o}function tn(e,t){const n=e[0];if(!n||n[0]>t)return;let o=0,{t:i,rate:a}=we;for(const[h,y]of e){if(h>t)break;const{set:g}=y;if(!g)continue;const{t:r,rate:s}=g;if(r!==void 0){o=h,i=r,s!==void 0&&(a=s);continue}if(s!==void 0){const d=(h-o)*a;o=h,i+=d,a=s}}const l=(t-o)*a,p=i+l;return{rate:a,t:p}}const pa=1e3;class We{constructor(t,n,o){this.surfaceElement=t,this.clipElement=n,this._state=o,setTimeout(this.loop)}delay=pa;isConnected(t){return!(!this.surfaceElement||!this.clipElement||!this.surfaceElement.contains(this.clipElement)||t&&!this.clipElement.contains(t))}_state;setState(t){this._state=t,clearTimeout(this.timeout),this.loop()}timeout;loop=async()=>{this.isConnected()?(this.update(),this.timeout=setTimeout(this.loop,this.delay)):this.destroy()}}class fa extends We{imageElement;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateImageElement(){this.imageElement=document.createElement("img"),this.clipElement.replaceChildren(this.imageElement),this.imageElement.style.position="absolute",this.imageElement.style.height="100%",this.imageElement.style.widows="100%"}update(){const t=ke(this._state,Date.now());if(t?(!this.imageElement||!this.isConnected(this.imageElement))&&this.updateImageElement():(this.imageElement?.remove(),this.imageElement=void 0),!this.imageElement||!t)return;this.imageElement.src.startsWith(this._state.file)||(this.imageElement.src=this._state.file),this.imageElement.style.objectFit!==this._state.fit&&(this.imageElement.style.objectFit=this._state.fit),parseFloat(this.imageElement.style.opacity)!==t.opacity&&(this.imageElement.style.opacity=String(t.opacity??be.opacity));const n=Math.round(t.zIndex??be.zIndex);parseInt(this.imageElement.style.zIndex)!==n&&(this.imageElement.style.zIndex=String(n));const{opacity:o}=t;typeof o=="string"&&o!==this.imageElement.style.opacity&&(this.imageElement.style.opacity=o)}destroy(){this.imageElement?.remove()}}const ha=1e3,nn=10,on=1e3,_a=200,ma=.5,va=.3;function ga(e){return Math.sign(e)*Math.pow(Math.abs(e)/on,va)*ma}class ya extends We{videoElement;isSeeking=!1;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateVideoElement(){this.destroy(),this.videoElement=document.createElement("video"),this.clipElement.replaceChildren(this.videoElement),this.videoElement.style.position="absolute",this.videoElement.style.width="100%",this.videoElement.style.height="100%"}seekTo(t){this.videoElement&&(this.videoElement.addEventListener("seeked",()=>{this.isSeeking=!1},{once:!0,passive:!0}),this.videoElement.currentTime=t/1e3)}update(){if(this.isSeeking)return;this.delay=ha;const t=ke(this._state,Date.now());if(t?(!this.videoElement||!this.isConnected(this.videoElement))&&this.updateVideoElement():(this.videoElement?.remove(),this.videoElement=void 0),!t||!this.videoElement)return;const{t:n,rate:o,volume:i}={...ie,...t};this.videoElement.src.endsWith(this._state.file)||(this.videoElement.src=this._state.file),this.videoElement.style.objectFit!==this._state.fit&&(this.videoElement.style.objectFit=this._state.fit),parseFloat(this.videoElement.style.opacity)!==t.opacity&&(this.videoElement.style.opacity=String(t.opacity??ie.opacity));const a=Math.round(t.zIndex??ie.zIndex);parseInt(this.videoElement.style.zIndex)!==a&&(this.videoElement.style.zIndex=String(a)),this.videoElement.volume!==i&&(this.videoElement.volume=i),this.videoElement.paused&&o>0&&this.videoElement.play().catch(()=>{});const l=this.videoElement.currentTime*1e3-n,p=Math.abs(l);switch(this.delay=100,!0){case p<=nn:this.videoElement.playbackRate!==o&&(this.videoElement.playbackRate=o);break;case(o>0&&p>nn&&p<=on):{const h=ga(l),y=Math.max(0,o-h);this.videoElement.playbackRate!==y&&(this.videoElement.playbackRate=y);break}default:{this.videoElement.playbackRate!==o&&(this.videoElement.playbackRate=o),this.delay=10,this.seekTo(n+o*(_a/1e3));break}}}destroy(){this.videoElement&&(this.videoElement.src="",this.videoElement.remove())}}const ba=1e3,rn=10,sn=1e3,wa=200,Ea=.2,ka=.5;function Ca(e){return Math.sign(e)*Math.pow(Math.abs(e)/sn,ka)*Ea}class Sa extends We{audioElement;isSeeking=!1;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateAudioElement(){this.destroy(),this.audioElement=document.createElement("audio"),this.clipElement.replaceChildren(this.audioElement)}seekTo(t){this.audioElement&&(this.audioElement.addEventListener("seeked",()=>{this.isSeeking=!1},{once:!0,passive:!0}),this.audioElement.currentTime=t/1e3)}update(){if(this.isSeeking)return;this.delay=ba;const t=ke(this._state,Date.now());if(t?(!this.audioElement||!this.isConnected(this.audioElement))&&this.updateAudioElement():this.destroy(),!t||!this.audioElement)return;const{t:n,rate:o,volume:i}={...we,...t};this.audioElement.src.endsWith(this._state.file)||(this.audioElement.src=this._state.file),this.audioElement.volume!==i&&(this.audioElement.volume=i),this.audioElement.paused&&o>0&&this.audioElement.play().catch(()=>{});const c=this.audioElement.currentTime*1e3-n,l=Math.abs(c);switch(this.delay=100,!0){case l<=rn:this.audioElement.playbackRate!==o&&(this.audioElement.playbackRate=o);break;case(o>0&&l>rn&&l<=sn):{const p=Ca(c),h=Math.max(0,o-p);this.audioElement.playbackRate!==h&&(this.audioElement.playbackRate=h);break}default:{this.audioElement.playbackRate!==o&&(this.audioElement.playbackRate=o),this.delay=10,this.seekTo(n+o*(wa/1e3));break}}}destroy(){this.audioElement&&(this.audioElement.src="",this.audioElement.remove())}}const Aa="data-clip-id";class Ta{_state={};setState(t){this._state=t,this.update()}_element;get element(){return this._element}resources={};constructor(t){this._element=document.createElement("div"),this._element.style.width="100%",this._element.style.height="100%",this._state=t||{},this.update()}update(){Object.entries(this.resources).forEach(([n,{element:o,manager:i}])=>{n in this._state||(delete this.resources[n],o.remove(),i?.destroy())});const t=Object.keys(this._state).toSorted().map(n=>{const o=this.resources[n];if(o)return o.element;{const i=document.createElement("div");return i.setAttribute(Aa,n),this.resources[n]={element:i},i}});this._element.replaceChildren(...t),Object.keys(this._state).toSorted().forEach(n=>{const o=this._state[n],i=this.resources[n];if(!i)throw new Error("Failed to create resource");if(i.manager)i.manager.setState(o);else switch(o.type){case"image":i.manager=new fa(this._element,i.element,o);break;case"audio":i.manager=new Sa(this._element,i.element,o);break;case"video":i.manager=new ya(this._element,i.element,o);break}})}}const za=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));A.CogsAudioPlayer=ca,A.CogsConfigChangedEvent=tt,A.CogsConnection=Tn,A.CogsConnectionCloseEvent=Xe,A.CogsConnectionOpenEvent=Qe,A.CogsIncomingEvent=ot,A.CogsMediaConfigChangedEvent=rt,A.CogsMessageEvent=et,A.CogsShowPhaseChangedEvent=it,A.CogsStateChangedEvent=nt,A.CogsVideoPlayer=da,A.DataStoreItemEvent=Ae,A.DataStoreItemsEvent=Te,A.ManifestTypes=za,A.MediaSchema=sa,A.SurfaceManager=Ta,A.assetUrl=Ye,A.getStateAtTime=ke,A.preloadUrl=gn,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
38
|
+
`)}s.write("payload.value = newResult;"),s.write("return payload;");const _=s.compile();return(w,E)=>_(i,w,E)};let a;const c=ce,l=!ut.jitless,f=l&&Pn.value,y=t.catchall;let g;e._zod.parse=(i,s)=>{g??(g=o.value);const u=i.value;return c(u)?l&&f&&s?.async===!1&&s.jitless!==!0?(a||(a=r(t.shape)),i=a(i,s),y?At([],u,i,s,g,e):i):n(i,s):(i.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),i)}});function zt(e,t,n,o){for(const a of e)if(a.issues.length===0)return t.value=a.value,t;const r=e.filter(a=>!Y(a));return r.length===1?(t.value=r[0].value,r[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(a=>a.issues.map(c=>M(c,o,N())))}),t)}const wi=m("$ZodUnion",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),C(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),C(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),C(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(a=>a._zod.pattern);return new RegExp(`^(${r.map(a=>Oe(a.source)).join("|")})$`)}});const n=t.options.length===1,o=t.options[0]._zod.run;e._zod.parse=(r,a)=>{if(n)return o(r,a);let c=!1;const l=[];for(const p of t.options){const f=p._zod.run({value:r.value,issues:[]},a);if(f instanceof Promise)l.push(f),c=!0;else{if(f.issues.length===0)return f;l.push(f)}}return c?Promise.all(l).then(p=>zt(p,r,e,a)):zt(l,r,e,a)}}),Ei=m("$ZodIntersection",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const r=n.value,a=t.left._zod.run({value:r,issues:[]},o),c=t.right._zod.run({value:r,issues:[]},o);return a instanceof Promise||c instanceof Promise?Promise.all([a,c]).then(([p,f])=>It(n,p,f)):It(n,a,c)}});function Re(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(H(e)&&H(t)){const n=Object.keys(t),o=Object.keys(e).filter(a=>n.indexOf(a)!==-1),r={...e,...t};for(const a of o){const c=Re(e[a],t[a]);if(!c.valid)return{valid:!1,mergeErrorPath:[a,...c.mergeErrorPath]};r[a]=c.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let o=0;o<e.length;o++){const r=e[o],a=t[o],c=Re(r,a);if(!c.valid)return{valid:!1,mergeErrorPath:[o,...c.mergeErrorPath]};n.push(c.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function It(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Y(e))return e;const o=Re(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const ki=m("$ZodTuple",(e,t)=>{S.init(e,t);const n=t.items;e._zod.parse=(o,r)=>{const a=o.value;if(!Array.isArray(a))return o.issues.push({input:a,inst:e,expected:"tuple",code:"invalid_type"}),o;o.value=[];const c=[],l=[...n].reverse().findIndex(y=>y._zod.optin!=="optional"),p=l===-1?0:n.length-l;if(!t.rest){const y=a.length>n.length,g=a.length<p-1;if(y||g)return o.issues.push({...y?{code:"too_big",maximum:n.length}:{code:"too_small",minimum:n.length},input:a,inst:e,origin:"array"}),o}let f=-1;for(const y of n){if(f++,f>=a.length&&f>=p)continue;const g=y._zod.run({value:a[f],issues:[]},r);g instanceof Promise?c.push(g.then(i=>_e(i,o,f))):_e(g,o,f)}if(t.rest){const y=a.slice(n.length);for(const g of y){f++;const i=t.rest._zod.run({value:g,issues:[]},r);i instanceof Promise?c.push(i.then(s=>_e(s,o,f))):_e(i,o,f)}}return c.length?Promise.all(c).then(()=>o):o}});function _e(e,t,n){e.issues.length&&t.issues.push(...B(n,e.issues)),t.value[n]=e.value}const Ci=m("$ZodRecord",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const r=n.value;if(!H(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;const a=[],c=t.keyType._zod.values;if(c){n.value={};const l=new Set;for(const f of c)if(typeof f=="string"||typeof f=="number"||typeof f=="symbol"){l.add(typeof f=="number"?f.toString():f);const y=t.valueType._zod.run({value:r[f],issues:[]},o);y instanceof Promise?a.push(y.then(g=>{g.issues.length&&n.issues.push(...B(f,g.issues)),n.value[f]=g.value})):(y.issues.length&&n.issues.push(...B(f,y.issues)),n.value[f]=y.value)}let p;for(const f in r)l.has(f)||(p=p??[],p.push(f));p&&p.length>0&&n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:p})}else{n.value={};for(const l of Reflect.ownKeys(r)){if(l==="__proto__")continue;const p=t.keyType._zod.run({value:l,issues:[]},o);if(p instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(p.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map(y=>M(y,o,N())),input:l,path:[l],inst:e}),n.value[p.value]=p.value;continue}const f=t.valueType._zod.run({value:r[l],issues:[]},o);f instanceof Promise?a.push(f.then(y=>{y.issues.length&&n.issues.push(...B(l,y.issues)),n.value[p.value]=y.value})):(f.issues.length&&n.issues.push(...B(l,f.issues)),n.value[p.value]=f.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Si=m("$ZodEnum",(e,t)=>{S.init(e,t);const n=$n(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter(r=>xn.has(typeof r)).map(r=>typeof r=="string"?J(r):r.toString()).join("|")})$`),e._zod.parse=(r,a)=>{const c=r.value;return o.has(c)||r.issues.push({code:"invalid_value",values:n,input:c,inst:e}),r}}),Ti=m("$ZodLiteral",(e,t)=>{if(S.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(o=>typeof o=="string"?J(o):o?J(o.toString()):String(o)).join("|")})$`),e._zod.parse=(o,r)=>{const a=o.value;return n.has(a)||o.issues.push({code:"invalid_value",values:t.values,input:a,inst:e}),o}}),Ai=m("$ZodTransform",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new at(e.constructor.name);const r=t.transform(n.value,n);if(o.async)return(r instanceof Promise?r:Promise.resolve(r)).then(c=>(n.value=c,n));if(r instanceof Promise)throw new K;return n.value=r,n}});function $t(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const zi=m("$ZodOptional",(e,t)=>{S.init(e,t),e._zod.optin="optional",e._zod.optout="optional",C(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),C(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Oe(n.source)})?$`):void 0}),e._zod.parse=(n,o)=>{if(t.innerType._zod.optin==="optional"){const r=t.innerType._zod.run(n,o);return r instanceof Promise?r.then(a=>$t(a,n.value)):$t(r,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,o)}}),Ii=m("$ZodNullable",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.innerType._zod.optin),C(e._zod,"optout",()=>t.innerType._zod.optout),C(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Oe(n.source)}|null)$`):void 0}),C(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,o)=>n.value===null?n:t.innerType._zod.run(n,o)}),$i=m("$ZodDefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);if(n.value===void 0)return n.value=t.defaultValue,n;const r=t.innerType._zod.run(n,o);return r instanceof Promise?r.then(a=>Ot(a,t)):Ot(r,t)}});function Ot(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Oi=m("$ZodPrefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>(o.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,o))}),Zi=m("$ZodNonOptional",(e,t)=>{S.init(e,t),C(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(o=>o!==void 0)):void 0}),e._zod.parse=(n,o)=>{const r=t.innerType._zod.run(n,o);return r instanceof Promise?r.then(a=>Zt(a,e)):Zt(r,e)}});function Zt(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Pi=m("$ZodCatch",(e,t)=>{S.init(e,t),C(e._zod,"optin",()=>t.innerType._zod.optin),C(e._zod,"optout",()=>t.innerType._zod.optout),C(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);const r=t.innerType._zod.run(n,o);return r instanceof Promise?r.then(a=>(n.value=a.value,a.issues.length&&(n.value=t.catchValue({...n,error:{issues:a.issues.map(c=>M(c,o,N()))},input:n.value}),n.issues=[]),n)):(n.value=r.value,r.issues.length&&(n.value=t.catchValue({...n,error:{issues:r.issues.map(a=>M(a,o,N()))},input:n.value}),n.issues=[]),n)}}),xi=m("$ZodPipe",(e,t)=>{S.init(e,t),C(e._zod,"values",()=>t.in._zod.values),C(e._zod,"optin",()=>t.in._zod.optin),C(e._zod,"optout",()=>t.out._zod.optout),C(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,o)=>{if(o.direction==="backward"){const a=t.out._zod.run(n,o);return a instanceof Promise?a.then(c=>me(c,t.in,o)):me(a,t.in,o)}const r=t.in._zod.run(n,o);return r instanceof Promise?r.then(a=>me(a,t.out,o)):me(r,t.out,o)}});function me(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Li=m("$ZodReadonly",(e,t)=>{S.init(e,t),C(e._zod,"propValues",()=>t.innerType._zod.propValues),C(e._zod,"values",()=>t.innerType._zod.values),C(e._zod,"optin",()=>t.innerType?._zod?.optin),C(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,o)=>{if(o.direction==="backward")return t.innerType._zod.run(n,o);const r=t.innerType._zod.run(n,o);return r instanceof Promise?r.then(Pt):Pt(r)}});function Pt(e){return e.value=Object.freeze(e.value),e}const Ri=m("$ZodCustom",(e,t)=>{Z.init(e,t),S.init(e,t),e._zod.parse=(n,o)=>n,e._zod.check=n=>{const o=n.value,r=t.fn(o);if(r instanceof Promise)return r.then(a=>xt(a,n,o,e));xt(r,n,o,e)}});function xt(e,t,n,o){if(!e){const r={code:"custom",input:n,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};o._zod.def.params&&(r.params=o._zod.def.params),t.issues.push(ie(r))}}var Lt;class ji{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const o=n[0];if(this._map.set(t,o),o&&typeof o=="object"&&"id"in o){if(this._idmap.has(o.id))throw new Error(`ID ${o.id} already exists in the registry`);this._idmap.set(o.id,t)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const o={...this.get(n)??{}};delete o.id;const r={...o,...this._map.get(t)};return Object.keys(r).length?r:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Ni(){return new ji}(Lt=globalThis).__zod_globalRegistry??(Lt.__zod_globalRegistry=Ni());const ve=globalThis.__zod_globalRegistry;function Di(e,t){return new e({type:"string",...b(t)})}function Mi(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...b(t)})}function Rt(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...b(t)})}function Fi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...b(t)})}function Ui(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...b(t)})}function Vi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...b(t)})}function Bi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...b(t)})}function Gi(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...b(t)})}function Wi(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...b(t)})}function qi(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...b(t)})}function Ki(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...b(t)})}function Hi(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...b(t)})}function Ji(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...b(t)})}function Yi(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...b(t)})}function Qi(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...b(t)})}function Xi(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...b(t)})}function er(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...b(t)})}function tr(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...b(t)})}function nr(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...b(t)})}function or(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...b(t)})}function ir(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...b(t)})}function rr(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...b(t)})}function sr(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...b(t)})}function ar(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...b(t)})}function ur(e,t){return new e({type:"string",format:"date",check:"string_format",...b(t)})}function cr(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...b(t)})}function lr(e,t){return new e({type:"string",format:"duration",check:"string_format",...b(t)})}function dr(e,t){return new e({type:"number",checks:[],...b(t)})}function pr(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...b(t)})}function fr(e,t){return new e({type:"null",...b(t)})}function hr(e){return new e({type:"unknown"})}function _r(e,t){return new e({type:"never",...b(t)})}function jt(e,t){return new wt({check:"less_than",...b(t),value:e,inclusive:!1})}function je(e,t){return new wt({check:"less_than",...b(t),value:e,inclusive:!0})}function Nt(e,t){return new Et({check:"greater_than",...b(t),value:e,inclusive:!1})}function Ne(e,t){return new Et({check:"greater_than",...b(t),value:e,inclusive:!0})}function Dt(e,t){return new Io({check:"multiple_of",...b(t),value:e})}function Mt(e,t){return new Oo({check:"max_length",...b(t),maximum:e})}function ge(e,t){return new Zo({check:"min_length",...b(t),minimum:e})}function Ft(e,t){return new Po({check:"length_equals",...b(t),length:e})}function mr(e,t){return new xo({check:"string_format",format:"regex",...b(t),pattern:e})}function vr(e){return new Lo({check:"string_format",format:"lowercase",...b(e)})}function gr(e){return new Ro({check:"string_format",format:"uppercase",...b(e)})}function yr(e,t){return new jo({check:"string_format",format:"includes",...b(t),includes:e})}function br(e,t){return new No({check:"string_format",format:"starts_with",...b(t),prefix:e})}function wr(e,t){return new Do({check:"string_format",format:"ends_with",...b(t),suffix:e})}function Q(e){return new Mo({check:"overwrite",tx:e})}function Er(e){return Q(t=>t.normalize(e))}function kr(){return Q(e=>e.trim())}function Cr(){return Q(e=>e.toLowerCase())}function Sr(){return Q(e=>e.toUpperCase())}function Tr(){return Q(e=>Zn(e))}function Ar(e,t,n){return new e({type:"array",element:t,...b(n)})}function zr(e,t,n){return new e({type:"custom",check:"custom",fn:t,...b(n)})}function Ir(e){const t=$r(n=>(n.addIssue=o=>{if(typeof o=="string")n.issues.push(ie(o,n.value,t._zod.def));else{const r=o;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(ie(r))}},e(n.value,n)));return t}function $r(e,t){const n=new Z({check:"custom",...b(t)});return n._zod.check=e,n}const Or=m("ZodISODateTime",(e,t)=>{ei.init(e,t),O.init(e,t)});function Zr(e){return ar(Or,e)}const Pr=m("ZodISODate",(e,t)=>{ti.init(e,t),O.init(e,t)});function xr(e){return ur(Pr,e)}const Lr=m("ZodISOTime",(e,t)=>{ni.init(e,t),O.init(e,t)});function Rr(e){return cr(Lr,e)}const jr=m("ZodISODuration",(e,t)=>{oi.init(e,t),O.init(e,t)});function Nr(e){return lr(jr,e)}const P=m("ZodError",(e,t)=>{ht.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Gn(e,n)},flatten:{value:n=>Bn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ze,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ze,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Dr=Pe(P),Mr=xe(P),Fr=de(P),Ur=pe(P),Vr=Kn(P),Br=Hn(P),Gr=Jn(P),Wr=Yn(P),qr=Qn(P),Kr=Xn(P),Hr=eo(P),Jr=to(P),$=m("ZodType",(e,t)=>(S.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(V(t,{checks:[...t.checks??[],...n.map(o=>typeof o=="function"?{_zod:{check:o,def:{check:"custom"},onattach:[]}}:o)]})),e.clone=(n,o)=>D(e,n,o),e.brand=()=>e,e.register=(n,o)=>(n.add(e,o),e),e.parse=(n,o)=>Dr(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Fr(e,n,o),e.parseAsync=async(n,o)=>Mr(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>Ur(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Vr(e,n,o),e.decode=(n,o)=>Br(e,n,o),e.encodeAsync=async(n,o)=>Gr(e,n,o),e.decodeAsync=async(n,o)=>Wr(e,n,o),e.safeEncode=(n,o)=>qr(e,n,o),e.safeDecode=(n,o)=>Kr(e,n,o),e.safeEncodeAsync=async(n,o)=>Hr(e,n,o),e.safeDecodeAsync=async(n,o)=>Jr(e,n,o),e.refine=(n,o)=>e.check(Ws(n,o)),e.superRefine=n=>e.check(qs(n)),e.overwrite=n=>e.check(Q(n)),e.optional=()=>Kt(e),e.nullable=()=>Ht(e),e.nullish=()=>Kt(Ht(e)),e.nonoptional=n=>Ds(e,n),e.array=()=>Es(e),e.or=n=>G([e,n]),e.and=n=>Ts(e,n),e.transform=n=>Yt(e,Ps(n)),e.default=n=>Rs(e,n),e.prefault=n=>Ns(e,n),e.catch=n=>Fs(e,n),e.pipe=n=>Yt(e,n),e.readonly=()=>Bs(e),e.describe=n=>{const o=e.clone();return ve.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return ve.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ve.get(e);const o=e.clone();return ve.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Ut=m("_ZodString",(e,t)=>{Le.init(e,t),$.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...o)=>e.check(mr(...o)),e.includes=(...o)=>e.check(yr(...o)),e.startsWith=(...o)=>e.check(br(...o)),e.endsWith=(...o)=>e.check(wr(...o)),e.min=(...o)=>e.check(ge(...o)),e.max=(...o)=>e.check(Mt(...o)),e.length=(...o)=>e.check(Ft(...o)),e.nonempty=(...o)=>e.check(ge(1,...o)),e.lowercase=o=>e.check(vr(o)),e.uppercase=o=>e.check(gr(o)),e.trim=()=>e.check(kr()),e.normalize=(...o)=>e.check(Er(...o)),e.toLowerCase=()=>e.check(Cr()),e.toUpperCase=()=>e.check(Sr()),e.slugify=()=>e.check(Tr())}),Yr=m("ZodString",(e,t)=>{Le.init(e,t),Ut.init(e,t),e.email=n=>e.check(Mi(Qr,n)),e.url=n=>e.check(Gi(Xr,n)),e.jwt=n=>e.check(sr(hs,n)),e.emoji=n=>e.check(Wi(es,n)),e.guid=n=>e.check(Rt(Vt,n)),e.uuid=n=>e.check(Fi(ye,n)),e.uuidv4=n=>e.check(Ui(ye,n)),e.uuidv6=n=>e.check(Vi(ye,n)),e.uuidv7=n=>e.check(Bi(ye,n)),e.nanoid=n=>e.check(qi(ts,n)),e.guid=n=>e.check(Rt(Vt,n)),e.cuid=n=>e.check(Ki(ns,n)),e.cuid2=n=>e.check(Hi(os,n)),e.ulid=n=>e.check(Ji(is,n)),e.base64=n=>e.check(or(ds,n)),e.base64url=n=>e.check(ir(ps,n)),e.xid=n=>e.check(Yi(rs,n)),e.ksuid=n=>e.check(Qi(ss,n)),e.ipv4=n=>e.check(Xi(as,n)),e.ipv6=n=>e.check(er(us,n)),e.cidrv4=n=>e.check(tr(cs,n)),e.cidrv6=n=>e.check(nr(ls,n)),e.e164=n=>e.check(rr(fs,n)),e.datetime=n=>e.check(Zr(n)),e.date=n=>e.check(xr(n)),e.time=n=>e.check(Rr(n)),e.duration=n=>e.check(Nr(n))});function X(e){return Di(Yr,e)}const O=m("ZodStringFormat",(e,t)=>{A.init(e,t),Ut.init(e,t)}),Qr=m("ZodEmail",(e,t)=>{Go.init(e,t),O.init(e,t)}),Vt=m("ZodGUID",(e,t)=>{Vo.init(e,t),O.init(e,t)}),ye=m("ZodUUID",(e,t)=>{Bo.init(e,t),O.init(e,t)}),Xr=m("ZodURL",(e,t)=>{Wo.init(e,t),O.init(e,t)}),es=m("ZodEmoji",(e,t)=>{qo.init(e,t),O.init(e,t)}),ts=m("ZodNanoID",(e,t)=>{Ko.init(e,t),O.init(e,t)}),ns=m("ZodCUID",(e,t)=>{Ho.init(e,t),O.init(e,t)}),os=m("ZodCUID2",(e,t)=>{Jo.init(e,t),O.init(e,t)}),is=m("ZodULID",(e,t)=>{Yo.init(e,t),O.init(e,t)}),rs=m("ZodXID",(e,t)=>{Qo.init(e,t),O.init(e,t)}),ss=m("ZodKSUID",(e,t)=>{Xo.init(e,t),O.init(e,t)}),as=m("ZodIPv4",(e,t)=>{ii.init(e,t),O.init(e,t)}),us=m("ZodIPv6",(e,t)=>{ri.init(e,t),O.init(e,t)}),cs=m("ZodCIDRv4",(e,t)=>{si.init(e,t),O.init(e,t)}),ls=m("ZodCIDRv6",(e,t)=>{ai.init(e,t),O.init(e,t)}),ds=m("ZodBase64",(e,t)=>{ui.init(e,t),O.init(e,t)}),ps=m("ZodBase64URL",(e,t)=>{li.init(e,t),O.init(e,t)}),fs=m("ZodE164",(e,t)=>{di.init(e,t),O.init(e,t)}),hs=m("ZodJWT",(e,t)=>{fi.init(e,t),O.init(e,t)}),Bt=m("ZodNumber",(e,t)=>{Ct.init(e,t),$.init(e,t),e.gt=(o,r)=>e.check(Nt(o,r)),e.gte=(o,r)=>e.check(Ne(o,r)),e.min=(o,r)=>e.check(Ne(o,r)),e.lt=(o,r)=>e.check(jt(o,r)),e.lte=(o,r)=>e.check(je(o,r)),e.max=(o,r)=>e.check(je(o,r)),e.int=o=>e.check(Gt(o)),e.safe=o=>e.check(Gt(o)),e.positive=o=>e.check(Nt(0,o)),e.nonnegative=o=>e.check(Ne(0,o)),e.negative=o=>e.check(jt(0,o)),e.nonpositive=o=>e.check(je(0,o)),e.multipleOf=(o,r)=>e.check(Dt(o,r)),e.step=(o,r)=>e.check(Dt(o,r)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function x(e){return dr(Bt,e)}const _s=m("ZodNumberFormat",(e,t)=>{hi.init(e,t),Bt.init(e,t)});function Gt(e){return pr(_s,e)}const ms=m("ZodNull",(e,t)=>{_i.init(e,t),$.init(e,t)});function vs(e){return fr(ms,e)}const gs=m("ZodUnknown",(e,t)=>{mi.init(e,t),$.init(e,t)});function Wt(){return hr(gs)}const ys=m("ZodNever",(e,t)=>{vi.init(e,t),$.init(e,t)});function bs(e){return _r(ys,e)}const ws=m("ZodArray",(e,t)=>{gi.init(e,t),$.init(e,t),e.element=t.element,e.min=(n,o)=>e.check(ge(n,o)),e.nonempty=n=>e.check(ge(1,n)),e.max=(n,o)=>e.check(Mt(n,o)),e.length=(n,o)=>e.check(Ft(n,o)),e.unwrap=()=>e.element});function Es(e,t){return Ar(ws,e,t)}const ks=m("ZodObject",(e,t)=>{bi.init(e,t),$.init(e,t),C(e,"shape",()=>t.shape),e.keyof=()=>$s(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Wt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Wt()}),e.strict=()=>e.clone({...e._zod.def,catchall:bs()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>Dn(e,n),e.safeExtend=n=>Mn(e,n),e.merge=n=>Fn(e,n),e.pick=n=>jn(e,n),e.omit=n=>Nn(e,n),e.partial=(...n)=>Un(qt,e,n[0]),e.required=(...n)=>Vn(Jt,e,n[0])});function z(e,t){const n={type:"object",shape:e??{},...b(t)};return new ks(n)}const Cs=m("ZodUnion",(e,t)=>{wi.init(e,t),$.init(e,t),e.options=t.options});function G(e,t){return new Cs({type:"union",options:e,...b(t)})}const Ss=m("ZodIntersection",(e,t)=>{Ei.init(e,t),$.init(e,t)});function Ts(e,t){return new Ss({type:"intersection",left:e,right:t})}const As=m("ZodTuple",(e,t)=>{ki.init(e,t),$.init(e,t),e.rest=n=>e.clone({...e._zod.def,rest:n})});function L(e,t,n){const o=t instanceof S,r=o?n:t,a=o?t:null;return new As({type:"tuple",items:e,rest:a,...b(r)})}const zs=m("ZodRecord",(e,t)=>{Ci.init(e,t),$.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Is(e,t,n){return new zs({type:"record",keyType:e,valueType:t,...b(n)})}const De=m("ZodEnum",(e,t)=>{Si.init(e,t),$.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(o,r)=>{const a={};for(const c of o)if(n.has(c))a[c]=t.entries[c];else throw new Error(`Key ${c} not found in enum`);return new De({...t,checks:[],...b(r),entries:a})},e.exclude=(o,r)=>{const a={...t.entries};for(const c of o)if(n.has(c))delete a[c];else throw new Error(`Key ${c} not found in enum`);return new De({...t,checks:[],...b(r),entries:a})}});function $s(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(o=>[o,o])):e;return new De({type:"enum",entries:n,...b(t)})}const Os=m("ZodLiteral",(e,t)=>{Ti.init(e,t),$.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function j(e,t){return new Os({type:"literal",values:Array.isArray(e)?e:[e],...b(t)})}const Zs=m("ZodTransform",(e,t)=>{Ai.init(e,t),$.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new at(e.constructor.name);n.addIssue=a=>{if(typeof a=="string")n.issues.push(ie(a,n.value,t));else{const c=a;c.fatal&&(c.continue=!1),c.code??(c.code="custom"),c.input??(c.input=n.value),c.inst??(c.inst=e),n.issues.push(ie(c))}};const r=t.transform(n.value,n);return r instanceof Promise?r.then(a=>(n.value=a,n)):(n.value=r,n)}});function Ps(e){return new Zs({type:"transform",transform:e})}const qt=m("ZodOptional",(e,t)=>{zi.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Kt(e){return new qt({type:"optional",innerType:e})}const xs=m("ZodNullable",(e,t)=>{Ii.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ht(e){return new xs({type:"nullable",innerType:e})}const Ls=m("ZodDefault",(e,t)=>{$i.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Rs(e,t){return new Ls({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():pt(t)}})}const js=m("ZodPrefault",(e,t)=>{Oi.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ns(e,t){return new js({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():pt(t)}})}const Jt=m("ZodNonOptional",(e,t)=>{Zi.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ds(e,t){return new Jt({type:"nonoptional",innerType:e,...b(t)})}const Ms=m("ZodCatch",(e,t)=>{Pi.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Fs(e,t){return new Ms({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Us=m("ZodPipe",(e,t)=>{xi.init(e,t),$.init(e,t),e.in=t.in,e.out=t.out});function Yt(e,t){return new Us({type:"pipe",in:e,out:t})}const Vs=m("ZodReadonly",(e,t)=>{Li.init(e,t),$.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Bs(e){return new Vs({type:"readonly",innerType:e})}const Gs=m("ZodCustom",(e,t)=>{Ri.init(e,t),$.init(e,t)});function Ws(e,t={}){return zr(Gs,e,t)}function qs(e){return Ir(e)}const be=z({t:x().gte(0),rate:x().gte(0)}),ee=z({opacity:x().gte(0).lte(1),zIndex:x()}),te=z({volume:x().gte(0).lte(1)}),Ks=z({type:j("image"),file:X(),fit:G([j("contain"),j("cover"),j("none")])}),Hs=z({type:j("audio"),file:X(),audioOutput:X()}),Js=z({type:j("video"),file:X(),audioOutput:X(),fit:G([j("contain"),j("cover"),j("none")])}),Me=L([x(),vs()]),Ys=L([x(),z({set:z({...ee.shape}).partial()}).partial()]),Qs=L([x(),z({set:z({...ee.shape}).partial(),lerp:z({...ee.shape}).partial()}).partial()]),Xs=L([x(),z({set:z({...be.shape,...te.shape}).partial()}).partial()]),ea=L([x(),z({set:z({...be.shape,...te.shape}).partial(),lerp:z({...te.shape}).partial()}).partial()]),ta=L([x(),z({set:z({...be.shape,...te.shape,...ee.shape}).partial()}).partial()]),na=L([x(),z({set:z({...be.shape,...te.shape,...ee.shape}).partial(),lerp:z({...te.shape,...ee.shape}).partial()}).partial()]),oa=z({...Ks.shape,keyframes:L([Qs],G([Ys,Me]))}),ia=z({...Hs.shape,keyframes:L([ea],G([Xs,Me]))}),ra=z({...Js.shape,keyframes:L([na],G([ta,Me]))}),sa=Is(X(),G([oa,ia,ra])),we={opacity:1,zIndex:0},Ee={t:0,rate:1,volume:1},re={t:0,rate:1,volume:1,opacity:1,zIndex:0},aa=Object.freeze(Object.defineProperty({__proto__:null,MediaSurfaceStateSchema:sa,defaultAudioOptions:Ee,defaultImageOptions:we,defaultVideoOptions:re},Symbol.toStringTag,{value:"Module"}));var Fe={},Qt;function ua(){return Qt||(Qt=1,function(e){var t={};/*! howler.js v2.2.1 | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */(function(){var n=function(){this.init()};n.prototype={init:function(){var i=this||o;return i._counter=1e3,i._html5AudioPool=[],i.html5PoolSize=10,i._codecs={},i._howls=[],i._muted=!1,i._volume=1,i._canPlayEvent="canplaythrough",i._navigator=typeof window<"u"&&window.navigator?window.navigator:null,i.masterGain=null,i.noAudio=!1,i.usingWebAudio=!0,i.autoSuspend=!0,i.ctx=null,i.autoUnlock=!0,i._setup(),i},volume:function(i){var s=this||o;if(i=parseFloat(i),s.ctx||g(),i!==void 0&&i>=0&&i<=1){if(s._volume=i,s._muted)return s;s.usingWebAudio&&s.masterGain.gain.setValueAtTime(i,o.ctx.currentTime);for(var u=0;u<s._howls.length;u++)if(!s._howls[u]._webAudio)for(var d=s._howls[u]._getSoundIds(),h=0;h<d.length;h++){var v=s._howls[u]._soundById(d[h]);v&&v._node&&(v._node.volume=v._volume*i)}return s}return s._volume},mute:function(i){var s=this||o;s.ctx||g(),s._muted=i,s.usingWebAudio&&s.masterGain.gain.setValueAtTime(i?0:s._volume,o.ctx.currentTime);for(var u=0;u<s._howls.length;u++)if(!s._howls[u]._webAudio)for(var d=s._howls[u]._getSoundIds(),h=0;h<d.length;h++){var v=s._howls[u]._soundById(d[h]);v&&v._node&&(v._node.muted=!!i||v._muted)}return s},stop:function(){for(var i=this||o,s=0;s<i._howls.length;s++)i._howls[s].stop();return i},unload:function(){for(var i=this||o,s=i._howls.length-1;s>=0;s--)i._howls[s].unload();return i.usingWebAudio&&i.ctx&&i.ctx.close!==void 0&&(i.ctx.close(),i.ctx=null,g()),i},codecs:function(i){return(this||o)._codecs[i.replace(/^x-/,"")]},_setup:function(){var i=this||o;if(i.state=i.ctx&&i.ctx.state||"suspended",i._autoSuspend(),!i.usingWebAudio)if(typeof Audio<"u")try{var s=new Audio;s.oncanplaythrough===void 0&&(i._canPlayEvent="canplay")}catch{i.noAudio=!0}else i.noAudio=!0;try{var s=new Audio;s.muted&&(i.noAudio=!0)}catch{}return i.noAudio||i._setupCodecs(),i},_setupCodecs:function(){var i=this||o,s=null;try{s=typeof Audio<"u"?new Audio:null}catch{return i}if(!s||typeof s.canPlayType!="function")return i;var u=s.canPlayType("audio/mpeg;").replace(/^no$/,""),d=i._navigator&&i._navigator.userAgent.match(/OPR\/([0-6].)/g),h=d&&parseInt(d[0].split("/")[1],10)<33;return i._codecs={mp3:!(h||!u&&!s.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!u,opus:!!s.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!s.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!s.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(s.canPlayType('audio/wav; codecs="1"')||s.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!s.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!s.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(s.canPlayType("audio/x-m4a;")||s.canPlayType("audio/m4a;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(s.canPlayType("audio/x-m4b;")||s.canPlayType("audio/m4b;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(s.canPlayType("audio/x-mp4;")||s.canPlayType("audio/mp4;")||s.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!s.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),webm:!!s.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),dolby:!!s.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(s.canPlayType("audio/x-flac;")||s.canPlayType("audio/flac;")).replace(/^no$/,"")},i},_unlockAudio:function(){var i=this||o;if(!i._audioUnlocked&&i.ctx){i._audioUnlocked=!1,i.autoUnlock=!1,i._mobileUnloaded||i.ctx.sampleRate===44100||(i._mobileUnloaded=!0,i.unload()),i._scratchBuffer=i.ctx.createBuffer(1,1,22050);var s=function(u){for(;i._html5AudioPool.length<i.html5PoolSize;)try{var d=new Audio;d._unlocked=!0,i._releaseHtml5Audio(d)}catch{i.noAudio=!0;break}for(var h=0;h<i._howls.length;h++)if(!i._howls[h]._webAudio)for(var v=i._howls[h]._getSoundIds(),_=0;_<v.length;_++){var w=i._howls[h]._soundById(v[_]);w&&w._node&&!w._node._unlocked&&(w._node._unlocked=!0,w._node.load())}i._autoResume();var E=i.ctx.createBufferSource();E.buffer=i._scratchBuffer,E.connect(i.ctx.destination),E.start===void 0?E.noteOn(0):E.start(0),typeof i.ctx.resume=="function"&&i.ctx.resume(),E.onended=function(){E.disconnect(0),i._audioUnlocked=!0,document.removeEventListener("touchstart",s,!0),document.removeEventListener("touchend",s,!0),document.removeEventListener("click",s,!0);for(var k=0;k<i._howls.length;k++)i._howls[k]._emit("unlock")}};return document.addEventListener("touchstart",s,!0),document.addEventListener("touchend",s,!0),document.addEventListener("click",s,!0),i}},_obtainHtml5Audio:function(){var i=this||o;if(i._html5AudioPool.length)return i._html5AudioPool.pop();var s=new Audio().play();return s&&typeof Promise<"u"&&(s instanceof Promise||typeof s.then=="function")&&s.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(i){var s=this||o;return i._unlocked&&s._html5AudioPool.push(i),s},_autoSuspend:function(){var i=this;if(i.autoSuspend&&i.ctx&&i.ctx.suspend!==void 0&&o.usingWebAudio){for(var s=0;s<i._howls.length;s++)if(i._howls[s]._webAudio){for(var u=0;u<i._howls[s]._sounds.length;u++)if(!i._howls[s]._sounds[u]._paused)return i}return i._suspendTimer&&clearTimeout(i._suspendTimer),i._suspendTimer=setTimeout(function(){if(i.autoSuspend){i._suspendTimer=null,i.state="suspending";var d=function(){i.state="suspended",i._resumeAfterSuspend&&(delete i._resumeAfterSuspend,i._autoResume())};i.ctx.suspend().then(d,d)}},3e4),i}},_autoResume:function(){var i=this;if(i.ctx&&i.ctx.resume!==void 0&&o.usingWebAudio)return i.state==="running"&&i.ctx.state!=="interrupted"&&i._suspendTimer?(clearTimeout(i._suspendTimer),i._suspendTimer=null):i.state==="suspended"||i.state==="running"&&i.ctx.state==="interrupted"?(i.ctx.resume().then(function(){i.state="running";for(var s=0;s<i._howls.length;s++)i._howls[s]._emit("resume")}),i._suspendTimer&&(clearTimeout(i._suspendTimer),i._suspendTimer=null)):i.state==="suspending"&&(i._resumeAfterSuspend=!0),i}};var o=new n,r=function(i){var s=this;if(!i.src||i.src.length===0)return void console.error("An array of source files must be passed with any new Howl.");s.init(i)};r.prototype={init:function(i){var s=this;return o.ctx||g(),s._autoplay=i.autoplay||!1,s._format=typeof i.format!="string"?i.format:[i.format],s._html5=i.html5||!1,s._muted=i.mute||!1,s._loop=i.loop||!1,s._pool=i.pool||5,s._preload=typeof i.preload!="boolean"&&i.preload!=="metadata"||i.preload,s._rate=i.rate||1,s._sprite=i.sprite||{},s._src=typeof i.src!="string"?i.src:[i.src],s._volume=i.volume!==void 0?i.volume:1,s._xhr={method:i.xhr&&i.xhr.method?i.xhr.method:"GET",headers:i.xhr&&i.xhr.headers?i.xhr.headers:null,withCredentials:!(!i.xhr||!i.xhr.withCredentials)&&i.xhr.withCredentials},s._duration=0,s._state="unloaded",s._sounds=[],s._endTimers={},s._queue=[],s._playLock=!1,s._onend=i.onend?[{fn:i.onend}]:[],s._onfade=i.onfade?[{fn:i.onfade}]:[],s._onload=i.onload?[{fn:i.onload}]:[],s._onloaderror=i.onloaderror?[{fn:i.onloaderror}]:[],s._onplayerror=i.onplayerror?[{fn:i.onplayerror}]:[],s._onpause=i.onpause?[{fn:i.onpause}]:[],s._onplay=i.onplay?[{fn:i.onplay}]:[],s._onstop=i.onstop?[{fn:i.onstop}]:[],s._onmute=i.onmute?[{fn:i.onmute}]:[],s._onvolume=i.onvolume?[{fn:i.onvolume}]:[],s._onrate=i.onrate?[{fn:i.onrate}]:[],s._onseek=i.onseek?[{fn:i.onseek}]:[],s._onunlock=i.onunlock?[{fn:i.onunlock}]:[],s._onresume=[],s._webAudio=o.usingWebAudio&&!s._html5,o.ctx!==void 0&&o.ctx&&o.autoUnlock&&o._unlockAudio(),o._howls.push(s),s._autoplay&&s._queue.push({event:"play",action:function(){s.play()}}),s._preload&&s._preload!=="none"&&s.load(),s},load:function(){var i=this,s=null;if(o.noAudio)return void i._emit("loaderror",null,"No audio support.");typeof i._src=="string"&&(i._src=[i._src]);for(var u=0;u<i._src.length;u++){var d,h;if(i._format&&i._format[u])d=i._format[u];else{if(typeof(h=i._src[u])!="string"){i._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}d=/^data:audio\/([^;,]+);/i.exec(h),d||(d=/\.([^.]+)$/.exec(h.split("?",1)[0])),d&&(d=d[1].toLowerCase())}if(d||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),d&&o.codecs(d)){s=i._src[u];break}}return s?(i._src=s,i._state="loading",window.location.protocol==="https:"&&s.slice(0,5)==="http:"&&(i._html5=!0,i._webAudio=!1),new a(i),i._webAudio&&l(i),i):void i._emit("loaderror",null,"No codec support for selected audio sources.")},play:function(i,s){var u=this,d=null;if(typeof i=="number")d=i,i=null;else{if(typeof i=="string"&&u._state==="loaded"&&!u._sprite[i])return null;if(i===void 0&&(i="__default",!u._playLock)){for(var h=0,v=0;v<u._sounds.length;v++)u._sounds[v]._paused&&!u._sounds[v]._ended&&(h++,d=u._sounds[v]._id);h===1?i=null:d=null}}var _=d?u._soundById(d):u._inactiveSound();if(!_)return null;if(d&&!i&&(i=_._sprite||"__default"),u._state!=="loaded"){_._sprite=i,_._ended=!1;var w=_._id;return u._queue.push({event:"play",action:function(){u.play(w)}}),w}if(d&&!_._paused)return s||u._loadQueue("play"),_._id;u._webAudio&&o._autoResume();var E=Math.max(0,_._seek>0?_._seek:u._sprite[i][0]/1e3),k=Math.max(0,(u._sprite[i][0]+u._sprite[i][1])/1e3-E),R=1e3*k/Math.abs(_._rate),W=u._sprite[i][0]/1e3,Ce=(u._sprite[i][0]+u._sprite[i][1])/1e3;_._sprite=i,_._ended=!1;var Ke=function(){_._paused=!1,_._seek=E,_._start=W,_._stop=Ce,_._loop=!(!_._loop&&!u._sprite[i][2])};if(E>=Ce)return void u._ended(_);var I=_._node;if(u._webAudio){var un=function(){u._playLock=!1,Ke(),u._refreshBuffer(_);var ne=_._muted||u._muted?0:_._volume;I.gain.setValueAtTime(ne,o.ctx.currentTime),_._playStart=o.ctx.currentTime,I.bufferSource.start===void 0?_._loop?I.bufferSource.noteGrainOn(0,E,86400):I.bufferSource.noteGrainOn(0,E,k):_._loop?I.bufferSource.start(0,E,86400):I.bufferSource.start(0,E,k),R!==1/0&&(u._endTimers[_._id]=setTimeout(u._ended.bind(u,_),R)),s||setTimeout(function(){u._emit("play",_._id),u._loadQueue()},0)};o.state==="running"&&o.ctx.state!=="interrupted"?un():(u._playLock=!0,u.once("resume",un),u._clearTimer(_._id))}else{var cn=function(){I.currentTime=E,I.muted=_._muted||u._muted||o._muted||I.muted,I.volume=_._volume*o.volume(),I.playbackRate=_._rate;try{var ne=I.play();if(ne&&typeof Promise<"u"&&(ne instanceof Promise||typeof ne.then=="function")?(u._playLock=!0,Ke(),ne.then(function(){u._playLock=!1,I._unlocked=!0,s||(u._emit("play",_._id),u._loadQueue())}).catch(function(){u._playLock=!1,u._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."),_._ended=!0,_._paused=!0})):s||(u._playLock=!1,Ke(),u._emit("play",_._id),u._loadQueue()),I.playbackRate=_._rate,I.paused)return void u._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");i!=="__default"||_._loop?u._endTimers[_._id]=setTimeout(u._ended.bind(u,_),R):(u._endTimers[_._id]=function(){u._ended(_),I.removeEventListener("ended",u._endTimers[_._id],!1)},I.addEventListener("ended",u._endTimers[_._id],!1))}catch(Pa){u._emit("playerror",_._id,Pa)}};I.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(I.src=u._src,I.load());var Za=window&&window.ejecta||!I.readyState&&o._navigator.isCocoonJS;if(I.readyState>=3||Za)cn();else{u._playLock=!0;var ln=function(){cn(),I.removeEventListener(o._canPlayEvent,ln,!1)};I.addEventListener(o._canPlayEvent,ln,!1),u._clearTimer(_._id)}}return _._id},pause:function(i){var s=this;if(s._state!=="loaded"||s._playLock)return s._queue.push({event:"pause",action:function(){s.pause(i)}}),s;for(var u=s._getSoundIds(i),d=0;d<u.length;d++){s._clearTimer(u[d]);var h=s._soundById(u[d]);if(h&&!h._paused&&(h._seek=s.seek(u[d]),h._rateSeek=0,h._paused=!0,s._stopFade(u[d]),h._node))if(s._webAudio){if(!h._node.bufferSource)continue;h._node.bufferSource.stop===void 0?h._node.bufferSource.noteOff(0):h._node.bufferSource.stop(0),s._cleanBuffer(h._node)}else isNaN(h._node.duration)&&h._node.duration!==1/0||h._node.pause();arguments[1]||s._emit("pause",h?h._id:null)}return s},stop:function(i,s){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"stop",action:function(){u.stop(i,s)}}),u;for(var d=u._getSoundIds(i),h=0;h<d.length;h++){u._clearTimer(d[h]);var v=u._soundById(d[h]);v&&(v._seek=v._start||0,v._rateSeek=0,v._paused=!0,v._ended=!0,u._stopFade(d[h]),v._node&&(u._webAudio?v._node.bufferSource&&(v._node.bufferSource.stop===void 0?v._node.bufferSource.noteOff(0):v._node.bufferSource.stop(0),u._cleanBuffer(v._node)):isNaN(v._node.duration)&&v._node.duration!==1/0||(v._node.currentTime=v._start||0,v._node.pause(),v._node.duration===1/0&&u._clearSound(v._node))),s||u._emit("stop",v._id))}return u},mute:function(i,s){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"mute",action:function(){u.mute(i,s)}}),u;if(s===void 0){if(typeof i!="boolean")return u._muted;u._muted=i}for(var d=u._getSoundIds(s),h=0;h<d.length;h++){var v=u._soundById(d[h]);v&&(v._muted=i,v._interval&&u._stopFade(v._id),u._webAudio&&v._node?v._node.gain.setValueAtTime(i?0:v._volume,o.ctx.currentTime):v._node&&(v._node.muted=!!o._muted||i),u._emit("mute",v._id))}return u},volume:function(){var i,s,u=this,d=arguments;if(d.length===0)return u._volume;d.length===1||d.length===2&&d[1]===void 0?u._getSoundIds().indexOf(d[0])>=0?s=parseInt(d[0],10):i=parseFloat(d[0]):d.length>=2&&(i=parseFloat(d[0]),s=parseInt(d[1],10));var h;if(!(i!==void 0&&i>=0&&i<=1))return h=s?u._soundById(s):u._sounds[0],h?h._volume:0;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"volume",action:function(){u.volume.apply(u,d)}}),u;s===void 0&&(u._volume=i),s=u._getSoundIds(s);for(var v=0;v<s.length;v++)(h=u._soundById(s[v]))&&(h._volume=i,d[2]||u._stopFade(s[v]),u._webAudio&&h._node&&!h._muted?h._node.gain.setValueAtTime(i,o.ctx.currentTime):h._node&&!h._muted&&(h._node.volume=i*o.volume()),u._emit("volume",h._id));return u},fade:function(i,s,u,d){var h=this;if(h._state!=="loaded"||h._playLock)return h._queue.push({event:"fade",action:function(){h.fade(i,s,u,d)}}),h;i=Math.min(Math.max(0,parseFloat(i)),1),s=Math.min(Math.max(0,parseFloat(s)),1),u=parseFloat(u),h.volume(i,d);for(var v=h._getSoundIds(d),_=0;_<v.length;_++){var w=h._soundById(v[_]);if(w){if(d||h._stopFade(v[_]),h._webAudio&&!w._muted){var E=o.ctx.currentTime,k=E+u/1e3;w._volume=i,w._node.gain.setValueAtTime(i,E),w._node.gain.linearRampToValueAtTime(s,k)}h._startFadeInterval(w,i,s,u,v[_],d===void 0)}}return h},_startFadeInterval:function(i,s,u,d,h,v){var _=this,w=s,E=u-s,k=Math.abs(E/.01),R=Math.max(4,k>0?d/k:d),W=Date.now();i._fadeTo=u,i._interval=setInterval(function(){var Ce=(Date.now()-W)/d;W=Date.now(),w+=E*Ce,w=Math.round(100*w)/100,w=E<0?Math.max(u,w):Math.min(u,w),_._webAudio?i._volume=w:_.volume(w,i._id,!0),v&&(_._volume=w),(u<s&&w<=u||u>s&&w>=u)&&(clearInterval(i._interval),i._interval=null,i._fadeTo=null,_.volume(u,i._id),_._emit("fade",i._id))},R)},_stopFade:function(i){var s=this,u=s._soundById(i);return u&&u._interval&&(s._webAudio&&u._node.gain.cancelScheduledValues(o.ctx.currentTime),clearInterval(u._interval),u._interval=null,s.volume(u._fadeTo,i),u._fadeTo=null,s._emit("fade",i)),s},loop:function(){var i,s,u,d=this,h=arguments;if(h.length===0)return d._loop;if(h.length===1){if(typeof h[0]!="boolean")return!!(u=d._soundById(parseInt(h[0],10)))&&u._loop;i=h[0],d._loop=i}else h.length===2&&(i=h[0],s=parseInt(h[1],10));for(var v=d._getSoundIds(s),_=0;_<v.length;_++)(u=d._soundById(v[_]))&&(u._loop=i,d._webAudio&&u._node&&u._node.bufferSource&&(u._node.bufferSource.loop=i,i&&(u._node.bufferSource.loopStart=u._start||0,u._node.bufferSource.loopEnd=u._stop)));return d},rate:function(){var i,s,u=this,d=arguments;if(d.length===0)s=u._sounds[0]._id;else if(d.length===1){var h=u._getSoundIds(),v=h.indexOf(d[0]);v>=0?s=parseInt(d[0],10):i=parseFloat(d[0])}else d.length===2&&(i=parseFloat(d[0]),s=parseInt(d[1],10));var _;if(typeof i!="number")return _=u._soundById(s),_?_._rate:u._rate;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"rate",action:function(){u.rate.apply(u,d)}}),u;s===void 0&&(u._rate=i),s=u._getSoundIds(s);for(var w=0;w<s.length;w++)if(_=u._soundById(s[w])){u.playing(s[w])&&(_._rateSeek=u.seek(s[w]),_._playStart=u._webAudio?o.ctx.currentTime:_._playStart),_._rate=i,u._webAudio&&_._node&&_._node.bufferSource?_._node.bufferSource.playbackRate.setValueAtTime(i,o.ctx.currentTime):_._node&&(_._node.playbackRate=i);var E=u.seek(s[w]),k=(u._sprite[_._sprite][0]+u._sprite[_._sprite][1])/1e3-E,R=1e3*k/Math.abs(_._rate);!u._endTimers[s[w]]&&_._paused||(u._clearTimer(s[w]),u._endTimers[s[w]]=setTimeout(u._ended.bind(u,_),R)),u._emit("rate",_._id)}return u},seek:function(){var i,s,u=this,d=arguments;if(d.length===0)s=u._sounds[0]._id;else if(d.length===1){var h=u._getSoundIds(),v=h.indexOf(d[0]);v>=0?s=parseInt(d[0],10):u._sounds.length&&(s=u._sounds[0]._id,i=parseFloat(d[0]))}else d.length===2&&(i=parseFloat(d[0]),s=parseInt(d[1],10));if(s===void 0)return u;if(typeof i=="number"&&(u._state!=="loaded"||u._playLock))return u._queue.push({event:"seek",action:function(){u.seek.apply(u,d)}}),u;var _=u._soundById(s);if(_){if(!(typeof i=="number"&&i>=0)){if(u._webAudio){var w=u.playing(s)?o.ctx.currentTime-_._playStart:0,E=_._rateSeek?_._rateSeek-_._seek:0;return _._seek+(E+w*Math.abs(_._rate))}return _._node.currentTime}var k=u.playing(s);k&&u.pause(s,!0),_._seek=i,_._ended=!1,u._clearTimer(s),u._webAudio||!_._node||isNaN(_._node.duration)||(_._node.currentTime=i);var R=function(){u._emit("seek",s),k&&u.play(s,!0)};if(k&&!u._webAudio){var W=function(){u._playLock?setTimeout(W,0):R()};setTimeout(W,0)}else R()}return u},playing:function(i){var s=this;if(typeof i=="number"){var u=s._soundById(i);return!!u&&!u._paused}for(var d=0;d<s._sounds.length;d++)if(!s._sounds[d]._paused)return!0;return!1},duration:function(i){var s=this,u=s._duration,d=s._soundById(i);return d&&(u=s._sprite[d._sprite][1]/1e3),u},state:function(){return this._state},unload:function(){for(var i=this,s=i._sounds,u=0;u<s.length;u++)s[u]._paused||i.stop(s[u]._id),i._webAudio||(i._clearSound(s[u]._node),s[u]._node.removeEventListener("error",s[u]._errorFn,!1),s[u]._node.removeEventListener(o._canPlayEvent,s[u]._loadFn,!1),s[u]._node.removeEventListener("ended",s[u]._endFn,!1),o._releaseHtml5Audio(s[u]._node)),delete s[u]._node,i._clearTimer(s[u]._id);var d=o._howls.indexOf(i);d>=0&&o._howls.splice(d,1);var h=!0;for(u=0;u<o._howls.length;u++)if(o._howls[u]._src===i._src||i._src.indexOf(o._howls[u]._src)>=0){h=!1;break}return c&&h&&delete c[i._src],o.noAudio=!1,i._state="unloaded",i._sounds=[],i=null,null},on:function(i,s,u,d){var h=this,v=h["_on"+i];return typeof s=="function"&&v.push(d?{id:u,fn:s,once:d}:{id:u,fn:s}),h},off:function(i,s,u){var d=this,h=d["_on"+i],v=0;if(typeof s=="number"&&(u=s,s=null),s||u)for(v=0;v<h.length;v++){var _=u===h[v].id;if(s===h[v].fn&&_||!s&&_){h.splice(v,1);break}}else if(i)d["_on"+i]=[];else{var w=Object.keys(d);for(v=0;v<w.length;v++)w[v].indexOf("_on")===0&&Array.isArray(d[w[v]])&&(d[w[v]]=[])}return d},once:function(i,s,u){var d=this;return d.on(i,s,u,1),d},_emit:function(i,s,u){for(var d=this,h=d["_on"+i],v=h.length-1;v>=0;v--)h[v].id&&h[v].id!==s&&i!=="load"||(setTimeout((function(_){_.call(this,s,u)}).bind(d,h[v].fn),0),h[v].once&&d.off(i,h[v].fn,h[v].id));return d._loadQueue(i),d},_loadQueue:function(i){var s=this;if(s._queue.length>0){var u=s._queue[0];u.event===i&&(s._queue.shift(),s._loadQueue()),i||u.action()}return s},_ended:function(i){var s=this,u=i._sprite;if(!s._webAudio&&i._node&&!i._node.paused&&!i._node.ended&&i._node.currentTime<i._stop)return setTimeout(s._ended.bind(s,i),100),s;var d=!(!i._loop&&!s._sprite[u][2]);if(s._emit("end",i._id),!s._webAudio&&d&&s.stop(i._id,!0).play(i._id),s._webAudio&&d){s._emit("play",i._id),i._seek=i._start||0,i._rateSeek=0,i._playStart=o.ctx.currentTime;var h=1e3*(i._stop-i._start)/Math.abs(i._rate);s._endTimers[i._id]=setTimeout(s._ended.bind(s,i),h)}return s._webAudio&&!d&&(i._paused=!0,i._ended=!0,i._seek=i._start||0,i._rateSeek=0,s._clearTimer(i._id),s._cleanBuffer(i._node),o._autoSuspend()),s._webAudio||d||s.stop(i._id,!0),s},_clearTimer:function(i){var s=this;if(s._endTimers[i]){if(typeof s._endTimers[i]!="function")clearTimeout(s._endTimers[i]);else{var u=s._soundById(i);u&&u._node&&u._node.removeEventListener("ended",s._endTimers[i],!1)}delete s._endTimers[i]}return s},_soundById:function(i){for(var s=this,u=0;u<s._sounds.length;u++)if(i===s._sounds[u]._id)return s._sounds[u];return null},_inactiveSound:function(){var i=this;i._drain();for(var s=0;s<i._sounds.length;s++)if(i._sounds[s]._ended)return i._sounds[s].reset();return new a(i)},_drain:function(){var i=this,s=i._pool,u=0,d=0;if(!(i._sounds.length<s)){for(d=0;d<i._sounds.length;d++)i._sounds[d]._ended&&u++;for(d=i._sounds.length-1;d>=0;d--){if(u<=s)return;i._sounds[d]._ended&&(i._webAudio&&i._sounds[d]._node&&i._sounds[d]._node.disconnect(0),i._sounds.splice(d,1),u--)}}},_getSoundIds:function(i){var s=this;if(i===void 0){for(var u=[],d=0;d<s._sounds.length;d++)u.push(s._sounds[d]._id);return u}return[i]},_refreshBuffer:function(i){var s=this;return i._node.bufferSource=o.ctx.createBufferSource(),i._node.bufferSource.buffer=c[s._src],i._panner?i._node.bufferSource.connect(i._panner):i._node.bufferSource.connect(i._node),i._node.bufferSource.loop=i._loop,i._loop&&(i._node.bufferSource.loopStart=i._start||0,i._node.bufferSource.loopEnd=i._stop||0),i._node.bufferSource.playbackRate.setValueAtTime(i._rate,o.ctx.currentTime),s},_cleanBuffer:function(i){var s=this,u=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(o._scratchBuffer&&i.bufferSource&&(i.bufferSource.onended=null,i.bufferSource.disconnect(0),u))try{i.bufferSource.buffer=o._scratchBuffer}catch{}return i.bufferSource=null,s},_clearSound:function(i){/MSIE |Trident\//.test(o._navigator&&o._navigator.userAgent)||(i.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var a=function(i){this._parent=i,this.init()};a.prototype={init:function(){var i=this,s=i._parent;return i._muted=s._muted,i._loop=s._loop,i._volume=s._volume,i._rate=s._rate,i._seek=0,i._paused=!0,i._ended=!0,i._sprite="__default",i._id=++o._counter,s._sounds.push(i),i.create(),i},create:function(){var i=this,s=i._parent,u=o._muted||i._muted||i._parent._muted?0:i._volume;return s._webAudio?(i._node=o.ctx.createGain===void 0?o.ctx.createGainNode():o.ctx.createGain(),i._node.gain.setValueAtTime(u,o.ctx.currentTime),i._node.paused=!0,i._node.connect(o.masterGain)):o.noAudio||(i._node=o._obtainHtml5Audio(),i._errorFn=i._errorListener.bind(i),i._node.addEventListener("error",i._errorFn,!1),i._loadFn=i._loadListener.bind(i),i._node.addEventListener(o._canPlayEvent,i._loadFn,!1),i._endFn=i._endListener.bind(i),i._node.addEventListener("ended",i._endFn,!1),i._node.src=s._src,i._node.preload=s._preload===!0?"auto":s._preload,i._node.volume=u*o.volume(),i._node.load()),i},reset:function(){var i=this,s=i._parent;return i._muted=s._muted,i._loop=s._loop,i._volume=s._volume,i._rate=s._rate,i._seek=0,i._rateSeek=0,i._paused=!0,i._ended=!0,i._sprite="__default",i._id=++o._counter,i},_errorListener:function(){var i=this;i._parent._emit("loaderror",i._id,i._node.error?i._node.error.code:0),i._node.removeEventListener("error",i._errorFn,!1)},_loadListener:function(){var i=this,s=i._parent;s._duration=Math.ceil(10*i._node.duration)/10,Object.keys(s._sprite).length===0&&(s._sprite={__default:[0,1e3*s._duration]}),s._state!=="loaded"&&(s._state="loaded",s._emit("load"),s._loadQueue()),i._node.removeEventListener(o._canPlayEvent,i._loadFn,!1)},_endListener:function(){var i=this,s=i._parent;s._duration===1/0&&(s._duration=Math.ceil(10*i._node.duration)/10,s._sprite.__default[1]===1/0&&(s._sprite.__default[1]=1e3*s._duration),s._ended(i)),i._node.removeEventListener("ended",i._endFn,!1)}};var c={},l=function(i){var s=i._src;if(c[s])return i._duration=c[s].duration,void y(i);if(/^data:[^;]+;base64,/.test(s)){for(var u=atob(s.split(",")[1]),d=new Uint8Array(u.length),h=0;h<u.length;++h)d[h]=u.charCodeAt(h);f(d.buffer,i)}else{var v=new XMLHttpRequest;v.open(i._xhr.method,s,!0),v.withCredentials=i._xhr.withCredentials,v.responseType="arraybuffer",i._xhr.headers&&Object.keys(i._xhr.headers).forEach(function(_){v.setRequestHeader(_,i._xhr.headers[_])}),v.onload=function(){var _=(v.status+"")[0];if(_!=="0"&&_!=="2"&&_!=="3")return void i._emit("loaderror",null,"Failed loading audio file with status: "+v.status+".");f(v.response,i)},v.onerror=function(){i._webAudio&&(i._html5=!0,i._webAudio=!1,i._sounds=[],delete c[s],i.load())},p(v)}},p=function(i){try{i.send()}catch{i.onerror()}},f=function(i,s){var u=function(){s._emit("loaderror",null,"Decoding audio data failed.")},d=function(h){h&&s._sounds.length>0?(c[s._src]=h,y(s,h)):u()};typeof Promise<"u"&&o.ctx.decodeAudioData.length===1?o.ctx.decodeAudioData(i).then(d).catch(u):o.ctx.decodeAudioData(i,d,u)},y=function(i,s){s&&!i._duration&&(i._duration=s.duration),Object.keys(i._sprite).length===0&&(i._sprite={__default:[0,1e3*i._duration]}),i._state!=="loaded"&&(i._state="loaded",i._emit("load"),i._loadQueue())},g=function(){if(o.usingWebAudio){try{typeof AudioContext<"u"?o.ctx=new AudioContext:typeof webkitAudioContext<"u"?o.ctx=new webkitAudioContext:o.usingWebAudio=!1}catch{o.usingWebAudio=!1}o.ctx||(o.usingWebAudio=!1);var i=/iP(hone|od|ad)/.test(o._navigator&&o._navigator.platform),s=o._navigator&&o._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),u=s?parseInt(s[1],10):null;if(i&&u&&u<9){var d=/safari/.test(o._navigator&&o._navigator.userAgent.toLowerCase());o._navigator&&!d&&(o.usingWebAudio=!1)}o.usingWebAudio&&(o.masterGain=o.ctx.createGain===void 0?o.ctx.createGainNode():o.ctx.createGain(),o.masterGain.gain.setValueAtTime(o._muted?0:o._volume,o.ctx.currentTime),o.masterGain.connect(o.ctx.destination)),o._setup()}};e.Howler=o,e.Howl=r,typeof t<"u"?(t.HowlerGlobal=n,t.Howler=o,t.Howl=r,t.Sound=a):typeof window<"u"&&(window.HowlerGlobal=n,window.Howler=o,window.Howl=r,window.Sound=a)})()}(Fe)),Fe}var Xt=ua();const ca=typeof navigator<"u"&&typeof navigator.standalone<"u";class la{constructor(t){this.cogsConnection=t,this.addEventListener("audioClipState",({detail:o})=>{t.sendMediaClipState(o)}),t.addEventListener("message",({message:o})=>{switch(o.type){case"media_config_update":if(this.globalVolume!==o.globalVolume&&this.setGlobalVolume(o.globalVolume),o.audioOutput!==void 0){const r=t.getAudioSinkId(o.audioOutput);this.setAudioSink(r??"")}this.updateConfig(o.files);break;case"audio_play":this.playAudioClip(o.file,{playId:o.playId,volume:o.volume,loop:!!o.loop,fade:o.fade});break;case"audio_pause":this.pauseAudioClip(o.file,{fade:o.fade});break;case"audio_stop":o.file?this.stopAudioClip(o.file,{fade:o.fade}):this.stopAllAudioClips({fade:o.fade});break;case"audio_set_clip_volume":this.setAudioClipVolume(o.file,{volume:o.volume,fade:o.fade});break}});const n=()=>{const o=Object.entries(this.audioClipPlayers).map(([r,a])=>{const c=Object.values(a.activeClips),l=c.some(({state:p})=>p.type==="playing"||p.type==="pausing"||p.type==="stopping"||p.type==="play_requested"||p.type==="pause_requested"||p.type==="stop_requested")?"playing":c.some(({state:p})=>p.type==="paused")?"paused":"stopped";return[r,l]});t.sendInitialMediaClipStates({mediaType:"audio",files:o})};t.addEventListener("open",n),n()}eventTarget=new EventTarget;globalVolume=1;audioClipPlayers={};sinkId="";setGlobalVolume(t){this.globalVolume=t,Xt.Howler.volume(t),this.notifyStateListeners()}playAudioClip(t,{playId:n,volume:o,fade:r,loop:a}){t in this.audioClipPlayers||(this.audioClipPlayers[t]=this.createClip(t,{preload:!1,ephemeral:!0})),this.updateAudioClipPlayer(t,c=>{const l=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="paused").map(([g])=>parseInt(g)),p=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="pausing").map(([g])=>parseInt(g));l.forEach(g=>{c.player.play(g)});const f=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="pause_requested").map(([g])=>parseInt(g)),y=l.length>0||p.length>0||f.length>0?[]:[c.player.play()];return p.forEach(g=>{c.player.off("fade",void 0,g),c.player.loop(a,g),this.updateActiveAudioClip(t,g,i=>({...i,state:{type:"playing"}})),se(r)?ae(c.player,o,r*1e3,g):Ve(c.player,o,g)}),[...l,...f,...y].forEach(g=>{c.player.loop(a,g),c.player.off("play",void 0,g),c.player.off("pause",void 0,g),c.player.off("fade",void 0,g),c.player.off("end",void 0,g),c.player.off("stop",void 0,g),c.player.once("play",()=>{Ue(c.player,this.sinkId)}),c.player.once("stop",()=>this.handleStoppedClip(t,n,g),g),c.player.on("end",()=>{c.activeClips[g]?.loop||this.handleStoppedClip(t,n,g)},g);const i={playId:n,state:{type:"play_requested"},loop:a,volume:o};c.player.once("play",()=>{const s=c.activeClips[g]?.state;s?.type==="pause_requested"?this.pauseAudioClip(t,{fade:s.fade},g,!0):s?.type==="stop_requested"?this.stopAudioClip(t,{fade:s.fade},g,!0):this.updateActiveAudioClip(t,g,u=>({...u,state:{type:"playing"}}))},g),se(r)?(c.player.volume(0,g),c.player.mute(!1,g),c.player.once("play",()=>{ae(c.player,o,r*1e3,g)},g)):Ve(c.player,o,g),c.activeClips={...c.activeClips,[g]:i}}),c}),this.notifyClipStateListeners(n,t,"playing")}pauseAudioClip(t,{fade:n},o,r){Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,a=>(a.activeClips=Object.fromEntries(Object.entries(a.activeClips).map(([c,l])=>{const p=parseInt(c);return(o===void 0||o===p)&&(r&&l.state.type==="pause_requested"||l.state.type==="playing"||l.state.type==="pausing"?se(n)?(a.player.once("fade",f=>{a.player.pause(f),this.updateActiveAudioClip(t,f,y=>({...y,state:{type:"paused"}})),this.notifyClipStateListeners(l.playId,t,"paused")},p),ae(a.player,0,n*1e3,p),l.state={type:"pausing"}):(a.player.pause(p),l.state={type:"paused"},this.notifyClipStateListeners(l.playId,t,"paused")):(l.state.type==="play_requested"||l.state.type==="pause_requested")&&(l.state={type:"pause_requested",fade:n})),[c,l]})),a))}stopAudioClip(t,{fade:n},o,r){da("Stop audio clip",{activeClips:this.audioClipPlayers[t]?.activeClips}),Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,a=>(a.activeClips=Object.fromEntries(Object.entries(a.activeClips).map(([c,l])=>{const p=parseInt(c);return(o===void 0||o===p)&&(r&&l.state.type==="stop_requested"||l.state.type==="playing"||l.state.type==="pausing"||l.state.type==="paused"||l.state.type==="stopping"?se(n)&&l.state.type!=="paused"?(a.player.off("fade",p),ae(a.player,0,n*1e3,p),a.player.once("fade",f=>{a.player.loop(!1,f),a.player.stop(f)},p),l.state={type:"stopping"}):(a.player.loop(!1,p),a.player.stop(p)):(l.state.type==="play_requested"||l.state.type==="pause_requested"||l.state.type==="stop_requested")&&(l.state={type:"stop_requested",fade:n})),[c,l]})),a))}stopAllAudioClips(t){Object.keys(this.audioClipPlayers).forEach(n=>{this.stopAudioClip(n,t)})}setAudioClipVolume(t,{volume:n,fade:o}){if(!(n>=0&&n<=1)){console.warn("Invalid volume",n);return}Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,r=>(r.activeClips=Object.fromEntries(Object.entries(r.activeClips).map(([a,c])=>{if(c.state.type!=="pausing"&&c.state.type!=="stopping"){const l=parseInt(a);return se(o)?ae(r.player,n,o*1e3,l):Ve(r.player,n,l),[a,{...c,volume:n}]}else return[a,c]})),r))}handleStoppedClip(t,n,o){this.updateAudioClipPlayer(t,r=>(delete r.activeClips[o],r)),this.notifyClipStateListeners(n,t,"stopped")}updateActiveAudioClip(t,n,o){this.updateAudioClipPlayer(t,r=>n in r.activeClips?{...r,activeClips:{...r.activeClips,[n]:o(r.activeClips[n])}}:r)}updateAudioClipPlayer(t,n){t in this.audioClipPlayers&&(this.audioClipPlayers={...this.audioClipPlayers,[t]:n(this.audioClipPlayers[t])});const o=this.audioClipPlayers[t];o&&Object.keys(o.activeClips??{}).length===0&&o.config.ephemeral&&(o.player.unload(),delete this.audioClipPlayers[t]),this.notifyStateListeners()}setAudioSink(t){for(const n of Object.values(this.audioClipPlayers))Ue(n.player,t);this.sinkId=t}updateConfig(t){const n=Object.fromEntries(Object.entries(t).filter(r=>{const a=r[1].type;return a==="audio"||!a})),o=this.audioClipPlayers;this.audioClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(p=>!(p in n)&&!o[p].config.ephemeral).forEach(p=>{o[p].player.unload(),delete r[p]}),Object.entries(n).filter(([p])=>!o[p]).forEach(([p,f])=>{r[p]=this.createClip(p,{...f,ephemeral:!1})}),Object.keys(o).filter(p=>p in n).forEach(p=>{r[p]=this.updatedClip(p,r[p],{...n[p],ephemeral:!1})}),r})(),this.notifyStateListeners()}notifyStateListeners(){const t=Object.entries(this.audioClipPlayers).reduce((r,[a,c])=>(r[a]={config:{preload:c.config.preload,ephemeral:c.config.ephemeral},activeClips:c.activeClips},r),{}),n=Object.values(this.audioClipPlayers).some(({activeClips:r})=>Object.values(r).some(a=>a.state.type==="playing"||a.state.type==="pausing"||a.state.type==="stopping")),o={globalVolume:this.globalVolume,isPlaying:n,clips:t};this.dispatchEvent("state",o)}notifyClipStateListeners(t,n,o){this.dispatchEvent("audioClipState",{mediaType:"audio",playId:t,file:n,status:o})}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t,n){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:n}))}createPlayer(t,n){const o=new Xt.Howl({src:this.cogsConnection.getAssetUrl(t),autoplay:!1,loop:!1,volume:1,html5:!0,preload:n.preload});return Ue(o,this.sinkId),o}createClip(t,n){return{config:n,player:this.createPlayer(t,n),activeClips:{}}}updatedClip(t,n,o){const r={...n,config:o};return n.config.preload!==o.preload&&(r.player.unload(),r.player=this.createPlayer(t,o)),r}}function da(...e){}function se(e){return!ca&&typeof e=="number"&&!isNaN(e)&&e>0}function Ue(e,t){t!==void 0&&(e._html5?e._sounds?.forEach(n=>{n._node?.setSinkId?.(t)}):console.warn("Cannot set sink ID: web audio not supported",e))}function Ve(e,t,n){e.volume(t,n),e.mute(t===0,n)}function ae(e,t,n,o){e.fade(e.volume(o),t,n,o)}var Be=(e=>(e.Paused="paused",e.Playing="playing",e))(Be||{});class pa{constructor(t,n=document.body){this.cogsConnection=t,this.parentElement=n,this.addEventListener("videoClipState",({detail:r})=>{t.sendMediaClipState(r)}),t.addEventListener("message",({message:r})=>{switch(r.type){case"media_config_update":if(this.setGlobalVolume(r.globalVolume),r.audioOutput!==void 0){const a=t.getAudioSinkId(r.audioOutput);this.setAudioSink(a??"")}this.updateConfig(r.files);break;case"video_play":this.playVideoClip(r.file,{playId:r.playId,volume:r.volume,loop:!!r.loop,fit:r.fit});break;case"video_pause":this.pauseVideoClip();break;case"video_stop":this.stopVideoClip();break;case"video_set_volume":this.setVideoClipVolume({volume:r.volume});break;case"video_set_fit":this.setVideoClipFit({fit:r.fit});break}});const o=()=>{const r=Object.entries(this.videoClipPlayers).map(([a,c])=>{const l=c.videoElement.paused?c.videoElement.currentTime===0||c.videoElement.currentTime===c.videoElement.duration?"paused":"stopped":"playing";return[a,l]});t.sendInitialMediaClipStates({mediaType:"video",files:r})};t.addEventListener("open",o),o()}eventTarget=new EventTarget;globalVolume=1;videoClipPlayers={};activeClip;pendingClip;parentElement;sinkId="";setParentElement(t){this.parentElement=t,Object.values(this.videoClipPlayers).forEach(n=>{t.appendChild(n.videoElement)})}resetParentElement(){this.setParentElement(document.body)}setGlobalVolume(t){Object.values(this.videoClipPlayers).forEach(n=>{ke(n.videoElement,n.volume*t)}),this.globalVolume=t,this.notifyStateListeners()}playVideoClip(t,{playId:n,volume:o,loop:r,fit:a}){this.videoClipPlayers[t]||(this.videoClipPlayers[t]=this.createClipPlayer(t,{preload:"none",ephemeral:!0,fit:a})),this.pendingClip&&this.updateVideoClipPlayer(this.pendingClip.path,c=>(c.videoElement.load(),c)),this.activeClip?.path!==t&&(this.pendingClip={path:t,playId:n,actionOncePlaying:"play"}),this.updateVideoClipPlayer(t,c=>(c.volume=o,ke(c.videoElement,o*this.globalVolume),c.videoElement.loop=r,c.videoElement.style.objectFit=a,c.videoElement.currentTime===c.videoElement.duration&&(c.videoElement.currentTime=0),c.videoElement.play(),this.activeClip||(c.videoElement.style.display="block"),c))}pauseVideoClip(){if(this.pendingClip&&(this.pendingClip.actionOncePlaying="pause"),this.activeClip){const{playId:t,path:n}=this.activeClip;this.updateVideoClipPlayer(n,o=>(o.videoElement?.pause(),o)),this.notifyClipStateListeners(t,n,"paused")}}stopVideoClip(){this.pendingClip&&(this.pendingClip.actionOncePlaying="stop"),this.activeClip&&this.handleStoppedClip(this.activeClip.path)}setVideoClipVolume({volume:t}){const n=this.pendingClip??this.activeClip??void 0;if(n){if(!(t>=0&&t<=1)){console.warn("Invalid volume",t);return}this.updateVideoClipPlayer(n.path,o=>(o.videoElement&&(o.volume=t,ke(o.videoElement,t*this.globalVolume)),o))}}setVideoClipFit({fit:t}){const n=this.pendingClip??this.activeClip??void 0;n&&this.updateVideoClipPlayer(n.path,o=>(o.videoElement&&(o.videoElement.style.objectFit=t),o))}handleStoppedClip(t){if(!this.activeClip||this.activeClip.path!==t)return;const n=this.activeClip.playId;this.videoClipPlayers[this.activeClip.path]?.config.ephemeral&&this.unloadClip(t),this.activeClip=void 0,this.updateVideoClipPlayer(t,o=>(o.videoElement.pause(),o.videoElement.currentTime=0,o.videoElement.style.display="none",o)),this.notifyClipStateListeners(n,t,"stopped")}updateVideoClipPlayer(t,n){if(this.videoClipPlayers[t]){const o=n(this.videoClipPlayers[t]);o?this.videoClipPlayers[t]=o:delete this.videoClipPlayers[t],this.notifyStateListeners()}}setAudioSink(t){for(const n of Object.values(this.videoClipPlayers))tn(n,t);this.sinkId=t}updateConfig(t){const n=Object.fromEntries(Object.entries(t).filter(([,{type:r}])=>r==="video"||!r)),o=this.videoClipPlayers;this.videoClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(p=>!(p in n)).forEach(p=>{this.activeClip?.path===p&&o[p]?.config.ephemeral===!1?this.updateVideoClipPlayer(p,f=>(f.config={...f.config,ephemeral:!0},f)):(this.unloadClip(p),delete r[p])}),Object.entries(n).filter(([p])=>!o[p]).forEach(([p,f])=>{r[p]=this.createClipPlayer(p,{...f,preload:en(f.preload),ephemeral:!1,fit:"contain"})}),Object.entries(o).filter(([p])=>p in n).forEach(([p,f])=>{f.config.preload!==n[p].preload&&this.updateVideoClipPlayer(p,y=>(y.config={...y.config,preload:en(n[p].preload),ephemeral:!1},y.videoElement.preload=y.config.preload,y))}),r})(),this.notifyStateListeners()}notifyStateListeners(){const t={globalVolume:this.globalVolume,isPlaying:this.activeClip?!this.videoClipPlayers[this.activeClip.path].videoElement?.paused:!1,clips:{...this.videoClipPlayers},activeClip:this.activeClip?{path:this.activeClip.path,state:this.videoClipPlayers[this.activeClip.path].videoElement?.paused?Be.Paused:Be.Playing,loop:this.videoClipPlayers[this.activeClip.path].videoElement?.loop??!1,volume:this.videoClipPlayers[this.activeClip.path].videoElement?.muted?0:this.videoClipPlayers[this.activeClip.path].videoElement?.volume??0}:void 0};this.dispatchEvent("state",t)}notifyClipStateListeners(t,n,o){this.dispatchEvent("videoClipState",{playId:t,mediaType:"video",file:n,status:o})}addEventListener(t,n,o){this.eventTarget.addEventListener(t,n,o)}removeEventListener(t,n,o){this.eventTarget.removeEventListener(t,n,o)}dispatchEvent(t,n){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:n}))}createVideoElement(t,n,{volume:o}){const r=document.createElement("video");return r.playsInline=!0,r.src=this.cogsConnection.getAssetUrl(t),r.autoplay=!1,r.loop=!1,ke(r,o*this.globalVolume),r.preload=n.preload,r.addEventListener("playing",()=>{if(this.pendingClip?.path===t){switch(this.pendingClip.actionOncePlaying){case"play":{r.style.display="block",this.notifyClipStateListeners(this.pendingClip.playId,t,"playing");break}case"pause":{r.style.display="block",r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,t,"paused");break}case"stop":{r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,t,"stopped");break}}this.activeClip&&this.handleStoppedClip(this.activeClip.path),this.activeClip=this.pendingClip,this.pendingClip=void 0}else this.activeClip?.path===t?this.notifyClipStateListeners(this.activeClip.playId,t,"playing"):r.pause()}),r.addEventListener("ended",()=>{!this.pendingClip&&!r.loop&&this.handleStoppedClip(t)}),r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",r.style.objectFit=n.fit,r.style.display="none",this.parentElement.appendChild(r),r}createClipPlayer(t,n){const r={config:n,videoElement:this.createVideoElement(t,n,{volume:1}),volume:1};return tn(r,this.sinkId),r}unloadClip(t){if(this.activeClip?.path===t){const n=this.activeClip.playId;this.activeClip=void 0,this.notifyClipStateListeners(n,t,"stopped")}this.videoClipPlayers[t]?.videoElement.remove(),this.updateVideoClipPlayer(t,()=>null)}}function en(e){return typeof e=="string"?e:e?"auto":"none"}function tn(e,t){t!==void 0&&typeof e.videoElement.setSinkId=="function"&&e.videoElement.setSinkId(t)}function ke(e,t){e.volume=t,e.muted=t===0}function ue(e,t){switch(e.type){case"image":{if(e.keyframes[0][0]>t)return;const o=e.keyframes.filter(a=>a[1]!==null),r=Ge(o,t);return{...we,...r}}case"audio":{const n=e.keyframes.filter(a=>a[1]!==null),o=nn(n,t);if(!o)return;const r=Ge(n,t);return{...Ee,...r,...o}}case"video":{const n=e.keyframes.filter(a=>a[1]!==null),o=nn(n,t);if(!o)return;const r=Ge(n,t);return{...re,...r,...o}}}}function Ge(e,t){const n={};for(const[r,a]of e)r<=t?(Object.entries(a.lerp??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[r,l]}),Object.entries(a.set??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[r,l]})):Object.entries(a.lerp??{}).forEach(([c,l])=>{n[c]??={},n[c].after===void 0&&(n[c].after=[r,l])});const o={};return Object.entries(n).forEach(([r,{before:a,after:c}])=>{if(c===void 0&&a){o[r]=a[1];return}if(a&&c&&a[0]===c[0]){o[r]=c[1];return}if(a&&typeof a[1]=="number"&&c&&typeof c[1]=="number"){o[r]=a[1]+(t-a[0])*(c[1]-a[1])/(c[0]-a[0]);return}}),o}function nn(e,t){const n=e[0];if(!n||n[0]>t)return;let o=0,{t:r,rate:a}=Ee;for(const[f,y]of e){if(f>t)break;const{set:g}=y;if(!g)continue;const{t:i,rate:s}=g;if(i!==void 0){o=f,r=i,s!==void 0&&(a=s);continue}if(s!==void 0){const d=(f-o)*a;o=f,r+=d,a=s}}const l=(t-o)*a,p=r+l;return{rate:a,t:p}}const fa=1e3;class We{constructor(t,n,o){this.surfaceElement=t,this.clipElement=n,this._state=o,setTimeout(this.loop)}delay=fa;isConnected(t){return!(!this.surfaceElement||!this.clipElement||!this.surfaceElement.contains(this.clipElement)||t&&!this.clipElement.contains(t))}_state;setState(t){this._state=t,clearTimeout(this.timeout),this.loop()}timeout;loop=async()=>{this.isConnected()?(this.update(),isFinite(this.delay)&&(this.timeout=setTimeout(this.loop,this.delay))):this.destroy()}}class ha extends We{imageElement;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateImageElement(){this.imageElement=document.createElement("img"),this.clipElement.replaceChildren(this.imageElement),this.imageElement.style.position="absolute",this.imageElement.style.height="100%",this.imageElement.style.widows="100%"}update(){const t=ue(this._state,Date.now());if(t?(!this.imageElement||!this.isConnected(this.imageElement))&&this.updateImageElement():(this.imageElement?.remove(),this.imageElement=void 0),!this.imageElement||!t)return;this.imageElement.src.startsWith(this._state.file)||(this.imageElement.src=this._state.file),this.imageElement.style.objectFit!==this._state.fit&&(this.imageElement.style.objectFit=this._state.fit),parseFloat(this.imageElement.style.opacity)!==t.opacity&&(this.imageElement.style.opacity=String(t.opacity??we.opacity));const n=Math.round(t.zIndex??we.zIndex);parseInt(this.imageElement.style.zIndex)!==n&&(this.imageElement.style.zIndex=String(n));const{opacity:o}=t;typeof o=="string"&&o!==this.imageElement.style.opacity&&(this.imageElement.style.opacity=o)}destroy(){this.imageElement?.remove()}}const _a=1e3,qe=10,on=1e3,ma=200,va=.15,rn=.7,ga=.3;function ya(e){return-Math.sign(e)*Math.pow(Math.abs(e)/on,ga)*va}const ba=5;function wa(e,t,n){const o=ue(e,t);if(!o)return!1;const{t:r,rate:a}=o;if(r===void 0||a===void 0)return!1;const c=e.keyframes.filter(([f,y])=>f>t&&(y?.set?.t!==void 0||y?.set?.rate!==void 0))[0];if(c?.[1]?.set?.t!==0)return!1;const l=(n-r)/a,p=c[0]-t;return Math.abs(l-p)<=ba}class Ea extends We{videoElement;isSeeking=!1;timeToIntercept=void 0;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateVideoElement(){this.destroy(),this.videoElement=document.createElement("video"),this.clipElement.replaceChildren(this.videoElement),this.videoElement.style.position="absolute",this.videoElement.style.width="100%",this.videoElement.style.height="100%"}get videoDuration(){if(this.videoElement&&!(this.videoElement.readyState<HTMLMediaElement.HAVE_METADATA))return this.videoElement.duration*1e3}seekTo(t){this.videoElement&&(this.videoElement.addEventListener("seeked",()=>{console.debug("seeked"),this.isSeeking=!1},{once:!0,passive:!0}),this.videoElement.currentTime=t/1e3)}update(){if(this.isSeeking)return;const t=Date.now(),n=ue(this._state,t);if(n?(!this.videoElement||!this.isConnected(this.videoElement))&&this.updateVideoElement():(this.videoElement?.remove(),this.videoElement=void 0),!n||!this.videoElement)return;const{t:o,rate:r,volume:a}={...re,...n};this.videoElement.src.endsWith(this._state.file)||(this.videoElement.src=this._state.file),this.videoElement.style.objectFit!==this._state.fit&&(this.videoElement.style.objectFit=this._state.fit),parseFloat(this.videoElement.style.opacity)!==n.opacity&&(this.videoElement.style.opacity=String(n.opacity??re.opacity));const c=Math.round(n.zIndex??re.zIndex);parseInt(this.videoElement.style.zIndex)!==c&&(this.videoElement.style.zIndex=String(c)),this.videoElement.volume!==a&&(this.videoElement.volume=a);const l=this.videoDuration;if(l!==void 0){if(wa(this._state,t,l))this.videoElement.loop||(console.debug("starting loop"),this.videoElement.loop=!0);else if(this.videoElement.loop&&(console.debug("stopping loop"),this.videoElement.loop=!1),o>l){console.debug("ended"),this.delay=1/0;return}}this.videoElement.paused&&r>0&&(l===void 0||l>o)&&this.videoElement.play().catch(()=>{});const f=this.videoElement.currentTime*1e3-o,y=Math.abs(f);if(this.timeToIntercept!==void 0)if(y<=qe)console.log("intercepted",`${f.toFixed(0)}ms`),this.timeToIntercept=void 0;else{const g=f/(r-this.videoElement.playbackRate);g<this.timeToIntercept&&g>0?(console.debug(`intercepting ${g.toFixed(0)}ms`,`${f.toFixed(0)}ms`),this.timeToIntercept=g):(console.debug("missed intercept",f,this.timeToIntercept,g),this.timeToIntercept=void 0)}switch(!0){case y<=qe:{console.debug(`${r}x`,f.toFixed(0)),this.timeToIntercept=void 0,this.videoElement.playbackRate!==r&&(this.videoElement.playbackRate=r),this.delay=_a;break}case this.timeToIntercept!==void 0:this.delay=this.timeToIntercept*rn;break;case(r>0&&y>qe&&y<=on&&this.timeToIntercept===void 0):{const g=ya(f),i=Math.max(0,r+g);this.timeToIntercept=f/(r-i),console.debug(`${i.toFixed(2)}x`,`${f.toFixed(0)}ms`),this.videoElement.playbackRate!==i&&(this.videoElement.playbackRate=i),this.delay=this.timeToIntercept*rn;break}default:{this.videoElement.playbackRate!==r&&(this.videoElement.playbackRate=r),console.debug("seeking"),this.delay=10,this.seekTo(o+r*ma);break}}}destroy(){this.videoElement&&(this.videoElement.src="",this.videoElement.remove())}}const ka=1e3,sn=10,an=1e3,Ca=200,Sa=.2,Ta=.5;function Aa(e){return Math.sign(e)*Math.pow(Math.abs(e)/an,Ta)*Sa}class za extends We{audioElement;isSeeking=!1;constructor(t,n,o){super(t,n,o),this.clipElement=n}updateAudioElement(){this.destroy(),this.audioElement=document.createElement("audio"),this.clipElement.replaceChildren(this.audioElement)}seekTo(t){this.audioElement&&(this.audioElement.addEventListener("seeked",()=>{this.isSeeking=!1},{once:!0,passive:!0}),this.audioElement.currentTime=t/1e3)}update(){if(this.isSeeking)return;this.delay=ka;const t=ue(this._state,Date.now());if(t?(!this.audioElement||!this.isConnected(this.audioElement))&&this.updateAudioElement():this.destroy(),!t||!this.audioElement)return;const{t:n,rate:o,volume:r}={...Ee,...t};this.audioElement.src.endsWith(this._state.file)||(this.audioElement.src=this._state.file),this.audioElement.volume!==r&&(this.audioElement.volume=r),this.audioElement.paused&&o>0&&this.audioElement.play().catch(()=>{});const c=this.audioElement.currentTime*1e3-n,l=Math.abs(c);switch(this.delay=100,!0){case l<=sn:this.audioElement.playbackRate!==o&&(this.audioElement.playbackRate=o);break;case(o>0&&l>sn&&l<=an):{const p=Aa(c),f=Math.max(0,o-p);this.audioElement.playbackRate!==f&&(this.audioElement.playbackRate=f);break}default:{this.audioElement.playbackRate!==o&&(this.audioElement.playbackRate=o),this.delay=10,this.seekTo(n+o*(Ca/1e3));break}}}destroy(){this.audioElement&&(this.audioElement.src="",this.audioElement.remove())}}const Ia="data-clip-id";class $a{_state={};setState(t){this._state=t,this.update()}_element;get element(){return this._element}resources={};constructor(t){this._element=document.createElement("div"),this._element.style.width="100%",this._element.style.height="100%",this._state=t||{},this.update()}update(){Object.entries(this.resources).forEach(([n,{element:o,manager:r}])=>{n in this._state||(delete this.resources[n],o.remove(),r?.destroy())});const t=Object.keys(this._state).toSorted().map(n=>{const o=this.resources[n];if(o)return o.element;{const r=document.createElement("div");return r.setAttribute(Ia,n),this.resources[n]={element:r},r}});this._element.replaceChildren(...t),Object.keys(this._state).toSorted().forEach(n=>{const o=this._state[n],r=this.resources[n];if(!r)throw new Error("Failed to create resource");if(r.manager)r.manager.setState(o);else switch(o.type){case"image":r.manager=new ha(this._element,r.element,o);break;case"audio":r.manager=new za(this._element,r.element,o);break;case"video":r.manager=new Ea(this._element,r.element,o);break}})}}const Oa=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));T.CogsAudioPlayer=la,T.CogsConfigChangedEvent=nt,T.CogsConnection=zn,T.CogsConnectionCloseEvent=et,T.CogsConnectionOpenEvent=Xe,T.CogsIncomingEvent=it,T.CogsMediaConfigChangedEvent=rt,T.CogsMessageEvent=tt,T.CogsShowPhaseChangedEvent=st,T.CogsStateChangedEvent=ot,T.CogsVideoPlayer=pa,T.DataStoreItemEvent=Te,T.DataStoreItemsEvent=Ae,T.ManifestTypes=Oa,T.MediaSchema=aa,T.SurfaceManager=$a,T.assetUrl=Qe,T.getStateAtTime=ue,T.preloadUrl=yn,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|