@clockworkdog/cogs-client 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(w,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(w=typeof globalThis<"u"?globalThis:w||self,F(w.COGS={}))})(this,function(w){"use strict";var F=(e=>(e.Setup="setup",e.Preshow="pre-show",e.InProgress="in progress",e.Finished="finished",e))(F||{});/*! *****************************************************************************
1
+ (function(k,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(k=typeof globalThis<"u"?globalThis:k||self,F(k.COGS={}))})(this,function(k){"use strict";var F=(e=>(e.Setup="setup",e.Preshow="pre-show",e.InProgress="in progress",e.Finished="finished",e))(F||{});/*! *****************************************************************************
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
@@ -16,9 +16,9 @@
16
16
  * by Pedro Ladaria <pedro.ladaria@gmail.com>
17
17
  * https://github.com/pladaria/reconnecting-websocket
18
18
  * License MIT
19
- */var cn=function(){if(typeof WebSocket<"u")return WebSocket},un=function(e){return typeof e<"u"&&!!e&&e.CLOSING===2},D={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},an=function(){function e(t,n,r){var o=this;r===void 0&&(r={}),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(s){o._debug("open event");var i=o._options.minUptime,c=i===void 0?D.minUptime:i;clearTimeout(o._connectTimeout),o._uptimeTimeout=setTimeout(function(){return o._acceptOpen()},c),o._ws.binaryType=o._binaryType,o._messageQueue.forEach(function(a){return o._ws.send(a)}),o._messageQueue=[],o.onopen&&o.onopen(s),o._listeners.open.forEach(function(a){return o._callEventListener(s,a)})},this._handleMessage=function(s){o._debug("message event"),o.onmessage&&o.onmessage(s),o._listeners.message.forEach(function(i){return o._callEventListener(s,i)})},this._handleError=function(s){o._debug("error event",s.message),o._disconnect(void 0,s.message==="TIMEOUT"?"timeout":void 0),o.onerror&&o.onerror(s),o._debug("exec error listeners"),o._listeners.error.forEach(function(i){return o._callEventListener(s,i)}),o._connect()},this._handleClose=function(s){o._debug("close event"),o._clearTimeouts(),o._shouldReconnect&&o._connect(),o.onclose&&o.onclose(s),o._listeners.close.forEach(function(i){return o._callEventListener(s,i)})},this._url=t,this._protocols=n,this._options=r,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,r){return typeof r=="string"?n+=r.length:r instanceof Blob?n+=r.size:n+=r.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,r=n===void 0?D.maxEnqueuedMessages:n;this._messageQueue.length<r&&(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,r,o=this._listeners[t.type];if(o)try{for(var s=tn(o),i=s.next();!i.done;i=s.next()){var c=i.value;this._callEventListener(t,c)}}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}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(r){return r!==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,rn(["RWS>"],t))},e.prototype._getNextDelay=function(){var t=this._options,n=t.reconnectionDelayGrowFactor,r=n===void 0?D.reconnectionDelayGrowFactor:n,o=t.minReconnectionDelay,s=o===void 0?D.minReconnectionDelay:o,i=t.maxReconnectionDelay,c=i===void 0?D.maxReconnectionDelay:i,a=0;return this._retryCount>0&&(a=s*Math.pow(r,this._retryCount-1),a>c&&(a=c)),this._debug("next delay",a),a},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,r=n.maxRetries,o=r===void 0?D.maxRetries:r,s=n.connectionTimeout,i=s===void 0?D.connectionTimeout:s,c=n.WebSocket,a=c===void 0?cn():c;if(this._retryCount>=o){this._debug("max retries reached",this._retryCount,">=",o);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!un(a))throw Error("No valid WebSocket class provided");this._wait().then(function(){return t._getNextUrl(t._url)}).then(function(l){t._closeCalled||(t._debug("connect",{url:l,protocols:t._protocols}),t._ws=t._protocols?new a(l,t._protocols):new a(l),t._ws.binaryType=t._binaryType,t._connectLock=!1,t._addListeners(),t._connectTimeout=setTimeout(function(){return t._handleTimeout()},i))})}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new on(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 sn(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 xe=12095;function Me(e){const t=typeof window<"u"?window.location:void 0,n=`/assets/${encodeURIComponent(e)}`;return`${t?.protocol}//${t?.hostname}:${xe}${n}`}async function ln(e){const t=await fetch(e);return URL.createObjectURL(new Blob([await t.arrayBuffer()]))}class hn{_items;#e=new EventTarget;constructor(t){this._items={...t}}handleDataStoreItemsMessage(t){this._items={...this._items,...t.items},Object.entries(t.items).forEach(([n,r])=>{this.dispatchEvent(new _e(n,r))}),this.dispatchEvent(new ge(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,r])=>{this.dispatchEvent(new _e(n,r))}),this.dispatchEvent(new ge(t)),this}addEventListener(t,n,r){this.#e.addEventListener(t,n,r)}removeEventListener(t,n,r){this.#e.removeEventListener(t,n,r)}dispatchEvent(t){this.#e.dispatchEvent(t)}}class _e extends Event{constructor(t,n){super("item"),this.key=t,this.value=n}_cogsConnectionEventType="item"}class ge extends Event{constructor(t){super("items"),this.items=t}_cogsConnectionEventType="item"}const q=globalThis.Date;function dn(e){const t=Math.round(e-q.now());function n(...o){return o.length===0?new q(n.now()):new q(...o)}const r=Object.getOwnPropertyDescriptors(q);Object.defineProperties(n,r),n.now=function(){return q.now()+t},globalThis.Date=n}let fn=0;function pn(){return++fn}const mn=5,_n=1e4;function gn({interval:e,send:t,onChange:n=dn,syncSampleSize:r=mn,syncRequestTimeout:o=_n}){const s={};async function i(){const h=[];for(let m=0;m<r;m++){const E=new Promise(P=>{const Q=pn(),De=Date.now(),je=performance.now();t({timesync:{id:Q}});const O=(S,M)=>P({sentAt:je,receivedAt:S,serverNow:M,clientNow:De});s[Q]={complete:O},setTimeout(()=>P(null),o)});h.push(E),await E}const p=(await Promise.all(h)).filter(m=>m!==null),d=vn(p);isNaN(d)||n(Date.now()+d)}const c=h=>{const p=performance.now(),d=s[h.timesync.id];d&&d.complete(p,h.timesync.now)};i();const a=setInterval(i,e);return{receive:c,destroy:()=>{clearInterval(a)}}}function vn(e){return e.map(({sentAt:t,receivedAt:n,clientNow:r,serverNow:o})=>{const s=(n-t)/2;return o-r-s}).reduce((t,n)=>t+n,0)/e.length}class bn{constructor(t,{hostname:n=document.location.hostname,port:r=xe}={},o,s){this.manifest=t,this.currentState={...o},this.store=new hn(s??{});const{useReconnectingWebsocket:i,path:c,pathParams:a}=yn(document.location.href);this.urlParams=new URLSearchParams(a),this.urlParams.set("screenWidth",window.screen.width.toString()),this.urlParams.set("screenHeight",window.screen.height.toString()),this.urlParams.set("screenPixelRatio",window.devicePixelRatio.toString());const l=`ws://${n}:${r}${c}?${this.urlParams}`;this.websocket=i?new an(l):new WebSocket(l);let h;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new Fe),this.setState(this.currentState),h=gn({interval:6e4,send:p=>{this.websocket.send(JSON.stringify(p))}})},this.websocket.addEventListener("message",({data:p})=>{try{const d=JSON.parse(p);if(typeof d=="object"&&d!==null&&"timesync"in d){const m=d;h?.receive(m)}}catch(d){console.error(d)}}),this.websocket.onclose=()=>{h?.destroy(),this.dispatchEvent(new Ke)},this.websocket.addEventListener("message",({data:p})=>{try{const d=JSON.parse(p);try{if(d.config)this.currentConfig=d.config,this.dispatchEvent(new We(this.currentConfig));else if(d.updates)this.currentState={...this.currentState,...d.updates},this.dispatchEvent(new Ge(d.updates));else if(d.event&&d.event.key)this.dispatchEvent(new Be(d.event.key,d.event.value));else if(typeof d.message=="object"){const m=d.message;switch(m.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:m.durationMillis,ticking:m.ticking};break;case"show_phase":this._showPhase=m.phase,this.dispatchEvent(new He(m.phase));break;case"media_config_update":this._mediaConfig=m;for(const E of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])m[E]?this.urlParams.set(E,"true"):this.urlParams.delete(E);this.dispatchEvent(new Je(m));break;case"data_store_items":this.store.handleDataStoreItemsMessage(m);break;case"audio_play":case"audio_pause":case"audio_stop":case"audio_set_clip_volume":case"video_play":case"video_pause":case"video_stop":case"video_set_volume":case"video_set_fit":case"image_show":case"image_hide":case"image_set_fit":{const{type:E}=m;"media_strategy"in m||console.warn(`Legacy ${E} message received, this is no longer supported. Please upgrade to COGS 5.10 or downgrade to cogs-client@2.11`)}}this.dispatchEvent(new Ve(m))}}catch(m){console.warn("Error handling data",p,m)}}catch(d){console.error("Unable to parse incoming data from server",p,d)}}),this.store.addEventListener("items",p=>{this.sendDataStoreItems(p.items)});{const p=async()=>{if(navigator.mediaDevices){const d=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:m})=>m==="audiooutput");this.sendAudioOutputs(d),this.audioOutputs=d}};this.eventTarget.addEventListener("open",p),navigator.mediaDevices?.addEventListener("devicechange",p),p()}}websocket;eventTarget=new EventTarget;currentConfig={};get config(){return{...this.currentConfig}}currentState={};get state(){return{...this.currentState}}_showPhase=F.Setup;get showPhase(){return this._showPhase}_timerState=null;get timerState(){return this._timerState?{...this._timerState}:null}_mediaConfig=null;get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(t){return`${Me(t)}?${this.urlParams?.toString()??""}`}audioOutputs=void 0;_selectedAudioOutput="";get selectedAudioOutput(){return this._selectedAudioOutput}store;urlParams;get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(t,...[n]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:t,value:n}}))}setState(t){this.currentState={...this.currentState,...t},this.isConnected&&this.websocket.send(JSON.stringify({updates:t}))}getAudioSinkId(t){return t?this.audioOutputs?.find(({label:n})=>n===t)?.deviceId:""}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,r){this.eventTarget.addEventListener(t,n,r)}removeEventListener(t,n,r){this.eventTarget.removeEventListener(t,n,r)}dispatchEvent(t){this.eventTarget.dispatchEvent(t)}}function yn(e){const t=new URL(e),n=new URLSearchParams(t.searchParams),r=n.get("local_id"),o=n.get("simulator")==="true",s=n.get("display")??"",i=t.pathname.startsWith("/plugin/")?decodeURIComponent(t.pathname.split("/")[2]):void 0;if(r){const c=n.get("t")??"";return n.delete("local_id"),{path:`/local/${encodeURIComponent(r)}`,pathParams:new URLSearchParams({t:c}),useReconnectingWebsocket:!0}}else if(o){const c=n.get("name")??"";return n.delete("simulator"),n.delete("name"),{path:`/simulator/${encodeURIComponent(c)}`,pathParams:n,useReconnectingWebsocket:!0}}else if(s){const c=n.get("displayIdIndex")??"";return n.delete("display"),n.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(s)}/${encodeURIComponent(c)}`}}else{if(i)return{path:`/plugin/${encodeURIComponent(i)}`,useReconnectingWebsocket:!0};{const c=n.get("serial")??"";return n.delete("serial"),{path:`/client/${encodeURIComponent(c)}`,pathParams:n}}}}class Fe extends Event{_cogsConnectionEventType="open";constructor(){super("open")}}class Ke extends Event{_cogsConnectionEventType="close";constructor(){super("close")}}class Ve extends Event{constructor(t){super("message"),this.message=t}_cogsConnectionEventType="message"}class We extends Event{constructor(t){super("config"),this.config=t}_cogsConnectionEventType="config"}class Ge extends Event{constructor(t){super("state"),this.state=t}_cogsConnectionEventType="state"}class Be extends Event{constructor(t,n){super("event"),this.name=t,this.value=n}_cogsConnectionEventType="event"}class Je extends Event{constructor(t){super("mediaConfig"),this.mediaConfig=t}_cogsConnectionEventType="mediaConfig"}class He extends Event{constructor(t){super("showPhase"),this.showPhase=t}_cogsConnectionEventType="showPhase"}function u(e,t,n){function r(c,a){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:a,constr:i,traits:new Set},enumerable:!1}),c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,a);const l=i.prototype,h=Object.keys(l);for(let p=0;p<h.length;p++){const d=h[p];d in c||(c[d]=l[d].bind(c))}}const o=n?.Parent??Object;class s extends o{}Object.defineProperty(s,"name",{value:e});function i(c){var a;const l=n?.Parent?new s:this;r(l,c),(a=l._zod).deferred??(a.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:c=>n?.Parent&&c instanceof n.Parent?!0:c?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class K extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ye extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const qe={};function A(e){return qe}function wn(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function ve(e,t){return typeof t=="bigint"?t.toString():t}function be(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function ye(e){return e==null}function we(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function kn(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(r)){const a=r.match(/\d?e-(\d?)/);a?.[1]&&(o=Number.parseInt(a[1]))}const s=n>o?n:o,i=Number.parseInt(e.toFixed(s).replace(".","")),c=Number.parseInt(t.toFixed(s).replace(".",""));return i%c/10**s}const Xe=Symbol("evaluating");function _(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Xe)return r===void 0&&(r=Xe,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function j(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function L(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function Qe(e){return JSON.stringify(e)}function En(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const et="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ee(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const zn=be(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function V(e){if(ee(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ee(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tt(e){return V(e)?{...e}:Array.isArray(e)?[...e]:e}const $n=new Set(["string","number","symbol"]);function W(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function R(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function f(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 Zn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Sn={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 On(e,t){const n=e._zod.def,r=L(e._zod.def,{get shape(){const o={};for(const s in t){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);t[s]&&(o[s]=n.shape[s])}return j(this,"shape",o),o},checks:[]});return R(e,r)}function Tn(e,t){const n=e._zod.def,r=L(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const s in t){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);t[s]&&delete o[s]}return j(this,"shape",o),o},checks:[]});return R(e,r)}function In(e,t){if(!V(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 o=L(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return j(this,"shape",s),s},checks:[]});return R(e,o)}function Cn(e,t){if(!V(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const r={...e._zod.def.shape,...t};return j(this,"shape",r),r},checks:e._zod.def.checks};return R(e,n)}function Pn(e,t){const n=L(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return j(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return R(e,n)}function An(e,t,n){const r=L(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=e?new e({type:"optional",innerType:o[i]}):o[i])}else for(const i in o)s[i]=e?new e({type:"optional",innerType:o[i]}):o[i];return j(this,"shape",s),s},checks:[]});return R(t,r)}function Rn(e,t,n){const r=L(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:o[i]}))}else for(const i in o)s[i]=new e({type:"nonoptional",innerType:o[i]});return j(this,"shape",s),s},checks:[]});return R(t,r)}function G(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 U(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function te(e){return typeof e=="string"?e:e?.message}function N(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=te(e.inst?._zod.def?.error?.(e))??te(t?.error?.(e))??te(n.customError?.(e))??te(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function ke(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function X(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const nt=(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,ve,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},rt=u("$ZodError",nt),ot=u("$ZodError",nt,{Parent:Error});function Nn(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function Dn(e,t=n=>n.message){const n={_errors:[]},r=o=>{for(const s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>r({issues:i}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let i=n,c=0;for(;c<s.path.length;){const a=s.path[c];c===s.path.length-1?(i[a]=i[a]||{_errors:[]},i[a]._errors.push(t(s))):i[a]=i[a]||{_errors:[]},i=i[a],c++}}};return r(e),n}const Ee=e=>(t,n,r,o)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new K;if(i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>N(a,s,A())));throw et(c,o?.callee),c}return i.value},ze=e=>async(t,n,r,o)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>N(a,s,A())));throw et(c,o?.callee),c}return i.value},ne=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new K;return s.issues.length?{success:!1,error:new(e??rt)(s.issues.map(i=>N(i,o,A())))}:{success:!0,data:s.value}},jn=ne(ot),re=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>N(i,o,A())))}:{success:!0,data:s.value}},Ln=re(ot),Un=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ee(e)(t,n,o)},xn=e=>(t,n,r)=>Ee(e)(t,n,r),Mn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ze(e)(t,n,o)},Fn=e=>async(t,n,r)=>ze(e)(t,n,r),Kn=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ne(e)(t,n,o)},Vn=e=>(t,n,r)=>ne(e)(t,n,r),Wn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return re(e)(t,n,o)},Gn=e=>async(t,n,r)=>re(e)(t,n,r),Bn=/^[cC][^\s-]{8,}$/,Jn=/^[0-9a-z]+$/,Hn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Yn=/^[0-9a-vA-V]{20}$/,qn=/^[A-Za-z0-9]{27}$/,Xn=/^[a-zA-Z0-9_-]{21}$/,Qn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,er=/^([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})$/,st=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)$/,tr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,nr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function rr(){return new RegExp(nr,"u")}const or=/^(?:(?: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])$/,sr=/^(([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}|:))$/,ir=/^((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])$/,cr=/^(([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])$/,ur=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,it=/^[A-Za-z0-9_-]*$/,ar=/^\+(?:[0-9]){6,14}[0-9]$/,ct="(?:(?:\\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])))",lr=new RegExp(`^${ct}$`);function ut(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 hr(e){return new RegExp(`^${ut(e)}$`)}function dr(e){const t=ut({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${ct}T(?:${r})$`)}const fr=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},pr=/^-?\d+$/,mr=/^-?\d+(?:\.\d+)?/,_r=/^(?:true|false)$/i,gr=/^null$/i,vr=/^[^A-Z]*$/,br=/^[^a-z]*$/,z=u("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),at={number:"number",bigint:"bigint",object:"date"},lt=u("$ZodCheckLessThan",(e,t)=>{z.init(e,t);const n=at[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ht=u("$ZodCheckGreaterThan",(e,t)=>{z.init(e,t);const n=at[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),yr=u("$ZodCheckMultipleOf",(e,t)=>{z.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.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):kn(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})}}),wr=u("$ZodCheckNumberFormat",(e,t)=>{z.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=Sn[t.format];e._zod.onattach.push(i=>{const c=i._zod.bag;c.format=t.format,c.minimum=o,c.maximum=s,n&&(c.pattern=pr)}),e._zod.check=i=>{const c=i.value;if(n){if(!Number.isInteger(c)){i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort});return}}c<o&&i.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),c>s&&i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inst:e})}}),kr=u("$ZodCheckMaxLength",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ye(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const i=ke(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Er=u("$ZodCheckMinLength",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ye(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const i=ke(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),zr=u("$ZodCheckLengthEquals",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ye(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,s=o.length;if(s===t.length)return;const i=ke(o),c=s>t.length;r.issues.push({origin:i,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),oe=u("$ZodCheckStringFormat",(e,t)=>{var n,r;z.init(e,t),e._zod.onattach.push(o=>{const s=o._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),$r=u("$ZodCheckRegex",(e,t)=>{oe.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})}}),Zr=u("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=vr),oe.init(e,t)}),Sr=u("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=br),oe.init(e,t)}),Or=u("$ZodCheckIncludes",(e,t)=>{z.init(e,t);const n=W(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const s=o._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Tr=u("$ZodCheckStartsWith",(e,t)=>{z.init(e,t);const n=new RegExp(`^${W(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),Ir=u("$ZodCheckEndsWith",(e,t)=>{z.init(e,t);const n=new RegExp(`.*${W(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),Cr=u("$ZodCheckOverwrite",(e,t)=>{z.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Pr{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 r=t.split(`
19
+ */var cn=function(){if(typeof WebSocket<"u")return WebSocket},un=function(e){return typeof e<"u"&&!!e&&e.CLOSING===2},D={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0},an=function(){function e(t,n,r){var o=this;r===void 0&&(r={}),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(s){o._debug("open event");var i=o._options.minUptime,c=i===void 0?D.minUptime:i;clearTimeout(o._connectTimeout),o._uptimeTimeout=setTimeout(function(){return o._acceptOpen()},c),o._ws.binaryType=o._binaryType,o._messageQueue.forEach(function(a){return o._ws.send(a)}),o._messageQueue=[],o.onopen&&o.onopen(s),o._listeners.open.forEach(function(a){return o._callEventListener(s,a)})},this._handleMessage=function(s){o._debug("message event"),o.onmessage&&o.onmessage(s),o._listeners.message.forEach(function(i){return o._callEventListener(s,i)})},this._handleError=function(s){o._debug("error event",s.message),o._disconnect(void 0,s.message==="TIMEOUT"?"timeout":void 0),o.onerror&&o.onerror(s),o._debug("exec error listeners"),o._listeners.error.forEach(function(i){return o._callEventListener(s,i)}),o._connect()},this._handleClose=function(s){o._debug("close event"),o._clearTimeouts(),o._shouldReconnect&&o._connect(),o.onclose&&o.onclose(s),o._listeners.close.forEach(function(i){return o._callEventListener(s,i)})},this._url=t,this._protocols=n,this._options=r,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,r){return typeof r=="string"?n+=r.length:r instanceof Blob?n+=r.size:n+=r.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,r=n===void 0?D.maxEnqueuedMessages:n;this._messageQueue.length<r&&(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,r,o=this._listeners[t.type];if(o)try{for(var s=tn(o),i=s.next();!i.done;i=s.next()){var c=i.value;this._callEventListener(t,c)}}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}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(r){return r!==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,rn(["RWS>"],t))},e.prototype._getNextDelay=function(){var t=this._options,n=t.reconnectionDelayGrowFactor,r=n===void 0?D.reconnectionDelayGrowFactor:n,o=t.minReconnectionDelay,s=o===void 0?D.minReconnectionDelay:o,i=t.maxReconnectionDelay,c=i===void 0?D.maxReconnectionDelay:i,a=0;return this._retryCount>0&&(a=s*Math.pow(r,this._retryCount-1),a>c&&(a=c)),this._debug("next delay",a),a},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,r=n.maxRetries,o=r===void 0?D.maxRetries:r,s=n.connectionTimeout,i=s===void 0?D.connectionTimeout:s,c=n.WebSocket,a=c===void 0?cn():c;if(this._retryCount>=o){this._debug("max retries reached",this._retryCount,">=",o);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!un(a))throw Error("No valid WebSocket class provided");this._wait().then(function(){return t._getNextUrl(t._url)}).then(function(l){t._closeCalled||(t._debug("connect",{url:l,protocols:t._protocols}),t._ws=t._protocols?new a(l,t._protocols):new a(l),t._ws.binaryType=t._binaryType,t._connectLock=!1,t._addListeners(),t._connectTimeout=setTimeout(function(){return t._handleTimeout()},i))})}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new on(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 sn(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 xe=12095;function Me(e){const t=typeof window<"u"?window.location:void 0,n=`/assets/${encodeURIComponent(e)}`;return`${t?.protocol}//${t?.hostname}:${xe}${n}`}async function ln(e){const t=await fetch(e);return URL.createObjectURL(new Blob([await t.arrayBuffer()]))}class hn{_items;#e=new EventTarget;constructor(t){this._items={...t}}handleDataStoreItemsMessage(t){this._items={...this._items,...t.items},Object.entries(t.items).forEach(([n,r])=>{this.dispatchEvent(new _e(n,r))}),this.dispatchEvent(new ge(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,r])=>{this.dispatchEvent(new _e(n,r))}),this.dispatchEvent(new ge(t)),this}addEventListener(t,n,r){this.#e.addEventListener(t,n,r)}removeEventListener(t,n,r){this.#e.removeEventListener(t,n,r)}dispatchEvent(t){this.#e.dispatchEvent(t)}}class _e extends Event{constructor(t,n){super("item"),this.key=t,this.value=n}_cogsConnectionEventType="item"}class ge extends Event{constructor(t){super("items"),this.items=t}_cogsConnectionEventType="item"}const q=globalThis.Date;function dn(e){const t=Math.round(e-q.now());function n(...o){return o.length===0?new q(n.now()):new q(...o)}const r=Object.getOwnPropertyDescriptors(q);Object.defineProperties(n,r),n.now=function(){return q.now()+t},globalThis.Date=n}let fn=0;function pn(){return++fn}const mn=5,_n=1e4;function gn({interval:e,send:t,onChange:n=dn,syncSampleSize:r=mn,syncRequestTimeout:o=_n}){const s={};async function i(){const h=[];for(let m=0;m<r;m++){const v=new Promise(P=>{const Q=pn(),De=Date.now(),je=performance.now();t({timesync:{id:Q}});const O=(S,M)=>P({sentAt:je,receivedAt:S,serverNow:M,clientNow:De});s[Q]={complete:O},setTimeout(()=>P(null),o)});h.push(v),await v}const f=(await Promise.all(h)).filter(m=>m!==null),d=vn(f);isNaN(d)||n(Date.now()+d)}const c=h=>{const f=performance.now(),d=s[h.timesync.id];d&&d.complete(f,h.timesync.now)};i();const a=setInterval(i,e);return{receive:c,destroy:()=>{clearInterval(a)}}}function vn(e){return e.map(({sentAt:t,receivedAt:n,clientNow:r,serverNow:o})=>{const s=(n-t)/2;return o-r-s}).reduce((t,n)=>t+n,0)/e.length}class bn{constructor(t,{hostname:n=document.location.hostname,port:r=xe}={},o,s){this.manifest=t,this.currentState={...o},this.store=new hn(s??{});const{useReconnectingWebsocket:i,path:c,pathParams:a}=wn(document.location.href);this.urlParams=new URLSearchParams(a),this.urlParams.set("screenWidth",window.screen.width.toString()),this.urlParams.set("screenHeight",window.screen.height.toString()),this.urlParams.set("screenPixelRatio",window.devicePixelRatio.toString());const l=`ws://${n}:${r}${c}?${this.urlParams}`;this.websocket=i?new an(l):new WebSocket(l);let h;this.websocket.onopen=()=>{this.currentConfig={},this.currentState={},this.dispatchEvent(new Fe),this.setState(this.currentState),h=gn({interval:6e4,send:f=>{this.websocket.send(JSON.stringify(f))}})},this.websocket.addEventListener("message",({data:f})=>{try{const d=JSON.parse(f);if(typeof d=="object"&&d!==null&&"timesync"in d){const m=d;h?.receive(m)}}catch(d){console.error(d)}}),this.websocket.onclose=()=>{h?.destroy(),this.dispatchEvent(new Ke)},this.websocket.addEventListener("message",({data:f})=>{try{const d=JSON.parse(f);try{if(d.config)this.currentConfig=d.config,this.dispatchEvent(new We(this.currentConfig));else if(d.updates)this.currentState={...this.currentState,...d.updates},this.dispatchEvent(new Ge(d.updates));else if(d.event&&d.event.key)this.dispatchEvent(new Be(d.event.key,d.event.value));else if(typeof d.message=="object"){const m=d.message;switch(m.type){case"adjustable_timer_update":this._timerState={startedAt:Date.now(),durationMillis:m.durationMillis,ticking:m.ticking};break;case"show_phase":this._showPhase=m.phase,this.dispatchEvent(new He(m.phase));break;case"media_config_update":this._mediaConfig=m;for(const v of["preferOptimizedAudio","preferOptimizedVideo","preferOptimizedImages"])m[v]?this.urlParams.set(v,"true"):this.urlParams.delete(v);this.dispatchEvent(new Je(m));break;case"data_store_items":this.store.handleDataStoreItemsMessage(m);break;case"audio_play":case"audio_pause":case"audio_stop":case"audio_set_clip_volume":case"video_play":case"video_pause":case"video_stop":case"video_set_volume":case"video_set_fit":case"image_show":case"image_hide":case"image_set_fit":{const{type:v}=m;"media_strategy"in m||console.warn(`Legacy ${v} message received, this is no longer supported. Please upgrade to COGS 5.10 or downgrade to cogs-client@2.11`)}}this.dispatchEvent(new Ve(m))}}catch(m){console.warn("Error handling data",f,m)}}catch(d){console.error("Unable to parse incoming data from server",f,d)}}),this.store.addEventListener("items",f=>{this.sendDataStoreItems(f.items)});{const f=async()=>{if(navigator.mediaDevices){const d=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:m})=>m==="audiooutput");this.sendAudioOutputs(d),this.audioOutputs=d}};this.eventTarget.addEventListener("open",f),navigator.mediaDevices?.addEventListener("devicechange",f),f()}}websocket;eventTarget=new EventTarget;currentConfig={};get config(){return{...this.currentConfig}}currentState={};get state(){return{...this.currentState}}_showPhase=F.Setup;get showPhase(){return this._showPhase}_timerState=null;get timerState(){return this._timerState?{...this._timerState}:null}_mediaConfig=null;get mediaConfig(){return this._mediaConfig?{...this._mediaConfig}:null}getAssetUrl(t){return`${Me(t)}?${this.urlParams?.toString()??""}`}audioOutputs=void 0;_selectedAudioOutput="";get selectedAudioOutput(){return this._selectedAudioOutput}store;urlParams;get isConnected(){return this.websocket.readyState===WebSocket.OPEN}close(){this.websocket.close()}sendEvent(t,...[n]){this.isConnected&&this.websocket.send(JSON.stringify({event:{key:t,value:n}}))}setState(t){this.currentState={...this.currentState,...t},this.isConnected&&this.websocket.send(JSON.stringify({updates:t}))}getAudioSinkId(t){return t?this.audioOutputs?.find(({label:n})=>n===t)?.deviceId:""}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,r){this.eventTarget.addEventListener(t,n,r)}removeEventListener(t,n,r){this.eventTarget.removeEventListener(t,n,r)}dispatchEvent(t){this.eventTarget.dispatchEvent(t)}}function wn(e){const t=new URL(e),n=new URLSearchParams(t.searchParams),r=n.get("local_id"),o=n.get("simulator")==="true",s=n.get("display")??"",i=t.pathname.startsWith("/plugin/")?decodeURIComponent(t.pathname.split("/")[2]):void 0;if(r){const c=n.get("t")??"";return n.delete("local_id"),{path:`/local/${encodeURIComponent(r)}`,pathParams:new URLSearchParams({t:c}),useReconnectingWebsocket:!0}}else if(o){const c=n.get("name")??"";return n.delete("simulator"),n.delete("name"),{path:`/simulator/${encodeURIComponent(c)}`,pathParams:n,useReconnectingWebsocket:!0}}else if(s){const c=n.get("displayIdIndex")??"";return n.delete("display"),n.delete("displayIdIndex"),{path:`/display/${encodeURIComponent(s)}/${encodeURIComponent(c)}`}}else{if(i)return{path:`/plugin/${encodeURIComponent(i)}`,useReconnectingWebsocket:!0};{const c=n.get("serial")??"";return n.delete("serial"),{path:`/client/${encodeURIComponent(c)}`,pathParams:n}}}}class Fe extends Event{_cogsConnectionEventType="open";constructor(){super("open")}}class Ke extends Event{_cogsConnectionEventType="close";constructor(){super("close")}}class Ve extends Event{constructor(t){super("message"),this.message=t}_cogsConnectionEventType="message"}class We extends Event{constructor(t){super("config"),this.config=t}_cogsConnectionEventType="config"}class Ge extends Event{constructor(t){super("state"),this.state=t}_cogsConnectionEventType="state"}class Be extends Event{constructor(t,n){super("event"),this.name=t,this.value=n}_cogsConnectionEventType="event"}class Je extends Event{constructor(t){super("mediaConfig"),this.mediaConfig=t}_cogsConnectionEventType="mediaConfig"}class He extends Event{constructor(t){super("showPhase"),this.showPhase=t}_cogsConnectionEventType="showPhase"}function u(e,t,n){function r(c,a){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:a,constr:i,traits:new Set},enumerable:!1}),c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,a);const l=i.prototype,h=Object.keys(l);for(let f=0;f<h.length;f++){const d=h[f];d in c||(c[d]=l[d].bind(c))}}const o=n?.Parent??Object;class s extends o{}Object.defineProperty(s,"name",{value:e});function i(c){var a;const l=n?.Parent?new s:this;r(l,c),(a=l._zod).deferred??(a.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:c=>n?.Parent&&c instanceof n.Parent?!0:c?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class K extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ye extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const qe={};function A(e){return qe}function yn(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function ve(e,t){return typeof t=="bigint"?t.toString():t}function be(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function we(e){return e==null}function ye(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function kn(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(r)){const a=r.match(/\d?e-(\d?)/);a?.[1]&&(o=Number.parseInt(a[1]))}const s=n>o?n:o,i=Number.parseInt(e.toFixed(s).replace(".","")),c=Number.parseInt(t.toFixed(s).replace(".",""));return i%c/10**s}const Xe=Symbol("evaluating");function _(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Xe)return r===void 0&&(r=Xe,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function j(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function L(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function Qe(e){return JSON.stringify(e)}function En(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const et="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ee(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const zn=be(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function V(e){if(ee(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ee(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tt(e){return V(e)?{...e}:Array.isArray(e)?[...e]:e}const $n=new Set(["string","number","symbol"]);function W(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function R(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function p(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 Zn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Sn={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 On(e,t){const n=e._zod.def,r=L(e._zod.def,{get shape(){const o={};for(const s in t){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);t[s]&&(o[s]=n.shape[s])}return j(this,"shape",o),o},checks:[]});return R(e,r)}function Tn(e,t){const n=e._zod.def,r=L(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const s in t){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);t[s]&&delete o[s]}return j(this,"shape",o),o},checks:[]});return R(e,r)}function In(e,t){if(!V(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 o=L(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return j(this,"shape",s),s},checks:[]});return R(e,o)}function Cn(e,t){if(!V(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const r={...e._zod.def.shape,...t};return j(this,"shape",r),r},checks:e._zod.def.checks};return R(e,n)}function Pn(e,t){const n=L(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return j(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return R(e,n)}function An(e,t,n){const r=L(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=e?new e({type:"optional",innerType:o[i]}):o[i])}else for(const i in o)s[i]=e?new e({type:"optional",innerType:o[i]}):o[i];return j(this,"shape",s),s},checks:[]});return R(t,r)}function Rn(e,t,n){const r=L(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:o[i]}))}else for(const i in o)s[i]=new e({type:"nonoptional",innerType:o[i]});return j(this,"shape",s),s},checks:[]});return R(t,r)}function G(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 U(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function te(e){return typeof e=="string"?e:e?.message}function N(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=te(e.inst?._zod.def?.error?.(e))??te(t?.error?.(e))??te(n.customError?.(e))??te(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function ke(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function X(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const nt=(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,ve,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},rt=u("$ZodError",nt),ot=u("$ZodError",nt,{Parent:Error});function Nn(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function Dn(e,t=n=>n.message){const n={_errors:[]},r=o=>{for(const s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>r({issues:i}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let i=n,c=0;for(;c<s.path.length;){const a=s.path[c];c===s.path.length-1?(i[a]=i[a]||{_errors:[]},i[a]._errors.push(t(s))):i[a]=i[a]||{_errors:[]},i=i[a],c++}}};return r(e),n}const Ee=e=>(t,n,r,o)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new K;if(i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>N(a,s,A())));throw et(c,o?.callee),c}return i.value},ze=e=>async(t,n,r,o)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>N(a,s,A())));throw et(c,o?.callee),c}return i.value},ne=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new K;return s.issues.length?{success:!1,error:new(e??rt)(s.issues.map(i=>N(i,o,A())))}:{success:!0,data:s.value}},jn=ne(ot),re=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>N(i,o,A())))}:{success:!0,data:s.value}},Ln=re(ot),Un=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ee(e)(t,n,o)},xn=e=>(t,n,r)=>Ee(e)(t,n,r),Mn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ze(e)(t,n,o)},Fn=e=>async(t,n,r)=>ze(e)(t,n,r),Kn=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ne(e)(t,n,o)},Vn=e=>(t,n,r)=>ne(e)(t,n,r),Wn=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return re(e)(t,n,o)},Gn=e=>async(t,n,r)=>re(e)(t,n,r),Bn=/^[cC][^\s-]{8,}$/,Jn=/^[0-9a-z]+$/,Hn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Yn=/^[0-9a-vA-V]{20}$/,qn=/^[A-Za-z0-9]{27}$/,Xn=/^[a-zA-Z0-9_-]{21}$/,Qn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,er=/^([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})$/,st=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)$/,tr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,nr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function rr(){return new RegExp(nr,"u")}const or=/^(?:(?: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])$/,sr=/^(([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}|:))$/,ir=/^((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])$/,cr=/^(([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])$/,ur=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,it=/^[A-Za-z0-9_-]*$/,ar=/^\+(?:[0-9]){6,14}[0-9]$/,ct="(?:(?:\\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])))",lr=new RegExp(`^${ct}$`);function ut(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 hr(e){return new RegExp(`^${ut(e)}$`)}function dr(e){const t=ut({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${ct}T(?:${r})$`)}const fr=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},pr=/^-?\d+$/,mr=/^-?\d+(?:\.\d+)?/,_r=/^(?:true|false)$/i,gr=/^null$/i,vr=/^[^A-Z]*$/,br=/^[^a-z]*$/,z=u("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),at={number:"number",bigint:"bigint",object:"date"},lt=u("$ZodCheckLessThan",(e,t)=>{z.init(e,t);const n=at[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ht=u("$ZodCheckGreaterThan",(e,t)=>{z.init(e,t);const n=at[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),wr=u("$ZodCheckMultipleOf",(e,t)=>{z.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.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):kn(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})}}),yr=u("$ZodCheckNumberFormat",(e,t)=>{z.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=Sn[t.format];e._zod.onattach.push(i=>{const c=i._zod.bag;c.format=t.format,c.minimum=o,c.maximum=s,n&&(c.pattern=pr)}),e._zod.check=i=>{const c=i.value;if(n){if(!Number.isInteger(c)){i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort});return}}c<o&&i.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),c>s&&i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inst:e})}}),kr=u("$ZodCheckMaxLength",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!we(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const i=ke(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Er=u("$ZodCheckMinLength",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!we(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const i=ke(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),zr=u("$ZodCheckLengthEquals",(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!we(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,s=o.length;if(s===t.length)return;const i=ke(o),c=s>t.length;r.issues.push({origin:i,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),oe=u("$ZodCheckStringFormat",(e,t)=>{var n,r;z.init(e,t),e._zod.onattach.push(o=>{const s=o._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),$r=u("$ZodCheckRegex",(e,t)=>{oe.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})}}),Zr=u("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=vr),oe.init(e,t)}),Sr=u("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=br),oe.init(e,t)}),Or=u("$ZodCheckIncludes",(e,t)=>{z.init(e,t);const n=W(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const s=o._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Tr=u("$ZodCheckStartsWith",(e,t)=>{z.init(e,t);const n=new RegExp(`^${W(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),Ir=u("$ZodCheckEndsWith",(e,t)=>{z.init(e,t);const n=new RegExp(`.*${W(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),Cr=u("$ZodCheckOverwrite",(e,t)=>{z.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Pr{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 r=t.split(`
20
20
  `).filter(i=>i),o=Math.min(...r.map(i=>i.length-i.trimStart().length)),s=r.map(i=>i.slice(o)).map(i=>" ".repeat(this.indent*2)+i);for(const i of s)this.content.push(i)}compile(){const t=Function,n=this?.args,o=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,o.join(`
21
- `))}}const Ar={major:4,minor:1,patch:13},g=u("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Ar;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const s of o._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(i,c,a)=>{let l=G(i),h;for(const p of c){if(p._zod.def.when){if(!p._zod.def.when(i))continue}else if(l)continue;const d=i.issues.length,m=p._zod.check(i);if(m instanceof Promise&&a?.async===!1)throw new K;if(h||m instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await m,i.issues.length!==d&&(l||(l=G(i,d)))});else{if(i.issues.length===d)continue;l||(l=G(i,d))}}return h?h.then(()=>i):i},s=(i,c,a)=>{if(G(i))return i.aborted=!0,i;const l=o(c,r,a);if(l instanceof Promise){if(a.async===!1)throw new K;return l.then(h=>e._zod.parse(h,a))}return e._zod.parse(l,a)};e._zod.run=(i,c)=>{if(c.skipChecks)return e._zod.parse(i,c);if(c.direction==="backward"){const l=e._zod.parse({value:i.value,issues:[]},{...c,skipChecks:!0});return l instanceof Promise?l.then(h=>s(h,i,c)):s(l,i,c)}const a=e._zod.parse(i,c);if(a instanceof Promise){if(c.async===!1)throw new K;return a.then(l=>o(l,r,c))}return o(a,r,c)}}e["~standard"]={validate:o=>{try{const s=jn(e,o);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return Ln(e,o).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}}),$e=u("$ZodString",(e,t)=>{g.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??fr(e._zod.bag),e._zod.parse=(n,r)=>{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}}),v=u("$ZodStringFormat",(e,t)=>{oe.init(e,t),$e.init(e,t)}),Rr=u("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=er),v.init(e,t)}),Nr=u("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=st(r))}else t.pattern??(t.pattern=st());v.init(e,t)}),Dr=u("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=tr),v.init(e,t)}),jr=u("$ZodURL",(e,t)=>{v.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.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(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.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=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Lr=u("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=rr()),v.init(e,t)}),Ur=u("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Xn),v.init(e,t)}),xr=u("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Bn),v.init(e,t)}),Mr=u("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Jn),v.init(e,t)}),Fr=u("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Hn),v.init(e,t)}),Kr=u("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Yn),v.init(e,t)}),Vr=u("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=qn),v.init(e,t)}),Wr=u("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=dr(t)),v.init(e,t)}),Gr=u("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=lr),v.init(e,t)}),Br=u("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=hr(t)),v.init(e,t)}),Jr=u("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Qn),v.init(e,t)}),Hr=u("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=or),v.init(e,t),e._zod.bag.format="ipv4"}),Yr=u("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=sr),v.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})}}}),qr=u("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=ir),v.init(e,t)}),Xr=u("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=cr),v.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,s]=r;if(!s)throw new Error;const i=Number(s);if(`${i}`!==s)throw new Error;if(i<0||i>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function dt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Qr=u("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ur),v.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{dt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function eo(e){if(!it.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return dt(n)}const to=u("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=it),v.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{eo(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),no=u("$ZodE164",(e,t)=>{t.pattern??(t.pattern=ar),v.init(e,t)});function ro(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}const oo=u("$ZodJWT",(e,t)=>{v.init(e,t),e._zod.check=n=>{ro(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),ft=u("$ZodNumber",(e,t)=>{g.init(e,t),e._zod.pattern=e._zod.bag.pattern??mr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),n}}),so=u("$ZodNumberFormat",(e,t)=>{wr.init(e,t),ft.init(e,t)}),io=u("$ZodBoolean",(e,t)=>{g.init(e,t),e._zod.pattern=_r,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),co=u("$ZodNull",(e,t)=>{g.init(e,t),e._zod.pattern=gr,e._zod.values=new Set([null]),e._zod.parse=(n,r)=>{const o=n.value;return o===null||n.issues.push({expected:"null",code:"invalid_type",input:o,inst:e}),n}}),uo=u("$ZodUnknown",(e,t)=>{g.init(e,t),e._zod.parse=n=>n}),ao=u("$ZodNever",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function pt(e,t,n){e.issues.length&&t.issues.push(...U(n,e.issues)),t.value[n]=e.value}const lo=u("$ZodArray",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const s=[];for(let i=0;i<o.length;i++){const c=o[i],a=t.element._zod.run({value:c,issues:[]},r);a instanceof Promise?s.push(a.then(l=>pt(l,n,i))):pt(a,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function se(e,t,n,r){e.issues.length&&t.issues.push(...U(n,e.issues)),e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function mt(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=Zn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function _t(e,t,n,r,o,s){const i=[],c=o.keySet,a=o.catchall._zod,l=a.def.type;for(const h in t){if(c.has(h))continue;if(l==="never"){i.push(h);continue}const p=a.run({value:t[h],issues:[]},r);p instanceof Promise?e.push(p.then(d=>se(d,n,h,t))):se(p,n,h,t)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const ho=u("$ZodObject",(e,t)=>{if(g.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const c=t.shape;Object.defineProperty(t,"shape",{get:()=>{const a={...c};return Object.defineProperty(t,"shape",{value:a}),a}})}const r=be(()=>mt(t));_(e._zod,"propValues",()=>{const c=t.shape,a={};for(const l in c){const h=c[l]._zod;if(h.values){a[l]??(a[l]=new Set);for(const p of h.values)a[l].add(p)}}return a});const o=ee,s=t.catchall;let i;e._zod.parse=(c,a)=>{i??(i=r.value);const l=c.value;if(!o(l))return c.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),c;c.value={};const h=[],p=i.shape;for(const d of i.keys){const E=p[d]._zod.run({value:l[d],issues:[]},a);E instanceof Promise?h.push(E.then(P=>se(P,c,d,l))):se(E,c,d,l)}return s?_t(h,l,c,a,r.value,e):h.length?Promise.all(h).then(()=>c):c}}),fo=u("$ZodObjectJIT",(e,t)=>{ho.init(e,t);const n=e._zod.parse,r=be(()=>mt(t)),o=d=>{const m=new Pr(["shape","payload","ctx"]),E=r.value,P=O=>{const S=Qe(O);return`shape[${S}]._zod.run({ value: input[${S}], issues: [] }, ctx)`};m.write("const input = payload.value;");const Q=Object.create(null);let De=0;for(const O of E.keys)Q[O]=`key_${De++}`;m.write("const newResult = {};");for(const O of E.keys){const S=Q[O],M=Qe(O);m.write(`const ${S} = ${P(O)};`),m.write(`
21
+ `))}}const Ar={major:4,minor:1,patch:13},g=u("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Ar;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const s of o._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(i,c,a)=>{let l=G(i),h;for(const f of c){if(f._zod.def.when){if(!f._zod.def.when(i))continue}else if(l)continue;const d=i.issues.length,m=f._zod.check(i);if(m instanceof Promise&&a?.async===!1)throw new K;if(h||m instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await m,i.issues.length!==d&&(l||(l=G(i,d)))});else{if(i.issues.length===d)continue;l||(l=G(i,d))}}return h?h.then(()=>i):i},s=(i,c,a)=>{if(G(i))return i.aborted=!0,i;const l=o(c,r,a);if(l instanceof Promise){if(a.async===!1)throw new K;return l.then(h=>e._zod.parse(h,a))}return e._zod.parse(l,a)};e._zod.run=(i,c)=>{if(c.skipChecks)return e._zod.parse(i,c);if(c.direction==="backward"){const l=e._zod.parse({value:i.value,issues:[]},{...c,skipChecks:!0});return l instanceof Promise?l.then(h=>s(h,i,c)):s(l,i,c)}const a=e._zod.parse(i,c);if(a instanceof Promise){if(c.async===!1)throw new K;return a.then(l=>o(l,r,c))}return o(a,r,c)}}e["~standard"]={validate:o=>{try{const s=jn(e,o);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return Ln(e,o).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}}),$e=u("$ZodString",(e,t)=>{g.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??fr(e._zod.bag),e._zod.parse=(n,r)=>{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}}),b=u("$ZodStringFormat",(e,t)=>{oe.init(e,t),$e.init(e,t)}),Rr=u("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=er),b.init(e,t)}),Nr=u("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=st(r))}else t.pattern??(t.pattern=st());b.init(e,t)}),Dr=u("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=tr),b.init(e,t)}),jr=u("$ZodURL",(e,t)=>{b.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.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(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.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=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Lr=u("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=rr()),b.init(e,t)}),Ur=u("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Xn),b.init(e,t)}),xr=u("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Bn),b.init(e,t)}),Mr=u("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Jn),b.init(e,t)}),Fr=u("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Hn),b.init(e,t)}),Kr=u("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Yn),b.init(e,t)}),Vr=u("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=qn),b.init(e,t)}),Wr=u("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=dr(t)),b.init(e,t)}),Gr=u("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=lr),b.init(e,t)}),Br=u("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=hr(t)),b.init(e,t)}),Jr=u("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Qn),b.init(e,t)}),Hr=u("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=or),b.init(e,t),e._zod.bag.format="ipv4"}),Yr=u("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=sr),b.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})}}}),qr=u("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=ir),b.init(e,t)}),Xr=u("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=cr),b.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,s]=r;if(!s)throw new Error;const i=Number(s);if(`${i}`!==s)throw new Error;if(i<0||i>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function dt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Qr=u("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ur),b.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{dt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function eo(e){if(!it.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return dt(n)}const to=u("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=it),b.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{eo(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),no=u("$ZodE164",(e,t)=>{t.pattern??(t.pattern=ar),b.init(e,t)});function ro(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}const oo=u("$ZodJWT",(e,t)=>{b.init(e,t),e._zod.check=n=>{ro(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),ft=u("$ZodNumber",(e,t)=>{g.init(e,t),e._zod.pattern=e._zod.bag.pattern??mr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),n}}),so=u("$ZodNumberFormat",(e,t)=>{yr.init(e,t),ft.init(e,t)}),io=u("$ZodBoolean",(e,t)=>{g.init(e,t),e._zod.pattern=_r,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),co=u("$ZodNull",(e,t)=>{g.init(e,t),e._zod.pattern=gr,e._zod.values=new Set([null]),e._zod.parse=(n,r)=>{const o=n.value;return o===null||n.issues.push({expected:"null",code:"invalid_type",input:o,inst:e}),n}}),uo=u("$ZodUnknown",(e,t)=>{g.init(e,t),e._zod.parse=n=>n}),ao=u("$ZodNever",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function pt(e,t,n){e.issues.length&&t.issues.push(...U(n,e.issues)),t.value[n]=e.value}const lo=u("$ZodArray",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const s=[];for(let i=0;i<o.length;i++){const c=o[i],a=t.element._zod.run({value:c,issues:[]},r);a instanceof Promise?s.push(a.then(l=>pt(l,n,i))):pt(a,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function se(e,t,n,r){e.issues.length&&t.issues.push(...U(n,e.issues)),e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function mt(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=Zn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function _t(e,t,n,r,o,s){const i=[],c=o.keySet,a=o.catchall._zod,l=a.def.type;for(const h in t){if(c.has(h))continue;if(l==="never"){i.push(h);continue}const f=a.run({value:t[h],issues:[]},r);f instanceof Promise?e.push(f.then(d=>se(d,n,h,t))):se(f,n,h,t)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const ho=u("$ZodObject",(e,t)=>{if(g.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const c=t.shape;Object.defineProperty(t,"shape",{get:()=>{const a={...c};return Object.defineProperty(t,"shape",{value:a}),a}})}const r=be(()=>mt(t));_(e._zod,"propValues",()=>{const c=t.shape,a={};for(const l in c){const h=c[l]._zod;if(h.values){a[l]??(a[l]=new Set);for(const f of h.values)a[l].add(f)}}return a});const o=ee,s=t.catchall;let i;e._zod.parse=(c,a)=>{i??(i=r.value);const l=c.value;if(!o(l))return c.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),c;c.value={};const h=[],f=i.shape;for(const d of i.keys){const v=f[d]._zod.run({value:l[d],issues:[]},a);v instanceof Promise?h.push(v.then(P=>se(P,c,d,l))):se(v,c,d,l)}return s?_t(h,l,c,a,r.value,e):h.length?Promise.all(h).then(()=>c):c}}),fo=u("$ZodObjectJIT",(e,t)=>{ho.init(e,t);const n=e._zod.parse,r=be(()=>mt(t)),o=d=>{const m=new Pr(["shape","payload","ctx"]),v=r.value,P=O=>{const S=Qe(O);return`shape[${S}]._zod.run({ value: input[${S}], issues: [] }, ctx)`};m.write("const input = payload.value;");const Q=Object.create(null);let De=0;for(const O of v.keys)Q[O]=`key_${De++}`;m.write("const newResult = {};");for(const O of v.keys){const S=Q[O],M=Qe(O);m.write(`const ${S} = ${P(O)};`),m.write(`
22
22
  if (${S}.issues.length) {
23
23
  payload.issues = payload.issues.concat(${S}.issues.map(iss => ({
24
24
  ...iss,
@@ -35,4 +35,4 @@
35
35
  newResult[${M}] = ${S}.value;
36
36
  }
37
37
 
38
- `)}m.write("payload.value = newResult;"),m.write("return payload;");const je=m.compile();return(O,S)=>je(d,O,S)};let s;const i=ee,c=!qe.jitless,l=c&&zn.value,h=t.catchall;let p;e._zod.parse=(d,m)=>{p??(p=r.value);const E=d.value;return i(E)?c&&l&&m?.async===!1&&m.jitless!==!0?(s||(s=o(t.shape)),d=s(d,m),h?_t([],E,d,m,p,e):d):n(d,m):(d.issues.push({expected:"object",code:"invalid_type",input:E,inst:e}),d)}});function gt(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const o=e.filter(s=>!G(s));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(i=>N(i,r,A())))}),t)}const po=u("$ZodUnion",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.options.some(o=>o._zod.optin==="optional")?"optional":void 0),_(e._zod,"optout",()=>t.options.some(o=>o._zod.optout==="optional")?"optional":void 0),_(e._zod,"values",()=>{if(t.options.every(o=>o._zod.values))return new Set(t.options.flatMap(o=>Array.from(o._zod.values)))}),_(e._zod,"pattern",()=>{if(t.options.every(o=>o._zod.pattern)){const o=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${o.map(s=>we(s.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const c=[];for(const a of t.options){const l=a._zod.run({value:o.value,issues:[]},s);if(l instanceof Promise)c.push(l),i=!0;else{if(l.issues.length===0)return l;c.push(l)}}return i?Promise.all(c).then(a=>gt(a,o,e,s)):gt(c,o,e,s)}}),mo=u("$ZodIntersection",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,s=t.left._zod.run({value:o,issues:[]},r),i=t.right._zod.run({value:o,issues:[]},r);return s instanceof Promise||i instanceof Promise?Promise.all([s,i]).then(([a,l])=>vt(n,a,l)):vt(n,s,i)}});function Ze(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(V(e)&&V(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),o={...e,...t};for(const s of r){const i=Ze(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],s=t[r],i=Ze(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function vt(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),G(e))return e;const r=Ze(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const _o=u("$ZodTuple",(e,t)=>{g.init(e,t);const n=t.items;e._zod.parse=(r,o)=>{const s=r.value;if(!Array.isArray(s))return r.issues.push({input:s,inst:e,expected:"tuple",code:"invalid_type"}),r;r.value=[];const i=[],c=[...n].reverse().findIndex(h=>h._zod.optin!=="optional"),a=c===-1?0:n.length-c;if(!t.rest){const h=s.length>n.length,p=s.length<a-1;if(h||p)return r.issues.push({...h?{code:"too_big",maximum:n.length}:{code:"too_small",minimum:n.length},input:s,inst:e,origin:"array"}),r}let l=-1;for(const h of n){if(l++,l>=s.length&&l>=a)continue;const p=h._zod.run({value:s[l],issues:[]},o);p instanceof Promise?i.push(p.then(d=>ie(d,r,l))):ie(p,r,l)}if(t.rest){const h=s.slice(n.length);for(const p of h){l++;const d=t.rest._zod.run({value:p,issues:[]},o);d instanceof Promise?i.push(d.then(m=>ie(m,r,l))):ie(d,r,l)}}return i.length?Promise.all(i).then(()=>r):r}});function ie(e,t,n){e.issues.length&&t.issues.push(...U(n,e.issues)),t.value[n]=e.value}const go=u("$ZodRecord",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!V(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const s=[],i=t.keyType._zod.values;if(i){n.value={};const c=new Set;for(const l of i)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){c.add(typeof l=="number"?l.toString():l);const h=t.valueType._zod.run({value:o[l],issues:[]},r);h instanceof Promise?s.push(h.then(p=>{p.issues.length&&n.issues.push(...U(l,p.issues)),n.value[l]=p.value})):(h.issues.length&&n.issues.push(...U(l,h.issues)),n.value[l]=h.value)}let a;for(const l in o)c.has(l)||(a=a??[],a.push(l));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:a})}else{n.value={};for(const c of Reflect.ownKeys(o)){if(c==="__proto__")continue;const a=t.keyType._zod.run({value:c,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(h=>N(h,r,A())),input:c,path:[c],inst:e}),n.value[a.value]=a.value;continue}const l=t.valueType._zod.run({value:o[c],issues:[]},r);l instanceof Promise?s.push(l.then(h=>{h.issues.length&&n.issues.push(...U(c,h.issues)),n.value[a.value]=h.value})):(l.issues.length&&n.issues.push(...U(c,l.issues)),n.value[a.value]=l.value)}}return s.length?Promise.all(s).then(()=>n):n}}),vo=u("$ZodEnum",(e,t)=>{g.init(e,t);const n=wn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(o=>$n.has(typeof o)).map(o=>typeof o=="string"?W(o):o.toString()).join("|")})$`),e._zod.parse=(o,s)=>{const i=o.value;return r.has(i)||o.issues.push({code:"invalid_value",values:n,input:i,inst:e}),o}}),bo=u("$ZodLiteral",(e,t)=>{if(g.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(r=>typeof r=="string"?W(r):r?W(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,o)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),r}}),yo=u("$ZodTransform",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ye(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(i=>(n.value=i,n));if(o instanceof Promise)throw new K;return n.value=o,n}});function bt(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const wo=u("$ZodOptional",(e,t)=>{g.init(e,t),e._zod.optin="optional",e._zod.optout="optional",_(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),_(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${we(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>bt(s,n.value)):bt(o,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),ko=u("$ZodNullable",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.innerType._zod.optin),_(e._zod,"optout",()=>t.innerType._zod.optout),_(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${we(n.source)}|null)$`):void 0}),_(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),Eo=u("$ZodDefault",(e,t)=>{g.init(e,t),e._zod.optin="optional",_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>yt(s,t)):yt(o,t)}});function yt(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const zo=u("$ZodPrefault",(e,t)=>{g.init(e,t),e._zod.optin="optional",_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),$o=u("$ZodNonOptional",(e,t)=>{g.init(e,t),_(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>wt(s,e)):wt(o,e)}});function wt(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 Zo=u("$ZodCatch",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.innerType._zod.optin),_(e._zod,"optout",()=>t.innerType._zod.optout),_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(i=>N(i,r,A()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(s=>N(s,r,A()))},input:n.value}),n.issues=[]),n)}}),So=u("$ZodPipe",(e,t)=>{g.init(e,t),_(e._zod,"values",()=>t.in._zod.values),_(e._zod,"optin",()=>t.in._zod.optin),_(e._zod,"optout",()=>t.out._zod.optout),_(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(i=>ce(i,t.in,r)):ce(s,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(s=>ce(s,t.out,r)):ce(o,t.out,r)}});function ce(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Oo=u("$ZodReadonly",(e,t)=>{g.init(e,t),_(e._zod,"propValues",()=>t.innerType._zod.propValues),_(e._zod,"values",()=>t.innerType._zod.values),_(e._zod,"optin",()=>t.innerType?._zod?.optin),_(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(kt):kt(o)}});function kt(e){return e.value=Object.freeze(e.value),e}const To=u("$ZodCustom",(e,t)=>{z.init(e,t),g.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(s=>Et(s,n,r,e));Et(o,n,r,e)}});function Et(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(X(o))}}var zt;class Io{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.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 r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(t)};return Object.keys(o).length?o:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Co(){return new Io}(zt=globalThis).__zod_globalRegistry??(zt.__zod_globalRegistry=Co());const ue=globalThis.__zod_globalRegistry;function Po(e,t){return new e({type:"string",...f(t)})}function Ao(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...f(t)})}function $t(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...f(t)})}function Ro(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...f(t)})}function No(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...f(t)})}function Do(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...f(t)})}function jo(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...f(t)})}function Lo(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...f(t)})}function Uo(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...f(t)})}function xo(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...f(t)})}function Mo(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...f(t)})}function Fo(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...f(t)})}function Ko(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...f(t)})}function Vo(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...f(t)})}function Wo(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...f(t)})}function Go(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...f(t)})}function Bo(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...f(t)})}function Jo(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...f(t)})}function Ho(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...f(t)})}function Yo(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...f(t)})}function qo(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...f(t)})}function Xo(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...f(t)})}function Qo(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...f(t)})}function es(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...f(t)})}function ts(e,t){return new e({type:"string",format:"date",check:"string_format",...f(t)})}function ns(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...f(t)})}function rs(e,t){return new e({type:"string",format:"duration",check:"string_format",...f(t)})}function os(e,t){return new e({type:"number",checks:[],...f(t)})}function ss(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...f(t)})}function is(e,t){return new e({type:"boolean",...f(t)})}function cs(e,t){return new e({type:"null",...f(t)})}function us(e){return new e({type:"unknown"})}function as(e,t){return new e({type:"never",...f(t)})}function Zt(e,t){return new lt({check:"less_than",...f(t),value:e,inclusive:!1})}function Se(e,t){return new lt({check:"less_than",...f(t),value:e,inclusive:!0})}function St(e,t){return new ht({check:"greater_than",...f(t),value:e,inclusive:!1})}function Oe(e,t){return new ht({check:"greater_than",...f(t),value:e,inclusive:!0})}function Ot(e,t){return new yr({check:"multiple_of",...f(t),value:e})}function Tt(e,t){return new kr({check:"max_length",...f(t),maximum:e})}function ae(e,t){return new Er({check:"min_length",...f(t),minimum:e})}function It(e,t){return new zr({check:"length_equals",...f(t),length:e})}function ls(e,t){return new $r({check:"string_format",format:"regex",...f(t),pattern:e})}function hs(e){return new Zr({check:"string_format",format:"lowercase",...f(e)})}function ds(e){return new Sr({check:"string_format",format:"uppercase",...f(e)})}function fs(e,t){return new Or({check:"string_format",format:"includes",...f(t),includes:e})}function ps(e,t){return new Tr({check:"string_format",format:"starts_with",...f(t),prefix:e})}function ms(e,t){return new Ir({check:"string_format",format:"ends_with",...f(t),suffix:e})}function B(e){return new Cr({check:"overwrite",tx:e})}function _s(e){return B(t=>t.normalize(e))}function gs(){return B(e=>e.trim())}function vs(){return B(e=>e.toLowerCase())}function bs(){return B(e=>e.toUpperCase())}function ys(){return B(e=>En(e))}function ws(e,t,n){return new e({type:"array",element:t,...f(n)})}function ks(e,t,n){return new e({type:"custom",check:"custom",fn:t,...f(n)})}function Es(e){const t=zs(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(X(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(X(o))}},e(n.value,n)));return t}function zs(e,t){const n=new z({check:"custom",...f(t)});return n._zod.check=e,n}const $s=u("ZodISODateTime",(e,t)=>{Wr.init(e,t),k.init(e,t)});function Zs(e){return es($s,e)}const Ss=u("ZodISODate",(e,t)=>{Gr.init(e,t),k.init(e,t)});function Os(e){return ts(Ss,e)}const Ts=u("ZodISOTime",(e,t)=>{Br.init(e,t),k.init(e,t)});function Is(e){return ns(Ts,e)}const Cs=u("ZodISODuration",(e,t)=>{Jr.init(e,t),k.init(e,t)});function Ps(e){return rs(Cs,e)}const $=u("ZodError",(e,t)=>{rt.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Dn(e,n)},flatten:{value:n=>Nn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ve,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ve,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),As=Ee($),Rs=ze($),Ns=ne($),Ds=re($),js=Un($),Ls=xn($),Us=Mn($),xs=Fn($),Ms=Kn($),Fs=Vn($),Ks=Wn($),Vs=Gn($),b=u("ZodType",(e,t)=>(g.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(L(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]})),e.clone=(n,r)=>R(e,n,r),e.brand=()=>e,e.register=(n,r)=>(n.add(e,r),e),e.parse=(n,r)=>As(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Ns(e,n,r),e.parseAsync=async(n,r)=>Rs(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>Ds(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>js(e,n,r),e.decode=(n,r)=>Ls(e,n,r),e.encodeAsync=async(n,r)=>Us(e,n,r),e.decodeAsync=async(n,r)=>xs(e,n,r),e.safeEncode=(n,r)=>Ms(e,n,r),e.safeDecode=(n,r)=>Fs(e,n,r),e.safeEncodeAsync=async(n,r)=>Ks(e,n,r),e.safeDecodeAsync=async(n,r)=>Vs(e,n,r),e.refine=(n,r)=>e.check(Mi(n,r)),e.superRefine=n=>e.check(Fi(n)),e.overwrite=n=>e.check(B(n)),e.optional=()=>Lt(e),e.nullable=()=>Ut(e),e.nullish=()=>Lt(Ut(e)),e.nonoptional=n=>Ri(e,n),e.array=()=>gi(e),e.or=n=>x([e,n]),e.and=n=>wi(e,n),e.transform=n=>Mt(e,Oi(n)),e.default=n=>Ci(e,n),e.prefault=n=>Ai(e,n),e.catch=n=>Di(e,n),e.pipe=n=>Mt(e,n),e.readonly=()=>Ui(e),e.describe=n=>{const r=e.clone();return ue.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return ue.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ue.get(e);const r=e.clone();return ue.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Ct=u("_ZodString",(e,t)=>{$e.init(e,t),b.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=(...r)=>e.check(ls(...r)),e.includes=(...r)=>e.check(fs(...r)),e.startsWith=(...r)=>e.check(ps(...r)),e.endsWith=(...r)=>e.check(ms(...r)),e.min=(...r)=>e.check(ae(...r)),e.max=(...r)=>e.check(Tt(...r)),e.length=(...r)=>e.check(It(...r)),e.nonempty=(...r)=>e.check(ae(1,...r)),e.lowercase=r=>e.check(hs(r)),e.uppercase=r=>e.check(ds(r)),e.trim=()=>e.check(gs()),e.normalize=(...r)=>e.check(_s(...r)),e.toLowerCase=()=>e.check(vs()),e.toUpperCase=()=>e.check(bs()),e.slugify=()=>e.check(ys())}),Ws=u("ZodString",(e,t)=>{$e.init(e,t),Ct.init(e,t),e.email=n=>e.check(Ao(Gs,n)),e.url=n=>e.check(Lo(Bs,n)),e.jwt=n=>e.check(Qo(ui,n)),e.emoji=n=>e.check(Uo(Js,n)),e.guid=n=>e.check($t(Pt,n)),e.uuid=n=>e.check(Ro(le,n)),e.uuidv4=n=>e.check(No(le,n)),e.uuidv6=n=>e.check(Do(le,n)),e.uuidv7=n=>e.check(jo(le,n)),e.nanoid=n=>e.check(xo(Hs,n)),e.guid=n=>e.check($t(Pt,n)),e.cuid=n=>e.check(Mo(Ys,n)),e.cuid2=n=>e.check(Fo(qs,n)),e.ulid=n=>e.check(Ko(Xs,n)),e.base64=n=>e.check(Yo(si,n)),e.base64url=n=>e.check(qo(ii,n)),e.xid=n=>e.check(Vo(Qs,n)),e.ksuid=n=>e.check(Wo(ei,n)),e.ipv4=n=>e.check(Go(ti,n)),e.ipv6=n=>e.check(Bo(ni,n)),e.cidrv4=n=>e.check(Jo(ri,n)),e.cidrv6=n=>e.check(Ho(oi,n)),e.e164=n=>e.check(Xo(ci,n)),e.datetime=n=>e.check(Zs(n)),e.date=n=>e.check(Os(n)),e.time=n=>e.check(Is(n)),e.duration=n=>e.check(Ps(n))});function J(e){return Po(Ws,e)}const k=u("ZodStringFormat",(e,t)=>{v.init(e,t),Ct.init(e,t)}),Gs=u("ZodEmail",(e,t)=>{Dr.init(e,t),k.init(e,t)}),Pt=u("ZodGUID",(e,t)=>{Rr.init(e,t),k.init(e,t)}),le=u("ZodUUID",(e,t)=>{Nr.init(e,t),k.init(e,t)}),Bs=u("ZodURL",(e,t)=>{jr.init(e,t),k.init(e,t)}),Js=u("ZodEmoji",(e,t)=>{Lr.init(e,t),k.init(e,t)}),Hs=u("ZodNanoID",(e,t)=>{Ur.init(e,t),k.init(e,t)}),Ys=u("ZodCUID",(e,t)=>{xr.init(e,t),k.init(e,t)}),qs=u("ZodCUID2",(e,t)=>{Mr.init(e,t),k.init(e,t)}),Xs=u("ZodULID",(e,t)=>{Fr.init(e,t),k.init(e,t)}),Qs=u("ZodXID",(e,t)=>{Kr.init(e,t),k.init(e,t)}),ei=u("ZodKSUID",(e,t)=>{Vr.init(e,t),k.init(e,t)}),ti=u("ZodIPv4",(e,t)=>{Hr.init(e,t),k.init(e,t)}),ni=u("ZodIPv6",(e,t)=>{Yr.init(e,t),k.init(e,t)}),ri=u("ZodCIDRv4",(e,t)=>{qr.init(e,t),k.init(e,t)}),oi=u("ZodCIDRv6",(e,t)=>{Xr.init(e,t),k.init(e,t)}),si=u("ZodBase64",(e,t)=>{Qr.init(e,t),k.init(e,t)}),ii=u("ZodBase64URL",(e,t)=>{to.init(e,t),k.init(e,t)}),ci=u("ZodE164",(e,t)=>{no.init(e,t),k.init(e,t)}),ui=u("ZodJWT",(e,t)=>{oo.init(e,t),k.init(e,t)}),At=u("ZodNumber",(e,t)=>{ft.init(e,t),b.init(e,t),e.gt=(r,o)=>e.check(St(r,o)),e.gte=(r,o)=>e.check(Oe(r,o)),e.min=(r,o)=>e.check(Oe(r,o)),e.lt=(r,o)=>e.check(Zt(r,o)),e.lte=(r,o)=>e.check(Se(r,o)),e.max=(r,o)=>e.check(Se(r,o)),e.int=r=>e.check(Rt(r)),e.safe=r=>e.check(Rt(r)),e.positive=r=>e.check(St(0,r)),e.nonnegative=r=>e.check(Oe(0,r)),e.negative=r=>e.check(Zt(0,r)),e.nonpositive=r=>e.check(Se(0,r)),e.multipleOf=(r,o)=>e.check(Ot(r,o)),e.step=(r,o)=>e.check(Ot(r,o)),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 Z(e){return os(At,e)}const ai=u("ZodNumberFormat",(e,t)=>{so.init(e,t),At.init(e,t)});function Rt(e){return ss(ai,e)}const li=u("ZodBoolean",(e,t)=>{io.init(e,t),b.init(e,t)});function Nt(e){return is(li,e)}const hi=u("ZodNull",(e,t)=>{co.init(e,t),b.init(e,t)});function di(e){return cs(hi,e)}const fi=u("ZodUnknown",(e,t)=>{uo.init(e,t),b.init(e,t)});function Dt(){return us(fi)}const pi=u("ZodNever",(e,t)=>{ao.init(e,t),b.init(e,t)});function mi(e){return as(pi,e)}const _i=u("ZodArray",(e,t)=>{lo.init(e,t),b.init(e,t),e.element=t.element,e.min=(n,r)=>e.check(ae(n,r)),e.nonempty=n=>e.check(ae(1,n)),e.max=(n,r)=>e.check(Tt(n,r)),e.length=(n,r)=>e.check(It(n,r)),e.unwrap=()=>e.element});function gi(e,t){return ws(_i,e,t)}const vi=u("ZodObject",(e,t)=>{fo.init(e,t),b.init(e,t),_(e,"shape",()=>t.shape),e.keyof=()=>$i(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Dt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Dt()}),e.strict=()=>e.clone({...e._zod.def,catchall:mi()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>In(e,n),e.safeExtend=n=>Cn(e,n),e.merge=n=>Pn(e,n),e.pick=n=>On(e,n),e.omit=n=>Tn(e,n),e.partial=(...n)=>An(jt,e,n[0]),e.required=(...n)=>Rn(xt,e,n[0])});function y(e,t){const n={type:"object",shape:e??{},...f(t)};return new vi(n)}const bi=u("ZodUnion",(e,t)=>{po.init(e,t),b.init(e,t),e.options=t.options});function x(e,t){return new bi({type:"union",options:e,...f(t)})}const yi=u("ZodIntersection",(e,t)=>{mo.init(e,t),b.init(e,t)});function wi(e,t){return new yi({type:"intersection",left:e,right:t})}const ki=u("ZodTuple",(e,t)=>{_o.init(e,t),b.init(e,t),e.rest=n=>e.clone({...e._zod.def,rest:n})});function T(e,t,n){const r=t instanceof g,o=r?n:t,s=r?t:null;return new ki({type:"tuple",items:e,rest:s,...f(o)})}const Ei=u("ZodRecord",(e,t)=>{go.init(e,t),b.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function zi(e,t,n){return new Ei({type:"record",keyType:e,valueType:t,...f(n)})}const Te=u("ZodEnum",(e,t)=>{vo.init(e,t),b.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const s={};for(const i of r)if(n.has(i))s[i]=t.entries[i];else throw new Error(`Key ${i} not found in enum`);return new Te({...t,checks:[],...f(o),entries:s})},e.exclude=(r,o)=>{const s={...t.entries};for(const i of r)if(n.has(i))delete s[i];else throw new Error(`Key ${i} not found in enum`);return new Te({...t,checks:[],...f(o),entries:s})}});function $i(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Te({type:"enum",entries:n,...f(t)})}const Zi=u("ZodLiteral",(e,t)=>{bo.init(e,t),b.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 C(e,t){return new Zi({type:"literal",values:Array.isArray(e)?e:[e],...f(t)})}const Si=u("ZodTransform",(e,t)=>{yo.init(e,t),b.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ye(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(X(s,n.value,t));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=e),n.issues.push(X(i))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(s=>(n.value=s,n)):(n.value=o,n)}});function Oi(e){return new Si({type:"transform",transform:e})}const jt=u("ZodOptional",(e,t)=>{wo.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Lt(e){return new jt({type:"optional",innerType:e})}const Ti=u("ZodNullable",(e,t)=>{ko.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ut(e){return new Ti({type:"nullable",innerType:e})}const Ii=u("ZodDefault",(e,t)=>{Eo.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ci(e,t){return new Ii({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():tt(t)}})}const Pi=u("ZodPrefault",(e,t)=>{zo.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ai(e,t){return new Pi({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():tt(t)}})}const xt=u("ZodNonOptional",(e,t)=>{$o.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ri(e,t){return new xt({type:"nonoptional",innerType:e,...f(t)})}const Ni=u("ZodCatch",(e,t)=>{Zo.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Di(e,t){return new Ni({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const ji=u("ZodPipe",(e,t)=>{So.init(e,t),b.init(e,t),e.in=t.in,e.out=t.out});function Mt(e,t){return new ji({type:"pipe",in:e,out:t})}const Li=u("ZodReadonly",(e,t)=>{Oo.init(e,t),b.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ui(e){return new Li({type:"readonly",innerType:e})}const xi=u("ZodCustom",(e,t)=>{To.init(e,t),b.init(e,t)});function Mi(e,t={}){return ks(xi,e,t)}function Fi(e){return Es(e)}const he=y({t:Z().gte(0),rate:Z().gte(0)}),H=y({opacity:Z().gte(0).lte(1),zIndex:Z().default(0)}),Y=y({volume:Z().gte(0).lte(1)}),Ki=y({type:C("image"),file:J(),fit:x([C("contain"),C("cover"),C("none")])}),Vi=y({type:C("audio"),file:J(),audioOutput:J(),enablePlaybackRateAdjustment:Nt()}),Wi=y({type:C("video"),file:J(),audioOutput:J(),enablePlaybackRateAdjustment:Nt(),fit:x([C("contain"),C("cover"),C("none")])}),Ie=T([Z(),di()]),Gi=T([Z(),y({set:y({...H.shape}).partial()}).partial()]),Bi=T([Z(),y({set:y({...H.shape}).partial(),lerp:y({...H.shape}).partial()}).partial()]),Ji=T([Z(),y({set:y({...he.shape,...Y.shape}).partial()}).partial()]),Hi=T([Z(),y({set:y({...he.shape,...Y.shape}).partial(),lerp:y({...Y.shape}).partial()}).partial()]),Yi=T([Z(),y({set:y({...he.shape,...Y.shape,...H.shape}).partial()}).partial()]),qi=T([Z(),y({set:y({...he.shape,...Y.shape,...H.shape}).partial(),lerp:y({...Y.shape,...H.shape}).partial()}).partial()]),Xi=y({...Ki.shape,keyframes:T([Bi],x([Gi,Ie]))}),Qi=y({...Vi.shape,keyframes:T([Hi],x([Ji,Ie]))}),ec=y({...Wi.shape,keyframes:T([qi],x([Yi,Ie]))}),tc=zi(J(),x([Xi,Qi,ec])),Ft={opacity:1,zIndex:0},Ce={t:0,rate:1,volume:1},Kt={t:0,rate:1,volume:1,opacity:1,zIndex:0},nc=Object.freeze(Object.defineProperty({__proto__:null,MediaSurfaceStateSchema:tc,defaultAudioOptions:Ce,defaultImageOptions:Ft,defaultVideoOptions:Kt},Symbol.toStringTag,{value:"Module"}));function de(e,t){if(!e.keyframes.filter(r=>r[1]===null).some(r=>r[0]<=t))switch(e.type){case"image":{if(e.keyframes[0][0]>t)return;const o=e.keyframes.filter(i=>i[1]!==null),s=Pe(o,t);return{...Ft,...s}}case"audio":{const r=e.keyframes.filter(i=>i[1]!==null),o=Vt(r,t);if(!o)return;const s=Pe(r,t);return{...Ce,...s,...o}}case"video":{const r=e.keyframes.filter(i=>i[1]!==null),o=Vt(r,t);if(!o)return;const s=Pe(r,t);return{...Kt,...s,...o}}}}function Pe(e,t){const n={};for(const[o,s]of e)o<=t?(Object.entries(s.lerp??{}).forEach(([i,c])=>{n[i]??={},n[i].before=[o,c]}),Object.entries(s.set??{}).forEach(([i,c])=>{n[i]??={},n[i].before=[o,c]})):Object.entries(s.lerp??{}).forEach(([i,c])=>{n[i]??={},n[i].after===void 0&&(n[i].after=[o,c])});const r={};return Object.entries(n).forEach(([o,{before:s,after:i}])=>{if(i===void 0&&s){r[o]=s[1];return}if(s&&i&&s[0]===i[0]){r[o]=i[1];return}if(s&&typeof s[1]=="number"&&i&&typeof i[1]=="number"){r[o]=s[1]+(t-s[0])*(i[1]-s[1])/(i[0]-s[0]);return}}),r}function Vt(e,t){const n=e[0];if(!n||n[0]>t)return;let r=0,{t:o,rate:s}=Ce;for(const[l,h]of e){if(l>t)break;const{set:p}=h;if(!p)continue;const{t:d,rate:m}=p;if(d!==void 0){r=l,o=d,m!==void 0&&(s=m);continue}if(m!==void 0){const P=(l-r)*s;r=l,o+=P,s=m}}const c=(t-r)*s,a=o+c;return{rate:s,t:a}}const rc=typeof navigator<"u"&&typeof navigator.standalone<"u",oc="GestureEvent"in window;function fe(e,t){return(e%t+t)%t}function sc(e,t,n){return e=fe(e,n),t=fe(t,n),Math.abs(e-t)<n/2?e-t:e<t?e+n-t:e-(t+n)}const Ae=e=>{try{const{pathname:t}=new URL(e,window.location.href);return t}catch{return}};class Re{constructor(t,n,r,o,s,i){this.surfaceElement=t,this.clipElement=n,this.constructAssetURL=o,this.getAudioOutput=s,this.mediaPreloader=i,this._state=r}isConnected(t){return!(!this.surfaceElement||!this.clipElement||!this.surfaceElement.contains(this.clipElement)||t&&!this.clipElement.contains(t))}_state;setState(t){this._state=t}timeout;loop=async()=>{clearTimeout(this.timeout),this.isConnected()?(this.update(),this.timeout=setTimeout(this.loop,Yt)):this.destroy()}}function Ne(e,t,n,r,o){let s;const i=r(n.file),c=Ae(i);switch(n.type){case"image":s=e instanceof HTMLImageElement?e:document.createElement("img"),Ae(s.src)!==c&&(s.src=i);break;case"audio":case"video":{if(e!==void 0){const a=Ae(e.src);e.tagName.toLowerCase()===n.type&&a!==void 0&&a===c&&(s=e)}s||(s=o.getElement(n.file,n.type)),s instanceof HTMLVideoElement&&!s.playsInline&&(s.playsInline=!0);break}}return(t.children.length!==1||t.childNodes[0]!==s)&&t.replaceChildren(s),s.style.position="absolute",s.style.width="100%",s.style.height="100%",s}function Wt(e,t,n){const r=String(t.opacity);e.style.opacity!==r&&(e.style.opacity=r);const o=Math.round(t.zIndex??0);parseInt(e.style.zIndex)!==o&&(e.style.zIndex=String(o)),e.style.objectFit!==n&&(e.style.objectFit=n)}function Gt(e,t,n,r){const o=t.volume*r;if(rc)o===0&&!e.muted?e.muted=!0:o>0&&e.muted&&(e.muted=!1);else if(e.muted&&(e.muted=!1),e.volume!==o&&(e.volume=o),e.sinkId!==n)try{e.setSinkId(n).catch(()=>{})}catch{}}const Bt=2e3,ic=1e3,Jt=100,Ht=50,Yt=5,pe=1e3,cc=10,uc=5,ac=.3,lc=.1;function hc(e){return Math.sign(e)*Math.pow(Math.abs(e)/pe,ac)*lc}function I(e,t){e.playbackRate!==t&&(e.playbackRate=t),e.paused&&e.play().catch(()=>{})}function qt(e,t,n,r,o){const s=o&&!oc;let i=!1;if(e.duration){const h=n.filter(([p,d])=>p>t.t&&(d?.set?.t!==void 0||d?.set?.rate!==void 0))[0];if(h?.[1]?.set?.t===0){const p=(e.duration-t.t)/t.rate,d=h[0]-t.t;i=Math.abs(p-d)<=uc,e.loop!==i&&(e.loop=i)}}const c=e.currentTime*1e3,a=i&&e.duration!==void 0?sc(c,t.t,e.duration*1e3):c-t.t,l=Math.abs(a);switch(!0){case(!s&&r.state==="idle"&&t.rate>0&&l>Bt):{const h=(t.t+t.rate*ic)/1e3;return e.duration!==void 0&&h>e.duration&&!i?{state:"idle"}:(I(e,0),e.currentTime=i?fe(h,e.duration*1e3):h,{state:"seeking-ahead"})}case(r.state==="seeking-ahead"&&e.seeking===!0):return{state:"seeking-ahead"};case(r.state==="seeking-ahead"&&e.seeking===!1):return I(e,0),{state:"seeked-ahead"};case(r.state==="seeked-ahead"&&a<-Jt):return I(e,t.rate),console.warn("Failed to seek ahead in time"),{state:"idle"};case(r.state==="seeked-ahead"&&l<=Jt):return I(e,t.rate),{state:"idle"};case(r.state==="seeked-ahead"&&l>Bt*1.5):return console.warn("Failed to seek ahead"),{state:"idle"};case r.state==="seeked-ahead":return{state:"seeked-ahead"};case(s&&r.state==="idle"&&t.rate>0&&l>Ht&&l<=pe):{const h=hc(a),p=Math.max(0,t.rate-h);return I(e,p),{state:"intercepting"}}case(r.state==="intercepting"&&l<=Yt):return I(e,t.rate),{state:"idle"};case(r.state==="intercepting"&&Math.sign(a)===Math.sign(e.playbackRate-t.rate)):return I(e,t.rate),{state:"idle"};case(r.state==="intercepting"&&l<pe*2):return{state:"intercepting"};case r.state==="intercepting":return I(e,t.rate),{state:"idle"};case(s&&r.state==="idle"&&l>pe):{const h=(t.t+t.rate*cc)/1e3;return e.currentTime=i?fe(h,e.duration*1e3):h,I(e,t.rate),{state:"seeking"}}case(r.state==="seeking"&&e.seeking):return{state:"seeking"};case(r.state==="seeking"&&!e.seeking):return{state:"idle"};case r.state==="idle":return I(e,t.rate),t.rate===0&&l>Ht&&(e.currentTime=t.t/1e3),{state:"idle"};default:return{state:"idle"}}}class dc extends Re{imageElement;update(){const t=de(this._state,Date.now());t?this.imageElement=Ne(this.imageElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.imageElement&&this.destroy(),!(!t||!this.imageElement)&&Wt(this.imageElement,t,this._state.fit)}destroy(){this.imageElement&&(this.imageElement.remove(),this.imageElement.src="",this.imageElement=void 0)}}class Xt extends Re{syncState={state:"idle"};audioElement;volume=1;update(){const t=de(this._state,Date.now());if(t?this.audioElement=Ne(this.audioElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.destroy(),!t||!this.audioElement)return;const n=this.getAudioOutput(this._state.audioOutput);Gt(this.audioElement,t,n,this.volume);const r=qt(this.audioElement,t,this._state.keyframes,this.syncState,this._state.enablePlaybackRateAdjustment);this.syncState=r}destroy(){this.audioElement&&(this.audioElement.pause(),this.audioElement.remove(),this.audioElement.volume=0,this.audioElement.currentTime=0,this.mediaPreloader.releaseElement(this.audioElement)),this.audioElement=void 0}}class Qt extends Re{syncState={state:"idle"};videoElement;volume=1;update(){const t=de(this._state,Date.now());if(t?this.videoElement=Ne(this.videoElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.destroy(),!t||!this.videoElement)return;const n=this.getAudioOutput(this._state.audioOutput);Wt(this.videoElement,t,this._state.fit),Gt(this.videoElement,t,n,this.volume);const r=qt(this.videoElement,t,this._state.keyframes,this.syncState,this._state.enablePlaybackRateAdjustment);this.syncState=r}destroy(){this.videoElement&&(this.videoElement.pause(),this.videoElement.remove(),this.videoElement.volume=0,this.videoElement.currentTime=0,this.mediaPreloader.releaseElement(this.videoElement)),this.videoElement=void 0}}class en{_state;_elements={};_constructAssetURL;constructor(t,n={}){this._constructAssetURL=t,this._state=n}get state(){return{...this._state}}setState(t){this._state=t,this.update()}update(){for(const[t,n]of Object.entries(this._elements)){if(!(t in this._state)){if(n.inUse){console.warn(`Failed to clean up element ${n.element.src}`);continue}n.element.src="",n.element.load(),delete this._elements[t]}n.inUse=n.element.isConnected}for(const[t,n]of Object.entries(this._state)){if(t in this._elements)continue;let r;switch(n.preload===!0?r="auto":n.preload===!1?r="none":r=n.preload,n.type){case"audio":{const o=document.createElement("audio");o.src=this._constructAssetURL(t),o.preload=r,this._elements[t]={element:o,inUse:!1,type:"audio"};break}case"video":{const o=document.createElement("video");o.src=this._constructAssetURL(t),o.preload=r,this._elements[t]={element:o,inUse:!1,type:"video"};break}}}}getElement(t,n){const r=this._elements[t];if(r&&r.inUse===!1)return r.inUse=!0,r.element;{const o=document.createElement(n);return o.src=this._constructAssetURL(t),n==="video"&&(this._elements[t]={element:o,type:n,inUse:!0}),o}}releaseElement(t){if(typeof t=="string"){const n=this._elements[t];n&&(n.inUse=!1)}else Object.values(this._elements).forEach(n=>{n.element===t&&(n.inUse=!1)})}}const fc="data-clip-id";class pc{constructor(t,n,r,o=new en(t)){this.constructAssetUrl=t,this.getAudioOutput=n,this.mediaPreloader=o,this._element=document.createElement("div"),this._element.className="surface-manager",this._element.style.width="100%",this._element.style.height="100%",this._state=r||{},this.update()}_state={};setState(t){this._state=t,this.update()}_volume=1;get volume(){return this._volume}set volume(t){this._volume=t,Object.values(this.resources).forEach(({manager:n})=>{(n instanceof Xt||n instanceof Qt)&&(n.volume=t)})}_element;get element(){return this._element}resources={};update(){Object.entries(this.resources).forEach(([n,{element:r,manager:o}])=>{n in this._state||(delete this.resources[n],r.remove(),o?.destroy())});const t=Object.keys(this._state).toSorted().map(n=>{const r=this.resources[n];if(r)return r.element;{const o=document.createElement("div");return o.setAttribute(fc,n),this.resources[n]={element:o},o}});this._element.replaceChildren(...t),Object.keys(this._state).toSorted().forEach(n=>{const r=this._state[n],o=this.resources[n];if(!o)throw new Error("Failed to create resource");if(o.manager)o.manager.setState(r);else switch(r.type){case"image":o.manager=new dc(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader),o.manager.loop();break;case"audio":{const s=new Xt(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader);o.manager=s,s.volume=this._volume,s.loop();break}case"video":{const s=new Qt(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader);o.manager=s,s.volume=this._volume,s.loop();break}}})}}const mc=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));w.CogsConfigChangedEvent=We,w.CogsConnection=bn,w.CogsConnectionCloseEvent=Ke,w.CogsConnectionOpenEvent=Fe,w.CogsIncomingEvent=Be,w.CogsMediaConfigChangedEvent=Je,w.CogsMessageEvent=Ve,w.CogsShowPhaseChangedEvent=He,w.CogsStateChangedEvent=Ge,w.DataStoreItemEvent=_e,w.DataStoreItemsEvent=ge,w.ManifestTypes=mc,w.MediaPreloader=en,w.MediaSchema=nc,w.SurfaceManager=pc,w.assetUrl=Me,w.getStateAtTime=de,w.preloadUrl=ln,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
38
+ `)}m.write("payload.value = newResult;"),m.write("return payload;");const je=m.compile();return(O,S)=>je(d,O,S)};let s;const i=ee,c=!qe.jitless,l=c&&zn.value,h=t.catchall;let f;e._zod.parse=(d,m)=>{f??(f=r.value);const v=d.value;return i(v)?c&&l&&m?.async===!1&&m.jitless!==!0?(s||(s=o(t.shape)),d=s(d,m),h?_t([],v,d,m,f,e):d):n(d,m):(d.issues.push({expected:"object",code:"invalid_type",input:v,inst:e}),d)}});function gt(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const o=e.filter(s=>!G(s));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(i=>N(i,r,A())))}),t)}const po=u("$ZodUnion",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.options.some(o=>o._zod.optin==="optional")?"optional":void 0),_(e._zod,"optout",()=>t.options.some(o=>o._zod.optout==="optional")?"optional":void 0),_(e._zod,"values",()=>{if(t.options.every(o=>o._zod.values))return new Set(t.options.flatMap(o=>Array.from(o._zod.values)))}),_(e._zod,"pattern",()=>{if(t.options.every(o=>o._zod.pattern)){const o=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${o.map(s=>ye(s.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const c=[];for(const a of t.options){const l=a._zod.run({value:o.value,issues:[]},s);if(l instanceof Promise)c.push(l),i=!0;else{if(l.issues.length===0)return l;c.push(l)}}return i?Promise.all(c).then(a=>gt(a,o,e,s)):gt(c,o,e,s)}}),mo=u("$ZodIntersection",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,s=t.left._zod.run({value:o,issues:[]},r),i=t.right._zod.run({value:o,issues:[]},r);return s instanceof Promise||i instanceof Promise?Promise.all([s,i]).then(([a,l])=>vt(n,a,l)):vt(n,s,i)}});function Ze(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(V(e)&&V(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),o={...e,...t};for(const s of r){const i=Ze(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],s=t[r],i=Ze(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function vt(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),G(e))return e;const r=Ze(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const _o=u("$ZodTuple",(e,t)=>{g.init(e,t);const n=t.items;e._zod.parse=(r,o)=>{const s=r.value;if(!Array.isArray(s))return r.issues.push({input:s,inst:e,expected:"tuple",code:"invalid_type"}),r;r.value=[];const i=[],c=[...n].reverse().findIndex(h=>h._zod.optin!=="optional"),a=c===-1?0:n.length-c;if(!t.rest){const h=s.length>n.length,f=s.length<a-1;if(h||f)return r.issues.push({...h?{code:"too_big",maximum:n.length}:{code:"too_small",minimum:n.length},input:s,inst:e,origin:"array"}),r}let l=-1;for(const h of n){if(l++,l>=s.length&&l>=a)continue;const f=h._zod.run({value:s[l],issues:[]},o);f instanceof Promise?i.push(f.then(d=>ie(d,r,l))):ie(f,r,l)}if(t.rest){const h=s.slice(n.length);for(const f of h){l++;const d=t.rest._zod.run({value:f,issues:[]},o);d instanceof Promise?i.push(d.then(m=>ie(m,r,l))):ie(d,r,l)}}return i.length?Promise.all(i).then(()=>r):r}});function ie(e,t,n){e.issues.length&&t.issues.push(...U(n,e.issues)),t.value[n]=e.value}const go=u("$ZodRecord",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!V(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const s=[],i=t.keyType._zod.values;if(i){n.value={};const c=new Set;for(const l of i)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){c.add(typeof l=="number"?l.toString():l);const h=t.valueType._zod.run({value:o[l],issues:[]},r);h instanceof Promise?s.push(h.then(f=>{f.issues.length&&n.issues.push(...U(l,f.issues)),n.value[l]=f.value})):(h.issues.length&&n.issues.push(...U(l,h.issues)),n.value[l]=h.value)}let a;for(const l in o)c.has(l)||(a=a??[],a.push(l));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:a})}else{n.value={};for(const c of Reflect.ownKeys(o)){if(c==="__proto__")continue;const a=t.keyType._zod.run({value:c,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(h=>N(h,r,A())),input:c,path:[c],inst:e}),n.value[a.value]=a.value;continue}const l=t.valueType._zod.run({value:o[c],issues:[]},r);l instanceof Promise?s.push(l.then(h=>{h.issues.length&&n.issues.push(...U(c,h.issues)),n.value[a.value]=h.value})):(l.issues.length&&n.issues.push(...U(c,l.issues)),n.value[a.value]=l.value)}}return s.length?Promise.all(s).then(()=>n):n}}),vo=u("$ZodEnum",(e,t)=>{g.init(e,t);const n=yn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(o=>$n.has(typeof o)).map(o=>typeof o=="string"?W(o):o.toString()).join("|")})$`),e._zod.parse=(o,s)=>{const i=o.value;return r.has(i)||o.issues.push({code:"invalid_value",values:n,input:i,inst:e}),o}}),bo=u("$ZodLiteral",(e,t)=>{if(g.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(r=>typeof r=="string"?W(r):r?W(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,o)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),r}}),wo=u("$ZodTransform",(e,t)=>{g.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ye(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(i=>(n.value=i,n));if(o instanceof Promise)throw new K;return n.value=o,n}});function bt(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const yo=u("$ZodOptional",(e,t)=>{g.init(e,t),e._zod.optin="optional",e._zod.optout="optional",_(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),_(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ye(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>bt(s,n.value)):bt(o,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),ko=u("$ZodNullable",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.innerType._zod.optin),_(e._zod,"optout",()=>t.innerType._zod.optout),_(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ye(n.source)}|null)$`):void 0}),_(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),Eo=u("$ZodDefault",(e,t)=>{g.init(e,t),e._zod.optin="optional",_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>wt(s,t)):wt(o,t)}});function wt(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const zo=u("$ZodPrefault",(e,t)=>{g.init(e,t),e._zod.optin="optional",_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),$o=u("$ZodNonOptional",(e,t)=>{g.init(e,t),_(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>yt(s,e)):yt(o,e)}});function yt(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 Zo=u("$ZodCatch",(e,t)=>{g.init(e,t),_(e._zod,"optin",()=>t.innerType._zod.optin),_(e._zod,"optout",()=>t.innerType._zod.optout),_(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(i=>N(i,r,A()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(s=>N(s,r,A()))},input:n.value}),n.issues=[]),n)}}),So=u("$ZodPipe",(e,t)=>{g.init(e,t),_(e._zod,"values",()=>t.in._zod.values),_(e._zod,"optin",()=>t.in._zod.optin),_(e._zod,"optout",()=>t.out._zod.optout),_(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(i=>ce(i,t.in,r)):ce(s,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(s=>ce(s,t.out,r)):ce(o,t.out,r)}});function ce(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Oo=u("$ZodReadonly",(e,t)=>{g.init(e,t),_(e._zod,"propValues",()=>t.innerType._zod.propValues),_(e._zod,"values",()=>t.innerType._zod.values),_(e._zod,"optin",()=>t.innerType?._zod?.optin),_(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(kt):kt(o)}});function kt(e){return e.value=Object.freeze(e.value),e}const To=u("$ZodCustom",(e,t)=>{z.init(e,t),g.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(s=>Et(s,n,r,e));Et(o,n,r,e)}});function Et(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(X(o))}}var zt;class Io{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.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 r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(t)};return Object.keys(o).length?o:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Co(){return new Io}(zt=globalThis).__zod_globalRegistry??(zt.__zod_globalRegistry=Co());const ue=globalThis.__zod_globalRegistry;function Po(e,t){return new e({type:"string",...p(t)})}function Ao(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...p(t)})}function $t(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...p(t)})}function Ro(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...p(t)})}function No(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...p(t)})}function Do(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...p(t)})}function jo(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...p(t)})}function Lo(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...p(t)})}function Uo(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...p(t)})}function xo(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...p(t)})}function Mo(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...p(t)})}function Fo(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...p(t)})}function Ko(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...p(t)})}function Vo(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...p(t)})}function Wo(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...p(t)})}function Go(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...p(t)})}function Bo(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...p(t)})}function Jo(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...p(t)})}function Ho(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...p(t)})}function Yo(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...p(t)})}function qo(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...p(t)})}function Xo(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...p(t)})}function Qo(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...p(t)})}function es(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...p(t)})}function ts(e,t){return new e({type:"string",format:"date",check:"string_format",...p(t)})}function ns(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...p(t)})}function rs(e,t){return new e({type:"string",format:"duration",check:"string_format",...p(t)})}function os(e,t){return new e({type:"number",checks:[],...p(t)})}function ss(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...p(t)})}function is(e,t){return new e({type:"boolean",...p(t)})}function cs(e,t){return new e({type:"null",...p(t)})}function us(e){return new e({type:"unknown"})}function as(e,t){return new e({type:"never",...p(t)})}function Zt(e,t){return new lt({check:"less_than",...p(t),value:e,inclusive:!1})}function Se(e,t){return new lt({check:"less_than",...p(t),value:e,inclusive:!0})}function St(e,t){return new ht({check:"greater_than",...p(t),value:e,inclusive:!1})}function Oe(e,t){return new ht({check:"greater_than",...p(t),value:e,inclusive:!0})}function Ot(e,t){return new wr({check:"multiple_of",...p(t),value:e})}function Tt(e,t){return new kr({check:"max_length",...p(t),maximum:e})}function ae(e,t){return new Er({check:"min_length",...p(t),minimum:e})}function It(e,t){return new zr({check:"length_equals",...p(t),length:e})}function ls(e,t){return new $r({check:"string_format",format:"regex",...p(t),pattern:e})}function hs(e){return new Zr({check:"string_format",format:"lowercase",...p(e)})}function ds(e){return new Sr({check:"string_format",format:"uppercase",...p(e)})}function fs(e,t){return new Or({check:"string_format",format:"includes",...p(t),includes:e})}function ps(e,t){return new Tr({check:"string_format",format:"starts_with",...p(t),prefix:e})}function ms(e,t){return new Ir({check:"string_format",format:"ends_with",...p(t),suffix:e})}function B(e){return new Cr({check:"overwrite",tx:e})}function _s(e){return B(t=>t.normalize(e))}function gs(){return B(e=>e.trim())}function vs(){return B(e=>e.toLowerCase())}function bs(){return B(e=>e.toUpperCase())}function ws(){return B(e=>En(e))}function ys(e,t,n){return new e({type:"array",element:t,...p(n)})}function ks(e,t,n){return new e({type:"custom",check:"custom",fn:t,...p(n)})}function Es(e){const t=zs(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(X(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(X(o))}},e(n.value,n)));return t}function zs(e,t){const n=new z({check:"custom",...p(t)});return n._zod.check=e,n}const $s=u("ZodISODateTime",(e,t)=>{Wr.init(e,t),E.init(e,t)});function Zs(e){return es($s,e)}const Ss=u("ZodISODate",(e,t)=>{Gr.init(e,t),E.init(e,t)});function Os(e){return ts(Ss,e)}const Ts=u("ZodISOTime",(e,t)=>{Br.init(e,t),E.init(e,t)});function Is(e){return ns(Ts,e)}const Cs=u("ZodISODuration",(e,t)=>{Jr.init(e,t),E.init(e,t)});function Ps(e){return rs(Cs,e)}const $=u("ZodError",(e,t)=>{rt.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Dn(e,n)},flatten:{value:n=>Nn(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ve,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ve,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),As=Ee($),Rs=ze($),Ns=ne($),Ds=re($),js=Un($),Ls=xn($),Us=Mn($),xs=Fn($),Ms=Kn($),Fs=Vn($),Ks=Wn($),Vs=Gn($),w=u("ZodType",(e,t)=>(g.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(L(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]})),e.clone=(n,r)=>R(e,n,r),e.brand=()=>e,e.register=(n,r)=>(n.add(e,r),e),e.parse=(n,r)=>As(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Ns(e,n,r),e.parseAsync=async(n,r)=>Rs(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>Ds(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>js(e,n,r),e.decode=(n,r)=>Ls(e,n,r),e.encodeAsync=async(n,r)=>Us(e,n,r),e.decodeAsync=async(n,r)=>xs(e,n,r),e.safeEncode=(n,r)=>Ms(e,n,r),e.safeDecode=(n,r)=>Fs(e,n,r),e.safeEncodeAsync=async(n,r)=>Ks(e,n,r),e.safeDecodeAsync=async(n,r)=>Vs(e,n,r),e.refine=(n,r)=>e.check(Mi(n,r)),e.superRefine=n=>e.check(Fi(n)),e.overwrite=n=>e.check(B(n)),e.optional=()=>Lt(e),e.nullable=()=>Ut(e),e.nullish=()=>Lt(Ut(e)),e.nonoptional=n=>Ri(e,n),e.array=()=>gi(e),e.or=n=>x([e,n]),e.and=n=>yi(e,n),e.transform=n=>Mt(e,Oi(n)),e.default=n=>Ci(e,n),e.prefault=n=>Ai(e,n),e.catch=n=>Di(e,n),e.pipe=n=>Mt(e,n),e.readonly=()=>Ui(e),e.describe=n=>{const r=e.clone();return ue.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return ue.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ue.get(e);const r=e.clone();return ue.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Ct=u("_ZodString",(e,t)=>{$e.init(e,t),w.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=(...r)=>e.check(ls(...r)),e.includes=(...r)=>e.check(fs(...r)),e.startsWith=(...r)=>e.check(ps(...r)),e.endsWith=(...r)=>e.check(ms(...r)),e.min=(...r)=>e.check(ae(...r)),e.max=(...r)=>e.check(Tt(...r)),e.length=(...r)=>e.check(It(...r)),e.nonempty=(...r)=>e.check(ae(1,...r)),e.lowercase=r=>e.check(hs(r)),e.uppercase=r=>e.check(ds(r)),e.trim=()=>e.check(gs()),e.normalize=(...r)=>e.check(_s(...r)),e.toLowerCase=()=>e.check(vs()),e.toUpperCase=()=>e.check(bs()),e.slugify=()=>e.check(ws())}),Ws=u("ZodString",(e,t)=>{$e.init(e,t),Ct.init(e,t),e.email=n=>e.check(Ao(Gs,n)),e.url=n=>e.check(Lo(Bs,n)),e.jwt=n=>e.check(Qo(ui,n)),e.emoji=n=>e.check(Uo(Js,n)),e.guid=n=>e.check($t(Pt,n)),e.uuid=n=>e.check(Ro(le,n)),e.uuidv4=n=>e.check(No(le,n)),e.uuidv6=n=>e.check(Do(le,n)),e.uuidv7=n=>e.check(jo(le,n)),e.nanoid=n=>e.check(xo(Hs,n)),e.guid=n=>e.check($t(Pt,n)),e.cuid=n=>e.check(Mo(Ys,n)),e.cuid2=n=>e.check(Fo(qs,n)),e.ulid=n=>e.check(Ko(Xs,n)),e.base64=n=>e.check(Yo(si,n)),e.base64url=n=>e.check(qo(ii,n)),e.xid=n=>e.check(Vo(Qs,n)),e.ksuid=n=>e.check(Wo(ei,n)),e.ipv4=n=>e.check(Go(ti,n)),e.ipv6=n=>e.check(Bo(ni,n)),e.cidrv4=n=>e.check(Jo(ri,n)),e.cidrv6=n=>e.check(Ho(oi,n)),e.e164=n=>e.check(Xo(ci,n)),e.datetime=n=>e.check(Zs(n)),e.date=n=>e.check(Os(n)),e.time=n=>e.check(Is(n)),e.duration=n=>e.check(Ps(n))});function J(e){return Po(Ws,e)}const E=u("ZodStringFormat",(e,t)=>{b.init(e,t),Ct.init(e,t)}),Gs=u("ZodEmail",(e,t)=>{Dr.init(e,t),E.init(e,t)}),Pt=u("ZodGUID",(e,t)=>{Rr.init(e,t),E.init(e,t)}),le=u("ZodUUID",(e,t)=>{Nr.init(e,t),E.init(e,t)}),Bs=u("ZodURL",(e,t)=>{jr.init(e,t),E.init(e,t)}),Js=u("ZodEmoji",(e,t)=>{Lr.init(e,t),E.init(e,t)}),Hs=u("ZodNanoID",(e,t)=>{Ur.init(e,t),E.init(e,t)}),Ys=u("ZodCUID",(e,t)=>{xr.init(e,t),E.init(e,t)}),qs=u("ZodCUID2",(e,t)=>{Mr.init(e,t),E.init(e,t)}),Xs=u("ZodULID",(e,t)=>{Fr.init(e,t),E.init(e,t)}),Qs=u("ZodXID",(e,t)=>{Kr.init(e,t),E.init(e,t)}),ei=u("ZodKSUID",(e,t)=>{Vr.init(e,t),E.init(e,t)}),ti=u("ZodIPv4",(e,t)=>{Hr.init(e,t),E.init(e,t)}),ni=u("ZodIPv6",(e,t)=>{Yr.init(e,t),E.init(e,t)}),ri=u("ZodCIDRv4",(e,t)=>{qr.init(e,t),E.init(e,t)}),oi=u("ZodCIDRv6",(e,t)=>{Xr.init(e,t),E.init(e,t)}),si=u("ZodBase64",(e,t)=>{Qr.init(e,t),E.init(e,t)}),ii=u("ZodBase64URL",(e,t)=>{to.init(e,t),E.init(e,t)}),ci=u("ZodE164",(e,t)=>{no.init(e,t),E.init(e,t)}),ui=u("ZodJWT",(e,t)=>{oo.init(e,t),E.init(e,t)}),At=u("ZodNumber",(e,t)=>{ft.init(e,t),w.init(e,t),e.gt=(r,o)=>e.check(St(r,o)),e.gte=(r,o)=>e.check(Oe(r,o)),e.min=(r,o)=>e.check(Oe(r,o)),e.lt=(r,o)=>e.check(Zt(r,o)),e.lte=(r,o)=>e.check(Se(r,o)),e.max=(r,o)=>e.check(Se(r,o)),e.int=r=>e.check(Rt(r)),e.safe=r=>e.check(Rt(r)),e.positive=r=>e.check(St(0,r)),e.nonnegative=r=>e.check(Oe(0,r)),e.negative=r=>e.check(Zt(0,r)),e.nonpositive=r=>e.check(Se(0,r)),e.multipleOf=(r,o)=>e.check(Ot(r,o)),e.step=(r,o)=>e.check(Ot(r,o)),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 Z(e){return os(At,e)}const ai=u("ZodNumberFormat",(e,t)=>{so.init(e,t),At.init(e,t)});function Rt(e){return ss(ai,e)}const li=u("ZodBoolean",(e,t)=>{io.init(e,t),w.init(e,t)});function Nt(e){return is(li,e)}const hi=u("ZodNull",(e,t)=>{co.init(e,t),w.init(e,t)});function di(e){return cs(hi,e)}const fi=u("ZodUnknown",(e,t)=>{uo.init(e,t),w.init(e,t)});function Dt(){return us(fi)}const pi=u("ZodNever",(e,t)=>{ao.init(e,t),w.init(e,t)});function mi(e){return as(pi,e)}const _i=u("ZodArray",(e,t)=>{lo.init(e,t),w.init(e,t),e.element=t.element,e.min=(n,r)=>e.check(ae(n,r)),e.nonempty=n=>e.check(ae(1,n)),e.max=(n,r)=>e.check(Tt(n,r)),e.length=(n,r)=>e.check(It(n,r)),e.unwrap=()=>e.element});function gi(e,t){return ys(_i,e,t)}const vi=u("ZodObject",(e,t)=>{fo.init(e,t),w.init(e,t),_(e,"shape",()=>t.shape),e.keyof=()=>$i(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Dt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Dt()}),e.strict=()=>e.clone({...e._zod.def,catchall:mi()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>In(e,n),e.safeExtend=n=>Cn(e,n),e.merge=n=>Pn(e,n),e.pick=n=>On(e,n),e.omit=n=>Tn(e,n),e.partial=(...n)=>An(jt,e,n[0]),e.required=(...n)=>Rn(xt,e,n[0])});function y(e,t){const n={type:"object",shape:e??{},...p(t)};return new vi(n)}const bi=u("ZodUnion",(e,t)=>{po.init(e,t),w.init(e,t),e.options=t.options});function x(e,t){return new bi({type:"union",options:e,...p(t)})}const wi=u("ZodIntersection",(e,t)=>{mo.init(e,t),w.init(e,t)});function yi(e,t){return new wi({type:"intersection",left:e,right:t})}const ki=u("ZodTuple",(e,t)=>{_o.init(e,t),w.init(e,t),e.rest=n=>e.clone({...e._zod.def,rest:n})});function T(e,t,n){const r=t instanceof g,o=r?n:t,s=r?t:null;return new ki({type:"tuple",items:e,rest:s,...p(o)})}const Ei=u("ZodRecord",(e,t)=>{go.init(e,t),w.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function zi(e,t,n){return new Ei({type:"record",keyType:e,valueType:t,...p(n)})}const Te=u("ZodEnum",(e,t)=>{vo.init(e,t),w.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const s={};for(const i of r)if(n.has(i))s[i]=t.entries[i];else throw new Error(`Key ${i} not found in enum`);return new Te({...t,checks:[],...p(o),entries:s})},e.exclude=(r,o)=>{const s={...t.entries};for(const i of r)if(n.has(i))delete s[i];else throw new Error(`Key ${i} not found in enum`);return new Te({...t,checks:[],...p(o),entries:s})}});function $i(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Te({type:"enum",entries:n,...p(t)})}const Zi=u("ZodLiteral",(e,t)=>{bo.init(e,t),w.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 C(e,t){return new Zi({type:"literal",values:Array.isArray(e)?e:[e],...p(t)})}const Si=u("ZodTransform",(e,t)=>{wo.init(e,t),w.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ye(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(X(s,n.value,t));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=e),n.issues.push(X(i))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(s=>(n.value=s,n)):(n.value=o,n)}});function Oi(e){return new Si({type:"transform",transform:e})}const jt=u("ZodOptional",(e,t)=>{yo.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Lt(e){return new jt({type:"optional",innerType:e})}const Ti=u("ZodNullable",(e,t)=>{ko.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ut(e){return new Ti({type:"nullable",innerType:e})}const Ii=u("ZodDefault",(e,t)=>{Eo.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ci(e,t){return new Ii({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():tt(t)}})}const Pi=u("ZodPrefault",(e,t)=>{zo.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ai(e,t){return new Pi({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():tt(t)}})}const xt=u("ZodNonOptional",(e,t)=>{$o.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ri(e,t){return new xt({type:"nonoptional",innerType:e,...p(t)})}const Ni=u("ZodCatch",(e,t)=>{Zo.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Di(e,t){return new Ni({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const ji=u("ZodPipe",(e,t)=>{So.init(e,t),w.init(e,t),e.in=t.in,e.out=t.out});function Mt(e,t){return new ji({type:"pipe",in:e,out:t})}const Li=u("ZodReadonly",(e,t)=>{Oo.init(e,t),w.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ui(e){return new Li({type:"readonly",innerType:e})}const xi=u("ZodCustom",(e,t)=>{To.init(e,t),w.init(e,t)});function Mi(e,t={}){return ks(xi,e,t)}function Fi(e){return Es(e)}const he=y({t:Z().gte(0),rate:Z().gte(0)}),H=y({opacity:Z().gte(0).lte(1),zIndex:Z().default(0)}),Y=y({volume:Z().gte(0).lte(1)}),Ki=y({type:C("image"),file:J(),fit:x([C("contain"),C("cover"),C("none")])}),Vi=y({type:C("audio"),file:J(),audioOutput:J(),enablePlaybackRateAdjustment:Nt()}),Wi=y({type:C("video"),file:J(),audioOutput:J(),enablePlaybackRateAdjustment:Nt(),fit:x([C("contain"),C("cover"),C("none")])}),Ie=T([Z(),di()]),Gi=T([Z(),y({set:y({...H.shape}).partial()}).partial()]),Bi=T([Z(),y({set:y({...H.shape}).partial(),lerp:y({...H.shape}).partial()}).partial()]),Ji=T([Z(),y({set:y({...he.shape,...Y.shape}).partial()}).partial()]),Hi=T([Z(),y({set:y({...he.shape,...Y.shape}).partial(),lerp:y({...Y.shape}).partial()}).partial()]),Yi=T([Z(),y({set:y({...he.shape,...Y.shape,...H.shape}).partial()}).partial()]),qi=T([Z(),y({set:y({...he.shape,...Y.shape,...H.shape}).partial(),lerp:y({...Y.shape,...H.shape}).partial()}).partial()]),Xi=y({...Ki.shape,keyframes:T([Bi],x([Gi,Ie]))}),Qi=y({...Vi.shape,keyframes:T([Hi],x([Ji,Ie]))}),ec=y({...Wi.shape,keyframes:T([qi],x([Yi,Ie]))}),tc=zi(J(),x([Xi,Qi,ec])),Ft={opacity:1,zIndex:0},Ce={t:0,rate:1,volume:1},Kt={t:0,rate:1,volume:1,opacity:1,zIndex:0},nc=Object.freeze(Object.defineProperty({__proto__:null,MediaSurfaceStateSchema:tc,defaultAudioOptions:Ce,defaultImageOptions:Ft,defaultVideoOptions:Kt},Symbol.toStringTag,{value:"Module"}));function de(e,t){if(!e.keyframes.filter(r=>r[1]===null).some(r=>r[0]<=t))switch(e.type){case"image":{if(e.keyframes[0][0]>t)return;const o=e.keyframes.filter(i=>i[1]!==null),s=Pe(o,t);return{...Ft,...s}}case"audio":{const r=e.keyframes.filter(i=>i[1]!==null),o=Vt(r,t);if(!o)return;const s=Pe(r,t);return{...Ce,...s,...o}}case"video":{const r=e.keyframes.filter(i=>i[1]!==null),o=Vt(r,t);if(!o)return;const s=Pe(r,t);return{...Kt,...s,...o}}}}function Pe(e,t){const n={};for(const[o,s]of e)o<=t?(Object.entries(s.lerp??{}).forEach(([i,c])=>{n[i]??={},n[i].before=[o,c]}),Object.entries(s.set??{}).forEach(([i,c])=>{n[i]??={},n[i].before=[o,c]})):Object.entries(s.lerp??{}).forEach(([i,c])=>{n[i]??={},n[i].after===void 0&&(n[i].after=[o,c])});const r={};return Object.entries(n).forEach(([o,{before:s,after:i}])=>{if(i===void 0&&s){r[o]=s[1];return}if(s&&i&&s[0]===i[0]){r[o]=i[1];return}if(s&&typeof s[1]=="number"&&i&&typeof i[1]=="number"){r[o]=s[1]+(t-s[0])*(i[1]-s[1])/(i[0]-s[0]);return}}),r}function Vt(e,t){const n=e[0];if(!n||n[0]>t)return;let r=0,{t:o,rate:s}=Ce;for(const[l,h]of e){if(l>t)break;const{set:f}=h;if(!f)continue;const{t:d,rate:m}=f;if(d!==void 0){r=l,o=d,m!==void 0&&(s=m);continue}if(m!==void 0){const P=(l-r)*s;r=l,o+=P,s=m}}const c=(t-r)*s,a=o+c;return{rate:s,t:a}}const rc=typeof navigator<"u"&&typeof navigator.standalone<"u",oc="GestureEvent"in window;function fe(e,t){return(e%t+t)%t}function sc(e,t,n){return e=fe(e,n),t=fe(t,n),Math.abs(e-t)<n/2?e-t:e<t?e+n-t:e-(t+n)}const Ae=e=>{try{const{pathname:t}=new URL(e,window.location.href);return t}catch{return}};class Re{constructor(t,n,r,o,s,i){this.surfaceElement=t,this.clipElement=n,this.constructAssetURL=o,this.getAudioOutput=s,this.mediaPreloader=i,this._state=r}isConnected(t){return!(!this.surfaceElement||!this.clipElement||!this.surfaceElement.contains(this.clipElement)||t&&!this.clipElement.contains(t))}_state;setState(t){this._state=t}timeout;loop=async()=>{clearTimeout(this.timeout),this.isConnected()?(this.update(),this.timeout=setTimeout(this.loop,Yt)):this.destroy()}}function Ne(e,t,n,r,o){let s;const i=r(n.file),c=Ae(i);switch(n.type){case"image":s=e instanceof HTMLImageElement?e:document.createElement("img"),Ae(s.src)!==c&&(s.src=i);break;case"audio":case"video":{if(e!==void 0){const a=Ae(e.src);e.tagName.toLowerCase()===n.type&&a!==void 0&&a===c&&(s=e)}s||(s=o.getElement(n.file,n.type)),s instanceof HTMLVideoElement&&!s.playsInline&&(s.playsInline=!0);break}}return(t.children.length!==1||t.childNodes[0]!==s)&&t.replaceChildren(s),s.style.position="absolute",s.style.width="100%",s.style.height="100%",s}function Wt(e,t,n){const r=String(t.opacity);e.style.opacity!==r&&(e.style.opacity=r);const o=Math.round(t.zIndex??0);parseInt(e.style.zIndex)!==o&&(e.style.zIndex=String(o)),e.style.objectFit!==n&&(e.style.objectFit=n)}function Gt(e,t,n,r){const o=t.volume*r;if(rc)o===0&&!e.muted?e.muted=!0:o>0&&e.muted&&(e.muted=!1);else if(e.muted&&(e.muted=!1),e.volume!==o&&(e.volume=o),e.sinkId!==n)try{e.setSinkId(n).catch(()=>{})}catch{}}const Bt=2e3,ic=1e3,Jt=100,Ht=50,Yt=5,pe=1e3,cc=10,uc=100,ac=.3,lc=.1;function hc(e){return Math.sign(e)*Math.pow(Math.abs(e)/pe,ac)*lc}function I(e,t){e.playbackRate!==t&&(e.playbackRate=t),e.paused&&e.play().catch(()=>{})}function qt(e,t,n,r,o,s){const i=s&&!oc;let c=!1;if(e.duration){const d=n.filter(([m])=>m>n[0][0]&&m>r).filter(([,m])=>m?.set?.t!==void 0||m?.set?.rate!==void 0)[0];if(d?.[1]?.set?.t===0){const m=(e.duration*1e3-t.t)/t.rate,v=d[0]-r;c=Math.abs(m-v)<=uc,e.loop!==c&&(e.loop=c)}}const a=e.currentTime*1e3,l=c&&e.duration!==void 0?sc(a,t.t,e.duration*1e3):a-t.t,h=Math.abs(l);switch(!0){case(!i&&o.state==="idle"&&t.rate>0&&h>Bt):{const f=(t.t+t.rate*ic)/1e3;return e.duration!==void 0&&f>e.duration&&!c?{state:"idle"}:(I(e,0),e.currentTime=c?fe(f,e.duration*1e3):f,{state:"seeking-ahead"})}case(o.state==="seeking-ahead"&&e.seeking===!0):return{state:"seeking-ahead"};case(o.state==="seeking-ahead"&&e.seeking===!1):return I(e,0),{state:"seeked-ahead"};case(o.state==="seeked-ahead"&&l<-Jt):return I(e,t.rate),console.warn("Failed to seek ahead in time"),{state:"idle"};case(o.state==="seeked-ahead"&&h<=Jt):return I(e,t.rate),{state:"idle"};case(o.state==="seeked-ahead"&&h>Bt*1.5):return console.warn("Failed to seek ahead"),{state:"idle"};case o.state==="seeked-ahead":return{state:"seeked-ahead"};case(i&&o.state==="idle"&&t.rate>0&&h>Ht&&h<=pe):{const f=hc(l),d=Math.max(0,t.rate-f);return I(e,d),{state:"intercepting"}}case(o.state==="intercepting"&&h<=Yt):return I(e,t.rate),{state:"idle"};case(o.state==="intercepting"&&Math.sign(l)===Math.sign(e.playbackRate-t.rate)):return I(e,t.rate),{state:"idle"};case(o.state==="intercepting"&&h<pe*2):return{state:"intercepting"};case o.state==="intercepting":return I(e,t.rate),{state:"idle"};case(i&&o.state==="idle"&&h>pe):{const f=(t.t+t.rate*cc)/1e3;return e.currentTime=c?fe(f,e.duration*1e3):f,I(e,t.rate),{state:"seeking"}}case(o.state==="seeking"&&e.seeking):return{state:"seeking"};case(o.state==="seeking"&&!e.seeking):return{state:"idle"};case o.state==="idle":return I(e,t.rate),t.rate===0&&h>Ht&&(e.currentTime=t.t/1e3),{state:"idle"};default:return{state:"idle"}}}class dc extends Re{imageElement;update(){const t=de(this._state,Date.now());t?this.imageElement=Ne(this.imageElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.imageElement&&this.destroy(),!(!t||!this.imageElement)&&Wt(this.imageElement,t,this._state.fit)}destroy(){this.imageElement&&(this.imageElement.remove(),this.imageElement.src="",this.imageElement=void 0)}}class Xt extends Re{syncState={state:"idle"};audioElement;volume=1;update(){const t=Date.now(),n=de(this._state,t);if(n?this.audioElement=Ne(this.audioElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.destroy(),!n||!this.audioElement)return;const r=this.getAudioOutput(this._state.audioOutput);Gt(this.audioElement,n,r,this.volume);const o=qt(this.audioElement,n,this._state.keyframes,t,this.syncState,this._state.enablePlaybackRateAdjustment);this.syncState=o}destroy(){this.audioElement&&(this.audioElement.pause(),this.audioElement.remove(),this.audioElement.volume=0,this.audioElement.currentTime=0,this.mediaPreloader.releaseElement(this.audioElement)),this.audioElement=void 0}}class Qt extends Re{syncState={state:"idle"};videoElement;volume=1;update(){const t=Date.now(),n=de(this._state,t);if(n?this.videoElement=Ne(this.videoElement,this.clipElement,this._state,this.constructAssetURL,this.mediaPreloader):this.destroy(),!n||!this.videoElement)return;const r=this.getAudioOutput(this._state.audioOutput);Wt(this.videoElement,n,this._state.fit),Gt(this.videoElement,n,r,this.volume);const o=qt(this.videoElement,n,this._state.keyframes,t,this.syncState,this._state.enablePlaybackRateAdjustment);this.syncState=o}destroy(){this.videoElement&&(this.videoElement.pause(),this.videoElement.remove(),this.videoElement.volume=0,this.videoElement.currentTime=0,this.mediaPreloader.releaseElement(this.videoElement)),this.videoElement=void 0}}class en{_state;_elements={};_constructAssetURL;constructor(t,n={}){this._constructAssetURL=t,this._state=n}get state(){return{...this._state}}setState(t){this._state=t,this.update()}update(){for(const[t,n]of Object.entries(this._elements)){if(!(t in this._state)){if(n.inUse){console.warn(`Failed to clean up element ${n.element.src}`);continue}n.element.src="",n.element.load(),delete this._elements[t]}n.inUse=n.element.isConnected}for(const[t,n]of Object.entries(this._state)){if(t in this._elements)continue;let r;switch(n.preload===!0?r="auto":n.preload===!1?r="none":r=n.preload,n.type){case"audio":{const o=document.createElement("audio");o.src=this._constructAssetURL(t),o.preload=r,this._elements[t]={element:o,inUse:!1,type:"audio"};break}case"video":{const o=document.createElement("video");o.src=this._constructAssetURL(t),o.preload=r,this._elements[t]={element:o,inUse:!1,type:"video"};break}}}}getElement(t,n){const r=this._elements[t];if(r&&r.inUse===!1)return r.inUse=!0,r.element;{const o=document.createElement(n);return o.src=this._constructAssetURL(t),n==="video"&&(this._elements[t]={element:o,type:n,inUse:!0}),o}}releaseElement(t){if(typeof t=="string"){const n=this._elements[t];n&&(n.inUse=!1)}else Object.values(this._elements).forEach(n=>{n.element===t&&(n.inUse=!1)})}}const fc="data-clip-id";class pc{constructor(t,n,r,o=new en(t)){this.constructAssetUrl=t,this.getAudioOutput=n,this.mediaPreloader=o,this._element=document.createElement("div"),this._element.className="surface-manager",this._element.style.width="100%",this._element.style.height="100%",this._state=r||{},this.update()}_state={};setState(t){this._state=t,this.update()}_volume=1;get volume(){return this._volume}set volume(t){this._volume=t,Object.values(this.resources).forEach(({manager:n})=>{(n instanceof Xt||n instanceof Qt)&&(n.volume=t)})}_element;get element(){return this._element}resources={};update(){Object.entries(this.resources).forEach(([n,{element:r,manager:o}])=>{n in this._state||(delete this.resources[n],r.remove(),o?.destroy())});const t=Object.keys(this._state).toSorted().map(n=>{const r=this.resources[n];if(r)return r.element;{const o=document.createElement("div");return o.setAttribute(fc,n),this.resources[n]={element:o},o}});this._element.replaceChildren(...t),Object.keys(this._state).toSorted().forEach(n=>{const r=this._state[n],o=this.resources[n];if(!o)throw new Error("Failed to create resource");if(o.manager)o.manager.setState(r);else switch(r.type){case"image":o.manager=new dc(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader),o.manager.loop();break;case"audio":{const s=new Xt(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader);o.manager=s,s.volume=this._volume,s.loop();break}case"video":{const s=new Qt(this._element,o.element,r,this.constructAssetUrl,this.getAudioOutput,this.mediaPreloader);o.manager=s,s.volume=this._volume,s.loop();break}}})}}const mc=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));k.CogsConfigChangedEvent=We,k.CogsConnection=bn,k.CogsConnectionCloseEvent=Ke,k.CogsConnectionOpenEvent=Fe,k.CogsIncomingEvent=Be,k.CogsMediaConfigChangedEvent=Je,k.CogsMessageEvent=Ve,k.CogsShowPhaseChangedEvent=He,k.CogsStateChangedEvent=Ge,k.DataStoreItemEvent=_e,k.DataStoreItemsEvent=ge,k.ManifestTypes=mc,k.MediaPreloader=en,k.MediaSchema=nc,k.SurfaceManager=pc,k.assetUrl=Me,k.getStateAtTime=de,k.preloadUrl=ln,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
@@ -43,7 +43,7 @@ interface TemporalSyncState {
43
43
  * Makes sure the media is at the correct time and speed.
44
44
  * - Algorithms and constants defined above
45
45
  */
46
- export declare function assertTemporalProperties(mediaElement: HTMLMediaElement, properties: TemporalProperties, keyframes: VideoState['keyframes'], syncState: TemporalSyncState, enablePlaybackRateAdjustment: boolean): TemporalSyncState;
46
+ export declare function assertTemporalProperties(mediaElement: HTMLMediaElement, properties: TemporalProperties, keyframes: VideoState['keyframes'], currentTime: number, syncState: TemporalSyncState, enablePlaybackRateAdjustment: boolean): TemporalSyncState;
47
47
  export declare class ImageManager extends MediaClipManager<ImageState> {
48
48
  private imageElement;
49
49
  protected update(): void;
@@ -181,7 +181,8 @@ const SYNC_INNER_TARGET_THRESHOLD_MS = 5;
181
181
  const SYNC_MAX_THRESHOLD_MS = 1_000;
182
182
  const SYNC_SEEK_LOOKAHEAD_MS = 10;
183
183
  // If the media is scheduled to go back to the start close in time to the end of the video, we'll use the loop attribute.
184
- const LOOPING_EPSILON_MS = 5;
184
+ // This value allows disagreement between HTMLVideoElement.duration and the length of the different audio streams we have in COGS.
185
+ const LOOPING_EPSILON_MS = 100;
185
186
  const PLAYBACK_ADJUSTMENT_SMOOTHING = 0.3;
186
187
  const MAX_PLAYBACK_RATE_ADJUSTMENT = 0.1;
187
188
  function playbackSmoothing(deltaTime) {
@@ -204,7 +205,7 @@ function assertPlaybackRate(mediaElement, playbackRate) {
204
205
  * Makes sure the media is at the correct time and speed.
205
206
  * - Algorithms and constants defined above
206
207
  */
207
- export function assertTemporalProperties(mediaElement, properties, keyframes, syncState, enablePlaybackRateAdjustment) {
208
+ export function assertTemporalProperties(mediaElement, properties, keyframes, currentTime, syncState, enablePlaybackRateAdjustment) {
208
209
  // On Webkit (using the simulator on safari and COGS mobile app on iOS) changes to currentTime and playbackRate are much less responsive.
209
210
  // We make sure we only do lower frequency updates, and don't change playbackRate.
210
211
  const playbackRateSync = enablePlaybackRateAdjustment && !IS_WEBKIT;
@@ -212,20 +213,23 @@ export function assertTemporalProperties(mediaElement, properties, keyframes, sy
212
213
  // Sounds like looping to me!
213
214
  let isLooping = false;
214
215
  if (mediaElement.duration) {
215
- const nextTemporalKeyframe = keyframes.filter(([t, kf]) => t > properties.t && (kf?.set?.t !== undefined || kf?.set?.rate !== undefined))[0];
216
+ const futureTemporalKeyframes = keyframes
217
+ .filter(([t]) => t > keyframes[0][0] && t > currentTime)
218
+ .filter(([, props]) => props?.set?.t !== undefined || props?.set?.rate !== undefined);
219
+ const nextTemporalKeyframe = futureTemporalKeyframes[0];
216
220
  if (nextTemporalKeyframe?.[1]?.set?.t === 0) {
217
- const timeRemaining = (mediaElement.duration - properties.t) / properties.rate;
218
- const timeUntilKeyframe = nextTemporalKeyframe[0] - properties.t;
221
+ const timeRemaining = (mediaElement.duration * 1000 - properties.t) / properties.rate;
222
+ const timeUntilKeyframe = nextTemporalKeyframe[0] - currentTime;
219
223
  isLooping = Math.abs(timeRemaining - timeUntilKeyframe) <= LOOPING_EPSILON_MS;
220
224
  if (mediaElement.loop !== isLooping) {
221
225
  mediaElement.loop = isLooping;
222
226
  }
223
227
  }
224
228
  }
225
- const currentTime = mediaElement.currentTime * 1000;
229
+ const currentMediaTime = mediaElement.currentTime * 1000;
226
230
  const deltaTime = isLooping && mediaElement.duration !== undefined
227
- ? moduloDiff(currentTime, properties.t, mediaElement.duration * 1000)
228
- : currentTime - properties.t;
231
+ ? moduloDiff(currentMediaTime, properties.t, mediaElement.duration * 1000)
232
+ : currentMediaTime - properties.t;
229
233
  const deltaTimeAbs = Math.abs(deltaTime);
230
234
  switch (true) {
231
235
  /**
@@ -362,7 +366,8 @@ export class AudioManager extends MediaClipManager {
362
366
  audioElement;
363
367
  volume = 1;
364
368
  update() {
365
- const currentState = getStateAtTime(this._state, Date.now());
369
+ const now = Date.now();
370
+ const currentState = getStateAtTime(this._state, now);
366
371
  if (currentState) {
367
372
  this.audioElement = assertElement(this.audioElement, this.clipElement, this._state, this.constructAssetURL, this.mediaPreloader);
368
373
  }
@@ -373,7 +378,7 @@ export class AudioManager extends MediaClipManager {
373
378
  return;
374
379
  const sinkId = this.getAudioOutput(this._state.audioOutput);
375
380
  assertAudialProperties(this.audioElement, currentState, sinkId, this.volume);
376
- const nextSyncState = assertTemporalProperties(this.audioElement, currentState, this._state.keyframes, this.syncState, this._state.enablePlaybackRateAdjustment);
381
+ const nextSyncState = assertTemporalProperties(this.audioElement, currentState, this._state.keyframes, now, this.syncState, this._state.enablePlaybackRateAdjustment);
377
382
  this.syncState = nextSyncState;
378
383
  }
379
384
  destroy() {
@@ -392,7 +397,8 @@ export class VideoManager extends MediaClipManager {
392
397
  videoElement;
393
398
  volume = 1;
394
399
  update() {
395
- const currentState = getStateAtTime(this._state, Date.now());
400
+ const now = Date.now();
401
+ const currentState = getStateAtTime(this._state, now);
396
402
  if (currentState) {
397
403
  this.videoElement = assertElement(this.videoElement, this.clipElement, this._state, this.constructAssetURL, this.mediaPreloader);
398
404
  }
@@ -404,7 +410,7 @@ export class VideoManager extends MediaClipManager {
404
410
  const sinkId = this.getAudioOutput(this._state.audioOutput);
405
411
  assertVisualProperties(this.videoElement, currentState, this._state.fit);
406
412
  assertAudialProperties(this.videoElement, currentState, sinkId, this.volume);
407
- const nextSyncState = assertTemporalProperties(this.videoElement, currentState, this._state.keyframes, this.syncState, this._state.enablePlaybackRateAdjustment);
413
+ const nextSyncState = assertTemporalProperties(this.videoElement, currentState, this._state.keyframes, now, this.syncState, this._state.enablePlaybackRateAdjustment);
408
414
  this.syncState = nextSyncState;
409
415
  }
410
416
  destroy() {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Connect to COGS to build a custom Media Master",
4
4
  "author": "Clockwork Dog <info@clockwork.dog>",
5
5
  "homepage": "https://github.com/clockwork-dog/cogs-sdk/tree/main/packages/javascript",
6
- "version": "3.0.3",
6
+ "version": "3.0.4",
7
7
  "keywords": [],
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "cy:generate": "cypress run --e2e"
38
38
  },
39
39
  "dependencies": {
40
- "@clockworkdog/timesync": "^3.0.3",
40
+ "@clockworkdog/timesync": "^3.0.4",
41
41
  "reconnecting-websocket": "^4.4.0",
42
42
  "zod": "^4.1.13"
43
43
  },