@clockworkdog/cogs-client 2.11.2 → 3.0.0-alpha.1
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.
- package/dist/browser/index.mjs +3653 -1033
- package/dist/browser/index.umd.js +22 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types/CogsClientMessage.d.ts +19 -1
- package/dist/types/MediaSchema.d.ts +199 -0
- package/dist/types/MediaSchema.js +153 -0
- package/dist/utils/getStateAtTime.d.ts +28 -0
- package/dist/utils/getStateAtTime.js +141 -0
- package/package.json +8 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function($,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):($=typeof globalThis<"u"?globalThis:$||self,q($.COGS={}))})(this,function($){"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,9 +11,28 @@
|
|
|
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
|
|
14
|
+
***************************************************************************** */var we=function(e,t){return we=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},we(e,t)};function Be(e,t){we(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function rn(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 sn(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var o=n.call(e),i,u=[],c;try{for(;(t===void 0||t-- >0)&&!(i=o.next()).done;)u.push(i.value)}catch(l){c={error:l}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(c)throw c.error}}return u}function an(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(sn(arguments[t]));return e}var We=function(){function e(t,n){this.target=n,this.type=t}return e}(),un=function(e){Be(t,e);function t(n,o){var i=e.call(this,"error",o)||this;return i.message=n.message,i.error=n,i}return t}(We),cn=function(e){Be(t,e);function t(n,o,i){n===void 0&&(n=1e3),o===void 0&&(o="");var u=e.call(this,"close",i)||this;return u.wasClean=!0,u.code=n,u.reason=o,u}return t}(We);/*!
|
|
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 _e=function(){if(typeof WebSocket<"u")return WebSocket},fe=function(u){return typeof u<"u"&&!!u&&u.CLOSING===2},A={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},he=function(){function u(n,s,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(_){r._debug("open event");var c=r._options.minUptime,v=c===void 0?A.minUptime:c;clearTimeout(r._connectTimeout),r._uptimeTimeout=setTimeout(function(){return r._acceptOpen()},v),r._ws.binaryType=r._binaryType,r._messageQueue.forEach(function(f){return r._ws.send(f)}),r._messageQueue=[],r.onopen&&r.onopen(_),r._listeners.open.forEach(function(f){return r._callEventListener(_,f)})},this._handleMessage=function(_){r._debug("message event"),r.onmessage&&r.onmessage(_),r._listeners.message.forEach(function(c){return r._callEventListener(_,c)})},this._handleError=function(_){r._debug("error event",_.message),r._disconnect(void 0,_.message==="TIMEOUT"?"timeout":void 0),r.onerror&&r.onerror(_),r._debug("exec error listeners"),r._listeners.error.forEach(function(c){return r._callEventListener(_,c)}),r._connect()},this._handleClose=function(_){r._debug("close event"),r._clearTimeouts(),r._shouldReconnect&&r._connect(),r.onclose&&r.onclose(_),r._listeners.close.forEach(function(c){return r._callEventListener(_,c)})},this._url=n,this._protocols=s,this._options=o,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(u,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(u,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(u,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(u,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CONNECTING",{get:function(){return u.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"OPEN",{get:function(){return u.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CLOSING",{get:function(){return u.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"CLOSED",{get:function(){return u.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(n){this._binaryType=n,this._ws&&(this._ws.binaryType=n)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"bufferedAmount",{get:function(){var n=this._messageQueue.reduce(function(s,o){return typeof o=="string"?s+=o.length:o instanceof Blob?s+=o.size:s+=o.byteLength,s},0);return n+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?u.CLOSED:u.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),u.prototype.close=function(n,s){if(n===void 0&&(n=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(n,s)},u.prototype.reconnect=function(n,s){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===this.CLOSED?this._connect():(this._disconnect(n,s),this._connect())},u.prototype.send=function(n){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",n),this._ws.send(n);else{var s=this._options.maxEnqueuedMessages,o=s===void 0?A.maxEnqueuedMessages:s;this._messageQueue.length<o&&(this._debug("enqueue",n),this._messageQueue.push(n))}},u.prototype.addEventListener=function(n,s){this._listeners[n]&&this._listeners[n].push(s)},u.prototype.dispatchEvent=function(n){var s,o,r=this._listeners[n.type];if(r)try{for(var _=ue(r),c=_.next();!c.done;c=_.next()){var v=c.value;this._callEventListener(n,v)}}catch(f){s={error:f}}finally{try{c&&!c.done&&(o=_.return)&&o.call(_)}finally{if(s)throw s.error}}return!0},u.prototype.removeEventListener=function(n,s){this._listeners[n]&&(this._listeners[n]=this._listeners[n].filter(function(o){return o!==s}))},u.prototype._debug=function(){for(var n=[],s=0;s<arguments.length;s++)n[s]=arguments[s];this._options.debug&&console.log.apply(console,le(["RWS>"],n))},u.prototype._getNextDelay=function(){var n=this._options,s=n.reconnectionDelayGrowFactor,o=s===void 0?A.reconnectionDelayGrowFactor:s,r=n.minReconnectionDelay,_=r===void 0?A.minReconnectionDelay:r,c=n.maxReconnectionDelay,v=c===void 0?A.maxReconnectionDelay:c,f=0;return this._retryCount>0&&(f=_*Math.pow(o,this._retryCount-1),f>v&&(f=v)),this._debug("next delay",f),f},u.prototype._wait=function(){var n=this;return new Promise(function(s){setTimeout(s,n._getNextDelay())})},u.prototype._getNextUrl=function(n){if(typeof n=="string")return Promise.resolve(n);if(typeof n=="function"){var s=n();if(typeof s=="string")return Promise.resolve(s);if(s.then)return s}throw Error("Invalid URL")},u.prototype._connect=function(){var n=this;if(!(this._connectLock||!this._shouldReconnect)){this._connectLock=!0;var s=this._options,o=s.maxRetries,r=o===void 0?A.maxRetries:o,_=s.connectionTimeout,c=_===void 0?A.connectionTimeout:_,v=s.WebSocket,f=v===void 0?_e():v;if(this._retryCount>=r){this._debug("max retries reached",this._retryCount,">=",r);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!fe(f))throw Error("No valid WebSocket class provided");this._wait().then(function(){return n._getNextUrl(n._url)}).then(function(y){n._closeCalled||(n._debug("connect",{url:y,protocols:n._protocols}),n._ws=n._protocols?new f(y,n._protocols):new f(y),n._ws.binaryType=n._binaryType,n._connectLock=!1,n._addListeners(),n._connectTimeout=setTimeout(function(){return n._handleTimeout()},c))})}},u.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new ce(Error("TIMEOUT"),this))},u.prototype._disconnect=function(n,s){if(n===void 0&&(n=1e3),this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(n,s),this._handleClose(new pe(n,s,this))}catch{}}},u.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},u.prototype._callEventListener=function(n,s){"handleEvent"in s?s.handleEvent(n):s(n)},u.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))},u.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))},u.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},u}();const $=12095;function W(u){const n=typeof window<"u"?window.location:void 0,s=`/assets/${encodeURIComponent(u)}`;return`${n?.protocol}//${n?.hostname}:${$}${s}`}async function ve(u){const n=await fetch(u);return URL.createObjectURL(new Blob([await n.arrayBuffer()]))}class me{#e=new EventTarget;constructor(n){this._items={...n}}handleDataStoreItemsMessage(n){this._items={...this._items,...n.items},Object.entries(n.items).forEach(([s,o])=>{this.dispatchEvent(new R(s,o))}),this.dispatchEvent(new N(n.items))}get items(){return this._items}getItem(n){return this._items[n]}setItems(n){return this._items={...this._items,...n},Object.entries(n).forEach(([s,o])=>{this.dispatchEvent(new R(s,o))}),this.dispatchEvent(new N(n)),this}addEventListener(n,s,o){this.#e.addEventListener(n,s,o)}removeEventListener(n,s,o){this.#e.removeEventListener(n,s,o)}dispatchEvent(n){this.#e.dispatchEvent(n)}}class R extends Event{constructor(n,s){super("item"),this.key=n,this.value=s,this._cogsConnectionEventType="item"}}class N extends Event{constructor(n){super("items"),this.items=n,this._cogsConnectionEventType="item"}}const O=globalThis.Date;function ye(u){const n=u-O.now();function s(...r){return r.length===0?new O(s.now()):new O(...r)}const o=Object.getOwnPropertyDescriptors(O);Object.defineProperties(s,o),s.now=function(){return O.now()+n},globalThis.Date=s}let ge=0;function be(){return++ge}const Ce=5,we=1e4;function Ee({interval:u,send:n,onChange:s=ye,syncSampleSize:o=Ce,syncRequestTimeout:r=we}){const _={};async function c(){const C=[];for(let t=0;t<o;t++){const i=new Promise(a=>{const d=be(),p=Date.now(),l=performance.now();n({timesync:{id:d}});const m=(g,E)=>a({sentAt:l,receivedAt:g,serverNow:E,clientNow:p});_[d]={complete:m},setTimeout(()=>a(null),r)});C.push(i),await i}const h=(await Promise.all(C)).filter(t=>t!==null),e=Se(h);isNaN(e)||s(Date.now()+e)}const v=C=>{const h=performance.now(),e=_[C.timesync.id];e&&e.complete(h,C.timesync.now)};c();const f=setInterval(c,u);return{receive:v,destroy:()=>{clearInterval(f)}}}function Se(u){return u.map(({sentAt:n,receivedAt:s,clientNow:o,serverNow:r})=>{const _=(s-n)/2;return r-o-_}).reduce((n,s)=>n+s,0)/u.length}class Ae{constructor(n,{hostname:s=document.location.hostname,port:o=$}={},r,_){this.manifest=n,this.eventTarget=new EventTarget,this.currentConfig={},this.currentState={},this._showPhase=k.Setup,this._timerState=null,this._mediaConfig=null,this.audioOutputs=void 0,this._selectedAudioOutput="",this.currentState={...r},this.store=new me(_??{});const{useReconnectingWebsocket:c,path:v,pathParams:f}=Te(document.location.href);this.urlParams=new URLSearchParams(f),this.urlParams.set("screenWidth",window.screen.width.toString()),this.urlParams.set("screenHeight",window.screen.height.toString()),this.urlParams.set("screenPixelRatio",window.devicePixelRatio.toString());const y=`ws://${s}:${o}${v}?${this.urlParams}`;this.websocket=c?new he(y):new WebSocket(y);let C;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new H),this.setState(this.currentState),C=Ee({interval:6e4,send:h=>{this.websocket.send(JSON.stringify(h))}})},this.websocket.addEventListener("message",({data:h})=>{try{const e=JSON.parse(h);if(typeof e=="object"&&e!==null&&"timesync"in e){const t=e;C?.receive(t)}}catch(e){console.error(e)}}),this.websocket.onclose=()=>{C?.destroy(),this.dispatchEvent(new Q)},this.websocket.addEventListener("message",({data:h})=>{try{const e=JSON.parse(h);try{if(e.config)this.currentConfig=e.config,this.dispatchEvent(new z(this.currentConfig));else if(e.updates)this.currentState={...this.currentState,...e.updates},this.dispatchEvent(new Y(e.updates));else if(e.event&&e.event.key)this.dispatchEvent(new X(e.event.key,e.event.value));else if(typeof e.message=="object"){const t=e.message;switch(t.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:t.durationMillis,ticking:t.ticking};break;case"show_phase":this._showPhase=t.phase,this.dispatchEvent(new K(t.phase));break;case"media_config_update":this._mediaConfig=t;for(const i of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])t[i]?this.urlParams.set(i,"true"):this.urlParams.delete(i);this.dispatchEvent(new Z(t));break;case"data_store_items":this.store.handleDataStoreItemsMessage(t);break}this.dispatchEvent(new J(t))}}catch(t){console.warn("Error handling data",h,t)}}catch(e){console.error("Unable to parse incoming data from server",h,e)}}),this.store.addEventListener("items",h=>{this.sendDataStoreItems(h.items)});{const h=async()=>{if(navigator.mediaDevices){const e=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:t})=>t==="audiooutput");this.sendAudioOutputs(e),this.audioOutputs=e}};this.eventTarget.addEventListener("open",h),navigator.mediaDevices?.addEventListener("devicechange",h),h()}}get config(){return{...this.currentConfig}}get state(){return{...this.currentState}}get showPhase(){return this._showPhase}get timerState(){return this._timerState?{...this._timerState}:null}get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(n){return`${W(n)}?${this.urlParams?.toString()??""}`}get selectedAudioOutput(){return this._selectedAudioOutput}get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(n,...[s]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:n,value:s}}))}setState(n){this.currentState={...this.currentState,...n},this.isConnected&&this.websocket.send(JSON.stringify({updates:n}))}getAudioSinkId(n){return n?this.audioOutputs?.find(({label:s})=>s===n)?.deviceId:""}sendInitialMediaClipStates(n){this.isConnected&&this.websocket.send(JSON.stringify({allMediaClipStates:n}))}sendMediaClipState(n){this.isConnected&&this.websocket.send(JSON.stringify({mediaClipState:n}))}sendAudioOutputs(n){this.isConnected&&this.websocket.send(JSON.stringify({audioOutputs:n}))}sendDataStoreItems(n){this.isConnected&&this.websocket.send(JSON.stringify({dataStoreItems:n}))}setPluginWindowVisible(n){this.isConnected&&this.websocket.send(JSON.stringify({window:{visible:n}}))}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n){this.eventTarget.dispatchEvent(n)}}function Te(u){const n=new URL(u),s=new URLSearchParams(n.searchParams),o=s.get("local_id"),r=s.get("simulator")==="true",_=s.get("display")??"",c=n.pathname.startsWith("/plugin/")?decodeURIComponent(n.pathname.split("/")[2]):void 0;if(o){const v=s.get("t")??"";return s.delete("local_id"),{path:`/local/${encodeURIComponent(o)}`,pathParams:new URLSearchParams({t:v}),useReconnectingWebsocket:!0}}else if(r){const v=s.get("name")??"";return s.delete("simulator"),s.delete("name"),{path:`/simulator/${encodeURIComponent(v)}`,pathParams:s,useReconnectingWebsocket:!0}}else if(_){const v=s.get("displayIdIndex")??"";return s.delete("display"),s.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(_)}/${encodeURIComponent(v)}`}}else{if(c)return{path:`/plugin/${encodeURIComponent(c)}`,useReconnectingWebsocket:!0};{const v=s.get("serial")??"";return s.delete("serial"),{path:`/client/${encodeURIComponent(v)}`,pathParams:s}}}}class H extends Event{constructor(){super("open"),this._cogsConnectionEventType="open"}}class Q extends Event{constructor(){super("close"),this._cogsConnectionEventType="close"}}class J extends Event{constructor(n){super("message"),this.message=n,this._cogsConnectionEventType="message"}}class z extends Event{constructor(n){super("config"),this.config=n,this._cogsConnectionEventType="config"}}class Y extends Event{constructor(n){super("state"),this.state=n,this._cogsConnectionEventType="state"}}class X extends Event{constructor(n,s){super("event"),this.name=n,this.value=s,this._cogsConnectionEventType="event"}}class Z extends Event{constructor(n){super("mediaConfig"),this.mediaConfig=n,this._cogsConnectionEventType="mediaConfig"}}class K extends Event{constructor(n){super("showPhase"),this.showPhase=n,this._cogsConnectionEventType="showPhase"}}var D={},ee;function ke(){return ee||(ee=1,function(u){var n={};/*! howler.js v2.2.1 | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */(function(){var s=function(){this.init()};s.prototype={init:function(){var e=this||o;return e._counter=1e3,e._html5AudioPool=[],e.html5PoolSize=10,e._codecs={},e._howls=[],e._muted=!1,e._volume=1,e._canPlayEvent="canplaythrough",e._navigator=typeof window<"u"&&window.navigator?window.navigator:null,e.masterGain=null,e.noAudio=!1,e.usingWebAudio=!0,e.autoSuspend=!0,e.ctx=null,e.autoUnlock=!0,e._setup(),e},volume:function(e){var t=this||o;if(e=parseFloat(e),t.ctx||h(),e!==void 0&&e>=0&&e<=1){if(t._volume=e,t._muted)return t;t.usingWebAudio&&t.masterGain.gain.setValueAtTime(e,o.ctx.currentTime);for(var i=0;i<t._howls.length;i++)if(!t._howls[i]._webAudio)for(var a=t._howls[i]._getSoundIds(),d=0;d<a.length;d++){var p=t._howls[i]._soundById(a[d]);p&&p._node&&(p._node.volume=p._volume*e)}return t}return t._volume},mute:function(e){var t=this||o;t.ctx||h(),t._muted=e,t.usingWebAudio&&t.masterGain.gain.setValueAtTime(e?0:t._volume,o.ctx.currentTime);for(var i=0;i<t._howls.length;i++)if(!t._howls[i]._webAudio)for(var a=t._howls[i]._getSoundIds(),d=0;d<a.length;d++){var p=t._howls[i]._soundById(a[d]);p&&p._node&&(p._node.muted=!!e||p._muted)}return t},stop:function(){for(var e=this||o,t=0;t<e._howls.length;t++)e._howls[t].stop();return e},unload:function(){for(var e=this||o,t=e._howls.length-1;t>=0;t--)e._howls[t].unload();return e.usingWebAudio&&e.ctx&&e.ctx.close!==void 0&&(e.ctx.close(),e.ctx=null,h()),e},codecs:function(e){return(this||o)._codecs[e.replace(/^x-/,"")]},_setup:function(){var e=this||o;if(e.state=e.ctx&&e.ctx.state||"suspended",e._autoSuspend(),!e.usingWebAudio)if(typeof Audio<"u")try{var t=new Audio;t.oncanplaythrough===void 0&&(e._canPlayEvent="canplay")}catch{e.noAudio=!0}else e.noAudio=!0;try{var t=new Audio;t.muted&&(e.noAudio=!0)}catch{}return e.noAudio||e._setupCodecs(),e},_setupCodecs:function(){var e=this||o,t=null;try{t=typeof Audio<"u"?new Audio:null}catch{return e}if(!t||typeof t.canPlayType!="function")return e;var i=t.canPlayType("audio/mpeg;").replace(/^no$/,""),a=e._navigator&&e._navigator.userAgent.match(/OPR\/([0-6].)/g),d=a&&parseInt(a[0].split("/")[1],10)<33;return e._codecs={mp3:!(d||!i&&!t.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!i,opus:!!t.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!t.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!t.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(t.canPlayType('audio/wav; codecs="1"')||t.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!t.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!t.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(t.canPlayType("audio/x-m4a;")||t.canPlayType("audio/m4a;")||t.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(t.canPlayType("audio/x-m4b;")||t.canPlayType("audio/m4b;")||t.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(t.canPlayType("audio/x-mp4;")||t.canPlayType("audio/mp4;")||t.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!t.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),webm:!!t.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),dolby:!!t.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(t.canPlayType("audio/x-flac;")||t.canPlayType("audio/flac;")).replace(/^no$/,"")},e},_unlockAudio:function(){var e=this||o;if(!e._audioUnlocked&&e.ctx){e._audioUnlocked=!1,e.autoUnlock=!1,e._mobileUnloaded||e.ctx.sampleRate===44100||(e._mobileUnloaded=!0,e.unload()),e._scratchBuffer=e.ctx.createBuffer(1,1,22050);var t=function(i){for(;e._html5AudioPool.length<e.html5PoolSize;)try{var a=new Audio;a._unlocked=!0,e._releaseHtml5Audio(a)}catch{e.noAudio=!0;break}for(var d=0;d<e._howls.length;d++)if(!e._howls[d]._webAudio)for(var p=e._howls[d]._getSoundIds(),l=0;l<p.length;l++){var m=e._howls[d]._soundById(p[l]);m&&m._node&&!m._node._unlocked&&(m._node._unlocked=!0,m._node.load())}e._autoResume();var g=e.ctx.createBufferSource();g.buffer=e._scratchBuffer,g.connect(e.ctx.destination),g.start===void 0?g.noteOn(0):g.start(0),typeof e.ctx.resume=="function"&&e.ctx.resume(),g.onended=function(){g.disconnect(0),e._audioUnlocked=!0,document.removeEventListener("touchstart",t,!0),document.removeEventListener("touchend",t,!0),document.removeEventListener("click",t,!0);for(var E=0;E<e._howls.length;E++)e._howls[E]._emit("unlock")}};return document.addEventListener("touchstart",t,!0),document.addEventListener("touchend",t,!0),document.addEventListener("click",t,!0),e}},_obtainHtml5Audio:function(){var e=this||o;if(e._html5AudioPool.length)return e._html5AudioPool.pop();var t=new Audio().play();return t&&typeof Promise<"u"&&(t instanceof Promise||typeof t.then=="function")&&t.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(e){var t=this||o;return e._unlocked&&t._html5AudioPool.push(e),t},_autoSuspend:function(){var e=this;if(e.autoSuspend&&e.ctx&&e.ctx.suspend!==void 0&&o.usingWebAudio){for(var t=0;t<e._howls.length;t++)if(e._howls[t]._webAudio){for(var i=0;i<e._howls[t]._sounds.length;i++)if(!e._howls[t]._sounds[i]._paused)return e}return e._suspendTimer&&clearTimeout(e._suspendTimer),e._suspendTimer=setTimeout(function(){if(e.autoSuspend){e._suspendTimer=null,e.state="suspending";var a=function(){e.state="suspended",e._resumeAfterSuspend&&(delete e._resumeAfterSuspend,e._autoResume())};e.ctx.suspend().then(a,a)}},3e4),e}},_autoResume:function(){var e=this;if(e.ctx&&e.ctx.resume!==void 0&&o.usingWebAudio)return e.state==="running"&&e.ctx.state!=="interrupted"&&e._suspendTimer?(clearTimeout(e._suspendTimer),e._suspendTimer=null):e.state==="suspended"||e.state==="running"&&e.ctx.state==="interrupted"?(e.ctx.resume().then(function(){e.state="running";for(var t=0;t<e._howls.length;t++)e._howls[t]._emit("resume")}),e._suspendTimer&&(clearTimeout(e._suspendTimer),e._suspendTimer=null)):e.state==="suspending"&&(e._resumeAfterSuspend=!0),e}};var o=new s,r=function(e){var t=this;if(!e.src||e.src.length===0)return void console.error("An array of source files must be passed with any new Howl.");t.init(e)};r.prototype={init:function(e){var t=this;return o.ctx||h(),t._autoplay=e.autoplay||!1,t._format=typeof e.format!="string"?e.format:[e.format],t._html5=e.html5||!1,t._muted=e.mute||!1,t._loop=e.loop||!1,t._pool=e.pool||5,t._preload=typeof e.preload!="boolean"&&e.preload!=="metadata"||e.preload,t._rate=e.rate||1,t._sprite=e.sprite||{},t._src=typeof e.src!="string"?e.src:[e.src],t._volume=e.volume!==void 0?e.volume:1,t._xhr={method:e.xhr&&e.xhr.method?e.xhr.method:"GET",headers:e.xhr&&e.xhr.headers?e.xhr.headers:null,withCredentials:!(!e.xhr||!e.xhr.withCredentials)&&e.xhr.withCredentials},t._duration=0,t._state="unloaded",t._sounds=[],t._endTimers={},t._queue=[],t._playLock=!1,t._onend=e.onend?[{fn:e.onend}]:[],t._onfade=e.onfade?[{fn:e.onfade}]:[],t._onload=e.onload?[{fn:e.onload}]:[],t._onloaderror=e.onloaderror?[{fn:e.onloaderror}]:[],t._onplayerror=e.onplayerror?[{fn:e.onplayerror}]:[],t._onpause=e.onpause?[{fn:e.onpause}]:[],t._onplay=e.onplay?[{fn:e.onplay}]:[],t._onstop=e.onstop?[{fn:e.onstop}]:[],t._onmute=e.onmute?[{fn:e.onmute}]:[],t._onvolume=e.onvolume?[{fn:e.onvolume}]:[],t._onrate=e.onrate?[{fn:e.onrate}]:[],t._onseek=e.onseek?[{fn:e.onseek}]:[],t._onunlock=e.onunlock?[{fn:e.onunlock}]:[],t._onresume=[],t._webAudio=o.usingWebAudio&&!t._html5,o.ctx!==void 0&&o.ctx&&o.autoUnlock&&o._unlockAudio(),o._howls.push(t),t._autoplay&&t._queue.push({event:"play",action:function(){t.play()}}),t._preload&&t._preload!=="none"&&t.load(),t},load:function(){var e=this,t=null;if(o.noAudio)return void e._emit("loaderror",null,"No audio support.");typeof e._src=="string"&&(e._src=[e._src]);for(var i=0;i<e._src.length;i++){var a,d;if(e._format&&e._format[i])a=e._format[i];else{if(typeof(d=e._src[i])!="string"){e._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}a=/^data:audio\/([^;,]+);/i.exec(d),a||(a=/\.([^.]+)$/.exec(d.split("?",1)[0])),a&&(a=a[1].toLowerCase())}if(a||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),a&&o.codecs(a)){t=e._src[i];break}}return t?(e._src=t,e._state="loading",window.location.protocol==="https:"&&t.slice(0,5)==="http:"&&(e._html5=!0,e._webAudio=!1),new _(e),e._webAudio&&v(e),e):void e._emit("loaderror",null,"No codec support for selected audio sources.")},play:function(e,t){var i=this,a=null;if(typeof e=="number")a=e,e=null;else{if(typeof e=="string"&&i._state==="loaded"&&!i._sprite[e])return null;if(e===void 0&&(e="__default",!i._playLock)){for(var d=0,p=0;p<i._sounds.length;p++)i._sounds[p]._paused&&!i._sounds[p]._ended&&(d++,a=i._sounds[p]._id);d===1?e=null:a=null}}var l=a?i._soundById(a):i._inactiveSound();if(!l)return null;if(a&&!e&&(e=l._sprite||"__default"),i._state!=="loaded"){l._sprite=e,l._ended=!1;var m=l._id;return i._queue.push({event:"play",action:function(){i.play(m)}}),m}if(a&&!l._paused)return t||i._loadQueue("play"),l._id;i._webAudio&&o._autoResume();var g=Math.max(0,l._seek>0?l._seek:i._sprite[e][0]/1e3),E=Math.max(0,(i._sprite[e][0]+i._sprite[e][1])/1e3-g),S=1e3*E/Math.abs(l._rate),T=i._sprite[e][0]/1e3,j=(i._sprite[e][0]+i._sprite[e][1])/1e3;l._sprite=e,l._ended=!1;var F=function(){l._paused=!1,l._seek=g,l._start=T,l._stop=j,l._loop=!(!l._loop&&!i._sprite[e][2])};if(g>=j)return void i._ended(l);var b=l._node;if(i._webAudio){var se=function(){i._playLock=!1,F(),i._refreshBuffer(l);var L=l._muted||i._muted?0:l._volume;b.gain.setValueAtTime(L,o.ctx.currentTime),l._playStart=o.ctx.currentTime,b.bufferSource.start===void 0?l._loop?b.bufferSource.noteGrainOn(0,g,86400):b.bufferSource.noteGrainOn(0,g,E):l._loop?b.bufferSource.start(0,g,86400):b.bufferSource.start(0,g,E),S!==1/0&&(i._endTimers[l._id]=setTimeout(i._ended.bind(i,l),S)),t||setTimeout(function(){i._emit("play",l._id),i._loadQueue()},0)};o.state==="running"&&o.ctx.state!=="interrupted"?se():(i._playLock=!0,i.once("resume",se),i._clearTimer(l._id))}else{var re=function(){b.currentTime=g,b.muted=l._muted||i._muted||o._muted||b.muted,b.volume=l._volume*o.volume(),b.playbackRate=l._rate;try{var L=b.play();if(L&&typeof Promise<"u"&&(L instanceof Promise||typeof L.then=="function")?(i._playLock=!0,F(),L.then(function(){i._playLock=!1,b._unlocked=!0,t||(i._emit("play",l._id),i._loadQueue())}).catch(function(){i._playLock=!1,i._emit("playerror",l._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."),l._ended=!0,l._paused=!0})):t||(i._playLock=!1,F(),i._emit("play",l._id),i._loadQueue()),b.playbackRate=l._rate,b.paused)return void i._emit("playerror",l._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.");e!=="__default"||l._loop?i._endTimers[l._id]=setTimeout(i._ended.bind(i,l),S):(i._endTimers[l._id]=function(){i._ended(l),b.removeEventListener("ended",i._endTimers[l._id],!1)},b.addEventListener("ended",i._endTimers[l._id],!1))}catch(Ve){i._emit("playerror",l._id,Ve)}};b.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(b.src=i._src,b.load());var je=window&&window.ejecta||!b.readyState&&o._navigator.isCocoonJS;if(b.readyState>=3||je)re();else{i._playLock=!0;var ae=function(){re(),b.removeEventListener(o._canPlayEvent,ae,!1)};b.addEventListener(o._canPlayEvent,ae,!1),i._clearTimer(l._id)}}return l._id},pause:function(e){var t=this;if(t._state!=="loaded"||t._playLock)return t._queue.push({event:"pause",action:function(){t.pause(e)}}),t;for(var i=t._getSoundIds(e),a=0;a<i.length;a++){t._clearTimer(i[a]);var d=t._soundById(i[a]);if(d&&!d._paused&&(d._seek=t.seek(i[a]),d._rateSeek=0,d._paused=!0,t._stopFade(i[a]),d._node))if(t._webAudio){if(!d._node.bufferSource)continue;d._node.bufferSource.stop===void 0?d._node.bufferSource.noteOff(0):d._node.bufferSource.stop(0),t._cleanBuffer(d._node)}else isNaN(d._node.duration)&&d._node.duration!==1/0||d._node.pause();arguments[1]||t._emit("pause",d?d._id:null)}return t},stop:function(e,t){var i=this;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"stop",action:function(){i.stop(e,t)}}),i;for(var a=i._getSoundIds(e),d=0;d<a.length;d++){i._clearTimer(a[d]);var p=i._soundById(a[d]);p&&(p._seek=p._start||0,p._rateSeek=0,p._paused=!0,p._ended=!0,i._stopFade(a[d]),p._node&&(i._webAudio?p._node.bufferSource&&(p._node.bufferSource.stop===void 0?p._node.bufferSource.noteOff(0):p._node.bufferSource.stop(0),i._cleanBuffer(p._node)):isNaN(p._node.duration)&&p._node.duration!==1/0||(p._node.currentTime=p._start||0,p._node.pause(),p._node.duration===1/0&&i._clearSound(p._node))),t||i._emit("stop",p._id))}return i},mute:function(e,t){var i=this;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"mute",action:function(){i.mute(e,t)}}),i;if(t===void 0){if(typeof e!="boolean")return i._muted;i._muted=e}for(var a=i._getSoundIds(t),d=0;d<a.length;d++){var p=i._soundById(a[d]);p&&(p._muted=e,p._interval&&i._stopFade(p._id),i._webAudio&&p._node?p._node.gain.setValueAtTime(e?0:p._volume,o.ctx.currentTime):p._node&&(p._node.muted=!!o._muted||e),i._emit("mute",p._id))}return i},volume:function(){var e,t,i=this,a=arguments;if(a.length===0)return i._volume;a.length===1||a.length===2&&a[1]===void 0?i._getSoundIds().indexOf(a[0])>=0?t=parseInt(a[0],10):e=parseFloat(a[0]):a.length>=2&&(e=parseFloat(a[0]),t=parseInt(a[1],10));var d;if(!(e!==void 0&&e>=0&&e<=1))return d=t?i._soundById(t):i._sounds[0],d?d._volume:0;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"volume",action:function(){i.volume.apply(i,a)}}),i;t===void 0&&(i._volume=e),t=i._getSoundIds(t);for(var p=0;p<t.length;p++)(d=i._soundById(t[p]))&&(d._volume=e,a[2]||i._stopFade(t[p]),i._webAudio&&d._node&&!d._muted?d._node.gain.setValueAtTime(e,o.ctx.currentTime):d._node&&!d._muted&&(d._node.volume=e*o.volume()),i._emit("volume",d._id));return i},fade:function(e,t,i,a){var d=this;if(d._state!=="loaded"||d._playLock)return d._queue.push({event:"fade",action:function(){d.fade(e,t,i,a)}}),d;e=Math.min(Math.max(0,parseFloat(e)),1),t=Math.min(Math.max(0,parseFloat(t)),1),i=parseFloat(i),d.volume(e,a);for(var p=d._getSoundIds(a),l=0;l<p.length;l++){var m=d._soundById(p[l]);if(m){if(a||d._stopFade(p[l]),d._webAudio&&!m._muted){var g=o.ctx.currentTime,E=g+i/1e3;m._volume=e,m._node.gain.setValueAtTime(e,g),m._node.gain.linearRampToValueAtTime(t,E)}d._startFadeInterval(m,e,t,i,p[l],a===void 0)}}return d},_startFadeInterval:function(e,t,i,a,d,p){var l=this,m=t,g=i-t,E=Math.abs(g/.01),S=Math.max(4,E>0?a/E:a),T=Date.now();e._fadeTo=i,e._interval=setInterval(function(){var j=(Date.now()-T)/a;T=Date.now(),m+=g*j,m=Math.round(100*m)/100,m=g<0?Math.max(i,m):Math.min(i,m),l._webAudio?e._volume=m:l.volume(m,e._id,!0),p&&(l._volume=m),(i<t&&m<=i||i>t&&m>=i)&&(clearInterval(e._interval),e._interval=null,e._fadeTo=null,l.volume(i,e._id),l._emit("fade",e._id))},S)},_stopFade:function(e){var t=this,i=t._soundById(e);return i&&i._interval&&(t._webAudio&&i._node.gain.cancelScheduledValues(o.ctx.currentTime),clearInterval(i._interval),i._interval=null,t.volume(i._fadeTo,e),i._fadeTo=null,t._emit("fade",e)),t},loop:function(){var e,t,i,a=this,d=arguments;if(d.length===0)return a._loop;if(d.length===1){if(typeof d[0]!="boolean")return!!(i=a._soundById(parseInt(d[0],10)))&&i._loop;e=d[0],a._loop=e}else d.length===2&&(e=d[0],t=parseInt(d[1],10));for(var p=a._getSoundIds(t),l=0;l<p.length;l++)(i=a._soundById(p[l]))&&(i._loop=e,a._webAudio&&i._node&&i._node.bufferSource&&(i._node.bufferSource.loop=e,e&&(i._node.bufferSource.loopStart=i._start||0,i._node.bufferSource.loopEnd=i._stop)));return a},rate:function(){var e,t,i=this,a=arguments;if(a.length===0)t=i._sounds[0]._id;else if(a.length===1){var d=i._getSoundIds(),p=d.indexOf(a[0]);p>=0?t=parseInt(a[0],10):e=parseFloat(a[0])}else a.length===2&&(e=parseFloat(a[0]),t=parseInt(a[1],10));var l;if(typeof e!="number")return l=i._soundById(t),l?l._rate:i._rate;if(i._state!=="loaded"||i._playLock)return i._queue.push({event:"rate",action:function(){i.rate.apply(i,a)}}),i;t===void 0&&(i._rate=e),t=i._getSoundIds(t);for(var m=0;m<t.length;m++)if(l=i._soundById(t[m])){i.playing(t[m])&&(l._rateSeek=i.seek(t[m]),l._playStart=i._webAudio?o.ctx.currentTime:l._playStart),l._rate=e,i._webAudio&&l._node&&l._node.bufferSource?l._node.bufferSource.playbackRate.setValueAtTime(e,o.ctx.currentTime):l._node&&(l._node.playbackRate=e);var g=i.seek(t[m]),E=(i._sprite[l._sprite][0]+i._sprite[l._sprite][1])/1e3-g,S=1e3*E/Math.abs(l._rate);!i._endTimers[t[m]]&&l._paused||(i._clearTimer(t[m]),i._endTimers[t[m]]=setTimeout(i._ended.bind(i,l),S)),i._emit("rate",l._id)}return i},seek:function(){var e,t,i=this,a=arguments;if(a.length===0)t=i._sounds[0]._id;else if(a.length===1){var d=i._getSoundIds(),p=d.indexOf(a[0]);p>=0?t=parseInt(a[0],10):i._sounds.length&&(t=i._sounds[0]._id,e=parseFloat(a[0]))}else a.length===2&&(e=parseFloat(a[0]),t=parseInt(a[1],10));if(t===void 0)return i;if(typeof e=="number"&&(i._state!=="loaded"||i._playLock))return i._queue.push({event:"seek",action:function(){i.seek.apply(i,a)}}),i;var l=i._soundById(t);if(l){if(!(typeof e=="number"&&e>=0)){if(i._webAudio){var m=i.playing(t)?o.ctx.currentTime-l._playStart:0,g=l._rateSeek?l._rateSeek-l._seek:0;return l._seek+(g+m*Math.abs(l._rate))}return l._node.currentTime}var E=i.playing(t);E&&i.pause(t,!0),l._seek=e,l._ended=!1,i._clearTimer(t),i._webAudio||!l._node||isNaN(l._node.duration)||(l._node.currentTime=e);var S=function(){i._emit("seek",t),E&&i.play(t,!0)};if(E&&!i._webAudio){var T=function(){i._playLock?setTimeout(T,0):S()};setTimeout(T,0)}else S()}return i},playing:function(e){var t=this;if(typeof e=="number"){var i=t._soundById(e);return!!i&&!i._paused}for(var a=0;a<t._sounds.length;a++)if(!t._sounds[a]._paused)return!0;return!1},duration:function(e){var t=this,i=t._duration,a=t._soundById(e);return a&&(i=t._sprite[a._sprite][1]/1e3),i},state:function(){return this._state},unload:function(){for(var e=this,t=e._sounds,i=0;i<t.length;i++)t[i]._paused||e.stop(t[i]._id),e._webAudio||(e._clearSound(t[i]._node),t[i]._node.removeEventListener("error",t[i]._errorFn,!1),t[i]._node.removeEventListener(o._canPlayEvent,t[i]._loadFn,!1),t[i]._node.removeEventListener("ended",t[i]._endFn,!1),o._releaseHtml5Audio(t[i]._node)),delete t[i]._node,e._clearTimer(t[i]._id);var a=o._howls.indexOf(e);a>=0&&o._howls.splice(a,1);var d=!0;for(i=0;i<o._howls.length;i++)if(o._howls[i]._src===e._src||e._src.indexOf(o._howls[i]._src)>=0){d=!1;break}return c&&d&&delete c[e._src],o.noAudio=!1,e._state="unloaded",e._sounds=[],e=null,null},on:function(e,t,i,a){var d=this,p=d["_on"+e];return typeof t=="function"&&p.push(a?{id:i,fn:t,once:a}:{id:i,fn:t}),d},off:function(e,t,i){var a=this,d=a["_on"+e],p=0;if(typeof t=="number"&&(i=t,t=null),t||i)for(p=0;p<d.length;p++){var l=i===d[p].id;if(t===d[p].fn&&l||!t&&l){d.splice(p,1);break}}else if(e)a["_on"+e]=[];else{var m=Object.keys(a);for(p=0;p<m.length;p++)m[p].indexOf("_on")===0&&Array.isArray(a[m[p]])&&(a[m[p]]=[])}return a},once:function(e,t,i){var a=this;return a.on(e,t,i,1),a},_emit:function(e,t,i){for(var a=this,d=a["_on"+e],p=d.length-1;p>=0;p--)d[p].id&&d[p].id!==t&&e!=="load"||(setTimeout((function(l){l.call(this,t,i)}).bind(a,d[p].fn),0),d[p].once&&a.off(e,d[p].fn,d[p].id));return a._loadQueue(e),a},_loadQueue:function(e){var t=this;if(t._queue.length>0){var i=t._queue[0];i.event===e&&(t._queue.shift(),t._loadQueue()),e||i.action()}return t},_ended:function(e){var t=this,i=e._sprite;if(!t._webAudio&&e._node&&!e._node.paused&&!e._node.ended&&e._node.currentTime<e._stop)return setTimeout(t._ended.bind(t,e),100),t;var a=!(!e._loop&&!t._sprite[i][2]);if(t._emit("end",e._id),!t._webAudio&&a&&t.stop(e._id,!0).play(e._id),t._webAudio&&a){t._emit("play",e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=o.ctx.currentTime;var d=1e3*(e._stop-e._start)/Math.abs(e._rate);t._endTimers[e._id]=setTimeout(t._ended.bind(t,e),d)}return t._webAudio&&!a&&(e._paused=!0,e._ended=!0,e._seek=e._start||0,e._rateSeek=0,t._clearTimer(e._id),t._cleanBuffer(e._node),o._autoSuspend()),t._webAudio||a||t.stop(e._id,!0),t},_clearTimer:function(e){var t=this;if(t._endTimers[e]){if(typeof t._endTimers[e]!="function")clearTimeout(t._endTimers[e]);else{var i=t._soundById(e);i&&i._node&&i._node.removeEventListener("ended",t._endTimers[e],!1)}delete t._endTimers[e]}return t},_soundById:function(e){for(var t=this,i=0;i<t._sounds.length;i++)if(e===t._sounds[i]._id)return t._sounds[i];return null},_inactiveSound:function(){var e=this;e._drain();for(var t=0;t<e._sounds.length;t++)if(e._sounds[t]._ended)return e._sounds[t].reset();return new _(e)},_drain:function(){var e=this,t=e._pool,i=0,a=0;if(!(e._sounds.length<t)){for(a=0;a<e._sounds.length;a++)e._sounds[a]._ended&&i++;for(a=e._sounds.length-1;a>=0;a--){if(i<=t)return;e._sounds[a]._ended&&(e._webAudio&&e._sounds[a]._node&&e._sounds[a]._node.disconnect(0),e._sounds.splice(a,1),i--)}}},_getSoundIds:function(e){var t=this;if(e===void 0){for(var i=[],a=0;a<t._sounds.length;a++)i.push(t._sounds[a]._id);return i}return[e]},_refreshBuffer:function(e){var t=this;return e._node.bufferSource=o.ctx.createBufferSource(),e._node.bufferSource.buffer=c[t._src],e._panner?e._node.bufferSource.connect(e._panner):e._node.bufferSource.connect(e._node),e._node.bufferSource.loop=e._loop,e._loop&&(e._node.bufferSource.loopStart=e._start||0,e._node.bufferSource.loopEnd=e._stop||0),e._node.bufferSource.playbackRate.setValueAtTime(e._rate,o.ctx.currentTime),t},_cleanBuffer:function(e){var t=this,i=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(o._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),i))try{e.bufferSource.buffer=o._scratchBuffer}catch{}return e.bufferSource=null,t},_clearSound:function(e){/MSIE |Trident\//.test(o._navigator&&o._navigator.userAgent)||(e.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var _=function(e){this._parent=e,this.init()};_.prototype={init:function(){var e=this,t=e._parent;return e._muted=t._muted,e._loop=t._loop,e._volume=t._volume,e._rate=t._rate,e._seek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++o._counter,t._sounds.push(e),e.create(),e},create:function(){var e=this,t=e._parent,i=o._muted||e._muted||e._parent._muted?0:e._volume;return t._webAudio?(e._node=o.ctx.createGain===void 0?o.ctx.createGainNode():o.ctx.createGain(),e._node.gain.setValueAtTime(i,o.ctx.currentTime),e._node.paused=!0,e._node.connect(o.masterGain)):o.noAudio||(e._node=o._obtainHtml5Audio(),e._errorFn=e._errorListener.bind(e),e._node.addEventListener("error",e._errorFn,!1),e._loadFn=e._loadListener.bind(e),e._node.addEventListener(o._canPlayEvent,e._loadFn,!1),e._endFn=e._endListener.bind(e),e._node.addEventListener("ended",e._endFn,!1),e._node.src=t._src,e._node.preload=t._preload===!0?"auto":t._preload,e._node.volume=i*o.volume(),e._node.load()),e},reset:function(){var e=this,t=e._parent;return e._muted=t._muted,e._loop=t._loop,e._volume=t._volume,e._rate=t._rate,e._seek=0,e._rateSeek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++o._counter,e},_errorListener:function(){var e=this;e._parent._emit("loaderror",e._id,e._node.error?e._node.error.code:0),e._node.removeEventListener("error",e._errorFn,!1)},_loadListener:function(){var e=this,t=e._parent;t._duration=Math.ceil(10*e._node.duration)/10,Object.keys(t._sprite).length===0&&(t._sprite={__default:[0,1e3*t._duration]}),t._state!=="loaded"&&(t._state="loaded",t._emit("load"),t._loadQueue()),e._node.removeEventListener(o._canPlayEvent,e._loadFn,!1)},_endListener:function(){var e=this,t=e._parent;t._duration===1/0&&(t._duration=Math.ceil(10*e._node.duration)/10,t._sprite.__default[1]===1/0&&(t._sprite.__default[1]=1e3*t._duration),t._ended(e)),e._node.removeEventListener("ended",e._endFn,!1)}};var c={},v=function(e){var t=e._src;if(c[t])return e._duration=c[t].duration,void C(e);if(/^data:[^;]+;base64,/.test(t)){for(var i=atob(t.split(",")[1]),a=new Uint8Array(i.length),d=0;d<i.length;++d)a[d]=i.charCodeAt(d);y(a.buffer,e)}else{var p=new XMLHttpRequest;p.open(e._xhr.method,t,!0),p.withCredentials=e._xhr.withCredentials,p.responseType="arraybuffer",e._xhr.headers&&Object.keys(e._xhr.headers).forEach(function(l){p.setRequestHeader(l,e._xhr.headers[l])}),p.onload=function(){var l=(p.status+"")[0];if(l!=="0"&&l!=="2"&&l!=="3")return void e._emit("loaderror",null,"Failed loading audio file with status: "+p.status+".");y(p.response,e)},p.onerror=function(){e._webAudio&&(e._html5=!0,e._webAudio=!1,e._sounds=[],delete c[t],e.load())},f(p)}},f=function(e){try{e.send()}catch{e.onerror()}},y=function(e,t){var i=function(){t._emit("loaderror",null,"Decoding audio data failed.")},a=function(d){d&&t._sounds.length>0?(c[t._src]=d,C(t,d)):i()};typeof Promise<"u"&&o.ctx.decodeAudioData.length===1?o.ctx.decodeAudioData(e).then(a).catch(i):o.ctx.decodeAudioData(e,a,i)},C=function(e,t){t&&!e._duration&&(e._duration=t.duration),Object.keys(e._sprite).length===0&&(e._sprite={__default:[0,1e3*e._duration]}),e._state!=="loaded"&&(e._state="loaded",e._emit("load"),e._loadQueue())},h=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 e=/iP(hone|od|ad)/.test(o._navigator&&o._navigator.platform),t=o._navigator&&o._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),i=t?parseInt(t[1],10):null;if(e&&i&&i<9){var a=/safari/.test(o._navigator&&o._navigator.userAgent.toLowerCase());o._navigator&&!a&&(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()}};u.Howler=o,u.Howl=r,typeof n<"u"?(n.HowlerGlobal=s,n.Howler=o,n.Howl=r,n.Sound=_):typeof window<"u"&&(window.HowlerGlobal=s,window.Howler=o,window.Howl=r,window.Sound=_)})()}(D)),D}var te=ke();const Le=typeof navigator.standalone<"u";class Oe{constructor(n){this.cogsConnection=n,this.eventTarget=new EventTarget,this.globalVolume=1,this.audioClipPlayers={},this.sinkId="",this.addEventListener("audioClipState",({detail:o})=>{n.sendMediaClipState(o)}),n.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=n.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 s=()=>{const o=Object.entries(this.audioClipPlayers).map(([r,_])=>{const c=Object.values(_.activeClips),v=c.some(({state:f})=>f.type==="playing"||f.type==="pausing"||f.type==="stopping"||f.type==="play_requested"||f.type==="pause_requested"||f.type==="stop_requested")?"playing":c.some(({state:f})=>f.type==="paused")?"paused":"stopped";return[r,v]});n.sendInitialMediaClipStates({mediaType:"audio",files:o})};n.addEventListener("open",s),s()}setGlobalVolume(n){this.globalVolume=n,te.Howler.volume(n),this.notifyStateListeners()}playAudioClip(n,{playId:s,volume:o,fade:r,loop:_}){n in this.audioClipPlayers||(this.audioClipPlayers[n]=this.createClip(n,{preload:!1,ephemeral:!0})),this.updateAudioClipPlayer(n,c=>{const v=Object.entries(c.activeClips).filter(([,{state:h}])=>h.type==="paused").map(([h])=>parseInt(h)),f=Object.entries(c.activeClips).filter(([,{state:h}])=>h.type==="pausing").map(([h])=>parseInt(h));v.forEach(h=>{c.player.play(h)});const y=Object.entries(c.activeClips).filter(([,{state:h}])=>h.type==="pause_requested").map(([h])=>parseInt(h)),C=v.length>0||f.length>0||y.length>0?[]:[c.player.play()];return f.forEach(h=>{c.player.off("fade",void 0,h),c.player.loop(_,h),this.updateActiveAudioClip(n,h,e=>({...e,state:{type:"playing"}})),x(r)?P(c.player,o,r*1e3,h):U(c.player,o,h)}),[...v,...y,...C].forEach(h=>{c.player.loop(_,h),c.player.off("play",void 0,h),c.player.off("pause",void 0,h),c.player.off("fade",void 0,h),c.player.off("end",void 0,h),c.player.off("stop",void 0,h),c.player.once("play",()=>{M(c.player,this.sinkId)}),c.player.once("stop",()=>this.handleStoppedClip(n,s,h),h),c.player.on("end",()=>{c.activeClips[h]?.loop||this.handleStoppedClip(n,s,h)},h);const e={playId:s,state:{type:"play_requested"},loop:_,volume:o};c.player.once("play",()=>{const t=c.activeClips[h]?.state;t?.type==="pause_requested"?this.pauseAudioClip(n,{fade:t.fade},h,!0):t?.type==="stop_requested"?this.stopAudioClip(n,{fade:t.fade},h,!0):this.updateActiveAudioClip(n,h,i=>({...i,state:{type:"playing"}}))},h),x(r)?(c.player.volume(0,h),c.player.mute(!1,h),c.player.once("play",()=>{P(c.player,o,r*1e3,h)},h)):U(c.player,o,h),c.activeClips={...c.activeClips,[h]:e}}),c}),this.notifyClipStateListeners(s,n,"playing")}pauseAudioClip(n,{fade:s},o,r){Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,_=>(_.activeClips=Object.fromEntries(Object.entries(_.activeClips).map(([c,v])=>{const f=parseInt(c);return(o===void 0||o===f)&&(r&&v.state.type==="pause_requested"||v.state.type==="playing"||v.state.type==="pausing"?x(s)?(_.player.once("fade",y=>{_.player.pause(y),this.updateActiveAudioClip(n,y,C=>({...C,state:{type:"paused"}})),this.notifyClipStateListeners(v.playId,n,"paused")},f),P(_.player,0,s*1e3,f),v.state={type:"pausing"}):(_.player.pause(f),v.state={type:"paused"},this.notifyClipStateListeners(v.playId,n,"paused")):(v.state.type==="play_requested"||v.state.type==="pause_requested")&&(v.state={type:"pause_requested",fade:s})),[c,v]})),_))}stopAudioClip(n,{fade:s},o,r){xe("Stop audio clip",{activeClips:this.audioClipPlayers[n]?.activeClips}),Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,_=>(_.activeClips=Object.fromEntries(Object.entries(_.activeClips).map(([c,v])=>{const f=parseInt(c);return(o===void 0||o===f)&&(r&&v.state.type==="stop_requested"||v.state.type==="playing"||v.state.type==="pausing"||v.state.type==="paused"||v.state.type==="stopping"?x(s)&&v.state.type!=="paused"?(_.player.off("fade",f),P(_.player,0,s*1e3,f),_.player.once("fade",y=>{_.player.loop(!1,y),_.player.stop(y)},f),v.state={type:"stopping"}):(_.player.loop(!1,f),_.player.stop(f)):(v.state.type==="play_requested"||v.state.type==="pause_requested"||v.state.type==="stop_requested")&&(v.state={type:"stop_requested",fade:s})),[c,v]})),_))}stopAllAudioClips(n){Object.keys(this.audioClipPlayers).forEach(s=>{this.stopAudioClip(s,n)})}setAudioClipVolume(n,{volume:s,fade:o}){if(!(s>=0&&s<=1)){console.warn("Invalid volume",s);return}Object.keys(this.audioClipPlayers[n]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(n,r=>(r.activeClips=Object.fromEntries(Object.entries(r.activeClips).map(([_,c])=>{if(c.state.type!=="pausing"&&c.state.type!=="stopping"){const v=parseInt(_);return x(o)?P(r.player,s,o*1e3,v):U(r.player,s,v),[_,{...c,volume:s}]}else return[_,c]})),r))}handleStoppedClip(n,s,o){this.updateAudioClipPlayer(n,r=>(delete r.activeClips[o],r)),this.notifyClipStateListeners(s,n,"stopped")}updateActiveAudioClip(n,s,o){this.updateAudioClipPlayer(n,r=>s in r.activeClips?{...r,activeClips:{...r.activeClips,[s]:o(r.activeClips[s])}}:r)}updateAudioClipPlayer(n,s){n in this.audioClipPlayers&&(this.audioClipPlayers={...this.audioClipPlayers,[n]:s(this.audioClipPlayers[n])});const o=this.audioClipPlayers[n];o&&Object.keys(o.activeClips??{}).length===0&&o.config.ephemeral&&(o.player.unload(),delete this.audioClipPlayers[n]),this.notifyStateListeners()}setAudioSink(n){for(const s of Object.values(this.audioClipPlayers))M(s.player,n);this.sinkId=n}updateConfig(n){const s=Object.fromEntries(Object.entries(n).filter(r=>{const _=r[1].type;return _==="audio"||!_})),o=this.audioClipPlayers;this.audioClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(f=>!(f in s)&&!o[f].config.ephemeral).forEach(f=>{o[f].player.unload(),delete r[f]}),Object.entries(s).filter(([f])=>!o[f]).forEach(([f,y])=>{r[f]=this.createClip(f,{...y,ephemeral:!1})}),Object.keys(o).filter(f=>f in s).forEach(f=>{r[f]=this.updatedClip(f,r[f],{...s[f],ephemeral:!1})}),r})(),this.notifyStateListeners()}notifyStateListeners(){const n=Object.entries(this.audioClipPlayers).reduce((r,[_,c])=>(r[_]={config:{preload:c.config.preload,ephemeral:c.config.ephemeral},activeClips:c.activeClips},r),{}),s=Object.values(this.audioClipPlayers).some(({activeClips:r})=>Object.values(r).some(_=>_.state.type==="playing"||_.state.type==="pausing"||_.state.type==="stopping")),o={globalVolume:this.globalVolume,isPlaying:s,clips:n};this.dispatchEvent("state",o)}notifyClipStateListeners(n,s,o){this.dispatchEvent("audioClipState",{mediaType:"audio",playId:n,file:s,status:o})}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n,s){this.eventTarget.dispatchEvent(new CustomEvent(n,{detail:s}))}createPlayer(n,s){const o=new te.Howl({src:this.cogsConnection.getAssetUrl(n),autoplay:!1,loop:!1,volume:1,html5:!0,preload:s.preload});return M(o,this.sinkId),o}createClip(n,s){return{config:s,player:this.createPlayer(n,s),activeClips:{}}}updatedClip(n,s,o){const r={...s,config:o};return s.config.preload!==o.preload&&(r.player.unload(),r.player=this.createPlayer(n,o)),r}}function xe(...u){}function x(u){return!Le&&typeof u=="number"&&!isNaN(u)&&u>0}function M(u,n){n!==void 0&&(u._html5?u._sounds?.forEach(s=>{s._node?.setSinkId?.(n)}):console.warn("Cannot set sink ID: web audio not supported",u))}function U(u,n,s){u.volume(n,s),u.mute(n===0,s)}function P(u,n,s,o){u.fade(u.volume(o),n,s,o)}var B=(u=>(u.Paused="paused",u.Playing="playing",u))(B||{});const ne=document.body;class Pe{constructor(n,s=ne){this.cogsConnection=n,this.eventTarget=new EventTarget,this.globalVolume=1,this.videoClipPlayers={},this.sinkId="",this.parentElement=s,this.addEventListener("videoClipState",({detail:r})=>{n.sendMediaClipState(r)}),n.addEventListener("message",({message:r})=>{switch(r.type){case"media_config_update":if(this.setGlobalVolume(r.globalVolume),r.audioOutput!==void 0){const _=n.getAudioSinkId(r.audioOutput);this.setAudioSink(_??"")}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(([_,c])=>{const v=c.videoElement.paused?c.videoElement.currentTime===0||c.videoElement.currentTime===c.videoElement.duration?"paused":"stopped":"playing";return[_,v]});n.sendInitialMediaClipStates({mediaType:"video",files:r})};n.addEventListener("open",o),o()}setParentElement(n){this.parentElement=n,Object.values(this.videoClipPlayers).forEach(s=>{n.appendChild(s.videoElement)})}resetParentElement(){this.setParentElement(ne)}setGlobalVolume(n){Object.values(this.videoClipPlayers).forEach(s=>{I(s.videoElement,s.volume*n)}),this.globalVolume=n,this.notifyStateListeners()}playVideoClip(n,{playId:s,volume:o,loop:r,fit:_}){this.videoClipPlayers[n]||(this.videoClipPlayers[n]=this.createClipPlayer(n,{preload:"none",ephemeral:!0,fit:_})),this.pendingClip&&this.updateVideoClipPlayer(this.pendingClip.path,c=>(c.videoElement.load(),c)),this.activeClip?.path!==n&&(this.pendingClip={path:n,playId:s,actionOncePlaying:"play"}),this.updateVideoClipPlayer(n,c=>(c.volume=o,I(c.videoElement,o*this.globalVolume),c.videoElement.loop=r,c.videoElement.style.objectFit=_,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:n,path:s}=this.activeClip;this.updateVideoClipPlayer(s,o=>(o.videoElement?.pause(),o)),this.notifyClipStateListeners(n,s,"paused")}}stopVideoClip(){this.pendingClip&&(this.pendingClip.actionOncePlaying="stop"),this.activeClip&&this.handleStoppedClip(this.activeClip.path)}setVideoClipVolume({volume:n}){const s=this.pendingClip??this.activeClip??void 0;if(s){if(!(n>=0&&n<=1)){console.warn("Invalid volume",n);return}this.updateVideoClipPlayer(s.path,o=>(o.videoElement&&(o.volume=n,I(o.videoElement,n*this.globalVolume)),o))}}setVideoClipFit({fit:n}){const s=this.pendingClip??this.activeClip??void 0;s&&this.updateVideoClipPlayer(s.path,o=>(o.videoElement&&(o.videoElement.style.objectFit=n),o))}handleStoppedClip(n){if(!this.activeClip||this.activeClip.path!==n)return;const s=this.activeClip.playId;this.videoClipPlayers[this.activeClip.path]?.config.ephemeral&&this.unloadClip(n),this.activeClip=void 0,this.updateVideoClipPlayer(n,o=>(o.videoElement.pause(),o.videoElement.currentTime=0,o.videoElement.style.display="none",o)),this.notifyClipStateListeners(s,n,"stopped")}updateVideoClipPlayer(n,s){if(this.videoClipPlayers[n]){const o=s(this.videoClipPlayers[n]);o?this.videoClipPlayers[n]=o:delete this.videoClipPlayers[n],this.notifyStateListeners()}}setAudioSink(n){for(const s of Object.values(this.videoClipPlayers))oe(s,n);this.sinkId=n}updateConfig(n){const s=Object.fromEntries(Object.entries(n).filter(([,{type:r}])=>r==="video"||!r)),o=this.videoClipPlayers;this.videoClipPlayers=(()=>{const r={...o};return Object.keys(o).filter(f=>!(f in s)).forEach(f=>{this.activeClip?.path===f&&o[f]?.config.ephemeral===!1?this.updateVideoClipPlayer(f,y=>(y.config={...y.config,ephemeral:!0},y)):(this.unloadClip(f),delete r[f])}),Object.entries(s).filter(([f])=>!o[f]).forEach(([f,y])=>{r[f]=this.createClipPlayer(f,{...y,preload:ie(y.preload),ephemeral:!1,fit:"contain"})}),Object.entries(o).filter(([f])=>f in s).forEach(([f,y])=>{y.config.preload!==s[f].preload&&this.updateVideoClipPlayer(f,C=>(C.config={...C.config,preload:ie(s[f].preload),ephemeral:!1},C.videoElement.preload=C.config.preload,C))}),r})(),this.notifyStateListeners()}notifyStateListeners(){const n={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?B.Paused:B.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",n)}notifyClipStateListeners(n,s,o){this.dispatchEvent("videoClipState",{playId:n,mediaType:"video",file:s,status:o})}addEventListener(n,s,o){this.eventTarget.addEventListener(n,s,o)}removeEventListener(n,s,o){this.eventTarget.removeEventListener(n,s,o)}dispatchEvent(n,s){this.eventTarget.dispatchEvent(new CustomEvent(n,{detail:s}))}createVideoElement(n,s,{volume:o}){const r=document.createElement("video");return r.playsInline=!0,r.src=this.cogsConnection.getAssetUrl(n),r.autoplay=!1,r.loop=!1,I(r,o*this.globalVolume),r.preload=s.preload,r.addEventListener("playing",()=>{if(this.pendingClip?.path===n){switch(this.pendingClip.actionOncePlaying){case"play":{r.style.display="block",this.notifyClipStateListeners(this.pendingClip.playId,n,"playing");break}case"pause":{r.style.display="block",r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,n,"paused");break}case"stop":{r.pause(),this.notifyClipStateListeners(this.pendingClip.playId,n,"stopped");break}}this.activeClip&&this.handleStoppedClip(this.activeClip.path),this.activeClip=this.pendingClip,this.pendingClip=void 0}else this.activeClip?.path===n?this.notifyClipStateListeners(this.activeClip.playId,n,"playing"):r.pause()}),r.addEventListener("ended",()=>{!this.pendingClip&&!r.loop&&this.handleStoppedClip(n)}),r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",r.style.objectFit=s.fit,r.style.display="none",this.parentElement.appendChild(r),r}createClipPlayer(n,s){const r={config:s,videoElement:this.createVideoElement(n,s,{volume:1}),volume:1};return oe(r,this.sinkId),r}unloadClip(n){if(this.activeClip?.path===n){const s=this.activeClip.playId;this.activeClip=void 0,this.notifyClipStateListeners(s,n,"stopped")}this.videoClipPlayers[n]?.videoElement.remove(),this.updateVideoClipPlayer(n,()=>null)}}function ie(u){return typeof u=="string"?u:u?"auto":"none"}function oe(u,n){n!==void 0&&typeof u.videoElement.setSinkId=="function"&&u.videoElement.setSinkId(n)}function I(u,n){u.volume=n,u.muted=n===0}const Ie=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));w.CogsAudioPlayer=Oe,w.CogsConfigChangedEvent=z,w.CogsConnection=Ae,w.CogsConnectionCloseEvent=Q,w.CogsConnectionOpenEvent=H,w.CogsIncomingEvent=X,w.CogsMediaConfigChangedEvent=Z,w.CogsMessageEvent=J,w.CogsShowPhaseChangedEvent=K,w.CogsStateChangedEvent=Y,w.CogsVideoPlayer=Pe,w.DataStoreItemEvent=R,w.DataStoreItemsEvent=N,w.ManifestTypes=Ie,w.assetUrl=W,w.preloadUrl=ve,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
19
|
+
*/var ln=function(){if(typeof WebSocket<"u")return WebSocket},dn=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},pn=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(u){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(u),i._listeners.open.forEach(function(p){return i._callEventListener(u,p)})},this._handleMessage=function(u){i._debug("message event"),i.onmessage&&i.onmessage(u),i._listeners.message.forEach(function(c){return i._callEventListener(u,c)})},this._handleError=function(u){i._debug("error event",u.message),i._disconnect(void 0,u.message==="TIMEOUT"?"timeout":void 0),i.onerror&&i.onerror(u),i._debug("exec error listeners"),i._listeners.error.forEach(function(c){return i._callEventListener(u,c)}),i._connect()},this._handleClose=function(u){i._debug("close event"),i._clearTimeouts(),i._shouldReconnect&&i._connect(),i.onclose&&i.onclose(u),i._listeners.close.forEach(function(c){return i._callEventListener(u,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 u=rn(i),c=u.next();!c.done;c=u.next()){var l=c.value;this._callEventListener(t,l)}}catch(p){n={error:p}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}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,an(["RWS>"],t))},e.prototype._getNextDelay=function(){var t=this._options,n=t.reconnectionDelayGrowFactor,o=n===void 0?F.reconnectionDelayGrowFactor:n,i=t.minReconnectionDelay,u=i===void 0?F.minReconnectionDelay:i,c=t.maxReconnectionDelay,l=c===void 0?F.maxReconnectionDelay:c,p=0;return this._retryCount>0&&(p=u*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,u=n.connectionTimeout,c=u===void 0?F.connectionTimeout:u,l=n.WebSocket,p=l===void 0?ln():l;if(this._retryCount>=i){this._debug("max retries reached",this._retryCount,">=",i);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!dn(p))throw Error("No valid WebSocket class provided");this._wait().then(function(){return t._getNextUrl(t._url)}).then(function(m){t._closeCalled||(t._debug("connect",{url:m,protocols:t._protocols}),t._ws=t._protocols?new p(m,t._protocols):new p(m),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 un(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 cn(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 Ge=12095;function qe(e){const t=typeof window<"u"?window.location:void 0,n=`/assets/${encodeURIComponent(e)}`;return`${t?.protocol}//${t?.hostname}:${Ge}${n}`}async function fn(e){const t=await fetch(e);return URL.createObjectURL(new Blob([await t.arrayBuffer()]))}class hn{#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 ke(n,o))}),this.dispatchEvent(new Ce(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 ke(n,o))}),this.dispatchEvent(new Ce(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 ke extends Event{constructor(t,n){super("item"),this.key=t,this.value=n,this._cogsConnectionEventType="item"}}class Ce extends Event{constructor(t){super("items"),this.items=t,this._cogsConnectionEventType="item"}}const oe=globalThis.Date;function _n(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 mn=0;function vn(){return++mn}const gn=5,yn=1e4;function bn({interval:e,send:t,onChange:n=_n,syncSampleSize:o=gn,syncRequestTimeout:i=yn}){const u={};async function c(){const y=[];for(let s=0;s<o;s++){const a=new Promise(d=>{const f=vn(),v=Date.now(),h=performance.now();t({timesync:{id:f}});const w=(k,C)=>d({sentAt:h,receivedAt:k,serverNow:C,clientNow:v});u[f]={complete:w},setTimeout(()=>d(null),i)});y.push(a),await a}const g=(await Promise.all(y)).filter(s=>s!==null),r=wn(g);isNaN(r)||n(Date.now()+r)}const l=y=>{const g=performance.now(),r=u[y.timesync.id];r&&r.complete(g,y.timesync.now)};c();const p=setInterval(c,e);return{receive:l,destroy:()=>{clearInterval(p)}}}function wn(e){return e.map(({sentAt:t,receivedAt:n,clientNow:o,serverNow:i})=>{const u=(n-t)/2;return i-o-u}).reduce((t,n)=>t+n,0)/e.length}class kn{constructor(t,{hostname:n=document.location.hostname,port:o=Ge}={},i,u){this.manifest=t,this.eventTarget=new EventTarget,this.currentConfig={},this.currentState={},this._showPhase=q.Setup,this._timerState=null,this._mediaConfig=null,this.audioOutputs=void 0,this._selectedAudioOutput="",this.currentState={...i},this.store=new hn(u??{});const{useReconnectingWebsocket:c,path:l,pathParams:p}=Cn(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 m=`ws://${n}:${o}${l}?${this.urlParams}`;this.websocket=c?new pn(m):new WebSocket(m);let y;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new Ke),this.setState(this.currentState),y=bn({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 Je)},this.websocket.addEventListener("message",({data:g})=>{try{const r=JSON.parse(g);try{if(r.config)this.currentConfig=r.config,this.dispatchEvent(new Qe(this.currentConfig));else if(r.updates)this.currentState={...this.currentState,...r.updates},this.dispatchEvent(new Ye(r.updates));else if(r.event&&r.event.key)this.dispatchEvent(new Xe(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 tt(s.phase));break;case"media_config_update":this._mediaConfig=s;for(const a of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])s[a]?this.urlParams.set(a,"true"):this.urlParams.delete(a);this.dispatchEvent(new et(s));break;case"data_store_items":this.store.handleDataStoreItemsMessage(s);break}this.dispatchEvent(new He(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()}}get config(){return{...this.currentConfig}}get state(){return{...this.currentState}}get showPhase(){return this._showPhase}get timerState(){return this._timerState?{...this._timerState}:null}get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(t){return`${qe(t)}?${this.urlParams?.toString()??""}`}get selectedAudioOutput(){return this._selectedAudioOutput}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 Cn(e){const t=new URL(e),n=new URLSearchParams(t.searchParams),o=n.get("local_id"),i=n.get("simulator")==="true",u=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(u){const l=n.get("displayIdIndex")??"";return n.delete("display"),n.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(u)}/${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 Ke extends Event{constructor(){super("open"),this._cogsConnectionEventType="open"}}class Je extends Event{constructor(){super("close"),this._cogsConnectionEventType="close"}}class He extends Event{constructor(t){super("message"),this.message=t,this._cogsConnectionEventType="message"}}class Qe extends Event{constructor(t){super("config"),this.config=t,this._cogsConnectionEventType="config"}}class Ye extends Event{constructor(t){super("state"),this.state=t,this._cogsConnectionEventType="state"}}class Xe extends Event{constructor(t,n){super("event"),this.name=t,this.value=n,this._cogsConnectionEventType="event"}}class et extends Event{constructor(t){super("mediaConfig"),this.mediaConfig=t,this._cogsConnectionEventType="mediaConfig"}}class tt extends Event{constructor(t){super("showPhase"),this.showPhase=t,this._cogsConnectionEventType="showPhase"}}function _(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 m=c.prototype,y=Object.keys(m);for(let g=0;g<y.length;g++){const r=y[g];r in l||(l[r]=m[r].bind(l))}}const i=n?.Parent??Object;class u extends i{}Object.defineProperty(u,"name",{value:e});function c(l){var p;const m=n?.Parent?new u:this;o(m,l),(p=m._zod).deferred??(p.deferred=[]);for(const y of m._zod.deferred)y();return m}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 nt extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const ot={};function R(e){return ot}function En(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 Ee(e,t){return typeof t=="bigint"?t.toString():t}function Se(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Ae(e){return e==null}function Te(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Sn(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 u=n>i?n:i,c=Number.parseInt(e.toFixed(u).replace(".","")),l=Number.parseInt(t.toFixed(u).replace(".",""));return c%l/10**u}const rt=Symbol("evaluating");function E(e,t,n){let o;Object.defineProperty(e,t,{get(){if(o!==rt)return o===void 0&&(o=rt,o=n()),o},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}function V(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function M(...e){const t={};for(const n of e){const o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function it(e){return JSON.stringify(e)}function An(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const st="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ae(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Tn=Se(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function J(e){if(ae(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ae(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function at(e){return J(e)?{...e}:Array.isArray(e)?[...e]:e}const zn=new Set(["string","number","symbol"]);function H(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 $n(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const In={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 Zn(e,t){const n=e._zod.def,o=M(e._zod.def,{get shape(){const i={};for(const u in t){if(!(u in n.shape))throw new Error(`Unrecognized key: "${u}"`);t[u]&&(i[u]=n.shape[u])}return V(this,"shape",i),i},checks:[]});return D(e,o)}function On(e,t){const n=e._zod.def,o=M(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const u in t){if(!(u in n.shape))throw new Error(`Unrecognized key: "${u}"`);t[u]&&delete i[u]}return V(this,"shape",i),i},checks:[]});return D(e,o)}function Pn(e,t){if(!J(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=M(e._zod.def,{get shape(){const u={...e._zod.def.shape,...t};return V(this,"shape",u),u},checks:[]});return D(e,i)}function xn(e,t){if(!J(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 V(this,"shape",o),o},checks:e._zod.def.checks};return D(e,n)}function Ln(e,t){const n=M(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t._zod.def.shape};return V(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return D(e,n)}function jn(e,t,n){const o=M(t._zod.def,{get shape(){const i=t._zod.def.shape,u={...i};if(n)for(const c in n){if(!(c in i))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(u[c]=e?new e({type:"optional",innerType:i[c]}):i[c])}else for(const c in i)u[c]=e?new e({type:"optional",innerType:i[c]}):i[c];return V(this,"shape",u),u},checks:[]});return D(t,o)}function Nn(e,t,n){const o=M(t._zod.def,{get shape(){const i=t._zod.def.shape,u={...i};if(n)for(const c in n){if(!(c in u))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(u[c]=new e({type:"nonoptional",innerType:i[c]}))}else for(const c in i)u[c]=new e({type:"nonoptional",innerType:i[c]});return V(this,"shape",u),u},checks:[]});return D(t,o)}function Q(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 ue(e){return typeof e=="string"?e:e?.message}function U(e,t,n){const o={...e,path:e.path??[]};if(!e.message){const i=ue(e.inst?._zod.def?.error?.(e))??ue(t?.error?.(e))??ue(n.customError?.(e))??ue(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 ut=(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,Ee,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ct=_("$ZodError",ut),lt=_("$ZodError",ut,{Parent:Error});function Rn(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 Dn(e,t=n=>n.message){const n={_errors:[]},o=i=>{for(const u of i.issues)if(u.code==="invalid_union"&&u.errors.length)u.errors.map(c=>o({issues:c}));else if(u.code==="invalid_key")o({issues:u.issues});else if(u.code==="invalid_element")o({issues:u.issues});else if(u.path.length===0)n._errors.push(t(u));else{let c=n,l=0;for(;l<u.path.length;){const p=u.path[l];l===u.path.length-1?(c[p]=c[p]||{_errors:[]},c[p]._errors.push(t(u))):c[p]=c[p]||{_errors:[]},c=c[p],l++}}};return o(e),n}const $e=e=>(t,n,o,i)=>{const u=o?Object.assign(o,{async:!1}):{async:!1},c=t._zod.run({value:n,issues:[]},u);if(c instanceof Promise)throw new K;if(c.issues.length){const l=new(i?.Err??e)(c.issues.map(p=>U(p,u,R())));throw st(l,i?.callee),l}return c.value},Ie=e=>async(t,n,o,i)=>{const u=o?Object.assign(o,{async:!0}):{async:!0};let c=t._zod.run({value:n,issues:[]},u);if(c instanceof Promise&&(c=await c),c.issues.length){const l=new(i?.Err??e)(c.issues.map(p=>U(p,u,R())));throw st(l,i?.callee),l}return c.value},ce=e=>(t,n,o)=>{const i=o?{...o,async:!1}:{async:!1},u=t._zod.run({value:n,issues:[]},i);if(u instanceof Promise)throw new K;return u.issues.length?{success:!1,error:new(e??ct)(u.issues.map(c=>U(c,i,R())))}:{success:!0,data:u.value}},Un=ce(lt),le=e=>async(t,n,o)=>{const i=o?Object.assign(o,{async:!0}):{async:!0};let u=t._zod.run({value:n,issues:[]},i);return u instanceof Promise&&(u=await u),u.issues.length?{success:!1,error:new e(u.issues.map(c=>U(c,i,R())))}:{success:!0,data:u.value}},Fn=le(lt),Vn=e=>(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return $e(e)(t,n,i)},Mn=e=>(t,n,o)=>$e(e)(t,n,o),Bn=e=>async(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Ie(e)(t,n,i)},Wn=e=>async(t,n,o)=>Ie(e)(t,n,o),Gn=e=>(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ce(e)(t,n,i)},qn=e=>(t,n,o)=>ce(e)(t,n,o),Kn=e=>async(t,n,o)=>{const i=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return le(e)(t,n,i)},Jn=e=>async(t,n,o)=>le(e)(t,n,o),Hn=/^[cC][^\s-]{8,}$/,Qn=/^[0-9a-z]+$/,Yn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Xn=/^[0-9a-vA-V]{20}$/,eo=/^[A-Za-z0-9]{27}$/,to=/^[a-zA-Z0-9_-]{21}$/,no=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,oo=/^([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})$/,dt=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)$/,ro=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,io="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function so(){return new RegExp(io,"u")}const ao=/^(?:(?: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])$/,uo=/^(([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}|:))$/,co=/^((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])$/,lo=/^(([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])$/,po=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,pt=/^[A-Za-z0-9_-]*$/,fo=/^\+(?:[0-9]){6,14}[0-9]$/,ft="(?:(?:\\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])))",ho=new RegExp(`^${ft}$`);function ht(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 _o(e){return new RegExp(`^${ht(e)}$`)}function mo(e){const t=ht({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(`^${ft}T(?:${o})$`)}const vo=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},go=/^-?\d+$/,yo=/^-?\d+(?:\.\d+)?/,bo=/^null$/i,wo=/^[^A-Z]*$/,ko=/^[^a-z]*$/,O=_("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),_t={number:"number",bigint:"bigint",object:"date"},mt=_("$ZodCheckLessThan",(e,t)=>{O.init(e,t);const n=_t[typeof t.value];e._zod.onattach.push(o=>{const i=o._zod.bag,u=(t.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<u&&(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})}}),vt=_("$ZodCheckGreaterThan",(e,t)=>{O.init(e,t);const n=_t[typeof t.value];e._zod.onattach.push(o=>{const i=o._zod.bag,u=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>u&&(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})}}),Co=_("$ZodCheckMultipleOf",(e,t)=>{O.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):Sn(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})}}),Eo=_("$ZodCheckNumberFormat",(e,t)=>{O.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),o=n?"int":"number",[i,u]=In[t.format];e._zod.onattach.push(c=>{const l=c._zod.bag;l.format=t.format,l.minimum=i,l.maximum=u,n&&(l.pattern=go)}),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>u&&c.issues.push({origin:"number",input:l,code:"too_big",maximum:u,inst:e})}}),So=_("$ZodCheckMaxLength",(e,t)=>{var n;O.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!Ae(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})}}),Ao=_("$ZodCheckMinLength",(e,t)=>{var n;O.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!Ae(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})}}),To=_("$ZodCheckLengthEquals",(e,t)=>{var n;O.init(e,t),(n=e._zod.def).when??(n.when=o=>{const i=o.value;return!Ae(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,u=i.length;if(u===t.length)return;const c=ze(i),l=u>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})}}),de=_("$ZodCheckStringFormat",(e,t)=>{var n,o;O.init(e,t),e._zod.onattach.push(i=>{const u=i._zod.bag;u.format=t.format,t.pattern&&(u.patterns??(u.patterns=new Set),u.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=()=>{})}),zo=_("$ZodCheckRegex",(e,t)=>{de.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})}}),$o=_("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=wo),de.init(e,t)}),Io=_("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=ko),de.init(e,t)}),Zo=_("$ZodCheckIncludes",(e,t)=>{O.init(e,t);const n=H(t.includes),o=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push(i=>{const u=i._zod.bag;u.patterns??(u.patterns=new Set),u.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})}}),Oo=_("$ZodCheckStartsWith",(e,t)=>{O.init(e,t);const n=new RegExp(`^${H(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})}}),Po=_("$ZodCheckEndsWith",(e,t)=>{O.init(e,t);const n=new RegExp(`.*${H(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})}}),xo=_("$ZodCheckOverwrite",(e,t)=>{O.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Lo{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),i=Math.min(...o.map(c=>c.length-c.trimStart().length)),u=o.map(c=>c.slice(i)).map(c=>" ".repeat(this.indent*2)+c);for(const c of u)this.content.push(c)}compile(){const t=Function,n=this?.args,i=[...(this?.content??[""]).map(u=>` ${u}`)];return new t(...n,i.join(`
|
|
21
|
+
`))}}const jo={major:4,minor:1,patch:13},S=_("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=jo;const o=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&o.unshift(e);for(const i of o)for(const u of i._zod.onattach)u(e);if(o.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const i=(c,l,p)=>{let m=Q(c),y;for(const g of l){if(g._zod.def.when){if(!g._zod.def.when(c))continue}else if(m)continue;const r=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!==r&&(m||(m=Q(c,r)))});else{if(c.issues.length===r)continue;m||(m=Q(c,r))}}return y?y.then(()=>c):c},u=(c,l,p)=>{if(Q(c))return c.aborted=!0,c;const m=i(l,o,p);if(m instanceof Promise){if(p.async===!1)throw new K;return m.then(y=>e._zod.parse(y,p))}return e._zod.parse(m,p)};e._zod.run=(c,l)=>{if(l.skipChecks)return e._zod.parse(c,l);if(l.direction==="backward"){const m=e._zod.parse({value:c.value,issues:[]},{...l,skipChecks:!0});return m instanceof Promise?m.then(y=>u(y,c,l)):u(m,c,l)}const p=e._zod.parse(c,l);if(p instanceof Promise){if(l.async===!1)throw new K;return p.then(m=>i(m,o,l))}return i(p,o,l)}}e["~standard"]={validate:i=>{try{const u=Un(e,i);return u.success?{value:u.data}:{issues:u.error?.issues}}catch{return Fn(e,i).then(c=>c.success?{value:c.data}:{issues:c.error?.issues})}},vendor:"zod",version:1}}),Ze=_("$ZodString",(e,t)=>{S.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??vo(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=_("$ZodStringFormat",(e,t)=>{de.init(e,t),Ze.init(e,t)}),No=_("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=oo),A.init(e,t)}),Ro=_("$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=dt(o))}else t.pattern??(t.pattern=dt());A.init(e,t)}),Do=_("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=ro),A.init(e,t)}),Uo=_("$ZodURL",(e,t)=>{A.init(e,t),e._zod.check=n=>{try{const o=n.value.trim(),i=new URL(o);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.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(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.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=i.href:n.value=o;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Fo=_("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=so()),A.init(e,t)}),Vo=_("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=to),A.init(e,t)}),Mo=_("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Hn),A.init(e,t)}),Bo=_("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Qn),A.init(e,t)}),Wo=_("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Yn),A.init(e,t)}),Go=_("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Xn),A.init(e,t)}),qo=_("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=eo),A.init(e,t)}),Ko=_("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=mo(t)),A.init(e,t)}),Jo=_("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=ho),A.init(e,t)}),Ho=_("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=_o(t)),A.init(e,t)}),Qo=_("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=no),A.init(e,t)}),Yo=_("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ao),A.init(e,t),e._zod.bag.format="ipv4"}),Xo=_("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=uo),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})}}}),er=_("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=co),A.init(e,t)}),tr=_("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=lo),A.init(e,t),e._zod.check=n=>{const o=n.value.split("/");try{if(o.length!==2)throw new Error;const[i,u]=o;if(!u)throw new Error;const c=Number(u);if(`${c}`!==u)throw new Error;if(c<0||c>128)throw new Error;new URL(`http://[${i}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function gt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const nr=_("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=po),A.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{gt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function or(e){if(!pt.test(e))return!1;const t=e.replace(/[-_]/g,o=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return gt(n)}const rr=_("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=pt),A.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{or(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ir=_("$ZodE164",(e,t)=>{t.pattern??(t.pattern=fo),A.init(e,t)});function sr(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[o]=n;if(!o)return!1;const i=JSON.parse(atob(o));return!("typ"in i&&i?.typ!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}}const ar=_("$ZodJWT",(e,t)=>{A.init(e,t),e._zod.check=n=>{sr(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),yt=_("$ZodNumber",(e,t)=>{S.init(e,t),e._zod.pattern=e._zod.bag.pattern??yo,e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const u=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...u?{received:u}:{}}),n}}),ur=_("$ZodNumberFormat",(e,t)=>{Eo.init(e,t),yt.init(e,t)}),cr=_("$ZodNull",(e,t)=>{S.init(e,t),e._zod.pattern=bo,e._zod.values=new Set([null]),e._zod.parse=(n,o)=>{const i=n.value;return i===null||n.issues.push({expected:"null",code:"invalid_type",input:i,inst:e}),n}}),lr=_("$ZodUnknown",(e,t)=>{S.init(e,t),e._zod.parse=n=>n}),dr=_("$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 bt(e,t,n){e.issues.length&&t.issues.push(...B(n,e.issues)),t.value[n]=e.value}const pr=_("$ZodArray",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const u=[];for(let c=0;c<i.length;c++){const l=i[c],p=t.element._zod.run({value:l,issues:[]},o);p instanceof Promise?u.push(p.then(m=>bt(m,n,c))):bt(p,n,c)}return u.length?Promise.all(u).then(()=>n):n}});function pe(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 wt(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=$n(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function kt(e,t,n,o,i,u){const c=[],l=i.keySet,p=i.catchall._zod,m=p.def.type;for(const y in t){if(l.has(y))continue;if(m==="never"){c.push(y);continue}const g=p.run({value:t[y],issues:[]},o);g instanceof Promise?e.push(g.then(r=>pe(r,n,y,t))):pe(g,n,y,t)}return c.length&&n.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:u}),e.length?Promise.all(e).then(()=>n):n}const fr=_("$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=Se(()=>wt(t));E(e._zod,"propValues",()=>{const l=t.shape,p={};for(const m in l){const y=l[m]._zod;if(y.values){p[m]??(p[m]=new Set);for(const g of y.values)p[m].add(g)}}return p});const i=ae,u=t.catchall;let c;e._zod.parse=(l,p)=>{c??(c=o.value);const m=l.value;if(!i(m))return l.issues.push({expected:"object",code:"invalid_type",input:m,inst:e}),l;l.value={};const y=[],g=c.shape;for(const r of c.keys){const a=g[r]._zod.run({value:m[r],issues:[]},p);a instanceof Promise?y.push(a.then(d=>pe(d,l,r,m))):pe(a,l,r,m)}return u?kt(y,m,l,p,o.value,e):y.length?Promise.all(y).then(()=>l):l}}),hr=_("$ZodObjectJIT",(e,t)=>{fr.init(e,t);const n=e._zod.parse,o=Se(()=>wt(t)),i=r=>{const s=new Lo(["shape","payload","ctx"]),a=o.value,d=w=>{const k=it(w);return`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`};s.write("const input = payload.value;");const f=Object.create(null);let v=0;for(const w of a.keys)f[w]=`key_${v++}`;s.write("const newResult = {};");for(const w of a.keys){const k=f[w],C=it(w);s.write(`const ${k} = ${d(w)};`),s.write(`
|
|
22
|
+
if (${k}.issues.length) {
|
|
23
|
+
payload.issues = payload.issues.concat(${k}.issues.map(iss => ({
|
|
24
|
+
...iss,
|
|
25
|
+
path: iss.path ? [${C}, ...iss.path] : [${C}]
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if (${k}.value === undefined) {
|
|
31
|
+
if (${C} in input) {
|
|
32
|
+
newResult[${C}] = undefined;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
newResult[${C}] = ${k}.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
`)}s.write("payload.value = newResult;"),s.write("return payload;");const h=s.compile();return(w,k)=>h(r,w,k)};let u;const c=ae,l=!ot.jitless,m=l&&Tn.value,y=t.catchall;let g;e._zod.parse=(r,s)=>{g??(g=o.value);const a=r.value;return c(a)?l&&m&&s?.async===!1&&s.jitless!==!0?(u||(u=i(t.shape)),r=u(r,s),y?kt([],a,r,s,g,e):r):n(r,s):(r.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),r)}});function Ct(e,t,n,o){for(const u of e)if(u.issues.length===0)return t.value=u.value,t;const i=e.filter(u=>!Q(u));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(u=>u.issues.map(c=>U(c,o,R())))}),t)}const _r=_("$ZodUnion",(e,t)=>{S.init(e,t),E(e._zod,"optin",()=>t.options.some(i=>i._zod.optin==="optional")?"optional":void 0),E(e._zod,"optout",()=>t.options.some(i=>i._zod.optout==="optional")?"optional":void 0),E(e._zod,"values",()=>{if(t.options.every(i=>i._zod.values))return new Set(t.options.flatMap(i=>Array.from(i._zod.values)))}),E(e._zod,"pattern",()=>{if(t.options.every(i=>i._zod.pattern)){const i=t.options.map(u=>u._zod.pattern);return new RegExp(`^(${i.map(u=>Te(u.source)).join("|")})$`)}});const n=t.options.length===1,o=t.options[0]._zod.run;e._zod.parse=(i,u)=>{if(n)return o(i,u);let c=!1;const l=[];for(const p of t.options){const m=p._zod.run({value:i.value,issues:[]},u);if(m instanceof Promise)l.push(m),c=!0;else{if(m.issues.length===0)return m;l.push(m)}}return c?Promise.all(l).then(p=>Ct(p,i,e,u)):Ct(l,i,e,u)}}),mr=_("$ZodIntersection",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const i=n.value,u=t.left._zod.run({value:i,issues:[]},o),c=t.right._zod.run({value:i,issues:[]},o);return u instanceof Promise||c instanceof Promise?Promise.all([u,c]).then(([p,m])=>Et(n,p,m)):Et(n,u,c)}});function Oe(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(J(e)&&J(t)){const n=Object.keys(t),o=Object.keys(e).filter(u=>n.indexOf(u)!==-1),i={...e,...t};for(const u of o){const c=Oe(e[u],t[u]);if(!c.valid)return{valid:!1,mergeErrorPath:[u,...c.mergeErrorPath]};i[u]=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],u=t[o],c=Oe(i,u);if(!c.valid)return{valid:!1,mergeErrorPath:[o,...c.mergeErrorPath]};n.push(c.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Et(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Q(e))return e;const o=Oe(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 vr=_("$ZodTuple",(e,t)=>{S.init(e,t);const n=t.items;e._zod.parse=(o,i)=>{const u=o.value;if(!Array.isArray(u))return o.issues.push({input:u,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=u.length>n.length,g=u.length<p-1;if(y||g)return o.issues.push({...y?{code:"too_big",maximum:n.length}:{code:"too_small",minimum:n.length},input:u,inst:e,origin:"array"}),o}let m=-1;for(const y of n){if(m++,m>=u.length&&m>=p)continue;const g=y._zod.run({value:u[m],issues:[]},i);g instanceof Promise?c.push(g.then(r=>fe(r,o,m))):fe(g,o,m)}if(t.rest){const y=u.slice(n.length);for(const g of y){m++;const r=t.rest._zod.run({value:g,issues:[]},i);r instanceof Promise?c.push(r.then(s=>fe(s,o,m))):fe(r,o,m)}}return c.length?Promise.all(c).then(()=>o):o}});function fe(e,t,n){e.issues.length&&t.issues.push(...B(n,e.issues)),t.value[n]=e.value}const gr=_("$ZodRecord",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const i=n.value;if(!J(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const u=[],c=t.keyType._zod.values;if(c){n.value={};const l=new Set;for(const m of c)if(typeof m=="string"||typeof m=="number"||typeof m=="symbol"){l.add(typeof m=="number"?m.toString():m);const y=t.valueType._zod.run({value:i[m],issues:[]},o);y instanceof Promise?u.push(y.then(g=>{g.issues.length&&n.issues.push(...B(m,g.issues)),n.value[m]=g.value})):(y.issues.length&&n.issues.push(...B(m,y.issues)),n.value[m]=y.value)}let p;for(const m in i)l.has(m)||(p=p??[],p.push(m));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=>U(y,o,R())),input:l,path:[l],inst:e}),n.value[p.value]=p.value;continue}const m=t.valueType._zod.run({value:i[l],issues:[]},o);m instanceof Promise?u.push(m.then(y=>{y.issues.length&&n.issues.push(...B(l,y.issues)),n.value[p.value]=y.value})):(m.issues.length&&n.issues.push(...B(l,m.issues)),n.value[p.value]=m.value)}}return u.length?Promise.all(u).then(()=>n):n}}),yr=_("$ZodEnum",(e,t)=>{S.init(e,t);const n=En(t.entries),o=new Set(n);e._zod.values=o,e._zod.pattern=new RegExp(`^(${n.filter(i=>zn.has(typeof i)).map(i=>typeof i=="string"?H(i):i.toString()).join("|")})$`),e._zod.parse=(i,u)=>{const c=i.value;return o.has(c)||i.issues.push({code:"invalid_value",values:n,input:c,inst:e}),i}}),br=_("$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"?H(o):o?H(o.toString()):String(o)).join("|")})$`),e._zod.parse=(o,i)=>{const u=o.value;return n.has(u)||o.issues.push({code:"invalid_value",values:t.values,input:u,inst:e}),o}}),wr=_("$ZodTransform",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new nt(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 St(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const kr=_("$ZodOptional",(e,t)=>{S.init(e,t),e._zod.optin="optional",e._zod.optout="optional",E(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),E(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Te(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(u=>St(u,n.value)):St(i,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,o)}}),Cr=_("$ZodNullable",(e,t)=>{S.init(e,t),E(e._zod,"optin",()=>t.innerType._zod.optin),E(e._zod,"optout",()=>t.innerType._zod.optout),E(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Te(n.source)}|null)$`):void 0}),E(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)}),Er=_("$ZodDefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",E(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(u=>At(u,t)):At(i,t)}});function At(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Sr=_("$ZodPrefault",(e,t)=>{S.init(e,t),e._zod.optin="optional",E(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))}),Ar=_("$ZodNonOptional",(e,t)=>{S.init(e,t),E(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(u=>Tt(u,e)):Tt(i,e)}});function Tt(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 Tr=_("$ZodCatch",(e,t)=>{S.init(e,t),E(e._zod,"optin",()=>t.innerType._zod.optin),E(e._zod,"optout",()=>t.innerType._zod.optout),E(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(u=>(n.value=u.value,u.issues.length&&(n.value=t.catchValue({...n,error:{issues:u.issues.map(c=>U(c,o,R()))},input:n.value}),n.issues=[]),n)):(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(u=>U(u,o,R()))},input:n.value}),n.issues=[]),n)}}),zr=_("$ZodPipe",(e,t)=>{S.init(e,t),E(e._zod,"values",()=>t.in._zod.values),E(e._zod,"optin",()=>t.in._zod.optin),E(e._zod,"optout",()=>t.out._zod.optout),E(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,o)=>{if(o.direction==="backward"){const u=t.out._zod.run(n,o);return u instanceof Promise?u.then(c=>he(c,t.in,o)):he(u,t.in,o)}const i=t.in._zod.run(n,o);return i instanceof Promise?i.then(u=>he(u,t.out,o)):he(i,t.out,o)}});function he(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const $r=_("$ZodReadonly",(e,t)=>{S.init(e,t),E(e._zod,"propValues",()=>t.innerType._zod.propValues),E(e._zod,"values",()=>t.innerType._zod.values),E(e._zod,"optin",()=>t.innerType?._zod?.optin),E(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 Ir=_("$ZodCustom",(e,t)=>{O.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(u=>$t(u,n,o,e));$t(i,n,o,e)}});function $t(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 It;class Zr{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 Or(){return new Zr}(It=globalThis).__zod_globalRegistry??(It.__zod_globalRegistry=Or());const _e=globalThis.__zod_globalRegistry;function Pr(e,t){return new e({type:"string",...b(t)})}function xr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...b(t)})}function Zt(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...b(t)})}function Lr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...b(t)})}function jr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...b(t)})}function Nr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...b(t)})}function Rr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...b(t)})}function Dr(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...b(t)})}function Ur(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...b(t)})}function Fr(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...b(t)})}function Vr(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...b(t)})}function Mr(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...b(t)})}function Br(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...b(t)})}function Wr(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...b(t)})}function Gr(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 Kr(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...b(t)})}function Jr(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...b(t)})}function Hr(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...b(t)})}function Qr(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...b(t)})}function Yr(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...b(t)})}function Xr(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...b(t)})}function ei(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...b(t)})}function ti(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...b(t)})}function ni(e,t){return new e({type:"string",format:"date",check:"string_format",...b(t)})}function oi(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...b(t)})}function ri(e,t){return new e({type:"string",format:"duration",check:"string_format",...b(t)})}function ii(e,t){return new e({type:"number",checks:[],...b(t)})}function si(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...b(t)})}function ai(e,t){return new e({type:"null",...b(t)})}function ui(e){return new e({type:"unknown"})}function ci(e,t){return new e({type:"never",...b(t)})}function Ot(e,t){return new mt({check:"less_than",...b(t),value:e,inclusive:!1})}function Pe(e,t){return new mt({check:"less_than",...b(t),value:e,inclusive:!0})}function Pt(e,t){return new vt({check:"greater_than",...b(t),value:e,inclusive:!1})}function xe(e,t){return new vt({check:"greater_than",...b(t),value:e,inclusive:!0})}function xt(e,t){return new Co({check:"multiple_of",...b(t),value:e})}function Lt(e,t){return new So({check:"max_length",...b(t),maximum:e})}function me(e,t){return new Ao({check:"min_length",...b(t),minimum:e})}function jt(e,t){return new To({check:"length_equals",...b(t),length:e})}function li(e,t){return new zo({check:"string_format",format:"regex",...b(t),pattern:e})}function di(e){return new $o({check:"string_format",format:"lowercase",...b(e)})}function pi(e){return new Io({check:"string_format",format:"uppercase",...b(e)})}function fi(e,t){return new Zo({check:"string_format",format:"includes",...b(t),includes:e})}function hi(e,t){return new Oo({check:"string_format",format:"starts_with",...b(t),prefix:e})}function _i(e,t){return new Po({check:"string_format",format:"ends_with",...b(t),suffix:e})}function Y(e){return new xo({check:"overwrite",tx:e})}function mi(e){return Y(t=>t.normalize(e))}function vi(){return Y(e=>e.trim())}function gi(){return Y(e=>e.toLowerCase())}function yi(){return Y(e=>e.toUpperCase())}function bi(){return Y(e=>An(e))}function wi(e,t,n){return new e({type:"array",element:t,...b(n)})}function ki(e,t,n){return new e({type:"custom",check:"custom",fn:t,...b(n)})}function Ci(e){const t=Ei(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 Ei(e,t){const n=new O({check:"custom",...b(t)});return n._zod.check=e,n}const Si=_("ZodISODateTime",(e,t)=>{Ko.init(e,t),Z.init(e,t)});function Ai(e){return ti(Si,e)}const Ti=_("ZodISODate",(e,t)=>{Jo.init(e,t),Z.init(e,t)});function zi(e){return ni(Ti,e)}const $i=_("ZodISOTime",(e,t)=>{Ho.init(e,t),Z.init(e,t)});function Ii(e){return oi($i,e)}const Zi=_("ZodISODuration",(e,t)=>{Qo.init(e,t),Z.init(e,t)});function Oi(e){return ri(Zi,e)}const P=_("ZodError",(e,t)=>{ct.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Dn(e,n)},flatten:{value:n=>Rn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Ee,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Ee,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Pi=$e(P),xi=Ie(P),Li=ce(P),ji=le(P),Ni=Vn(P),Ri=Mn(P),Di=Bn(P),Ui=Wn(P),Fi=Gn(P),Vi=qn(P),Mi=Kn(P),Bi=Jn(P),I=_("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(M(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)=>Pi(e,n,o,{callee:e.parse}),e.safeParse=(n,o)=>Li(e,n,o),e.parseAsync=async(n,o)=>xi(e,n,o,{callee:e.parseAsync}),e.safeParseAsync=async(n,o)=>ji(e,n,o),e.spa=e.safeParseAsync,e.encode=(n,o)=>Ni(e,n,o),e.decode=(n,o)=>Ri(e,n,o),e.encodeAsync=async(n,o)=>Di(e,n,o),e.decodeAsync=async(n,o)=>Ui(e,n,o),e.safeEncode=(n,o)=>Fi(e,n,o),e.safeDecode=(n,o)=>Vi(e,n,o),e.safeEncodeAsync=async(n,o)=>Mi(e,n,o),e.safeDecodeAsync=async(n,o)=>Bi(e,n,o),e.refine=(n,o)=>e.check(Us(n,o)),e.superRefine=n=>e.check(Fs(n)),e.overwrite=n=>e.check(Y(n)),e.optional=()=>Mt(e),e.nullable=()=>Bt(e),e.nullish=()=>Mt(Bt(e)),e.nonoptional=n=>Ps(e,n),e.array=()=>ms(e),e.or=n=>W([e,n]),e.and=n=>bs(e,n),e.transform=n=>Gt(e,Ts(n)),e.default=n=>Is(e,n),e.prefault=n=>Os(e,n),e.catch=n=>Ls(e,n),e.pipe=n=>Gt(e,n),e.readonly=()=>Rs(e),e.describe=n=>{const o=e.clone();return _e.add(o,{description:n}),o},Object.defineProperty(e,"description",{get(){return _e.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return _e.get(e);const o=e.clone();return _e.add(o,n[0]),o},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Nt=_("_ZodString",(e,t)=>{Ze.init(e,t),I.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(li(...o)),e.includes=(...o)=>e.check(fi(...o)),e.startsWith=(...o)=>e.check(hi(...o)),e.endsWith=(...o)=>e.check(_i(...o)),e.min=(...o)=>e.check(me(...o)),e.max=(...o)=>e.check(Lt(...o)),e.length=(...o)=>e.check(jt(...o)),e.nonempty=(...o)=>e.check(me(1,...o)),e.lowercase=o=>e.check(di(o)),e.uppercase=o=>e.check(pi(o)),e.trim=()=>e.check(vi()),e.normalize=(...o)=>e.check(mi(...o)),e.toLowerCase=()=>e.check(gi()),e.toUpperCase=()=>e.check(yi()),e.slugify=()=>e.check(bi())}),Wi=_("ZodString",(e,t)=>{Ze.init(e,t),Nt.init(e,t),e.email=n=>e.check(xr(Gi,n)),e.url=n=>e.check(Dr(qi,n)),e.jwt=n=>e.check(ei(us,n)),e.emoji=n=>e.check(Ur(Ki,n)),e.guid=n=>e.check(Zt(Rt,n)),e.uuid=n=>e.check(Lr(ve,n)),e.uuidv4=n=>e.check(jr(ve,n)),e.uuidv6=n=>e.check(Nr(ve,n)),e.uuidv7=n=>e.check(Rr(ve,n)),e.nanoid=n=>e.check(Fr(Ji,n)),e.guid=n=>e.check(Zt(Rt,n)),e.cuid=n=>e.check(Vr(Hi,n)),e.cuid2=n=>e.check(Mr(Qi,n)),e.ulid=n=>e.check(Br(Yi,n)),e.base64=n=>e.check(Qr(is,n)),e.base64url=n=>e.check(Yr(ss,n)),e.xid=n=>e.check(Wr(Xi,n)),e.ksuid=n=>e.check(Gr(es,n)),e.ipv4=n=>e.check(qr(ts,n)),e.ipv6=n=>e.check(Kr(ns,n)),e.cidrv4=n=>e.check(Jr(os,n)),e.cidrv6=n=>e.check(Hr(rs,n)),e.e164=n=>e.check(Xr(as,n)),e.datetime=n=>e.check(Ai(n)),e.date=n=>e.check(zi(n)),e.time=n=>e.check(Ii(n)),e.duration=n=>e.check(Oi(n))});function X(e){return Pr(Wi,e)}const Z=_("ZodStringFormat",(e,t)=>{A.init(e,t),Nt.init(e,t)}),Gi=_("ZodEmail",(e,t)=>{Do.init(e,t),Z.init(e,t)}),Rt=_("ZodGUID",(e,t)=>{No.init(e,t),Z.init(e,t)}),ve=_("ZodUUID",(e,t)=>{Ro.init(e,t),Z.init(e,t)}),qi=_("ZodURL",(e,t)=>{Uo.init(e,t),Z.init(e,t)}),Ki=_("ZodEmoji",(e,t)=>{Fo.init(e,t),Z.init(e,t)}),Ji=_("ZodNanoID",(e,t)=>{Vo.init(e,t),Z.init(e,t)}),Hi=_("ZodCUID",(e,t)=>{Mo.init(e,t),Z.init(e,t)}),Qi=_("ZodCUID2",(e,t)=>{Bo.init(e,t),Z.init(e,t)}),Yi=_("ZodULID",(e,t)=>{Wo.init(e,t),Z.init(e,t)}),Xi=_("ZodXID",(e,t)=>{Go.init(e,t),Z.init(e,t)}),es=_("ZodKSUID",(e,t)=>{qo.init(e,t),Z.init(e,t)}),ts=_("ZodIPv4",(e,t)=>{Yo.init(e,t),Z.init(e,t)}),ns=_("ZodIPv6",(e,t)=>{Xo.init(e,t),Z.init(e,t)}),os=_("ZodCIDRv4",(e,t)=>{er.init(e,t),Z.init(e,t)}),rs=_("ZodCIDRv6",(e,t)=>{tr.init(e,t),Z.init(e,t)}),is=_("ZodBase64",(e,t)=>{nr.init(e,t),Z.init(e,t)}),ss=_("ZodBase64URL",(e,t)=>{rr.init(e,t),Z.init(e,t)}),as=_("ZodE164",(e,t)=>{ir.init(e,t),Z.init(e,t)}),us=_("ZodJWT",(e,t)=>{ar.init(e,t),Z.init(e,t)}),Dt=_("ZodNumber",(e,t)=>{yt.init(e,t),I.init(e,t),e.gt=(o,i)=>e.check(Pt(o,i)),e.gte=(o,i)=>e.check(xe(o,i)),e.min=(o,i)=>e.check(xe(o,i)),e.lt=(o,i)=>e.check(Ot(o,i)),e.lte=(o,i)=>e.check(Pe(o,i)),e.max=(o,i)=>e.check(Pe(o,i)),e.int=o=>e.check(Ut(o)),e.safe=o=>e.check(Ut(o)),e.positive=o=>e.check(Pt(0,o)),e.nonnegative=o=>e.check(xe(0,o)),e.negative=o=>e.check(Ot(0,o)),e.nonpositive=o=>e.check(Pe(0,o)),e.multipleOf=(o,i)=>e.check(xt(o,i)),e.step=(o,i)=>e.check(xt(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 ii(Dt,e)}const cs=_("ZodNumberFormat",(e,t)=>{ur.init(e,t),Dt.init(e,t)});function Ut(e){return si(cs,e)}const ls=_("ZodNull",(e,t)=>{cr.init(e,t),I.init(e,t)});function ds(e){return ai(ls,e)}const ps=_("ZodUnknown",(e,t)=>{lr.init(e,t),I.init(e,t)});function Ft(){return ui(ps)}const fs=_("ZodNever",(e,t)=>{dr.init(e,t),I.init(e,t)});function hs(e){return ci(fs,e)}const _s=_("ZodArray",(e,t)=>{pr.init(e,t),I.init(e,t),e.element=t.element,e.min=(n,o)=>e.check(me(n,o)),e.nonempty=n=>e.check(me(1,n)),e.max=(n,o)=>e.check(Lt(n,o)),e.length=(n,o)=>e.check(jt(n,o)),e.unwrap=()=>e.element});function ms(e,t){return wi(_s,e,t)}const vs=_("ZodObject",(e,t)=>{hr.init(e,t),I.init(e,t),E(e,"shape",()=>t.shape),e.keyof=()=>Es(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ft()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ft()}),e.strict=()=>e.clone({...e._zod.def,catchall:hs()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>Pn(e,n),e.safeExtend=n=>xn(e,n),e.merge=n=>Ln(e,n),e.pick=n=>Zn(e,n),e.omit=n=>On(e,n),e.partial=(...n)=>jn(Vt,e,n[0]),e.required=(...n)=>Nn(Wt,e,n[0])});function T(e,t){const n={type:"object",shape:e??{},...b(t)};return new vs(n)}const gs=_("ZodUnion",(e,t)=>{_r.init(e,t),I.init(e,t),e.options=t.options});function W(e,t){return new gs({type:"union",options:e,...b(t)})}const ys=_("ZodIntersection",(e,t)=>{mr.init(e,t),I.init(e,t)});function bs(e,t){return new ys({type:"intersection",left:e,right:t})}const ws=_("ZodTuple",(e,t)=>{vr.init(e,t),I.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,u=o?t:null;return new ws({type:"tuple",items:e,rest:u,...b(i)})}const ks=_("ZodRecord",(e,t)=>{gr.init(e,t),I.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Cs(e,t,n){return new ks({type:"record",keyType:e,valueType:t,...b(n)})}const Le=_("ZodEnum",(e,t)=>{yr.init(e,t),I.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 u={};for(const c of o)if(n.has(c))u[c]=t.entries[c];else throw new Error(`Key ${c} not found in enum`);return new Le({...t,checks:[],...b(i),entries:u})},e.exclude=(o,i)=>{const u={...t.entries};for(const c of o)if(n.has(c))delete u[c];else throw new Error(`Key ${c} not found in enum`);return new Le({...t,checks:[],...b(i),entries:u})}});function Es(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(o=>[o,o])):e;return new Le({type:"enum",entries:n,...b(t)})}const Ss=_("ZodLiteral",(e,t)=>{br.init(e,t),I.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 N(e,t){return new Ss({type:"literal",values:Array.isArray(e)?e:[e],...b(t)})}const As=_("ZodTransform",(e,t)=>{wr.init(e,t),I.init(e,t),e._zod.parse=(n,o)=>{if(o.direction==="backward")throw new nt(e.constructor.name);n.addIssue=u=>{if(typeof u=="string")n.issues.push(re(u,n.value,t));else{const c=u;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(u=>(n.value=u,n)):(n.value=i,n)}});function Ts(e){return new As({type:"transform",transform:e})}const Vt=_("ZodOptional",(e,t)=>{kr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Mt(e){return new Vt({type:"optional",innerType:e})}const zs=_("ZodNullable",(e,t)=>{Cr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Bt(e){return new zs({type:"nullable",innerType:e})}const $s=_("ZodDefault",(e,t)=>{Er.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Is(e,t){return new $s({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():at(t)}})}const Zs=_("ZodPrefault",(e,t)=>{Sr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Os(e,t){return new Zs({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():at(t)}})}const Wt=_("ZodNonOptional",(e,t)=>{Ar.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ps(e,t){return new Wt({type:"nonoptional",innerType:e,...b(t)})}const xs=_("ZodCatch",(e,t)=>{Tr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Ls(e,t){return new xs({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const js=_("ZodPipe",(e,t)=>{zr.init(e,t),I.init(e,t),e.in=t.in,e.out=t.out});function Gt(e,t){return new js({type:"pipe",in:e,out:t})}const Ns=_("ZodReadonly",(e,t)=>{$r.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Rs(e){return new Ns({type:"readonly",innerType:e})}const Ds=_("ZodCustom",(e,t)=>{Ir.init(e,t),I.init(e,t)});function Us(e,t={}){return ki(Ds,e,t)}function Fs(e){return Ci(e)}const ge=T({t:x().gte(0),rate:x().gte(0)}),ee=T({opacity:x().gte(0).lte(1)}),te=T({volume:x().gte(0).lte(1)}),Vs=T({type:N("image"),file:X(),fit:W([N("contain"),N("cover"),N("none")])}),Ms=T({type:N("audio"),file:X(),audioOutput:X()}),Bs=T({type:N("video"),file:X(),audioOutput:X(),fit:W([N("contain"),N("cover"),N("none")])}),je=L([x(),ds()]),Ws=L([x(),T({set:T({...ee.shape}).partial()}).partial()]),Gs=L([x(),T({set:T({...ee.shape}).partial(),lerp:T({...ee.shape}).partial()}).partial()]),qs=L([x(),T({set:T({...ge.shape,...te.shape}).partial()}).partial()]),Ks=L([x(),T({set:T({...ge.shape,...te.shape}).partial(),lerp:T({...te.shape}).partial()}).partial()]),Js=L([x(),T({set:T({...ge.shape,...te.shape,...ee.shape}).partial()}).partial()]),Hs=L([x(),T({set:T({...ge.shape,...te.shape,...ee.shape}).partial(),lerp:T({...te.shape,...ee.shape}).partial()}).partial()]),Qs=T({...Vs.shape,keyframes:L([Gs],W([Ws,je]))}),Ys=T({...Ms.shape,keyframes:L([Ks],W([qs,je]))}),Xs=T({...Bs.shape,keyframes:L([Hs],W([Js,je]))}),ea=Cs(X(),W([Qs,Ys,Xs])),qt={opacity:1},Ne={t:0,rate:1,volume:1},Kt={t:0,rate:1,volume:1,opacity:1},ta=Object.freeze(Object.defineProperty({__proto__:null,MediaSurfaceStateSchema:ea,defaultAudioOptions:Ne,defaultImageOptions:qt,defaultVideoOptions:Kt},Symbol.toStringTag,{value:"Module"}));var Re={},Jt;function na(){return Jt||(Jt=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 a=0;a<s._howls.length;a++)if(!s._howls[a]._webAudio)for(var d=s._howls[a]._getSoundIds(),f=0;f<d.length;f++){var v=s._howls[a]._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 a=0;a<s._howls.length;a++)if(!s._howls[a]._webAudio)for(var d=s._howls[a]._getSoundIds(),f=0;f<d.length;f++){var v=s._howls[a]._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 a=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||!a&&!s.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!a,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(a){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(),h=0;h<v.length;h++){var w=r._howls[f]._soundById(v[h]);w&&w._node&&!w._node._unlocked&&(w._node._unlocked=!0,w._node.load())}r._autoResume();var k=r.ctx.createBufferSource();k.buffer=r._scratchBuffer,k.connect(r.ctx.destination),k.start===void 0?k.noteOn(0):k.start(0),typeof r.ctx.resume=="function"&&r.ctx.resume(),k.onended=function(){k.disconnect(0),r._audioUnlocked=!0,document.removeEventListener("touchstart",s,!0),document.removeEventListener("touchend",s,!0),document.removeEventListener("click",s,!0);for(var C=0;C<r._howls.length;C++)r._howls[C]._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 a=0;a<r._howls[s]._sounds.length;a++)if(!r._howls[s]._sounds[a]._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 a=0;a<r._src.length;a++){var d,f;if(r._format&&r._format[a])d=r._format[a];else{if(typeof(f=r._src[a])!="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[a];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 u(r),r._webAudio&&l(r),r):void r._emit("loaderror",null,"No codec support for selected audio sources.")},play:function(r,s){var a=this,d=null;if(typeof r=="number")d=r,r=null;else{if(typeof r=="string"&&a._state==="loaded"&&!a._sprite[r])return null;if(r===void 0&&(r="__default",!a._playLock)){for(var f=0,v=0;v<a._sounds.length;v++)a._sounds[v]._paused&&!a._sounds[v]._ended&&(f++,d=a._sounds[v]._id);f===1?r=null:d=null}}var h=d?a._soundById(d):a._inactiveSound();if(!h)return null;if(d&&!r&&(r=h._sprite||"__default"),a._state!=="loaded"){h._sprite=r,h._ended=!1;var w=h._id;return a._queue.push({event:"play",action:function(){a.play(w)}}),w}if(d&&!h._paused)return s||a._loadQueue("play"),h._id;a._webAudio&&o._autoResume();var k=Math.max(0,h._seek>0?h._seek:a._sprite[r][0]/1e3),C=Math.max(0,(a._sprite[r][0]+a._sprite[r][1])/1e3-k),j=1e3*C/Math.abs(h._rate),G=a._sprite[r][0]/1e3,be=(a._sprite[r][0]+a._sprite[r][1])/1e3;h._sprite=r,h._ended=!1;var Me=function(){h._paused=!1,h._seek=k,h._start=G,h._stop=be,h._loop=!(!h._loop&&!a._sprite[r][2])};if(k>=be)return void a._ended(h);var z=h._node;if(a._webAudio){var tn=function(){a._playLock=!1,Me(),a._refreshBuffer(h);var ne=h._muted||a._muted?0:h._volume;z.gain.setValueAtTime(ne,o.ctx.currentTime),h._playStart=o.ctx.currentTime,z.bufferSource.start===void 0?h._loop?z.bufferSource.noteGrainOn(0,k,86400):z.bufferSource.noteGrainOn(0,k,C):h._loop?z.bufferSource.start(0,k,86400):z.bufferSource.start(0,k,C),j!==1/0&&(a._endTimers[h._id]=setTimeout(a._ended.bind(a,h),j)),s||setTimeout(function(){a._emit("play",h._id),a._loadQueue()},0)};o.state==="running"&&o.ctx.state!=="interrupted"?tn():(a._playLock=!0,a.once("resume",tn),a._clearTimer(h._id))}else{var nn=function(){z.currentTime=k,z.muted=h._muted||a._muted||o._muted||z.muted,z.volume=h._volume*o.volume(),z.playbackRate=h._rate;try{var ne=z.play();if(ne&&typeof Promise<"u"&&(ne instanceof Promise||typeof ne.then=="function")?(a._playLock=!0,Me(),ne.then(function(){a._playLock=!1,z._unlocked=!0,s||(a._emit("play",h._id),a._loadQueue())}).catch(function(){a._playLock=!1,a._emit("playerror",h._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."),h._ended=!0,h._paused=!0})):s||(a._playLock=!1,Me(),a._emit("play",h._id),a._loadQueue()),z.playbackRate=h._rate,z.paused)return void a._emit("playerror",h._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"||h._loop?a._endTimers[h._id]=setTimeout(a._ended.bind(a,h),j):(a._endTimers[h._id]=function(){a._ended(h),z.removeEventListener("ended",a._endTimers[h._id],!1)},z.addEventListener("ended",a._endTimers[h._id],!1))}catch(la){a._emit("playerror",h._id,la)}};z.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(z.src=a._src,z.load());var ca=window&&window.ejecta||!z.readyState&&o._navigator.isCocoonJS;if(z.readyState>=3||ca)nn();else{a._playLock=!0;var on=function(){nn(),z.removeEventListener(o._canPlayEvent,on,!1)};z.addEventListener(o._canPlayEvent,on,!1),a._clearTimer(h._id)}}return h._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 a=s._getSoundIds(r),d=0;d<a.length;d++){s._clearTimer(a[d]);var f=s._soundById(a[d]);if(f&&!f._paused&&(f._seek=s.seek(a[d]),f._rateSeek=0,f._paused=!0,s._stopFade(a[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 a=this;if(a._state!=="loaded"||a._playLock)return a._queue.push({event:"stop",action:function(){a.stop(r,s)}}),a;for(var d=a._getSoundIds(r),f=0;f<d.length;f++){a._clearTimer(d[f]);var v=a._soundById(d[f]);v&&(v._seek=v._start||0,v._rateSeek=0,v._paused=!0,v._ended=!0,a._stopFade(d[f]),v._node&&(a._webAudio?v._node.bufferSource&&(v._node.bufferSource.stop===void 0?v._node.bufferSource.noteOff(0):v._node.bufferSource.stop(0),a._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&&a._clearSound(v._node))),s||a._emit("stop",v._id))}return a},mute:function(r,s){var a=this;if(a._state!=="loaded"||a._playLock)return a._queue.push({event:"mute",action:function(){a.mute(r,s)}}),a;if(s===void 0){if(typeof r!="boolean")return a._muted;a._muted=r}for(var d=a._getSoundIds(s),f=0;f<d.length;f++){var v=a._soundById(d[f]);v&&(v._muted=r,v._interval&&a._stopFade(v._id),a._webAudio&&v._node?v._node.gain.setValueAtTime(r?0:v._volume,o.ctx.currentTime):v._node&&(v._node.muted=!!o._muted||r),a._emit("mute",v._id))}return a},volume:function(){var r,s,a=this,d=arguments;if(d.length===0)return a._volume;d.length===1||d.length===2&&d[1]===void 0?a._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?a._soundById(s):a._sounds[0],f?f._volume:0;if(a._state!=="loaded"||a._playLock)return a._queue.push({event:"volume",action:function(){a.volume.apply(a,d)}}),a;s===void 0&&(a._volume=r),s=a._getSoundIds(s);for(var v=0;v<s.length;v++)(f=a._soundById(s[v]))&&(f._volume=r,d[2]||a._stopFade(s[v]),a._webAudio&&f._node&&!f._muted?f._node.gain.setValueAtTime(r,o.ctx.currentTime):f._node&&!f._muted&&(f._node.volume=r*o.volume()),a._emit("volume",f._id));return a},fade:function(r,s,a,d){var f=this;if(f._state!=="loaded"||f._playLock)return f._queue.push({event:"fade",action:function(){f.fade(r,s,a,d)}}),f;r=Math.min(Math.max(0,parseFloat(r)),1),s=Math.min(Math.max(0,parseFloat(s)),1),a=parseFloat(a),f.volume(r,d);for(var v=f._getSoundIds(d),h=0;h<v.length;h++){var w=f._soundById(v[h]);if(w){if(d||f._stopFade(v[h]),f._webAudio&&!w._muted){var k=o.ctx.currentTime,C=k+a/1e3;w._volume=r,w._node.gain.setValueAtTime(r,k),w._node.gain.linearRampToValueAtTime(s,C)}f._startFadeInterval(w,r,s,a,v[h],d===void 0)}}return f},_startFadeInterval:function(r,s,a,d,f,v){var h=this,w=s,k=a-s,C=Math.abs(k/.01),j=Math.max(4,C>0?d/C:d),G=Date.now();r._fadeTo=a,r._interval=setInterval(function(){var be=(Date.now()-G)/d;G=Date.now(),w+=k*be,w=Math.round(100*w)/100,w=k<0?Math.max(a,w):Math.min(a,w),h._webAudio?r._volume=w:h.volume(w,r._id,!0),v&&(h._volume=w),(a<s&&w<=a||a>s&&w>=a)&&(clearInterval(r._interval),r._interval=null,r._fadeTo=null,h.volume(a,r._id),h._emit("fade",r._id))},j)},_stopFade:function(r){var s=this,a=s._soundById(r);return a&&a._interval&&(s._webAudio&&a._node.gain.cancelScheduledValues(o.ctx.currentTime),clearInterval(a._interval),a._interval=null,s.volume(a._fadeTo,r),a._fadeTo=null,s._emit("fade",r)),s},loop:function(){var r,s,a,d=this,f=arguments;if(f.length===0)return d._loop;if(f.length===1){if(typeof f[0]!="boolean")return!!(a=d._soundById(parseInt(f[0],10)))&&a._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),h=0;h<v.length;h++)(a=d._soundById(v[h]))&&(a._loop=r,d._webAudio&&a._node&&a._node.bufferSource&&(a._node.bufferSource.loop=r,r&&(a._node.bufferSource.loopStart=a._start||0,a._node.bufferSource.loopEnd=a._stop)));return d},rate:function(){var r,s,a=this,d=arguments;if(d.length===0)s=a._sounds[0]._id;else if(d.length===1){var f=a._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 h;if(typeof r!="number")return h=a._soundById(s),h?h._rate:a._rate;if(a._state!=="loaded"||a._playLock)return a._queue.push({event:"rate",action:function(){a.rate.apply(a,d)}}),a;s===void 0&&(a._rate=r),s=a._getSoundIds(s);for(var w=0;w<s.length;w++)if(h=a._soundById(s[w])){a.playing(s[w])&&(h._rateSeek=a.seek(s[w]),h._playStart=a._webAudio?o.ctx.currentTime:h._playStart),h._rate=r,a._webAudio&&h._node&&h._node.bufferSource?h._node.bufferSource.playbackRate.setValueAtTime(r,o.ctx.currentTime):h._node&&(h._node.playbackRate=r);var k=a.seek(s[w]),C=(a._sprite[h._sprite][0]+a._sprite[h._sprite][1])/1e3-k,j=1e3*C/Math.abs(h._rate);!a._endTimers[s[w]]&&h._paused||(a._clearTimer(s[w]),a._endTimers[s[w]]=setTimeout(a._ended.bind(a,h),j)),a._emit("rate",h._id)}return a},seek:function(){var r,s,a=this,d=arguments;if(d.length===0)s=a._sounds[0]._id;else if(d.length===1){var f=a._getSoundIds(),v=f.indexOf(d[0]);v>=0?s=parseInt(d[0],10):a._sounds.length&&(s=a._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 a;if(typeof r=="number"&&(a._state!=="loaded"||a._playLock))return a._queue.push({event:"seek",action:function(){a.seek.apply(a,d)}}),a;var h=a._soundById(s);if(h){if(!(typeof r=="number"&&r>=0)){if(a._webAudio){var w=a.playing(s)?o.ctx.currentTime-h._playStart:0,k=h._rateSeek?h._rateSeek-h._seek:0;return h._seek+(k+w*Math.abs(h._rate))}return h._node.currentTime}var C=a.playing(s);C&&a.pause(s,!0),h._seek=r,h._ended=!1,a._clearTimer(s),a._webAudio||!h._node||isNaN(h._node.duration)||(h._node.currentTime=r);var j=function(){a._emit("seek",s),C&&a.play(s,!0)};if(C&&!a._webAudio){var G=function(){a._playLock?setTimeout(G,0):j()};setTimeout(G,0)}else j()}return a},playing:function(r){var s=this;if(typeof r=="number"){var a=s._soundById(r);return!!a&&!a._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,a=s._duration,d=s._soundById(r);return d&&(a=s._sprite[d._sprite][1]/1e3),a},state:function(){return this._state},unload:function(){for(var r=this,s=r._sounds,a=0;a<s.length;a++)s[a]._paused||r.stop(s[a]._id),r._webAudio||(r._clearSound(s[a]._node),s[a]._node.removeEventListener("error",s[a]._errorFn,!1),s[a]._node.removeEventListener(o._canPlayEvent,s[a]._loadFn,!1),s[a]._node.removeEventListener("ended",s[a]._endFn,!1),o._releaseHtml5Audio(s[a]._node)),delete s[a]._node,r._clearTimer(s[a]._id);var d=o._howls.indexOf(r);d>=0&&o._howls.splice(d,1);var f=!0;for(a=0;a<o._howls.length;a++)if(o._howls[a]._src===r._src||r._src.indexOf(o._howls[a]._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,a,d){var f=this,v=f["_on"+r];return typeof s=="function"&&v.push(d?{id:a,fn:s,once:d}:{id:a,fn:s}),f},off:function(r,s,a){var d=this,f=d["_on"+r],v=0;if(typeof s=="number"&&(a=s,s=null),s||a)for(v=0;v<f.length;v++){var h=a===f[v].id;if(s===f[v].fn&&h||!s&&h){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,a){var d=this;return d.on(r,s,a,1),d},_emit:function(r,s,a){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(h){h.call(this,s,a)}).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 a=s._queue[0];a.event===r&&(s._queue.shift(),s._loadQueue()),r||a.action()}return s},_ended:function(r){var s=this,a=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[a][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 a=s._soundById(r);a&&a._node&&a._node.removeEventListener("ended",s._endTimers[r],!1)}delete s._endTimers[r]}return s},_soundById:function(r){for(var s=this,a=0;a<s._sounds.length;a++)if(r===s._sounds[a]._id)return s._sounds[a];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 u(r)},_drain:function(){var r=this,s=r._pool,a=0,d=0;if(!(r._sounds.length<s)){for(d=0;d<r._sounds.length;d++)r._sounds[d]._ended&&a++;for(d=r._sounds.length-1;d>=0;d--){if(a<=s)return;r._sounds[d]._ended&&(r._webAudio&&r._sounds[d]._node&&r._sounds[d]._node.disconnect(0),r._sounds.splice(d,1),a--)}}},_getSoundIds:function(r){var s=this;if(r===void 0){for(var a=[],d=0;d<s._sounds.length;d++)a.push(s._sounds[d]._id);return a}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,a=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(o._scratchBuffer&&r.bufferSource&&(r.bufferSource.onended=null,r.bufferSource.disconnect(0),a))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 u=function(r){this._parent=r,this.init()};u.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,a=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(a,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=a*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 a=atob(s.split(",")[1]),d=new Uint8Array(a.length),f=0;f<a.length;++f)d[f]=a.charCodeAt(f);m(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(h){v.setRequestHeader(h,r._xhr.headers[h])}),v.onload=function(){var h=(v.status+"")[0];if(h!=="0"&&h!=="2"&&h!=="3")return void r._emit("loaderror",null,"Failed loading audio file with status: "+v.status+".");m(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()}},m=function(r,s){var a=function(){s._emit("loaderror",null,"Decoding audio data failed.")},d=function(f){f&&s._sounds.length>0?(c[s._src]=f,y(s,f)):a()};typeof Promise<"u"&&o.ctx.decodeAudioData.length===1?o.ctx.decodeAudioData(r).then(d).catch(a):o.ctx.decodeAudioData(r,d,a)},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+)?/),a=s?parseInt(s[1],10):null;if(r&&a&&a<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=u):typeof window<"u"&&(window.HowlerGlobal=n,window.Howler=o,window.Howl=i,window.Sound=u)})()}(Re)),Re}var Ht=na();const oa=typeof navigator.standalone<"u";class ra{constructor(t){this.cogsConnection=t,this.eventTarget=new EventTarget,this.globalVolume=1,this.audioClipPlayers={},this.sinkId="",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,u])=>{const c=Object.values(u.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()}setGlobalVolume(t){this.globalVolume=t,Ht.Howler.volume(t),this.notifyStateListeners()}playAudioClip(t,{playId:n,volume:o,fade:i,loop:u}){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 m=Object.entries(c.activeClips).filter(([,{state:g}])=>g.type==="pause_requested").map(([g])=>parseInt(g)),y=l.length>0||p.length>0||m.length>0?[]:[c.player.play()];return p.forEach(g=>{c.player.off("fade",void 0,g),c.player.loop(u,g),this.updateActiveAudioClip(t,g,r=>({...r,state:{type:"playing"}})),ie(i)?se(c.player,o,i*1e3,g):Ue(c.player,o,g)}),[...l,...m,...y].forEach(g=>{c.player.loop(u,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",()=>{De(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:u,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,a=>({...a,state:{type:"playing"}}))},g),ie(i)?(c.player.volume(0,g),c.player.mute(!1,g),c.player.once("play",()=>{se(c.player,o,i*1e3,g)},g)):Ue(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,u=>(u.activeClips=Object.fromEntries(Object.entries(u.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"?ie(n)?(u.player.once("fade",m=>{u.player.pause(m),this.updateActiveAudioClip(t,m,y=>({...y,state:{type:"paused"}})),this.notifyClipStateListeners(l.playId,t,"paused")},p),se(u.player,0,n*1e3,p),l.state={type:"pausing"}):(u.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]})),u))}stopAudioClip(t,{fade:n},o,i){ia("Stop audio clip",{activeClips:this.audioClipPlayers[t]?.activeClips}),Object.keys(this.audioClipPlayers[t]?.activeClips??{}).length!==0&&this.updateAudioClipPlayer(t,u=>(u.activeClips=Object.fromEntries(Object.entries(u.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"?ie(n)&&l.state.type!=="paused"?(u.player.off("fade",p),se(u.player,0,n*1e3,p),u.player.once("fade",m=>{u.player.loop(!1,m),u.player.stop(m)},p),l.state={type:"stopping"}):(u.player.loop(!1,p),u.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]})),u))}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(([u,c])=>{if(c.state.type!=="pausing"&&c.state.type!=="stopping"){const l=parseInt(u);return ie(o)?se(i.player,n,o*1e3,l):Ue(i.player,n,l),[u,{...c,volume:n}]}else return[u,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))De(n.player,t);this.sinkId=t}updateConfig(t){const n=Object.fromEntries(Object.entries(t).filter(i=>{const u=i[1].type;return u==="audio"||!u})),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,m])=>{i[p]=this.createClip(p,{...m,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,[u,c])=>(i[u]={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(u=>u.state.type==="playing"||u.state.type==="pausing"||u.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 Ht.Howl({src:this.cogsConnection.getAssetUrl(t),autoplay:!1,loop:!1,volume:1,html5:!0,preload:n.preload});return De(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 ia(...e){}function ie(e){return!oa&&typeof e=="number"&&!isNaN(e)&&e>0}function De(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 Ue(e,t,n){e.volume(t,n),e.mute(t===0,n)}function se(e,t,n,o){e.fade(e.volume(o),t,n,o)}var Fe=(e=>(e.Paused="paused",e.Playing="playing",e))(Fe||{});const Qt=document.body;class sa{constructor(t,n=Qt){this.cogsConnection=t,this.eventTarget=new EventTarget,this.globalVolume=1,this.videoClipPlayers={},this.sinkId="",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 u=t.getAudioSinkId(i.audioOutput);this.setAudioSink(u??"")}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(([u,c])=>{const l=c.videoElement.paused?c.videoElement.currentTime===0||c.videoElement.currentTime===c.videoElement.duration?"paused":"stopped":"playing";return[u,l]});t.sendInitialMediaClipStates({mediaType:"video",files:i})};t.addEventListener("open",o),o()}setParentElement(t){this.parentElement=t,Object.values(this.videoClipPlayers).forEach(n=>{t.appendChild(n.videoElement)})}resetParentElement(){this.setParentElement(Qt)}setGlobalVolume(t){Object.values(this.videoClipPlayers).forEach(n=>{ye(n.videoElement,n.volume*t)}),this.globalVolume=t,this.notifyStateListeners()}playVideoClip(t,{playId:n,volume:o,loop:i,fit:u}){this.videoClipPlayers[t]||(this.videoClipPlayers[t]=this.createClipPlayer(t,{preload:"none",ephemeral:!0,fit:u})),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,ye(c.videoElement,o*this.globalVolume),c.videoElement.loop=i,c.videoElement.style.objectFit=u,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,ye(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))Xt(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,m=>(m.config={...m.config,ephemeral:!0},m)):(this.unloadClip(p),delete i[p])}),Object.entries(n).filter(([p])=>!o[p]).forEach(([p,m])=>{i[p]=this.createClipPlayer(p,{...m,preload:Yt(m.preload),ephemeral:!1,fit:"contain"})}),Object.entries(o).filter(([p])=>p in n).forEach(([p,m])=>{m.config.preload!==n[p].preload&&this.updateVideoClipPlayer(p,y=>(y.config={...y.config,preload:Yt(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?Fe.Paused:Fe.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,ye(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 Xt(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 Yt(e){return typeof e=="string"?e:e?"auto":"none"}function Xt(e,t){t!==void 0&&typeof e.videoElement.setSinkId=="function"&&e.videoElement.setSinkId(t)}function ye(e,t){e.volume=t,e.muted=t===0}function aa(e,t){switch(e.type){case"image":{if(e.keyframes[0][0]>t)return;const o=e.keyframes.filter(u=>u[1]!==null),i=Ve(o,t);return{...qt,...i}}case"audio":{const n=e.keyframes.filter(u=>u[1]!==null),o=en(n,t);if(!o)return;const i=Ve(n,t);return{...Ne,...i,...o}}case"video":{const n=e.keyframes.filter(u=>u[1]!==null),o=en(n,t);if(!o)return;const i=Ve(n,t);return{...Kt,...i,...o}}}}function Ve(e,t){const n={};for(const[i,u]of e)i<=t?(Object.entries(u.lerp??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[i,l]}),Object.entries(u.set??{}).forEach(([c,l])=>{n[c]??={},n[c].before=[i,l]})):Object.entries(u.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:u,after:c}])=>{if(c===void 0&&u){o[i]=u[1];return}if(u&&c&&u[0]===c[0]){o[i]=c[1];return}if(u&&typeof u[1]=="number"&&c&&typeof c[1]=="number"){o[i]=u[1]+(t-u[0])*(c[1]-u[1])/(c[0]-u[0]);return}}),o}function en(e,t){const n=e[0];if(!n||n[0]>t)return;let o=0,{t:i,rate:u}=Ne;for(const[m,y]of e){if(m>t)break;const{set:g}=y;if(!g)continue;const{t:r,rate:s}=g;if(r!==void 0){o=m,i=r,s!==void 0&&(u=s);continue}if(s!==void 0){const d=(m-o)*u;o=m,i+=d,u=s}}const l=(t-o)*u,p=i+l;return{rate:u,t:p}}const ua=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));$.CogsAudioPlayer=ra,$.CogsConfigChangedEvent=Qe,$.CogsConnection=kn,$.CogsConnectionCloseEvent=Je,$.CogsConnectionOpenEvent=Ke,$.CogsIncomingEvent=Xe,$.CogsMediaConfigChangedEvent=et,$.CogsMessageEvent=He,$.CogsShowPhaseChangedEvent=tt,$.CogsStateChangedEvent=Ye,$.CogsVideoPlayer=sa,$.DataStoreItemEvent=ke,$.DataStoreItemsEvent=Ce,$.ManifestTypes=ua,$.MediaSchema=ta,$.assetUrl=qe,$.getStateAtTime=aa,$.preloadUrl=fn,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ export type { default as CogsClientMessage, MediaClientConfig } from './types/Co
|
|
|
4
4
|
export type { default as MediaClipStateMessage } from './types/MediaClipStateMessage';
|
|
5
5
|
export type { default as ShowPhase } from './types/ShowPhase';
|
|
6
6
|
export type { default as MediaObjectFit } from './types/MediaObjectFit';
|
|
7
|
+
export * as MediaSchema from './types/MediaSchema';
|
|
7
8
|
export { default as CogsAudioPlayer } from './AudioPlayer';
|
|
8
9
|
export { default as CogsVideoPlayer } from './VideoPlayer';
|
|
9
10
|
export * from './types/AudioState';
|
|
10
11
|
export { assetUrl, preloadUrl } from './utils/urls';
|
|
12
|
+
export { getStateAtTime } from './utils/getStateAtTime';
|
|
11
13
|
export * from './types/CogsPluginManifest';
|
|
12
14
|
export * as ManifestTypes from './types/ManifestTypes';
|
|
13
15
|
export * from './DataStore';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { default as CogsConnection } from './CogsConnection';
|
|
2
2
|
export * from './CogsConnection';
|
|
3
|
+
export * as MediaSchema from './types/MediaSchema';
|
|
3
4
|
export { default as CogsAudioPlayer } from './AudioPlayer';
|
|
4
5
|
export { default as CogsVideoPlayer } from './VideoPlayer';
|
|
5
6
|
export * from './types/AudioState';
|
|
6
7
|
export { assetUrl, preloadUrl } from './utils/urls';
|
|
8
|
+
export { getStateAtTime } from './utils/getStateAtTime';
|
|
7
9
|
export * from './types/CogsPluginManifest';
|
|
8
10
|
export * as ManifestTypes from './types/ManifestTypes';
|
|
9
11
|
export * from './DataStore';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import MediaObjectFit from './MediaObjectFit';
|
|
2
|
+
import { MediaSurfaceState } from './MediaSchema';
|
|
2
3
|
import ShowPhase from './ShowPhase';
|
|
3
4
|
interface ShowResetMessage {
|
|
4
5
|
type: 'show_reset';
|
|
@@ -46,7 +47,17 @@ export interface MediaClientConfig {
|
|
|
46
47
|
preferOptimizedVideo?: boolean;
|
|
47
48
|
preferOptimizedImages?: boolean;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Legacy media client events
|
|
52
|
+
*
|
|
53
|
+
* media_strategy: 'events' was added to this interface in @clockworkdog/cogs-client@2.12.0
|
|
54
|
+
*
|
|
55
|
+
* If the media_strategy property is missing, cogs-client can detect that it is connected to an
|
|
56
|
+
* older version of COGS that does not support state-based media client messages.
|
|
57
|
+
*/
|
|
58
|
+
type MediaEventClientMessage = {
|
|
59
|
+
media_strategy: 'events';
|
|
60
|
+
} & ({
|
|
50
61
|
type: 'audio_play';
|
|
51
62
|
playId: string;
|
|
52
63
|
file: string;
|
|
@@ -95,6 +106,13 @@ type MediaClientMessage = {
|
|
|
95
106
|
type: 'image_set_fit';
|
|
96
107
|
file: string;
|
|
97
108
|
fit: MediaObjectFit;
|
|
109
|
+
});
|
|
110
|
+
type MediaStateClientMessage = {
|
|
111
|
+
media_strategy: 'state';
|
|
112
|
+
} & {
|
|
113
|
+
type: 'media_state';
|
|
114
|
+
state: MediaSurfaceState;
|
|
98
115
|
};
|
|
116
|
+
type MediaClientMessage = MediaEventClientMessage | MediaStateClientMessage;
|
|
99
117
|
export type CogsClientMessage<CustomConfig = {}> = ShowResetMessage | ShowPhaseMessage | AdjustableTimerUpdateMessage | TextHintsUpdateMessage | (MediaClientConfigMessage & CustomConfig) | CogsEnvironmentMessage | MediaClientMessage | DataStoreItemsClientMessage;
|
|
100
118
|
export default CogsClientMessage;
|