@bylqwjc/media-editor-server 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{ZodError as R,ZodIssueCode as o}from"./ZodError.js";import{defaultErrorMap as _e,getErrorMap as ye}from"./errors.js";import{errorUtil as l}from"./helpers/errorUtil.js";import{DIRTY as W,INVALID as f,OK as x,ParseStatus as w,addIssueToContext as c,isAborted as ge,isAsync as ie,isDirty as ve,isValid as D,makeIssue as ke}from"./helpers/parseUtil.js";import{util as k,ZodParsedType as h,getParsedType as j}from"./helpers/util.js";class C{constructor(e,t,s,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=s,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const xe=(n,e)=>{if(D(e))return{success:!0,data:e.value};if(!n.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 R(n.common.issues);return this._error=t,this._error}}};function _(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:s,description:a}=n;if(e&&(t||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(d,i)=>{const{message:r}=n;return d.code==="invalid_enum_value"?{message:r??i.defaultError}:typeof i.data>"u"?{message:r??s??i.defaultError}:d.code!=="invalid_type"?{message:i.defaultError}:{message:r??t??i.defaultError}},description:a}}class y{get description(){return this._def.description}_getType(e){return j(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new w,ctx:{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ie(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 s=this.safeParse(e,t);if(s.success)return s.data;throw s.error}safeParse(e,t){const s={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},a=this._parseSync({data:e,path:s.path,parent:s});return xe(s,a)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return D(s)?{value:s.value}:{issues:t.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>D(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const s=await this.safeParseAsync(e,t);if(s.success)return s.data;throw s.error}async safeParseAsync(e,t){const s={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},a=this._parse({data:e,path:s.path,parent:s}),d=await(ie(a)?a:Promise.resolve(a));return xe(s,d)}refine(e,t){const s=a=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(a):t;return this._refinement((a,d)=>{const i=e(a),r=()=>d.addIssue({code:o.custom,...s(a)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(r(),!1)):i?!0:(r(),!1)})}refinement(e,t){return this._refinement((s,a)=>e(s)?!0:(a.addIssue(typeof t=="function"?t(s,a):t),!1))}_refinement(e){return new b({schema:this,typeName:p.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 O.create(this,this._def)}nullable(){return I.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Z.create(this)}promise(){return K.create(this,this._def)}or(e){return J.create([this,e],this._def)}and(e){return G.create(this,e,this._def)}transform(e){return new b({..._(this._def),schema:this,typeName:p.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new te({..._(this._def),innerType:this,defaultValue:t,typeName:p.ZodDefault})}brand(){return new fe({typeName:p.ZodBranded,type:this,..._(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new se({..._(this._def),innerType:this,catchValue:t,typeName:p.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return ne.create(this,e)}readonly(){return ae.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const je=/^c[^\s-]{8,}$/i,Pe=/^[0-9a-z]+$/,Ie=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ee=/^[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,Fe=/^[a-z0-9_-]{21}$/i,Me=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Le=/^[-+]?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)?)??$/,$e=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ze="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let pe;const De=/^(?:(?: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])$/,Ue=/^(?:(?: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])$/,Ve=/^(([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]))$/,Ke=/^(([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])$/,Be=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,We=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,we="((\\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])))",Ye=new RegExp(`^${we}$`);function be(n){let e="[0-5]\\d";n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`);const t=n.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function qe(n){return new RegExp(`^${be(n)}$`)}function Ze(n){let e=`${we}T${be(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function He(n,e){return!!((e==="v4"||!e)&&De.test(n)||(e==="v6"||!e)&&Ve.test(n))}function Je(n,e){if(!Me.test(n))return!1;try{const[t]=n.split(".");if(!t)return!1;const s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),a=JSON.parse(atob(s));return!(typeof a!="object"||a===null||"typ"in a&&a?.typ!=="JWT"||!a.alg||e&&a.alg!==e)}catch{return!1}}function Ge(n,e){return!!((e==="v4"||!e)&&Ue.test(n)||(e==="v6"||!e)&&Ke.test(n))}class T extends y{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==h.string){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.string,received:a.parsedType}),f}const t=new w;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),t.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),t.dirty());else if(a.kind==="length"){const d=e.data.length>a.value,i=e.data.length<a.value;(d||i)&&(s=this._getOrReturnCtx(e,s),d?c(s,{code:o.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&c(s,{code:o.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),t.dirty())}else if(a.kind==="email")$e.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"email",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="emoji")pe||(pe=new RegExp(ze,"u")),pe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"emoji",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="uuid")Ee.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"uuid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="nanoid")Fe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"nanoid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="cuid")je.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cuid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="cuid2")Pe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cuid2",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="ulid")Ie.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"ulid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),c(s,{validation:"url",code:o.invalid_string,message:a.message}),t.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"regex",code:o.invalid_string,message:a.message}),t.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),t.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{startsWith:a.value},message:a.message}),t.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{endsWith:a.value},message:a.message}),t.dirty()):a.kind==="datetime"?Ze(a).test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"datetime",message:a.message}),t.dirty()):a.kind==="date"?Ye.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"date",message:a.message}),t.dirty()):a.kind==="time"?qe(a).test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"time",message:a.message}),t.dirty()):a.kind==="duration"?Le.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"duration",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="ip"?He(e.data,a.version)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"ip",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="jwt"?Je(e.data,a.alg)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"jwt",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="cidr"?Ge(e.data,a.version)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cidr",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="base64"?Be.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"base64",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="base64url"?We.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"base64url",code:o.invalid_string,message:a.message}),t.dirty()):k.assertNever(a);return{status:t.value,value:e.data}}_regex(e,t,s){return this.refinement(a=>e.test(a),{validation:t,code:o.invalid_string,...l.errToObj(s)})}_addCheck(e){return new T({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...l.errToObj(e)})}url(e){return this._addCheck({kind:"url",...l.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...l.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...l.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...l.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...l.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...l.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...l.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...l.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...l.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...l.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...l.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...l.errToObj(e)})}datetime(e){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:e?.offset??!1,local:e?.local??!1,...l.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,...l.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...l.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...l.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...l.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...l.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...l.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...l.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...l.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...l.errToObj(t)})}nonempty(e){return this.min(1,l.errToObj(e))}trim(){return new T({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new T({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new T({...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}}T.create=n=>new T({checks:[],typeName:p.ZodString,coerce:n?.coerce??!1,..._(n)});function Xe(n,e){const t=(n.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,a=t>s?t:s,d=Number.parseInt(n.toFixed(a).replace(".","")),i=Number.parseInt(e.toFixed(a).replace(".",""));return d%i/10**a}class E extends y{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)!==h.number){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.number,received:a.parsedType}),f}let t;const s=new w;for(const a of this._def.checks)a.kind==="int"?k.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),c(t,{code:o.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Xe(e.data,a.value)!==0&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_finite,message:a.message}),s.dirty()):k.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,l.toString(t))}gt(e,t){return this.setLimit("min",e,!1,l.toString(t))}lte(e,t){return this.setLimit("max",e,!0,l.toString(t))}lt(e,t){return this.setLimit("max",e,!1,l.toString(t))}setLimit(e,t,s,a){return new E({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:l.toString(a)}]})}_addCheck(e){return new E({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:l.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:l.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:l.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:l.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:l.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:l.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:l.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:l.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:l.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"&&k.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(t===null||s.value>t)&&(t=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(t)&&Number.isFinite(e)}}E.create=n=>new E({checks:[],typeName:p.ZodNumber,coerce:n?.coerce||!1,..._(n)});class F extends y{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)!==h.bigint)return this._getInvalidInput(e);let t;const s=new w;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):k.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.bigint,received:t.parsedType}),f}gte(e,t){return this.setLimit("min",e,!0,l.toString(t))}gt(e,t){return this.setLimit("min",e,!1,l.toString(t))}lte(e,t){return this.setLimit("max",e,!0,l.toString(t))}lt(e,t){return this.setLimit("max",e,!1,l.toString(t))}setLimit(e,t,s,a){return new F({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:l.toString(a)}]})}_addCheck(e){return new F({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:l.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:l.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:l.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:l.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:l.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}}F.create=n=>new F({checks:[],typeName:p.ZodBigInt,coerce:n?.coerce??!1,..._(n)});class Y extends y{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==h.boolean){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.boolean,received:t.parsedType}),f}return x(e.data)}}Y.create=n=>new Y({typeName:p.ZodBoolean,coerce:n?.coerce||!1,..._(n)});class $ extends y{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==h.date){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.date,received:a.parsedType}),f}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_date}),f}const t=new w;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),t.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),t.dirty()):k.assertNever(a);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new $({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:l.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:l.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}}$.create=n=>new $({checks:[],coerce:n?.coerce||!1,typeName:p.ZodDate,..._(n)});class de extends y{_parse(e){if(this._getType(e)!==h.symbol){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.symbol,received:t.parsedType}),f}return x(e.data)}}de.create=n=>new de({typeName:p.ZodSymbol,..._(n)});class q extends y{_parse(e){if(this._getType(e)!==h.undefined){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.undefined,received:t.parsedType}),f}return x(e.data)}}q.create=n=>new q({typeName:p.ZodUndefined,..._(n)});class H extends y{_parse(e){if(this._getType(e)!==h.null){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.null,received:t.parsedType}),f}return x(e.data)}}H.create=n=>new H({typeName:p.ZodNull,..._(n)});class U extends y{constructor(){super(...arguments),this._any=!0}_parse(e){return x(e.data)}}U.create=n=>new U({typeName:p.ZodAny,..._(n)});class L extends y{constructor(){super(...arguments),this._unknown=!0}_parse(e){return x(e.data)}}L.create=n=>new L({typeName:p.ZodUnknown,..._(n)});class N extends y{_parse(e){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.never,received:t.parsedType}),f}}N.create=n=>new N({typeName:p.ZodNever,..._(n)});class oe extends y{_parse(e){if(this._getType(e)!==h.undefined){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.void,received:t.parsedType}),f}return x(e.data)}}oe.create=n=>new oe({typeName:p.ZodVoid,..._(n)});class Z extends y{_parse(e){const{ctx:t,status:s}=this._processInputParams(e),a=this._def;if(t.parsedType!==h.array)return c(t,{code:o.invalid_type,expected:h.array,received:t.parsedType}),f;if(a.exactLength!==null){const i=t.data.length>a.exactLength.value,r=t.data.length<a.exactLength.value;(i||r)&&(c(t,{code:i?o.too_big:o.too_small,minimum:r?a.exactLength.value:void 0,maximum:i?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),s.dirty())}if(a.minLength!==null&&t.data.length<a.minLength.value&&(c(t,{code:o.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),s.dirty()),a.maxLength!==null&&t.data.length>a.maxLength.value&&(c(t,{code:o.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map((i,r)=>a.type._parseAsync(new C(t,i,t.path,r)))).then(i=>w.mergeArray(s,i));const d=[...t.data].map((i,r)=>a.type._parseSync(new C(t,i,t.path,r)));return w.mergeArray(s,d)}get element(){return this._def.type}min(e,t){return new Z({...this._def,minLength:{value:e,message:l.toString(t)}})}max(e,t){return new Z({...this._def,maxLength:{value:e,message:l.toString(t)}})}length(e,t){return new Z({...this._def,exactLength:{value:e,message:l.toString(t)}})}nonempty(e){return this.min(1,e)}}Z.create=(n,e)=>new Z({type:n,minLength:null,maxLength:null,exactLength:null,typeName:p.ZodArray,..._(e)});function V(n){if(n instanceof v){const e={};for(const t in n.shape){const s=n.shape[t];e[t]=O.create(V(s))}return new v({...n._def,shape:()=>e})}else return n instanceof Z?new Z({...n._def,type:V(n.element)}):n instanceof O?O.create(V(n.unwrap())):n instanceof I?I.create(V(n.unwrap())):n instanceof A?A.create(n.items.map(e=>V(e))):n}class v extends y{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=k.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==h.object){const u=this._getOrReturnCtx(e);return c(u,{code:o.invalid_type,expected:h.object,received:u.parsedType}),f}const{status:t,ctx:s}=this._processInputParams(e),{shape:a,keys:d}=this._getCached(),i=[];if(!(this._def.catchall instanceof N&&this._def.unknownKeys==="strip"))for(const u in s.data)d.includes(u)||i.push(u);const r=[];for(const u of d){const m=a[u],g=s.data[u];r.push({key:{status:"valid",value:u},value:m._parse(new C(s,g,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof N){const u=this._def.unknownKeys;if(u==="passthrough")for(const m of i)r.push({key:{status:"valid",value:m},value:{status:"valid",value:s.data[m]}});else if(u==="strict")i.length>0&&(c(s,{code:o.unrecognized_keys,keys:i}),t.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const m of i){const g=s.data[m];r.push({key:{status:"valid",value:m},value:u._parse(new C(s,g,s.path,m)),alwaysSet:m in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const m of r){const g=await m.key,S=await m.value;u.push({key:g,value:S,alwaysSet:m.alwaysSet})}return u}).then(u=>w.mergeObjectSync(t,u)):w.mergeObjectSync(t,r)}get shape(){return this._def.shape()}strict(e){return l.errToObj,new v({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,s)=>{const a=this._def.errorMap?.(t,s).message??s.defaultError;return t.code==="unrecognized_keys"?{message:l.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new v({...this._def,unknownKeys:"strip"})}passthrough(){return new v({...this._def,unknownKeys:"passthrough"})}extend(e){return new v({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new v({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:p.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new v({...this._def,catchall:e})}pick(e){const t={};for(const s of k.objectKeys(e))e[s]&&this.shape[s]&&(t[s]=this.shape[s]);return new v({...this._def,shape:()=>t})}omit(e){const t={};for(const s of k.objectKeys(this.shape))e[s]||(t[s]=this.shape[s]);return new v({...this._def,shape:()=>t})}deepPartial(){return V(this)}partial(e){const t={};for(const s of k.objectKeys(this.shape)){const a=this.shape[s];e&&!e[s]?t[s]=a:t[s]=a.optional()}return new v({...this._def,shape:()=>t})}required(e){const t={};for(const s of k.objectKeys(this.shape))if(e&&!e[s])t[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof O;)a=a._def.innerType;t[s]=a}return new v({...this._def,shape:()=>t})}keyof(){return Te(k.objectKeys(this.shape))}}v.create=(n,e)=>new v({shape:()=>n,unknownKeys:"strip",catchall:N.create(),typeName:p.ZodObject,..._(e)}),v.strictCreate=(n,e)=>new v({shape:()=>n,unknownKeys:"strict",catchall:N.create(),typeName:p.ZodObject,..._(e)}),v.lazycreate=(n,e)=>new v({shape:n,unknownKeys:"strip",catchall:N.create(),typeName:p.ZodObject,..._(e)});class J extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s=this._def.options;function a(d){for(const r of d)if(r.result.status==="valid")return r.result;for(const r of d)if(r.result.status==="dirty")return t.common.issues.push(...r.ctx.common.issues),r.result;const i=d.map(r=>new R(r.ctx.common.issues));return c(t,{code:o.invalid_union,unionErrors:i}),f}if(t.common.async)return Promise.all(s.map(async d=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await d._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(a);{let d;const i=[];for(const u of s){const m={...t,common:{...t.common,issues:[]},parent:null},g=u._parseSync({data:t.data,path:t.path,parent:m});if(g.status==="valid")return g;g.status==="dirty"&&!d&&(d={result:g,ctx:m}),m.common.issues.length&&i.push(m.common.issues)}if(d)return t.common.issues.push(...d.ctx.common.issues),d.result;const r=i.map(u=>new R(u));return c(t,{code:o.invalid_union,unionErrors:r}),f}}get options(){return this._def.options}}J.create=(n,e)=>new J({options:n,typeName:p.ZodUnion,..._(e)});const P=n=>n instanceof X?P(n.schema):n instanceof b?P(n.innerType()):n instanceof Q?[n.value]:n instanceof M?n.options:n instanceof ee?k.objectValues(n.enum):n instanceof te?P(n._def.innerType):n instanceof q?[void 0]:n instanceof H?[null]:n instanceof O?[void 0,...P(n.unwrap())]:n instanceof I?[null,...P(n.unwrap())]:n instanceof fe||n instanceof ae?P(n.unwrap()):n instanceof se?P(n._def.innerType):[];class le extends y{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.object)return c(t,{code:o.invalid_type,expected:h.object,received:t.parsedType}),f;const s=this.discriminator,a=t.data[s],d=this.optionsMap.get(a);return d?t.common.async?d._parseAsync({data:t.data,path:t.path,parent:t}):d._parseSync({data:t.data,path:t.path,parent:t}):(c(t,{code:o.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),f)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,s){const a=new Map;for(const d of t){const i=P(d.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const r of i){if(a.has(r))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(r)}`);a.set(r,d)}}return new le({typeName:p.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:a,..._(s)})}}function me(n,e){const t=j(n),s=j(e);if(n===e)return{valid:!0,data:n};if(t===h.object&&s===h.object){const a=k.objectKeys(e),d=k.objectKeys(n).filter(r=>a.indexOf(r)!==-1),i={...n,...e};for(const r of d){const u=me(n[r],e[r]);if(!u.valid)return{valid:!1};i[r]=u.data}return{valid:!0,data:i}}else if(t===h.array&&s===h.array){if(n.length!==e.length)return{valid:!1};const a=[];for(let d=0;d<n.length;d++){const i=n[d],r=e[d],u=me(i,r);if(!u.valid)return{valid:!1};a.push(u.data)}return{valid:!0,data:a}}else return t===h.date&&s===h.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class G extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=(d,i)=>{if(ge(d)||ge(i))return f;const r=me(d.value,i.value);return r.valid?((ve(d)||ve(i))&&t.dirty(),{status:t.value,value:r.data}):(c(s,{code:o.invalid_intersection_types}),f)};return s.common.async?Promise.all([this._def.left._parseAsync({data:s.data,path:s.path,parent:s}),this._def.right._parseAsync({data:s.data,path:s.path,parent:s})]).then(([d,i])=>a(d,i)):a(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}}G.create=(n,e,t)=>new G({left:n,right:e,typeName:p.ZodIntersection,..._(t)});class A extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.array)return c(s,{code:o.invalid_type,expected:h.array,received:s.parsedType}),f;if(s.data.length<this._def.items.length)return c(s,{code:o.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),f;!this._def.rest&&s.data.length>this._def.items.length&&(c(s,{code:o.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...s.data].map((d,i)=>{const r=this._def.items[i]||this._def.rest;return r?r._parse(new C(s,d,s.path,i)):null}).filter(d=>!!d);return s.common.async?Promise.all(a).then(d=>w.mergeArray(t,d)):w.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new A({...this._def,rest:e})}}A.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new A({items:n,typeName:p.ZodTuple,rest:null,..._(e)})};class re extends y{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.object)return c(s,{code:o.invalid_type,expected:h.object,received:s.parsedType}),f;const a=[],d=this._def.keyType,i=this._def.valueType;for(const r in s.data)a.push({key:d._parse(new C(s,r,s.path,r)),value:i._parse(new C(s,s.data[r],s.path,r)),alwaysSet:r in s.data});return s.common.async?w.mergeObjectAsync(t,a):w.mergeObjectSync(t,a)}get element(){return this._def.valueType}static create(e,t,s){return t instanceof y?new re({keyType:e,valueType:t,typeName:p.ZodRecord,..._(s)}):new re({keyType:T.create(),valueType:e,typeName:p.ZodRecord,..._(t)})}}class ce extends y{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.map)return c(s,{code:o.invalid_type,expected:h.map,received:s.parsedType}),f;const a=this._def.keyType,d=this._def.valueType,i=[...s.data.entries()].map(([r,u],m)=>({key:a._parse(new C(s,r,s.path,[m,"key"])),value:d._parse(new C(s,u,s.path,[m,"value"]))}));if(s.common.async){const r=new Map;return Promise.resolve().then(async()=>{for(const u of i){const m=await u.key,g=await u.value;if(m.status==="aborted"||g.status==="aborted")return f;(m.status==="dirty"||g.status==="dirty")&&t.dirty(),r.set(m.value,g.value)}return{status:t.value,value:r}})}else{const r=new Map;for(const u of i){const m=u.key,g=u.value;if(m.status==="aborted"||g.status==="aborted")return f;(m.status==="dirty"||g.status==="dirty")&&t.dirty(),r.set(m.value,g.value)}return{status:t.value,value:r}}}}ce.create=(n,e,t)=>new ce({valueType:e,keyType:n,typeName:p.ZodMap,..._(t)});class z extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.set)return c(s,{code:o.invalid_type,expected:h.set,received:s.parsedType}),f;const a=this._def;a.minSize!==null&&s.data.size<a.minSize.value&&(c(s,{code:o.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),a.maxSize!==null&&s.data.size>a.maxSize.value&&(c(s,{code:o.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());const d=this._def.valueType;function i(u){const m=new Set;for(const g of u){if(g.status==="aborted")return f;g.status==="dirty"&&t.dirty(),m.add(g.value)}return{status:t.value,value:m}}const r=[...s.data.values()].map((u,m)=>d._parse(new C(s,u,s.path,m)));return s.common.async?Promise.all(r).then(u=>i(u)):i(r)}min(e,t){return new z({...this._def,minSize:{value:e,message:l.toString(t)}})}max(e,t){return new z({...this._def,maxSize:{value:e,message:l.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}z.create=(n,e)=>new z({valueType:n,minSize:null,maxSize:null,typeName:p.ZodSet,..._(e)});class B extends y{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.function)return c(t,{code:o.invalid_type,expected:h.function,received:t.parsedType}),f;function s(r,u){return ke({data:r,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,ye(),_e].filter(m=>!!m),issueData:{code:o.invalid_arguments,argumentsError:u}})}function a(r,u){return ke({data:r,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,ye(),_e].filter(m=>!!m),issueData:{code:o.invalid_return_type,returnTypeError:u}})}const d={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof K){const r=this;return x(async function(...u){const m=new R([]),g=await r._def.args.parseAsync(u,d).catch(he=>{throw m.addIssue(s(u,he)),m}),S=await Reflect.apply(i,this,g);return await r._def.returns._def.type.parseAsync(S,d).catch(he=>{throw m.addIssue(a(S,he)),m})})}else{const r=this;return x(function(...u){const m=r._def.args.safeParse(u,d);if(!m.success)throw new R([s(u,m.error)]);const g=Reflect.apply(i,this,m.data),S=r._def.returns.safeParse(g,d);if(!S.success)throw new R([a(g,S.error)]);return S.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new B({...this._def,args:A.create(e).rest(L.create())})}returns(e){return new B({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,s){return new B({args:e||A.create([]).rest(L.create()),returns:t||L.create(),typeName:p.ZodFunction,..._(s)})}}class X extends y{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})}}X.create=(n,e)=>new X({getter:n,typeName:p.ZodLazy,..._(e)});class Q extends y{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return c(t,{received:t.data,code:o.invalid_literal,expected:this._def.value}),f}return{status:"valid",value:e.data}}get value(){return this._def.value}}Q.create=(n,e)=>new Q({value:n,typeName:p.ZodLiteral,..._(e)});function Te(n,e){return new M({values:n,typeName:p.ZodEnum,..._(e)})}class M extends y{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),s=this._def.values;return c(t,{expected:k.joinValues(s),received:t.parsedType,code:o.invalid_type}),f}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),s=this._def.values;return c(t,{received:t.data,code:o.invalid_enum_value,options:s}),f}return x(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 M.create(e,{...this._def,...t})}exclude(e,t=this._def){return M.create(this.options.filter(s=>!e.includes(s)),{...this._def,...t})}}M.create=Te;class ee extends y{_parse(e){const t=k.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==h.string&&s.parsedType!==h.number){const a=k.objectValues(t);return c(s,{expected:k.joinValues(a),received:s.parsedType,code:o.invalid_type}),f}if(this._cache||(this._cache=new Set(k.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const a=k.objectValues(t);return c(s,{received:s.data,code:o.invalid_enum_value,options:a}),f}return x(e.data)}get enum(){return this._def.values}}ee.create=(n,e)=>new ee({values:n,typeName:p.ZodNativeEnum,..._(e)});class K extends y{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.promise&&t.common.async===!1)return c(t,{code:o.invalid_type,expected:h.promise,received:t.parsedType}),f;const s=t.parsedType===h.promise?t.data:Promise.resolve(t.data);return x(s.then(a=>this._def.type.parseAsync(a,{path:t.path,errorMap:t.common.contextualErrorMap})))}}K.create=(n,e)=>new K({type:n,typeName:p.ZodPromise,..._(e)});class b extends y{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===p.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=this._def.effect||null,d={addIssue:i=>{c(s,i),i.fatal?t.abort():t.dirty()},get path(){return s.path}};if(d.addIssue=d.addIssue.bind(d),a.type==="preprocess"){const i=a.transform(s.data,d);if(s.common.async)return Promise.resolve(i).then(async r=>{if(t.value==="aborted")return f;const u=await this._def.schema._parseAsync({data:r,path:s.path,parent:s});return u.status==="aborted"?f:u.status==="dirty"?W(u.value):t.value==="dirty"?W(u.value):u});{if(t.value==="aborted")return f;const r=this._def.schema._parseSync({data:i,path:s.path,parent:s});return r.status==="aborted"?f:r.status==="dirty"?W(r.value):t.value==="dirty"?W(r.value):r}}if(a.type==="refinement"){const i=r=>{const u=a.refinement(r,d);if(s.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return r};if(s.common.async===!1){const r=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return r.status==="aborted"?f:(r.status==="dirty"&&t.dirty(),i(r.value),{status:t.value,value:r.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(r=>r.status==="aborted"?f:(r.status==="dirty"&&t.dirty(),i(r.value).then(()=>({status:t.value,value:r.value}))))}if(a.type==="transform")if(s.common.async===!1){const i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!D(i))return f;const r=a.transform(i.value,d);if(r instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:r}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>D(i)?Promise.resolve(a.transform(i.value,d)).then(r=>({status:t.value,value:r})):f);k.assertNever(a)}}b.create=(n,e,t)=>new b({schema:n,typeName:p.ZodEffects,effect:e,..._(t)}),b.createWithPreprocess=(n,e,t)=>new b({schema:e,effect:{type:"preprocess",transform:n},typeName:p.ZodEffects,..._(t)});class O extends y{_parse(e){return this._getType(e)===h.undefined?x(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}O.create=(n,e)=>new O({innerType:n,typeName:p.ZodOptional,..._(e)});class I extends y{_parse(e){return this._getType(e)===h.null?x(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}I.create=(n,e)=>new I({innerType:n,typeName:p.ZodNullable,..._(e)});class te extends y{_parse(e){const{ctx:t}=this._processInputParams(e);let s=t.data;return t.parsedType===h.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}te.create=(n,e)=>new te({innerType:n,typeName:p.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class se extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return ie(a)?a.then(d=>({status:"valid",value:d.status==="valid"?d.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}}se.create=(n,e)=>new se({innerType:n,typeName:p.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class ue extends y{_parse(e){if(this._getType(e)!==h.nan){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.nan,received:t.parsedType}),f}return{status:"valid",value:e.data}}}ue.create=n=>new ue({typeName:p.ZodNaN,..._(n)});const Qe=Symbol("zod_brand");class fe extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}}class ne extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?f:a.status==="dirty"?(t.dirty(),W(a.value)):this._def.out._parseAsync({data:a.value,path:s.path,parent:s})})();{const a=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?f:a.status==="dirty"?(t.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:s.path,parent:s})}}static create(e,t){return new ne({in:e,out:t,typeName:p.ZodPipeline})}}class ae extends y{_parse(e){const t=this._def.innerType._parse(e),s=a=>(D(a)&&(a.value=Object.freeze(a.value)),a);return ie(t)?t.then(a=>s(a)):s(t)}unwrap(){return this._def.innerType}}ae.create=(n,e)=>new ae({innerType:n,typeName:p.ZodReadonly,..._(e)});function Ce(n,e){const t=typeof n=="function"?n(e):typeof n=="string"?{message:n}:n;return typeof t=="string"?{message:t}:t}function Oe(n,e={},t){return n?U.create().superRefine((s,a)=>{const d=n(s);if(d instanceof Promise)return d.then(i=>{if(!i){const r=Ce(e,s),u=r.fatal??t??!0;a.addIssue({code:"custom",...r,fatal:u})}});if(!d){const i=Ce(e,s),r=i.fatal??t??!0;a.addIssue({code:"custom",...i,fatal:r})}}):U.create()}const et={object:v.lazycreate};var p;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(p||(p={}));class Ut{constructor(...e){}}const tt=(n,e={message:`Input not instance of ${n.name}`})=>Oe(t=>t instanceof n,e),Ae=T.create,Ne=E.create,st=ue.create,at=F.create,Se=Y.create,nt=$.create,rt=de.create,it=q.create,dt=H.create,ot=U.create,ct=L.create,ut=N.create,lt=oe.create,ht=Z.create,pt=v.create,mt=v.strictCreate,ft=J.create,_t=le.create,yt=G.create,gt=A.create,vt=re.create,kt=ce.create,xt=z.create,wt=B.create,bt=X.create,Zt=Q.create,Tt=M.create,Ct=ee.create,Ot=K.create,Re=b.create,At=O.create,Nt=I.create,St=b.createWithPreprocess,Rt=ne.create,jt=()=>Ae().optional(),Pt=()=>Ne().optional(),It=()=>Se().optional(),Et={string:(n=>T.create({...n,coerce:!0})),number:(n=>E.create({...n,coerce:!0})),boolean:(n=>Y.create({...n,coerce:!0})),bigint:(n=>F.create({...n,coerce:!0})),date:(n=>$.create({...n,coerce:!0}))},Ft=f;export{Qe as BRAND,Ft as NEVER,y as Schema,U as ZodAny,Z as ZodArray,F as ZodBigInt,Y as ZodBoolean,fe as ZodBranded,se as ZodCatch,$ as ZodDate,te as ZodDefault,le as ZodDiscriminatedUnion,b as ZodEffects,M as ZodEnum,p as ZodFirstPartyTypeKind,B as ZodFunction,G as ZodIntersection,X as ZodLazy,Q as ZodLiteral,ce as ZodMap,ue as ZodNaN,ee as ZodNativeEnum,N as ZodNever,H as ZodNull,I as ZodNullable,E as ZodNumber,v as ZodObject,O as ZodOptional,ne as ZodPipeline,K as ZodPromise,ae as ZodReadonly,re as ZodRecord,y as ZodSchema,z as ZodSet,T as ZodString,de as ZodSymbol,b as ZodTransformer,A as ZodTuple,y as ZodType,q as ZodUndefined,J as ZodUnion,L as ZodUnknown,oe as ZodVoid,ot as any,ht as array,at as bigint,Se as boolean,Et as coerce,Oe as custom,nt as date,Ze as datetimeRegex,_t as discriminatedUnion,Re as effect,Tt as enum,wt as function,tt as instanceof,yt as intersection,et as late,bt as lazy,Zt as literal,kt as map,st as nan,Ct as nativeEnum,ut as never,dt as null,Nt as nullable,Ne as number,pt as object,It as oboolean,Pt as onumber,At as optional,jt as ostring,Rt as pipeline,St as preprocess,Ot as promise,vt as record,xt as set,mt as strictObject,Ae as string,rt as symbol,Re as transformer,gt as tuple,it as undefined,ft as union,ct as unknown,lt as void};
1
+ import{ZodError as R,ZodIssueCode as o}from"./ZodError.js";import{defaultErrorMap as _e,getErrorMap as ye}from"./errors.js";import{errorUtil as l}from"./helpers/errorUtil.js";import{DIRTY as W,INVALID as f,OK as x,ParseStatus as w,addIssueToContext as c,isAborted as ge,isAsync as ie,isDirty as ve,isValid as D,makeIssue as ke}from"./helpers/parseUtil.js";import{util as k,ZodParsedType as h,getParsedType as j}from"./helpers/util.js";class C{constructor(e,t,s,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=s,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const xe=(r,e)=>{if(D(e))return{success:!0,data:e.value};if(!r.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 R(r.common.issues);return this._error=t,this._error}}};function _(r){if(!r)return{};const{errorMap:e,invalid_type_error:t,required_error:s,description:a}=r;if(e&&(t||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(d,i)=>{const{message:n}=r;return d.code==="invalid_enum_value"?{message:n??i.defaultError}:typeof i.data>"u"?{message:n??s??i.defaultError}:d.code!=="invalid_type"?{message:i.defaultError}:{message:n??t??i.defaultError}},description:a}}class y{get description(){return this._def.description}_getType(e){return j(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new w,ctx:{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ie(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 s=this.safeParse(e,t);if(s.success)return s.data;throw s.error}safeParse(e,t){const s={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},a=this._parseSync({data:e,path:s.path,parent:s});return xe(s,a)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return D(s)?{value:s.value}:{issues:t.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>D(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const s=await this.safeParseAsync(e,t);if(s.success)return s.data;throw s.error}async safeParseAsync(e,t){const s={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},a=this._parse({data:e,path:s.path,parent:s}),d=await(ie(a)?a:Promise.resolve(a));return xe(s,d)}refine(e,t){const s=a=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(a):t;return this._refinement((a,d)=>{const i=e(a),n=()=>d.addIssue({code:o.custom,...s(a)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(n(),!1)):i?!0:(n(),!1)})}refinement(e,t){return this._refinement((s,a)=>e(s)?!0:(a.addIssue(typeof t=="function"?t(s,a):t),!1))}_refinement(e){return new b({schema:this,typeName:p.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 O.create(this,this._def)}nullable(){return I.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Z.create(this)}promise(){return K.create(this,this._def)}or(e){return J.create([this,e],this._def)}and(e){return G.create(this,e,this._def)}transform(e){return new b({..._(this._def),schema:this,typeName:p.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new te({..._(this._def),innerType:this,defaultValue:t,typeName:p.ZodDefault})}brand(){return new fe({typeName:p.ZodBranded,type:this,..._(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new se({..._(this._def),innerType:this,catchValue:t,typeName:p.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return re.create(this,e)}readonly(){return ae.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const je=/^c[^\s-]{8,}$/i,Pe=/^[0-9a-z]+$/,Ie=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ee=/^[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,Fe=/^[a-z0-9_-]{21}$/i,Le=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Me=/^[-+]?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)?)??$/,$e=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ze="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let pe;const De=/^(?:(?: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])$/,Ue=/^(?:(?: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])$/,Ve=/^(([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]))$/,Ke=/^(([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])$/,Be=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,We=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,we="((\\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])))",Ye=new RegExp(`^${we}$`);function be(r){let e="[0-5]\\d";r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`);const t=r.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function qe(r){return new RegExp(`^${be(r)}$`)}function Ze(r){let e=`${we}T${be(r)}`;const t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function He(r,e){return!!((e==="v4"||!e)&&De.test(r)||(e==="v6"||!e)&&Ve.test(r))}function Je(r,e){if(!Le.test(r))return!1;try{const[t]=r.split(".");if(!t)return!1;const s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),a=JSON.parse(atob(s));return!(typeof a!="object"||a===null||"typ"in a&&a?.typ!=="JWT"||!a.alg||e&&a.alg!==e)}catch{return!1}}function Ge(r,e){return!!((e==="v4"||!e)&&Ue.test(r)||(e==="v6"||!e)&&Ke.test(r))}class T extends y{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==h.string){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.string,received:a.parsedType}),f}const t=new w;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),t.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),t.dirty());else if(a.kind==="length"){const d=e.data.length>a.value,i=e.data.length<a.value;(d||i)&&(s=this._getOrReturnCtx(e,s),d?c(s,{code:o.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&c(s,{code:o.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),t.dirty())}else if(a.kind==="email")$e.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"email",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="emoji")pe||(pe=new RegExp(ze,"u")),pe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"emoji",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="uuid")Ee.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"uuid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="nanoid")Fe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"nanoid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="cuid")je.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cuid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="cuid2")Pe.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cuid2",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="ulid")Ie.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"ulid",code:o.invalid_string,message:a.message}),t.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),c(s,{validation:"url",code:o.invalid_string,message:a.message}),t.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"regex",code:o.invalid_string,message:a.message}),t.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),t.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{startsWith:a.value},message:a.message}),t.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:{endsWith:a.value},message:a.message}),t.dirty()):a.kind==="datetime"?Ze(a).test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"datetime",message:a.message}),t.dirty()):a.kind==="date"?Ye.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"date",message:a.message}),t.dirty()):a.kind==="time"?qe(a).test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{code:o.invalid_string,validation:"time",message:a.message}),t.dirty()):a.kind==="duration"?Me.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"duration",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="ip"?He(e.data,a.version)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"ip",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="jwt"?Je(e.data,a.alg)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"jwt",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="cidr"?Ge(e.data,a.version)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"cidr",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="base64"?Be.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"base64",code:o.invalid_string,message:a.message}),t.dirty()):a.kind==="base64url"?We.test(e.data)||(s=this._getOrReturnCtx(e,s),c(s,{validation:"base64url",code:o.invalid_string,message:a.message}),t.dirty()):k.assertNever(a);return{status:t.value,value:e.data}}_regex(e,t,s){return this.refinement(a=>e.test(a),{validation:t,code:o.invalid_string,...l.errToObj(s)})}_addCheck(e){return new T({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...l.errToObj(e)})}url(e){return this._addCheck({kind:"url",...l.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...l.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...l.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...l.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...l.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...l.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...l.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...l.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...l.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...l.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...l.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...l.errToObj(e)})}datetime(e){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:e?.offset??!1,local:e?.local??!1,...l.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,...l.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...l.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...l.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...l.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...l.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...l.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...l.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...l.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...l.errToObj(t)})}nonempty(e){return this.min(1,l.errToObj(e))}trim(){return new T({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new T({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new T({...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}}T.create=r=>new T({checks:[],typeName:p.ZodString,coerce:r?.coerce??!1,..._(r)});function Xe(r,e){const t=(r.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,a=t>s?t:s,d=Number.parseInt(r.toFixed(a).replace(".","")),i=Number.parseInt(e.toFixed(a).replace(".",""));return d%i/10**a}class E extends y{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)!==h.number){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.number,received:a.parsedType}),f}let t;const s=new w;for(const a of this._def.checks)a.kind==="int"?k.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),c(t,{code:o.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Xe(e.data,a.value)!==0&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_finite,message:a.message}),s.dirty()):k.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,l.toString(t))}gt(e,t){return this.setLimit("min",e,!1,l.toString(t))}lte(e,t){return this.setLimit("max",e,!0,l.toString(t))}lt(e,t){return this.setLimit("max",e,!1,l.toString(t))}setLimit(e,t,s,a){return new E({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:l.toString(a)}]})}_addCheck(e){return new E({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:l.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:l.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:l.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:l.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:l.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:l.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:l.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:l.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:l.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"&&k.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(t===null||s.value>t)&&(t=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(t)&&Number.isFinite(e)}}E.create=r=>new E({checks:[],typeName:p.ZodNumber,coerce:r?.coerce||!1,..._(r)});class F extends y{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)!==h.bigint)return this._getInvalidInput(e);let t;const s=new w;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),c(t,{code:o.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):k.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.bigint,received:t.parsedType}),f}gte(e,t){return this.setLimit("min",e,!0,l.toString(t))}gt(e,t){return this.setLimit("min",e,!1,l.toString(t))}lte(e,t){return this.setLimit("max",e,!0,l.toString(t))}lt(e,t){return this.setLimit("max",e,!1,l.toString(t))}setLimit(e,t,s,a){return new F({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:l.toString(a)}]})}_addCheck(e){return new F({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:l.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:l.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:l.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:l.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:l.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}}F.create=r=>new F({checks:[],typeName:p.ZodBigInt,coerce:r?.coerce??!1,..._(r)});class Y extends y{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==h.boolean){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.boolean,received:t.parsedType}),f}return x(e.data)}}Y.create=r=>new Y({typeName:p.ZodBoolean,coerce:r?.coerce||!1,..._(r)});class $ extends y{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==h.date){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_type,expected:h.date,received:a.parsedType}),f}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return c(a,{code:o.invalid_date}),f}const t=new w;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),t.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),c(s,{code:o.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),t.dirty()):k.assertNever(a);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new $({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:l.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:l.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}}$.create=r=>new $({checks:[],coerce:r?.coerce||!1,typeName:p.ZodDate,..._(r)});class de extends y{_parse(e){if(this._getType(e)!==h.symbol){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.symbol,received:t.parsedType}),f}return x(e.data)}}de.create=r=>new de({typeName:p.ZodSymbol,..._(r)});class q extends y{_parse(e){if(this._getType(e)!==h.undefined){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.undefined,received:t.parsedType}),f}return x(e.data)}}q.create=r=>new q({typeName:p.ZodUndefined,..._(r)});class H extends y{_parse(e){if(this._getType(e)!==h.null){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.null,received:t.parsedType}),f}return x(e.data)}}H.create=r=>new H({typeName:p.ZodNull,..._(r)});class U extends y{constructor(){super(...arguments),this._any=!0}_parse(e){return x(e.data)}}U.create=r=>new U({typeName:p.ZodAny,..._(r)});class M extends y{constructor(){super(...arguments),this._unknown=!0}_parse(e){return x(e.data)}}M.create=r=>new M({typeName:p.ZodUnknown,..._(r)});class N extends y{_parse(e){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.never,received:t.parsedType}),f}}N.create=r=>new N({typeName:p.ZodNever,..._(r)});class oe extends y{_parse(e){if(this._getType(e)!==h.undefined){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.void,received:t.parsedType}),f}return x(e.data)}}oe.create=r=>new oe({typeName:p.ZodVoid,..._(r)});class Z extends y{_parse(e){const{ctx:t,status:s}=this._processInputParams(e),a=this._def;if(t.parsedType!==h.array)return c(t,{code:o.invalid_type,expected:h.array,received:t.parsedType}),f;if(a.exactLength!==null){const i=t.data.length>a.exactLength.value,n=t.data.length<a.exactLength.value;(i||n)&&(c(t,{code:i?o.too_big:o.too_small,minimum:n?a.exactLength.value:void 0,maximum:i?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),s.dirty())}if(a.minLength!==null&&t.data.length<a.minLength.value&&(c(t,{code:o.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),s.dirty()),a.maxLength!==null&&t.data.length>a.maxLength.value&&(c(t,{code:o.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map((i,n)=>a.type._parseAsync(new C(t,i,t.path,n)))).then(i=>w.mergeArray(s,i));const d=[...t.data].map((i,n)=>a.type._parseSync(new C(t,i,t.path,n)));return w.mergeArray(s,d)}get element(){return this._def.type}min(e,t){return new Z({...this._def,minLength:{value:e,message:l.toString(t)}})}max(e,t){return new Z({...this._def,maxLength:{value:e,message:l.toString(t)}})}length(e,t){return new Z({...this._def,exactLength:{value:e,message:l.toString(t)}})}nonempty(e){return this.min(1,e)}}Z.create=(r,e)=>new Z({type:r,minLength:null,maxLength:null,exactLength:null,typeName:p.ZodArray,..._(e)});function V(r){if(r instanceof v){const e={};for(const t in r.shape){const s=r.shape[t];e[t]=O.create(V(s))}return new v({...r._def,shape:()=>e})}else return r instanceof Z?new Z({...r._def,type:V(r.element)}):r instanceof O?O.create(V(r.unwrap())):r instanceof I?I.create(V(r.unwrap())):r instanceof A?A.create(r.items.map(e=>V(e))):r}class v extends y{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=k.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==h.object){const u=this._getOrReturnCtx(e);return c(u,{code:o.invalid_type,expected:h.object,received:u.parsedType}),f}const{status:t,ctx:s}=this._processInputParams(e),{shape:a,keys:d}=this._getCached(),i=[];if(!(this._def.catchall instanceof N&&this._def.unknownKeys==="strip"))for(const u in s.data)d.includes(u)||i.push(u);const n=[];for(const u of d){const m=a[u],g=s.data[u];n.push({key:{status:"valid",value:u},value:m._parse(new C(s,g,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof N){const u=this._def.unknownKeys;if(u==="passthrough")for(const m of i)n.push({key:{status:"valid",value:m},value:{status:"valid",value:s.data[m]}});else if(u==="strict")i.length>0&&(c(s,{code:o.unrecognized_keys,keys:i}),t.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const m of i){const g=s.data[m];n.push({key:{status:"valid",value:m},value:u._parse(new C(s,g,s.path,m)),alwaysSet:m in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const m of n){const g=await m.key,S=await m.value;u.push({key:g,value:S,alwaysSet:m.alwaysSet})}return u}).then(u=>w.mergeObjectSync(t,u)):w.mergeObjectSync(t,n)}get shape(){return this._def.shape()}strict(e){return l.errToObj,new v({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,s)=>{const a=this._def.errorMap?.(t,s).message??s.defaultError;return t.code==="unrecognized_keys"?{message:l.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new v({...this._def,unknownKeys:"strip"})}passthrough(){return new v({...this._def,unknownKeys:"passthrough"})}extend(e){return new v({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new v({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:p.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new v({...this._def,catchall:e})}pick(e){const t={};for(const s of k.objectKeys(e))e[s]&&this.shape[s]&&(t[s]=this.shape[s]);return new v({...this._def,shape:()=>t})}omit(e){const t={};for(const s of k.objectKeys(this.shape))e[s]||(t[s]=this.shape[s]);return new v({...this._def,shape:()=>t})}deepPartial(){return V(this)}partial(e){const t={};for(const s of k.objectKeys(this.shape)){const a=this.shape[s];e&&!e[s]?t[s]=a:t[s]=a.optional()}return new v({...this._def,shape:()=>t})}required(e){const t={};for(const s of k.objectKeys(this.shape))if(e&&!e[s])t[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof O;)a=a._def.innerType;t[s]=a}return new v({...this._def,shape:()=>t})}keyof(){return Te(k.objectKeys(this.shape))}}v.create=(r,e)=>new v({shape:()=>r,unknownKeys:"strip",catchall:N.create(),typeName:p.ZodObject,..._(e)}),v.strictCreate=(r,e)=>new v({shape:()=>r,unknownKeys:"strict",catchall:N.create(),typeName:p.ZodObject,..._(e)}),v.lazycreate=(r,e)=>new v({shape:r,unknownKeys:"strip",catchall:N.create(),typeName:p.ZodObject,..._(e)});class J extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s=this._def.options;function a(d){for(const n of d)if(n.result.status==="valid")return n.result;for(const n of d)if(n.result.status==="dirty")return t.common.issues.push(...n.ctx.common.issues),n.result;const i=d.map(n=>new R(n.ctx.common.issues));return c(t,{code:o.invalid_union,unionErrors:i}),f}if(t.common.async)return Promise.all(s.map(async d=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await d._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(a);{let d;const i=[];for(const u of s){const m={...t,common:{...t.common,issues:[]},parent:null},g=u._parseSync({data:t.data,path:t.path,parent:m});if(g.status==="valid")return g;g.status==="dirty"&&!d&&(d={result:g,ctx:m}),m.common.issues.length&&i.push(m.common.issues)}if(d)return t.common.issues.push(...d.ctx.common.issues),d.result;const n=i.map(u=>new R(u));return c(t,{code:o.invalid_union,unionErrors:n}),f}}get options(){return this._def.options}}J.create=(r,e)=>new J({options:r,typeName:p.ZodUnion,..._(e)});const P=r=>r instanceof X?P(r.schema):r instanceof b?P(r.innerType()):r instanceof Q?[r.value]:r instanceof L?r.options:r instanceof ee?k.objectValues(r.enum):r instanceof te?P(r._def.innerType):r instanceof q?[void 0]:r instanceof H?[null]:r instanceof O?[void 0,...P(r.unwrap())]:r instanceof I?[null,...P(r.unwrap())]:r instanceof fe||r instanceof ae?P(r.unwrap()):r instanceof se?P(r._def.innerType):[];class le extends y{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.object)return c(t,{code:o.invalid_type,expected:h.object,received:t.parsedType}),f;const s=this.discriminator,a=t.data[s],d=this.optionsMap.get(a);return d?t.common.async?d._parseAsync({data:t.data,path:t.path,parent:t}):d._parseSync({data:t.data,path:t.path,parent:t}):(c(t,{code:o.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),f)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,s){const a=new Map;for(const d of t){const i=P(d.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const n of i){if(a.has(n))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(n)}`);a.set(n,d)}}return new le({typeName:p.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:a,..._(s)})}}function me(r,e){const t=j(r),s=j(e);if(r===e)return{valid:!0,data:r};if(t===h.object&&s===h.object){const a=k.objectKeys(e),d=k.objectKeys(r).filter(n=>a.indexOf(n)!==-1),i={...r,...e};for(const n of d){const u=me(r[n],e[n]);if(!u.valid)return{valid:!1};i[n]=u.data}return{valid:!0,data:i}}else if(t===h.array&&s===h.array){if(r.length!==e.length)return{valid:!1};const a=[];for(let d=0;d<r.length;d++){const i=r[d],n=e[d],u=me(i,n);if(!u.valid)return{valid:!1};a.push(u.data)}return{valid:!0,data:a}}else return t===h.date&&s===h.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}class G extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=(d,i)=>{if(ge(d)||ge(i))return f;const n=me(d.value,i.value);return n.valid?((ve(d)||ve(i))&&t.dirty(),{status:t.value,value:n.data}):(c(s,{code:o.invalid_intersection_types}),f)};return s.common.async?Promise.all([this._def.left._parseAsync({data:s.data,path:s.path,parent:s}),this._def.right._parseAsync({data:s.data,path:s.path,parent:s})]).then(([d,i])=>a(d,i)):a(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}}G.create=(r,e,t)=>new G({left:r,right:e,typeName:p.ZodIntersection,..._(t)});class A extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.array)return c(s,{code:o.invalid_type,expected:h.array,received:s.parsedType}),f;if(s.data.length<this._def.items.length)return c(s,{code:o.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),f;!this._def.rest&&s.data.length>this._def.items.length&&(c(s,{code:o.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...s.data].map((d,i)=>{const n=this._def.items[i]||this._def.rest;return n?n._parse(new C(s,d,s.path,i)):null}).filter(d=>!!d);return s.common.async?Promise.all(a).then(d=>w.mergeArray(t,d)):w.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new A({...this._def,rest:e})}}A.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new A({items:r,typeName:p.ZodTuple,rest:null,..._(e)})};class ne extends y{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.object)return c(s,{code:o.invalid_type,expected:h.object,received:s.parsedType}),f;const a=[],d=this._def.keyType,i=this._def.valueType;for(const n in s.data)a.push({key:d._parse(new C(s,n,s.path,n)),value:i._parse(new C(s,s.data[n],s.path,n)),alwaysSet:n in s.data});return s.common.async?w.mergeObjectAsync(t,a):w.mergeObjectSync(t,a)}get element(){return this._def.valueType}static create(e,t,s){return t instanceof y?new ne({keyType:e,valueType:t,typeName:p.ZodRecord,..._(s)}):new ne({keyType:T.create(),valueType:e,typeName:p.ZodRecord,..._(t)})}}class ce extends y{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.map)return c(s,{code:o.invalid_type,expected:h.map,received:s.parsedType}),f;const a=this._def.keyType,d=this._def.valueType,i=[...s.data.entries()].map(([n,u],m)=>({key:a._parse(new C(s,n,s.path,[m,"key"])),value:d._parse(new C(s,u,s.path,[m,"value"]))}));if(s.common.async){const n=new Map;return Promise.resolve().then(async()=>{for(const u of i){const m=await u.key,g=await u.value;if(m.status==="aborted"||g.status==="aborted")return f;(m.status==="dirty"||g.status==="dirty")&&t.dirty(),n.set(m.value,g.value)}return{status:t.value,value:n}})}else{const n=new Map;for(const u of i){const m=u.key,g=u.value;if(m.status==="aborted"||g.status==="aborted")return f;(m.status==="dirty"||g.status==="dirty")&&t.dirty(),n.set(m.value,g.value)}return{status:t.value,value:n}}}}ce.create=(r,e,t)=>new ce({valueType:e,keyType:r,typeName:p.ZodMap,..._(t)});class z extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.set)return c(s,{code:o.invalid_type,expected:h.set,received:s.parsedType}),f;const a=this._def;a.minSize!==null&&s.data.size<a.minSize.value&&(c(s,{code:o.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),a.maxSize!==null&&s.data.size>a.maxSize.value&&(c(s,{code:o.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());const d=this._def.valueType;function i(u){const m=new Set;for(const g of u){if(g.status==="aborted")return f;g.status==="dirty"&&t.dirty(),m.add(g.value)}return{status:t.value,value:m}}const n=[...s.data.values()].map((u,m)=>d._parse(new C(s,u,s.path,m)));return s.common.async?Promise.all(n).then(u=>i(u)):i(n)}min(e,t){return new z({...this._def,minSize:{value:e,message:l.toString(t)}})}max(e,t){return new z({...this._def,maxSize:{value:e,message:l.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}z.create=(r,e)=>new z({valueType:r,minSize:null,maxSize:null,typeName:p.ZodSet,..._(e)});class B extends y{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.function)return c(t,{code:o.invalid_type,expected:h.function,received:t.parsedType}),f;function s(n,u){return ke({data:n,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,ye(),_e].filter(m=>!!m),issueData:{code:o.invalid_arguments,argumentsError:u}})}function a(n,u){return ke({data:n,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,ye(),_e].filter(m=>!!m),issueData:{code:o.invalid_return_type,returnTypeError:u}})}const d={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof K){const n=this;return x(async function(...u){const m=new R([]),g=await n._def.args.parseAsync(u,d).catch(he=>{throw m.addIssue(s(u,he)),m}),S=await Reflect.apply(i,this,g);return await n._def.returns._def.type.parseAsync(S,d).catch(he=>{throw m.addIssue(a(S,he)),m})})}else{const n=this;return x(function(...u){const m=n._def.args.safeParse(u,d);if(!m.success)throw new R([s(u,m.error)]);const g=Reflect.apply(i,this,m.data),S=n._def.returns.safeParse(g,d);if(!S.success)throw new R([a(g,S.error)]);return S.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new B({...this._def,args:A.create(e).rest(M.create())})}returns(e){return new B({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,s){return new B({args:e||A.create([]).rest(M.create()),returns:t||M.create(),typeName:p.ZodFunction,..._(s)})}}class X extends y{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})}}X.create=(r,e)=>new X({getter:r,typeName:p.ZodLazy,..._(e)});class Q extends y{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return c(t,{received:t.data,code:o.invalid_literal,expected:this._def.value}),f}return{status:"valid",value:e.data}}get value(){return this._def.value}}Q.create=(r,e)=>new Q({value:r,typeName:p.ZodLiteral,..._(e)});function Te(r,e){return new L({values:r,typeName:p.ZodEnum,..._(e)})}class L extends y{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),s=this._def.values;return c(t,{expected:k.joinValues(s),received:t.parsedType,code:o.invalid_type}),f}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),s=this._def.values;return c(t,{received:t.data,code:o.invalid_enum_value,options:s}),f}return x(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 L.create(e,{...this._def,...t})}exclude(e,t=this._def){return L.create(this.options.filter(s=>!e.includes(s)),{...this._def,...t})}}L.create=Te;class ee extends y{_parse(e){const t=k.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==h.string&&s.parsedType!==h.number){const a=k.objectValues(t);return c(s,{expected:k.joinValues(a),received:s.parsedType,code:o.invalid_type}),f}if(this._cache||(this._cache=new Set(k.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const a=k.objectValues(t);return c(s,{received:s.data,code:o.invalid_enum_value,options:a}),f}return x(e.data)}get enum(){return this._def.values}}ee.create=(r,e)=>new ee({values:r,typeName:p.ZodNativeEnum,..._(e)});class K extends y{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==h.promise&&t.common.async===!1)return c(t,{code:o.invalid_type,expected:h.promise,received:t.parsedType}),f;const s=t.parsedType===h.promise?t.data:Promise.resolve(t.data);return x(s.then(a=>this._def.type.parseAsync(a,{path:t.path,errorMap:t.common.contextualErrorMap})))}}K.create=(r,e)=>new K({type:r,typeName:p.ZodPromise,..._(e)});class b extends y{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===p.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=this._def.effect||null,d={addIssue:i=>{c(s,i),i.fatal?t.abort():t.dirty()},get path(){return s.path}};if(d.addIssue=d.addIssue.bind(d),a.type==="preprocess"){const i=a.transform(s.data,d);if(s.common.async)return Promise.resolve(i).then(async n=>{if(t.value==="aborted")return f;const u=await this._def.schema._parseAsync({data:n,path:s.path,parent:s});return u.status==="aborted"?f:u.status==="dirty"?W(u.value):t.value==="dirty"?W(u.value):u});{if(t.value==="aborted")return f;const n=this._def.schema._parseSync({data:i,path:s.path,parent:s});return n.status==="aborted"?f:n.status==="dirty"?W(n.value):t.value==="dirty"?W(n.value):n}}if(a.type==="refinement"){const i=n=>{const u=a.refinement(n,d);if(s.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return n};if(s.common.async===!1){const n=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return n.status==="aborted"?f:(n.status==="dirty"&&t.dirty(),i(n.value),{status:t.value,value:n.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(n=>n.status==="aborted"?f:(n.status==="dirty"&&t.dirty(),i(n.value).then(()=>({status:t.value,value:n.value}))))}if(a.type==="transform")if(s.common.async===!1){const i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!D(i))return f;const n=a.transform(i.value,d);if(n instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:n}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>D(i)?Promise.resolve(a.transform(i.value,d)).then(n=>({status:t.value,value:n})):f);k.assertNever(a)}}b.create=(r,e,t)=>new b({schema:r,typeName:p.ZodEffects,effect:e,..._(t)}),b.createWithPreprocess=(r,e,t)=>new b({schema:e,effect:{type:"preprocess",transform:r},typeName:p.ZodEffects,..._(t)});class O extends y{_parse(e){return this._getType(e)===h.undefined?x(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}O.create=(r,e)=>new O({innerType:r,typeName:p.ZodOptional,..._(e)});class I extends y{_parse(e){return this._getType(e)===h.null?x(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}I.create=(r,e)=>new I({innerType:r,typeName:p.ZodNullable,..._(e)});class te extends y{_parse(e){const{ctx:t}=this._processInputParams(e);let s=t.data;return t.parsedType===h.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}te.create=(r,e)=>new te({innerType:r,typeName:p.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class se extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return ie(a)?a.then(d=>({status:"valid",value:d.status==="valid"?d.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}}se.create=(r,e)=>new se({innerType:r,typeName:p.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class ue extends y{_parse(e){if(this._getType(e)!==h.nan){const t=this._getOrReturnCtx(e);return c(t,{code:o.invalid_type,expected:h.nan,received:t.parsedType}),f}return{status:"valid",value:e.data}}}ue.create=r=>new ue({typeName:p.ZodNaN,..._(r)});const Qe=Symbol("zod_brand");class fe extends y{_parse(e){const{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}}class re extends y{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?f:a.status==="dirty"?(t.dirty(),W(a.value)):this._def.out._parseAsync({data:a.value,path:s.path,parent:s})})();{const a=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?f:a.status==="dirty"?(t.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:s.path,parent:s})}}static create(e,t){return new re({in:e,out:t,typeName:p.ZodPipeline})}}class ae extends y{_parse(e){const t=this._def.innerType._parse(e),s=a=>(D(a)&&(a.value=Object.freeze(a.value)),a);return ie(t)?t.then(a=>s(a)):s(t)}unwrap(){return this._def.innerType}}ae.create=(r,e)=>new ae({innerType:r,typeName:p.ZodReadonly,..._(e)});function Ce(r,e){const t=typeof r=="function"?r(e):typeof r=="string"?{message:r}:r;return typeof t=="string"?{message:t}:t}function Oe(r,e={},t){return r?U.create().superRefine((s,a)=>{const d=r(s);if(d instanceof Promise)return d.then(i=>{if(!i){const n=Ce(e,s),u=n.fatal??t??!0;a.addIssue({code:"custom",...n,fatal:u})}});if(!d){const i=Ce(e,s),n=i.fatal??t??!0;a.addIssue({code:"custom",...i,fatal:n})}}):U.create()}const et={object:v.lazycreate};var p;(function(r){r.ZodString="ZodString",r.ZodNumber="ZodNumber",r.ZodNaN="ZodNaN",r.ZodBigInt="ZodBigInt",r.ZodBoolean="ZodBoolean",r.ZodDate="ZodDate",r.ZodSymbol="ZodSymbol",r.ZodUndefined="ZodUndefined",r.ZodNull="ZodNull",r.ZodAny="ZodAny",r.ZodUnknown="ZodUnknown",r.ZodNever="ZodNever",r.ZodVoid="ZodVoid",r.ZodArray="ZodArray",r.ZodObject="ZodObject",r.ZodUnion="ZodUnion",r.ZodDiscriminatedUnion="ZodDiscriminatedUnion",r.ZodIntersection="ZodIntersection",r.ZodTuple="ZodTuple",r.ZodRecord="ZodRecord",r.ZodMap="ZodMap",r.ZodSet="ZodSet",r.ZodFunction="ZodFunction",r.ZodLazy="ZodLazy",r.ZodLiteral="ZodLiteral",r.ZodEnum="ZodEnum",r.ZodEffects="ZodEffects",r.ZodNativeEnum="ZodNativeEnum",r.ZodOptional="ZodOptional",r.ZodNullable="ZodNullable",r.ZodDefault="ZodDefault",r.ZodCatch="ZodCatch",r.ZodPromise="ZodPromise",r.ZodBranded="ZodBranded",r.ZodPipeline="ZodPipeline",r.ZodReadonly="ZodReadonly"})(p||(p={}));class Ut{constructor(...e){}}const tt=(r,e={message:`Input not instance of ${r.name}`})=>Oe(t=>t instanceof r,e),Ae=T.create,Ne=E.create,st=ue.create,at=F.create,Se=Y.create,rt=$.create,nt=de.create,it=q.create,dt=H.create,ot=U.create,ct=M.create,ut=N.create,lt=oe.create,ht=Z.create,pt=v.create,mt=v.strictCreate,ft=J.create,_t=le.create,yt=G.create,gt=A.create,vt=ne.create,kt=ce.create,xt=z.create,wt=B.create,bt=X.create,Zt=Q.create,Tt=L.create,Ct=ee.create,Ot=K.create,Re=b.create,At=O.create,Nt=I.create,St=b.createWithPreprocess,Rt=re.create,jt=()=>Ae().optional(),Pt=()=>Ne().optional(),It=()=>Se().optional(),Et={string:(r=>T.create({...r,coerce:!0})),number:(r=>E.create({...r,coerce:!0})),boolean:(r=>Y.create({...r,coerce:!0})),bigint:(r=>F.create({...r,coerce:!0})),date:(r=>$.create({...r,coerce:!0}))},Ft=f;export{Qe as BRAND,Ft as NEVER,y as Schema,U as ZodAny,Z as ZodArray,F as ZodBigInt,Y as ZodBoolean,fe as ZodBranded,se as ZodCatch,$ as ZodDate,te as ZodDefault,le as ZodDiscriminatedUnion,b as ZodEffects,L as ZodEnum,p as ZodFirstPartyTypeKind,B as ZodFunction,G as ZodIntersection,X as ZodLazy,Q as ZodLiteral,ce as ZodMap,ue as ZodNaN,ee as ZodNativeEnum,N as ZodNever,H as ZodNull,I as ZodNullable,E as ZodNumber,v as ZodObject,O as ZodOptional,re as ZodPipeline,K as ZodPromise,ae as ZodReadonly,ne as ZodRecord,y as ZodSchema,z as ZodSet,T as ZodString,de as ZodSymbol,b as ZodTransformer,A as ZodTuple,y as ZodType,q as ZodUndefined,J as ZodUnion,M as ZodUnknown,oe as ZodVoid,ot as any,ht as array,at as bigint,Se as boolean,Et as coerce,Oe as custom,rt as date,Ze as datetimeRegex,_t as discriminatedUnion,Re as effect,Tt as enum,wt as function,tt as instanceof,yt as intersection,et as late,bt as lazy,Zt as literal,kt as map,st as nan,Ct as nativeEnum,ut as never,dt as null,Nt as nullable,Ne as number,pt as object,It as oboolean,Pt as onumber,At as optional,jt as ostring,Rt as pipeline,St as preprocess,Ot as promise,vt as record,xt as set,mt as strictObject,Ae as string,nt as symbol,Re as transformer,gt as tuple,it as undefined,ft as union,ct as unknown,lt as void};
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty,c=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,d=Object.prototype.hasOwnProperty,m=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!d.call(t,r)&&r!==n&&a(t,r,{get:()=>e[r],enumerable:!(s=c(e,r))||s.enumerable});return t},g=t=>b(a({},"__esModule",{value:!0}),t),f={};m(f,{expressPoster:()=>O,expressVideoExport:()=>v}),module.exports=g(f);function u(t){return Array.isArray(t.files)?t.files:t.files&&typeof t.files=="object"?Object.values(t.files).flat():[]}function y(t,e){const n=[];for(let s=0;;s++){const r=t.find(o=>o.fieldname===`${e}_${s}`);if(!r)break;n.push({type:r.mimetype,bytes:r.buffer})}return n}function i(t,e){if(e.ok){t.setHeader("Content-Type",e.contentType),t.setHeader("Content-Disposition",`attachment; filename="${e.filename}"`),t.setHeader("Cache-Control","no-store"),t.send(e.bytes);return}t.status(e.status).json({error:e.error,message:e.message})}function v(t){return async(e,n)=>{const s=u(e),r=s.find(l=>l.fieldname==="overlay");if(r&&r.mimetype!=="image/png"){i(n,{ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});return}const o={videos:y(s,"video"),audios:y(s,"audio"),overlay:r?.buffer,editStateRaw:typeof e.body?.editState=="string"?e.body.editState:""};i(n,await t.handle(o))}}function O(t){return async(e,n)=>{const s=u(e).find(o=>o.fieldname==="file"),r=e.body?.time;if(!s||typeof r!="string"){i(n,{ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"});return}i(n,await t.handle({type:s.mimetype,bytes:s.buffer},Number(r)))}}
1
+ "use strict";var a=Object.defineProperty,c=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,d=Object.prototype.hasOwnProperty,m=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!d.call(t,r)&&r!==o&&a(t,r,{get:()=>e[r],enumerable:!(s=c(e,r))||s.enumerable});return t},g=t=>b(a({},"__esModule",{value:!0}),t),f={};m(f,{expressPoster:()=>O,expressVideoExport:()=>v}),module.exports=g(f);function u(t){return Array.isArray(t.files)?t.files:t.files&&typeof t.files=="object"?Object.values(t.files).flat():[]}function y(t,e){const o=[];for(let s=0;;s++){const r=t.find(n=>n.fieldname===`${e}_${s}`);if(!r)break;o.push({type:r.mimetype,bytes:r.buffer})}return o}function i(t,e){if(e.ok){t.setHeader("Content-Type",e.contentType),t.setHeader("Content-Disposition",`attachment; filename="${e.filename}"`),t.setHeader("Cache-Control","no-store"),t.send(e.bytes);return}t.status(e.status).json({error:e.error,message:e.message})}function v(t){return async(e,o)=>{const s=u(e),r=s.find(l=>l.fieldname==="overlay");if(r&&r.mimetype!=="image/png"){i(o,{ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});return}const n={videos:y(s,"video"),audios:y(s,"audio"),overlay:r?.buffer,editStateRaw:typeof e.body?.editState=="string"?e.body.editState:""};i(o,await t.handle(n))}}function O(t){return async(e,o)=>{const s=u(e).find(n=>n.fieldname==="file"),r=e.body?.time;if(!s||typeof r!="string"){i(o,{ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"});return}i(o,await t.handle({type:s.mimetype,bytes:s.buffer},Number(r)))}}
@@ -1 +1 @@
1
- function m(e){return Array.isArray(e.files)?e.files:e.files&&typeof e.files=="object"?Object.values(e.files).flat():[]}function f(e,t){const s=[];for(let r=0;;r++){const i=e.find(o=>o.fieldname===`${t}_${r}`);if(!i)break;s.push({type:i.mimetype,bytes:i.buffer})}return s}function a(e,t){if(t.ok){e.setHeader("Content-Type",t.contentType),e.setHeader("Content-Disposition",`attachment; filename="${t.filename}"`),e.setHeader("Cache-Control","no-store"),e.send(t.bytes);return}e.status(t.status).json({error:t.error,message:t.message})}function d(e){return async(t,s)=>{const r=m(t),i=r.find(n=>n.fieldname==="overlay"),o=r.find(n=>n.fieldname==="videoCover"),u=f(r,"textOverlay");if(i&&i.mimetype!=="image/png"){a(s,{ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});return}if(u.some(n=>n.type!=="image/png")){a(s,{ok:!1,status:415,error:"BAD_OVERLAY",message:"textOverlay \u5FC5\u987B\u662F PNG"});return}if(o&&!/^image\/(?:png|jpe?g)$/.test(o.mimetype)){a(s,{ok:!1,status:415,error:"BAD_COVER",message:"videoCover must be PNG or JPG"});return}const y={videos:f(r,"video"),audios:f(r,"audio"),overlay:i?.buffer,videoCover:o?.buffer,textOverlays:u.map(n=>n.bytes),editStateRaw:typeof t.body?.editState=="string"?t.body.editState:""};a(s,await e.handle(y))}}function l(e){return async(t,s)=>{const r=m(t).find(o=>o.fieldname==="file"),i=t.body?.time;if(!r||typeof i!="string"){a(s,{ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"});return}a(s,await e.handle({type:r.mimetype,bytes:r.buffer},Number(i)))}}export{l as expressPoster,d as expressVideoExport};
1
+ function m(e){return Array.isArray(e.files)?e.files:e.files&&typeof e.files=="object"?Object.values(e.files).flat():[]}function f(e,t){const s=[];for(let r=0;;r++){const i=e.find(o=>o.fieldname===`${t}_${r}`);if(!i)break;s.push({type:i.mimetype,bytes:i.buffer})}return s}function n(e,t){if(t.ok){e.setHeader("Content-Type",t.contentType),e.setHeader("Content-Disposition",`attachment; filename="${t.filename}"`),e.setHeader("Cache-Control","no-store"),e.send(t.bytes);return}e.status(t.status).json({error:t.error,message:t.message})}function d(e){return async(t,s)=>{const r=m(t),i=r.find(a=>a.fieldname==="overlay"),o=r.find(a=>a.fieldname==="videoCover"),u=f(r,"textOverlay");if(i&&i.mimetype!=="image/png"){n(s,{ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});return}if(u.some(a=>a.type!=="image/png")){n(s,{ok:!1,status:415,error:"BAD_OVERLAY",message:"textOverlay \u5FC5\u987B\u662F PNG"});return}if(o&&!/^image\/(?:png|jpe?g)$/.test(o.mimetype)){n(s,{ok:!1,status:415,error:"BAD_COVER",message:"videoCover must be PNG or JPG"});return}const y={videos:f(r,"video"),audios:f(r,"audio"),overlay:i?.buffer,videoCover:o?.buffer,textOverlays:u.map(a=>a.bytes),editStateRaw:typeof t.body?.editState=="string"?t.body.editState:""};n(s,await e.handle(y))}}function l(e){return async(t,s)=>{const r=m(t).find(o=>o.fieldname==="file"),i=t.body?.time;if(!r||typeof i!="string"){n(s,{ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"});return}n(s,await e.handle({type:r.mimetype,bytes:r.buffer},Number(i)))}}export{l as expressPoster,d as expressVideoExport};
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty,w=Object.getOwnPropertyDescriptor,B=Object.getOwnPropertyNames,h=Object.prototype.hasOwnProperty,v=(t,r)=>{for(var e in r)c(t,e,{get:r[e],enumerable:!0})},D=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of B(r))!h.call(t,a)&&a!==e&&c(t,a,{get:()=>r[a],enumerable:!(o=w(r,a))||o.enumerable});return t},C=t=>D(c({},"__esModule",{value:!0}),t),g={};v(g,{toWebPosterHandler:()=>O,toWebVideoHandler:()=>E}),module.exports=C(g);var m=16;function f(t){return typeof t=="object"&&t!==null&&typeof t.type=="string"&&typeof t.arrayBuffer=="function"}async function y(t){return{type:t.type,bytes:Buffer.from(await t.arrayBuffer())}}function s(t){return t.ok?new Response(new Uint8Array(t.bytes),{status:200,headers:{"Content-Type":t.contentType,"Content-Disposition":`attachment; filename="${t.filename}"`,"Cache-Control":"no-store"}}):new Response(JSON.stringify({error:t.error,message:t.message}),{status:t.status,headers:{"Content-Type":"application/json"}})}function E(t){return async r=>{let e;try{e=await r.formData()}catch{return s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u8BF7\u6C42\u4F53\u89E3\u6790\u5931\u8D25"})}const o=[];for(let n=0;n<m;n++){const u=e.get(`video_${n}`);if(!f(u))break;o.push(await y(u))}const a=[];for(let n=0;n<m;n++){const u=e.get(`audio_${n}`);if(!f(u))break;a.push(await y(u))}const p=e.get("editState"),l=e.get("overlay"),i=f(l)?l:void 0,d=i?Buffer.from(await i.arrayBuffer()):void 0;if(i&&i.type!=="image/png")return s({ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});const b={videos:o,audios:a,overlay:d,editStateRaw:typeof p=="string"?p:""};return s(await t.handle(b))}}function O(t){return async r=>{let e;try{e=await r.formData()}catch{return s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u8BF7\u6C42\u4F53\u89E3\u6790\u5931\u8D25"})}const o=e.get("file"),a=e.get("time");return!f(o)||typeof a!="string"?s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"}):s(await t.handle(await y(o),Number(a)))}}
1
+ "use strict";var c=Object.defineProperty,w=Object.getOwnPropertyDescriptor,B=Object.getOwnPropertyNames,h=Object.prototype.hasOwnProperty,v=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},D=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of B(r))!h.call(e,a)&&a!==t&&c(e,a,{get:()=>r[a],enumerable:!(o=w(r,a))||o.enumerable});return e},C=e=>D(c({},"__esModule",{value:!0}),e),g={};v(g,{toWebPosterHandler:()=>O,toWebVideoHandler:()=>E}),module.exports=C(g);var m=16;function f(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"&&typeof e.arrayBuffer=="function"}async function y(e){return{type:e.type,bytes:Buffer.from(await e.arrayBuffer())}}function s(e){return e.ok?new Response(new Uint8Array(e.bytes),{status:200,headers:{"Content-Type":e.contentType,"Content-Disposition":`attachment; filename="${e.filename}"`,"Cache-Control":"no-store"}}):new Response(JSON.stringify({error:e.error,message:e.message}),{status:e.status,headers:{"Content-Type":"application/json"}})}function E(e){return async r=>{let t;try{t=await r.formData()}catch{return s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u8BF7\u6C42\u4F53\u89E3\u6790\u5931\u8D25"})}const o=[];for(let n=0;n<m;n++){const u=t.get(`video_${n}`);if(!f(u))break;o.push(await y(u))}const a=[];for(let n=0;n<m;n++){const u=t.get(`audio_${n}`);if(!f(u))break;a.push(await y(u))}const p=t.get("editState"),l=t.get("overlay"),i=f(l)?l:void 0,d=i?Buffer.from(await i.arrayBuffer()):void 0;if(i&&i.type!=="image/png")return s({ok:!1,status:415,error:"BAD_OVERLAY",message:"overlay \u5FC5\u987B\u662F PNG"});const b={videos:o,audios:a,overlay:d,editStateRaw:typeof p=="string"?p:""};return s(await e.handle(b))}}function O(e){return async r=>{let t;try{t=await r.formData()}catch{return s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u8BF7\u6C42\u4F53\u89E3\u6790\u5931\u8D25"})}const o=t.get("file"),a=t.get("time");return!f(o)||typeof a!="string"?s({ok:!1,status:400,error:"BAD_REQUEST",message:"\u7F3A\u5C11 file \u6216 time"}):s(await e.handle(await y(o),Number(a)))}}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var z=Object.create;var V=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var W=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of U(t))!Q.call(e,r)&&r!==u&&V(e,r,{get:()=>t[r],enumerable:!(n=K(t,r))||n.enumerable});return e};var X=(e,t,u)=>(u=e!=null?z(J(e)):{},W(t||!e||!e.__esModule?V(u,"default",{value:e,enumerable:!0}):u,e));var Z=Object.create,M=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyNames,ue=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,oe=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of te(t))!re.call(e,r)&&r!==u&&M(e,r,{get:()=>t[r],enumerable:!(n=ee(t,r))||n.enumerable});return e},ke=(e,t,u)=>(u=e!=null?Z(ue(e)):{},oe(t||!e||!e.__esModule?M(u,"default",{value:e,enumerable:!0}):u,e)),ne=Object.create,R=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyNames,se=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty,le=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ae(t))!ce.call(e,r)&&r!==u&&R(e,r,{get:()=>t[r],enumerable:!(n=ie(t,r))||n.enumerable});return e},Ne=(e,t,u)=>(u=e!=null?ne(se(e)):{},le(t||!e||!e.__esModule?R(u,"default",{value:e,enumerable:!0}):u,e)),pe=Object.create,I=Object.defineProperty,me=Object.getOwnPropertyDescriptor,fe=Object.getOwnPropertyNames,de=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty,ye=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fe(t))!ge.call(e,r)&&r!==u&&I(e,r,{get:()=>t[r],enumerable:!(n=me(t,r))||n.enumerable});return e},qe=(e,t,u)=>(u=e!=null?pe(de(e)):{},ye(t||!e||!e.__esModule?I(u,"default",{value:e,enumerable:!0}):u,e)),Fe=Object.create,D=Object.defineProperty,we=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyNames,Ae=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ee=(e,t)=>{for(var u in t)D(e,u,{get:t[u],enumerable:!0})},L=(e,t,u,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ve(t))!he.call(e,r)&&r!==u&&D(e,r,{get:()=>t[r],enumerable:!(n=we(t,r))||n.enumerable});return e},be=(e,t,u)=>(u=e!=null?Fe(Ae(e)):{},L(t||!e||!e.__esModule?D(u,"default",{value:e,enumerable:!0}):u,e)),Ce=e=>L(D({},"__esModule",{value:!0}),e),k={};Ee(k,{DEFAULT_LIMITS:()=>Y,composeVideo:()=>Pe,createPosterHandler:()=>Ie,createVideoExportHandler:()=>Re,extractAudio:()=>xe,probeHasAudio:()=>P,probeVideoDuration:()=>q,runVideoEdit:()=>$}),module.exports=Ce(k);var Oe=require("../core/dist/index.cjs"),N=require("../core/dist/index.cjs"),T=be(require("ffmpeg-static"),1),_=require("child_process"),d=require("fs/promises"),Be=require("fs"),De=require("os"),m=require("path"),_e={};async function je(){const e=[];T.default&&typeof T.default=="string"&&e.push(T.default);try{const{createRequire:t}=await import("module"),u=t(_e.url).resolve("ffmpeg-static/package.json"),n=u.substring(0,u.lastIndexOf("/"));e.push((0,m.join)(n,"ffmpeg"))}catch{}e.push((0,m.join)(process.cwd(),"node_modules","ffmpeg-static","ffmpeg"),(0,m.join)(process.cwd(),"node_modules",".pnpm","ffmpeg-static@5.3.0","node_modules","ffmpeg-static","ffmpeg"));for(const t of e)if(t&&!t.startsWith("/ROOT/"))try{return await(0,d.access)(t,Be.constants.X_OK),t}catch{}return null}var j;async function x(){return j!==void 0||(j=await je(),j||console.warn("[ffmpeg-runner] ffmpeg-static \u4E8C\u8FDB\u5236\u672A\u627E\u5230 (\u5C1D\u8BD5\u4E86\u591A\u4E2A fallback \u8DEF\u5F84)")),j}async function B({args:e,timeoutMs:t=18e4}){const u=await x();if(!u)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931 \u2014 \u8BF7\u68C0\u67E5 node_modules/ffmpeg-static/ffmpeg \u662F\u5426\u5B58\u5728");return console.log("[ffmpeg-runner] args:",JSON.stringify(e)),new Promise((n,r)=>{const i=(0,_.spawn)(u,e,{stdio:["ignore","pipe","pipe"]});let a="",p=!1;const s=setTimeout(()=>{p=!0,i.kill("SIGKILL"),r(new Error(`ffmpeg \u8D85\u65F6 (${t}ms)`))},t);i.stderr.on("data",o=>{a+=o.toString(),a.length>8192&&(a=a.slice(-8192))}),i.on("close",o=>{if(clearTimeout(s),p)return;const f=a.slice(-2500);console.log(`[ffmpeg-runner] exit=${o}, stderr tail:
2
- ${f}
3
- ---end---`),o===0?n():r(new Error(`ffmpeg \u9000\u51FA\u7801 ${o}: ${f.slice(-800)}`))}),i.on("error",o=>{clearTimeout(s),r(o)})})}async function O(e){const t=await(0,d.mkdtemp)((0,m.join)((0,De.tmpdir)(),"vtrans-"));try{return await e(t)}finally{(0,d.rm)(t,{recursive:!0,force:!0}).catch(()=>{})}}async function P(e){const t=await x();return t?O(async u=>{const n=(0,m.join)(u,"probe.mp4");return await(0,d.writeFile)(n,e),new Promise(r=>{const i=(0,_.spawn)(t,["-hide_banner","-i",n],{stdio:["ignore","ignore","pipe"]});let a="";const p=setTimeout(()=>{i.kill("SIGKILL"),r(!1)},15e3);i.stderr.on("data",s=>{a+=s.toString(),a.length>16384&&(a=a.slice(-16384))}),i.on("close",()=>{clearTimeout(p),r(/Stream #[^\n]*Audio:/.test(a))}),i.on("error",()=>{clearTimeout(p),r(!1)})})}):!1}async function xe(e){return O(async t=>{const u=(0,m.join)(t,"in.mp4"),n=(0,m.join)(t,"audio.mp3");return await(0,d.writeFile)(u,e),await B({args:["-y","-i",u,"-vn","-acodec","libmp3lame","-ar","16000","-ac","1","-b:a","64k",n],timeoutMs:6e4}),(0,d.readFile)(n)})}var Te=["Fontsize=14","PrimaryColour=&H00FFFFFF","OutlineColour=&H00000000","BackColour=&H80000000","BorderStyle=1","Outline=2","Shadow=0","Alignment=2","MarginV=80","Bold=1"].join(",");async function Pe(e){const t=(await q(e.videoBytes)).durationSeconds;return O(async u=>{const n=(0,m.join)(u,"in.mp4"),r=(0,m.join)(u,"out.mp4");await(0,d.writeFile)(n,e.videoBytes);const i=["-i",n];let a=-1,p=-1;if(e.newAudioBytes){const g=(0,m.join)(u,"new.mp3");await(0,d.writeFile)(g,e.newAudioBytes),a=(i.length-0)/2,i.push("-i",g)}if(e.bgmAudioBytes){const g=(0,m.join)(u,"bgm.mp3");await(0,d.writeFile)(g,e.bgmAudioBytes),p=i.length/2,i.push("-i",g)}const s=e.srtContent&&e.srtContent.trim().length>0;let o=null;s&&(o=(0,m.join)(u,"subs.srt"),await(0,d.writeFile)(o,e.srtContent));const f=e.bgmVolume??.18;console.log(`[ffmpeg-runner] composeVideo: video=${e.videoBytes.length}B (${t.toFixed(2)}s), newAudio=${e.newAudioBytes?.length??0}B, bgm=${e.bgmAudioBytes?.length??0}B@${f}, srt=${e.srtContent?.length??0}chars`);const F=Te.replace(/,/g,"\\,"),w=[];let v,h=!1;s&&o?(w.push(`[0:v]subtitles=${o}:force_style=${F}[v]`),v="[v]",h=!0):v="0:v:0";const A=[];a>=0&&A.push({idx:a,isBgm:!1}),p>=0&&A.push({idx:p,isBgm:!0});let c=null;if(A.length===1)c=`${A[0].idx}:a:0`;else if(A.length>=2){const g=[];for(const E of A)E.isBgm?(w.push(`[${E.idx}:a]volume=${f}[bgm]`),g.push("[bgm]")):g.push(`[${E.idx}:a]`);w.push(`${g.join("")}amix=inputs=${g.length}:duration=first:dropout_transition=0[a]`),c="[a]"}const y=["-y",...i];w.length>0&&y.push("-filter_complex",w.join(";")),y.push("-map",v),c&&y.push("-map",c),h?y.push("-c:v","libx264","-preset","fast","-crf","22","-pix_fmt","yuv420p"):y.push("-c:v","copy"),y.push("-c:a","aac","-b:a","128k","-ar","44100","-ac","2","-movflags","+faststart","-t",t.toFixed(3)),y.push(r),await B({args:y,timeoutMs:18e4});const C=c?await x():null;if(C)try{const g=await new Promise(E=>{const b=(0,_.spawn)(C,["-i",r],{stdio:["ignore","pipe","pipe"]});let S="";b.stderr.on("data",H=>S+=H.toString()),b.on("close",()=>E(S))});if(!/Audio:/.test(g))throw console.error(`[ffmpeg-runner] \u4EA7\u7269\u7F3A\u5C11\u97F3\u8F68,ffmpeg \u6D41\u6982\u89C8:
4
- `,g.slice(-2e3)),new Error("\u5408\u6210\u5931\u8D25: \u8F93\u51FA mp4 \u7F3A\u5C11\u97F3\u8F68 (\u68C0\u67E5 filter_complex \u8BED\u6CD5)");console.log("[ffmpeg-runner] composeVideo \u5B8C\u6210,\u5DF2\u542B\u97F3\u89C6\u9891\u53CC\u6D41")}catch(g){if(g instanceof Error&&g.message.includes("\u5408\u6210\u5931\u8D25"))throw g}return(0,d.readFile)(r)})}async function q(e){return O(async t=>{const u=(0,m.join)(t,"in.mp4");await(0,d.writeFile)(u,e);const n=await x();if(!n)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931");return new Promise((r,i)=>{const a=(0,_.spawn)(n,["-i",u],{stdio:["ignore","pipe","pipe"]});let p="";a.stderr.on("data",s=>p+=s.toString()),a.on("close",()=>{const s=p.match(/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/);if(!s)return i(new Error("\u65E0\u6CD5\u89E3\u6790\u89C6\u9891\u65F6\u957F"));const o=parseInt(s[1]),f=parseInt(s[2]),F=parseFloat(s[3]);r({durationSeconds:o*3600+f*60+F})}),a.on("error",i)})})}async function $(e,t,u="mp4",n=[],r=24e4){return O(async i=>{const a=(0,m.join)(i,"input.mp4"),p=(0,m.join)(i,`output.${u}`);await(0,d.writeFile)(a,e);const s={};for(const o of n){const f=o.name.replace(/[^a-zA-Z0-9._-]/g,"_"),F=(0,m.join)(i,f);await(0,d.writeFile)(F,o.bytes),s[o.name]=F}return await B({args:t(a,p,s),timeoutMs:r}),(0,d.readFile)(p)})}function $e(e){const t=String(e??"").toLowerCase();return t==="mp4"||t==="mov"}function Se(e,t,u){return["-y","-loop","1","-t","0.04","-i",t,"-i",e,"-filter_complex","[0:v][1:v]scale2ref=w=main_w:h=main_h[vcover][vmainref];[vcover]setsar=1,fps=30,format=yuv420p[vcoverf];[vmainref]setpts=PTS-STARTPTS,fps=30,format=yuv420p[vmain];[vcoverf][vmain]concat=n=2:v=1:a=0[v]","-map","[v]","-map","1:a?","-c:v","libx264","-preset","fast","-crf","18","-pix_fmt","yuv420p","-c:a","copy","-movflags","+faststart",u]}async function Ve(e,t,u="mp4",n=[],r,i=24e4){return O(async a=>{const p=(0,m.join)(a,"input.mp4"),s=(0,m.join)(a,`output.${u}`),o=(0,m.join)(a,"video-cover.png"),f=(0,m.join)(a,`output-with-cover.${u}`);await(0,d.writeFile)(p,e);const F={};for(const w of n){const v=w.name.replace(/[^a-zA-Z0-9._-]/g,"_"),h=(0,m.join)(a,v);await(0,d.writeFile)(h,w.bytes),F[w.name]=h}return await B({args:t(p,s,F),timeoutMs:i}),!$e(u)||!r?.length?(0,d.readFile)(s):(await(0,d.writeFile)(o,r),await B({args:Se(s,o,f),timeoutMs:i}),(0,d.readFile)(f))})}var Y={maxVideos:6,maxAudios:3,maxVideoBytes:100*1024*1024,maxTotalVideoBytes:300*1024*1024,maxAudioBytes:30*1024*1024,maxOverlayBytes:20*1024*1024},l=(e,t,u)=>({ok:!1,status:e,error:t,message:u});function G(e){return e.startsWith("video/")?"mp4":e.includes("mpeg")||e.includes("mp3")?"mp3":e.includes("wav")?"wav":e.includes("aac")?"aac":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("flac")?"flac":"bin"}function Me(e){if(!e?.poster?.useAsVideoCover)return;const t=(typeof e.poster.preview=="string"?e.poster.preview:"").match(/^data:image\/(?:png|jpe?g);base64,([a-z0-9+/=]+)$/i);if(t)return Buffer.from(t[1],"base64")}function Re(e){const t={...Y,...e?.limits};return{async handle(u){const{videos:n,audios:r,overlay:i,videoCover:a,editStateRaw:p}=u;if(n.length>t.maxVideos)return l(413,"TOO_MANY",`\u89C6\u9891\u6570\u8D85\u8FC7 ${t.maxVideos}`);for(let o=0;o<n.length;o++){if(!/^video\//.test(n[o].type))return l(415,"BAD_TYPE",`video_${o} \u4E0D\u662F\u89C6\u9891\u6587\u4EF6`);if(n[o].bytes.length>t.maxVideoBytes)return l(413,"TOO_LARGE",`\u89C6\u9891 ${o+1} \u8D85\u8FC7 100MB`)}if(!n.length)return l(400,"BAD_REQUEST","\u7F3A\u5C11\u89C6\u9891\u6587\u4EF6(video_0)");if(n.reduce((o,f)=>o+f.bytes.length,0)>t.maxTotalVideoBytes)return l(413,"TOO_LARGE","\u89C6\u9891\u603B\u5927\u5C0F\u8D85\u8FC7 300MB,\u8BF7\u51CF\u5C11\u7D20\u6750\u6216\u538B\u7F29");if(r.length>t.maxAudios)return l(413,"TOO_MANY",`\u97F3\u9891\u6570\u8D85\u8FC7 ${t.maxAudios}`);for(let o=0;o<r.length;o++){const f=/^audio\//.test(r[o].type),F=/^video\//.test(r[o].type);if(!f&&!F)return l(415,"BAD_TYPE",`audio_${o} \u4E0D\u662F\u97F3\u9891\u6216\u89C6\u9891\u6587\u4EF6`);if(r[o].bytes.length>(F?t.maxVideoBytes:t.maxAudioBytes))return l(413,"TOO_LARGE",`\u97F3\u9891 ${o+1} \u8D85\u8FC7 ${F?"100MB":"30MB"}`)}if(typeof p!="string")return l(400,"BAD_REQUEST","\u7F3A\u5C11 editState");if(i&&i.length>t.maxOverlayBytes)return l(413,"OVERLAY_TOO_LARGE","overlay \u8FC7\u5927");if(a&&a.length>t.maxOverlayBytes)return l(413,"COVER_TOO_LARGE","videoCover \u8FC7\u5927");let s;try{s=Oe.VideoEditState.parse(JSON.parse(p))}catch{return l(400,"BAD_STATE","\u7F16\u8F91\u53C2\u6570\u4E0D\u5408\u6CD5")}if(s.clips.some(o=>o.srcIdx>=n.length))return l(400,"BAD_STATE","clips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u89C6\u9891\u6570");if((s.audioClips??[]).some(o=>o.srcIdx>=r.length))return l(400,"BAD_STATE","audioClips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u97F3\u9891\u6570");try{const o=n.map(c=>c.bytes),f=r.map(c=>c.bytes),F=[...new Set((s.audioClips??[]).map(c=>c.srcIdx))];for(const c of F)if(/^video\//.test(r[c].type)&&!await P(f[c]))return l(400,"BAD_TYPE",`\u97F3\u9891 ${c+1} \u662F\u89C6\u9891\u6587\u4EF6\u4F46\u6CA1\u6709\u97F3\u8F68,\u65E0\u6CD5\u63D0\u53D6\u58F0\u97F3`);const w=n.map(()=>!1);if(s.keepAudio){const c=[...new Set(s.clips.map(y=>y.srcIdx))];await Promise.all(c.map(async y=>{w[y]=await P(o[y])})),!w.some(Boolean)&&!(s.audioClips??[]).length&&(s={...s,keepAudio:!1})}const v=[];for(let c=1;c<o.length;c++)v.push({name:`video_${c}.mp4`,bytes:o[c]});f.forEach((c,y)=>v.push({name:`audio_${y}.${G(r[y].type)}`,bytes:c})),i&&v.push({name:"overlay.png",bytes:i});const h=a?.length?a:Me(s),A=(c,y,C)=>{const g={videoPaths:[c,...o.slice(1).map((E,b)=>C[`video_${b+1}.mp4`])],videoHasAudio:w,audioPaths:f.map((E,b)=>C[`audio_${b}.${G(r[b].type)}`]),overlayPath:i?C["overlay.png"]:void 0};return(0,N.buildFfmpegArgs)(s,g,y)};return{ok:!0,bytes:h==null?await $(o[0],A,"mp4",v,28e4):await Ve(o[0],A,"mp4",v,h,28e4),contentType:"video/mp4",filename:"edited.mp4"}}catch(o){return(o.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"ENCODE_FAILED","\u89C6\u9891\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u66F4\u77ED\u7684\u89C6\u9891")}}}}function Ie(e){const t=e?.maxBytes??104857600;return{async handle(u,n){if(!/^video\//.test(u.type))return l(415,"BAD_TYPE","\u53EA\u652F\u6301\u89C6\u9891\u6587\u4EF6");if(u.bytes.length>t)return l(413,"TOO_LARGE","\u6587\u4EF6\u8D85\u8FC7 100MB");if(!isFinite(n)||n<0)return l(400,"BAD_TIME","time \u53C2\u6570\u4E0D\u5408\u6CD5");try{return{ok:!0,bytes:await $(u.bytes,(r,i)=>(0,N.buildPosterArgs)(r,n,i),"jpg"),contentType:"image/jpeg",filename:"poster.jpg"}}catch(r){return(r.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"EXTRACT_FAILED","\u5C01\u9762\u62BD\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5")}}}}
1
+ "use strict";var K=Object.create;var M=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var X=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of J(t))!W.call(e,r)&&r!==u&&M(e,r,{get:()=>t[r],enumerable:!(o=U(t,r))||o.enumerable});return e};var Z=(e,t,u)=>(u=e!=null?K(Q(e)):{},X(t||!e||!e.__esModule?M(u,"default",{value:e,enumerable:!0}):u,e));var ee=Object.create,V=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ue=Object.getOwnPropertyNames,re=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,ne=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ue(t))!oe.call(e,r)&&r!==u&&V(e,r,{get:()=>t[r],enumerable:!(o=te(t,r))||o.enumerable});return e},Ke=(e,t,u)=>(u=e!=null?ee(re(e)):{},ne(t||!e||!e.__esModule?V(u,"default",{value:e,enumerable:!0}):u,e)),ie=Object.create,R=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,se=Object.getOwnPropertyNames,ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty,pe=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of se(t))!le.call(e,r)&&r!==u&&R(e,r,{get:()=>t[r],enumerable:!(o=ae(t,r))||o.enumerable});return e},Ue=(e,t,u)=>(u=e!=null?ie(ce(e)):{},pe(t||!e||!e.__esModule?R(u,"default",{value:e,enumerable:!0}):u,e)),fe=Object.create,I=Object.defineProperty,me=Object.getOwnPropertyDescriptor,de=Object.getOwnPropertyNames,ge=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty,ye=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of de(t))!Fe.call(e,r)&&r!==u&&I(e,r,{get:()=>t[r],enumerable:!(o=me(t,r))||o.enumerable});return e},Je=(e,t,u)=>(u=e!=null?fe(ge(e)):{},ye(t||!e||!e.__esModule?I(u,"default",{value:e,enumerable:!0}):u,e)),we=Object.create,L=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,be=Object.getOwnPropertyNames,Ae=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ee=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of be(t))!he.call(e,r)&&r!==u&&L(e,r,{get:()=>t[r],enumerable:!(o=ve(t,r))||o.enumerable});return e},Qe=(e,t,u)=>(u=e!=null?we(Ae(e)):{},Ee(t||!e||!e.__esModule?L(u,"default",{value:e,enumerable:!0}):u,e)),Oe=Object.create,D=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyNames,De=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty,je=(e,t)=>{for(var u in t)D(e,u,{get:t[u],enumerable:!0})},k=(e,t,u,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Be(t))!_e.call(e,r)&&r!==u&&D(e,r,{get:()=>t[r],enumerable:!(o=Ce(t,r))||o.enumerable});return e},xe=(e,t,u)=>(u=e!=null?Oe(De(e)):{},k(t||!e||!e.__esModule?D(u,"default",{value:e,enumerable:!0}):u,e)),Pe=e=>k(D({},"__esModule",{value:!0}),e),N={};je(N,{DEFAULT_LIMITS:()=>G,composeVideo:()=>Le,createPosterHandler:()=>He,createVideoExportHandler:()=>Ge,extractAudio:()=>Re,probeHasAudio:()=>T,probeVideoDuration:()=>Y,runVideoEdit:()=>$}),module.exports=Pe(N);var Te=require("../core/dist/index.cjs"),q=require("../core/dist/index.cjs"),P=xe(require("ffmpeg-static"),1),_=require("child_process"),d=require("fs/promises"),$e=require("fs"),Se=require("os"),f=require("path"),Me={};async function Ve(){const e=[];P.default&&typeof P.default=="string"&&e.push(P.default);try{const{createRequire:t}=await import("module"),u=t(Me.url).resolve("ffmpeg-static/package.json"),o=u.substring(0,u.lastIndexOf("/"));e.push((0,f.join)(o,"ffmpeg"))}catch{}e.push((0,f.join)(process.cwd(),"node_modules","ffmpeg-static","ffmpeg"),(0,f.join)(process.cwd(),"node_modules",".pnpm","ffmpeg-static@5.3.0","node_modules","ffmpeg-static","ffmpeg"));for(const t of e)if(t&&!t.startsWith("/ROOT/"))try{return await(0,d.access)(t,$e.constants.X_OK),t}catch{}return null}var j;async function x(){return j!==void 0||(j=await Ve(),j||console.warn("[ffmpeg-runner] ffmpeg-static \u4E8C\u8FDB\u5236\u672A\u627E\u5230 (\u5C1D\u8BD5\u4E86\u591A\u4E2A fallback \u8DEF\u5F84)")),j}async function B({args:e,timeoutMs:t=18e4}){const u=await x();if(!u)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931 \u2014 \u8BF7\u68C0\u67E5 node_modules/ffmpeg-static/ffmpeg \u662F\u5426\u5B58\u5728");return console.log("[ffmpeg-runner] args:",JSON.stringify(e)),new Promise((o,r)=>{const i=(0,_.spawn)(u,e,{stdio:["ignore","pipe","pipe"]});let a="",p=!1;const s=setTimeout(()=>{p=!0,i.kill("SIGKILL"),r(new Error(`ffmpeg \u8D85\u65F6 (${t}ms)`))},t);i.stderr.on("data",n=>{a+=n.toString(),a.length>8192&&(a=a.slice(-8192))}),i.on("close",n=>{if(clearTimeout(s),p)return;const m=a.slice(-2500);console.log(`[ffmpeg-runner] exit=${n}, stderr tail:
2
+ ${m}
3
+ ---end---`),n===0?o():r(new Error(`ffmpeg \u9000\u51FA\u7801 ${n}: ${m.slice(-800)}`))}),i.on("error",n=>{clearTimeout(s),r(n)})})}async function C(e){const t=await(0,d.mkdtemp)((0,f.join)((0,Se.tmpdir)(),"vtrans-"));try{return await e(t)}finally{(0,d.rm)(t,{recursive:!0,force:!0}).catch(()=>{})}}async function T(e){const t=await x();return t?C(async u=>{const o=(0,f.join)(u,"probe.mp4");return await(0,d.writeFile)(o,e),new Promise(r=>{const i=(0,_.spawn)(t,["-hide_banner","-i",o],{stdio:["ignore","ignore","pipe"]});let a="";const p=setTimeout(()=>{i.kill("SIGKILL"),r(!1)},15e3);i.stderr.on("data",s=>{a+=s.toString(),a.length>16384&&(a=a.slice(-16384))}),i.on("close",()=>{clearTimeout(p),r(/Stream #[^\n]*Audio:/.test(a))}),i.on("error",()=>{clearTimeout(p),r(!1)})})}):!1}async function Re(e){return C(async t=>{const u=(0,f.join)(t,"in.mp4"),o=(0,f.join)(t,"audio.mp3");return await(0,d.writeFile)(u,e),await B({args:["-y","-i",u,"-vn","-acodec","libmp3lame","-ar","16000","-ac","1","-b:a","64k",o],timeoutMs:6e4}),(0,d.readFile)(o)})}var Ie=["Fontsize=14","PrimaryColour=&H00FFFFFF","OutlineColour=&H00000000","BackColour=&H80000000","BorderStyle=1","Outline=2","Shadow=0","Alignment=2","MarginV=80","Bold=1"].join(",");async function Le(e){const t=(await Y(e.videoBytes)).durationSeconds;return C(async u=>{const o=(0,f.join)(u,"in.mp4"),r=(0,f.join)(u,"out.mp4");await(0,d.writeFile)(o,e.videoBytes);const i=["-i",o];let a=-1,p=-1;if(e.newAudioBytes){const g=(0,f.join)(u,"new.mp3");await(0,d.writeFile)(g,e.newAudioBytes),a=(i.length-0)/2,i.push("-i",g)}if(e.bgmAudioBytes){const g=(0,f.join)(u,"bgm.mp3");await(0,d.writeFile)(g,e.bgmAudioBytes),p=i.length/2,i.push("-i",g)}const s=e.srtContent&&e.srtContent.trim().length>0;let n=null;s&&(n=(0,f.join)(u,"subs.srt"),await(0,d.writeFile)(n,e.srtContent));const m=e.bgmVolume??.18;console.log(`[ffmpeg-runner] composeVideo: video=${e.videoBytes.length}B (${t.toFixed(2)}s), newAudio=${e.newAudioBytes?.length??0}B, bgm=${e.bgmAudioBytes?.length??0}B@${m}, srt=${e.srtContent?.length??0}chars`);const y=Ie.replace(/,/g,"\\,"),w=[];let v,A=!1;s&&n?(w.push(`[0:v]subtitles=${n}:force_style=${y}[v]`),v="[v]",A=!0):v="0:v:0";const b=[];a>=0&&b.push({idx:a,isBgm:!1}),p>=0&&b.push({idx:p,isBgm:!0});let c=null;if(b.length===1)c=`${b[0].idx}:a:0`;else if(b.length>=2){const g=[];for(const h of b)h.isBgm?(w.push(`[${h.idx}:a]volume=${m}[bgm]`),g.push("[bgm]")):g.push(`[${h.idx}:a]`);w.push(`${g.join("")}amix=inputs=${g.length}:duration=first:dropout_transition=0[a]`),c="[a]"}const F=["-y",...i];w.length>0&&F.push("-filter_complex",w.join(";")),F.push("-map",v),c&&F.push("-map",c),A?F.push("-c:v","libx264","-preset","fast","-crf","22","-pix_fmt","yuv420p"):F.push("-c:v","copy"),F.push("-c:a","aac","-b:a","128k","-ar","44100","-ac","2","-movflags","+faststart","-t",t.toFixed(3)),F.push(r),await B({args:F,timeoutMs:18e4});const O=c?await x():null;if(O)try{const g=await new Promise(h=>{const E=(0,_.spawn)(O,["-i",r],{stdio:["ignore","pipe","pipe"]});let S="";E.stderr.on("data",z=>S+=z.toString()),E.on("close",()=>h(S))});if(!/Audio:/.test(g))throw console.error(`[ffmpeg-runner] \u4EA7\u7269\u7F3A\u5C11\u97F3\u8F68,ffmpeg \u6D41\u6982\u89C8:
4
+ `,g.slice(-2e3)),new Error("\u5408\u6210\u5931\u8D25: \u8F93\u51FA mp4 \u7F3A\u5C11\u97F3\u8F68 (\u68C0\u67E5 filter_complex \u8BED\u6CD5)");console.log("[ffmpeg-runner] composeVideo \u5B8C\u6210,\u5DF2\u542B\u97F3\u89C6\u9891\u53CC\u6D41")}catch(g){if(g instanceof Error&&g.message.includes("\u5408\u6210\u5931\u8D25"))throw g}return(0,d.readFile)(r)})}async function Y(e){return C(async t=>{const u=(0,f.join)(t,"in.mp4");await(0,d.writeFile)(u,e);const o=await x();if(!o)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931");return new Promise((r,i)=>{const a=(0,_.spawn)(o,["-i",u],{stdio:["ignore","pipe","pipe"]});let p="";a.stderr.on("data",s=>p+=s.toString()),a.on("close",()=>{const s=p.match(/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/);if(!s)return i(new Error("\u65E0\u6CD5\u89E3\u6790\u89C6\u9891\u65F6\u957F"));const n=parseInt(s[1]),m=parseInt(s[2]),y=parseFloat(s[3]);r({durationSeconds:n*3600+m*60+y})}),a.on("error",i)})})}async function $(e,t,u="mp4",o=[],r=24e4){return C(async i=>{const a=(0,f.join)(i,"input.mp4"),p=(0,f.join)(i,`output.${u}`);await(0,d.writeFile)(a,e);const s={};for(const n of o){const m=n.name.replace(/[^a-zA-Z0-9._-]/g,"_"),y=(0,f.join)(i,m);await(0,d.writeFile)(y,n.bytes),s[n.name]=y}return await B({args:t(a,p,s),timeoutMs:r}),(0,d.readFile)(p)})}function ke(e){const t=String(e??"").toLowerCase();return t==="mp4"||t==="mov"}function Ne(e,t,u){return["-y","-loop","1","-t","0.04","-i",t,"-i",e,"-filter_complex","[0:v][1:v]scale2ref=w=main_w:h=main_h[vcover][vmainref];[vcover]setsar=1,fps=30,format=yuv420p[vcoverf];[vmainref]setpts=PTS-STARTPTS,fps=30,format=yuv420p[vmain];[vcoverf][vmain]concat=n=2:v=1:a=0[v]","-map","[v]","-map","1:a?","-c:v","libx264","-preset","fast","-crf","18","-pix_fmt","yuv420p","-c:a","copy","-movflags","+faststart",u]}async function qe(e,t,u="mp4",o=[],r,i=24e4){return C(async a=>{const p=(0,f.join)(a,"input.mp4"),s=(0,f.join)(a,`output.${u}`),n=(0,f.join)(a,"video-cover.png"),m=(0,f.join)(a,`output-with-cover.${u}`);await(0,d.writeFile)(p,e);const y={};for(const w of o){const v=w.name.replace(/[^a-zA-Z0-9._-]/g,"_"),A=(0,f.join)(a,v);await(0,d.writeFile)(A,w.bytes),y[w.name]=A}return await B({args:t(p,s,y),timeoutMs:i}),!ke(u)||!r?.length?(0,d.readFile)(s):(await(0,d.writeFile)(n,r),await B({args:Ne(s,n,m),timeoutMs:i}),(0,d.readFile)(m))})}var G={maxVideos:6,maxAudios:3,maxVideoBytes:100*1024*1024,maxTotalVideoBytes:300*1024*1024,maxAudioBytes:30*1024*1024,maxOverlayBytes:20*1024*1024},l=(e,t,u)=>({ok:!1,status:e,error:t,message:u});function H(e){return e.startsWith("video/")?"mp4":e.includes("mpeg")||e.includes("mp3")?"mp3":e.includes("wav")?"wav":e.includes("aac")?"aac":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("flac")?"flac":"bin"}function Ye(e){if(!e?.poster?.useAsVideoCover)return;const t=(typeof e.poster.preview=="string"?e.poster.preview:"").match(/^data:image\/(?:png|jpe?g);base64,([a-z0-9+/=]+)$/i);if(t)return Buffer.from(t[1],"base64")}function Ge(e){const t={...G,...e?.limits};return{async handle(u){const{videos:o,audios:r,overlay:i,videoCover:a,editStateRaw:p}=u;if(o.length>t.maxVideos)return l(413,"TOO_MANY",`\u89C6\u9891\u6570\u8D85\u8FC7 ${t.maxVideos}`);for(let n=0;n<o.length;n++){if(!/^video\//.test(o[n].type))return l(415,"BAD_TYPE",`video_${n} \u4E0D\u662F\u89C6\u9891\u6587\u4EF6`);if(o[n].bytes.length>t.maxVideoBytes)return l(413,"TOO_LARGE",`\u89C6\u9891 ${n+1} \u8D85\u8FC7 100MB`)}if(!o.length)return l(400,"BAD_REQUEST","\u7F3A\u5C11\u89C6\u9891\u6587\u4EF6(video_0)");if(o.reduce((n,m)=>n+m.bytes.length,0)>t.maxTotalVideoBytes)return l(413,"TOO_LARGE","\u89C6\u9891\u603B\u5927\u5C0F\u8D85\u8FC7 300MB,\u8BF7\u51CF\u5C11\u7D20\u6750\u6216\u538B\u7F29");if(r.length>t.maxAudios)return l(413,"TOO_MANY",`\u97F3\u9891\u6570\u8D85\u8FC7 ${t.maxAudios}`);for(let n=0;n<r.length;n++){const m=/^audio\//.test(r[n].type),y=/^video\//.test(r[n].type);if(!m&&!y)return l(415,"BAD_TYPE",`audio_${n} \u4E0D\u662F\u97F3\u9891\u6216\u89C6\u9891\u6587\u4EF6`);if(r[n].bytes.length>(y?t.maxVideoBytes:t.maxAudioBytes))return l(413,"TOO_LARGE",`\u97F3\u9891 ${n+1} \u8D85\u8FC7 ${y?"100MB":"30MB"}`)}if(typeof p!="string")return l(400,"BAD_REQUEST","\u7F3A\u5C11 editState");if(i&&i.length>t.maxOverlayBytes)return l(413,"OVERLAY_TOO_LARGE","overlay \u8FC7\u5927");if(a&&a.length>t.maxOverlayBytes)return l(413,"COVER_TOO_LARGE","videoCover \u8FC7\u5927");let s;try{s=Te.VideoEditState.parse(JSON.parse(p))}catch{return l(400,"BAD_STATE","\u7F16\u8F91\u53C2\u6570\u4E0D\u5408\u6CD5")}if(s.clips.some(n=>n.srcIdx>=o.length))return l(400,"BAD_STATE","clips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u89C6\u9891\u6570");if((s.audioClips??[]).some(n=>n.srcIdx>=r.length))return l(400,"BAD_STATE","audioClips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u97F3\u9891\u6570");try{const n=o.map(c=>c.bytes),m=r.map(c=>c.bytes),y=[...new Set((s.audioClips??[]).map(c=>c.srcIdx))];for(const c of y)if(/^video\//.test(r[c].type)&&!await T(m[c]))return l(400,"BAD_TYPE",`\u97F3\u9891 ${c+1} \u662F\u89C6\u9891\u6587\u4EF6\u4F46\u6CA1\u6709\u97F3\u8F68,\u65E0\u6CD5\u63D0\u53D6\u58F0\u97F3`);const w=o.map(()=>!1);if(s.keepAudio){const c=[...new Set(s.clips.map(F=>F.srcIdx))];await Promise.all(c.map(async F=>{w[F]=await T(n[F])})),!w.some(Boolean)&&!(s.audioClips??[]).length&&(s={...s,keepAudio:!1})}const v=[];for(let c=1;c<n.length;c++)v.push({name:`video_${c}.mp4`,bytes:n[c]});m.forEach((c,F)=>v.push({name:`audio_${F}.${H(r[F].type)}`,bytes:c})),i&&v.push({name:"overlay.png",bytes:i});const A=a?.length?a:Ye(s),b=(c,F,O)=>{const g={videoPaths:[c,...n.slice(1).map((h,E)=>O[`video_${E+1}.mp4`])],videoHasAudio:w,audioPaths:m.map((h,E)=>O[`audio_${E}.${H(r[E].type)}`]),overlayPath:i?O["overlay.png"]:void 0};return(0,q.buildFfmpegArgs)(s,g,F)};return{ok:!0,bytes:A==null?await $(n[0],b,"mp4",v,28e4):await qe(n[0],b,"mp4",v,A,28e4),contentType:"video/mp4",filename:"edited.mp4"}}catch(n){return(n.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"ENCODE_FAILED","\u89C6\u9891\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u66F4\u77ED\u7684\u89C6\u9891")}}}}function He(e){const t=e?.maxBytes??104857600;return{async handle(u,o){if(!/^video\//.test(u.type))return l(415,"BAD_TYPE","\u53EA\u652F\u6301\u89C6\u9891\u6587\u4EF6");if(u.bytes.length>t)return l(413,"TOO_LARGE","\u6587\u4EF6\u8D85\u8FC7 100MB");if(!isFinite(o)||o<0)return l(400,"BAD_TIME","time \u53C2\u6570\u4E0D\u5408\u6CD5");try{return{ok:!0,bytes:await $(u.bytes,(r,i)=>(0,q.buildPosterArgs)(r,o,i),"jpg"),contentType:"image/jpeg",filename:"poster.jpg"}}catch(r){return(r.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"EXTRACT_FAILED","\u5C01\u9762\u62BD\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5")}}}}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{VideoEditState as k}from"../core/dist/index.js";import{buildFfmpegArgs as Y,buildPosterArgs as j}from"../core/dist/index.js";import R from"ffmpeg-static";import{spawn as b}from"child_process";import{writeFile as v,readFile as x,mkdtemp as G,rm as H,access as N}from"fs/promises";import{constants as z}from"fs";import{tmpdir as K}from"os";import{join as d}from"path";async function U(){const t=[];R&&typeof R=="string"&&t.push(R);try{const{createRequire:e}=await import("module"),o=e(import.meta.url).resolve("ffmpeg-static/package.json"),r=o.substring(0,o.lastIndexOf("/"));t.push(d(r,"ffmpeg"))}catch{}t.push(d(process.cwd(),"node_modules","ffmpeg-static","ffmpeg"),d(process.cwd(),"node_modules",".pnpm","ffmpeg-static@5.3.0","node_modules","ffmpeg-static","ffmpeg"));for(const e of t)if(e&&!e.startsWith("/ROOT/"))try{return await N(e,z.X_OK),e}catch{}return null}var $;async function S(){return $!==void 0||($=await U(),$||console.warn("[ffmpeg-runner] ffmpeg-static \u4E8C\u8FDB\u5236\u672A\u627E\u5230 (\u5C1D\u8BD5\u4E86\u591A\u4E2A fallback \u8DEF\u5F84)")),$}async function T({args:t,timeoutMs:e=18e4}){const o=await S();if(!o)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931 \u2014 \u8BF7\u68C0\u67E5 node_modules/ffmpeg-static/ffmpeg \u662F\u5426\u5B58\u5728");return console.log("[ffmpeg-runner] args:",JSON.stringify(t)),new Promise((r,s)=>{const a=b(o,t,{stdio:["ignore","pipe","pipe"]});let i="",f=!1;const m=setTimeout(()=>{f=!0,a.kill("SIGKILL"),s(new Error(`ffmpeg \u8D85\u65F6 (${e}ms)`))},e);a.stderr.on("data",n=>{i+=n.toString(),i.length>8192&&(i=i.slice(-8192))}),a.on("close",n=>{if(clearTimeout(m),f)return;const u=i.slice(-2500);console.log(`[ffmpeg-runner] exit=${n}, stderr tail:
1
+ import{VideoEditState as k}from"../core/dist/index.js";import{buildFfmpegArgs as Y,buildPosterArgs as j}from"../core/dist/index.js";import R from"ffmpeg-static";import{spawn as b}from"child_process";import{writeFile as A,readFile as x,mkdtemp as G,rm as H,access as N}from"fs/promises";import{constants as z}from"fs";import{tmpdir as K}from"os";import{join as d}from"path";async function U(){const e=[];R&&typeof R=="string"&&e.push(R);try{const{createRequire:t}=await import("module"),o=t(import.meta.url).resolve("ffmpeg-static/package.json"),r=o.substring(0,o.lastIndexOf("/"));e.push(d(r,"ffmpeg"))}catch{}e.push(d(process.cwd(),"node_modules","ffmpeg-static","ffmpeg"),d(process.cwd(),"node_modules",".pnpm","ffmpeg-static@5.3.0","node_modules","ffmpeg-static","ffmpeg"));for(const t of e)if(t&&!t.startsWith("/ROOT/"))try{return await N(t,z.X_OK),t}catch{}return null}var $;async function S(){return $!==void 0||($=await U(),$||console.warn("[ffmpeg-runner] ffmpeg-static \u4E8C\u8FDB\u5236\u672A\u627E\u5230 (\u5C1D\u8BD5\u4E86\u591A\u4E2A fallback \u8DEF\u5F84)")),$}async function T({args:e,timeoutMs:t=18e4}){const o=await S();if(!o)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931 \u2014 \u8BF7\u68C0\u67E5 node_modules/ffmpeg-static/ffmpeg \u662F\u5426\u5B58\u5728");return console.log("[ffmpeg-runner] args:",JSON.stringify(e)),new Promise((r,s)=>{const i=b(o,e,{stdio:["ignore","pipe","pipe"]});let a="",f=!1;const p=setTimeout(()=>{f=!0,i.kill("SIGKILL"),s(new Error(`ffmpeg \u8D85\u65F6 (${t}ms)`))},t);i.stderr.on("data",n=>{a+=n.toString(),a.length>8192&&(a=a.slice(-8192))}),i.on("close",n=>{if(clearTimeout(p),f)return;const u=a.slice(-2500);console.log(`[ffmpeg-runner] exit=${n}, stderr tail:
2
2
  ${u}
3
- ---end---`),n===0?r():s(new Error(`ffmpeg \u9000\u51FA\u7801 ${n}: ${u.slice(-800)}`))}),a.on("error",n=>{clearTimeout(m),s(n)})})}async function D(t){const e=await G(d(K(),"vtrans-"));try{return await t(e)}finally{H(e,{recursive:!0,force:!0}).catch(()=>{})}}async function V(t){const e=await S();return e?D(async o=>{const r=d(o,"probe.mp4");return await v(r,t),new Promise(s=>{const a=b(e,["-hide_banner","-i",r],{stdio:["ignore","ignore","pipe"]});let i="";const f=setTimeout(()=>{a.kill("SIGKILL"),s(!1)},15e3);a.stderr.on("data",m=>{i+=m.toString(),i.length>16384&&(i=i.slice(-16384))}),a.on("close",()=>{clearTimeout(f),s(/Stream #[^\n]*Audio:/.test(i))}),a.on("error",()=>{clearTimeout(f),s(!1)})})}):!1}async function q(t){return D(async e=>{const o=d(e,"in.mp4"),r=d(e,"audio.mp3");return await v(o,t),await T({args:["-y","-i",o,"-vn","-acodec","libmp3lame","-ar","16000","-ac","1","-b:a","64k",r],timeoutMs:6e4}),x(r)})}var J=["Fontsize=14","PrimaryColour=&H00FFFFFF","OutlineColour=&H00000000","BackColour=&H80000000","BorderStyle=1","Outline=2","Shadow=0","Alignment=2","MarginV=80","Bold=1"].join(",");async function Q(t){const e=(await I(t.videoBytes)).durationSeconds;return D(async o=>{const r=d(o,"in.mp4"),s=d(o,"out.mp4");await v(r,t.videoBytes);const a=["-i",r];let i=-1,f=-1;if(t.newAudioBytes){const c=d(o,"new.mp3");await v(c,t.newAudioBytes),i=(a.length-0)/2,a.push("-i",c)}if(t.bgmAudioBytes){const c=d(o,"bgm.mp3");await v(c,t.bgmAudioBytes),f=a.length/2,a.push("-i",c)}const m=t.srtContent&&t.srtContent.trim().length>0;let n=null;m&&(n=d(o,"subs.srt"),await v(n,t.srtContent));const u=t.bgmVolume??.18;console.log(`[ffmpeg-runner] composeVideo: video=${t.videoBytes.length}B (${e.toFixed(2)}s), newAudio=${t.newAudioBytes?.length??0}B, bgm=${t.bgmAudioBytes?.length??0}B@${u}, srt=${t.srtContent?.length??0}chars`);const g=J.replace(/,/g,"\\,"),F=[];let C,y=!1;m&&n?(F.push(`[0:v]subtitles=${n}:force_style=${g}[v]`),C="[v]",y=!0):C="0:v:0";const A=[];i>=0&&A.push({idx:i,isBgm:!1}),f>=0&&A.push({idx:f,isBgm:!0});let w=null;if(A.length===1)w=`${A[0].idx}:a:0`;else if(A.length>=2){const c=[];for(const h of A)h.isBgm?(F.push(`[${h.idx}:a]volume=${u}[bgm]`),c.push("[bgm]")):c.push(`[${h.idx}:a]`);F.push(`${c.join("")}amix=inputs=${c.length}:duration=first:dropout_transition=0[a]`),w="[a]"}const E=["-y",...a];F.length>0&&E.push("-filter_complex",F.join(";")),E.push("-map",C),w&&E.push("-map",w),y?E.push("-c:v","libx264","-preset","fast","-crf","22","-pix_fmt","yuv420p"):E.push("-c:v","copy"),E.push("-c:a","aac","-b:a","128k","-ar","44100","-ac","2","-movflags","+faststart","-t",e.toFixed(3)),E.push(s),await T({args:E,timeoutMs:18e4});const p=w?await S():null;if(p)try{const c=await new Promise(h=>{const O=b(p,["-i",s],{stdio:["ignore","pipe","pipe"]});let _="";O.stderr.on("data",B=>_+=B.toString()),O.on("close",()=>h(_))});if(!/Audio:/.test(c))throw console.error(`[ffmpeg-runner] \u4EA7\u7269\u7F3A\u5C11\u97F3\u8F68,ffmpeg \u6D41\u6982\u89C8:
4
- `,c.slice(-2e3)),new Error("\u5408\u6210\u5931\u8D25: \u8F93\u51FA mp4 \u7F3A\u5C11\u97F3\u8F68 (\u68C0\u67E5 filter_complex \u8BED\u6CD5)");console.log("[ffmpeg-runner] composeVideo \u5B8C\u6210,\u5DF2\u542B\u97F3\u89C6\u9891\u53CC\u6D41")}catch(c){if(c instanceof Error&&c.message.includes("\u5408\u6210\u5931\u8D25"))throw c}return x(s)})}async function I(t){return D(async e=>{const o=d(e,"in.mp4");await v(o,t);const r=await S();if(!r)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931");return new Promise((s,a)=>{const i=b(r,["-i",o],{stdio:["ignore","pipe","pipe"]});let f="";i.stderr.on("data",m=>f+=m.toString()),i.on("close",()=>{const m=f.match(/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/);if(!m)return a(new Error("\u65E0\u6CD5\u89E3\u6790\u89C6\u9891\u65F6\u957F"));const n=parseInt(m[1]),u=parseInt(m[2]),g=parseFloat(m[3]);s({durationSeconds:n*3600+u*60+g})}),i.on("error",a)})})}async function L(t,e,o="mp4",r=[],s=24e4){return D(async a=>{const i=d(a,"input.mp4"),f=d(a,`output.${o}`);await v(i,t);const m={};for(const n of r){const u=n.name.replace(/[^a-zA-Z0-9._-]/g,"_"),g=d(a,u);await v(g,n.bytes),m[n.name]=g}return await T({args:e(i,f,m),timeoutMs:s}),x(f)})}function W(t){const e=String(t??"").toLowerCase();return e==="mp4"||e==="mov"}function X(t,e,o){return["-y","-loop","1","-t","0.04","-i",e,"-i",t,"-filter_complex","[0:v][1:v]scale2ref=w=main_w:h=main_h[vcover][vmainref];[vcover]setsar=1,fps=30,format=yuv420p[vcoverf];[vmainref]setpts=PTS-STARTPTS,fps=30,format=yuv420p[vmain];[vcoverf][vmain]concat=n=2:v=1:a=0[v]","-map","[v]","-map","1:a?","-c:v","libx264","-preset","fast","-crf","18","-pix_fmt","yuv420p","-c:a","copy","-movflags","+faststart",o]}async function Z(t,e,o="mp4",r=[],s,a=24e4){return D(async i=>{const f=d(i,"input.mp4"),m=d(i,`output.${o}`),n=d(i,"video-cover.png"),u=d(i,`output-with-cover.${o}`);await v(f,t);const g={};for(const F of r){const C=F.name.replace(/[^a-zA-Z0-9._-]/g,"_"),y=d(i,C);await v(y,F.bytes),g[F.name]=y}return await T({args:e(f,m,g),timeoutMs:a}),!W(o)||!s?.length?x(m):(await v(n,s),await T({args:X(m,n,u),timeoutMs:a}),x(u))})}var P={maxVideos:6,maxAudios:3,maxVideoBytes:100*1024*1024,maxTotalVideoBytes:300*1024*1024,maxAudioBytes:30*1024*1024,maxOverlayBytes:20*1024*1024},l=(t,e,o)=>({ok:!1,status:t,error:e,message:o});function M(t){return t.startsWith("video/")?"mp4":t.includes("mpeg")||t.includes("mp3")?"mp3":t.includes("wav")?"wav":t.includes("aac")?"aac":t.includes("ogg")?"ogg":t.includes("mp4")||t.includes("m4a")?"m4a":t.includes("flac")?"flac":"bin"}function tt(t){const e=String(t??"mp4").toLowerCase();return e==="mov"||e==="mxf"?e:"mp4"}function et(t){return t==="mov"?"video/quicktime":t==="mxf"?"application/mxf":"video/mp4"}function ut(t){if(!t?.poster?.useAsVideoCover)return;const e=(typeof t.poster.preview=="string"?t.poster.preview:"").match(/^data:image\/(?:png|jpe?g);base64,([a-z0-9+/=]+)$/i);if(e)return Buffer.from(e[1],"base64")}function ot(t){const e={...P,...t?.limits};return{async handle(o){const{videos:r,audios:s,overlay:a,videoCover:i,textOverlays:f=[],editStateRaw:m}=o;if(r.length>e.maxVideos)return l(413,"TOO_MANY",`\u89C6\u9891\u6570\u8D85\u8FC7 ${e.maxVideos}`);for(let u=0;u<r.length;u++){if(!/^video\//.test(r[u].type))return l(415,"BAD_TYPE",`video_${u} \u4E0D\u662F\u89C6\u9891\u6587\u4EF6`);if(r[u].bytes.length>e.maxVideoBytes)return l(413,"TOO_LARGE",`\u89C6\u9891 ${u+1} \u8D85\u8FC7 100MB`)}if(!r.length)return l(400,"BAD_REQUEST","\u7F3A\u5C11\u89C6\u9891\u6587\u4EF6(video_0)");if(r.reduce((u,g)=>u+g.bytes.length,0)>e.maxTotalVideoBytes)return l(413,"TOO_LARGE","\u89C6\u9891\u603B\u5927\u5C0F\u8D85\u8FC7 300MB,\u8BF7\u51CF\u5C11\u7D20\u6750\u6216\u538B\u7F29");if(s.length>e.maxAudios)return l(413,"TOO_MANY",`\u97F3\u9891\u6570\u8D85\u8FC7 ${e.maxAudios}`);for(let u=0;u<s.length;u++){const g=/^audio\//.test(s[u].type),F=/^video\//.test(s[u].type);if(!g&&!F)return l(415,"BAD_TYPE",`audio_${u} \u4E0D\u662F\u97F3\u9891\u6216\u89C6\u9891\u6587\u4EF6`);if(s[u].bytes.length>(F?e.maxVideoBytes:e.maxAudioBytes))return l(413,"TOO_LARGE",`\u97F3\u9891 ${u+1} \u8D85\u8FC7 ${F?"100MB":"30MB"}`)}if(typeof m!="string")return l(400,"BAD_REQUEST","\u7F3A\u5C11 editState");if(a&&a.length>e.maxOverlayBytes)return l(413,"OVERLAY_TOO_LARGE","overlay \u8FC7\u5927");if(i&&i.length>e.maxOverlayBytes)return l(413,"COVER_TOO_LARGE","videoCover \u8FC7\u5927");if(f.some(u=>u.length>e.maxOverlayBytes))return l(413,"OVERLAY_TOO_LARGE","textOverlay \u8FC7\u5927");let n;try{n=k.parse(JSON.parse(m))}catch{return l(400,"BAD_STATE","\u7F16\u8F91\u53C2\u6570\u4E0D\u5408\u6CD5")}if(n.clips.some(u=>u.srcIdx>=r.length))return l(400,"BAD_STATE","clips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u89C6\u9891\u6570");if((n.audioClips??[]).some(u=>u.srcIdx>=s.length))return l(400,"BAD_STATE","audioClips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u97F3\u9891\u6570");try{const u=r.map(p=>p.bytes),g=s.map(p=>p.bytes),F=[...new Set((n.audioClips??[]).map(p=>p.srcIdx))];for(const p of F)if(/^video\//.test(s[p].type)&&!await V(g[p]))return l(400,"BAD_TYPE",`\u97F3\u9891 ${p+1} \u662F\u89C6\u9891\u6587\u4EF6\u4F46\u6CA1\u6709\u97F3\u8F68,\u65E0\u6CD5\u63D0\u53D6\u58F0\u97F3`);const C=r.map(()=>!1);if(n.keepAudio){const p=[...new Set(n.clips.map(c=>c.srcIdx))];await Promise.all(p.map(async c=>{C[c]=await V(u[c])})),!C.some(Boolean)&&!(n.audioClips??[]).length&&(n={...n,keepAudio:!1})}const y=[];for(let p=1;p<u.length;p++)y.push({name:`video_${p}.mp4`,bytes:u[p]});g.forEach((p,c)=>y.push({name:`audio_${c}.${M(s[c].type)}`,bytes:p})),a&&y.push({name:"overlay.png",bytes:a}),f.forEach((p,c)=>y.push({name:`textOverlay_${c}.png`,bytes:p}));const A=tt(n.exportSettings?.format),w=i?.length?i:ut(n),E=(p,c,h)=>{const O={videoPaths:[p,...u.slice(1).map((_,B)=>h[`video_${B+1}.mp4`])],videoHasAudio:C,audioPaths:g.map((_,B)=>h[`audio_${B}.${M(s[B].type)}`]),overlayPath:a?h["overlay.png"]:void 0,textOverlayPaths:f.map((_,B)=>h[`textOverlay_${B}.png`]).filter(Boolean)};return Y(n,O,c)};return{ok:!0,bytes:w==null?await L(u[0],E,A,y,28e4):await Z(u[0],E,A,y,w,28e4),contentType:et(A),filename:`edited.${A}`}}catch(u){return(u.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"ENCODE_FAILED","\u89C6\u9891\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u66F4\u77ED\u7684\u89C6\u9891")}}}}function nt(t){const e=t?.maxBytes??104857600;return{async handle(o,r){if(!/^video\//.test(o.type))return l(415,"BAD_TYPE","\u53EA\u652F\u6301\u89C6\u9891\u6587\u4EF6");if(o.bytes.length>e)return l(413,"TOO_LARGE","\u6587\u4EF6\u8D85\u8FC7 100MB");if(!isFinite(r)||r<0)return l(400,"BAD_TIME","time \u53C2\u6570\u4E0D\u5408\u6CD5");try{return{ok:!0,bytes:await L(o.bytes,(s,a)=>j(s,r,a),"jpg"),contentType:"image/jpeg",filename:"poster.jpg"}}catch(s){return(s.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"EXTRACT_FAILED","\u5C01\u9762\u62BD\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5")}}}}export{P as DEFAULT_LIMITS,Q as composeVideo,nt as createPosterHandler,ot as createVideoExportHandler,q as extractAudio,V as probeHasAudio,I as probeVideoDuration,L as runVideoEdit};
3
+ ---end---`),n===0?r():s(new Error(`ffmpeg \u9000\u51FA\u7801 ${n}: ${u.slice(-800)}`))}),i.on("error",n=>{clearTimeout(p),s(n)})})}async function D(e){const t=await G(d(K(),"vtrans-"));try{return await e(t)}finally{H(t,{recursive:!0,force:!0}).catch(()=>{})}}async function V(e){const t=await S();return t?D(async o=>{const r=d(o,"probe.mp4");return await A(r,e),new Promise(s=>{const i=b(t,["-hide_banner","-i",r],{stdio:["ignore","ignore","pipe"]});let a="";const f=setTimeout(()=>{i.kill("SIGKILL"),s(!1)},15e3);i.stderr.on("data",p=>{a+=p.toString(),a.length>16384&&(a=a.slice(-16384))}),i.on("close",()=>{clearTimeout(f),s(/Stream #[^\n]*Audio:/.test(a))}),i.on("error",()=>{clearTimeout(f),s(!1)})})}):!1}async function q(e){return D(async t=>{const o=d(t,"in.mp4"),r=d(t,"audio.mp3");return await A(o,e),await T({args:["-y","-i",o,"-vn","-acodec","libmp3lame","-ar","16000","-ac","1","-b:a","64k",r],timeoutMs:6e4}),x(r)})}var J=["Fontsize=14","PrimaryColour=&H00FFFFFF","OutlineColour=&H00000000","BackColour=&H80000000","BorderStyle=1","Outline=2","Shadow=0","Alignment=2","MarginV=80","Bold=1"].join(",");async function Q(e){const t=(await I(e.videoBytes)).durationSeconds;return D(async o=>{const r=d(o,"in.mp4"),s=d(o,"out.mp4");await A(r,e.videoBytes);const i=["-i",r];let a=-1,f=-1;if(e.newAudioBytes){const c=d(o,"new.mp3");await A(c,e.newAudioBytes),a=(i.length-0)/2,i.push("-i",c)}if(e.bgmAudioBytes){const c=d(o,"bgm.mp3");await A(c,e.bgmAudioBytes),f=i.length/2,i.push("-i",c)}const p=e.srtContent&&e.srtContent.trim().length>0;let n=null;p&&(n=d(o,"subs.srt"),await A(n,e.srtContent));const u=e.bgmVolume??.18;console.log(`[ffmpeg-runner] composeVideo: video=${e.videoBytes.length}B (${t.toFixed(2)}s), newAudio=${e.newAudioBytes?.length??0}B, bgm=${e.bgmAudioBytes?.length??0}B@${u}, srt=${e.srtContent?.length??0}chars`);const g=J.replace(/,/g,"\\,"),F=[];let h,y=!1;p&&n?(F.push(`[0:v]subtitles=${n}:force_style=${g}[v]`),h="[v]",y=!0):h="0:v:0";const v=[];a>=0&&v.push({idx:a,isBgm:!1}),f>=0&&v.push({idx:f,isBgm:!0});let w=null;if(v.length===1)w=`${v[0].idx}:a:0`;else if(v.length>=2){const c=[];for(const C of v)C.isBgm?(F.push(`[${C.idx}:a]volume=${u}[bgm]`),c.push("[bgm]")):c.push(`[${C.idx}:a]`);F.push(`${c.join("")}amix=inputs=${c.length}:duration=first:dropout_transition=0[a]`),w="[a]"}const E=["-y",...i];F.length>0&&E.push("-filter_complex",F.join(";")),E.push("-map",h),w&&E.push("-map",w),y?E.push("-c:v","libx264","-preset","fast","-crf","22","-pix_fmt","yuv420p"):E.push("-c:v","copy"),E.push("-c:a","aac","-b:a","128k","-ar","44100","-ac","2","-movflags","+faststart","-t",t.toFixed(3)),E.push(s),await T({args:E,timeoutMs:18e4});const m=w?await S():null;if(m)try{const c=await new Promise(C=>{const O=b(m,["-i",s],{stdio:["ignore","pipe","pipe"]});let _="";O.stderr.on("data",B=>_+=B.toString()),O.on("close",()=>C(_))});if(!/Audio:/.test(c))throw console.error(`[ffmpeg-runner] \u4EA7\u7269\u7F3A\u5C11\u97F3\u8F68,ffmpeg \u6D41\u6982\u89C8:
4
+ `,c.slice(-2e3)),new Error("\u5408\u6210\u5931\u8D25: \u8F93\u51FA mp4 \u7F3A\u5C11\u97F3\u8F68 (\u68C0\u67E5 filter_complex \u8BED\u6CD5)");console.log("[ffmpeg-runner] composeVideo \u5B8C\u6210,\u5DF2\u542B\u97F3\u89C6\u9891\u53CC\u6D41")}catch(c){if(c instanceof Error&&c.message.includes("\u5408\u6210\u5931\u8D25"))throw c}return x(s)})}async function I(e){return D(async t=>{const o=d(t,"in.mp4");await A(o,e);const r=await S();if(!r)throw new Error("ffmpeg-static \u4E8C\u8FDB\u5236\u7F3A\u5931");return new Promise((s,i)=>{const a=b(r,["-i",o],{stdio:["ignore","pipe","pipe"]});let f="";a.stderr.on("data",p=>f+=p.toString()),a.on("close",()=>{const p=f.match(/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/);if(!p)return i(new Error("\u65E0\u6CD5\u89E3\u6790\u89C6\u9891\u65F6\u957F"));const n=parseInt(p[1]),u=parseInt(p[2]),g=parseFloat(p[3]);s({durationSeconds:n*3600+u*60+g})}),a.on("error",i)})})}async function L(e,t,o="mp4",r=[],s=24e4){return D(async i=>{const a=d(i,"input.mp4"),f=d(i,`output.${o}`);await A(a,e);const p={};for(const n of r){const u=n.name.replace(/[^a-zA-Z0-9._-]/g,"_"),g=d(i,u);await A(g,n.bytes),p[n.name]=g}return await T({args:t(a,f,p),timeoutMs:s}),x(f)})}function W(e){const t=String(e??"").toLowerCase();return t==="mp4"||t==="mov"}function X(e,t,o){return["-y","-loop","1","-t","0.04","-i",t,"-i",e,"-filter_complex","[0:v][1:v]scale2ref=w=main_w:h=main_h[vcover][vmainref];[vcover]setsar=1,fps=30,format=yuv420p[vcoverf];[vmainref]setpts=PTS-STARTPTS,fps=30,format=yuv420p[vmain];[vcoverf][vmain]concat=n=2:v=1:a=0[v]","-map","[v]","-map","1:a?","-c:v","libx264","-preset","fast","-crf","18","-pix_fmt","yuv420p","-c:a","copy","-movflags","+faststart",o]}async function Z(e,t,o="mp4",r=[],s,i=24e4){return D(async a=>{const f=d(a,"input.mp4"),p=d(a,`output.${o}`),n=d(a,"video-cover.png"),u=d(a,`output-with-cover.${o}`);await A(f,e);const g={};for(const F of r){const h=F.name.replace(/[^a-zA-Z0-9._-]/g,"_"),y=d(a,h);await A(y,F.bytes),g[F.name]=y}return await T({args:t(f,p,g),timeoutMs:i}),!W(o)||!s?.length?x(p):(await A(n,s),await T({args:X(p,n,u),timeoutMs:i}),x(u))})}var P={maxVideos:6,maxAudios:3,maxVideoBytes:100*1024*1024,maxTotalVideoBytes:300*1024*1024,maxAudioBytes:30*1024*1024,maxOverlayBytes:20*1024*1024},l=(e,t,o)=>({ok:!1,status:e,error:t,message:o});function M(e){return e.startsWith("video/")?"mp4":e.includes("mpeg")||e.includes("mp3")?"mp3":e.includes("wav")?"wav":e.includes("aac")?"aac":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("flac")?"flac":"bin"}function ee(e){const t=String(e??"mp4").toLowerCase();return t==="mov"||t==="mxf"?t:"mp4"}function te(e){return e==="mov"?"video/quicktime":e==="mxf"?"application/mxf":"video/mp4"}function ue(e){if(!e?.poster?.useAsVideoCover)return;const t=(typeof e.poster.preview=="string"?e.poster.preview:"").match(/^data:image\/(?:png|jpe?g);base64,([a-z0-9+/=]+)$/i);if(t)return Buffer.from(t[1],"base64")}function oe(e){const t={...P,...e?.limits};return{async handle(o){const{videos:r,audios:s,overlay:i,videoCover:a,textOverlays:f=[],editStateRaw:p}=o;if(r.length>t.maxVideos)return l(413,"TOO_MANY",`\u89C6\u9891\u6570\u8D85\u8FC7 ${t.maxVideos}`);for(let u=0;u<r.length;u++){if(!/^video\//.test(r[u].type))return l(415,"BAD_TYPE",`video_${u} \u4E0D\u662F\u89C6\u9891\u6587\u4EF6`);if(r[u].bytes.length>t.maxVideoBytes)return l(413,"TOO_LARGE",`\u89C6\u9891 ${u+1} \u8D85\u8FC7 100MB`)}if(!r.length)return l(400,"BAD_REQUEST","\u7F3A\u5C11\u89C6\u9891\u6587\u4EF6(video_0)");if(r.reduce((u,g)=>u+g.bytes.length,0)>t.maxTotalVideoBytes)return l(413,"TOO_LARGE","\u89C6\u9891\u603B\u5927\u5C0F\u8D85\u8FC7 300MB,\u8BF7\u51CF\u5C11\u7D20\u6750\u6216\u538B\u7F29");if(s.length>t.maxAudios)return l(413,"TOO_MANY",`\u97F3\u9891\u6570\u8D85\u8FC7 ${t.maxAudios}`);for(let u=0;u<s.length;u++){const g=/^audio\//.test(s[u].type),F=/^video\//.test(s[u].type);if(!g&&!F)return l(415,"BAD_TYPE",`audio_${u} \u4E0D\u662F\u97F3\u9891\u6216\u89C6\u9891\u6587\u4EF6`);if(s[u].bytes.length>(F?t.maxVideoBytes:t.maxAudioBytes))return l(413,"TOO_LARGE",`\u97F3\u9891 ${u+1} \u8D85\u8FC7 ${F?"100MB":"30MB"}`)}if(typeof p!="string")return l(400,"BAD_REQUEST","\u7F3A\u5C11 editState");if(i&&i.length>t.maxOverlayBytes)return l(413,"OVERLAY_TOO_LARGE","overlay \u8FC7\u5927");if(a&&a.length>t.maxOverlayBytes)return l(413,"COVER_TOO_LARGE","videoCover \u8FC7\u5927");if(f.some(u=>u.length>t.maxOverlayBytes))return l(413,"OVERLAY_TOO_LARGE","textOverlay \u8FC7\u5927");let n;try{n=k.parse(JSON.parse(p))}catch{return l(400,"BAD_STATE","\u7F16\u8F91\u53C2\u6570\u4E0D\u5408\u6CD5")}if(n.clips.some(u=>u.srcIdx>=r.length))return l(400,"BAD_STATE","clips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u89C6\u9891\u6570");if((n.audioClips??[]).some(u=>u.srcIdx>=s.length))return l(400,"BAD_STATE","audioClips.srcIdx \u8D85\u51FA\u4E0A\u4F20\u97F3\u9891\u6570");try{const u=r.map(m=>m.bytes),g=s.map(m=>m.bytes),F=[...new Set((n.audioClips??[]).map(m=>m.srcIdx))];for(const m of F)if(/^video\//.test(s[m].type)&&!await V(g[m]))return l(400,"BAD_TYPE",`\u97F3\u9891 ${m+1} \u662F\u89C6\u9891\u6587\u4EF6\u4F46\u6CA1\u6709\u97F3\u8F68,\u65E0\u6CD5\u63D0\u53D6\u58F0\u97F3`);const h=r.map(()=>!1);if(n.keepAudio){const m=[...new Set(n.clips.map(c=>c.srcIdx))];await Promise.all(m.map(async c=>{h[c]=await V(u[c])})),!h.some(Boolean)&&!(n.audioClips??[]).length&&(n={...n,keepAudio:!1})}const y=[];for(let m=1;m<u.length;m++)y.push({name:`video_${m}.mp4`,bytes:u[m]});g.forEach((m,c)=>y.push({name:`audio_${c}.${M(s[c].type)}`,bytes:m})),i&&y.push({name:"overlay.png",bytes:i}),f.forEach((m,c)=>y.push({name:`textOverlay_${c}.png`,bytes:m}));const v=ee(n.exportSettings?.format),w=a?.length?a:ue(n),E=(m,c,C)=>{const O={videoPaths:[m,...u.slice(1).map((_,B)=>C[`video_${B+1}.mp4`])],videoHasAudio:h,audioPaths:g.map((_,B)=>C[`audio_${B}.${M(s[B].type)}`]),overlayPath:i?C["overlay.png"]:void 0,textOverlayPaths:f.map((_,B)=>C[`textOverlay_${B}.png`]).filter(Boolean)};return Y(n,O,c)};return{ok:!0,bytes:w==null?await L(u[0],E,v,y,28e4):await Z(u[0],E,v,y,w,28e4),contentType:te(v),filename:`edited.${v}`}}catch(u){return(u.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"ENCODE_FAILED","\u89C6\u9891\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u66F4\u77ED\u7684\u89C6\u9891")}}}}function ne(e){const t=e?.maxBytes??104857600;return{async handle(o,r){if(!/^video\//.test(o.type))return l(415,"BAD_TYPE","\u53EA\u652F\u6301\u89C6\u9891\u6587\u4EF6");if(o.bytes.length>t)return l(413,"TOO_LARGE","\u6587\u4EF6\u8D85\u8FC7 100MB");if(!isFinite(r)||r<0)return l(400,"BAD_TIME","time \u53C2\u6570\u4E0D\u5408\u6CD5");try{return{ok:!0,bytes:await L(o.bytes,(s,i)=>j(s,r,i),"jpg"),contentType:"image/jpeg",filename:"poster.jpg"}}catch(s){return(s.message??"").includes("\u4E8C\u8FDB\u5236\u7F3A\u5931")?l(503,"SERVER_NOT_READY","\u670D\u52A1\u7AEF\u7F16\u7801\u7EC4\u4EF6\u672A\u5C31\u7EEA\uFF08ffmpeg \u7F3A\u5931\uFF09\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"):l(502,"EXTRACT_FAILED","\u5C01\u9762\u62BD\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5")}}}}export{P as DEFAULT_LIMITS,Q as composeVideo,ne as createPosterHandler,oe as createVideoExportHandler,q as extractAudio,V as probeHasAudio,I as probeVideoDuration,L as runVideoEdit};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bylqwjc/media-editor-server",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "媒体编辑器服务端:框架无关的视频导出/封面处理器 + Web(Next)/Express 适配器(Node + ffmpeg-static)",
5
5
  "type": "module",
6
6
  "license": "MIT",