@shotstack/shotstack-studio 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/entities/player.d.ts +2 -0
- package/dist/core/schemas/asset.d.ts +10 -6
- package/dist/core/schemas/audio-asset.d.ts +10 -6
- package/dist/core/schemas/clip.d.ts +35 -21
- package/dist/core/schemas/edit.d.ts +70 -42
- package/dist/core/schemas/track.d.ts +35 -21
- package/dist/core/schemas/video-asset.d.ts +10 -6
- package/dist/shotstack-studio.es.js +30 -4
- package/dist/shotstack-studio.umd.js +2 -2
- package/package.json +1 -1
- package/readme.md +10 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(F,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("pixi.js"),require("opentype.js"),require("howler"),require("@ffmpeg/ffmpeg")):typeof define=="function"&&define.amd?define(["exports","pixi.js","opentype.js","howler","@ffmpeg/ffmpeg"],K):(F=typeof globalThis<"u"?globalThis:F||self,K(F.ShotstackStudio={},F.PIXI,F.opentype,F.Howler,F.ffmpeg))})(this,function(F,K,Zt,Kt,Ht){"use strict";function $e(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const w=$e(K),ut=$e(Zt),Bt=$e(Kt);class dt{events;constructor(){this.events={}}on(e,t){this.events[e]||(this.events[e]=new Set),this.events[e].add(t)}off(e,t){this.events[e]&&(this.events[e].delete(t),!(this.events[e].size>0)&&delete this.events[e])}clear(e){delete this.events[e]}emit(e,t){if(this.events[e])for(const i of this.events[e])i(t)}}class jt extends dt{registry;constructor(){super(),this.registry={}}}class Vt{loadTracker;constructor(){this.loadTracker=new jt}async load(e,t){this.updateAssetLoadMetadata(e,"pending",0);try{const i=await w.Assets.load(t,s=>{this.updateAssetLoadMetadata(e,"loading",s)});return this.updateAssetLoadMetadata(e,"success",1),i}catch{return this.updateAssetLoadMetadata(e,"failed",1),null}}getProgress(){const e=Object.keys(this.loadTracker.registry);return e.reduce((i,s)=>i+this.loadTracker.registry[s].progress,0)/e.length}updateAssetLoadMetadata(e,t,i){this.loadTracker.registry[e]?(this.loadTracker.registry[e].progress=i,this.loadTracker.registry[e].status=t):this.loadTracker.registry[e]={progress:i,status:t};const s={...this.loadTracker.registry};this.loadTracker.emit("onAssetLoadInfoUpdated",{registry:s})}}class Oe{static Name="FontLoadParser";name;extension;validFontExtensions;woff2Decompressor;constructor(){this.name=Oe.Name,this.extension={type:[w.ExtensionType.LoadParser],priority:w.LoaderParserPriority.High,ref:null},this.validFontExtensions=["ttf","otf","woff","woff2"],this.woff2Decompressor=null}test(e){const t=e.split("?")[0]?.split(".").pop()?.toLowerCase()??"";return this.validFontExtensions.includes(t)}async load(e,t,i){const s=e.split("?")[0]?.split(".").pop()?.toLowerCase()??"",n=await fetch(e).then(p=>p.arrayBuffer());if(s!=="woff2"){const p=ut.parse(new Uint8Array(n).buffer),k=p.names.fontFamily.en||p.names.fontFamily[Object.keys(p.names.fontFamily)[0]],A=new FontFace(k,`url(${e})`);return await A.load(),document.fonts.add(A),A}if(await this.loadWoff2Decompressor(),!this.woff2Decompressor)throw new Error("Cannot initialize Woff2 decompressor.");const r=this.woff2Decompressor.decompress(n),o=ut.parse(new Uint8Array(r).buffer),h=o.names.fontFamily.en||o.names.fontFamily[Object.keys(o.names.fontFamily)[0]],c=new Blob([r],{type:"font/ttf"}),l=URL.createObjectURL(c),g=new FontFace(h,`url(${l})`);return await g.load(),document.fonts.add(g),g}async loadWoff2Decompressor(){if(this.woff2Decompressor)return;const t=`${await fetch("https://unpkg.com/wawoff2@2.0.1/build/decompress_binding.js").then(i=>i.text())}; return Module`;this.woff2Decompressor=new Function(t)(),await new Promise(i=>{this.woff2Decompressor.onRuntimeInitialized=i})}unload(e){e&&document.fonts.delete(e)}}var C;(function(a){a.assertEqual=s=>s;function e(s){}a.assertIs=e;function t(s){throw new Error}a.assertNever=t,a.arrayToEnum=s=>{const n={};for(const r of s)n[r]=r;return n},a.getValidEnumValues=s=>{const n=a.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),r={};for(const o of n)r[o]=s[o];return a.objectValues(r)},a.objectValues=s=>a.objectKeys(s).map(function(n){return s[n]}),a.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const n=[];for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&n.push(r);return n},a.find=(s,n)=>{for(const r of s)if(n(r))return r},a.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function i(s,n=" | "){return s.map(r=>typeof r=="string"?`'${r}'`:r).join(n)}a.joinValues=i,a.jsonStringifyReplacer=(s,n)=>typeof n=="bigint"?n.toString():n})(C||(C={}));var ft;(function(a){a.mergeShapes=(e,t)=>({...e,...t})})(ft||(ft={}));const f=C.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),G=a=>{switch(typeof a){case"undefined":return f.undefined;case"string":return f.string;case"number":return isNaN(a)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(a)?f.array:a===null?f.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?f.promise:typeof Map<"u"&&a instanceof Map?f.map:typeof Set<"u"&&a instanceof Set?f.set:typeof Date<"u"&&a instanceof Date?f.date:f.object;default:return f.unknown}},u=C.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class N extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(n){return n.message},i={_errors:[]},s=n=>{for(const r of n.issues)if(r.code==="invalid_union")r.unionErrors.map(s);else if(r.code==="invalid_return_type")s(r.returnTypeError);else if(r.code==="invalid_arguments")s(r.argumentsError);else if(r.path.length===0)i._errors.push(t(r));else{let o=i,h=0;for(;h<r.path.length;){const c=r.path[h];h===r.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(r))):o[c]=o[c]||{_errors:[]},o=o[c],h++}}};return s(this),i}static assert(e){if(!(e instanceof N))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,C.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},i=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):i.push(e(s));return{formErrors:i,fieldErrors:t}}get formErrors(){return this.flatten()}}N.create=a=>new N(a);const xe=(a,e)=>{let t;switch(a.code){case u.invalid_type:a.received===f.undefined?t="Required":t=`Expected ${a.expected}, received ${a.received}`;break;case u.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(a.expected,C.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:t=`Unrecognized key(s) in object: ${C.joinValues(a.keys,", ")}`;break;case u.invalid_union:t="Invalid input";break;case u.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${C.joinValues(a.options)}`;break;case u.invalid_enum_value:t=`Invalid enum value. Expected ${C.joinValues(a.options)}, received '${a.received}'`;break;case u.invalid_arguments:t="Invalid function arguments";break;case u.invalid_return_type:t="Invalid function return type";break;case u.invalid_date:t="Invalid date";break;case u.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(t=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?t=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?t=`Invalid input: must end with "${a.validation.endsWith}"`:C.assertNever(a.validation):a.validation!=="regex"?t=`Invalid ${a.validation}`:t="Invalid";break;case u.too_small:a.type==="array"?t=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?t=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?t=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?t=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:t="Invalid input";break;case u.too_big:a.type==="array"?t=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?t=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?t=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?t=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?t=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:t="Invalid input";break;case u.custom:t="Invalid input";break;case u.invalid_intersection_types:t="Intersection results could not be merged";break;case u.not_multiple_of:t=`Number must be a multiple of ${a.multipleOf}`;break;case u.not_finite:t="Number must be finite";break;default:t=e.defaultError,C.assertNever(a)}return{message:t}};let $t=xe;function Ue(){return $t}const We=a=>{const{data:e,path:t,errorMaps:i,issueData:s}=a,n=[...t,...s.path||[]],r={...s,path:n};if(s.message!==void 0)return{...s,path:n,message:s.message};let o="";const h=i.filter(c=>!!c).slice().reverse();for(const c of h)o=c(r,{data:e,defaultError:o}).message;return{...s,path:n,message:o}};function d(a,e){const t=Ue(),i=We({issueData:e,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,t,t===xe?void 0:xe].filter(s=>!!s)});a.common.issues.push(i)}class I{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const i=[];for(const s of t){if(s.status==="aborted")return x;s.status==="dirty"&&e.dirty(),i.push(s.value)}return{status:e.value,value:i}}static async mergeObjectAsync(e,t){const i=[];for(const s of t){const n=await s.key,r=await s.value;i.push({key:n,value:r})}return I.mergeObjectSync(e,i)}static mergeObjectSync(e,t){const i={};for(const s of t){const{key:n,value:r}=s;if(n.status==="aborted"||r.status==="aborted")return x;n.status==="dirty"&&e.dirty(),r.status==="dirty"&&e.dirty(),n.value!=="__proto__"&&(typeof r.value<"u"||s.alwaysSet)&&(i[n.value]=r.value)}return{status:e.value,value:i}}}const x=Object.freeze({status:"aborted"}),we=a=>({status:"dirty",value:a}),E=a=>({status:"valid",value:a}),pt=a=>a.status==="aborted",mt=a=>a.status==="dirty",he=a=>a.status==="valid",Ae=a=>typeof Promise<"u"&&a instanceof Promise;function Pe(a,e,t,i){if(typeof e=="function"?a!==e||!0:!e.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(a)}function gt(a,e,t,i,s){if(typeof e=="function"?a!==e||!0:!e.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(a,t),t}typeof SuppressedError=="function"&&SuppressedError;var m;(function(a){a.errToObj=e=>typeof e=="string"?{message:e}:e||{},a.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var _e,ke;class H{constructor(e,t,i,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=i,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const yt=(a,e)=>{if(he(e))return{success:!0,data:e.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new N(a.common.issues);return this._error=t,this._error}}};function _(a){if(!a)return{};const{errorMap:e,invalid_type_error:t,required_error:i,description:s}=a;if(e&&(t||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(r,o)=>{var h,c;const{message:l}=a;return r.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:(h=l??i)!==null&&h!==void 0?h:o.defaultError}:r.code!=="invalid_type"?{message:o.defaultError}:{message:(c=l??t)!==null&&c!==void 0?c:o.defaultError}},description:s}}class b{get description(){return this._def.description}_getType(e){return G(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:G(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new I,ctx:{common:e.parent.common,data:e.data,parsedType:G(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ae(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const i=this.safeParse(e,t);if(i.success)return i.data;throw i.error}safeParse(e,t){var i;const s={common:{issues:[],async:(i=t?.async)!==null&&i!==void 0?i:!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)},n=this._parseSync({data:e,path:s.path,parent:s});return yt(s,n)}"~validate"(e){var t,i;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:s});return he(n)?{value:n.value}:{issues:s.common.issues}}catch(n){!((i=(t=n?.message)===null||t===void 0?void 0:t.toLowerCase())===null||i===void 0)&&i.includes("encountered")&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then(n=>he(n)?{value:n.value}:{issues:s.common.issues})}async parseAsync(e,t){const i=await this.safeParseAsync(e,t);if(i.success)return i.data;throw i.error}async safeParseAsync(e,t){const i={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)},s=this._parse({data:e,path:i.path,parent:i}),n=await(Ae(s)?s:Promise.resolve(s));return yt(i,n)}refine(e,t){const i=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,n)=>{const r=e(s),o=()=>n.addIssue({code:u.custom,...i(s)});return typeof Promise<"u"&&r instanceof Promise?r.then(h=>h?!0:(o(),!1)):r?!0:(o(),!1)})}refinement(e,t){return this._refinement((i,s)=>e(i)?!0:(s.addIssue(typeof t=="function"?t(i,s):t),!1))}_refinement(e){return new U({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return W.create(this,this._def)}nullable(){return ie.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return B.create(this)}promise(){return Se.create(this,this._def)}or(e){return Ie.create([this,e],this._def)}and(e){return Le.create(this,e,this._def)}transform(e){return new U({..._(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new De({..._(this._def),innerType:this,defaultValue:t,typeName:v.ZodDefault})}brand(){return new _t({typeName:v.ZodBranded,type:this,..._(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Ze({..._(this._def),innerType:this,catchValue:t,typeName:v.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ke.create(this,e)}readonly(){return He.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ut=/^c[^\s-]{8,}$/i,Wt=/^[0-9a-z]+$/,Yt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Xt=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,qt=/^[a-z0-9_-]{21}$/i,Gt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Qt=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Jt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ei="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ye;const ti=/^(?:(?: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])$/,ii=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,si=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ni=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ai=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ri=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,vt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",oi=new RegExp(`^${vt}$`);function xt(a){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?e=`${e}\\.\\d{${a.precision}}`:a.precision==null&&(e=`${e}(\\.\\d+)?`),e}function ci(a){return new RegExp(`^${xt(a)}$`)}function li(a){let e=`${vt}T${xt(a)}`;const t=[];return t.push(a.local?"Z?":"Z"),a.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function hi(a,e){return!!((e==="v4"||!e)&&ti.test(a)||(e==="v6"||!e)&&si.test(a))}function ui(a,e){if(!Gt.test(a))return!1;try{const[t]=a.split("."),i=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(i));return!(typeof s!="object"||s===null||!s.typ||!s.alg||e&&s.alg!==e)}catch{return!1}}function di(a,e){return!!((e==="v4"||!e)&&ii.test(a)||(e==="v6"||!e)&&ni.test(a))}class j extends b{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.string,received:n.parsedType}),x}const i=new I;let s;for(const n of this._def.checks)if(n.kind==="min")e.data.length<n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),i.dirty());else if(n.kind==="max")e.data.length>n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),i.dirty());else if(n.kind==="length"){const r=e.data.length>n.value,o=e.data.length<n.value;(r||o)&&(s=this._getOrReturnCtx(e,s),r?d(s,{code:u.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}):o&&d(s,{code:u.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}),i.dirty())}else if(n.kind==="email")Jt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"email",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="emoji")Ye||(Ye=new RegExp(ei,"u")),Ye.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"emoji",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="uuid")Xt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"uuid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="nanoid")qt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"nanoid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="cuid")Ut.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="cuid2")Wt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid2",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="ulid")Yt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ulid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),d(s,{validation:"url",code:u.invalid_string,message:n.message}),i.dirty()}else n.kind==="regex"?(n.regex.lastIndex=0,n.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"regex",code:u.invalid_string,message:n.message}),i.dirty())):n.kind==="trim"?e.data=e.data.trim():n.kind==="includes"?e.data.includes(n.value,n.position)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{includes:n.value,position:n.position},message:n.message}),i.dirty()):n.kind==="toLowerCase"?e.data=e.data.toLowerCase():n.kind==="toUpperCase"?e.data=e.data.toUpperCase():n.kind==="startsWith"?e.data.startsWith(n.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{startsWith:n.value},message:n.message}),i.dirty()):n.kind==="endsWith"?e.data.endsWith(n.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{endsWith:n.value},message:n.message}),i.dirty()):n.kind==="datetime"?li(n).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"datetime",message:n.message}),i.dirty()):n.kind==="date"?oi.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"date",message:n.message}),i.dirty()):n.kind==="time"?ci(n).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"time",message:n.message}),i.dirty()):n.kind==="duration"?Qt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"duration",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="ip"?hi(e.data,n.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ip",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="jwt"?ui(e.data,n.alg)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"jwt",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="cidr"?di(e.data,n.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cidr",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="base64"?ai.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="base64url"?ri.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64url",code:u.invalid_string,message:n.message}),i.dirty()):C.assertNever(n);return{status:i.value,value:e.data}}_regex(e,t,i){return this.refinement(s=>e.test(s),{validation:t,code:u.invalid_string,...m.errToObj(i)})}_addCheck(e){return new j({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){var t,i;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:(t=e?.offset)!==null&&t!==void 0?t:!1,local:(i=e?.local)!==null&&i!==void 0?i:!1,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...m.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...m.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...m.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...m.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...m.errToObj(t)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new j({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}j.create=a=>{var e;return new j({checks:[],typeName:v.ZodString,coerce:(e=a?.coerce)!==null&&e!==void 0?e:!1,..._(a)})};function fi(a,e){const t=(a.toString().split(".")[1]||"").length,i=(e.toString().split(".")[1]||"").length,s=t>i?t:i,n=parseInt(a.toFixed(s).replace(".","")),r=parseInt(e.toFixed(s).replace(".",""));return n%r/Math.pow(10,s)}class ue extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.number,received:n.parsedType}),x}let i;const s=new I;for(const n of this._def.checks)n.kind==="int"?C.isInteger(e.data)||(i=this._getOrReturnCtx(e,i),d(i,{code:u.invalid_type,expected:"integer",received:"float",message:n.message}),s.dirty()):n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),s.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),s.dirty()):n.kind==="multipleOf"?fi(e.data,n.value)!==0&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_multiple_of,multipleOf:n.value,message:n.message}),s.dirty()):n.kind==="finite"?Number.isFinite(e.data)||(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_finite,message:n.message}),s.dirty()):C.assertNever(n);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,i,s){return new ue({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:m.toString(s)}]})}_addCheck(e){return new ue({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&C.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(t===null||i.value>t)&&(t=i.value):i.kind==="max"&&(e===null||i.value<e)&&(e=i.value)}return Number.isFinite(t)&&Number.isFinite(e)}}ue.create=a=>new ue({checks:[],typeName:v.ZodNumber,coerce:a?.coerce||!1,..._(a)});class de extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let i;const s=new I;for(const n of this._def.checks)n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),s.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),s.dirty()):n.kind==="multipleOf"?e.data%n.value!==BigInt(0)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_multiple_of,multipleOf:n.value,message:n.message}),s.dirty()):C.assertNever(n);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return d(t,{code:u.invalid_type,expected:f.bigint,received:t.parsedType}),x}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,i,s){return new de({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:m.toString(s)}]})}_addCheck(e){return new de({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}de.create=a=>{var e;return new de({checks:[],typeName:v.ZodBigInt,coerce:(e=a?.coerce)!==null&&e!==void 0?e:!1,..._(a)})};class Xe extends b{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.boolean,received:i.parsedType}),x}return E(e.data)}}Xe.create=a=>new Xe({typeName:v.ZodBoolean,coerce:a?.coerce||!1,..._(a)});class be extends b{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.date,received:n.parsedType}),x}if(isNaN(e.data.getTime())){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_date}),x}const i=new I;let s;for(const n of this._def.checks)n.kind==="min"?e.data.getTime()<n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),i.dirty()):n.kind==="max"?e.data.getTime()>n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),i.dirty()):C.assertNever(n);return{status:i.value,value:new Date(e.data.getTime())}}_addCheck(e){return new be({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}be.create=a=>new be({checks:[],coerce:a?.coerce||!1,typeName:v.ZodDate,..._(a)});class qe extends b{_parse(e){if(this._getType(e)!==f.symbol){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.symbol,received:i.parsedType}),x}return E(e.data)}}qe.create=a=>new qe({typeName:v.ZodSymbol,..._(a)});class Re extends b{_parse(e){if(this._getType(e)!==f.undefined){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.undefined,received:i.parsedType}),x}return E(e.data)}}Re.create=a=>new Re({typeName:v.ZodUndefined,..._(a)});class ze extends b{_parse(e){if(this._getType(e)!==f.null){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.null,received:i.parsedType}),x}return E(e.data)}}ze.create=a=>new ze({typeName:v.ZodNull,..._(a)});class Ge extends b{constructor(){super(...arguments),this._any=!0}_parse(e){return E(e.data)}}Ge.create=a=>new Ge({typeName:v.ZodAny,..._(a)});class fe extends b{constructor(){super(...arguments),this._unknown=!0}_parse(e){return E(e.data)}}fe.create=a=>new fe({typeName:v.ZodUnknown,..._(a)});class Q extends b{_parse(e){const t=this._getOrReturnCtx(e);return d(t,{code:u.invalid_type,expected:f.never,received:t.parsedType}),x}}Q.create=a=>new Q({typeName:v.ZodNever,..._(a)});class Qe extends b{_parse(e){if(this._getType(e)!==f.undefined){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.void,received:i.parsedType}),x}return E(e.data)}}Qe.create=a=>new Qe({typeName:v.ZodVoid,..._(a)});class B extends b{_parse(e){const{ctx:t,status:i}=this._processInputParams(e),s=this._def;if(t.parsedType!==f.array)return d(t,{code:u.invalid_type,expected:f.array,received:t.parsedType}),x;if(s.exactLength!==null){const r=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(r||o)&&(d(t,{code:r?u.too_big:u.too_small,minimum:o?s.exactLength.value:void 0,maximum:r?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),i.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(d(t,{code:u.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),i.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(d(t,{code:u.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),i.dirty()),t.common.async)return Promise.all([...t.data].map((r,o)=>s.type._parseAsync(new H(t,r,t.path,o)))).then(r=>I.mergeArray(i,r));const n=[...t.data].map((r,o)=>s.type._parseSync(new H(t,r,t.path,o)));return I.mergeArray(i,n)}get element(){return this._def.type}min(e,t){return new B({...this._def,minLength:{value:e,message:m.toString(t)}})}max(e,t){return new B({...this._def,maxLength:{value:e,message:m.toString(t)}})}length(e,t){return new B({...this._def,exactLength:{value:e,message:m.toString(t)}})}nonempty(e){return this.min(1,e)}}B.create=(a,e)=>new B({type:a,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,..._(e)});function pe(a){if(a instanceof P){const e={};for(const t in a.shape){const i=a.shape[t];e[t]=W.create(pe(i))}return new P({...a._def,shape:()=>e})}else return a instanceof B?new B({...a._def,type:pe(a.element)}):a instanceof W?W.create(pe(a.unwrap())):a instanceof ie?ie.create(pe(a.unwrap())):a instanceof $?$.create(a.items.map(e=>pe(e))):a}class P extends b{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=C.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==f.object){const c=this._getOrReturnCtx(e);return d(c,{code:u.invalid_type,expected:f.object,received:c.parsedType}),x}const{status:i,ctx:s}=this._processInputParams(e),{shape:n,keys:r}=this._getCached(),o=[];if(!(this._def.catchall instanceof Q&&this._def.unknownKeys==="strip"))for(const c in s.data)r.includes(c)||o.push(c);const h=[];for(const c of r){const l=n[c],g=s.data[c];h.push({key:{status:"valid",value:c},value:l._parse(new H(s,g,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof Q){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of o)h.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(c==="strict")o.length>0&&(d(s,{code:u.unrecognized_keys,keys:o}),i.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of o){const g=s.data[l];h.push({key:{status:"valid",value:l},value:c._parse(new H(s,g,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of h){const g=await l.key,p=await l.value;c.push({key:g,value:p,alwaysSet:l.alwaysSet})}return c}).then(c=>I.mergeObjectSync(i,c)):I.mergeObjectSync(i,h)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new P({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,i)=>{var s,n,r,o;const h=(r=(n=(s=this._def).errorMap)===null||n===void 0?void 0:n.call(s,t,i).message)!==null&&r!==void 0?r:i.defaultError;return t.code==="unrecognized_keys"?{message:(o=m.errToObj(e).message)!==null&&o!==void 0?o:h}:{message:h}}}:{}})}strip(){return new P({...this._def,unknownKeys:"strip"})}passthrough(){return new P({...this._def,unknownKeys:"passthrough"})}extend(e){return new P({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new P({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new P({...this._def,catchall:e})}pick(e){const t={};return C.objectKeys(e).forEach(i=>{e[i]&&this.shape[i]&&(t[i]=this.shape[i])}),new P({...this._def,shape:()=>t})}omit(e){const t={};return C.objectKeys(this.shape).forEach(i=>{e[i]||(t[i]=this.shape[i])}),new P({...this._def,shape:()=>t})}deepPartial(){return pe(this)}partial(e){const t={};return C.objectKeys(this.shape).forEach(i=>{const s=this.shape[i];e&&!e[i]?t[i]=s:t[i]=s.optional()}),new P({...this._def,shape:()=>t})}required(e){const t={};return C.objectKeys(this.shape).forEach(i=>{if(e&&!e[i])t[i]=this.shape[i];else{let n=this.shape[i];for(;n instanceof W;)n=n._def.innerType;t[i]=n}}),new P({...this._def,shape:()=>t})}keyof(){return wt(C.objectKeys(this.shape))}}P.create=(a,e)=>new P({shape:()=>a,unknownKeys:"strip",catchall:Q.create(),typeName:v.ZodObject,..._(e)}),P.strictCreate=(a,e)=>new P({shape:()=>a,unknownKeys:"strict",catchall:Q.create(),typeName:v.ZodObject,..._(e)}),P.lazycreate=(a,e)=>new P({shape:a,unknownKeys:"strip",catchall:Q.create(),typeName:v.ZodObject,..._(e)});class Ie extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i=this._def.options;function s(n){for(const o of n)if(o.result.status==="valid")return o.result;for(const o of n)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const r=n.map(o=>new N(o.ctx.common.issues));return d(t,{code:u.invalid_union,unionErrors:r}),x}if(t.common.async)return Promise.all(i.map(async n=>{const r={...t,common:{...t.common,issues:[]},parent:null};return{result:await n._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(s);{let n;const r=[];for(const h of i){const c={...t,common:{...t.common,issues:[]},parent:null},l=h._parseSync({data:t.data,path:t.path,parent:c});if(l.status==="valid")return l;l.status==="dirty"&&!n&&(n={result:l,ctx:c}),c.common.issues.length&&r.push(c.common.issues)}if(n)return t.common.issues.push(...n.ctx.common.issues),n.result;const o=r.map(h=>new N(h));return d(t,{code:u.invalid_union,unionErrors:o}),x}}get options(){return this._def.options}}Ie.create=(a,e)=>new Ie({options:a,typeName:v.ZodUnion,..._(e)});const V=a=>a instanceof Me?V(a.schema):a instanceof U?V(a.innerType()):a instanceof Fe?[a.value]:a instanceof te?a.options:a instanceof Ne?C.objectValues(a.enum):a instanceof De?V(a._def.innerType):a instanceof Re?[void 0]:a instanceof ze?[null]:a instanceof W?[void 0,...V(a.unwrap())]:a instanceof ie?[null,...V(a.unwrap())]:a instanceof _t||a instanceof He?V(a.unwrap()):a instanceof Ze?V(a._def.innerType):[];class Je extends b{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.object)return d(t,{code:u.invalid_type,expected:f.object,received:t.parsedType}),x;const i=this.discriminator,s=t.data[i],n=this.optionsMap.get(s);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(d(t,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[i]}),x)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,i){const s=new Map;for(const n of t){const r=V(n.shape[e]);if(!r.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of r){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,n)}}return new Je({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,..._(i)})}}function et(a,e){const t=G(a),i=G(e);if(a===e)return{valid:!0,data:a};if(t===f.object&&i===f.object){const s=C.objectKeys(e),n=C.objectKeys(a).filter(o=>s.indexOf(o)!==-1),r={...a,...e};for(const o of n){const h=et(a[o],e[o]);if(!h.valid)return{valid:!1};r[o]=h.data}return{valid:!0,data:r}}else if(t===f.array&&i===f.array){if(a.length!==e.length)return{valid:!1};const s=[];for(let n=0;n<a.length;n++){const r=a[n],o=e[n],h=et(r,o);if(!h.valid)return{valid:!1};s.push(h.data)}return{valid:!0,data:s}}else return t===f.date&&i===f.date&&+a==+e?{valid:!0,data:a}:{valid:!1}}class Le extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e),s=(n,r)=>{if(pt(n)||pt(r))return x;const o=et(n.value,r.value);return o.valid?((mt(n)||mt(r))&&t.dirty(),{status:t.value,value:o.data}):(d(i,{code:u.invalid_intersection_types}),x)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([n,r])=>s(n,r)):s(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}Le.create=(a,e,t)=>new Le({left:a,right:e,typeName:v.ZodIntersection,..._(t)});class $ extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.array)return d(i,{code:u.invalid_type,expected:f.array,received:i.parsedType}),x;if(i.data.length<this._def.items.length)return d(i,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),x;!this._def.rest&&i.data.length>this._def.items.length&&(d(i,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const n=[...i.data].map((r,o)=>{const h=this._def.items[o]||this._def.rest;return h?h._parse(new H(i,r,i.path,o)):null}).filter(r=>!!r);return i.common.async?Promise.all(n).then(r=>I.mergeArray(t,r)):I.mergeArray(t,n)}get items(){return this._def.items}rest(e){return new $({...this._def,rest:e})}}$.create=(a,e)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new $({items:a,typeName:v.ZodTuple,rest:null,..._(e)})};class Ee extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.object)return d(i,{code:u.invalid_type,expected:f.object,received:i.parsedType}),x;const s=[],n=this._def.keyType,r=this._def.valueType;for(const o in i.data)s.push({key:n._parse(new H(i,o,i.path,o)),value:r._parse(new H(i,i.data[o],i.path,o)),alwaysSet:o in i.data});return i.common.async?I.mergeObjectAsync(t,s):I.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,i){return t instanceof b?new Ee({keyType:e,valueType:t,typeName:v.ZodRecord,..._(i)}):new Ee({keyType:j.create(),valueType:e,typeName:v.ZodRecord,..._(t)})}}class tt extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.map)return d(i,{code:u.invalid_type,expected:f.map,received:i.parsedType}),x;const s=this._def.keyType,n=this._def.valueType,r=[...i.data.entries()].map(([o,h],c)=>({key:s._parse(new H(i,o,i.path,[c,"key"])),value:n._parse(new H(i,h,i.path,[c,"value"]))}));if(i.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const h of r){const c=await h.key,l=await h.value;if(c.status==="aborted"||l.status==="aborted")return x;(c.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(c.value,l.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const h of r){const c=h.key,l=h.value;if(c.status==="aborted"||l.status==="aborted")return x;(c.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(c.value,l.value)}return{status:t.value,value:o}}}}tt.create=(a,e,t)=>new tt({valueType:e,keyType:a,typeName:v.ZodMap,..._(t)});class me extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.set)return d(i,{code:u.invalid_type,expected:f.set,received:i.parsedType}),x;const s=this._def;s.minSize!==null&&i.data.size<s.minSize.value&&(d(i,{code:u.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&i.data.size>s.maxSize.value&&(d(i,{code:u.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const n=this._def.valueType;function r(h){const c=new Set;for(const l of h){if(l.status==="aborted")return x;l.status==="dirty"&&t.dirty(),c.add(l.value)}return{status:t.value,value:c}}const o=[...i.data.values()].map((h,c)=>n._parse(new H(i,h,i.path,c)));return i.common.async?Promise.all(o).then(h=>r(h)):r(o)}min(e,t){return new me({...this._def,minSize:{value:e,message:m.toString(t)}})}max(e,t){return new me({...this._def,maxSize:{value:e,message:m.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}me.create=(a,e)=>new me({valueType:a,minSize:null,maxSize:null,typeName:v.ZodSet,..._(e)});class Ce extends b{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.function)return d(t,{code:u.invalid_type,expected:f.function,received:t.parsedType}),x;function i(o,h){return We({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Ue(),xe].filter(c=>!!c),issueData:{code:u.invalid_arguments,argumentsError:h}})}function s(o,h){return We({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Ue(),xe].filter(c=>!!c),issueData:{code:u.invalid_return_type,returnTypeError:h}})}const n={errorMap:t.common.contextualErrorMap},r=t.data;if(this._def.returns instanceof Se){const o=this;return E(async function(...h){const c=new N([]),l=await o._def.args.parseAsync(h,n).catch(k=>{throw c.addIssue(i(h,k)),c}),g=await Reflect.apply(r,this,l);return await o._def.returns._def.type.parseAsync(g,n).catch(k=>{throw c.addIssue(s(g,k)),c})})}else{const o=this;return E(function(...h){const c=o._def.args.safeParse(h,n);if(!c.success)throw new N([i(h,c.error)]);const l=Reflect.apply(r,this,c.data),g=o._def.returns.safeParse(l,n);if(!g.success)throw new N([s(l,g.error)]);return g.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Ce({...this._def,args:$.create(e).rest(fe.create())})}returns(e){return new Ce({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,i){return new Ce({args:e||$.create([]).rest(fe.create()),returns:t||fe.create(),typeName:v.ZodFunction,..._(i)})}}class Me extends b{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Me.create=(a,e)=>new Me({getter:a,typeName:v.ZodLazy,..._(e)});class Fe extends b{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return d(t,{received:t.data,code:u.invalid_literal,expected:this._def.value}),x}return{status:"valid",value:e.data}}get value(){return this._def.value}}Fe.create=(a,e)=>new Fe({value:a,typeName:v.ZodLiteral,..._(e)});function wt(a,e){return new te({values:a,typeName:v.ZodEnum,..._(e)})}class te extends b{constructor(){super(...arguments),_e.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),i=this._def.values;return d(t,{expected:C.joinValues(i),received:t.parsedType,code:u.invalid_type}),x}if(Pe(this,_e)||gt(this,_e,new Set(this._def.values)),!Pe(this,_e).has(e.data)){const t=this._getOrReturnCtx(e),i=this._def.values;return d(t,{received:t.data,code:u.invalid_enum_value,options:i}),x}return E(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return te.create(e,{...this._def,...t})}exclude(e,t=this._def){return te.create(this.options.filter(i=>!e.includes(i)),{...this._def,...t})}}_e=new WeakMap,te.create=wt;class Ne extends b{constructor(){super(...arguments),ke.set(this,void 0)}_parse(e){const t=C.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(e);if(i.parsedType!==f.string&&i.parsedType!==f.number){const s=C.objectValues(t);return d(i,{expected:C.joinValues(s),received:i.parsedType,code:u.invalid_type}),x}if(Pe(this,ke)||gt(this,ke,new Set(C.getValidEnumValues(this._def.values))),!Pe(this,ke).has(e.data)){const s=C.objectValues(t);return d(i,{received:i.data,code:u.invalid_enum_value,options:s}),x}return E(e.data)}get enum(){return this._def.values}}ke=new WeakMap,Ne.create=(a,e)=>new Ne({values:a,typeName:v.ZodNativeEnum,..._(e)});class Se extends b{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.promise&&t.common.async===!1)return d(t,{code:u.invalid_type,expected:f.promise,received:t.parsedType}),x;const i=t.parsedType===f.promise?t.data:Promise.resolve(t.data);return E(i.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Se.create=(a,e)=>new Se({type:a,typeName:v.ZodPromise,..._(e)});class U extends b{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:i}=this._processInputParams(e),s=this._def.effect||null,n={addIssue:r=>{d(i,r),r.fatal?t.abort():t.dirty()},get path(){return i.path}};if(n.addIssue=n.addIssue.bind(n),s.type==="preprocess"){const r=s.transform(i.data,n);if(i.common.async)return Promise.resolve(r).then(async o=>{if(t.value==="aborted")return x;const h=await this._def.schema._parseAsync({data:o,path:i.path,parent:i});return h.status==="aborted"?x:h.status==="dirty"||t.value==="dirty"?we(h.value):h});{if(t.value==="aborted")return x;const o=this._def.schema._parseSync({data:r,path:i.path,parent:i});return o.status==="aborted"?x:o.status==="dirty"||t.value==="dirty"?we(o.value):o}}if(s.type==="refinement"){const r=o=>{const h=s.refinement(o,n);if(i.common.async)return Promise.resolve(h);if(h instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(i.common.async===!1){const o=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return o.status==="aborted"?x:(o.status==="dirty"&&t.dirty(),r(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(o=>o.status==="aborted"?x:(o.status==="dirty"&&t.dirty(),r(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(i.common.async===!1){const r=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!he(r))return r;const o=s.transform(r.value,n);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(r=>he(r)?Promise.resolve(s.transform(r.value,n)).then(o=>({status:t.value,value:o})):r);C.assertNever(s)}}U.create=(a,e,t)=>new U({schema:a,typeName:v.ZodEffects,effect:e,..._(t)}),U.createWithPreprocess=(a,e,t)=>new U({schema:e,effect:{type:"preprocess",transform:a},typeName:v.ZodEffects,..._(t)});class W extends b{_parse(e){return this._getType(e)===f.undefined?E(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}W.create=(a,e)=>new W({innerType:a,typeName:v.ZodOptional,..._(e)});class ie extends b{_parse(e){return this._getType(e)===f.null?E(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ie.create=(a,e)=>new ie({innerType:a,typeName:v.ZodNullable,..._(e)});class De extends b{_parse(e){const{ctx:t}=this._processInputParams(e);let i=t.data;return t.parsedType===f.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}De.create=(a,e)=>new De({innerType:a,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class Ze extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return Ae(s)?s.then(n=>({status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new N(i.common.issues)},input:i.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new N(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}Ze.create=(a,e)=>new Ze({innerType:a,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class it extends b{_parse(e){if(this._getType(e)!==f.nan){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.nan,received:i.parsedType}),x}return{status:"valid",value:e.data}}}it.create=a=>new it({typeName:v.ZodNaN,..._(a)});class _t extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i=t.data;return this._def.type._parse({data:i,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ke extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.common.async)return(async()=>{const n=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return n.status==="aborted"?x:n.status==="dirty"?(t.dirty(),we(n.value)):this._def.out._parseAsync({data:n.value,path:i.path,parent:i})})();{const s=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?x:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:i.path,parent:i})}}static create(e,t){return new Ke({in:e,out:t,typeName:v.ZodPipeline})}}class He extends b{_parse(e){const t=this._def.innerType._parse(e),i=s=>(he(s)&&(s.value=Object.freeze(s.value)),s);return Ae(t)?t.then(s=>i(s)):i(t)}unwrap(){return this._def.innerType}}He.create=(a,e)=>new He({innerType:a,typeName:v.ZodReadonly,..._(e)}),P.lazycreate;var v;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(v||(v={}));const L=j.create,y=ue.create;it.create,de.create,Xe.create,be.create,qe.create,Re.create,ze.create,Ge.create,fe.create,Q.create,Qe.create,B.create;const T=P.create;P.strictCreate;const pi=Ie.create;Je.create,Le.create,$.create,Ee.create,tt.create,me.create,Ce.create,Me.create;const se=Fe.create,J=te.create;Ne.create,Se.create,U.create,W.create,ie.create,U.createWithPreprocess,Ke.create;const mi=J(["linear","bezier","constant"]),gi=J(["ease","easeIn","easeOut","easeInOut","easeInQuad","easeInCubic","easeInQuart","easeInQuint","easeInSine","easeInExpo","easeInCirc","easeInBack","easeOutQuad","easeOutCubic","easeOutQuart","easeOutQuint","easeOutSine","easeOutExpo","easeOutCirc","easeOutBack","easeInOutQuad","easeInOutCubic","easeInOutQuart","easeInOutQuint","easeInOutSine","easeInOutExpo","easeInOutCirc","easeInOutBack"]),ne=T({from:y(),to:y(),start:y().min(0),length:y().positive(),interpolation:mi.optional(),easing:gi.optional()}),yi=L().url("Invalid audio url format."),vi=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),kt=T({type:se("audio"),src:yi,trim:y().optional(),volume:vi.optional()}),xi=J(["top","topRight","right","bottomRight","bottom","bottomLeft","left","topLeft","center"]),bt=T({type:se("html"),html:L(),css:L(),width:y().positive().optional(),height:y().positive().optional(),position:xi.optional()}),wi=L().url("Invalid image url format."),_i=T({top:y().min(0).optional(),right:y().min(0).optional(),bottom:y().min(0).optional(),left:y().min(0).optional()}),Ct=T({type:se("image"),src:wi,crop:_i.optional()}),ki=L().url("Invalid luma url format."),St=T({type:se("luma"),src:ki}),Tt=L().regex(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|transparent$/,"Invalid color format."),Ot=T({width:y().positive(),height:y().positive()}),At=T({radius:y().positive()}),Pt=T({length:y().positive(),thickness:y().positive()}),bi=T({color:Tt,opacity:y().min(0).max(1)}),Ci=T({color:Tt,width:y().positive()}),Rt=T({type:se("shape"),width:y().positive().optional(),height:y().positive().optional(),shape:J(["rectangle","circle","line"]),fill:bi.optional(),stroke:Ci.optional(),rectangle:Ot.optional(),circle:At.optional(),line:Pt.optional()}).refine(a=>a.shape==="rectangle"?Ot.safeParse(a.rectangle):a.shape==="circle"?At.safeParse(a.circle):a.shape==="line"?Pt.safeParse(a.line):!1),st=L().regex(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|transparent$/,"Invalid color format."),Si=T({color:st.optional(),family:L().optional(),size:y().positive().optional(),weight:y().optional(),lineHeight:y().optional()}),Ti=T({horizontal:J(["left","center","right"]).optional(),vertical:J(["top","center","bottom"]).optional()}),Oi=T({color:st,opacity:y().min(0).max(1)}),Ai=T({width:y().positive(),color:st}),zt=T({type:se("text"),text:L(),width:y().positive().optional(),height:y().positive().optional(),font:Si.optional(),alignment:Ti.optional(),background:Oi.optional(),stroke:Ai.optional()}),Pi=L().url("Invalid video url format."),Ri=T({top:y().min(0).optional(),right:y().min(0).optional(),bottom:y().min(0).optional(),left:y().min(0).optional()}),zi=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),It=T({type:se("video"),src:Pi,trim:y().optional(),crop:Ri.optional(),volume:zi.optional()}),Ii=pi([zt,Rt,bt,Ct,It,St,kt]).refine(a=>a.type==="text"?zt.safeParse(a):a.type==="shape"?Rt.safeParse(a):a.type==="html"?bt.safeParse(a):a.type==="image"?Ct.safeParse(a):a.type==="video"?It.safeParse(a):a.type==="luma"?St.safeParse(a):a.type==="audio"?kt.safeParse(a):!1),Li=J(["topLeft","top","topRight","left","center","right","bottomLeft","bottom","bottomRight"]),Ei=J(["crop","cover","contain","none"]),ge=y().min(-10).max(10).default(0),Mi=ne.extend({from:ge,to:ge}).array().or(ge),Fi=ne.extend({from:ge,to:ge}).array().or(ge),Ni=T({x:Mi.default(0),y:Fi.default(0)}),Di=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),Zi=ne.extend({from:y().min(0),to:y().min(0)}).array().or(y().min(0)),Ki=T({angle:ne.extend({from:y(),to:y()}).array().or(y())}),Hi=L(),Lt=L(),Bi=T({in:Lt.optional(),out:Lt.optional()}),ji=T({rotate:Ki.default({angle:0})}),Et=T({asset:Ii,start:y().min(0),length:y().positive(),position:Li.default("center").optional(),fit:Ei.default("crop").optional(),offset:Ni.default({x:0,y:0}).optional(),opacity:Di.default(1).optional(),scale:Zi.default(1).optional(),transform:ji.default({rotate:{angle:0}}).optional(),effect:Hi.optional(),transition:Bi.optional()}),Vi=T({clips:Et.array()}),$i=L().url("Invalid image url format."),Ui=T({src:$i}),Wi=T({background:L().optional(),fonts:Ui.array().optional(),tracks:Vi.array()}),Yi=T({size:T({width:y().positive(),height:y().positive()}),fps:y().positive().optional(),format:L()}),Xi=T({timeline:Wi,output:Yi});class qi{curves={};constructor(){this.initializeCurves()}initializeCurves(){this.curves={ease:[[.25,.1],[.25,1]],easeIn:[[.42,0],[1,1]],easeOut:[[0,0],[.58,1]],easeInOut:[[.42,0],[.58,1]],easeInQuad:[[.55,.085],[.68,.53]],easeInCubic:[[.55,.055],[.675,.19]],easeInQuart:[[.895,.03],[.685,.22]],easeInQuint:[[.755,.05],[.855,.06]],easeInSine:[[.47,0],[.745,.715]],easeInExpo:[[.95,.05],[.795,.035]],easeInCirc:[[.6,.04],[.98,.335]],easeInBack:[[.6,-.28],[.735,.045]],easeOutQuad:[[.25,.46],[.45,.94]],easeOutCubic:[[.215,.61],[.355,1]],easeOutQuart:[[.165,.84],[.44,1]],easeOutQuint:[[.23,1],[.32,1]],easeOutSine:[[.39,.575],[.565,1]],easeOutExpo:[[.19,1],[.22,1]],easeOutCirc:[[.075,.82],[.165,1]],easeOutBack:[[.175,.885],[.32,1.275]],easeInOutQuad:[[.455,.03],[.515,.955]],easeInOutCubic:[[.645,.045],[.355,1]],easeInOutQuart:[[.77,0],[.175,1]],easeInOutQuint:[[.86,0],[.07,1]],easeInOutSine:[[.445,.05],[.55,.95]],easeInOutExpo:[[1,0],[0,1]],easeInOutCirc:[[.785,.135],[.15,.86]],easeInOutBack:[[.68,-.55],[.265,1.55]]}}getValue(e,t,i,s){const n=this.curves[s??""]??this.curves.ease,[[r,o],[h,c]]=n,l=i+(3*r-3*h+1)*i*(1-i),g=e,p=e+(t-e)*o,k=e+(t-e)*c,A=t,S=l,D=1-S;return D**3*g+3*D**2*S*p+3*D*S**2*k+S**3*A}}class R{property;length;cubicBuilder;constructor(e,t,i=0){this.property=this.createKeyframes(e,t,i),this.length=t,this.cubicBuilder=new qi}getValue(e){const t=this.property.find(s=>e>=s.start&&e<s.start+s.length);if(!t){if(this.property.length>0){if(e>=this.length)return this.property[this.property.length-1].to;if(e<0)return this.property[0].from}return 1}const i=(e-t.start)/t.length;switch(t.interpolation){case"bezier":return this.cubicBuilder.getValue(t.from,t.to,i,t.easing);case"constant":return t.from;case"linear":default:return t.from+(t.to-t.from)*i}}createKeyframes(e,t,i=0){if(typeof e=="number")return[{start:0,length:t,from:e,to:e}];if(!e.length)throw new Error("Keyframes should have at least one value.");const s=this.createNormalizedKeyframes(e);try{this.validateKeyframes(s)}catch(n){console.warn("Keyframe configuration issues detected:",n)}return this.insertFillerKeyframes(s,t,i)}createNormalizedKeyframes(e){return e.toSorted((t,i)=>t.start-i.start).map(t=>({...t,start:t.start*1e3,length:t.length*1e3}))}validateKeyframes(e){for(let t=0;t<e.length;t+=1){const i=e[t],s=e[t+1];if(!s){if(i.start+i.length>this.length)throw new Error("Last keyframe exceeds the maximum duration.");break}if(i.start+i.length>s.start)throw new Error("Overlapping keyframes detected.")}}insertFillerKeyframes(e,t,i=0){const s=[];for(let n=0;n<e.length;n+=1){const r=e[n],o=e[n+1];if(n===0&&r.start!==0){const l={start:0,length:r.start,from:i,to:r.from};s.push(l)}if(s.push(r),!o){if(r.start+r.length<t){const g=r.start+r.length,p={start:g,length:t-g,from:r.to,to:r.to};s.push(p)}break}if(r.start+r.length!==o.start){const l={start:r.start+r.length,length:o.start,from:r.to,to:o.from};s.push(l)}}return s}}class Be{static Name="AudioLoadParser";name;extension;validAudioExtensions;constructor(){this.name=Be.Name,this.extension={type:[w.ExtensionType.LoadParser],priority:w.LoaderParserPriority.Normal,ref:null},this.validAudioExtensions=["mp3","mpeg","ogg","wav"]}test(e){const t=e.split("?")[0]?.split(".").pop()??"";return this.validAudioExtensions.includes(t)}async load(e,t,i){return new Promise(s=>{const n={src:e},r=new Howl(n);r.on("load",()=>s(r)),r.on("loaderror",()=>s(null))})}unload(e){e?.unload()}}class Gi{clipConfiguration;constructor(e){this.clipConfiguration=e}build(e,t){const i=[],s=[],n=[],r=[],o=[],{effect:h,length:c}=this.clipConfiguration;if(!h)return{offsetXKeyframes:i,offsetYKeyframes:s,opacityKeyframes:n,scaleKeyframes:r,rotationKeyframes:o};const l=0;switch(this.getPresetName()){case"zoomIn":{const p=this.getZoomSpeed(),k=1*this.clipConfiguration.scale,A=p*this.clipConfiguration.scale;r.push({from:k,to:A,start:l,length:c,interpolation:"linear"});break}case"zoomOut":{const k=this.getZoomSpeed()*this.clipConfiguration.scale,A=1*this.clipConfiguration.scale;r.push({from:k,to:A,start:l,length:c,interpolation:"linear"});break}case"slideLeft":{let p=this.getSlideStart();const k=e.width+e.width*p*2,A=t.height/t.width*e.height;if(A<k){const S=Math.abs(k/e.width);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.width)/2/e.width;i.push({from:p,to:-p,start:l,length:c});break}case"slideRight":{let p=this.getSlideStart();const k=e.width+e.width*p*2,A=t.height/t.width*e.height;if(A<k){const S=Math.abs(k/e.width);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.width)/2/e.width;i.push({from:-p,to:p,start:l,length:c});break}case"slideUp":{let p=this.getSlideStart();const k=e.height+e.height*p*2,A=t.height/t.width*e.width;if(A<k){const S=Math.abs(k/e.height);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.height)/2/e.height;s.push({from:p,to:-p,start:l,length:c});break}case"slideDown":{let p=this.getSlideStart();const k=e.height+e.height*p*2,A=t.height/t.width*e.width;if(A<k){const S=Math.abs(k/e.height);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.height)/2/e.height;s.push({from:-p,to:p,start:l,length:c});break}}return{offsetXKeyframes:i,offsetYKeyframes:s,opacityKeyframes:n,scaleKeyframes:r,rotationKeyframes:o}}getPresetName(){const[e]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);return e}getZoomSpeed(){const[e,t]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);if(e.startsWith("zoom"))switch(t){case"Slow":return 1.1;case"Fast":return 1.7;default:return 1.3}return 0}getSlideStart(){const[e,t]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);if(e.startsWith("slide"))switch(t){case"Slow":return .03;case"Fast":return 1.7;default:return .12}return 0}}class Qi{clipConfiguration;constructor(e){this.clipConfiguration=e}build(){const e=[],t=[],i=[],s=[],n=[],r=this.buildInPreset();e.push(...r.offsetXKeyframes),t.push(...r.offsetYKeyframes),i.push(...r.opacityKeyframes),s.push(...r.scaleKeyframes),n.push(...r.rotationKeyframes);const o=this.buildOutPreset();return e.push(...o.offsetXKeyframes),t.push(...o.offsetYKeyframes),i.push(...o.opacityKeyframes),s.push(...o.scaleKeyframes),n.push(...o.rotationKeyframes),{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}buildInPreset(){const e=[],t=[],i=[],s=[],n=[];if(!this.clipConfiguration.transition?.in)return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n};const r=0,o=this.getInPresetLength();switch(this.getInPresetName()){case"fade":{const l=Math.max(0,Math.min(this.clipConfiguration.opacity??1,1));i.push({from:0,to:l,start:r,length:o,interpolation:"linear"});break}case"zoom":{const l=this.clipConfiguration.scale+9,g=this.clipConfiguration.scale;s.push({from:l,to:g,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideLeft":{const c=this.clipConfiguration.offset?.x+.025,l=this.clipConfiguration.offset?.x;e.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideRight":{const c=this.clipConfiguration.offset?.x-.025,l=this.clipConfiguration.offset?.x;e.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideUp":{const c=this.clipConfiguration.offset?.y+.025,l=this.clipConfiguration.offset?.y;t.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideDown":{const c=this.clipConfiguration.offset?.y-.025,l=this.clipConfiguration.offset?.y;t.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeOut"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeOut"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":case"shuffleTopRight":case"shuffleRightTop":case"shuffleRightBottom":case"shuffleBottomRight":case"shuffleBottomLeft":case"shuffleLeftBottom":case"shuffleLeftTop":case"shuffleTopLeft":default:console.warn(`Unimplemented transition:in preset "${this.clipConfiguration.transition.in}"`);break}return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}buildOutPreset(){const e=[],t=[],i=[],s=[],n=[];if(!this.clipConfiguration.transition?.out)return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n};const r=this.getOutPresetLength(),o=this.clipConfiguration.length-r;switch(this.getOutPresetName()){case"fade":{const c=Math.max(0,Math.min(this.clipConfiguration.opacity??1,1));i.push({from:c,to:0,start:o,length:r,interpolation:"linear"});break}case"zoom":{const l=this.clipConfiguration.scale,g=l+9;s.push({from:l,to:g,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideLeft":{const c=this.clipConfiguration.offset?.x,l=c-.025;e.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideRight":{const c=this.clipConfiguration.offset?.x,l=c+.025;e.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideUp":{const c=this.clipConfiguration.offset?.y,l=c-.025;t.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeIn"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeIn"});break}case"slideDown":{const c=this.clipConfiguration.offset?.y,l=c+.025;t.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeIn"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeIn"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":case"shuffleTopRight":case"shuffleRightTop":case"shuffleRightBottom":case"shuffleBottomRight":case"shuffleBottomLeft":case"shuffleLeftBottom":case"shuffleLeftTop":case"shuffleTopLeft":default:console.warn(`Unimplemented transition:out preset "${this.clipConfiguration.transition.out}"`);break}return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}getInPresetName(){const[e]=(this.clipConfiguration.transition?.in??"").split(/(Slow|Fast|VeryFast)/);return e}getOutPresetName(){const[e]=(this.clipConfiguration.transition?.out??"").split(/(Slow|Fast|VeryFast)/);return e}getInPresetLength(){const[,e]=(this.clipConfiguration.transition?.in??"").split(/(Slow|Fast|VeryFast)/);switch(e){case"Slow":return 2;case"Fast":return .5;case"VeryFast":return .25;default:return 1}}getOutPresetLength(){const[,e]=(this.clipConfiguration.transition?.out??"").split(/(Slow|Fast|VeryFast)/);switch(e){case"Slow":return 2;case"Fast":return .5;case"VeryFast":return .25;default:return 1}}}class Ji{static ButtonLeftClick=0;static ButtonRightClick=3}class es{containerSize;constructor(e){this.containerSize=e}relativeToAbsolute(e,t,i){switch(t){case"topLeft":return{x:i.x*this.containerSize.width,y:-i.y*this.containerSize.height};case"topRight":return{x:(i.x+1)*this.containerSize.width-e.width,y:-i.y*this.containerSize.height};case"bottomLeft":return{x:i.x*this.containerSize.width,y:(-i.y+1)*this.containerSize.height-e.height};case"bottomRight":return{x:(i.x+1)*this.containerSize.width-e.width,y:(-i.y+1)*this.containerSize.height-e.height};case"left":return{x:i.x*this.containerSize.width,y:(-i.y+.5)*this.containerSize.height-e.height/2};case"right":return{x:(i.x+1)*this.containerSize.width-e.width,y:(-i.y+.5)*this.containerSize.height-e.height/2};case"top":return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:-i.y*this.containerSize.height};case"bottom":return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:(-i.y+1)*this.containerSize.height-e.height};case"center":default:return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:(-i.y+.5)*this.containerSize.height-e.height/2}}}absoluteToRelative(e,t,i){switch(t){case"topLeft":return{x:i.x/this.containerSize.width,y:-(i.y/this.containerSize.height)};case"topRight":return{x:(i.x+e.width)/this.containerSize.width-1,y:-(i.y/this.containerSize.height)};case"bottomLeft":return{x:i.x/this.containerSize.width,y:-((i.y+e.height)/this.containerSize.height-1)};case"bottomRight":return{x:(i.x+e.width)/this.containerSize.width-1,y:-((i.y+e.height)/this.containerSize.height-1)};case"left":return{x:i.x/this.containerSize.width,y:-((i.y+e.height/2)/this.containerSize.height-.5)};case"right":return{x:(i.x+e.width)/this.containerSize.width-1,y:-((i.y+e.height/2)/this.containerSize.height-.5)};case"top":return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-(i.y/this.containerSize.height)};case"bottom":return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-((i.y+e.height)/this.containerSize.height-1)};case"center":default:return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-((i.y+e.height/2)/this.containerSize.height-.5)}}}}class nt{container;constructor(){this.container=new w.Container}getContainer(){return this.container}}class z extends nt{static SnapThreshold=20;static DiscardedFrameCount=Math.ceil(1/30*1e3);static ScaleHandleRadius=10;static RotationHandleRadius=10;static RotationHandleOffset=50;static OutlineWidth=5;static MinScale=.1;static MaxScale=5;layer;shouldDispose;edit;clipConfiguration;positionBuilder;offsetXKeyframeBuilder;offsetYKeyframeBuilder;scaleKeyframeBuilder;opacityKeyframeBuilder;rotationKeyframeBuilder;outline;topLeftScaleHandle;topRightScaleHandle;bottomLeftScaleHandle;bottomRightScaleHandle;rotationHandle;isHovering;isDragging;dragOffset;scaleDirection;scaleStart;scaleOffset;isRotating;rotationStart;rotationOffset;constructor(e,t){super(),this.edit=e,this.layer=0,this.shouldDispose=!1,this.clipConfiguration=t,this.positionBuilder=new es(e.size),this.outline=null,this.topLeftScaleHandle=null,this.topRightScaleHandle=null,this.bottomRightScaleHandle=null,this.bottomLeftScaleHandle=null,this.rotationHandle=null,this.isHovering=!1,this.isDragging=!1,this.dragOffset={x:0,y:0},this.scaleDirection=null,this.scaleStart=null,this.scaleOffset={x:0,y:0},this.isRotating=!1,this.rotationStart=null,this.rotationOffset={x:0,y:0}}configureKeyframes(){if(this.offsetXKeyframeBuilder=new R(this.clipConfiguration.offset?.x??0,this.getLength()),this.offsetYKeyframeBuilder=new R(this.clipConfiguration.offset?.y??0,this.getLength()),this.scaleKeyframeBuilder=new R(this.clipConfiguration.scale??1,this.getLength(),1),this.opacityKeyframeBuilder=new R(this.clipConfiguration.opacity??1,this.getLength(),1),this.rotationKeyframeBuilder=new R(this.clipConfiguration.transform?.rotate?.angle??0,this.getLength()),this.clipHasKeyframes())return;const e=[],t=[],i=[],s=[],n=[],r=new Gi(this.clipConfiguration).build(this.edit.size,this.getSize());e.push(...r.offsetXKeyframes),t.push(...r.offsetYKeyframes),i.push(...r.opacityKeyframes),s.push(...r.scaleKeyframes),n.push(...r.rotationKeyframes);const o=new Qi(this.clipConfiguration).build();e.push(...o.offsetXKeyframes),t.push(...o.offsetYKeyframes),i.push(...o.opacityKeyframes),s.push(...o.scaleKeyframes),n.push(...o.rotationKeyframes),e.length&&(this.offsetXKeyframeBuilder=new R(e,this.getLength())),t.length&&(this.offsetYKeyframeBuilder=new R(t,this.getLength())),i.length&&(this.opacityKeyframeBuilder=new R(i,this.getLength(),1)),s.length&&(this.scaleKeyframeBuilder=new R(s,this.getLength(),1)),n.length&&(this.rotationKeyframeBuilder=new R(n,this.getLength()))}async load(){this.outline=new w.Graphics,this.getContainer().addChild(this.outline),this.topLeftScaleHandle=new w.Graphics,this.topRightScaleHandle=new w.Graphics,this.bottomRightScaleHandle=new w.Graphics,this.bottomLeftScaleHandle=new w.Graphics,this.getContainer().addChild(this.topLeftScaleHandle),this.getContainer().addChild(this.topRightScaleHandle),this.getContainer().addChild(this.bottomRightScaleHandle),this.getContainer().addChild(this.bottomLeftScaleHandle),this.rotationHandle=new w.Graphics,this.getContainer().addChild(this.rotationHandle),this.getContainer().cursor="pointer",this.getContainer().eventMode="static",this.getContainer().on("pointerdown",this.onPointerStart.bind(this)),this.getContainer().on("pointermove",this.onPointerMove.bind(this)),this.getContainer().on("globalpointermove",this.onPointerMove.bind(this)),this.getContainer().on("pointerup",this.onPointerUp.bind(this)),this.getContainer().on("pointerupoutside",this.onPointerUp.bind(this)),this.getContainer().on("pointerover",this.onPointerOver.bind(this)),this.getContainer().on("pointerout",this.onPointerOut.bind(this))}update(e,t){if(this.getContainer().visible=this.isActive(),this.getContainer().zIndex=this.layer,!this.isActive())return;const i=this.getPivot(),s=this.getPosition(),n=this.getScale();this.getContainer().scale.set(n),this.getContainer().pivot.set(i.x,i.y),this.getContainer().position.set(s.x+i.x,s.y+i.y);const r=this.getRotation();this.getContainer().alpha=this.getOpacity(),this.getContainer().angle=r,this.shouldDiscardFrame()&&(this.getContainer().alpha=0)}draw(){if(!this.outline)return;if((!this.isActive()||this.edit.getSelectedClip()!==this)&&!this.isHovering){this.outline.clear(),this.topLeftScaleHandle?.clear(),this.topRightScaleHandle?.clear(),this.bottomRightScaleHandle?.clear(),this.bottomLeftScaleHandle?.clear(),this.rotationHandle?.clear();return}const e=this.isHovering||this.isDragging?65535:16777215,t=this.getSize(),i=this.getScale();if(this.outline.clear(),this.outline.strokeStyle={width:z.OutlineWidth/i,color:e},this.outline.rect(0,0,t.width,t.height),this.outline.stroke(),!this.topLeftScaleHandle||!this.topRightScaleHandle||!this.bottomRightScaleHandle||!this.bottomLeftScaleHandle||!this.isActive()||this.edit.getSelectedClip()!==this)return;this.topLeftScaleHandle.fillStyle={color:e},this.topLeftScaleHandle.clear();const s=z.ScaleHandleRadius*2/i;if(this.topLeftScaleHandle.rect(-s/2,-s/2,s,s),this.topLeftScaleHandle.fill(),this.topRightScaleHandle.fillStyle={color:e},this.topRightScaleHandle.clear(),this.topRightScaleHandle.rect(t.width-s/2,-s/2,s,s),this.topRightScaleHandle.fill(),this.bottomRightScaleHandle.fillStyle={color:e},this.bottomRightScaleHandle.clear(),this.bottomRightScaleHandle.rect(t.width-s/2,t.height-s/2,s,s),this.bottomRightScaleHandle.fill(),this.bottomLeftScaleHandle.fillStyle={color:e},this.bottomLeftScaleHandle.clear(),this.bottomLeftScaleHandle.rect(-s/2,t.height-s/2,s,s),this.bottomLeftScaleHandle.fill(),!this.rotationHandle)return;const n=t.width/2,r=-50/i;this.rotationHandle.clear(),this.rotationHandle.fillStyle={color:e},this.rotationHandle.circle(n,r,z.RotationHandleRadius/i),this.rotationHandle.fill(),this.outline.strokeStyle={width:z.OutlineWidth/i,color:e},this.outline.moveTo(n,0),this.outline.lineTo(n,r),this.outline.stroke()}dispose(){this.outline?.destroy(),this.outline=null,this.topLeftScaleHandle?.destroy(),this.topLeftScaleHandle=null,this.topRightScaleHandle?.destroy(),this.topRightScaleHandle=null,this.bottomLeftScaleHandle?.destroy(),this.bottomLeftScaleHandle=null,this.bottomRightScaleHandle?.destroy(),this.bottomRightScaleHandle=null,this.rotationHandle?.destroy(),this.rotationHandle=null}getStart(){return this.clipConfiguration.start*1e3}getLength(){return this.clipConfiguration.length*1e3}getEnd(){return this.getStart()+this.getLength()}getPlaybackTime(){const e=this.edit.playbackTime-this.getStart();return e<0?0:e>this.getLength()?this.getLength():e}getOpacity(){return this.opacityKeyframeBuilder?.getValue(this.getPlaybackTime())??1}getPosition(){const e={x:this.offsetXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.offsetYKeyframeBuilder?.getValue(this.getPlaybackTime())??0};return this.positionBuilder.relativeToAbsolute(this.getSize(),this.clipConfiguration.position??"center",e)}getPivot(){const e=this.getSize();return{x:e.width/2,y:e.height/2}}getFitScale(){switch(this.clipConfiguration.fit??"crop"){case"crop":return Math.max(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"cover":return Math.max(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"contain":return Math.min(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"none":default:return 1}}getScale(){return(this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1)*this.getFitScale()}getRotation(){return this.rotationKeyframeBuilder?.getValue(this.getPlaybackTime())??0}isActive(){return this.edit.playbackTime>=this.getStart()&&this.edit.playbackTime<this.getEnd()}shouldDiscardFrame(){return this.getPlaybackTime()<z.DiscardedFrameCount}onPointerStart(e){if(e.button!==Ji.ButtonLeftClick||this.clipHasKeyframes())return;if(this.scaleDirection=null,this.topLeftScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="topLeft"),this.topRightScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="topRight"),this.bottomRightScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="bottomRight"),this.bottomLeftScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="bottomLeft"),this.scaleDirection!==null){this.scaleStart=this.getScale()/this.getFitScale();const h=e.getLocalPosition(this.edit.getContainer());this.scaleOffset=h;return}if(this.rotationHandle?.getBounds().containsPoint(e.globalX,e.globalY)){this.isRotating=!0,this.rotationStart=this.getRotation();const h=e.getLocalPosition(this.edit.getContainer());this.rotationOffset=h;return}this.isDragging=!0;const o=e.getLocalPosition(this.edit.getContainer());this.dragOffset={x:o.x-this.getContainer().position.x,y:o.y-this.getContainer().position.y}}onPointerMove(e){if(this.scaleDirection!==null&&this.scaleStart!==null){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPosition(),s=this.getPivot(),n={x:i.x+s.x,y:i.y+s.y},r=Math.sqrt((this.scaleOffset.x-n.x)**2+(this.scaleOffset.y-n.y)**2),h=Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)/r,c=this.scaleStart*h;this.clipConfiguration.scale=Math.max(z.MinScale,Math.min(c,z.MaxScale)),this.scaleKeyframeBuilder=new R(this.clipConfiguration.scale,this.getLength(),1);return}if(this.isRotating&&this.rotationStart!==null){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPosition(),s=this.getPivot(),n={x:i.x+s.x,y:i.y+s.y},r=Math.atan2(this.rotationOffset.y-n.y,this.rotationOffset.x-n.x),h=(Math.atan2(t.y-n.y,t.x-n.x)-r)*(180/Math.PI);let c=this.rotationStart+h;const l=45,g=c%l,p=2;Math.abs(g)<p?c=Math.floor(c/l)*l:Math.abs(g-l)<p&&(c=Math.ceil(c/l)*l),this.clipConfiguration.transform||(this.clipConfiguration.transform={rotate:{angle:0}}),this.clipConfiguration.transform.rotate||(this.clipConfiguration.transform.rotate={angle:0}),this.clipConfiguration.transform.rotate.angle=c,this.rotationKeyframeBuilder=new R(this.clipConfiguration.transform.rotate.angle,this.getLength());return}if(this.isDragging){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPivot(),s={x:t.x-this.dragOffset.x,y:t.y-this.dragOffset.y},n={x:s.x-i.x,y:s.y-i.y},r=[{x:0,y:0},{x:this.edit.size.width,y:0},{x:0,y:this.edit.size.height},{x:this.edit.size.width,y:this.edit.size.height}],o={x:this.edit.size.width/2,y:this.edit.size.height/2},h=[...r,o],c=[{x:n.x,y:n.y},{x:n.x+this.getSize().width,y:n.y},{x:n.x,y:n.y+this.getSize().height},{x:n.x+this.getSize().width,y:n.y+this.getSize().height}],l={x:n.x+this.getSize().width/2,y:n.y+this.getSize().height/2},g=[...c,l];let p=z.SnapThreshold,k=z.SnapThreshold,A=null,S=null;for(const ce of g)for(const ye of h){const Y=Math.abs(ce.x-ye.x);Y<p&&(p=Y,A=n.x+(ye.x-ce.x));const ve=Math.abs(ce.y-ye.y);ve<k&&(k=ve,S=n.y+(ye.y-ce.y))}A!==null&&(n.x=A),S!==null&&(n.y=S);const D=this.positionBuilder.absoluteToRelative(this.getSize(),this.clipConfiguration.position??"center",n);this.clipConfiguration.offset||(this.clipConfiguration.offset={x:0,y:0}),this.clipConfiguration.offset.x=D.x,this.clipConfiguration.offset.y=D.y,this.offsetXKeyframeBuilder=new R(this.clipConfiguration.offset.x,this.getLength()),this.offsetYKeyframeBuilder=new R(this.clipConfiguration.offset.y,this.getLength())}}onPointerUp(){this.isDragging&&this.edit.setSelectedClip(this),this.isDragging=!1,this.dragOffset={x:0,y:0},this.scaleDirection=null,this.scaleStart=null,this.scaleOffset={x:0,y:0},this.isRotating=!1,this.rotationStart=null,this.rotationOffset={x:0,y:0}}onPointerOver(){this.isHovering=!0}onPointerOut(){this.isHovering=!1}clipHasPresets(){return!!this.clipConfiguration.effect||!!this.clipConfiguration.transition?.in||!!this.clipConfiguration.transition?.out}clipHasKeyframes(){return[this.clipConfiguration.scale,this.clipConfiguration.offset?.x,this.clipConfiguration.offset?.y,this.clipConfiguration.transform?.rotate?.angle].some(e=>e&&typeof e!="number")}}class at extends z{audioResource;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t),this.audioResource=null,this.isPlaying=!1;const i=t.asset;this.volumeKeyframeBuilder=new R(i.volume??1,this.getLength()),this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,i={src:t,loadParser:Be.Name},s=await this.edit.assetLoader.load(t,i);if(!(s instanceof Bt.Howl))throw new Error(`Invalid audio source '${e.src}'.`);this.audioResource=s,this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:i=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,this.getContainer().alpha=0,!this.audioResource)return;const s=this.edit.isPlaying&&this.isActive(),n=this.getPlaybackTime();s&&(this.isPlaying||(this.isPlaying=!0,this.audioResource.seek(n/1e3+i),this.audioResource.play()),this.audioResource.volume()!==this.getVolume()&&this.audioResource.volume(this.getVolume()),Math.abs((this.audioResource.seek()-i)*1e3-n)>100&&this.audioResource.seek(n/1e3+i)),this.isPlaying&&!s&&(this.isPlaying=!1,this.audioResource.pause());const r=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&r&&(this.syncTimer=0,this.audioResource.seek(n/1e3+i))}draw(){super.draw()}dispose(){this.audioResource?.unload(),this.audioResource=null}getSize(){return{width:0,height:0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}}var ts=`in vec2 aPosition;
|
|
1
|
+
(function(F,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("pixi.js"),require("opentype.js"),require("howler"),require("@ffmpeg/ffmpeg")):typeof define=="function"&&define.amd?define(["exports","pixi.js","opentype.js","howler","@ffmpeg/ffmpeg"],K):(F=typeof globalThis<"u"?globalThis:F||self,K(F.ShotstackStudio={},F.PIXI,F.opentype,F.Howler,F.ffmpeg))})(this,function(F,K,Zt,Kt,Ht){"use strict";function $e(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const w=$e(K),ut=$e(Zt),Bt=$e(Kt);class dt{events;constructor(){this.events={}}on(e,t){this.events[e]||(this.events[e]=new Set),this.events[e].add(t)}off(e,t){this.events[e]&&(this.events[e].delete(t),!(this.events[e].size>0)&&delete this.events[e])}clear(e){delete this.events[e]}emit(e,t){if(this.events[e])for(const i of this.events[e])i(t)}}class jt extends dt{registry;constructor(){super(),this.registry={}}}class Vt{loadTracker;constructor(){this.loadTracker=new jt}async load(e,t){this.updateAssetLoadMetadata(e,"pending",0);try{const i=await w.Assets.load(t,s=>{this.updateAssetLoadMetadata(e,"loading",s)});return this.updateAssetLoadMetadata(e,"success",1),i}catch{return this.updateAssetLoadMetadata(e,"failed",1),null}}getProgress(){const e=Object.keys(this.loadTracker.registry);return e.reduce((i,s)=>i+this.loadTracker.registry[s].progress,0)/e.length}updateAssetLoadMetadata(e,t,i){this.loadTracker.registry[e]?(this.loadTracker.registry[e].progress=i,this.loadTracker.registry[e].status=t):this.loadTracker.registry[e]={progress:i,status:t};const s={...this.loadTracker.registry};this.loadTracker.emit("onAssetLoadInfoUpdated",{registry:s})}}class Oe{static Name="FontLoadParser";name;extension;validFontExtensions;woff2Decompressor;constructor(){this.name=Oe.Name,this.extension={type:[w.ExtensionType.LoadParser],priority:w.LoaderParserPriority.High,ref:null},this.validFontExtensions=["ttf","otf","woff","woff2"],this.woff2Decompressor=null}test(e){const t=e.split("?")[0]?.split(".").pop()?.toLowerCase()??"";return this.validFontExtensions.includes(t)}async load(e,t,i){const s=e.split("?")[0]?.split(".").pop()?.toLowerCase()??"",n=await fetch(e).then(p=>p.arrayBuffer());if(s!=="woff2"){const p=ut.parse(new Uint8Array(n).buffer),k=p.names.fontFamily.en||p.names.fontFamily[Object.keys(p.names.fontFamily)[0]],A=new FontFace(k,`url(${e})`);return await A.load(),document.fonts.add(A),A}if(await this.loadWoff2Decompressor(),!this.woff2Decompressor)throw new Error("Cannot initialize Woff2 decompressor.");const r=this.woff2Decompressor.decompress(n),o=ut.parse(new Uint8Array(r).buffer),h=o.names.fontFamily.en||o.names.fontFamily[Object.keys(o.names.fontFamily)[0]],c=new Blob([r],{type:"font/ttf"}),l=URL.createObjectURL(c),g=new FontFace(h,`url(${l})`);return await g.load(),document.fonts.add(g),g}async loadWoff2Decompressor(){if(this.woff2Decompressor)return;const t=`${await fetch("https://unpkg.com/wawoff2@2.0.1/build/decompress_binding.js").then(i=>i.text())}; return Module`;this.woff2Decompressor=new Function(t)(),await new Promise(i=>{this.woff2Decompressor.onRuntimeInitialized=i})}unload(e){e&&document.fonts.delete(e)}}var C;(function(a){a.assertEqual=s=>s;function e(s){}a.assertIs=e;function t(s){throw new Error}a.assertNever=t,a.arrayToEnum=s=>{const n={};for(const r of s)n[r]=r;return n},a.getValidEnumValues=s=>{const n=a.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),r={};for(const o of n)r[o]=s[o];return a.objectValues(r)},a.objectValues=s=>a.objectKeys(s).map(function(n){return s[n]}),a.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const n=[];for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&n.push(r);return n},a.find=(s,n)=>{for(const r of s)if(n(r))return r},a.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function i(s,n=" | "){return s.map(r=>typeof r=="string"?`'${r}'`:r).join(n)}a.joinValues=i,a.jsonStringifyReplacer=(s,n)=>typeof n=="bigint"?n.toString():n})(C||(C={}));var ft;(function(a){a.mergeShapes=(e,t)=>({...e,...t})})(ft||(ft={}));const f=C.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),G=a=>{switch(typeof a){case"undefined":return f.undefined;case"string":return f.string;case"number":return isNaN(a)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(a)?f.array:a===null?f.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?f.promise:typeof Map<"u"&&a instanceof Map?f.map:typeof Set<"u"&&a instanceof Set?f.set:typeof Date<"u"&&a instanceof Date?f.date:f.object;default:return f.unknown}},u=C.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class N extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(n){return n.message},i={_errors:[]},s=n=>{for(const r of n.issues)if(r.code==="invalid_union")r.unionErrors.map(s);else if(r.code==="invalid_return_type")s(r.returnTypeError);else if(r.code==="invalid_arguments")s(r.argumentsError);else if(r.path.length===0)i._errors.push(t(r));else{let o=i,h=0;for(;h<r.path.length;){const c=r.path[h];h===r.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(r))):o[c]=o[c]||{_errors:[]},o=o[c],h++}}};return s(this),i}static assert(e){if(!(e instanceof N))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,C.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},i=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):i.push(e(s));return{formErrors:i,fieldErrors:t}}get formErrors(){return this.flatten()}}N.create=a=>new N(a);const xe=(a,e)=>{let t;switch(a.code){case u.invalid_type:a.received===f.undefined?t="Required":t=`Expected ${a.expected}, received ${a.received}`;break;case u.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(a.expected,C.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:t=`Unrecognized key(s) in object: ${C.joinValues(a.keys,", ")}`;break;case u.invalid_union:t="Invalid input";break;case u.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${C.joinValues(a.options)}`;break;case u.invalid_enum_value:t=`Invalid enum value. Expected ${C.joinValues(a.options)}, received '${a.received}'`;break;case u.invalid_arguments:t="Invalid function arguments";break;case u.invalid_return_type:t="Invalid function return type";break;case u.invalid_date:t="Invalid date";break;case u.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(t=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?t=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?t=`Invalid input: must end with "${a.validation.endsWith}"`:C.assertNever(a.validation):a.validation!=="regex"?t=`Invalid ${a.validation}`:t="Invalid";break;case u.too_small:a.type==="array"?t=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?t=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?t=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?t=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:t="Invalid input";break;case u.too_big:a.type==="array"?t=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?t=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?t=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?t=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?t=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:t="Invalid input";break;case u.custom:t="Invalid input";break;case u.invalid_intersection_types:t="Intersection results could not be merged";break;case u.not_multiple_of:t=`Number must be a multiple of ${a.multipleOf}`;break;case u.not_finite:t="Number must be finite";break;default:t=e.defaultError,C.assertNever(a)}return{message:t}};let $t=xe;function Ue(){return $t}const We=a=>{const{data:e,path:t,errorMaps:i,issueData:s}=a,n=[...t,...s.path||[]],r={...s,path:n};if(s.message!==void 0)return{...s,path:n,message:s.message};let o="";const h=i.filter(c=>!!c).slice().reverse();for(const c of h)o=c(r,{data:e,defaultError:o}).message;return{...s,path:n,message:o}};function d(a,e){const t=Ue(),i=We({issueData:e,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,t,t===xe?void 0:xe].filter(s=>!!s)});a.common.issues.push(i)}class I{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const i=[];for(const s of t){if(s.status==="aborted")return x;s.status==="dirty"&&e.dirty(),i.push(s.value)}return{status:e.value,value:i}}static async mergeObjectAsync(e,t){const i=[];for(const s of t){const n=await s.key,r=await s.value;i.push({key:n,value:r})}return I.mergeObjectSync(e,i)}static mergeObjectSync(e,t){const i={};for(const s of t){const{key:n,value:r}=s;if(n.status==="aborted"||r.status==="aborted")return x;n.status==="dirty"&&e.dirty(),r.status==="dirty"&&e.dirty(),n.value!=="__proto__"&&(typeof r.value<"u"||s.alwaysSet)&&(i[n.value]=r.value)}return{status:e.value,value:i}}}const x=Object.freeze({status:"aborted"}),we=a=>({status:"dirty",value:a}),E=a=>({status:"valid",value:a}),pt=a=>a.status==="aborted",mt=a=>a.status==="dirty",he=a=>a.status==="valid",Ae=a=>typeof Promise<"u"&&a instanceof Promise;function Pe(a,e,t,i){if(typeof e=="function"?a!==e||!0:!e.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(a)}function gt(a,e,t,i,s){if(typeof e=="function"?a!==e||!0:!e.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(a,t),t}typeof SuppressedError=="function"&&SuppressedError;var m;(function(a){a.errToObj=e=>typeof e=="string"?{message:e}:e||{},a.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var _e,ke;class H{constructor(e,t,i,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=i,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const yt=(a,e)=>{if(he(e))return{success:!0,data:e.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new N(a.common.issues);return this._error=t,this._error}}};function _(a){if(!a)return{};const{errorMap:e,invalid_type_error:t,required_error:i,description:s}=a;if(e&&(t||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(r,o)=>{var h,c;const{message:l}=a;return r.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:(h=l??i)!==null&&h!==void 0?h:o.defaultError}:r.code!=="invalid_type"?{message:o.defaultError}:{message:(c=l??t)!==null&&c!==void 0?c:o.defaultError}},description:s}}class b{get description(){return this._def.description}_getType(e){return G(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:G(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new I,ctx:{common:e.parent.common,data:e.data,parsedType:G(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ae(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const i=this.safeParse(e,t);if(i.success)return i.data;throw i.error}safeParse(e,t){var i;const s={common:{issues:[],async:(i=t?.async)!==null&&i!==void 0?i:!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)},n=this._parseSync({data:e,path:s.path,parent:s});return yt(s,n)}"~validate"(e){var t,i;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:s});return he(n)?{value:n.value}:{issues:s.common.issues}}catch(n){!((i=(t=n?.message)===null||t===void 0?void 0:t.toLowerCase())===null||i===void 0)&&i.includes("encountered")&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then(n=>he(n)?{value:n.value}:{issues:s.common.issues})}async parseAsync(e,t){const i=await this.safeParseAsync(e,t);if(i.success)return i.data;throw i.error}async safeParseAsync(e,t){const i={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:G(e)},s=this._parse({data:e,path:i.path,parent:i}),n=await(Ae(s)?s:Promise.resolve(s));return yt(i,n)}refine(e,t){const i=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,n)=>{const r=e(s),o=()=>n.addIssue({code:u.custom,...i(s)});return typeof Promise<"u"&&r instanceof Promise?r.then(h=>h?!0:(o(),!1)):r?!0:(o(),!1)})}refinement(e,t){return this._refinement((i,s)=>e(i)?!0:(s.addIssue(typeof t=="function"?t(i,s):t),!1))}_refinement(e){return new U({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return W.create(this,this._def)}nullable(){return ie.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return B.create(this)}promise(){return Se.create(this,this._def)}or(e){return Ie.create([this,e],this._def)}and(e){return Le.create(this,e,this._def)}transform(e){return new U({..._(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new De({..._(this._def),innerType:this,defaultValue:t,typeName:v.ZodDefault})}brand(){return new _t({typeName:v.ZodBranded,type:this,..._(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Ze({..._(this._def),innerType:this,catchValue:t,typeName:v.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ke.create(this,e)}readonly(){return He.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ut=/^c[^\s-]{8,}$/i,Wt=/^[0-9a-z]+$/,Yt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Xt=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,qt=/^[a-z0-9_-]{21}$/i,Gt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Qt=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Jt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ei="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ye;const ti=/^(?:(?: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])$/,ii=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,si=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ni=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ai=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ri=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,vt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",oi=new RegExp(`^${vt}$`);function xt(a){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?e=`${e}\\.\\d{${a.precision}}`:a.precision==null&&(e=`${e}(\\.\\d+)?`),e}function ci(a){return new RegExp(`^${xt(a)}$`)}function li(a){let e=`${vt}T${xt(a)}`;const t=[];return t.push(a.local?"Z?":"Z"),a.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function hi(a,e){return!!((e==="v4"||!e)&&ti.test(a)||(e==="v6"||!e)&&si.test(a))}function ui(a,e){if(!Gt.test(a))return!1;try{const[t]=a.split("."),i=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(i));return!(typeof s!="object"||s===null||!s.typ||!s.alg||e&&s.alg!==e)}catch{return!1}}function di(a,e){return!!((e==="v4"||!e)&&ii.test(a)||(e==="v6"||!e)&&ni.test(a))}class j extends b{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.string,received:n.parsedType}),x}const i=new I;let s;for(const n of this._def.checks)if(n.kind==="min")e.data.length<n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),i.dirty());else if(n.kind==="max")e.data.length>n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),i.dirty());else if(n.kind==="length"){const r=e.data.length>n.value,o=e.data.length<n.value;(r||o)&&(s=this._getOrReturnCtx(e,s),r?d(s,{code:u.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}):o&&d(s,{code:u.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}),i.dirty())}else if(n.kind==="email")Jt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"email",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="emoji")Ye||(Ye=new RegExp(ei,"u")),Ye.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"emoji",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="uuid")Xt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"uuid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="nanoid")qt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"nanoid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="cuid")Ut.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="cuid2")Wt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cuid2",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="ulid")Yt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ulid",code:u.invalid_string,message:n.message}),i.dirty());else if(n.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),d(s,{validation:"url",code:u.invalid_string,message:n.message}),i.dirty()}else n.kind==="regex"?(n.regex.lastIndex=0,n.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"regex",code:u.invalid_string,message:n.message}),i.dirty())):n.kind==="trim"?e.data=e.data.trim():n.kind==="includes"?e.data.includes(n.value,n.position)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{includes:n.value,position:n.position},message:n.message}),i.dirty()):n.kind==="toLowerCase"?e.data=e.data.toLowerCase():n.kind==="toUpperCase"?e.data=e.data.toUpperCase():n.kind==="startsWith"?e.data.startsWith(n.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{startsWith:n.value},message:n.message}),i.dirty()):n.kind==="endsWith"?e.data.endsWith(n.value)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:{endsWith:n.value},message:n.message}),i.dirty()):n.kind==="datetime"?li(n).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"datetime",message:n.message}),i.dirty()):n.kind==="date"?oi.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"date",message:n.message}),i.dirty()):n.kind==="time"?ci(n).test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{code:u.invalid_string,validation:"time",message:n.message}),i.dirty()):n.kind==="duration"?Qt.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"duration",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="ip"?hi(e.data,n.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"ip",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="jwt"?ui(e.data,n.alg)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"jwt",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="cidr"?di(e.data,n.version)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"cidr",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="base64"?ai.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64",code:u.invalid_string,message:n.message}),i.dirty()):n.kind==="base64url"?ri.test(e.data)||(s=this._getOrReturnCtx(e,s),d(s,{validation:"base64url",code:u.invalid_string,message:n.message}),i.dirty()):C.assertNever(n);return{status:i.value,value:e.data}}_regex(e,t,i){return this.refinement(s=>e.test(s),{validation:t,code:u.invalid_string,...m.errToObj(i)})}_addCheck(e){return new j({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){var t,i;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:(t=e?.offset)!==null&&t!==void 0?t:!1,local:(i=e?.local)!==null&&i!==void 0?i:!1,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...m.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...m.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...m.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...m.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...m.errToObj(t)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new j({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}j.create=a=>{var e;return new j({checks:[],typeName:v.ZodString,coerce:(e=a?.coerce)!==null&&e!==void 0?e:!1,..._(a)})};function fi(a,e){const t=(a.toString().split(".")[1]||"").length,i=(e.toString().split(".")[1]||"").length,s=t>i?t:i,n=parseInt(a.toFixed(s).replace(".","")),r=parseInt(e.toFixed(s).replace(".",""));return n%r/Math.pow(10,s)}class ue extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.number,received:n.parsedType}),x}let i;const s=new I;for(const n of this._def.checks)n.kind==="int"?C.isInteger(e.data)||(i=this._getOrReturnCtx(e,i),d(i,{code:u.invalid_type,expected:"integer",received:"float",message:n.message}),s.dirty()):n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),s.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),s.dirty()):n.kind==="multipleOf"?fi(e.data,n.value)!==0&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_multiple_of,multipleOf:n.value,message:n.message}),s.dirty()):n.kind==="finite"?Number.isFinite(e.data)||(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_finite,message:n.message}),s.dirty()):C.assertNever(n);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,i,s){return new ue({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:m.toString(s)}]})}_addCheck(e){return new ue({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&C.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(t===null||i.value>t)&&(t=i.value):i.kind==="max"&&(e===null||i.value<e)&&(e=i.value)}return Number.isFinite(t)&&Number.isFinite(e)}}ue.create=a=>new ue({checks:[],typeName:v.ZodNumber,coerce:a?.coerce||!1,..._(a)});class de extends b{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let i;const s=new I;for(const n of this._def.checks)n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),s.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),s.dirty()):n.kind==="multipleOf"?e.data%n.value!==BigInt(0)&&(i=this._getOrReturnCtx(e,i),d(i,{code:u.not_multiple_of,multipleOf:n.value,message:n.message}),s.dirty()):C.assertNever(n);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return d(t,{code:u.invalid_type,expected:f.bigint,received:t.parsedType}),x}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,i,s){return new de({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:m.toString(s)}]})}_addCheck(e){return new de({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}de.create=a=>{var e;return new de({checks:[],typeName:v.ZodBigInt,coerce:(e=a?.coerce)!==null&&e!==void 0?e:!1,..._(a)})};class Xe extends b{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.boolean,received:i.parsedType}),x}return E(e.data)}}Xe.create=a=>new Xe({typeName:v.ZodBoolean,coerce:a?.coerce||!1,..._(a)});class be extends b{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_type,expected:f.date,received:n.parsedType}),x}if(isNaN(e.data.getTime())){const n=this._getOrReturnCtx(e);return d(n,{code:u.invalid_date}),x}const i=new I;let s;for(const n of this._def.checks)n.kind==="min"?e.data.getTime()<n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),i.dirty()):n.kind==="max"?e.data.getTime()>n.value&&(s=this._getOrReturnCtx(e,s),d(s,{code:u.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),i.dirty()):C.assertNever(n);return{status:i.value,value:new Date(e.data.getTime())}}_addCheck(e){return new be({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}be.create=a=>new be({checks:[],coerce:a?.coerce||!1,typeName:v.ZodDate,..._(a)});class qe extends b{_parse(e){if(this._getType(e)!==f.symbol){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.symbol,received:i.parsedType}),x}return E(e.data)}}qe.create=a=>new qe({typeName:v.ZodSymbol,..._(a)});class Re extends b{_parse(e){if(this._getType(e)!==f.undefined){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.undefined,received:i.parsedType}),x}return E(e.data)}}Re.create=a=>new Re({typeName:v.ZodUndefined,..._(a)});class ze extends b{_parse(e){if(this._getType(e)!==f.null){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.null,received:i.parsedType}),x}return E(e.data)}}ze.create=a=>new ze({typeName:v.ZodNull,..._(a)});class Ge extends b{constructor(){super(...arguments),this._any=!0}_parse(e){return E(e.data)}}Ge.create=a=>new Ge({typeName:v.ZodAny,..._(a)});class fe extends b{constructor(){super(...arguments),this._unknown=!0}_parse(e){return E(e.data)}}fe.create=a=>new fe({typeName:v.ZodUnknown,..._(a)});class Q extends b{_parse(e){const t=this._getOrReturnCtx(e);return d(t,{code:u.invalid_type,expected:f.never,received:t.parsedType}),x}}Q.create=a=>new Q({typeName:v.ZodNever,..._(a)});class Qe extends b{_parse(e){if(this._getType(e)!==f.undefined){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.void,received:i.parsedType}),x}return E(e.data)}}Qe.create=a=>new Qe({typeName:v.ZodVoid,..._(a)});class B extends b{_parse(e){const{ctx:t,status:i}=this._processInputParams(e),s=this._def;if(t.parsedType!==f.array)return d(t,{code:u.invalid_type,expected:f.array,received:t.parsedType}),x;if(s.exactLength!==null){const r=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(r||o)&&(d(t,{code:r?u.too_big:u.too_small,minimum:o?s.exactLength.value:void 0,maximum:r?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),i.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(d(t,{code:u.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),i.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(d(t,{code:u.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),i.dirty()),t.common.async)return Promise.all([...t.data].map((r,o)=>s.type._parseAsync(new H(t,r,t.path,o)))).then(r=>I.mergeArray(i,r));const n=[...t.data].map((r,o)=>s.type._parseSync(new H(t,r,t.path,o)));return I.mergeArray(i,n)}get element(){return this._def.type}min(e,t){return new B({...this._def,minLength:{value:e,message:m.toString(t)}})}max(e,t){return new B({...this._def,maxLength:{value:e,message:m.toString(t)}})}length(e,t){return new B({...this._def,exactLength:{value:e,message:m.toString(t)}})}nonempty(e){return this.min(1,e)}}B.create=(a,e)=>new B({type:a,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,..._(e)});function pe(a){if(a instanceof P){const e={};for(const t in a.shape){const i=a.shape[t];e[t]=W.create(pe(i))}return new P({...a._def,shape:()=>e})}else return a instanceof B?new B({...a._def,type:pe(a.element)}):a instanceof W?W.create(pe(a.unwrap())):a instanceof ie?ie.create(pe(a.unwrap())):a instanceof $?$.create(a.items.map(e=>pe(e))):a}class P extends b{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=C.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==f.object){const c=this._getOrReturnCtx(e);return d(c,{code:u.invalid_type,expected:f.object,received:c.parsedType}),x}const{status:i,ctx:s}=this._processInputParams(e),{shape:n,keys:r}=this._getCached(),o=[];if(!(this._def.catchall instanceof Q&&this._def.unknownKeys==="strip"))for(const c in s.data)r.includes(c)||o.push(c);const h=[];for(const c of r){const l=n[c],g=s.data[c];h.push({key:{status:"valid",value:c},value:l._parse(new H(s,g,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof Q){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of o)h.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(c==="strict")o.length>0&&(d(s,{code:u.unrecognized_keys,keys:o}),i.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of o){const g=s.data[l];h.push({key:{status:"valid",value:l},value:c._parse(new H(s,g,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of h){const g=await l.key,p=await l.value;c.push({key:g,value:p,alwaysSet:l.alwaysSet})}return c}).then(c=>I.mergeObjectSync(i,c)):I.mergeObjectSync(i,h)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new P({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,i)=>{var s,n,r,o;const h=(r=(n=(s=this._def).errorMap)===null||n===void 0?void 0:n.call(s,t,i).message)!==null&&r!==void 0?r:i.defaultError;return t.code==="unrecognized_keys"?{message:(o=m.errToObj(e).message)!==null&&o!==void 0?o:h}:{message:h}}}:{}})}strip(){return new P({...this._def,unknownKeys:"strip"})}passthrough(){return new P({...this._def,unknownKeys:"passthrough"})}extend(e){return new P({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new P({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new P({...this._def,catchall:e})}pick(e){const t={};return C.objectKeys(e).forEach(i=>{e[i]&&this.shape[i]&&(t[i]=this.shape[i])}),new P({...this._def,shape:()=>t})}omit(e){const t={};return C.objectKeys(this.shape).forEach(i=>{e[i]||(t[i]=this.shape[i])}),new P({...this._def,shape:()=>t})}deepPartial(){return pe(this)}partial(e){const t={};return C.objectKeys(this.shape).forEach(i=>{const s=this.shape[i];e&&!e[i]?t[i]=s:t[i]=s.optional()}),new P({...this._def,shape:()=>t})}required(e){const t={};return C.objectKeys(this.shape).forEach(i=>{if(e&&!e[i])t[i]=this.shape[i];else{let n=this.shape[i];for(;n instanceof W;)n=n._def.innerType;t[i]=n}}),new P({...this._def,shape:()=>t})}keyof(){return wt(C.objectKeys(this.shape))}}P.create=(a,e)=>new P({shape:()=>a,unknownKeys:"strip",catchall:Q.create(),typeName:v.ZodObject,..._(e)}),P.strictCreate=(a,e)=>new P({shape:()=>a,unknownKeys:"strict",catchall:Q.create(),typeName:v.ZodObject,..._(e)}),P.lazycreate=(a,e)=>new P({shape:a,unknownKeys:"strip",catchall:Q.create(),typeName:v.ZodObject,..._(e)});class Ie extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i=this._def.options;function s(n){for(const o of n)if(o.result.status==="valid")return o.result;for(const o of n)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const r=n.map(o=>new N(o.ctx.common.issues));return d(t,{code:u.invalid_union,unionErrors:r}),x}if(t.common.async)return Promise.all(i.map(async n=>{const r={...t,common:{...t.common,issues:[]},parent:null};return{result:await n._parseAsync({data:t.data,path:t.path,parent:r}),ctx:r}})).then(s);{let n;const r=[];for(const h of i){const c={...t,common:{...t.common,issues:[]},parent:null},l=h._parseSync({data:t.data,path:t.path,parent:c});if(l.status==="valid")return l;l.status==="dirty"&&!n&&(n={result:l,ctx:c}),c.common.issues.length&&r.push(c.common.issues)}if(n)return t.common.issues.push(...n.ctx.common.issues),n.result;const o=r.map(h=>new N(h));return d(t,{code:u.invalid_union,unionErrors:o}),x}}get options(){return this._def.options}}Ie.create=(a,e)=>new Ie({options:a,typeName:v.ZodUnion,..._(e)});const V=a=>a instanceof Me?V(a.schema):a instanceof U?V(a.innerType()):a instanceof Fe?[a.value]:a instanceof te?a.options:a instanceof Ne?C.objectValues(a.enum):a instanceof De?V(a._def.innerType):a instanceof Re?[void 0]:a instanceof ze?[null]:a instanceof W?[void 0,...V(a.unwrap())]:a instanceof ie?[null,...V(a.unwrap())]:a instanceof _t||a instanceof He?V(a.unwrap()):a instanceof Ze?V(a._def.innerType):[];class Je extends b{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.object)return d(t,{code:u.invalid_type,expected:f.object,received:t.parsedType}),x;const i=this.discriminator,s=t.data[i],n=this.optionsMap.get(s);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(d(t,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[i]}),x)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,i){const s=new Map;for(const n of t){const r=V(n.shape[e]);if(!r.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of r){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,n)}}return new Je({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,..._(i)})}}function et(a,e){const t=G(a),i=G(e);if(a===e)return{valid:!0,data:a};if(t===f.object&&i===f.object){const s=C.objectKeys(e),n=C.objectKeys(a).filter(o=>s.indexOf(o)!==-1),r={...a,...e};for(const o of n){const h=et(a[o],e[o]);if(!h.valid)return{valid:!1};r[o]=h.data}return{valid:!0,data:r}}else if(t===f.array&&i===f.array){if(a.length!==e.length)return{valid:!1};const s=[];for(let n=0;n<a.length;n++){const r=a[n],o=e[n],h=et(r,o);if(!h.valid)return{valid:!1};s.push(h.data)}return{valid:!0,data:s}}else return t===f.date&&i===f.date&&+a==+e?{valid:!0,data:a}:{valid:!1}}class Le extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e),s=(n,r)=>{if(pt(n)||pt(r))return x;const o=et(n.value,r.value);return o.valid?((mt(n)||mt(r))&&t.dirty(),{status:t.value,value:o.data}):(d(i,{code:u.invalid_intersection_types}),x)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([n,r])=>s(n,r)):s(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}Le.create=(a,e,t)=>new Le({left:a,right:e,typeName:v.ZodIntersection,..._(t)});class $ extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.array)return d(i,{code:u.invalid_type,expected:f.array,received:i.parsedType}),x;if(i.data.length<this._def.items.length)return d(i,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),x;!this._def.rest&&i.data.length>this._def.items.length&&(d(i,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const n=[...i.data].map((r,o)=>{const h=this._def.items[o]||this._def.rest;return h?h._parse(new H(i,r,i.path,o)):null}).filter(r=>!!r);return i.common.async?Promise.all(n).then(r=>I.mergeArray(t,r)):I.mergeArray(t,n)}get items(){return this._def.items}rest(e){return new $({...this._def,rest:e})}}$.create=(a,e)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new $({items:a,typeName:v.ZodTuple,rest:null,..._(e)})};class Ee extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.object)return d(i,{code:u.invalid_type,expected:f.object,received:i.parsedType}),x;const s=[],n=this._def.keyType,r=this._def.valueType;for(const o in i.data)s.push({key:n._parse(new H(i,o,i.path,o)),value:r._parse(new H(i,i.data[o],i.path,o)),alwaysSet:o in i.data});return i.common.async?I.mergeObjectAsync(t,s):I.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,i){return t instanceof b?new Ee({keyType:e,valueType:t,typeName:v.ZodRecord,..._(i)}):new Ee({keyType:j.create(),valueType:e,typeName:v.ZodRecord,..._(t)})}}class tt extends b{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.map)return d(i,{code:u.invalid_type,expected:f.map,received:i.parsedType}),x;const s=this._def.keyType,n=this._def.valueType,r=[...i.data.entries()].map(([o,h],c)=>({key:s._parse(new H(i,o,i.path,[c,"key"])),value:n._parse(new H(i,h,i.path,[c,"value"]))}));if(i.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const h of r){const c=await h.key,l=await h.value;if(c.status==="aborted"||l.status==="aborted")return x;(c.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(c.value,l.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const h of r){const c=h.key,l=h.value;if(c.status==="aborted"||l.status==="aborted")return x;(c.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(c.value,l.value)}return{status:t.value,value:o}}}}tt.create=(a,e,t)=>new tt({valueType:e,keyType:a,typeName:v.ZodMap,..._(t)});class me extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==f.set)return d(i,{code:u.invalid_type,expected:f.set,received:i.parsedType}),x;const s=this._def;s.minSize!==null&&i.data.size<s.minSize.value&&(d(i,{code:u.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&i.data.size>s.maxSize.value&&(d(i,{code:u.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const n=this._def.valueType;function r(h){const c=new Set;for(const l of h){if(l.status==="aborted")return x;l.status==="dirty"&&t.dirty(),c.add(l.value)}return{status:t.value,value:c}}const o=[...i.data.values()].map((h,c)=>n._parse(new H(i,h,i.path,c)));return i.common.async?Promise.all(o).then(h=>r(h)):r(o)}min(e,t){return new me({...this._def,minSize:{value:e,message:m.toString(t)}})}max(e,t){return new me({...this._def,maxSize:{value:e,message:m.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}me.create=(a,e)=>new me({valueType:a,minSize:null,maxSize:null,typeName:v.ZodSet,..._(e)});class Ce extends b{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.function)return d(t,{code:u.invalid_type,expected:f.function,received:t.parsedType}),x;function i(o,h){return We({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Ue(),xe].filter(c=>!!c),issueData:{code:u.invalid_arguments,argumentsError:h}})}function s(o,h){return We({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Ue(),xe].filter(c=>!!c),issueData:{code:u.invalid_return_type,returnTypeError:h}})}const n={errorMap:t.common.contextualErrorMap},r=t.data;if(this._def.returns instanceof Se){const o=this;return E(async function(...h){const c=new N([]),l=await o._def.args.parseAsync(h,n).catch(k=>{throw c.addIssue(i(h,k)),c}),g=await Reflect.apply(r,this,l);return await o._def.returns._def.type.parseAsync(g,n).catch(k=>{throw c.addIssue(s(g,k)),c})})}else{const o=this;return E(function(...h){const c=o._def.args.safeParse(h,n);if(!c.success)throw new N([i(h,c.error)]);const l=Reflect.apply(r,this,c.data),g=o._def.returns.safeParse(l,n);if(!g.success)throw new N([s(l,g.error)]);return g.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Ce({...this._def,args:$.create(e).rest(fe.create())})}returns(e){return new Ce({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,i){return new Ce({args:e||$.create([]).rest(fe.create()),returns:t||fe.create(),typeName:v.ZodFunction,..._(i)})}}class Me extends b{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Me.create=(a,e)=>new Me({getter:a,typeName:v.ZodLazy,..._(e)});class Fe extends b{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return d(t,{received:t.data,code:u.invalid_literal,expected:this._def.value}),x}return{status:"valid",value:e.data}}get value(){return this._def.value}}Fe.create=(a,e)=>new Fe({value:a,typeName:v.ZodLiteral,..._(e)});function wt(a,e){return new te({values:a,typeName:v.ZodEnum,..._(e)})}class te extends b{constructor(){super(...arguments),_e.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),i=this._def.values;return d(t,{expected:C.joinValues(i),received:t.parsedType,code:u.invalid_type}),x}if(Pe(this,_e)||gt(this,_e,new Set(this._def.values)),!Pe(this,_e).has(e.data)){const t=this._getOrReturnCtx(e),i=this._def.values;return d(t,{received:t.data,code:u.invalid_enum_value,options:i}),x}return E(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return te.create(e,{...this._def,...t})}exclude(e,t=this._def){return te.create(this.options.filter(i=>!e.includes(i)),{...this._def,...t})}}_e=new WeakMap,te.create=wt;class Ne extends b{constructor(){super(...arguments),ke.set(this,void 0)}_parse(e){const t=C.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(e);if(i.parsedType!==f.string&&i.parsedType!==f.number){const s=C.objectValues(t);return d(i,{expected:C.joinValues(s),received:i.parsedType,code:u.invalid_type}),x}if(Pe(this,ke)||gt(this,ke,new Set(C.getValidEnumValues(this._def.values))),!Pe(this,ke).has(e.data)){const s=C.objectValues(t);return d(i,{received:i.data,code:u.invalid_enum_value,options:s}),x}return E(e.data)}get enum(){return this._def.values}}ke=new WeakMap,Ne.create=(a,e)=>new Ne({values:a,typeName:v.ZodNativeEnum,..._(e)});class Se extends b{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.promise&&t.common.async===!1)return d(t,{code:u.invalid_type,expected:f.promise,received:t.parsedType}),x;const i=t.parsedType===f.promise?t.data:Promise.resolve(t.data);return E(i.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Se.create=(a,e)=>new Se({type:a,typeName:v.ZodPromise,..._(e)});class U extends b{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:i}=this._processInputParams(e),s=this._def.effect||null,n={addIssue:r=>{d(i,r),r.fatal?t.abort():t.dirty()},get path(){return i.path}};if(n.addIssue=n.addIssue.bind(n),s.type==="preprocess"){const r=s.transform(i.data,n);if(i.common.async)return Promise.resolve(r).then(async o=>{if(t.value==="aborted")return x;const h=await this._def.schema._parseAsync({data:o,path:i.path,parent:i});return h.status==="aborted"?x:h.status==="dirty"||t.value==="dirty"?we(h.value):h});{if(t.value==="aborted")return x;const o=this._def.schema._parseSync({data:r,path:i.path,parent:i});return o.status==="aborted"?x:o.status==="dirty"||t.value==="dirty"?we(o.value):o}}if(s.type==="refinement"){const r=o=>{const h=s.refinement(o,n);if(i.common.async)return Promise.resolve(h);if(h instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(i.common.async===!1){const o=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return o.status==="aborted"?x:(o.status==="dirty"&&t.dirty(),r(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(o=>o.status==="aborted"?x:(o.status==="dirty"&&t.dirty(),r(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(i.common.async===!1){const r=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!he(r))return r;const o=s.transform(r.value,n);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(r=>he(r)?Promise.resolve(s.transform(r.value,n)).then(o=>({status:t.value,value:o})):r);C.assertNever(s)}}U.create=(a,e,t)=>new U({schema:a,typeName:v.ZodEffects,effect:e,..._(t)}),U.createWithPreprocess=(a,e,t)=>new U({schema:e,effect:{type:"preprocess",transform:a},typeName:v.ZodEffects,..._(t)});class W extends b{_parse(e){return this._getType(e)===f.undefined?E(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}W.create=(a,e)=>new W({innerType:a,typeName:v.ZodOptional,..._(e)});class ie extends b{_parse(e){return this._getType(e)===f.null?E(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ie.create=(a,e)=>new ie({innerType:a,typeName:v.ZodNullable,..._(e)});class De extends b{_parse(e){const{ctx:t}=this._processInputParams(e);let i=t.data;return t.parsedType===f.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}De.create=(a,e)=>new De({innerType:a,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class Ze extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return Ae(s)?s.then(n=>({status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new N(i.common.issues)},input:i.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new N(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}Ze.create=(a,e)=>new Ze({innerType:a,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class it extends b{_parse(e){if(this._getType(e)!==f.nan){const i=this._getOrReturnCtx(e);return d(i,{code:u.invalid_type,expected:f.nan,received:i.parsedType}),x}return{status:"valid",value:e.data}}}it.create=a=>new it({typeName:v.ZodNaN,..._(a)});class _t extends b{_parse(e){const{ctx:t}=this._processInputParams(e),i=t.data;return this._def.type._parse({data:i,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ke extends b{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.common.async)return(async()=>{const n=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return n.status==="aborted"?x:n.status==="dirty"?(t.dirty(),we(n.value)):this._def.out._parseAsync({data:n.value,path:i.path,parent:i})})();{const s=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?x:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:i.path,parent:i})}}static create(e,t){return new Ke({in:e,out:t,typeName:v.ZodPipeline})}}class He extends b{_parse(e){const t=this._def.innerType._parse(e),i=s=>(he(s)&&(s.value=Object.freeze(s.value)),s);return Ae(t)?t.then(s=>i(s)):i(t)}unwrap(){return this._def.innerType}}He.create=(a,e)=>new He({innerType:a,typeName:v.ZodReadonly,..._(e)}),P.lazycreate;var v;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(v||(v={}));const L=j.create,y=ue.create;it.create,de.create,Xe.create,be.create,qe.create,Re.create,ze.create,Ge.create,fe.create,Q.create,Qe.create,B.create;const T=P.create;P.strictCreate;const pi=Ie.create;Je.create,Le.create,$.create,Ee.create,tt.create,me.create,Ce.create,Me.create;const se=Fe.create,J=te.create;Ne.create,Se.create,U.create,W.create,ie.create,U.createWithPreprocess,Ke.create;const mi=J(["linear","bezier","constant"]),gi=J(["ease","easeIn","easeOut","easeInOut","easeInQuad","easeInCubic","easeInQuart","easeInQuint","easeInSine","easeInExpo","easeInCirc","easeInBack","easeOutQuad","easeOutCubic","easeOutQuart","easeOutQuint","easeOutSine","easeOutExpo","easeOutCirc","easeOutBack","easeInOutQuad","easeInOutCubic","easeInOutQuart","easeInOutQuint","easeInOutSine","easeInOutExpo","easeInOutCirc","easeInOutBack"]),ne=T({from:y(),to:y(),start:y().min(0),length:y().positive(),interpolation:mi.optional(),easing:gi.optional()}),yi=L().url("Invalid audio url format."),vi=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),kt=T({type:se("audio"),src:yi,trim:y().optional(),volume:vi.optional()}),xi=J(["top","topRight","right","bottomRight","bottom","bottomLeft","left","topLeft","center"]),bt=T({type:se("html"),html:L(),css:L(),width:y().positive().optional(),height:y().positive().optional(),position:xi.optional()}),wi=L().url("Invalid image url format."),_i=T({top:y().min(0).optional(),right:y().min(0).optional(),bottom:y().min(0).optional(),left:y().min(0).optional()}),Ct=T({type:se("image"),src:wi,crop:_i.optional()}),ki=L().url("Invalid luma url format."),St=T({type:se("luma"),src:ki}),Tt=L().regex(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|transparent$/,"Invalid color format."),Ot=T({width:y().positive(),height:y().positive()}),At=T({radius:y().positive()}),Pt=T({length:y().positive(),thickness:y().positive()}),bi=T({color:Tt,opacity:y().min(0).max(1)}),Ci=T({color:Tt,width:y().positive()}),Rt=T({type:se("shape"),width:y().positive().optional(),height:y().positive().optional(),shape:J(["rectangle","circle","line"]),fill:bi.optional(),stroke:Ci.optional(),rectangle:Ot.optional(),circle:At.optional(),line:Pt.optional()}).refine(a=>a.shape==="rectangle"?Ot.safeParse(a.rectangle):a.shape==="circle"?At.safeParse(a.circle):a.shape==="line"?Pt.safeParse(a.line):!1),st=L().regex(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|transparent$/,"Invalid color format."),Si=T({color:st.optional(),family:L().optional(),size:y().positive().optional(),weight:y().optional(),lineHeight:y().optional()}),Ti=T({horizontal:J(["left","center","right"]).optional(),vertical:J(["top","center","bottom"]).optional()}),Oi=T({color:st,opacity:y().min(0).max(1)}),Ai=T({width:y().positive(),color:st}),zt=T({type:se("text"),text:L(),width:y().positive().optional(),height:y().positive().optional(),font:Si.optional(),alignment:Ti.optional(),background:Oi.optional(),stroke:Ai.optional()}),Pi=L().url("Invalid video url format."),Ri=T({top:y().min(0).optional(),right:y().min(0).optional(),bottom:y().min(0).optional(),left:y().min(0).optional()}),zi=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),It=T({type:se("video"),src:Pi,trim:y().optional(),crop:Ri.optional(),volume:zi.optional()}),Ii=pi([zt,Rt,bt,Ct,It,St,kt]).refine(a=>a.type==="text"?zt.safeParse(a):a.type==="shape"?Rt.safeParse(a):a.type==="html"?bt.safeParse(a):a.type==="image"?Ct.safeParse(a):a.type==="video"?It.safeParse(a):a.type==="luma"?St.safeParse(a):a.type==="audio"?kt.safeParse(a):!1),Li=J(["topLeft","top","topRight","left","center","right","bottomLeft","bottom","bottomRight"]),Ei=J(["crop","cover","contain","none"]),ge=y().min(-10).max(10).default(0),Mi=ne.extend({from:ge,to:ge}).array().or(ge),Fi=ne.extend({from:ge,to:ge}).array().or(ge),Ni=T({x:Mi.default(0),y:Fi.default(0)}),Di=ne.extend({from:y().min(0).max(1),to:y().min(0).max(1)}).array().or(y().min(0).max(1)),Zi=ne.extend({from:y().min(0),to:y().min(0)}).array().or(y().min(0)),Ki=T({angle:ne.extend({from:y(),to:y()}).array().or(y())}),Hi=L(),Lt=L(),Bi=T({in:Lt.optional(),out:Lt.optional()}),ji=T({rotate:Ki.default({angle:0})}),Et=T({asset:Ii,start:y().min(0),length:y().positive(),position:Li.default("center").optional(),fit:Ei.default("crop").optional(),offset:Ni.default({x:0,y:0}).optional(),opacity:Di.default(1).optional(),scale:Zi.default(1).optional(),transform:ji.default({rotate:{angle:0}}).optional(),effect:Hi.optional(),transition:Bi.optional()}),Vi=T({clips:Et.array()}),$i=L().url("Invalid image url format."),Ui=T({src:$i}),Wi=T({background:L().optional(),fonts:Ui.array().optional(),tracks:Vi.array()}),Yi=T({size:T({width:y().positive(),height:y().positive()}),fps:y().positive().optional(),format:L()}),Xi=T({timeline:Wi,output:Yi});class qi{curves={};constructor(){this.initializeCurves()}initializeCurves(){this.curves={ease:[[.25,.1],[.25,1]],easeIn:[[.42,0],[1,1]],easeOut:[[0,0],[.58,1]],easeInOut:[[.42,0],[.58,1]],easeInQuad:[[.55,.085],[.68,.53]],easeInCubic:[[.55,.055],[.675,.19]],easeInQuart:[[.895,.03],[.685,.22]],easeInQuint:[[.755,.05],[.855,.06]],easeInSine:[[.47,0],[.745,.715]],easeInExpo:[[.95,.05],[.795,.035]],easeInCirc:[[.6,.04],[.98,.335]],easeInBack:[[.6,-.28],[.735,.045]],easeOutQuad:[[.25,.46],[.45,.94]],easeOutCubic:[[.215,.61],[.355,1]],easeOutQuart:[[.165,.84],[.44,1]],easeOutQuint:[[.23,1],[.32,1]],easeOutSine:[[.39,.575],[.565,1]],easeOutExpo:[[.19,1],[.22,1]],easeOutCirc:[[.075,.82],[.165,1]],easeOutBack:[[.175,.885],[.32,1.275]],easeInOutQuad:[[.455,.03],[.515,.955]],easeInOutCubic:[[.645,.045],[.355,1]],easeInOutQuart:[[.77,0],[.175,1]],easeInOutQuint:[[.86,0],[.07,1]],easeInOutSine:[[.445,.05],[.55,.95]],easeInOutExpo:[[1,0],[0,1]],easeInOutCirc:[[.785,.135],[.15,.86]],easeInOutBack:[[.68,-.55],[.265,1.55]]}}getValue(e,t,i,s){const n=this.curves[s??""]??this.curves.ease,[[r,o],[h,c]]=n,l=i+(3*r-3*h+1)*i*(1-i),g=e,p=e+(t-e)*o,k=e+(t-e)*c,A=t,S=l,D=1-S;return D**3*g+3*D**2*S*p+3*D*S**2*k+S**3*A}}class R{property;length;cubicBuilder;constructor(e,t,i=0){this.property=this.createKeyframes(e,t,i),this.length=t,this.cubicBuilder=new qi}getValue(e){const t=this.property.find(s=>e>=s.start&&e<s.start+s.length);if(!t){if(this.property.length>0){if(e>=this.length)return this.property[this.property.length-1].to;if(e<0)return this.property[0].from}return 1}const i=(e-t.start)/t.length;switch(t.interpolation){case"bezier":return this.cubicBuilder.getValue(t.from,t.to,i,t.easing);case"constant":return t.from;case"linear":default:return t.from+(t.to-t.from)*i}}createKeyframes(e,t,i=0){if(typeof e=="number")return[{start:0,length:t,from:e,to:e}];if(!e.length)throw new Error("Keyframes should have at least one value.");const s=this.createNormalizedKeyframes(e);try{this.validateKeyframes(s)}catch(n){console.warn("Keyframe configuration issues detected:",n)}return this.insertFillerKeyframes(s,t,i)}createNormalizedKeyframes(e){return e.toSorted((t,i)=>t.start-i.start).map(t=>({...t,start:t.start*1e3,length:t.length*1e3}))}validateKeyframes(e){for(let t=0;t<e.length;t+=1){const i=e[t],s=e[t+1];if(!s){if(i.start+i.length>this.length)throw new Error("Last keyframe exceeds the maximum duration.");break}if(i.start+i.length>s.start)throw new Error("Overlapping keyframes detected.")}}insertFillerKeyframes(e,t,i=0){const s=[];for(let n=0;n<e.length;n+=1){const r=e[n],o=e[n+1];if(n===0&&r.start!==0){const l={start:0,length:r.start,from:i,to:r.from};s.push(l)}if(s.push(r),!o){if(r.start+r.length<t){const g=r.start+r.length,p={start:g,length:t-g,from:r.to,to:r.to};s.push(p)}break}if(r.start+r.length!==o.start){const l={start:r.start+r.length,length:o.start,from:r.to,to:o.from};s.push(l)}}return s}}class Be{static Name="AudioLoadParser";name;extension;validAudioExtensions;constructor(){this.name=Be.Name,this.extension={type:[w.ExtensionType.LoadParser],priority:w.LoaderParserPriority.Normal,ref:null},this.validAudioExtensions=["mp3","mpeg","ogg","wav"]}test(e){const t=e.split("?")[0]?.split(".").pop()??"";return this.validAudioExtensions.includes(t)}async load(e,t,i){return new Promise(s=>{const n={src:e},r=new Howl(n);r.on("load",()=>s(r)),r.on("loaderror",()=>s(null))})}unload(e){e?.unload()}}class Gi{clipConfiguration;constructor(e){this.clipConfiguration=e}build(e,t){const i=[],s=[],n=[],r=[],o=[],{effect:h,length:c}=this.clipConfiguration;if(!h)return{offsetXKeyframes:i,offsetYKeyframes:s,opacityKeyframes:n,scaleKeyframes:r,rotationKeyframes:o};const l=0;switch(this.getPresetName()){case"zoomIn":{const p=this.getZoomSpeed(),k=1*this.clipConfiguration.scale,A=p*this.clipConfiguration.scale;r.push({from:k,to:A,start:l,length:c,interpolation:"linear"});break}case"zoomOut":{const k=this.getZoomSpeed()*this.clipConfiguration.scale,A=1*this.clipConfiguration.scale;r.push({from:k,to:A,start:l,length:c,interpolation:"linear"});break}case"slideLeft":{let p=this.getSlideStart();const k=e.width+e.width*p*2,A=t.height/t.width*e.height;if(A<k){const S=Math.abs(k/e.width);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.width)/2/e.width;i.push({from:p,to:-p,start:l,length:c});break}case"slideRight":{let p=this.getSlideStart();const k=e.width+e.width*p*2,A=t.height/t.width*e.height;if(A<k){const S=Math.abs(k/e.width);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.width)/2/e.width;i.push({from:-p,to:p,start:l,length:c});break}case"slideUp":{let p=this.getSlideStart();const k=e.height+e.height*p*2,A=t.height/t.width*e.width;if(A<k){const S=Math.abs(k/e.height);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.height)/2/e.height;s.push({from:p,to:-p,start:l,length:c});break}case"slideDown":{let p=this.getSlideStart();const k=e.height+e.height*p*2,A=t.height/t.width*e.width;if(A<k){const S=Math.abs(k/e.height);r.push({from:S,to:S,start:l,length:c,interpolation:"linear"})}else p=(A-e.height)/2/e.height;s.push({from:-p,to:p,start:l,length:c});break}}return{offsetXKeyframes:i,offsetYKeyframes:s,opacityKeyframes:n,scaleKeyframes:r,rotationKeyframes:o}}getPresetName(){const[e]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);return e}getZoomSpeed(){const[e,t]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);if(e.startsWith("zoom"))switch(t){case"Slow":return 1.1;case"Fast":return 1.7;default:return 1.3}return 0}getSlideStart(){const[e,t]=(this.clipConfiguration.effect??"").split(/(Slow|Fast)/);if(e.startsWith("slide"))switch(t){case"Slow":return .03;case"Fast":return 1.7;default:return .12}return 0}}class Qi{clipConfiguration;constructor(e){this.clipConfiguration=e}build(){const e=[],t=[],i=[],s=[],n=[],r=this.buildInPreset();e.push(...r.offsetXKeyframes),t.push(...r.offsetYKeyframes),i.push(...r.opacityKeyframes),s.push(...r.scaleKeyframes),n.push(...r.rotationKeyframes);const o=this.buildOutPreset();return e.push(...o.offsetXKeyframes),t.push(...o.offsetYKeyframes),i.push(...o.opacityKeyframes),s.push(...o.scaleKeyframes),n.push(...o.rotationKeyframes),{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}buildInPreset(){const e=[],t=[],i=[],s=[],n=[];if(!this.clipConfiguration.transition?.in)return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n};const r=0,o=this.getInPresetLength();switch(this.getInPresetName()){case"fade":{const l=Math.max(0,Math.min(this.clipConfiguration.opacity??1,1));i.push({from:0,to:l,start:r,length:o,interpolation:"linear"});break}case"zoom":{const l=this.clipConfiguration.scale+9,g=this.clipConfiguration.scale;s.push({from:l,to:g,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideLeft":{const c=this.clipConfiguration.offset?.x+.025,l=this.clipConfiguration.offset?.x;e.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideRight":{const c=this.clipConfiguration.offset?.x-.025,l=this.clipConfiguration.offset?.x;e.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideUp":{const c=this.clipConfiguration.offset?.y+.025,l=this.clipConfiguration.offset?.y;t.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeIn"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeIn"});break}case"slideDown":{const c=this.clipConfiguration.offset?.y-.025,l=this.clipConfiguration.offset?.y;t.push({from:c,to:l,start:r,length:o,interpolation:"bezier",easing:"easeOut"}),i.push({from:0,to:1,start:r,length:o,interpolation:"bezier",easing:"easeOut"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":case"shuffleTopRight":case"shuffleRightTop":case"shuffleRightBottom":case"shuffleBottomRight":case"shuffleBottomLeft":case"shuffleLeftBottom":case"shuffleLeftTop":case"shuffleTopLeft":default:console.warn(`Unimplemented transition:in preset "${this.clipConfiguration.transition.in}"`);break}return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}buildOutPreset(){const e=[],t=[],i=[],s=[],n=[];if(!this.clipConfiguration.transition?.out)return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n};const r=this.getOutPresetLength(),o=this.clipConfiguration.length-r;switch(this.getOutPresetName()){case"fade":{const c=Math.max(0,Math.min(this.clipConfiguration.opacity??1,1));i.push({from:c,to:0,start:o,length:r,interpolation:"linear"});break}case"zoom":{const l=this.clipConfiguration.scale,g=l+9;s.push({from:l,to:g,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideLeft":{const c=this.clipConfiguration.offset?.x,l=c-.025;e.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideRight":{const c=this.clipConfiguration.offset?.x,l=c+.025;e.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeOut"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeOut"});break}case"slideUp":{const c=this.clipConfiguration.offset?.y,l=c-.025;t.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeIn"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeIn"});break}case"slideDown":{const c=this.clipConfiguration.offset?.y,l=c+.025;t.push({from:c,to:l,start:o,length:r,interpolation:"bezier",easing:"easeIn"}),i.push({from:1,to:0,start:o,length:r,interpolation:"bezier",easing:"easeIn"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":case"shuffleTopRight":case"shuffleRightTop":case"shuffleRightBottom":case"shuffleBottomRight":case"shuffleBottomLeft":case"shuffleLeftBottom":case"shuffleLeftTop":case"shuffleTopLeft":default:console.warn(`Unimplemented transition:out preset "${this.clipConfiguration.transition.out}"`);break}return{offsetXKeyframes:e,offsetYKeyframes:t,opacityKeyframes:i,scaleKeyframes:s,rotationKeyframes:n}}getInPresetName(){const[e]=(this.clipConfiguration.transition?.in??"").split(/(Slow|Fast|VeryFast)/);return e}getOutPresetName(){const[e]=(this.clipConfiguration.transition?.out??"").split(/(Slow|Fast|VeryFast)/);return e}getInPresetLength(){const[,e]=(this.clipConfiguration.transition?.in??"").split(/(Slow|Fast|VeryFast)/);switch(e){case"Slow":return 2;case"Fast":return .5;case"VeryFast":return .25;default:return 1}}getOutPresetLength(){const[,e]=(this.clipConfiguration.transition?.out??"").split(/(Slow|Fast|VeryFast)/);switch(e){case"Slow":return 2;case"Fast":return .5;case"VeryFast":return .25;default:return 1}}}class Ji{static ButtonLeftClick=0;static ButtonRightClick=3}class es{containerSize;constructor(e){this.containerSize=e}relativeToAbsolute(e,t,i){switch(t){case"topLeft":return{x:i.x*this.containerSize.width,y:-i.y*this.containerSize.height};case"topRight":return{x:(i.x+1)*this.containerSize.width-e.width,y:-i.y*this.containerSize.height};case"bottomLeft":return{x:i.x*this.containerSize.width,y:(-i.y+1)*this.containerSize.height-e.height};case"bottomRight":return{x:(i.x+1)*this.containerSize.width-e.width,y:(-i.y+1)*this.containerSize.height-e.height};case"left":return{x:i.x*this.containerSize.width,y:(-i.y+.5)*this.containerSize.height-e.height/2};case"right":return{x:(i.x+1)*this.containerSize.width-e.width,y:(-i.y+.5)*this.containerSize.height-e.height/2};case"top":return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:-i.y*this.containerSize.height};case"bottom":return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:(-i.y+1)*this.containerSize.height-e.height};case"center":default:return{x:(i.x+.5)*this.containerSize.width-e.width/2,y:(-i.y+.5)*this.containerSize.height-e.height/2}}}absoluteToRelative(e,t,i){switch(t){case"topLeft":return{x:i.x/this.containerSize.width,y:-(i.y/this.containerSize.height)};case"topRight":return{x:(i.x+e.width)/this.containerSize.width-1,y:-(i.y/this.containerSize.height)};case"bottomLeft":return{x:i.x/this.containerSize.width,y:-((i.y+e.height)/this.containerSize.height-1)};case"bottomRight":return{x:(i.x+e.width)/this.containerSize.width-1,y:-((i.y+e.height)/this.containerSize.height-1)};case"left":return{x:i.x/this.containerSize.width,y:-((i.y+e.height/2)/this.containerSize.height-.5)};case"right":return{x:(i.x+e.width)/this.containerSize.width-1,y:-((i.y+e.height/2)/this.containerSize.height-.5)};case"top":return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-(i.y/this.containerSize.height)};case"bottom":return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-((i.y+e.height)/this.containerSize.height-1)};case"center":default:return{x:(i.x+e.width/2)/this.containerSize.width-.5,y:-((i.y+e.height/2)/this.containerSize.height-.5)}}}}class nt{container;constructor(){this.container=new w.Container}getContainer(){return this.container}}class z extends nt{static SnapThreshold=20;static DiscardedFrameCount=Math.ceil(1/30*1e3);static ScaleHandleRadius=10;static RotationHandleRadius=10;static RotationHandleOffset=50;static OutlineWidth=5;static MinScale=.1;static MaxScale=5;layer;shouldDispose;edit;clipConfiguration;positionBuilder;offsetXKeyframeBuilder;offsetYKeyframeBuilder;scaleKeyframeBuilder;opacityKeyframeBuilder;rotationKeyframeBuilder;outline;topLeftScaleHandle;topRightScaleHandle;bottomLeftScaleHandle;bottomRightScaleHandle;rotationHandle;isHovering;isDragging;dragOffset;scaleDirection;scaleStart;scaleOffset;isRotating;rotationStart;rotationOffset;initialClipConfiguration;constructor(e,t){super(),this.edit=e,this.layer=0,this.shouldDispose=!1,this.clipConfiguration=t,this.positionBuilder=new es(e.size),this.outline=null,this.topLeftScaleHandle=null,this.topRightScaleHandle=null,this.bottomRightScaleHandle=null,this.bottomLeftScaleHandle=null,this.rotationHandle=null,this.isHovering=!1,this.isDragging=!1,this.dragOffset={x:0,y:0},this.scaleDirection=null,this.scaleStart=null,this.scaleOffset={x:0,y:0},this.isRotating=!1,this.rotationStart=null,this.rotationOffset={x:0,y:0},this.initialClipConfiguration=null}configureKeyframes(){if(this.offsetXKeyframeBuilder=new R(this.clipConfiguration.offset?.x??0,this.getLength()),this.offsetYKeyframeBuilder=new R(this.clipConfiguration.offset?.y??0,this.getLength()),this.scaleKeyframeBuilder=new R(this.clipConfiguration.scale??1,this.getLength(),1),this.opacityKeyframeBuilder=new R(this.clipConfiguration.opacity??1,this.getLength(),1),this.rotationKeyframeBuilder=new R(this.clipConfiguration.transform?.rotate?.angle??0,this.getLength()),this.clipHasKeyframes())return;const e=[],t=[],i=[],s=[],n=[],r=new Gi(this.clipConfiguration).build(this.edit.size,this.getSize());e.push(...r.offsetXKeyframes),t.push(...r.offsetYKeyframes),i.push(...r.opacityKeyframes),s.push(...r.scaleKeyframes),n.push(...r.rotationKeyframes);const o=new Qi(this.clipConfiguration).build();e.push(...o.offsetXKeyframes),t.push(...o.offsetYKeyframes),i.push(...o.opacityKeyframes),s.push(...o.scaleKeyframes),n.push(...o.rotationKeyframes),e.length&&(this.offsetXKeyframeBuilder=new R(e,this.getLength())),t.length&&(this.offsetYKeyframeBuilder=new R(t,this.getLength())),i.length&&(this.opacityKeyframeBuilder=new R(i,this.getLength(),1)),s.length&&(this.scaleKeyframeBuilder=new R(s,this.getLength(),1)),n.length&&(this.rotationKeyframeBuilder=new R(n,this.getLength()))}async load(){this.outline=new w.Graphics,this.getContainer().addChild(this.outline),this.topLeftScaleHandle=new w.Graphics,this.topRightScaleHandle=new w.Graphics,this.bottomRightScaleHandle=new w.Graphics,this.bottomLeftScaleHandle=new w.Graphics,this.getContainer().addChild(this.topLeftScaleHandle),this.getContainer().addChild(this.topRightScaleHandle),this.getContainer().addChild(this.bottomRightScaleHandle),this.getContainer().addChild(this.bottomLeftScaleHandle),this.rotationHandle=new w.Graphics,this.getContainer().addChild(this.rotationHandle),this.getContainer().cursor="pointer",this.getContainer().eventMode="static",this.getContainer().on("pointerdown",this.onPointerStart.bind(this)),this.getContainer().on("pointermove",this.onPointerMove.bind(this)),this.getContainer().on("globalpointermove",this.onPointerMove.bind(this)),this.getContainer().on("pointerup",this.onPointerUp.bind(this)),this.getContainer().on("pointerupoutside",this.onPointerUp.bind(this)),this.getContainer().on("pointerover",this.onPointerOver.bind(this)),this.getContainer().on("pointerout",this.onPointerOut.bind(this))}update(e,t){if(this.getContainer().visible=this.isActive(),this.getContainer().zIndex=this.layer,!this.isActive())return;const i=this.getPivot(),s=this.getPosition(),n=this.getScale();this.getContainer().scale.set(n),this.getContainer().pivot.set(i.x,i.y),this.getContainer().position.set(s.x+i.x,s.y+i.y);const r=this.getRotation();this.getContainer().alpha=this.getOpacity(),this.getContainer().angle=r,this.shouldDiscardFrame()&&(this.getContainer().alpha=0)}draw(){if(!this.outline)return;if((!this.isActive()||this.edit.getSelectedClip()!==this)&&!this.isHovering){this.outline.clear(),this.topLeftScaleHandle?.clear(),this.topRightScaleHandle?.clear(),this.bottomRightScaleHandle?.clear(),this.bottomLeftScaleHandle?.clear(),this.rotationHandle?.clear();return}const e=this.isHovering||this.isDragging?65535:16777215,t=this.getSize(),i=this.getScale();if(this.outline.clear(),this.outline.strokeStyle={width:z.OutlineWidth/i,color:e},this.outline.rect(0,0,t.width,t.height),this.outline.stroke(),!this.topLeftScaleHandle||!this.topRightScaleHandle||!this.bottomRightScaleHandle||!this.bottomLeftScaleHandle||!this.isActive()||this.edit.getSelectedClip()!==this)return;this.topLeftScaleHandle.fillStyle={color:e},this.topLeftScaleHandle.clear();const s=z.ScaleHandleRadius*2/i;if(this.topLeftScaleHandle.rect(-s/2,-s/2,s,s),this.topLeftScaleHandle.fill(),this.topRightScaleHandle.fillStyle={color:e},this.topRightScaleHandle.clear(),this.topRightScaleHandle.rect(t.width-s/2,-s/2,s,s),this.topRightScaleHandle.fill(),this.bottomRightScaleHandle.fillStyle={color:e},this.bottomRightScaleHandle.clear(),this.bottomRightScaleHandle.rect(t.width-s/2,t.height-s/2,s,s),this.bottomRightScaleHandle.fill(),this.bottomLeftScaleHandle.fillStyle={color:e},this.bottomLeftScaleHandle.clear(),this.bottomLeftScaleHandle.rect(-s/2,t.height-s/2,s,s),this.bottomLeftScaleHandle.fill(),!this.rotationHandle)return;const n=t.width/2,r=-50/i;this.rotationHandle.clear(),this.rotationHandle.fillStyle={color:e},this.rotationHandle.circle(n,r,z.RotationHandleRadius/i),this.rotationHandle.fill(),this.outline.strokeStyle={width:z.OutlineWidth/i,color:e},this.outline.moveTo(n,0),this.outline.lineTo(n,r),this.outline.stroke()}dispose(){this.outline?.destroy(),this.outline=null,this.topLeftScaleHandle?.destroy(),this.topLeftScaleHandle=null,this.topRightScaleHandle?.destroy(),this.topRightScaleHandle=null,this.bottomLeftScaleHandle?.destroy(),this.bottomLeftScaleHandle=null,this.bottomRightScaleHandle?.destroy(),this.bottomRightScaleHandle=null,this.rotationHandle?.destroy(),this.rotationHandle=null}getStart(){return this.clipConfiguration.start*1e3}getLength(){return this.clipConfiguration.length*1e3}getEnd(){return this.getStart()+this.getLength()}getPlaybackTime(){const e=this.edit.playbackTime-this.getStart();return e<0?0:e>this.getLength()?this.getLength():e}getOpacity(){return this.opacityKeyframeBuilder?.getValue(this.getPlaybackTime())??1}getPosition(){const e={x:this.offsetXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.offsetYKeyframeBuilder?.getValue(this.getPlaybackTime())??0};return this.positionBuilder.relativeToAbsolute(this.getSize(),this.clipConfiguration.position??"center",e)}getPivot(){const e=this.getSize();return{x:e.width/2,y:e.height/2}}getFitScale(){switch(this.clipConfiguration.fit??"crop"){case"crop":return Math.max(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"cover":return Math.max(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"contain":return Math.min(this.edit.size.width/this.getSize().width,this.edit.size.height/this.getSize().height);case"none":default:return 1}}getScale(){return(this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1)*this.getFitScale()}getRotation(){return this.rotationKeyframeBuilder?.getValue(this.getPlaybackTime())??0}isActive(){return this.edit.playbackTime>=this.getStart()&&this.edit.playbackTime<this.getEnd()}shouldDiscardFrame(){return this.getPlaybackTime()<z.DiscardedFrameCount}onPointerStart(e){if(e.button!==Ji.ButtonLeftClick||(this.edit.setSelectedClip(this),this.initialClipConfiguration=structuredClone(this.clipConfiguration),this.clipHasKeyframes()))return;if(this.scaleDirection=null,this.topLeftScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="topLeft"),this.topRightScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="topRight"),this.bottomRightScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="bottomRight"),this.bottomLeftScaleHandle?.getBounds().containsPoint(e.globalX,e.globalY)&&(this.scaleDirection="bottomLeft"),this.scaleDirection!==null){this.scaleStart=this.getScale()/this.getFitScale();const h=e.getLocalPosition(this.edit.getContainer());this.scaleOffset=h;return}if(this.rotationHandle?.getBounds().containsPoint(e.globalX,e.globalY)){this.isRotating=!0,this.rotationStart=this.getRotation();const h=e.getLocalPosition(this.edit.getContainer());this.rotationOffset=h;return}this.isDragging=!0;const o=e.getLocalPosition(this.edit.getContainer());this.dragOffset={x:o.x-this.getContainer().position.x,y:o.y-this.getContainer().position.y}}onPointerMove(e){if(this.scaleDirection!==null&&this.scaleStart!==null){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPosition(),s=this.getPivot(),n={x:i.x+s.x,y:i.y+s.y},r=Math.sqrt((this.scaleOffset.x-n.x)**2+(this.scaleOffset.y-n.y)**2),h=Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)/r,c=this.scaleStart*h;this.clipConfiguration.scale=Math.max(z.MinScale,Math.min(c,z.MaxScale)),this.scaleKeyframeBuilder=new R(this.clipConfiguration.scale,this.getLength(),1);return}if(this.isRotating&&this.rotationStart!==null){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPosition(),s=this.getPivot(),n={x:i.x+s.x,y:i.y+s.y},r=Math.atan2(this.rotationOffset.y-n.y,this.rotationOffset.x-n.x),h=(Math.atan2(t.y-n.y,t.x-n.x)-r)*(180/Math.PI);let c=this.rotationStart+h;const l=45,g=c%l,p=2;Math.abs(g)<p?c=Math.floor(c/l)*l:Math.abs(g-l)<p&&(c=Math.ceil(c/l)*l),this.clipConfiguration.transform||(this.clipConfiguration.transform={rotate:{angle:0}}),this.clipConfiguration.transform.rotate||(this.clipConfiguration.transform.rotate={angle:0}),this.clipConfiguration.transform.rotate.angle=c,this.rotationKeyframeBuilder=new R(this.clipConfiguration.transform.rotate.angle,this.getLength());return}if(this.isDragging){const t=e.getLocalPosition(this.edit.getContainer()),i=this.getPivot(),s={x:t.x-this.dragOffset.x,y:t.y-this.dragOffset.y},n={x:s.x-i.x,y:s.y-i.y},r=[{x:0,y:0},{x:this.edit.size.width,y:0},{x:0,y:this.edit.size.height},{x:this.edit.size.width,y:this.edit.size.height}],o={x:this.edit.size.width/2,y:this.edit.size.height/2},h=[...r,o],c=[{x:n.x,y:n.y},{x:n.x+this.getSize().width,y:n.y},{x:n.x,y:n.y+this.getSize().height},{x:n.x+this.getSize().width,y:n.y+this.getSize().height}],l={x:n.x+this.getSize().width/2,y:n.y+this.getSize().height/2},g=[...c,l];let p=z.SnapThreshold,k=z.SnapThreshold,A=null,S=null;for(const ce of g)for(const ye of h){const Y=Math.abs(ce.x-ye.x);Y<p&&(p=Y,A=n.x+(ye.x-ce.x));const ve=Math.abs(ce.y-ye.y);ve<k&&(k=ve,S=n.y+(ye.y-ce.y))}A!==null&&(n.x=A),S!==null&&(n.y=S);const D=this.positionBuilder.absoluteToRelative(this.getSize(),this.clipConfiguration.position??"center",n);this.clipConfiguration.offset||(this.clipConfiguration.offset={x:0,y:0}),this.clipConfiguration.offset.x=D.x,this.clipConfiguration.offset.y=D.y,this.offsetXKeyframeBuilder=new R(this.clipConfiguration.offset.x,this.getLength()),this.offsetYKeyframeBuilder=new R(this.clipConfiguration.offset.y,this.getLength())}}onPointerUp(){(this.isDragging||this.scaleDirection!==null||this.isRotating)&&this.hasStateChanged()&&this.edit.setUpdatedClip(this,this.initialClipConfiguration),this.isDragging=!1,this.dragOffset={x:0,y:0},this.scaleDirection=null,this.scaleStart=null,this.scaleOffset={x:0,y:0},this.isRotating=!1,this.rotationStart=null,this.rotationOffset={x:0,y:0},this.initialClipConfiguration=null}onPointerOver(){this.isHovering=!0}onPointerOut(){this.isHovering=!1}clipHasPresets(){return!!this.clipConfiguration.effect||!!this.clipConfiguration.transition?.in||!!this.clipConfiguration.transition?.out}clipHasKeyframes(){return[this.clipConfiguration.scale,this.clipConfiguration.offset?.x,this.clipConfiguration.offset?.y,this.clipConfiguration.transform?.rotate?.angle].some(e=>e&&typeof e!="number")}hasStateChanged(){if(!this.initialClipConfiguration)return!1;const e=this.clipConfiguration.offset?.x,t=this.clipConfiguration.offset?.y,i=this.clipConfiguration.scale,s=Number(this.clipConfiguration.transform?.rotate?.angle??0),n=this.initialClipConfiguration.offset?.x,r=this.initialClipConfiguration.offset?.y,o=this.initialClipConfiguration.scale,h=Number(this.initialClipConfiguration.transform?.rotate?.angle??0);return n!==void 0&&e!==n||r!==void 0&&t!==r||o!==void 0&&i!==o||s!==h}}class at extends z{audioResource;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t),this.audioResource=null,this.isPlaying=!1;const i=t.asset;this.volumeKeyframeBuilder=new R(i.volume??1,this.getLength()),this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,i={src:t,loadParser:Be.Name},s=await this.edit.assetLoader.load(t,i);if(!(s instanceof Bt.Howl))throw new Error(`Invalid audio source '${e.src}'.`);this.audioResource=s,this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:i=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,this.getContainer().alpha=0,!this.audioResource)return;const s=this.edit.isPlaying&&this.isActive(),n=this.getPlaybackTime();s&&(this.isPlaying||(this.isPlaying=!0,this.audioResource.seek(n/1e3+i),this.audioResource.play()),this.audioResource.volume()!==this.getVolume()&&this.audioResource.volume(this.getVolume()),Math.abs((this.audioResource.seek()-i)*1e3-n)>100&&this.audioResource.seek(n/1e3+i)),this.isPlaying&&!s&&(this.isPlaying=!1,this.audioResource.pause());const r=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&r&&(this.syncTimer=0,this.audioResource.seek(n/1e3+i))}draw(){super.draw()}dispose(){this.audioResource?.unload(),this.audioResource=null}getSize(){return{width:0,height:0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}}var ts=`in vec2 aPosition;
|
|
2
2
|
out vec2 vTextureCoord;
|
|
3
3
|
|
|
4
4
|
uniform vec4 uInputSize;
|
|
@@ -179,5 +179,5 @@ fn outlineMaxAlphaAtPos(uv: vec2<f32>) -> f32 {
|
|
|
179
179
|
return maxAlpha;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
const DOUBLE_PI: f32 = 3.14159265358979323846264 * 2.;`,as=Object.defineProperty,rs=(a,e,t)=>e in a?as(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,ae=(a,e,t)=>(rs(a,typeof e!="symbol"?e+"":e,t),t);const je=class le extends K.Filter{constructor(...e){let t=e[0]??{};typeof t=="number"&&(K.deprecation("6.0.0","OutlineFilter constructor params are now options object. See params: { thickness, color, quality, alpha, knockout }"),t={thickness:t},e[1]!==void 0&&(t.color=e[1]),e[2]!==void 0&&(t.quality=e[2]),e[3]!==void 0&&(t.alpha=e[3]),e[4]!==void 0&&(t.knockout=e[4])),t={...le.DEFAULT_OPTIONS,...t};const i=t.quality??.1,s=K.GpuProgram.from({vertex:{source:is,entryPoint:"mainVertex"},fragment:{source:ns,entryPoint:"mainFragment"}}),n=K.GlProgram.from({vertex:ts,fragment:ss.replace(/\$\{ANGLE_STEP\}/,le.getAngleStep(i).toFixed(7)),name:"outline-filter"});super({gpuProgram:s,glProgram:n,resources:{outlineUniforms:{uThickness:{value:new Float32Array(2),type:"vec2<f32>"},uColor:{value:new Float32Array(3),type:"vec3<f32>"},uAlpha:{value:t.alpha,type:"f32"},uAngleStep:{value:0,type:"f32"},uKnockout:{value:t.knockout?1:0,type:"f32"}}}}),ae(this,"uniforms"),ae(this,"_thickness"),ae(this,"_quality"),ae(this,"_color"),this.uniforms=this.resources.outlineUniforms.uniforms,this.uniforms.uAngleStep=le.getAngleStep(i),this._color=new K.Color,this.color=t.color??0,Object.assign(this,t)}apply(e,t,i,s){this.uniforms.uThickness[0]=this.thickness/t.source.width,this.uniforms.uThickness[1]=this.thickness/t.source.height,e.applyFilter(this,t,i,s)}static getAngleStep(e){return parseFloat((Math.PI*2/Math.max(e*le.MAX_SAMPLES,le.MIN_SAMPLES)).toFixed(7))}get thickness(){return this._thickness}set thickness(e){this._thickness=this.padding=e}get color(){return this._color.value}set color(e){this._color.setValue(e);const[t,i,s]=this._color.toArray();this.uniforms.uColor[0]=t,this.uniforms.uColor[1]=i,this.uniforms.uColor[2]=s}get alpha(){return this.uniforms.uAlpha}set alpha(e){this.uniforms.uAlpha=e}get quality(){return this._quality}set quality(e){this._quality=e,this.uniforms.uAngleStep=le.getAngleStep(e)}get knockout(){return this.uniforms.uKnockout===1}set knockout(e){this.uniforms.uKnockout=e?1:0}};ae(je,"DEFAULT_OPTIONS",{thickness:1,color:0,alpha:1,quality:.1,knockout:!1}),ae(je,"MIN_SAMPLES",1),ae(je,"MAX_SAMPLES",100);let rt=je;class os extends z{background;text;constructor(e,t){super(e,t),this.background=null,this.text=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=await this.parseDocument();if(!t)return;const i=new w.Graphics;t.background.color&&(i.fillStyle={color:t.background.color,alpha:t.background.opacity??1},i.rect(0,0,e.width??this.edit.size.width,e.height??this.edit.size.height),i.fill());const s=new w.Text;s.text=t.text;const{horizontal:n,vertical:r}=t.alignment;s.style={fontFamily:t.font?.family??"Open Sans",fontSize:t.font?.size??32,fill:t.font?.color??"#ffffff",fontWeight:(t.font?.weight??"400").toString(),wordWrap:!0,wordWrapWidth:e.width??this.edit.size.width,lineHeight:(t.font?.lineHeight??1)*(t.font?.size??32),align:n};let o=(e.width??this.edit.size.width)/2-s.width/2,h=(e.height??this.edit.size.height)/2-s.height/2;if(n==="left"&&(o=0),n==="right"&&(o=(e.width??this.edit.size.width)-s.width),r==="top"&&(h=0),r==="bottom"&&(h=(e.height??this.edit.size.height)-s.height),s.position={x:o,y:h},t.stroke.color&&t.stroke.width){const c=new rt({thickness:t.stroke.width,color:t.stroke.color});s.filters=[c]}this.background=i,this.text=s,this.getContainer().addChild(i),this.getContainer().addChild(s),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.background?.destroy(),this.background=null,this.text?.destroy(),this.text=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}async parseDocument(){const e=this.clipConfiguration.asset,{html:t,css:i,position:s}=e;if(!t.includes('data-html-type="text"'))return console.warn("Unsupported html format."),null;const r=new DOMParser().parseFromString(t,"text/html").body.textContent??"",h=(await new CSSStyleSheet().replace(i)).cssRules[0],c={text:r,font:{},alignment:{},background:{},stroke:{}};if(h?.constructor.name!=="CSSStyleRule"||!("style"in h))return console.warn("Unsupported css format."),c;const l=h.style,g=this.parseAlignment(s??"center");c.font={color:l.color.length?l.color:void 0,family:l.fontFamily.length?l.fontFamily:void 0,size:l.fontSize.length?parseInt(l.fontSize,10):void 0,weight:l.fontWeight.length?parseInt(l.fontWeight,10):void 0,lineHeight:l.lineHeight.length?parseInt(l.lineHeight,10):void 0},c.alignment=g;let p="";return l.background.length&&(p=l.background),l.backgroundColor.length&&(p=l.backgroundColor),c.background={color:p.length?p:void 0,opacity:l.opacity.length?parseInt(l.opacity,10):void 0},c.stroke={width:l.strokeWidth.length?parseInt(l.strokeWidth,10):void 0,color:l.stroke.length?l.stroke:void 0},c}parseAlignment(e){switch(e){case"topLeft":return{horizontal:"left",vertical:"top"};case"top":return{horizontal:"center",vertical:"top"};case"topRight":return{horizontal:"right",vertical:"top"};case"left":return{horizontal:"left",vertical:"center"};case"right":return{horizontal:"right",vertical:"center"};case"bottomLeft":return{horizontal:"left",vertical:"bottom"};case"bottom":return{horizontal:"center",vertical:"bottom"};case"bottomRight":return{horizontal:"right",vertical:"bottom"};case"center":default:return{horizontal:"center",vertical:"center"}}}}class cs extends z{texture;sprite;constructor(e,t){super(e,t),this.texture=null,this.sprite=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,i={src:t,crossovern:"anonymous",data:{}},s=await this.edit.assetLoader.load(t,i);if(!(s?.source instanceof w.ImageSource))throw new Error(`Invalid image source '${e.src}'.`);this.texture=this.createCroppedTexture(s),this.sprite=new w.Sprite(this.texture),this.getContainer().addChild(this.sprite),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.sprite?.destroy(),this.sprite=null,this.texture?.destroy(),this.texture=null}getSize(){return{width:this.sprite?.width??0,height:this.sprite?.height??0}}createCroppedTexture(e){const t=this.clipConfiguration.asset;if(!t.crop)return e;const i=e.width,s=e.height,n=Math.floor((t.crop?.left??0)*i),r=Math.floor((t.crop?.right??0)*i),o=Math.floor((t.crop?.top??0)*s),h=Math.floor((t.crop?.bottom??0)*s),c=n,l=o,g=i-n-r,p=s-o-h,k=new w.Rectangle(c,l,g,p);return new w.Texture({source:e.source,frame:k})}}class ls extends z{shape;shapeBackground;constructor(e,t){super(e,t),this.shape=null,this.shapeBackground=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=new w.Graphics,i=e.width??this.edit.size.width,s=e.height??this.edit.size.height;t.fillStyle={color:"transparent"},t.rect(0,0,i,s),t.fill();const n=new w.Graphics;switch(e.shape){case"rectangle":{const r=e.rectangle,o=i/2-r.width/2,h=s/2-r.height/2;n.rect(o,h,r.width,r.height);break}case"circle":{const r=e.circle,o=i/2,h=s/2;n.circle(o,h,r.radius);break}case"line":{const r=e.line,o=i/2-r.length/2,h=s/2-r.thickness/2;n.rect(o,h,r.length,r.thickness);break}default:console.warn("Unsupported shape asset type.");break}if(n.fillStyle={color:e.fill?.color??"#ffffff",alpha:e.fill?.opacity??1},n.fill(),e.stroke){const r=new rt({thickness:e.stroke.width,color:e.stroke.color});n.filters=[r]}this.shapeBackground=t,this.shape=n,this.getContainer().addChild(t),t.addChild(n),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.shape?.destroy(),this.shape=null,this.shapeBackground?.destroy(),this.shapeBackground=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}}class hs extends z{background;text;constructor(e,t){super(e,t),this.background=null,this.text=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=new w.Graphics;e.background&&(t.fillStyle={color:e.background.color,alpha:e.background.opacity},t.rect(0,0,e.width??this.edit.size.width,e.height??this.edit.size.height),t.fill());const i=new w.Text;i.text=e.text;const s=e.alignment?.horizontal??"center",n=e.alignment?.vertical??"center";i.style={fontFamily:e.font?.family??"Open Sans",fontSize:e.font?.size??32,fill:e.font?.color??"#ffffff",fontWeight:(e.font?.weight??"400").toString(),wordWrap:!0,wordWrapWidth:e.width??this.edit.size.width,lineHeight:(e.font?.lineHeight??1)*(e.font?.size??32),align:s};let r=(e.width??this.edit.size.width)/2-i.width/2,o=(e.height??this.edit.size.height)/2-i.height/2;if(s==="left"&&(r=0),s==="right"&&(r=(e.width??this.edit.size.width)-i.width),n==="top"&&(o=0),n==="bottom"&&(o=(e.height??this.edit.size.height)-i.height),i.position={x:r,y:o},e.stroke){const h=new rt({thickness:e.stroke.width,color:e.stroke.color});i.filters=[h]}this.background=t,this.text=i,this.getContainer().addChild(t),this.getContainer().addChild(i),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.background?.destroy(),this.background=null,this.text?.destroy(),this.text=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}}class us extends z{texture;sprite;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t),this.texture=null,this.sprite=null,this.isPlaying=!1;const i=this.clipConfiguration.asset;this.volumeKeyframeBuilder=new R(i.volume??1,this.getLength()),this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src;if(t.endsWith(".mov")||t.endsWith(".webm"))throw new Error(`Video source '${e.src}' is not supported. .mov and .webm files are currently not supported.`);const i={src:t,data:{autoPlay:!1,muted:!1}},s=await this.edit.assetLoader.load(t,i);if(!(s?.source instanceof w.VideoSource))throw new Error(`Invalid video source '${e.src}'.`);this.texture=this.createCroppedTexture(s),this.sprite=new w.Sprite(this.texture),this.getContainer().addChild(this.sprite),this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:i=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,!this.texture)return;const s=this.getPlaybackTime(),n=this.edit.isPlaying&&this.isActive();n&&(this.isPlaying||(this.isPlaying=!0,this.texture.source.resource.currentTime=s/1e3+i,this.texture.source.resource.play().catch(console.error)),this.texture.source.resource.volume!==this.getVolume()&&(this.texture.source.resource.volume=this.getVolume()),Math.abs((this.texture.source.resource.currentTime-i)*1e3-s)>100&&(this.texture.source.resource.currentTime=s/1e3+i)),!n&&this.isPlaying&&(this.isPlaying=!1,this.texture.source.resource.pause());const r=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&r&&(this.syncTimer=0,this.texture.source.resource.currentTime=s/1e3+i)}draw(){super.draw()}dispose(){super.dispose(),this.sprite?.destroy(),this.sprite=null,this.texture?.destroy(),this.texture=null}getSize(){return{width:this.sprite?.width??0,height:this.sprite?.height??0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}createCroppedTexture(e){const t=this.clipConfiguration.asset;if(!t.crop)return e;const i=e.width,s=e.height,n=Math.floor((t.crop?.left??0)*i),r=Math.floor((t.crop?.right??0)*i),o=Math.floor((t.crop?.top??0)*s),h=Math.floor((t.crop?.bottom??0)*s),c=n,l=o,g=i-n-r,p=s-o-h,k=new w.Rectangle(c,l,g,p);return new w.Texture({source:e.source,frame:k})}}class re extends nt{static ZIndexPadding=100;assetLoader;events;edit;tracks;clipsToDispose;clips;playbackTime;size;backgroundColor;totalDuration;isPlaying;selectedClip;constructor(e,t="#ffffff"){super(),this.assetLoader=new Vt,this.edit=null,this.tracks=[],this.clipsToDispose=[],this.clips=[],this.events=new dt,this.size=e,this.playbackTime=0,this.totalDuration=0,this.isPlaying=!1,this.selectedClip=null,this.backgroundColor=t}async load(){const e=new w.Graphics;e.fillStyle={color:this.backgroundColor},e.rect(0,0,this.size.width,this.size.height),e.fill(),this.getContainer().addChild(e)}update(e,t){for(const i of this.clips)i.shouldDispose&&this.queueDisposeClip(i),i.update(e,t);this.disposeClips(),this.isPlaying&&(this.playbackTime=Math.max(0,Math.min(this.playbackTime+t,this.totalDuration)),this.playbackTime===this.totalDuration&&this.pause())}draw(){for(const e of this.clips)e.draw()}dispose(){this.clearClips()}play(){this.isPlaying=!0}pause(){this.isPlaying=!1}seek(e){this.playbackTime=Math.max(0,Math.min(e,this.totalDuration)),this.pause()}stop(){this.seek(0)}async loadEdit(e){this.clearClips(),this.edit=Xi.parse(e),this.backgroundColor=this.edit.timeline.background||"#000000",await Promise.all((this.edit.timeline.fonts??[]).map(async t=>{const i=t.src,s={src:i,loadParser:Oe.Name};return this.assetLoader.load(i,s)}));for(const[t,i]of this.edit.timeline.tracks.entries())for(const s of i.clips){const n=this.createPlayerFromAssetType(s);n.layer=t+1,await this.addPlayer(t,n)}}getEdit(){const e=[],t=new Map;for(const s of this.clips)t.has(s.layer)||t.set(s.layer,{clips:[]}),t.get(s.layer).clips.push(s.clipConfiguration);const i=Math.max(...t.keys(),0);for(let s=1;s<=i;s+=1)e[s-1]=t.get(s)||{clips:[]};return{timeline:{background:this.backgroundColor,tracks:e,fonts:this.edit?.timeline.fonts||[]},output:this.edit?.output||{size:this.size,format:"mp4"}}}addClip(e,t){const i=Et.parse(t),s=this.createPlayerFromAssetType(i);s.layer=e+1,this.addPlayer(e,s),this.updateTotalDuration()}getClip(e,t){const i=this.clips.filter(s=>s.layer===e+1);return t<0||t>=i.length?null:i[t].clipConfiguration}deleteClip(e,t){const i=this.clips.find(s=>s.layer===e+1&&this.clips.filter(n=>n.layer===e+1).indexOf(s)===t);i&&(this.queueDisposeClip(i),this.updateTotalDuration())}addTrack(e,t){this.tracks.splice(e,0,[]);const i=this.clips.map((s,n)=>({clip:s,index:n})).filter(({clip:s})=>s.layer>=e+1);i.forEach(({clip:s})=>{const r=`shotstack-track-${1e5-s.layer*re.ZIndexPadding}`;this.getContainer().getChildByLabel(r,!1)?.removeChild(s.getContainer())});for(const{index:s}of i)this.clips[s].layer+=1;i.forEach(({clip:s})=>{const n=1e5-s.layer*re.ZIndexPadding,r=`shotstack-track-${n}`;let o=this.getContainer().getChildByLabel(r,!1);o||(o=new w.Container({label:r,zIndex:n}),this.getContainer().addChild(o)),o.addChild(s.getContainer())}),t?.clips?.forEach(s=>this.addClip(e,s)),this.updateTotalDuration()}getTrack(e){const t=this.clips.filter(i=>i.layer===e+1);return t.length===0?null:{clips:t.map(i=>i.clipConfiguration)}}deleteTrack(e){const t=this.clips.filter(s=>s.layer===e+1);for(const s of t)s.shouldDispose=!0;this.disposeClips(),this.tracks.splice(e,1);const i=this.clips.map((s,n)=>({clip:s,index:n})).filter(({clip:s})=>s.layer>e+1);i.forEach(({clip:s})=>{const r=`shotstack-track-${1e5-s.layer*re.ZIndexPadding}`;this.getContainer().getChildByLabel(r,!1)?.removeChild(s.getContainer())});for(const{index:s}of i)this.clips[s].layer-=1;i.forEach(({clip:s})=>{const n=1e5-s.layer*re.ZIndexPadding,r=`shotstack-track-${n}`;let o=this.getContainer().getChildByLabel(r,!1);o||(o=new w.Container({label:r,zIndex:n}),this.getContainer().addChild(o)),o.addChild(s.getContainer())}),this.updateTotalDuration()}getTotalDuration(){return this.totalDuration}getSelectedClip(){return this.selectedClip}setSelectedClip(e){this.selectedClip=e;const t=e.layer-1,s=this.clips.filter(r=>r.layer===e.layer).indexOf(e),n={clip:e.clipConfiguration,trackIndex:t,clipIndex:s};this.events.emit("clip:selected",n)}queueDisposeClip(e){this.clipsToDispose.push(e)}disposeClips(){if(this.clipsToDispose.length!==0){for(const e of this.clipsToDispose)this.disposeClip(e);this.clips=this.clips.filter(e=>!this.clipsToDispose.includes(e)),this.clipsToDispose=[],this.updateTotalDuration()}}disposeClip(e){try{if(this.getContainer().children.includes(e.getContainer())){const t=this.getContainer().getChildIndex(e.getContainer());this.getContainer().removeChildAt(t)}else for(const t of this.getContainer().children)if(t instanceof w.Container&&t.label?.toString().startsWith("shotstack-track-")&&t.children.includes(e.getContainer())){t.removeChild(e.getContainer());break}}catch{console.warn("Attempting to unmount an unmounted clip.")}this.unloadClipAssets(e),e.dispose()}unloadClipAssets(e){const{asset:t}=e.clipConfiguration;if(t&&"src"in t&&typeof t.src=="string")try{w.Assets.unload(t.src)}catch(i){console.warn(`Failed to unload asset: ${t.src}`,i)}}clearClips(){for(const e of this.clips)this.disposeClip(e);this.clips=[],this.clipsToDispose=[],this.updateTotalDuration()}updateTotalDuration(){let e=0;for(const t of this.tracks)for(const i of t)e=Math.max(e,i.getEnd());this.totalDuration=e}createPlayerFromAssetType(e){if(!e.asset?.type)throw new Error("Invalid clip configuration: missing asset type");let t;switch(e.asset.type){case"text":{t=new hs(this,e);break}case"shape":{t=new ls(this,e);break}case"html":{t=new os(this,e);break}case"image":{t=new cs(this,e);break}case"video":{t=new us(this,e);break}case"audio":{t=new at(this,e);break}default:throw new Error(`Unsupported clip type: ${e.asset.type}`)}return t}async addPlayer(e,t){for(;this.tracks.length<=e;)this.tracks.push([]);this.tracks[e].push(t),this.clips.push(t);const i=1e5-(e+1)*re.ZIndexPadding,s=`shotstack-track-${i}`;let n=this.getContainer().getChildByLabel(s,!1);n||(n=new w.Container({label:s,zIndex:i}),this.getContainer().addChild(n)),n.addChild(t.getContainer()),await t.load(),this.updateTotalDuration()}}class Te extends nt{static Width=250;static Height=100;fps;playbackTime;playbackDuration;isPlaying;background;text;constructor(){super(),this.background=null,this.text=null,this.fps=0,this.playbackTime=0,this.playbackDuration=0,this.isPlaying=!1}async load(){const e=new w.Graphics;e.fillStyle={color:"#424242",alpha:.5},e.rect(0,0,Te.Width,Te.Height),e.fill(),this.getContainer().addChild(e),this.background=e;const t=new w.Text;t.text="",t.style={fontFamily:"monospace",fontSize:14,fill:"#ffffff",wordWrap:!0,wordWrapWidth:Te.Width},this.getContainer().addChild(t),this.text=t}update(e,t){if(!this.text)return;const i=this.getMemoryInfo(),s=[`FPS: ${this.fps}`,`Playback: ${(this.playbackTime/1e3).toFixed(2)}/${(this.playbackDuration/1e3).toFixed(2)}`,`Playing: ${this.isPlaying}`,`Total Heap Size: ${i.totalHeapSize?`${this.bytesToMegabytes(i.totalHeapSize)}MB`:"N/A"}`,`Used Heap Size: ${i.usedHeapSize?`${this.bytesToMegabytes(i.usedHeapSize)}MB`:"N/A"}`,`Heap Size Limit: ${i.heapSizeLimit?`${this.bytesToMegabytes(i.heapSizeLimit)}MB`:"N/A"}`];this.text.text=s.join(`
|
|
182
|
+
const DOUBLE_PI: f32 = 3.14159265358979323846264 * 2.;`,as=Object.defineProperty,rs=(a,e,t)=>e in a?as(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,ae=(a,e,t)=>(rs(a,typeof e!="symbol"?e+"":e,t),t);const je=class le extends K.Filter{constructor(...e){let t=e[0]??{};typeof t=="number"&&(K.deprecation("6.0.0","OutlineFilter constructor params are now options object. See params: { thickness, color, quality, alpha, knockout }"),t={thickness:t},e[1]!==void 0&&(t.color=e[1]),e[2]!==void 0&&(t.quality=e[2]),e[3]!==void 0&&(t.alpha=e[3]),e[4]!==void 0&&(t.knockout=e[4])),t={...le.DEFAULT_OPTIONS,...t};const i=t.quality??.1,s=K.GpuProgram.from({vertex:{source:is,entryPoint:"mainVertex"},fragment:{source:ns,entryPoint:"mainFragment"}}),n=K.GlProgram.from({vertex:ts,fragment:ss.replace(/\$\{ANGLE_STEP\}/,le.getAngleStep(i).toFixed(7)),name:"outline-filter"});super({gpuProgram:s,glProgram:n,resources:{outlineUniforms:{uThickness:{value:new Float32Array(2),type:"vec2<f32>"},uColor:{value:new Float32Array(3),type:"vec3<f32>"},uAlpha:{value:t.alpha,type:"f32"},uAngleStep:{value:0,type:"f32"},uKnockout:{value:t.knockout?1:0,type:"f32"}}}}),ae(this,"uniforms"),ae(this,"_thickness"),ae(this,"_quality"),ae(this,"_color"),this.uniforms=this.resources.outlineUniforms.uniforms,this.uniforms.uAngleStep=le.getAngleStep(i),this._color=new K.Color,this.color=t.color??0,Object.assign(this,t)}apply(e,t,i,s){this.uniforms.uThickness[0]=this.thickness/t.source.width,this.uniforms.uThickness[1]=this.thickness/t.source.height,e.applyFilter(this,t,i,s)}static getAngleStep(e){return parseFloat((Math.PI*2/Math.max(e*le.MAX_SAMPLES,le.MIN_SAMPLES)).toFixed(7))}get thickness(){return this._thickness}set thickness(e){this._thickness=this.padding=e}get color(){return this._color.value}set color(e){this._color.setValue(e);const[t,i,s]=this._color.toArray();this.uniforms.uColor[0]=t,this.uniforms.uColor[1]=i,this.uniforms.uColor[2]=s}get alpha(){return this.uniforms.uAlpha}set alpha(e){this.uniforms.uAlpha=e}get quality(){return this._quality}set quality(e){this._quality=e,this.uniforms.uAngleStep=le.getAngleStep(e)}get knockout(){return this.uniforms.uKnockout===1}set knockout(e){this.uniforms.uKnockout=e?1:0}};ae(je,"DEFAULT_OPTIONS",{thickness:1,color:0,alpha:1,quality:.1,knockout:!1}),ae(je,"MIN_SAMPLES",1),ae(je,"MAX_SAMPLES",100);let rt=je;class os extends z{background;text;constructor(e,t){super(e,t),this.background=null,this.text=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=await this.parseDocument();if(!t)return;const i=new w.Graphics;t.background.color&&(i.fillStyle={color:t.background.color,alpha:t.background.opacity??1},i.rect(0,0,e.width??this.edit.size.width,e.height??this.edit.size.height),i.fill());const s=new w.Text;s.text=t.text;const{horizontal:n,vertical:r}=t.alignment;s.style={fontFamily:t.font?.family??"Open Sans",fontSize:t.font?.size??32,fill:t.font?.color??"#ffffff",fontWeight:(t.font?.weight??"400").toString(),wordWrap:!0,wordWrapWidth:e.width??this.edit.size.width,lineHeight:(t.font?.lineHeight??1)*(t.font?.size??32),align:n};let o=(e.width??this.edit.size.width)/2-s.width/2,h=(e.height??this.edit.size.height)/2-s.height/2;if(n==="left"&&(o=0),n==="right"&&(o=(e.width??this.edit.size.width)-s.width),r==="top"&&(h=0),r==="bottom"&&(h=(e.height??this.edit.size.height)-s.height),s.position={x:o,y:h},t.stroke.color&&t.stroke.width){const c=new rt({thickness:t.stroke.width,color:t.stroke.color});s.filters=[c]}this.background=i,this.text=s,this.getContainer().addChild(i),this.getContainer().addChild(s),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.background?.destroy(),this.background=null,this.text?.destroy(),this.text=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}async parseDocument(){const e=this.clipConfiguration.asset,{html:t,css:i,position:s}=e;if(!t.includes('data-html-type="text"'))return console.warn("Unsupported html format."),null;const r=new DOMParser().parseFromString(t,"text/html").body.textContent??"",h=(await new CSSStyleSheet().replace(i)).cssRules[0],c={text:r,font:{},alignment:{},background:{},stroke:{}};if(h?.constructor.name!=="CSSStyleRule"||!("style"in h))return console.warn("Unsupported css format."),c;const l=h.style,g=this.parseAlignment(s??"center");c.font={color:l.color.length?l.color:void 0,family:l.fontFamily.length?l.fontFamily:void 0,size:l.fontSize.length?parseInt(l.fontSize,10):void 0,weight:l.fontWeight.length?parseInt(l.fontWeight,10):void 0,lineHeight:l.lineHeight.length?parseInt(l.lineHeight,10):void 0},c.alignment=g;let p="";return l.background.length&&(p=l.background),l.backgroundColor.length&&(p=l.backgroundColor),c.background={color:p.length?p:void 0,opacity:l.opacity.length?parseInt(l.opacity,10):void 0},c.stroke={width:l.strokeWidth.length?parseInt(l.strokeWidth,10):void 0,color:l.stroke.length?l.stroke:void 0},c}parseAlignment(e){switch(e){case"topLeft":return{horizontal:"left",vertical:"top"};case"top":return{horizontal:"center",vertical:"top"};case"topRight":return{horizontal:"right",vertical:"top"};case"left":return{horizontal:"left",vertical:"center"};case"right":return{horizontal:"right",vertical:"center"};case"bottomLeft":return{horizontal:"left",vertical:"bottom"};case"bottom":return{horizontal:"center",vertical:"bottom"};case"bottomRight":return{horizontal:"right",vertical:"bottom"};case"center":default:return{horizontal:"center",vertical:"center"}}}}class cs extends z{texture;sprite;constructor(e,t){super(e,t),this.texture=null,this.sprite=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,i={src:t,crossovern:"anonymous",data:{}},s=await this.edit.assetLoader.load(t,i);if(!(s?.source instanceof w.ImageSource))throw new Error(`Invalid image source '${e.src}'.`);this.texture=this.createCroppedTexture(s),this.sprite=new w.Sprite(this.texture),this.getContainer().addChild(this.sprite),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.sprite?.destroy(),this.sprite=null,this.texture?.destroy(),this.texture=null}getSize(){return{width:this.sprite?.width??0,height:this.sprite?.height??0}}createCroppedTexture(e){const t=this.clipConfiguration.asset;if(!t.crop)return e;const i=e.width,s=e.height,n=Math.floor((t.crop?.left??0)*i),r=Math.floor((t.crop?.right??0)*i),o=Math.floor((t.crop?.top??0)*s),h=Math.floor((t.crop?.bottom??0)*s),c=n,l=o,g=i-n-r,p=s-o-h,k=new w.Rectangle(c,l,g,p);return new w.Texture({source:e.source,frame:k})}}class ls extends z{shape;shapeBackground;constructor(e,t){super(e,t),this.shape=null,this.shapeBackground=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=new w.Graphics,i=e.width??this.edit.size.width,s=e.height??this.edit.size.height;t.fillStyle={color:"transparent"},t.rect(0,0,i,s),t.fill();const n=new w.Graphics;switch(e.shape){case"rectangle":{const r=e.rectangle,o=i/2-r.width/2,h=s/2-r.height/2;n.rect(o,h,r.width,r.height);break}case"circle":{const r=e.circle,o=i/2,h=s/2;n.circle(o,h,r.radius);break}case"line":{const r=e.line,o=i/2-r.length/2,h=s/2-r.thickness/2;n.rect(o,h,r.length,r.thickness);break}default:console.warn("Unsupported shape asset type.");break}if(n.fillStyle={color:e.fill?.color??"#ffffff",alpha:e.fill?.opacity??1},n.fill(),e.stroke){const r=new rt({thickness:e.stroke.width,color:e.stroke.color});n.filters=[r]}this.shapeBackground=t,this.shape=n,this.getContainer().addChild(t),t.addChild(n),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.shape?.destroy(),this.shape=null,this.shapeBackground?.destroy(),this.shapeBackground=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}}class hs extends z{background;text;constructor(e,t){super(e,t),this.background=null,this.text=null}async load(){await super.load();const e=this.clipConfiguration.asset,t=new w.Graphics;e.background&&(t.fillStyle={color:e.background.color,alpha:e.background.opacity},t.rect(0,0,e.width??this.edit.size.width,e.height??this.edit.size.height),t.fill());const i=new w.Text;i.text=e.text;const s=e.alignment?.horizontal??"center",n=e.alignment?.vertical??"center";i.style={fontFamily:e.font?.family??"Open Sans",fontSize:e.font?.size??32,fill:e.font?.color??"#ffffff",fontWeight:(e.font?.weight??"400").toString(),wordWrap:!0,wordWrapWidth:e.width??this.edit.size.width,lineHeight:(e.font?.lineHeight??1)*(e.font?.size??32),align:s};let r=(e.width??this.edit.size.width)/2-i.width/2,o=(e.height??this.edit.size.height)/2-i.height/2;if(s==="left"&&(r=0),s==="right"&&(r=(e.width??this.edit.size.width)-i.width),n==="top"&&(o=0),n==="bottom"&&(o=(e.height??this.edit.size.height)-i.height),i.position={x:r,y:o},e.stroke){const h=new rt({thickness:e.stroke.width,color:e.stroke.color});i.filters=[h]}this.background=t,this.text=i,this.getContainer().addChild(t),this.getContainer().addChild(i),this.configureKeyframes()}update(e,t){super.update(e,t)}draw(){super.draw()}dispose(){super.dispose(),this.background?.destroy(),this.background=null,this.text?.destroy(),this.text=null}getSize(){const e=this.clipConfiguration.asset;return{width:e.width??this.edit.size.width,height:e.height??this.edit.size.height}}getFitScale(){return 1}}class us extends z{texture;sprite;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t),this.texture=null,this.sprite=null,this.isPlaying=!1;const i=this.clipConfiguration.asset;this.volumeKeyframeBuilder=new R(i.volume??1,this.getLength()),this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src;if(t.endsWith(".mov")||t.endsWith(".webm"))throw new Error(`Video source '${e.src}' is not supported. .mov and .webm files are currently not supported.`);const i={src:t,data:{autoPlay:!1,muted:!1}},s=await this.edit.assetLoader.load(t,i);if(!(s?.source instanceof w.VideoSource))throw new Error(`Invalid video source '${e.src}'.`);this.texture=this.createCroppedTexture(s),this.sprite=new w.Sprite(this.texture),this.getContainer().addChild(this.sprite),this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:i=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,!this.texture)return;const s=this.getPlaybackTime(),n=this.edit.isPlaying&&this.isActive();n&&(this.isPlaying||(this.isPlaying=!0,this.texture.source.resource.currentTime=s/1e3+i,this.texture.source.resource.play().catch(console.error)),this.texture.source.resource.volume!==this.getVolume()&&(this.texture.source.resource.volume=this.getVolume()),Math.abs((this.texture.source.resource.currentTime-i)*1e3-s)>100&&(this.texture.source.resource.currentTime=s/1e3+i)),!n&&this.isPlaying&&(this.isPlaying=!1,this.texture.source.resource.pause());const r=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&r&&(this.syncTimer=0,this.texture.source.resource.currentTime=s/1e3+i)}draw(){super.draw()}dispose(){super.dispose(),this.sprite?.destroy(),this.sprite=null,this.texture?.destroy(),this.texture=null}getSize(){return{width:this.sprite?.width??0,height:this.sprite?.height??0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}createCroppedTexture(e){const t=this.clipConfiguration.asset;if(!t.crop)return e;const i=e.width,s=e.height,n=Math.floor((t.crop?.left??0)*i),r=Math.floor((t.crop?.right??0)*i),o=Math.floor((t.crop?.top??0)*s),h=Math.floor((t.crop?.bottom??0)*s),c=n,l=o,g=i-n-r,p=s-o-h,k=new w.Rectangle(c,l,g,p);return new w.Texture({source:e.source,frame:k})}}class re extends nt{static ZIndexPadding=100;assetLoader;events;edit;tracks;clipsToDispose;clips;playbackTime;size;backgroundColor;totalDuration;isPlaying;selectedClip;updatedClip;constructor(e,t="#ffffff"){super(),this.assetLoader=new Vt,this.edit=null,this.tracks=[],this.clipsToDispose=[],this.clips=[],this.events=new dt,this.size=e,this.playbackTime=0,this.totalDuration=0,this.isPlaying=!1,this.selectedClip=null,this.updatedClip=null,this.backgroundColor=t}async load(){const e=new w.Graphics;e.fillStyle={color:this.backgroundColor},e.rect(0,0,this.size.width,this.size.height),e.fill(),this.getContainer().addChild(e)}update(e,t){for(const i of this.clips)i.shouldDispose&&this.queueDisposeClip(i),i.update(e,t);this.disposeClips(),this.isPlaying&&(this.playbackTime=Math.max(0,Math.min(this.playbackTime+t,this.totalDuration)),this.playbackTime===this.totalDuration&&this.pause())}draw(){for(const e of this.clips)e.draw()}dispose(){this.clearClips()}play(){this.isPlaying=!0}pause(){this.isPlaying=!1}seek(e){this.playbackTime=Math.max(0,Math.min(e,this.totalDuration)),this.pause()}stop(){this.seek(0)}async loadEdit(e){this.clearClips(),this.edit=Xi.parse(e),this.backgroundColor=this.edit.timeline.background||"#000000",await Promise.all((this.edit.timeline.fonts??[]).map(async t=>{const i=t.src,s={src:i,loadParser:Oe.Name};return this.assetLoader.load(i,s)}));for(const[t,i]of this.edit.timeline.tracks.entries())for(const s of i.clips){const n=this.createPlayerFromAssetType(s);n.layer=t+1,await this.addPlayer(t,n)}this.updateTotalDuration()}getEdit(){const e=[],t=new Map;for(const s of this.clips)t.has(s.layer)||t.set(s.layer,{clips:[]}),t.get(s.layer).clips.push(s.clipConfiguration);const i=Math.max(...t.keys(),0);for(let s=1;s<=i;s+=1)e[s-1]=t.get(s)||{clips:[]};return{timeline:{background:this.backgroundColor,tracks:e,fonts:this.edit?.timeline.fonts||[]},output:this.edit?.output||{size:this.size,format:"mp4"}}}addClip(e,t){const i=Et.parse(t),s=this.createPlayerFromAssetType(i);s.layer=e+1,this.addPlayer(e,s),this.updateTotalDuration()}getClip(e,t){const i=this.clips.filter(s=>s.layer===e+1);return t<0||t>=i.length?null:i[t].clipConfiguration}deleteClip(e,t){const i=this.clips.find(s=>s.layer===e+1&&this.clips.filter(n=>n.layer===e+1).indexOf(s)===t);i&&(this.queueDisposeClip(i),this.updateTotalDuration())}addTrack(e,t){this.tracks.splice(e,0,[]);const i=this.clips.map((s,n)=>({clip:s,index:n})).filter(({clip:s})=>s.layer>=e+1);i.forEach(({clip:s})=>{const r=`shotstack-track-${1e5-s.layer*re.ZIndexPadding}`;this.getContainer().getChildByLabel(r,!1)?.removeChild(s.getContainer())});for(const{index:s}of i)this.clips[s].layer+=1;i.forEach(({clip:s})=>{const n=1e5-s.layer*re.ZIndexPadding,r=`shotstack-track-${n}`;let o=this.getContainer().getChildByLabel(r,!1);o||(o=new w.Container({label:r,zIndex:n}),this.getContainer().addChild(o)),o.addChild(s.getContainer())}),t?.clips?.forEach(s=>this.addClip(e,s)),this.updateTotalDuration()}getTrack(e){const t=this.clips.filter(i=>i.layer===e+1);return t.length===0?null:{clips:t.map(i=>i.clipConfiguration)}}deleteTrack(e){const t=this.clips.filter(s=>s.layer===e+1);for(const s of t)s.shouldDispose=!0;this.disposeClips(),this.tracks.splice(e,1);const i=this.clips.map((s,n)=>({clip:s,index:n})).filter(({clip:s})=>s.layer>e+1);i.forEach(({clip:s})=>{const r=`shotstack-track-${1e5-s.layer*re.ZIndexPadding}`;this.getContainer().getChildByLabel(r,!1)?.removeChild(s.getContainer())});for(const{index:s}of i)this.clips[s].layer-=1;i.forEach(({clip:s})=>{const n=1e5-s.layer*re.ZIndexPadding,r=`shotstack-track-${n}`;let o=this.getContainer().getChildByLabel(r,!1);o||(o=new w.Container({label:r,zIndex:n}),this.getContainer().addChild(o)),o.addChild(s.getContainer())}),this.updateTotalDuration()}getTotalDuration(){return this.totalDuration}getSelectedClip(){return this.selectedClip}setSelectedClip(e){this.selectedClip=e;const t=e.layer-1,s=this.clips.filter(r=>r.layer===e.layer).indexOf(e),n={clip:e.clipConfiguration,trackIndex:t,clipIndex:s};this.events.emit("clip:selected",n)}setUpdatedClip(e,t=null){this.updatedClip=e;const i=e.layer-1,n=this.clips.filter(o=>o.layer===e.layer).indexOf(e),r={previous:{clip:t,trackIndex:i,clipIndex:n},current:{clip:e.clipConfiguration,trackIndex:i,clipIndex:n}};this.events.emit("clip:updated",r)}queueDisposeClip(e){this.clipsToDispose.push(e)}disposeClips(){if(this.clipsToDispose.length!==0){for(const e of this.clipsToDispose)this.disposeClip(e);this.clips=this.clips.filter(e=>!this.clipsToDispose.includes(e)),this.clipsToDispose=[],this.updateTotalDuration()}}disposeClip(e){try{if(this.getContainer().children.includes(e.getContainer())){const t=this.getContainer().getChildIndex(e.getContainer());this.getContainer().removeChildAt(t)}else for(const t of this.getContainer().children)if(t instanceof w.Container&&t.label?.toString().startsWith("shotstack-track-")&&t.children.includes(e.getContainer())){t.removeChild(e.getContainer());break}}catch{console.warn("Attempting to unmount an unmounted clip.")}this.unloadClipAssets(e),e.dispose()}unloadClipAssets(e){const{asset:t}=e.clipConfiguration;if(t&&"src"in t&&typeof t.src=="string")try{w.Assets.unload(t.src)}catch(i){console.warn(`Failed to unload asset: ${t.src}`,i)}}clearClips(){for(const e of this.clips)this.disposeClip(e);this.clips=[],this.clipsToDispose=[],this.updateTotalDuration()}updateTotalDuration(){let e=0;for(const t of this.tracks)for(const i of t)e=Math.max(e,i.getEnd());this.totalDuration=e}createPlayerFromAssetType(e){if(!e.asset?.type)throw new Error("Invalid clip configuration: missing asset type");let t;switch(e.asset.type){case"text":{t=new hs(this,e);break}case"shape":{t=new ls(this,e);break}case"html":{t=new os(this,e);break}case"image":{t=new cs(this,e);break}case"video":{t=new us(this,e);break}case"audio":{t=new at(this,e);break}default:throw new Error(`Unsupported clip type: ${e.asset.type}`)}return t}async addPlayer(e,t){for(;this.tracks.length<=e;)this.tracks.push([]);this.tracks[e].push(t),this.clips.push(t);const i=1e5-(e+1)*re.ZIndexPadding,s=`shotstack-track-${i}`;let n=this.getContainer().getChildByLabel(s,!1);n||(n=new w.Container({label:s,zIndex:i}),this.getContainer().addChild(n)),n.addChild(t.getContainer()),await t.load(),this.updateTotalDuration()}}class Te extends nt{static Width=250;static Height=100;fps;playbackTime;playbackDuration;isPlaying;background;text;constructor(){super(),this.background=null,this.text=null,this.fps=0,this.playbackTime=0,this.playbackDuration=0,this.isPlaying=!1}async load(){const e=new w.Graphics;e.fillStyle={color:"#424242",alpha:.5},e.rect(0,0,Te.Width,Te.Height),e.fill(),this.getContainer().addChild(e),this.background=e;const t=new w.Text;t.text="",t.style={fontFamily:"monospace",fontSize:14,fill:"#ffffff",wordWrap:!0,wordWrapWidth:Te.Width},this.getContainer().addChild(t),this.text=t}update(e,t){if(!this.text)return;const i=this.getMemoryInfo(),s=[`FPS: ${this.fps}`,`Playback: ${(this.playbackTime/1e3).toFixed(2)}/${(this.playbackDuration/1e3).toFixed(2)}`,`Playing: ${this.isPlaying}`,`Total Heap Size: ${i.totalHeapSize?`${this.bytesToMegabytes(i.totalHeapSize)}MB`:"N/A"}`,`Used Heap Size: ${i.usedHeapSize?`${this.bytesToMegabytes(i.usedHeapSize)}MB`:"N/A"}`,`Heap Size Limit: ${i.heapSizeLimit?`${this.bytesToMegabytes(i.heapSizeLimit)}MB`:"N/A"}`];this.text.text=s.join(`
|
|
183
183
|
`)}draw(){}dispose(){this.background?.destroy(),this.background=null,this.text?.destroy(),this.text=null}getMemoryInfo(){const e={};return"memory"in performance&&(e.totalHeapSize=performance.memory.totalJSHeapSize,e.usedHeapSize=performance.memory.usedJSHeapSize,e.heapSizeLimit=performance.memory.jsHeapSizeLimit),e}bytesToMegabytes(e){return Math.round(e/1024/1024)}}class oe{static CanvasSelector="[data-shotstack-studio]";static extensionsRegistered=!1;size;application;edit;inspector;container;background;minZoom=.1;maxZoom=4;currentZoom=.8;constructor(e,t){this.size=e,this.application=new w.Application,this.edit=t,this.inspector=new Te}async load(){const e=document.querySelector(oe.CanvasSelector);if(!e)throw new Error(`Shotstack canvas root element '${oe.CanvasSelector}' not found.`);this.registerExtensions(),this.container=new w.Container,this.background=new w.Graphics,this.background.fillStyle={color:"#424242"},this.background.rect(0,0,this.size.width,this.size.height),this.background.fill(),await this.configureApplication(),this.configureStage(),this.setupTouchHandling(e),this.edit.getContainer().scale=this.currentZoom,e.appendChild(this.application.canvas)}setupTouchHandling(e){const t=this.edit.getContainer();e.addEventListener("wheel",i=>{if(i.preventDefault(),i.stopPropagation(),i.ctrlKey){const s=Math.exp(-i.deltaY/100),n=this.currentZoom*s,r=this.currentZoom;this.currentZoom=Math.min(Math.max(n,this.minZoom),this.maxZoom);const o={x:this.application.canvas.width/2,y:this.application.canvas.height/2},h={x:t.position.x-o.x,y:t.position.y-o.y},c=this.currentZoom/r;t.position.x=o.x+h.x*c,t.position.y=o.y+h.y*c,t.scale.x=this.currentZoom,t.scale.y=this.currentZoom}},{passive:!1,capture:!0})}centerEdit(){if(!this.edit)return;const e=this.edit.getContainer();e.position={x:this.application.canvas.width/2-this.edit.size.width*this.currentZoom/2,y:this.application.canvas.height/2-this.edit.size.height*this.currentZoom/2}}zoomToFit(){if(!this.edit)return;const e=this.application.canvas.width/this.edit.size.width,t=this.application.canvas.height/this.edit.size.height,i=Math.min(e,t);this.currentZoom=Math.min(Math.max(i,this.minZoom),this.maxZoom);const s=this.edit.getContainer();s.scale.x=this.currentZoom,s.scale.y=this.currentZoom,this.centerEdit()}setZoom(e){this.currentZoom=Math.min(Math.max(e,this.minZoom),this.maxZoom);const t=this.edit.getContainer();t.scale.x=this.currentZoom,t.scale.y=this.currentZoom}registerExtensions(){oe.extensionsRegistered||(w.extensions.add(new Be),w.extensions.add(new Oe),oe.extensionsRegistered=!0)}async configureApplication(){const e={background:"#000000",width:this.size.width,height:this.size.height,antialias:!0};await this.application.init(e),this.application.ticker.add(this.onTick.bind(this)),this.application.ticker.minFPS=60,this.application.ticker.maxFPS=60}onTick(e){this.edit.update(e.deltaTime,e.deltaMS),this.edit.draw(),this.inspector.fps=Math.ceil(e.FPS),this.inspector.playbackTime=this.edit.playbackTime,this.inspector.playbackDuration=this.edit.totalDuration,this.inspector.isPlaying=this.edit.isPlaying,this.inspector.update(e.deltaTime,e.deltaMS),this.inspector.draw()}configureStage(){if(!this.container||!this.background)throw new Error("Shotstack canvas container not set up.");this.container.addChild(this.background),this.container.addChild(this.edit.getContainer()),this.container.addChild(this.inspector.getContainer()),this.application.stage.addChild(this.container),this.application.stage.eventMode="static",this.application.stage.hitArea=new w.Rectangle(0,0,this.size.width,this.size.height),this.application.stage.on("click",this.onClick.bind(this)),this.edit.getContainer().position={x:this.application.canvas.width/2-this.edit.size.width*this.currentZoom/2,y:this.application.canvas.height/2-this.edit.size.height*this.currentZoom/2}}onClick(){this.edit.pause()}dispose(){const e=document.querySelector(oe.CanvasSelector);e&&e.contains(this.application.canvas)&&e.removeChild(this.application.canvas),this.application.ticker.remove(this.onTick,this),this.application.stage.off("click",this.onClick,this),this.background?.destroy(),this.container?.destroy(),this.inspector.dispose(),this.application.destroy(!0,{children:!0,texture:!0})}}class ds{edit;seekDistance=50;seekDistanceLarge=500;frameTime=16.67;constructor(e){this.edit=e}async load(){document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keyup",this.handleKeyUp)}dispose(){document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp)}handleKeyDown=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.code){case"Space":{this.edit.isPlaying?this.edit.pause():this.edit.play();break}case"ArrowLeft":{if(e.metaKey)this.edit.seek(0);else{const t=e.shiftKey?this.seekDistanceLarge:this.seekDistance;this.edit.seek(this.edit.playbackTime-t)}break}case"ArrowRight":{if(e.metaKey)this.edit.seek(this.edit.getTotalDuration());else{const t=e.shiftKey?this.seekDistanceLarge:this.seekDistance;this.edit.seek(this.edit.playbackTime+t)}break}case"KeyJ":{this.edit.stop();break}case"KeyK":{this.edit.pause();break}case"KeyL":{this.edit.play();break}case"Comma":{this.edit.seek(this.edit.playbackTime-this.frameTime);break}case"Period":{this.edit.seek(this.edit.playbackTime+this.frameTime);break}}};handleKeyUp=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.code){case"KeyI":console.log(this.edit.getEdit());break}}}class fs{ffmpeg;isReady=!1;edit;application;constructor(e,t){this.edit=e,this.application=t.application,this.ffmpeg=new Ht.FFmpeg}async init(){if(!this.isReady)try{await this.ffmpeg.load(),this.isReady=!0}catch(e){throw console.error("FFmpeg initialization failed:",e),e}}async export(e="shotstack-export.mp4",t=30){this.isReady||await this.init();const i=this.edit.isPlaying,s=this.edit.playbackTime;this.edit.pause();const n=this.edit.getContainer(),r=n.visible,{x:o,y:h}=n.position,{x:c,y:l}=n.scale;n.visible=!1;const g=this.createProgressOverlay();try{const p=this.edit.getSize?this.edit.getSize():{width:1920,height:1080},k=Math.ceil(this.edit.totalDuration*t/1e3),A=1e3/t,S=100,D=50,ce=50,ye=O=>Math.round(O/k*D);this.updateProgressOverlay(g,0,S);const Y=document.createElement("canvas");Y.width=p.width,Y.height=p.height;const ve=Y.getContext("2d");if(!ve)throw new Error("Could not get 2D context for canvas");const ot=this.findAudioPlayers();this.updateProgressOverlay(g,2,S);const X=[];if(ot.length>0){this.updateProgressOverlay(g,3,S);for(let O=0;O<ot.length;O+=1){const Z=await this.processAudioTrack(ot[O],O);Z&&X.push(Z),this.updateProgressOverlay(g,4+O,S)}}n.position.x=0,n.position.y=0,n.scale.x=1,n.scale.y=1;for(let O=0;O<k;O+=1){this.edit.seek(O*A),this.edit.tick?this.edit.tick(0,0):(this.edit.update?.(0,0),this.edit.draw?.());try{const{extract:Z}=this.application.renderer,M=Z.canvas(n);ve.clearRect(0,0,Y.width,Y.height),ve.drawImage(M,0,0);const q=Y.toDataURL("image/png"),Ve=await(await fetch(q)).arrayBuffer(),gs=`frame_${O.toString().padStart(6,"0")}.png`;await this.ffmpeg.writeFile(gs,new Uint8Array(Ve))}catch(Z){console.error(`Error capturing frame ${O}:`,Z)}this.updateProgressOverlay(g,ye(O+1),S)}this.updateProgressOverlay(g,D,S);let ee=["-framerate",t.toString(),"-i","frame_%06d.png"];for(const O of X)ee=ee.concat(["-i",O.filename]);if(ee=ee.concat(["-c:v","libx264","-pix_fmt","yuv420p","-crf","23"]),X.length>0){let O="";for(let M=0;M<X.length;M+=1){const q=X[M],Dt=M+1,Ve=Math.max(0,q.start);O+=`[${Dt}:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,apad,afade=t=in:st=0:d=0.05,atrim=start=0:end=${q.duration/1e3+.1},adelay=${Ve}|${Ve},volume=${q.volume}[a${M}];`}const Z=X.length>1?`${X.map((M,q)=>`[a${q}]`).join("")}amix=inputs=${X.length}:duration=longest:dropout_transition=0.5:normalize=0[aout]`:"[a0]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo[aout]";O+=Z,ee=ee.concat(["-filter_complex",O,"-map","0:v","-map","[aout]","-c:a","aac","-b:a","192k","-shortest"])}const ct="output.mp4";ee.push(ct);let Mt=0;const Ft=({message:O})=>{const Z=O.includes("frame=")&&O.includes("fps=")?O.match(/frame=\s*(\d+)/):null;if(Z?.[1]){const M=parseInt(Z[1],10);if(!Number.isNaN(M)&&M>Mt&&(Mt=M,M<=k)){const q=Math.round(M/k*ce);this.updateProgressOverlay(g,D+q,S)}}};this.ffmpeg.on("log",Ft),await this.ffmpeg.exec(ee),this.ffmpeg.off("log",Ft),this.updateProgressOverlay(g,D+ce,S);const lt=await this.ffmpeg.readFile(ct),ps=lt instanceof Uint8Array?lt:new TextEncoder().encode(lt.toString()),ms=new Blob([ps],{type:"video/mp4"}),Nt=URL.createObjectURL(ms),ht=document.createElement("a");ht.href=Nt,ht.download=e,ht.click(),URL.revokeObjectURL(Nt);for(let O=0;O<k;O+=1)try{await this.ffmpeg.deleteFile(`frame_${O.toString().padStart(6,"0")}.png`)}catch{}for(const O of X)try{await this.ffmpeg.deleteFile(O.filename)}catch{}await this.ffmpeg.deleteFile(ct),this.updateProgressOverlay(g,S,S)}catch(p){throw console.error("Error during export:",p),p}finally{this.removeProgressOverlay(g),n.position.x=o,n.position.y=h,n.scale.x=c,n.scale.y=l,n.visible=r,this.edit.seek(s),i&&this.edit.play()}}findAudioPlayers(){const e=[],t=this.edit.tracks;if(t&&Array.isArray(t))for(let i=0;i<t.length;i+=1){const s=t[i];if(Array.isArray(s))for(let n=0;n<s.length;n+=1){const r=s[n];(r instanceof at||r.constructor.name==="AudioPlayer"||r.clipConfiguration?.asset?.type==="audio")&&(e.includes(r)||e.push(r))}}return this.searchContainerForPlayers(this.edit.getContainer(),e),e}searchContainerForPlayers(e,t){if(e){for(const i of e.children)if(i instanceof w.Container){if(i.label?.startsWith("shotstack-track-")){for(const n of i.children)if(n instanceof w.Container){const r=n,o=["player","clip","audioPlayer","entity"];for(const h of o){const c=r[h];c instanceof at&&!t.includes(c)&&t.push(c)}}}this.searchContainerForPlayers(i,t)}}}async processAudioTrack(e,t){try{const{clipConfiguration:i}=e;if(!i?.asset)return null;const s=i.asset;if(!s.src)return console.warn("Audio asset does not have a valid src property"),null;const n=await fetch(s.src);if(!n.ok)return console.error(`Failed to fetch audio file: ${s.src}`),null;const r=await n.arrayBuffer(),o=`audio_${t}.mp3`;return await this.ffmpeg.writeFile(o,new Uint8Array(r)),{filename:o,start:e.getStart(),duration:e.getLength(),volume:e.getVolume()}}catch(i){return console.error(`Error processing audio track ${t}:`,i),null}}createProgressOverlay(){const e=document.createElement("div");e.className="video-export-progress-overlay",Object.assign(e.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:"9999",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",color:"white",fontFamily:"Arial, sans-serif"});const t=document.createElement("div");Object.assign(t.style,{backgroundColor:"#222",borderRadius:"8px",padding:"20px",boxShadow:"0 4px 8px rgba(0, 0, 0, 0.2)",width:"300px",textAlign:"center"}),e.appendChild(t);const i=document.createElement("h3");i.innerText="Exporting Video",i.style.margin="0 0 15px 0",i.style.fontWeight="normal",t.appendChild(i);const s=document.createElement("div");Object.assign(s.style,{width:"100%",height:"6px",backgroundColor:"#444",borderRadius:"3px",overflow:"hidden",marginBottom:"10px"}),t.appendChild(s);const n=document.createElement("div");n.className="video-export-progress-bar",Object.assign(n.style,{width:"0%",height:"100%",backgroundColor:"#3498db",transition:"width 0.3s"}),s.appendChild(n);const r=document.createElement("div");return r.className="video-export-percent",r.innerText="0%",r.style.fontSize="12px",t.appendChild(r),document.body.appendChild(e),e}updateProgressOverlay(e,t,i){if(!e)return;const s=Math.round(t/i*100),n=e.querySelector(".video-export-progress-bar"),r=e.querySelector(".video-export-percent");n&&(n.style.width=`${s}%`),r&&(r.innerText=`${s}%`)}removeProgressOverlay(e){e?.parentNode?.removeChild(e)}}F.Canvas=oe,F.Controls=ds,F.Edit=re,F.VideoExporter=fs,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|