@usefillo/dom 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.js +14 -7
- package/dist/standalone.global.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,9 +9,10 @@ npm i @usefillo/dom
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
import { defineForm, renderForm } from "@usefillo/dom";
|
|
12
|
+
import { createClient, defineForm, renderForm } from "@usefillo/dom";
|
|
13
13
|
import "@usefillo/dom/styles.css"; // optional default theme — or bring your own
|
|
14
14
|
|
|
15
|
+
const client = createClient({ key: "pk_…" }); // collects responses in Fillo
|
|
15
16
|
const form = defineForm({
|
|
16
17
|
id: "cust-feedback",
|
|
17
18
|
pages: [{ id: "p1", blocks: [
|
|
@@ -22,7 +23,8 @@ const form = defineForm({
|
|
|
22
23
|
|
|
23
24
|
renderForm(document.querySelector("#fillo-form"), {
|
|
24
25
|
form,
|
|
25
|
-
|
|
26
|
+
client,
|
|
27
|
+
onSubmitted: (id) => console.log("response", id),
|
|
26
28
|
});
|
|
27
29
|
```
|
|
28
30
|
|
package/dist/index.js
CHANGED
|
@@ -530,6 +530,8 @@ var DomFormController = class {
|
|
|
530
530
|
closed = false;
|
|
531
531
|
// null = not yet resolved from the server; absent branding means "show".
|
|
532
532
|
fetchedPoweredBy = null;
|
|
533
|
+
fetchedBrandLabel;
|
|
534
|
+
fetchedBrandHref;
|
|
533
535
|
// The renderer owns its lifecycle phase; all field state, validation,
|
|
534
536
|
// conditional logic, paging, spam signals, funnel tracking, and submission
|
|
535
537
|
// live in the shared core engine.
|
|
@@ -586,6 +588,8 @@ var DomFormController = class {
|
|
|
586
588
|
this.engine?.setContext({ formId });
|
|
587
589
|
if (branding) {
|
|
588
590
|
this.fetchedPoweredBy = branding.poweredBy;
|
|
591
|
+
this.fetchedBrandLabel = branding.label;
|
|
592
|
+
this.fetchedBrandHref = branding.href;
|
|
589
593
|
this.render();
|
|
590
594
|
}
|
|
591
595
|
}).catch((error) => this.handleError(toFilloError(error)));
|
|
@@ -605,6 +609,8 @@ var DomFormController = class {
|
|
|
605
609
|
const published = await this.options.client.getForm(this.options.formId);
|
|
606
610
|
this.closed = Boolean(published.closed);
|
|
607
611
|
this.fetchedPoweredBy = published.branding?.poweredBy ?? null;
|
|
612
|
+
this.fetchedBrandLabel = published.branding?.label;
|
|
613
|
+
this.fetchedBrandHref = published.branding?.href;
|
|
608
614
|
this.setSchema(published.schema, this.options.theme ?? published.theme ?? void 0, published.id);
|
|
609
615
|
} catch (error) {
|
|
610
616
|
this.handleError(toFilloError(error));
|
|
@@ -740,7 +746,7 @@ var DomFormController = class {
|
|
|
740
746
|
const success = this.options.renderSuccess?.(api) ?? defaultSuccess(this.schema);
|
|
741
747
|
themeStyle(success, this.theme);
|
|
742
748
|
this.element.appendChild(success);
|
|
743
|
-
if (this.brandingVisible()) this.element.appendChild(poweredByEl());
|
|
749
|
+
if (this.brandingVisible()) this.element.appendChild(poweredByEl(this.fetchedBrandLabel, this.fetchedBrandHref));
|
|
744
750
|
return;
|
|
745
751
|
}
|
|
746
752
|
if (!this.options.client && isDevEnv()) this.element.appendChild(devNoClientEl());
|
|
@@ -858,11 +864,13 @@ function defaultSuccess(schema) {
|
|
|
858
864
|
success.appendChild(inner);
|
|
859
865
|
return success;
|
|
860
866
|
}
|
|
861
|
-
function poweredByEl() {
|
|
867
|
+
function poweredByEl(label, href) {
|
|
868
|
+
const base = href ?? "https://fillo.so";
|
|
869
|
+
const url = `${base}${base.includes("?") ? "&" : "?"}utm_source=form_badge`;
|
|
862
870
|
return el("a", {
|
|
863
871
|
className: "fillo-powered",
|
|
864
|
-
text: "Powered by Fillo",
|
|
865
|
-
attrs: { href:
|
|
872
|
+
text: label ?? "Powered by Fillo",
|
|
873
|
+
attrs: { href: url, target: "_blank", rel: "noopener" }
|
|
866
874
|
});
|
|
867
875
|
}
|
|
868
876
|
function isDevEnv() {
|
|
@@ -896,7 +904,7 @@ var FilloFormElement = class extends HTMLElement {
|
|
|
896
904
|
assignedTheme;
|
|
897
905
|
assignedInitialData;
|
|
898
906
|
static get observedAttributes() {
|
|
899
|
-
return ["
|
|
907
|
+
return ["publishable-key", "form-id"];
|
|
900
908
|
}
|
|
901
909
|
connectedCallback() {
|
|
902
910
|
this.mount();
|
|
@@ -929,10 +937,9 @@ var FilloFormElement = class extends HTMLElement {
|
|
|
929
937
|
}
|
|
930
938
|
mount() {
|
|
931
939
|
this.instance?.destroy();
|
|
932
|
-
const baseUrl = this.getAttribute("base-url");
|
|
933
940
|
const key = this.getAttribute("publishable-key") ?? void 0;
|
|
934
941
|
const formId = this.getAttribute("form-id") ?? void 0;
|
|
935
|
-
const client = this.assignedClient ?? (formId || key
|
|
942
|
+
const client = this.assignedClient ?? (formId || key ? createClient({ key }) : void 0);
|
|
936
943
|
this.instance = renderForm(this, {
|
|
937
944
|
form: this.assignedForm,
|
|
938
945
|
client,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Fillo=(()=>{var ze=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ut=Object.prototype.hasOwnProperty;var ct=(t,e)=>{for(var r in e)ze(t,r,{get:e[r],enumerable:!0})},zt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Dt(e))!Ut.call(t,n)&&n!==r&&ze(t,n,{get:()=>e[n],enumerable:!(s=Vt(e,n))||s.enumerable});return t};var Zt=t=>zt(ze({},"__esModule",{value:!0}),t);var Vs={};ct(Vs,{FilloClient:()=>Me,FilloError:()=>S,createClient:()=>Oe,createFormElement:()=>Rt,defineForm:()=>et,registerFilloElement:()=>at,renderForm:()=>Ue});var w={};ct(w,{BRAND:()=>mr,DIRTY:()=>te,EMPTY_PATH:()=>Wt,INVALID:()=>y,NEVER:()=>Gr,OK:()=>A,ParseStatus:()=>F,Schema:()=>_,ZodAny:()=>G,ZodArray:()=>Y,ZodBigInt:()=>se,ZodBoolean:()=>ne,ZodBranded:()=>Ee,ZodCatch:()=>me,ZodDate:()=>ie,ZodDefault:()=>pe,ZodDiscriminatedUnion:()=>$e,ZodEffects:()=>M,ZodEnum:()=>fe,ZodError:()=>R,ZodFirstPartyTypeKind:()=>v,ZodFunction:()=>je,ZodIntersection:()=>de,ZodIssueCode:()=>u,ZodLazy:()=>ce,ZodLiteral:()=>ue,ZodMap:()=>we,ZodNaN:()=>Te,ZodNativeEnum:()=>he,ZodNever:()=>U,ZodNull:()=>oe,ZodNullable:()=>H,ZodNumber:()=>re,ZodObject:()=>I,ZodOptional:()=>j,ZodParsedType:()=>p,ZodPipeline:()=>Fe,ZodPromise:()=>ee,ZodReadonly:()=>ge,ZodRecord:()=>Le,ZodSchema:()=>_,ZodSet:()=>Ce,ZodString:()=>X,ZodSymbol:()=>xe,ZodTransformer:()=>M,ZodTuple:()=>B,ZodType:()=>_,ZodUndefined:()=>ae,ZodUnion:()=>le,ZodUnknown:()=>K,ZodVoid:()=>ke,addIssueToContext:()=>h,any:()=>Cr,array:()=>Er,bigint:()=>br,boolean:()=>xt,coerce:()=>Xr,custom:()=>vt,date:()=>_r,datetimeRegex:()=>gt,defaultErrorMap:()=>W,discriminatedUnion:()=>Rr,effect:()=>Br,enum:()=>Ur,function:()=>Mr,getErrorMap:()=>ve,getParsedType:()=>Z,instanceof:()=>yr,intersection:()=>Ir,isAborted:()=>Re,isAsync:()=>be,isDirty:()=>Ie,isValid:()=>Q,late:()=>gr,lazy:()=>Vr,literal:()=>Dr,makeIssue:()=>Se,map:()=>jr,nan:()=>vr,nativeEnum:()=>zr,never:()=>Nr,null:()=>wr,nullable:()=>qr,number:()=>_t,object:()=>Fr,objectUtil:()=>Ze,oboolean:()=>Qr,onumber:()=>Yr,optional:()=>Hr,ostring:()=>Kr,pipeline:()=>Jr,preprocess:()=>Wr,promise:()=>Zr,quotelessJson:()=>Bt,record:()=>Lr,set:()=>Pr,setErrorMap:()=>qt,strictObject:()=>Ar,string:()=>bt,symbol:()=>xr,transformer:()=>Br,tuple:()=>$r,undefined:()=>kr,union:()=>Or,unknown:()=>Tr,util:()=>k,void:()=>Sr});var k;(function(t){t.assertEqual=n=>{};function e(n){}t.assertIs=e;function r(n){throw new Error}t.assertNever=r,t.arrayToEnum=n=>{let i={};for(let a of n)i[a]=a;return i},t.getValidEnumValues=n=>{let i=t.objectKeys(n).filter(o=>typeof n[n[o]]!="number"),a={};for(let o of i)a[o]=n[o];return t.objectValues(a)},t.objectValues=n=>t.objectKeys(n).map(function(i){return n[i]}),t.objectKeys=typeof Object.keys=="function"?n=>Object.keys(n):n=>{let i=[];for(let a in n)Object.prototype.hasOwnProperty.call(n,a)&&i.push(a);return i},t.find=(n,i)=>{for(let a of n)if(i(a))return a},t.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function s(n,i=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(i)}t.joinValues=s,t.jsonStringifyReplacer=(n,i)=>typeof i=="bigint"?i.toString():i})(k||(k={}));var Ze;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(Ze||(Ze={}));var p=k.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Z=t=>{switch(typeof t){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(t)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(t)?p.array:t===null?p.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?p.promise:typeof Map<"u"&&t instanceof Map?p.map:typeof Set<"u"&&t instanceof Set?p.set:typeof Date<"u"&&t instanceof Date?p.date:p.object;default:return p.unknown}};var u=k.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Bt=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),R=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=s=>{this.issues=[...this.issues,s]},this.addIssues=(s=[])=>{this.issues=[...this.issues,...s]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(i){return i.message},s={_errors:[]},n=i=>{for(let a of i.issues)if(a.code==="invalid_union")a.unionErrors.map(n);else if(a.code==="invalid_return_type")n(a.returnTypeError);else if(a.code==="invalid_arguments")n(a.argumentsError);else if(a.path.length===0)s._errors.push(r(a));else{let o=s,l=0;for(;l<a.path.length;){let d=a.path[l];l===a.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(r(a))):o[d]=o[d]||{_errors:[]},o=o[d],l++}}};return n(this),s}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,k.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},s=[];for(let n of this.issues)if(n.path.length>0){let i=n.path[0];r[i]=r[i]||[],r[i].push(e(n))}else s.push(e(n));return{formErrors:s,fieldErrors:r}}get formErrors(){return this.flatten()}};R.create=t=>new R(t);var Ht=(t,e)=>{let r;switch(t.code){case u.invalid_type:t.received===p.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case u.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,k.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:r=`Unrecognized key(s) in object: ${k.joinValues(t.keys,", ")}`;break;case u.invalid_union:r="Invalid input";break;case u.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${k.joinValues(t.options)}`;break;case u.invalid_enum_value:r=`Invalid enum value. Expected ${k.joinValues(t.options)}, received '${t.received}'`;break;case u.invalid_arguments:r="Invalid function arguments";break;case u.invalid_return_type:r="Invalid function return type";break;case u.invalid_date:r="Invalid date";break;case u.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:k.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case u.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case u.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case u.custom:r="Invalid input";break;case u.invalid_intersection_types:r="Intersection results could not be merged";break;case u.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case u.not_finite:r="Number must be finite";break;default:r=e.defaultError,k.assertNever(t)}return{message:r}},W=Ht;var ut=W;function qt(t){ut=t}function ve(){return ut}var Se=t=>{let{data:e,path:r,errorMaps:s,issueData:n}=t,i=[...r,...n.path||[]],a={...n,path:i};if(n.message!==void 0)return{...n,path:i,message:n.message};let o="",l=s.filter(d=>!!d).slice().reverse();for(let d of l)o=d(a,{data:e,defaultError:o}).message;return{...n,path:i,message:o}},Wt=[];function h(t,e){let r=ve(),s=Se({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===W?void 0:W].filter(n=>!!n)});t.common.issues.push(s)}var F=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let s=[];for(let n of r){if(n.status==="aborted")return y;n.status==="dirty"&&e.dirty(),s.push(n.value)}return{status:e.value,value:s}}static async mergeObjectAsync(e,r){let s=[];for(let n of r){let i=await n.key,a=await n.value;s.push({key:i,value:a})}return t.mergeObjectSync(e,s)}static mergeObjectSync(e,r){let s={};for(let n of r){let{key:i,value:a}=n;if(i.status==="aborted"||a.status==="aborted")return y;i.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(s[i.value]=a.value)}return{status:e.value,value:s}}},y=Object.freeze({status:"aborted"}),te=t=>({status:"dirty",value:t}),A=t=>({status:"valid",value:t}),Re=t=>t.status==="aborted",Ie=t=>t.status==="dirty",Q=t=>t.status==="valid",be=t=>typeof Promise<"u"&&t instanceof Promise;var m;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var P=class{constructor(e,r,s,n){this._cachedPath=[],this.parent=e,this.data=r,this._path=s,this._key=n}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}},ft=(t,e)=>{if(Q(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new R(t.common.issues);return this._error=r,this._error}}};function b(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:s,description:n}=t;if(e&&(r||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(a,o)=>{let{message:l}=t;return a.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:l??s??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:l??r??o.defaultError}},description:n}}var _=class{get description(){return this._def.description}_getType(e){return Z(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new F,ctx:{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(be(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let s=this.safeParse(e,r);if(s.success)return s.data;throw s.error}safeParse(e,r){let s={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},n=this._parseSync({data:e,path:s.path,parent:s});return ft(s,n)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)};if(!this["~standard"].async)try{let s=this._parseSync({data:e,path:[],parent:r});return Q(s)?{value:s.value}:{issues:r.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(s=>Q(s)?{value:s.value}:{issues:r.common.issues})}async parseAsync(e,r){let s=await this.safeParseAsync(e,r);if(s.success)return s.data;throw s.error}async safeParseAsync(e,r){let s={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},n=this._parse({data:e,path:s.path,parent:s}),i=await(be(n)?n:Promise.resolve(n));return ft(s,i)}refine(e,r){let s=n=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(n):r;return this._refinement((n,i)=>{let a=e(n),o=()=>i.addIssue({code:u.custom,...s(n)});return typeof Promise<"u"&&a instanceof Promise?a.then(l=>l?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,r){return this._refinement((s,n)=>e(s)?!0:(n.addIssue(typeof r=="function"?r(s,n):r),!1))}_refinement(e){return new M({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return j.create(this,this._def)}nullable(){return H.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Y.create(this)}promise(){return ee.create(this,this._def)}or(e){return le.create([this,e],this._def)}and(e){return de.create(this,e,this._def)}transform(e){return new M({...b(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new pe({...b(this._def),innerType:this,defaultValue:r,typeName:v.ZodDefault})}brand(){return new Ee({typeName:v.ZodBranded,type:this,...b(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new me({...b(this._def),innerType:this,catchValue:r,typeName:v.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return Fe.create(this,e)}readonly(){return ge.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Jt=/^c[^\s-]{8,}$/i,Kt=/^[0-9a-z]+$/,Yt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Qt=/^[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,Xt=/^[a-z0-9_-]{21}$/i,Gt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,er=/^[-+]?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)?)??$/,tr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,rr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Be,sr=/^(?:(?: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])$/,nr=/^(?:(?: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])$/,ir=/^(([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]))$/,ar=/^(([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])$/,or=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,lr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,pt="((\\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])))",dr=new RegExp(`^${pt}$`);function mt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function cr(t){return new RegExp(`^${mt(t)}$`)}function gt(t){let e=`${pt}T${mt(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function ur(t,e){return!!((e==="v4"||!e)&&sr.test(t)||(e==="v6"||!e)&&ir.test(t))}function fr(t,e){if(!Gt.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),n=JSON.parse(atob(s));return!(typeof n!="object"||n===null||"typ"in n&&n?.typ!=="JWT"||!n.alg||e&&n.alg!==e)}catch{return!1}}function hr(t,e){return!!((e==="v4"||!e)&&nr.test(t)||(e==="v6"||!e)&&ar.test(t))}var X=class t extends _{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.string,received:i.parsedType}),y}let s=new F,n;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),s.dirty());else if(i.kind==="max")e.data.length>i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),s.dirty());else if(i.kind==="length"){let a=e.data.length>i.value,o=e.data.length<i.value;(a||o)&&(n=this._getOrReturnCtx(e,n),a?h(n,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):o&&h(n,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),s.dirty())}else if(i.kind==="email")tr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"email",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="emoji")Be||(Be=new RegExp(rr,"u")),Be.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"emoji",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="uuid")Qt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"uuid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="nanoid")Xt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"nanoid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="cuid")Jt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cuid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="cuid2")Kt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cuid2",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="ulid")Yt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"ulid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),h(n,{validation:"url",code:u.invalid_string,message:i.message}),s.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"regex",code:u.invalid_string,message:i.message}),s.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),s.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{startsWith:i.value},message:i.message}),s.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{endsWith:i.value},message:i.message}),s.dirty()):i.kind==="datetime"?gt(i).test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"datetime",message:i.message}),s.dirty()):i.kind==="date"?dr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"date",message:i.message}),s.dirty()):i.kind==="time"?cr(i).test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"time",message:i.message}),s.dirty()):i.kind==="duration"?er.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"duration",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="ip"?ur(e.data,i.version)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"ip",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="jwt"?fr(e.data,i.alg)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"jwt",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="cidr"?hr(e.data,i.version)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cidr",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="base64"?or.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"base64",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="base64url"?lr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"base64url",code:u.invalid_string,message:i.message}),s.dirty()):k.assertNever(i);return{status:s.value,value:e.data}}_regex(e,r,s){return this.refinement(n=>e.test(n),{validation:r,code:u.invalid_string,...m.errToObj(s)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){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,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...m.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...m.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...m.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...m.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...m.errToObj(r)})}nonempty(e){return this.min(1,m.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(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};X.create=t=>new X({checks:[],typeName:v.ZodString,coerce:t?.coerce??!1,...b(t)});function pr(t,e){let r=(t.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,n=r>s?r:s,i=Number.parseInt(t.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return i%a/10**n}var re=class t extends _{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)!==p.number){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.number,received:i.parsedType}),y}let s,n=new F;for(let i of this._def.checks)i.kind==="int"?k.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:u.invalid_type,expected:"integer",received:"float",message:i.message}),n.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),n.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),n.dirty()):i.kind==="multipleOf"?pr(e.data,i.value)!==0&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),n.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_finite,message:i.message}),n.dirty()):k.assertNever(i);return{status:n.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,s,n){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.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,r=null;for(let s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(r===null||s.value>r)&&(r=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(r)&&Number.isFinite(e)}};re.create=t=>new re({checks:[],typeName:v.ZodNumber,coerce:t?.coerce||!1,...b(t)});var se=class t extends _{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)!==p.bigint)return this._getInvalidInput(e);let s,n=new F;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),n.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),n.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),n.dirty()):k.assertNever(i);return{status:n.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return h(r,{code:u.invalid_type,expected:p.bigint,received:r.parsedType}),y}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,s,n){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};se.create=t=>new se({checks:[],typeName:v.ZodBigInt,coerce:t?.coerce??!1,...b(t)});var ne=class extends _{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.boolean,received:s.parsedType}),y}return A(e.data)}};ne.create=t=>new ne({typeName:v.ZodBoolean,coerce:t?.coerce||!1,...b(t)});var ie=class t extends _{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.date,received:i.parsedType}),y}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_date}),y}let s=new F,n;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),s.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),s.dirty()):k.assertNever(i);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};ie.create=t=>new ie({checks:[],coerce:t?.coerce||!1,typeName:v.ZodDate,...b(t)});var xe=class extends _{_parse(e){if(this._getType(e)!==p.symbol){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.symbol,received:s.parsedType}),y}return A(e.data)}};xe.create=t=>new xe({typeName:v.ZodSymbol,...b(t)});var ae=class extends _{_parse(e){if(this._getType(e)!==p.undefined){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.undefined,received:s.parsedType}),y}return A(e.data)}};ae.create=t=>new ae({typeName:v.ZodUndefined,...b(t)});var oe=class extends _{_parse(e){if(this._getType(e)!==p.null){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.null,received:s.parsedType}),y}return A(e.data)}};oe.create=t=>new oe({typeName:v.ZodNull,...b(t)});var G=class extends _{constructor(){super(...arguments),this._any=!0}_parse(e){return A(e.data)}};G.create=t=>new G({typeName:v.ZodAny,...b(t)});var K=class extends _{constructor(){super(...arguments),this._unknown=!0}_parse(e){return A(e.data)}};K.create=t=>new K({typeName:v.ZodUnknown,...b(t)});var U=class extends _{_parse(e){let r=this._getOrReturnCtx(e);return h(r,{code:u.invalid_type,expected:p.never,received:r.parsedType}),y}};U.create=t=>new U({typeName:v.ZodNever,...b(t)});var ke=class extends _{_parse(e){if(this._getType(e)!==p.undefined){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.void,received:s.parsedType}),y}return A(e.data)}};ke.create=t=>new ke({typeName:v.ZodVoid,...b(t)});var Y=class t extends _{_parse(e){let{ctx:r,status:s}=this._processInputParams(e),n=this._def;if(r.parsedType!==p.array)return h(r,{code:u.invalid_type,expected:p.array,received:r.parsedType}),y;if(n.exactLength!==null){let a=r.data.length>n.exactLength.value,o=r.data.length<n.exactLength.value;(a||o)&&(h(r,{code:a?u.too_big:u.too_small,minimum:o?n.exactLength.value:void 0,maximum:a?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),s.dirty())}if(n.minLength!==null&&r.data.length<n.minLength.value&&(h(r,{code:u.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),s.dirty()),n.maxLength!==null&&r.data.length>n.maxLength.value&&(h(r,{code:u.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),s.dirty()),r.common.async)return Promise.all([...r.data].map((a,o)=>n.type._parseAsync(new P(r,a,r.path,o)))).then(a=>F.mergeArray(s,a));let i=[...r.data].map((a,o)=>n.type._parseSync(new P(r,a,r.path,o)));return F.mergeArray(s,i)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:m.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:m.toString(r)}})}nonempty(e){return this.min(1,e)}};Y.create=(t,e)=>new Y({type:t,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,...b(e)});function _e(t){if(t instanceof I){let e={};for(let r in t.shape){let s=t.shape[r];e[r]=j.create(_e(s))}return new I({...t._def,shape:()=>e})}else return t instanceof Y?new Y({...t._def,type:_e(t.element)}):t instanceof j?j.create(_e(t.unwrap())):t instanceof H?H.create(_e(t.unwrap())):t instanceof B?B.create(t.items.map(e=>_e(e))):t}var I=class t extends _{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=k.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==p.object){let d=this._getOrReturnCtx(e);return h(d,{code:u.invalid_type,expected:p.object,received:d.parsedType}),y}let{status:s,ctx:n}=this._processInputParams(e),{shape:i,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof U&&this._def.unknownKeys==="strip"))for(let d in n.data)a.includes(d)||o.push(d);let l=[];for(let d of a){let f=i[d],g=n.data[d];l.push({key:{status:"valid",value:d},value:f._parse(new P(n,g,n.path,d)),alwaysSet:d in n.data})}if(this._def.catchall instanceof U){let d=this._def.unknownKeys;if(d==="passthrough")for(let f of o)l.push({key:{status:"valid",value:f},value:{status:"valid",value:n.data[f]}});else if(d==="strict")o.length>0&&(h(n,{code:u.unrecognized_keys,keys:o}),s.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let d=this._def.catchall;for(let f of o){let g=n.data[f];l.push({key:{status:"valid",value:f},value:d._parse(new P(n,g,n.path,f)),alwaysSet:f in n.data})}}return n.common.async?Promise.resolve().then(async()=>{let d=[];for(let f of l){let g=await f.key,T=await f.value;d.push({key:g,value:T,alwaysSet:f.alwaysSet})}return d}).then(d=>F.mergeObjectSync(s,d)):F.mergeObjectSync(s,l)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,s)=>{let n=this._def.errorMap?.(r,s).message??s.defaultError;return r.code==="unrecognized_keys"?{message:m.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let s of k.objectKeys(e))e[s]&&this.shape[s]&&(r[s]=this.shape[s]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let s of k.objectKeys(this.shape))e[s]||(r[s]=this.shape[s]);return new t({...this._def,shape:()=>r})}deepPartial(){return _e(this)}partial(e){let r={};for(let s of k.objectKeys(this.shape)){let n=this.shape[s];e&&!e[s]?r[s]=n:r[s]=n.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let s of k.objectKeys(this.shape))if(e&&!e[s])r[s]=this.shape[s];else{let i=this.shape[s];for(;i instanceof j;)i=i._def.innerType;r[s]=i}return new t({...this._def,shape:()=>r})}keyof(){return yt(k.objectKeys(this.shape))}};I.create=(t,e)=>new I({shape:()=>t,unknownKeys:"strip",catchall:U.create(),typeName:v.ZodObject,...b(e)});I.strictCreate=(t,e)=>new I({shape:()=>t,unknownKeys:"strict",catchall:U.create(),typeName:v.ZodObject,...b(e)});I.lazycreate=(t,e)=>new I({shape:t,unknownKeys:"strip",catchall:U.create(),typeName:v.ZodObject,...b(e)});var le=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=this._def.options;function n(i){for(let o of i)if(o.result.status==="valid")return o.result;for(let o of i)if(o.result.status==="dirty")return r.common.issues.push(...o.ctx.common.issues),o.result;let a=i.map(o=>new R(o.ctx.common.issues));return h(r,{code:u.invalid_union,unionErrors:a}),y}if(r.common.async)return Promise.all(s.map(async i=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await i._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(n);{let i,a=[];for(let l of s){let d={...r,common:{...r.common,issues:[]},parent:null},f=l._parseSync({data:r.data,path:r.path,parent:d});if(f.status==="valid")return f;f.status==="dirty"&&!i&&(i={result:f,ctx:d}),d.common.issues.length&&a.push(d.common.issues)}if(i)return r.common.issues.push(...i.ctx.common.issues),i.result;let o=a.map(l=>new R(l));return h(r,{code:u.invalid_union,unionErrors:o}),y}}get options(){return this._def.options}};le.create=(t,e)=>new le({options:t,typeName:v.ZodUnion,...b(e)});var J=t=>t instanceof ce?J(t.schema):t instanceof M?J(t.innerType()):t instanceof ue?[t.value]:t instanceof fe?t.options:t instanceof he?k.objectValues(t.enum):t instanceof pe?J(t._def.innerType):t instanceof ae?[void 0]:t instanceof oe?[null]:t instanceof j?[void 0,...J(t.unwrap())]:t instanceof H?[null,...J(t.unwrap())]:t instanceof Ee||t instanceof ge?J(t.unwrap()):t instanceof me?J(t._def.innerType):[],$e=class t extends _{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.object)return h(r,{code:u.invalid_type,expected:p.object,received:r.parsedType}),y;let s=this.discriminator,n=r.data[s],i=this.optionsMap.get(n);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(h(r,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),y)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,s){let n=new Map;for(let i of r){let a=J(i.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let o of a){if(n.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);n.set(o,i)}}return new t({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:n,...b(s)})}};function He(t,e){let r=Z(t),s=Z(e);if(t===e)return{valid:!0,data:t};if(r===p.object&&s===p.object){let n=k.objectKeys(e),i=k.objectKeys(t).filter(o=>n.indexOf(o)!==-1),a={...t,...e};for(let o of i){let l=He(t[o],e[o]);if(!l.valid)return{valid:!1};a[o]=l.data}return{valid:!0,data:a}}else if(r===p.array&&s===p.array){if(t.length!==e.length)return{valid:!1};let n=[];for(let i=0;i<t.length;i++){let a=t[i],o=e[i],l=He(a,o);if(!l.valid)return{valid:!1};n.push(l.data)}return{valid:!0,data:n}}else return r===p.date&&s===p.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var de=class extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e),n=(i,a)=>{if(Re(i)||Re(a))return y;let o=He(i.value,a.value);return o.valid?((Ie(i)||Ie(a))&&r.dirty(),{status:r.value,value:o.data}):(h(s,{code:u.invalid_intersection_types}),y)};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(([i,a])=>n(i,a)):n(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}};de.create=(t,e,r)=>new de({left:t,right:e,typeName:v.ZodIntersection,...b(r)});var B=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.array)return h(s,{code:u.invalid_type,expected:p.array,received:s.parsedType}),y;if(s.data.length<this._def.items.length)return h(s,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),y;!this._def.rest&&s.data.length>this._def.items.length&&(h(s,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...s.data].map((a,o)=>{let l=this._def.items[o]||this._def.rest;return l?l._parse(new P(s,a,s.path,o)):null}).filter(a=>!!a);return s.common.async?Promise.all(i).then(a=>F.mergeArray(r,a)):F.mergeArray(r,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};B.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new B({items:t,typeName:v.ZodTuple,rest:null,...b(e)})};var Le=class t extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.object)return h(s,{code:u.invalid_type,expected:p.object,received:s.parsedType}),y;let n=[],i=this._def.keyType,a=this._def.valueType;for(let o in s.data)n.push({key:i._parse(new P(s,o,s.path,o)),value:a._parse(new P(s,s.data[o],s.path,o)),alwaysSet:o in s.data});return s.common.async?F.mergeObjectAsync(r,n):F.mergeObjectSync(r,n)}get element(){return this._def.valueType}static create(e,r,s){return r instanceof _?new t({keyType:e,valueType:r,typeName:v.ZodRecord,...b(s)}):new t({keyType:X.create(),valueType:e,typeName:v.ZodRecord,...b(r)})}},we=class extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.map)return h(s,{code:u.invalid_type,expected:p.map,received:s.parsedType}),y;let n=this._def.keyType,i=this._def.valueType,a=[...s.data.entries()].map(([o,l],d)=>({key:n._parse(new P(s,o,s.path,[d,"key"])),value:i._parse(new P(s,l,s.path,[d,"value"]))}));if(s.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let l of a){let d=await l.key,f=await l.value;if(d.status==="aborted"||f.status==="aborted")return y;(d.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(d.value,f.value)}return{status:r.value,value:o}})}else{let o=new Map;for(let l of a){let d=l.key,f=l.value;if(d.status==="aborted"||f.status==="aborted")return y;(d.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(d.value,f.value)}return{status:r.value,value:o}}}};we.create=(t,e,r)=>new we({valueType:e,keyType:t,typeName:v.ZodMap,...b(r)});var Ce=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.set)return h(s,{code:u.invalid_type,expected:p.set,received:s.parsedType}),y;let n=this._def;n.minSize!==null&&s.data.size<n.minSize.value&&(h(s,{code:u.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),r.dirty()),n.maxSize!==null&&s.data.size>n.maxSize.value&&(h(s,{code:u.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),r.dirty());let i=this._def.valueType;function a(l){let d=new Set;for(let f of l){if(f.status==="aborted")return y;f.status==="dirty"&&r.dirty(),d.add(f.value)}return{status:r.value,value:d}}let o=[...s.data.values()].map((l,d)=>i._parse(new P(s,l,s.path,d)));return s.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,r){return new t({...this._def,minSize:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:m.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Ce.create=(t,e)=>new Ce({valueType:t,minSize:null,maxSize:null,typeName:v.ZodSet,...b(e)});var je=class t extends _{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.function)return h(r,{code:u.invalid_type,expected:p.function,received:r.parsedType}),y;function s(o,l){return Se({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),W].filter(d=>!!d),issueData:{code:u.invalid_arguments,argumentsError:l}})}function n(o,l){return Se({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),W].filter(d=>!!d),issueData:{code:u.invalid_return_type,returnTypeError:l}})}let i={errorMap:r.common.contextualErrorMap},a=r.data;if(this._def.returns instanceof ee){let o=this;return A(async function(...l){let d=new R([]),f=await o._def.args.parseAsync(l,i).catch(C=>{throw d.addIssue(s(l,C)),d}),g=await Reflect.apply(a,this,f);return await o._def.returns._def.type.parseAsync(g,i).catch(C=>{throw d.addIssue(n(g,C)),d})})}else{let o=this;return A(function(...l){let d=o._def.args.safeParse(l,i);if(!d.success)throw new R([s(l,d.error)]);let f=Reflect.apply(a,this,d.data),g=o._def.returns.safeParse(f,i);if(!g.success)throw new R([n(f,g.error)]);return g.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:B.create(e).rest(K.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,s){return new t({args:e||B.create([]).rest(K.create()),returns:r||K.create(),typeName:v.ZodFunction,...b(s)})}},ce=class extends _{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};ce.create=(t,e)=>new ce({getter:t,typeName:v.ZodLazy,...b(e)});var ue=class extends _{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return h(r,{received:r.data,code:u.invalid_literal,expected:this._def.value}),y}return{status:"valid",value:e.data}}get value(){return this._def.value}};ue.create=(t,e)=>new ue({value:t,typeName:v.ZodLiteral,...b(e)});function yt(t,e){return new fe({values:t,typeName:v.ZodEnum,...b(e)})}var fe=class t extends _{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),s=this._def.values;return h(r,{expected:k.joinValues(s),received:r.parsedType,code:u.invalid_type}),y}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),s=this._def.values;return h(r,{received:r.data,code:u.invalid_enum_value,options:s}),y}return A(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(s=>!e.includes(s)),{...this._def,...r})}};fe.create=yt;var he=class extends _{_parse(e){let r=k.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==p.string&&s.parsedType!==p.number){let n=k.objectValues(r);return h(s,{expected:k.joinValues(n),received:s.parsedType,code:u.invalid_type}),y}if(this._cache||(this._cache=new Set(k.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let n=k.objectValues(r);return h(s,{received:s.data,code:u.invalid_enum_value,options:n}),y}return A(e.data)}get enum(){return this._def.values}};he.create=(t,e)=>new he({values:t,typeName:v.ZodNativeEnum,...b(e)});var ee=class extends _{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.promise&&r.common.async===!1)return h(r,{code:u.invalid_type,expected:p.promise,received:r.parsedType}),y;let s=r.parsedType===p.promise?r.data:Promise.resolve(r.data);return A(s.then(n=>this._def.type.parseAsync(n,{path:r.path,errorMap:r.common.contextualErrorMap})))}};ee.create=(t,e)=>new ee({type:t,typeName:v.ZodPromise,...b(e)});var M=class extends _{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:s}=this._processInputParams(e),n=this._def.effect||null,i={addIssue:a=>{h(s,a),a.fatal?r.abort():r.dirty()},get path(){return s.path}};if(i.addIssue=i.addIssue.bind(i),n.type==="preprocess"){let a=n.transform(s.data,i);if(s.common.async)return Promise.resolve(a).then(async o=>{if(r.value==="aborted")return y;let l=await this._def.schema._parseAsync({data:o,path:s.path,parent:s});return l.status==="aborted"?y:l.status==="dirty"?te(l.value):r.value==="dirty"?te(l.value):l});{if(r.value==="aborted")return y;let o=this._def.schema._parseSync({data:a,path:s.path,parent:s});return o.status==="aborted"?y:o.status==="dirty"?te(o.value):r.value==="dirty"?te(o.value):o}}if(n.type==="refinement"){let a=o=>{let l=n.refinement(o,i);if(s.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(s.common.async===!1){let o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return o.status==="aborted"?y:(o.status==="dirty"&&r.dirty(),a(o.value),{status:r.value,value:o.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>o.status==="aborted"?y:(o.status==="dirty"&&r.dirty(),a(o.value).then(()=>({status:r.value,value:o.value}))))}if(n.type==="transform")if(s.common.async===!1){let a=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!Q(a))return y;let o=n.transform(a.value,i);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(a=>Q(a)?Promise.resolve(n.transform(a.value,i)).then(o=>({status:r.value,value:o})):y);k.assertNever(n)}};M.create=(t,e,r)=>new M({schema:t,typeName:v.ZodEffects,effect:e,...b(r)});M.createWithPreprocess=(t,e,r)=>new M({schema:e,effect:{type:"preprocess",transform:t},typeName:v.ZodEffects,...b(r)});var j=class extends _{_parse(e){return this._getType(e)===p.undefined?A(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};j.create=(t,e)=>new j({innerType:t,typeName:v.ZodOptional,...b(e)});var H=class extends _{_parse(e){return this._getType(e)===p.null?A(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};H.create=(t,e)=>new H({innerType:t,typeName:v.ZodNullable,...b(e)});var pe=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=r.data;return r.parsedType===p.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};pe.create=(t,e)=>new pe({innerType:t,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...b(e)});var me=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s={...r,common:{...r.common,issues:[]}},n=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return be(n)?n.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}};me.create=(t,e)=>new me({innerType:t,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...b(e)});var Te=class extends _{_parse(e){if(this._getType(e)!==p.nan){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.nan,received:s.parsedType}),y}return{status:"valid",value:e.data}}};Te.create=t=>new Te({typeName:v.ZodNaN,...b(t)});var mr=Symbol("zod_brand"),Ee=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=r.data;return this._def.type._parse({data:s,path:r.path,parent:r})}unwrap(){return this._def.type}},Fe=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return i.status==="aborted"?y:i.status==="dirty"?(r.dirty(),te(i.value)):this._def.out._parseAsync({data:i.value,path:s.path,parent:s})})();{let n=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return n.status==="aborted"?y:n.status==="dirty"?(r.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:s.path,parent:s})}}static create(e,r){return new t({in:e,out:r,typeName:v.ZodPipeline})}},ge=class extends _{_parse(e){let r=this._def.innerType._parse(e),s=n=>(Q(n)&&(n.value=Object.freeze(n.value)),n);return be(r)?r.then(n=>s(n)):s(r)}unwrap(){return this._def.innerType}};ge.create=(t,e)=>new ge({innerType:t,typeName:v.ZodReadonly,...b(e)});function ht(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function vt(t,e={},r){return t?G.create().superRefine((s,n)=>{let i=t(s);if(i instanceof Promise)return i.then(a=>{if(!a){let o=ht(e,s),l=o.fatal??r??!0;n.addIssue({code:"custom",...o,fatal:l})}});if(!i){let a=ht(e,s),o=a.fatal??r??!0;n.addIssue({code:"custom",...a,fatal:o})}}):G.create()}var gr={object:I.lazycreate},v;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(v||(v={}));var yr=(t,e={message:`Input not instance of ${t.name}`})=>vt(r=>r instanceof t,e),bt=X.create,_t=re.create,vr=Te.create,br=se.create,xt=ne.create,_r=ie.create,xr=xe.create,kr=ae.create,wr=oe.create,Cr=G.create,Tr=K.create,Nr=U.create,Sr=ke.create,Er=Y.create,Fr=I.create,Ar=I.strictCreate,Or=le.create,Rr=$e.create,Ir=de.create,$r=B.create,Lr=Le.create,jr=we.create,Pr=Ce.create,Mr=je.create,Vr=ce.create,Dr=ue.create,Ur=fe.create,zr=he.create,Zr=ee.create,Br=M.create,Hr=j.create,qr=H.create,Wr=M.createWithPreprocess,Jr=Fe.create,Kr=()=>bt().optional(),Yr=()=>_t().optional(),Qr=()=>xt().optional(),Xr={string:(t=>X.create({...t,coerce:!0})),number:(t=>re.create({...t,coerce:!0})),boolean:(t=>ne.create({...t,coerce:!0})),bigint:(t=>se.create({...t,coerce:!0})),date:(t=>ie.create({...t,coerce:!0}))};var Gr=y;var es=["heading","paragraph","divider"];function Ae(t){return!es.includes(t.kind)}function kt(t){return t==null?!1:typeof t=="string"?t.trim()!=="":Array.isArray(t)?t.length>0:typeof t=="boolean"?t:typeof t=="object"?Object.keys(t).length>0:!0}function ts(t,e){let r=e[t.fieldId];switch(t.op){case"answered":return kt(r);case"not_answered":return!kt(r);case"eq":return Array.isArray(r)?r.some(s=>s===t.value):r===t.value;case"neq":return Array.isArray(r)?!r.some(s=>s===t.value):r!==t.value;case"contains":return typeof r=="string"?r.toLowerCase().includes(String(t.value??"").toLowerCase()):Array.isArray(r)?r.some(s=>s===t.value):!1;case"gt":return typeof r=="number"&&r>Number(t.value);case"lt":return typeof r=="number"&&r<Number(t.value)}}function rs(t,e){return!t.visibleIf||t.visibleIf.length===0?!0:t.visibleIf.every(r=>ts(r,e))}function Qe(t,e){return t.blocks.filter(r=>rs(r,e))}function ss(t){return t.pages.flatMap(e=>e.blocks.filter(Ae))}function ns(t,e){return t.pages.flatMap(r=>Qe(r,e).filter(Ae))}var is=w.object({fileId:w.string().min(1),name:w.string(),size:w.number().nonnegative(),mime:w.string(),url:w.string().optional()});function Ct(t){return t==null?!0:typeof t=="string"?t.trim()==="":Array.isArray(t)?t.length===0:typeof t=="boolean"?t===!1:typeof t=="object"?Object.keys(t).length===0:!1}function Tt(t,e){if(Ct(e))return t.required?"This field is required":null;switch(t.kind){case"short_text":case"long_text":{if(typeof e!="string")return"Expected text";if(t.maxLength&&e.length>t.maxLength)return`Must be at most ${t.maxLength} characters`;let r=t.kind==="long_text"?2e4:2e3;return!t.maxLength&&e.length>r?"Answer is too long":null}case"email":return w.string().email().safeParse(e).success?null:"Enter a valid email address";case"url":{if(typeof e!="string")return"Enter a valid URL (including https://)";try{let r=new URL(e);if(r.protocol!=="http:"&&r.protocol!=="https:")return"Enter an http(s) URL"}catch{return"Enter a valid URL (including https://)"}return null}case"phone":return typeof e!="string"||!/^[+\d][\d\s\-().]{4,}$/.test(e)?"Enter a valid phone number":null;case"number":{let r=typeof e=="string"?Number(e):e;return typeof r!="number"||Number.isNaN(r)?"Enter a number":t.min!==void 0&&r<t.min?`Must be at least ${t.min}`:t.max!==void 0&&r>t.max?`Must be at most ${t.max}`:null}case"select":case"dropdown":return typeof e!="string"||e===""?"Pick an option":t.options.some(r=>r.id===e)||t.allowOther&&e.length<=500?null:"Pick a valid option";case"multi_select":{if(!Array.isArray(e))return"Pick at least one option";let r=new Set(t.options.map(i=>i.id)),s=e,n=0;for(let i of s)if(!r.has(i)){if(t.allowOther!==!0||typeof i!="string"||i.length===0||i.length>500)return"Pick valid options";if(++n>1)return"Only one 'Other' answer is allowed"}return null}case"checkbox":return typeof e=="boolean"?null:"Invalid value";case"rating":{let r=t.max??5,s=typeof e=="string"?Number(e):e;return typeof s!="number"||!Number.isInteger(s)||s<1||s>r?`Pick a rating between 1 and ${r}`:null}case"linear_scale":{let r=t.min??1,s=t.max??10,n=typeof e=="string"?Number(e):e;return typeof n!="number"||!Number.isInteger(n)||n<r||n>s?`Pick a value between ${r} and ${s}`:null}case"ranking":{if(!Array.isArray(e))return"Drag the options into order";let r=t.options.map(n=>n.id).sort(),s=[...e].sort();return r.length!==s.length||r.some((n,i)=>n!==s[i])?"Rank every option":null}case"matrix":{if(typeof e!="object"||e===null||Array.isArray(e))return"Answer the grid";let r=e,s=new Set(t.columns.map(i=>i.id)),n=new Set(t.rows.map(i=>i.id));for(let[i,a]of Object.entries(r))if(!n.has(i)||!s.has(a))return"Invalid grid answer";return t.required&&Object.keys(r).length<t.rows.length?"Answer every row":null}case"signature":return typeof e!="string"||!e.startsWith("data:image/")?"Sign in the box":null;case"hidden":return typeof e=="string"?null:"Invalid value";case"custom":return null;case"date":return typeof e!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(e)?"Enter a valid date":null;case"file_upload":{let r=w.array(is).safeParse(e);if(!r.success)return"Upload did not complete";let s=t.maxFiles??1;return r.data.length>s?`At most ${s} file${s===1?"":"s"}`:null}}}function as(t,e){let r=ns(t,e),s={},n={};for(let i of r){let a=os(i,e[i.id]),o=Tt(i,a);o?s[i.id]=o:Ct(a)||(n[i.id]=a)}return{ok:Object.keys(s).length===0,errors:s,data:n}}function os(t,e){if(e==null)return e;if(t.kind==="number"&&typeof e=="string"&&e.trim()!==""){let r=Number(e);return Number.isNaN(r)?e:r}if(t.kind==="rating"&&typeof e=="string"){let r=Number(e);return Number.isNaN(r)?e:r}return typeof e=="string"?e.trim():e}var ls=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","custom"],ds=["heading","paragraph","divider"],cs=[...ls,...ds],Xe=w.string().min(1).max(128),qe=w.object({id:Xe,label:w.string().max(1e3)}).passthrough(),us=w.object({id:Xe,kind:w.enum(cs),label:w.string().max(2e3).optional(),options:w.array(qe).max(200).optional(),rows:w.array(qe).max(200).optional(),columns:w.array(qe).max(200).optional()}).passthrough(),fs=w.object({id:Xe,title:w.string().max(500).optional(),blocks:w.array(us).max(500)}),gn=w.object({version:w.literal(1),title:w.string().max(2e3).optional().default(""),description:w.string().max(5e3).optional(),pages:w.array(fs).min(1).max(50),settings:w.record(w.unknown()).optional().default({})});var hs="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",yn=256-256%hs.length;var Nt=class{h0=1732584193;h1=4023233417;h2=2562383102;h3=271733878;h4=3285377520;block=new Uint8Array(64);blockLen=0;totalLen=0;w=new Int32Array(80);update(t){this.totalLen+=t.length;let e=0;if(this.blockLen>0){for(;e<t.length&&this.blockLen<64;)this.block[this.blockLen++]=t[e++];this.blockLen===64&&(this.process(this.block),this.blockLen=0)}for(;e+64<=t.length;)this.process(t.subarray(e,e+64)),e+=64;for(;e<t.length;)this.block[this.blockLen++]=t[e++];return this}digest(){let t=Math.floor(this.totalLen/536870912),e=this.totalLen*8>>>0,r=[128],s=this.blockLen+1;for(;s%64!==56;)r.push(0),s++;r.push(t>>>24&255,t>>>16&255,t>>>8&255,t&255),r.push(e>>>24&255,e>>>16&255,e>>>8&255,e&255),this.update(new Uint8Array(r));let n=new Uint8Array(20),i=[this.h0,this.h1,this.h2,this.h3,this.h4];for(let a=0;a<5;a++)n[a*4]=i[a]>>>24&255,n[a*4+1]=i[a]>>>16&255,n[a*4+2]=i[a]>>>8&255,n[a*4+3]=i[a]&255;return n}process(t){let e=this.w;for(let o=0;o<16;o++)e[o]=t[o*4]<<24|t[o*4+1]<<16|t[o*4+2]<<8|t[o*4+3];for(let o=16;o<80;o++){let l=e[o-3]^e[o-8]^e[o-14]^e[o-16];e[o]=l<<1|l>>>31}let r=this.h0,s=this.h1,n=this.h2,i=this.h3,a=this.h4;for(let o=0;o<80;o++){let l,d;o<20?(l=s&n|~s&i,d=1518500249):o<40?(l=s^n^i,d=1859775393):o<60?(l=s&n|s&i|n&i,d=2400959708):(l=s^n^i,d=3395469782);let f=(r<<5|r>>>27)+l+a+d+e[o]|0;a=i,i=n,n=s<<30|s>>>2,s=r,r=f}this.h0=this.h0+r|0,this.h1=this.h1+s|0,this.h2=this.h2+n|0,this.h3=this.h3+i|0,this.h4=this.h4+a|0}},Pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Ge(t){let e="";for(let r=0;r<t.length;r+=3){let s=t[r],n=r+1<t.length?t[r+1]:0,i=r+2<t.length?t[r+2]:0;e+=Pe[s>>2],e+=Pe[(s&3)<<4|n>>4],e+=r+1<t.length?Pe[(n&15)<<2|i>>6]:"=",e+=r+2<t.length?Pe[i&63]:"="}return e}var ps=t=>Ge(new Nt().update(t).digest()),S=class extends Error{constructor(t,e){super(t),this.status=e,this.name="FilloError"}status},We=3;function Je(t,e){return r=>e.onProgress?.({uploadedBytes:r,totalBytes:t,fraction:t===0?1:r/t})}async function ms(t){let e=globalThis.crypto?.subtle;if(e){let r=await e.digest("SHA-1",t);return Ge(new Uint8Array(r))}return ps(t)}var gs="https://fillo.so",Me=class{baseUrl;fetch;key;constructor(t={}){this.baseUrl=(t.baseUrl??gs).replace(/\/$/,""),this.key=t.key,this.fetch=t.fetch??((...e)=>globalThis.fetch(...e))}url(t){return`${this.baseUrl}/api/v1${t}`}async json(t,e){let r=await this.fetch(this.url(t),{...e,headers:{"Content-Type":"application/json",...e?.headers}});if(!r.ok){let s=await r.text().catch(()=>"");throw new S(s||`Request failed: ${r.status}`,r.status)}return await r.json()}getForm(t){return this.json(`/forms/${encodeURIComponent(t)}`)}syncForm(t,e,r){return this.key?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:t,schema:e,theme:r})}):Promise.reject(new S("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401))}async submit(t,e,r){let s=await this.fetch(this.url(`/forms/${encodeURIComponent(t)}/responses`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:e,meta:r})});if(s.status===422)return{ok:!1,errors:(await s.json()).errors};if(!s.ok)throw new S(`Submit failed: ${s.status}`,s.status);return{ok:!0,responseId:(await s.json()).id}}async startSession(t,e){try{let r=await this.fetch(this.url(`/forms/${encodeURIComponent(t)}/sessions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageCount:e})});return r.ok?(await r.json()).id:null}catch{return null}}reportProgress(t,e){try{this.fetch(this.url(`/sessions/${encodeURIComponent(t)}/progress`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0}).catch(()=>{})}catch{}}getUploadSession(t,e){return this.json(`/uploads/${encodeURIComponent(t)}`,e?{headers:{"X-Fillo-Upload-Token":e}}:void 0)}async uploadFile(t,e,r){let s=e instanceof File?e.name:"upload.bin",n=e.type||"application/octet-stream",i;r.sessionId?i=await this.getUploadSession(r.sessionId,r.uploadToken):i=await this.json(`/forms/${encodeURIComponent(t)}/uploads`,{method:"POST",body:JSON.stringify({fieldId:r.fieldId,fileName:s,size:e.size,mime:n})});let a;if(i.transport?.type==="gdrive")await this.driveUploadLoop(i,i.transport.uploadUrl,e,r);else if(i.transport?.type==="s3-put")await this.s3PutUpload(i.transport.uploadUrl,e,r);else if(i.transport?.type==="box")a=await this.boxUpload(i.transport,e,r);else throw new S("This form's storage doesn't support uploads \u2014 connect Drive, S3, or Box.");let o=await this.json(`/uploads/${encodeURIComponent(i.id)}/complete`,{method:"POST",headers:i.token?{"X-Fillo-Upload-Token":i.token}:void 0,...a?{body:JSON.stringify(a)}:{}});if(!o.file)throw new S("Upload completed but no file was returned");return o.file}async boxUpload(t,e,r){let s=Je(e.size,r);s(0);let n={Authorization:`Bearer ${t.token}`};if(t.mode==="simple"){let T=new FormData;T.append("attributes",JSON.stringify({name:t.fileName,parent:{id:t.folderId}})),T.append("file",e,t.fileName);let C=await this.retry(r,()=>this.fetch(t.uploadUrl,{method:"POST",headers:n,body:T,signal:r.signal}));if(!C.ok)throw new S(`Box upload failed: ${C.status}`,C.status);let D=await C.json();return s(e.size),{providerFileId:D.entries?.[0]?.id}}if(t.size!==e.size)throw new S(`File size changed since the upload was requested (${e.size} vs ${t.size}).`,400);let i=await this.retry(r,()=>this.fetch(t.sessionUrl,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({folder_id:t.folderId,file_size:t.size,file_name:t.fileName}),signal:r.signal}));if(!i.ok)throw new S(`Box session failed: ${i.status}`,i.status);let a=await i.json(),o=new Nt,l=[],d=0;for(;d<e.size;){r.signal?.throwIfAborted();let T=Math.min(d+a.part_size,e.size),C=new Uint8Array(await e.slice(d,T).arrayBuffer());o.update(C);let D=await ms(C),$=await this.retry(r,()=>this.fetch(a.session_endpoints.upload_part,{method:"PUT",headers:{...n,"Content-Type":"application/octet-stream",Digest:`sha=${D}`,"Content-Range":`bytes ${d}-${T-1}/${e.size}`},body:C,signal:r.signal}));if(!$.ok)throw new S(`Box part failed: ${$.status}`,$.status);l.push((await $.json()).part),d=T,s(d)}let f=await this.retry(r,()=>this.fetch(a.session_endpoints.commit,{method:"POST",headers:{...n,"Content-Type":"application/json",Digest:`sha=${Ge(o.digest())}`},body:JSON.stringify({parts:l}),signal:r.signal}));if(!f.ok)throw new S(`Box commit failed: ${f.status}`,f.status);return{providerFileId:(await f.json()).entries?.[0]?.id}}async retry(t,e){let r=0;for(;;)try{return await e()}catch(s){if(t.signal?.aborted||(r+=1,r>=We))throw s;await new Promise(n=>setTimeout(n,500*2**r))}}async driveUploadLoop(t,e,r,s){let n=t.uploadedBytes,i=Je(r.size,s);for(i(n);n<r.size;){s.signal?.throwIfAborted();let a=Math.min(n+t.chunkSize,r.size),o=r.slice(n,a),l=0;for(;;)try{let d=await this.fetch(e,{method:"PUT",headers:{"Content-Range":`bytes ${n}-${a-1}/${r.size}`},body:o,signal:s.signal});if(d.status===308){let f=d.headers.get("Range")??d.headers.get("range"),g=f?.match(/bytes=0-(\d+)/);g?n=Number(g[1])+1:f==null?n=0:n=(await this.getUploadSession(t.id,t.token)).uploadedBytes;break}if(d.ok){n=r.size;break}throw new S(`Drive chunk failed: ${d.status}`,d.status)}catch(d){if(s.signal?.aborted||(l+=1,l>=We))throw d;await new Promise(g=>setTimeout(g,500*2**l)),n=(await this.getUploadSession(t.id,t.token)).uploadedBytes}i(n)}}async s3PutUpload(t,e,r){let s=Je(e.size,r);s(0);let n=0;for(;;)try{let i=await this.fetch(t,{method:"PUT",headers:{"Content-Type":e.type||"application/octet-stream"},body:e,signal:r.signal});if(!i.ok)throw new S(`S3 upload failed: ${i.status}`,i.status);s(e.size);return}catch(i){if(r.signal?.aborted||(n+=1,n>=We))throw i;await new Promise(a=>setTimeout(a,500*2**n))}}};function Oe(t={}){return new Me(t)}var ys={id:"empty",blocks:[]},wt=!1;function vs(){wt||(wt=!0,console.warn("[fillo] This form has no `client`, so responses can't be submitted \u2014 it's render-only. Pass a client (createClient) to collect responses in Fillo, or forward them to your own backend with webhooks: https://fillo.so/docs"))}function St(t){let{onChange:e,onSubmitted:r}=t,s=t.form,n=t.formId,i=t.client,a={...t.initialData??{}},o={},l=0,d="idle",f=new Set,g=new Set,T=Date.now(),C=null,D=!1;function $(){let x=s.pages.length,N=Math.min(l,Math.max(x-1,0)),E=s.pages[N]??ys;return{data:a,errors:o,status:d,pageIndex:N,pageCount:x,page:E,blocks:Qe(E,a),isFirstPage:N===0,isLastPage:N===x-1,uploading:f.size>0}}let ot=$();function L(){ot=$();for(let x of g)x()}function lt(x,N){try{r?.(x,N)}catch(E){console.error("[fillo] onSubmitted handler threw:",E)}}function It(x){let N=s.pages[x];if(!N)return{};let E={};for(let ye of Qe(N,a)){if(!Ae(ye))continue;let dt=Tt(ye,a[ye.id]);dt&&(E[ye.id]=dt)}return E}function $t(x,N){!D&&i&&n&&(D=!0,i.startSession(n,s.pages.length).then(E=>C=E)),a={...a,[x]:N},e?.(a),x in o&&(o=Object.fromEntries(Object.entries(o).filter(([E])=>E!==x))),L()}function Lt(x,N){N?f.add(x):f.delete(x),L()}function jt(){let x=s.pages.length,N=Math.min(l,Math.max(x-1,0));if(!t.skipValidation){let E=It(N);if(o=E,Object.keys(E).length>0){L();return}}l=Math.min(N+1,x-1),C&&i&&i.reportProgress(C,{furthestPage:l}),L()}function Pt(){o={},l=Math.max(Math.min(l,s.pages.length-1)-1,0),L()}async function Mt(){if(d==="submitting"||d==="submitted")return;let x=as(s,a);if(!x.ok){o=x.errors;let N=s.pages.findIndex(E=>E.blocks.some(ye=>ye.id in x.errors));N>=0&&(l=N),L();return}if(i&&n){d="submitting",L();let N;try{N=await i.submit(n,x.data,{hp:t.getHoneypot?.()??"",elapsedMs:Date.now()-T,surface:t.surface??"default"})}catch(E){throw d="idle",L(),E}if(!N.ok){o=N.errors??{},d="idle",L();return}C&&i.reportProgress(C,{completed:!0}),d="submitted",L(),lt(N.responseId,x.data);return}if(t.skipValidation){d="submitted",L(),lt(void 0,x.data);return}vs(),d="error",L()}return{getState:()=>ot,subscribe(x){return g.add(x),()=>{g.delete(x)}},setValue:$t,setUploading:Lt,next:jt,back:Pt,submit:Mt,setContext(x){"formId"in x&&(n=x.formId),"client"in x&&(i=x.client),x.form&&x.form!==s&&(s=x.form,L())},destroy(){g.clear()}}}function et(t){return{id:t.id,theme:t.theme,schema:{version:1,title:t.title??"",description:t.description,pages:t.pages,settings:t.settings??{}},__filloCodeForm:!0}}function tt(t){return typeof t=="object"&&t!==null&&"__filloCodeForm"in t}var Ke=new Map;function bs(t){let e=5381;for(let r=0;r<t.length;r++)e=(e<<5)+e+t.charCodeAt(r)|0;return(e>>>0).toString(36)}function Et(t,e){let r=JSON.stringify(e.schema)+JSON.stringify(e.theme??null),s=`${t.baseUrl}:${t.key}:${e.id}:${bs(r)}`,n=Ke.get(s);return n||(n=t.syncForm(e.id,e.schema,e.theme??null),Ke.set(s,n),n.catch(()=>Ke.delete(s))),n}var _s=/\{\{\s*([\w-]+)\s*\}\}/g;function Ye(t,e,r){if(!t.includes("{{"))return t;let s=ss(r);return t.replace(_s,(n,i)=>{let a=s.find(d=>d.id===i),o=e[i];if(o==null||o==="")return"";let l=d=>a&&"options"in a?a.options.find(f=>f.id===d)?.label??d:d;return Array.isArray(o)?o.map(d=>l(String(d))).join(", "):typeof o=="string"?l(o):String(o)})}function Ft(t,e,r){let s=n=>n===void 0?n:Ye(n,e,r);switch(t.kind){case"heading":case"paragraph":return{...t,text:Ye(t.text,e,r)};case"divider":return t;default:return{...t,label:Ye(t.label,e,r),description:s(t.description)}}}var O="fillo-";function c(t,e={}){let r=document.createElement(t);e.className&&(r.className=e.className),e.text!==void 0&&(r.textContent=e.text);for(let[s,n]of Object.entries(e.attrs??{}))r.setAttribute(s,n);return r}function Ve(t,e){e&&(e.primary&&t.style.setProperty("--fillo-primary",e.primary),e.background&&t.style.setProperty("--fillo-bg",e.background),e.text&&t.style.setProperty("--fillo-text",e.text),e.radius&&t.style.setProperty("--fillo-radius",e.radius),e.fontFamily&&t.style.setProperty("--fillo-font",e.fontFamily))}function xs(t){return typeof t=="string"||typeof t=="number"?String(t):""}function V(t,e){for(let r of e)r&&t.appendChild(r);return t}function q(t,e,r){r&&t.setAttribute("aria-invalid","true"),e.required&&t.setAttribute("aria-required","true");let s=[e.description?`${O}${e.id}-desc`:null,r?`${O}${e.id}-error`:null].filter(Boolean).join(" ");s&&t.setAttribute("aria-describedby",s)}function z(t,e,r){let s=c("div",{className:`fillo-field fillo-field--${t.kind}${e?" fillo-field--error":""}`,attrs:{"data-field":t.id}}),n=c("label",{className:"fillo-label",text:t.label,attrs:{id:`${O}${t.id}-label`,for:`${O}${t.id}`}});return t.required||n.appendChild(c("span",{className:"fillo-optional",text:" (optional)"})),s.appendChild(n),t.description&&s.appendChild(c("p",{className:"fillo-description",text:t.description,attrs:{id:`${O}${t.id}-desc`}})),s.appendChild(r),e&&s.appendChild(c("p",{className:"fillo-error",text:e,attrs:{role:"alert",id:`${O}${t.id}-error`}})),s}function Ne(t,e){let r=c("input",{className:"fillo-input",attrs:{id:`${O}${e.field.id}`,type:t}});return r.value=xs(e.value),e.field.placeholder&&(r.placeholder=e.field.placeholder),r.addEventListener("input",()=>e.setValue(r.value,{render:!1})),r.addEventListener("change",()=>e.setValue(r.value)),q(r,e.field,e.error),z(e.field,e.error,r)}function ks(t){let e=c("textarea",{className:"fillo-input fillo-textarea",attrs:{id:`${O}${t.field.id}`,rows:"4"}});return e.value=typeof t.value=="string"?t.value:"",t.field.placeholder&&(e.placeholder=t.field.placeholder),e.addEventListener("input",()=>t.setValue(e.value,{render:!1})),e.addEventListener("change",()=>t.setValue(e.value)),q(e,t.field,t.error),z(t.field,t.error,e)}function ws(t){let e=t.field,r=it(e),s=typeof t.value=="string"?t.value:"",n=s!==""&&!e.options.some(a=>a.id===s),i=c("div",{className:"fillo-options",attrs:{role:"radiogroup","aria-labelledby":`${O}${e.id}-label`}});q(i,e,t.error);for(let a of r){let o=c("label",{className:`fillo-option${s===a.id?" fillo-option--selected":""}`,attrs:{"data-option":a.id}}),l=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}`}});l.checked=s===a.id,l.addEventListener("change",()=>t.setValue(a.id)),V(o,[l,c("span",{className:"fillo-option-label",text:a.label})]),i.appendChild(o)}if(e.allowOther){let a=c("label",{className:`fillo-option${n?" fillo-option--selected":""}`}),o=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}`}});if(o.checked=n,o.addEventListener("change",()=>t.setValue("",{render:!0})),a.appendChild(o),a.appendChild(c("span",{className:"fillo-option-label",text:"Other"})),n){let l=c("input",{className:"fillo-input fillo-other-input",attrs:{type:"text"}});l.value=s,l.placeholder="Your answer",l.addEventListener("input",()=>t.setValue(l.value,{render:!1})),l.addEventListener("change",()=>t.setValue(l.value)),a.appendChild(l)}i.appendChild(a)}return z(e,t.error,i)}function Cs(t){let e=t.field,r=it(e),s=Array.isArray(t.value)?t.value:[],n=new Set(e.options.map(l=>l.id)),i=s.find(l=>!n.has(l)),a=c("div",{className:"fillo-options",attrs:{role:"group","aria-labelledby":`${O}${e.id}-label`}});q(a,e,t.error);let o=l=>t.setValue(l);for(let l of r){let d=c("label",{className:`fillo-option${s.includes(l.id)?" fillo-option--selected":""}`,attrs:{"data-option":l.id}}),f=c("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});f.checked=s.includes(l.id),f.addEventListener("change",()=>{o(f.checked?[...s,l.id]:s.filter(g=>g!==l.id))}),V(d,[f,c("span",{className:"fillo-option-label",text:l.label})]),a.appendChild(d)}if(e.allowOther){let l=i!==void 0,d=c("label",{className:`fillo-option${l?" fillo-option--selected":""}`}),f=c("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(f.checked=l,f.addEventListener("change",()=>{let g=s.filter(T=>n.has(T));o(f.checked?[...g,i??""]:g)}),V(d,[f,c("span",{className:"fillo-option-label",text:"Other"})]),l){let g=c("input",{className:"fillo-input fillo-other-input",attrs:{type:"text"}});g.value=i??"",g.placeholder="Your answer",g.addEventListener("input",()=>{let T=s.filter(C=>n.has(C));t.setValue(g.value?[...T,g.value]:T,{render:!1})}),g.addEventListener("change",()=>{let T=s.filter(C=>n.has(C));t.setValue(g.value?[...T,g.value]:T)}),d.appendChild(g)}a.appendChild(d)}return z(e,t.error,a)}var rt="__fillo_other__";function Ts(t){let e=t.field,r=typeof t.value=="string"?t.value:"",s=r!==""&&!e.options.some(a=>a.id===r),n=c("div"),i=c("select",{className:"fillo-input fillo-select",attrs:{id:`${O}${e.id}`}});i.appendChild(c("option",{text:e.placeholder??"Choose...",attrs:{value:""}}));for(let a of it(e))i.appendChild(c("option",{text:a.label,attrs:{value:a.id}}));if(e.allowOther&&i.appendChild(c("option",{text:"Other...",attrs:{value:rt}})),i.value=s?rt:r,i.addEventListener("change",()=>{t.setValue(i.value===rt?"":i.value||null)}),q(i,e,t.error),n.appendChild(i),s){let a=c("input",{className:"fillo-input fillo-other-input fillo-other-input--block",attrs:{type:"text"}});a.value=r,a.placeholder="Your answer",a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value)),n.appendChild(a)}return z(e,t.error,n)}function Ns(t){let e=c("div",{className:`fillo-field fillo-field--checkbox${t.error?" fillo-field--error":""}`,attrs:{"data-field":t.field.id}}),r=c("label",{className:"fillo-option"}),s=c("input",{className:"fillo-option-input",attrs:{id:`${O}${t.field.id}`,type:"checkbox"}});s.checked=t.value===!0,s.addEventListener("change",()=>t.setValue(s.checked)),q(s,t.field,t.error);let n=c("span",{className:"fillo-option-label",text:t.field.label});return t.field.required||n.appendChild(c("span",{className:"fillo-optional",text:" (optional)"})),V(r,[s,n]),e.appendChild(r),t.field.description&&e.appendChild(c("p",{className:"fillo-description",text:t.field.description,attrs:{id:`${O}${t.field.id}-desc`}})),t.error&&e.appendChild(c("p",{className:"fillo-error",text:t.error,attrs:{role:"alert",id:`${O}${t.field.id}-error`}})),e}function Ss(t){if(t.field.kind!=="rating")return c("div");let e=typeof t.field.max=="number"?t.field.max:5,r=typeof t.value=="number"?t.value:0,s=c("div",{className:"fillo-rating",attrs:{role:"radiogroup","aria-label":t.field.label}});q(s,t.field,t.error);for(let n=1;n<=e;n++){let i=c("button",{className:`fillo-star${n<=r?" fillo-star--active":""}`,text:"*",attrs:{type:"button","aria-label":`${n} of ${e}`,"aria-pressed":String(n===r)}});i.addEventListener("click",()=>t.setValue(n===r?null:n)),s.appendChild(i)}return z(t.field,t.error,s)}function Es(t){if(t.field.kind!=="linear_scale")return c("div");let e=typeof t.field.min=="number"?t.field.min:1,r=typeof t.field.max=="number"?t.field.max:10,s=c("div"),n=c("div",{className:"fillo-scale",attrs:{role:"radiogroup","aria-label":t.field.label}});q(n,t.field,t.error);for(let i=e;i<=r;i++){let a=c("button",{className:`fillo-scale-step${t.value===i?" fillo-scale-step--active":""}`,text:String(i),attrs:{type:"button","aria-pressed":String(t.value===i)}});a.addEventListener("click",()=>t.setValue(t.value===i?null:i)),n.appendChild(a)}return s.appendChild(n),("minLabel"in t.field||"maxLabel"in t.field)&&V(s,[V(c("div",{className:"fillo-scale-labels"}),[c("span",{text:String(t.field.minLabel??"")}),c("span",{text:String(t.field.maxLabel??"")})])]),z(t.field,t.error,s)}function Fs(t){let e=t.field;if(e.kind!=="ranking")return null;let r=Array.isArray(t.value)?t.value:[],s=[...r.filter(i=>e.options.some(a=>a.id===i)),...e.options.map(i=>i.id).filter(i=>!r.includes(i))],n=c("ol",{className:"fillo-ranking"});for(let[i,a]of s.entries()){let o=e.options.find(C=>C.id===a);if(!o)continue;let l=c("li",{className:"fillo-ranking-item"}),d=c("span",{className:"fillo-ranking-controls"}),f=C=>{let D=i+C;if(D<0||D>=s.length)return;let $=[...s];[$[i],$[D]]=[$[D],$[i]],t.setValue($)},g=c("button",{className:"fillo-ranking-move",text:"Up",attrs:{type:"button"}});g.toggleAttribute("disabled",i===0),g.addEventListener("click",()=>f(-1));let T=c("button",{className:"fillo-ranking-move",text:"Down",attrs:{type:"button"}});T.toggleAttribute("disabled",i===s.length-1),T.addEventListener("click",()=>f(1)),V(d,[g,T]),V(l,[c("span",{className:"fillo-ranking-index",text:String(i+1)}),c("span",{className:"fillo-ranking-label",text:o.label}),d]),n.appendChild(l)}return z(t.field,t.error,n)}function As(t){let e=t.field;if(e.kind!=="matrix")return null;let r=t.value&&typeof t.value=="object"&&!Array.isArray(t.value)?t.value:{},s=c("table",{className:"fillo-matrix"}),n=document.createElement("thead"),i=document.createElement("tr");i.appendChild(document.createElement("th"));for(let o of e.columns)i.appendChild(c("th",{text:o.label,attrs:{scope:"col"}}));n.appendChild(i),s.appendChild(n);let a=document.createElement("tbody");for(let o of e.rows){let l=document.createElement("tr");l.appendChild(c("th",{text:o.label,attrs:{scope:"row"}}));for(let d of e.columns){let f=document.createElement("td"),g=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}-${o.id}`,"aria-label":`${o.label}: ${d.label}`}});g.checked=r[o.id]===d.id,g.addEventListener("change",()=>t.setValue({...r,[o.id]:d.id})),f.appendChild(g),l.appendChild(f)}a.appendChild(l)}return s.appendChild(a),z(t.field,t.error,V(c("div",{className:"fillo-matrix-wrap"}),[s]))}function Os(t){let e=c("div",{className:"fillo-signature"}),r=c("canvas",{className:"fillo-signature-canvas",attrs:{id:`${O}${t.field.id}`}});q(r,t.field,t.error);let s=c("button",{className:"fillo-signature-clear",text:"Clear",attrs:{type:"button"}}),n=c("div",{className:"fillo-signature-hint",text:"Sign here"});r.width=720,r.height=220;let i=r.getContext("2d"),a=!1,o=typeof t.value=="string"&&t.value.startsWith("data:image/");if(o&&i){let f=new Image;f.onload=()=>i.drawImage(f,0,0,r.width,r.height),f.src=String(t.value),n.style.display="none"}let l=f=>{let g=r.getBoundingClientRect();return{x:(f.clientX-g.left)/g.width*r.width,y:(f.clientY-g.top)/g.height*r.height}};r.addEventListener("pointerdown",f=>{if(!i)return;a=!0,o=!0,n.style.display="none",r.setPointerCapture(f.pointerId);let g=l(f);i.beginPath(),i.moveTo(g.x,g.y)}),r.addEventListener("pointermove",f=>{if(!a||!i)return;let g=l(f);i.lineWidth=2.4,i.lineCap="round",i.strokeStyle=getComputedStyle(r).color||"#18181b",i.lineTo(g.x,g.y),i.stroke()});let d=()=>{a&&(a=!1,o&&t.setValue(r.toDataURL("image/png")))};return r.addEventListener("pointerup",d),r.addEventListener("pointercancel",d),s.addEventListener("click",()=>{i?.clearRect(0,0,r.width,r.height),o=!1,n.style.display="",t.setValue(null)}),V(e,[r,n,s]),z(t.field,t.error,e)}function Rs(t){let e=t.field;if(e.kind!=="file_upload")return null;let r=c("input",{className:"fillo-input",attrs:{id:`${O}${e.id}`,type:"file"}});(e.maxFiles??1)>1&&(r.multiple=!0),e.accept?.length&&(r.accept=e.accept.join(",")),q(r,e,t.error),r.addEventListener("change",()=>{let a=Array.from(r.files??[]);t.uploadFiles?.(e,a)});let s=c("div");s.appendChild(r);let n=t.uploadProgress?.get(e.id);if(n!==void 0){let a=c("div",{className:"fillo-upload-progress"});a.appendChild(c("div",{className:"fillo-upload-progress-fill"})),a.firstElementChild?.style.setProperty("width",`${Math.round(n*100)}%`),s.appendChild(a)}let i=Array.isArray(t.value)?t.value:[];for(let a of i)s.appendChild(c("p",{className:"fillo-description",text:`${a.name} (${Math.round(a.size/1024)} KB)`}));return z(e,t.error,s)}var At=new Map;function it(t){if(!t.shuffleOptions)return t.options;let e=`${t.id}|${t.options.map(i=>i.id).join(",")}`,r=At.get(e);if(!r){r=t.options.map(i=>i.id);for(let i=r.length-1;i>0;i--){let a=Math.floor(Math.random()*(i+1));[r[i],r[a]]=[r[a],r[i]]}At.set(e,r)}let s=new Map(t.options.map(i=>[i.id,i])),n=r.flatMap(i=>s.get(i)??[]);return n.length===t.options.length?n:t.options}var Is={short_text:t=>Ne("text",t),email:t=>Ne("email",t),url:t=>Ne("url",t),phone:t=>Ne("tel",t),number:t=>Ne("number",t),date:t=>Ne("date",t),long_text:ks,select:ws,multi_select:Cs,dropdown:Ts,checkbox:Ns,rating:Ss,linear_scale:Es,ranking:Fs,matrix:As,signature:Os,file_upload:Rs};function $s(t){if(t.field.kind==="hidden"||t.field.kind==="custom")return null;let e=Is[t.field.kind];return e?e(t):null}var st=class{constructor(e,r){this.target=e;this.options=r;this.element.className="fillo-dom-root",e.replaceChildren(this.element),this.resolve()}target;options;element=c("div");schema=null;theme;formId;closed=!1;fetchedPoweredBy=null;phase="loading";engine=null;destroyed=!1;renderQueued=!1;hpValue="";uploadProgress=new Map;get status(){return this.phase==="ready"?this.engine?.getState().status??"idle":this.phase}get data(){return this.engine?.getState().data??this.options.initialData??{}}get form(){return this.schema}get mutableData(){return this.engine?.getState().data??this.options.initialData??{}}api(){let e=this.schema??{version:1,title:"",pages:[],settings:{}},r=this.engine?.getState(),s=r?.pageCount??e.pages.length;return{form:e,formId:this.formId,client:this.options.client,data:r?.data??this.mutableData,errors:r?.errors??{},status:this.status,pageIndex:r?.pageIndex??0,pageCount:s,page:r?.page??e.pages[0]??{id:"empty",blocks:[]},blocks:r?.blocks??[],isFirstPage:r?.isFirstPage??!0,isLastPage:r?.isLastPage??s<=1,setValue:(n,i,a)=>this.setValueInternal(n,i,a),next:()=>this.next(),back:()=>this.back(),submit:()=>this.submit()}}async resolve(){try{let e=tt(this.options.form)?this.options.form:null;if(e){this.setSchema(e.schema,this.options.theme??e.theme,this.options.formId),this.options.client?.key&&Et(this.options.client,e).then(({formId:n,branding:i})=>{this.formId=n,this.engine?.setContext({formId:n}),i&&(this.fetchedPoweredBy=i.poweredBy,this.render())}).catch(n=>this.handleError(De(n)));return}let r=this.options.form&&!tt(this.options.form)?this.options.form:null;if(r){this.setSchema(r,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new S("Provide either `form`, or a `formId`.",0);this.options.client??=Oe(),this.render();let s=await this.options.client.getForm(this.options.formId);this.closed=!!s.closed,this.fetchedPoweredBy=s.branding?.poweredBy??null,this.setSchema(s.schema,this.options.theme??s.theme??void 0,s.id)}catch(e){this.handleError(De(e))}}setSchema(e,r,s){this.schema=e,this.theme=r,this.formId=s,this.engine=St({form:e,formId:s,client:this.options.client,initialData:this.options.initialData,onChange:this.options.onChange,onSubmitted:this.options.onSubmitted,getHoneypot:()=>this.hpValue,surface:"default"}),this.phase=this.closed?"closed":"ready",this.render()}setValue(e,r){this.setValueInternal(e,r)}setValueInternal(e,r,s={}){this.engine?.setValue(e,r),s.render!==!1&&this.queueRender()}next(){this.engine&&(this.engine.next(),this.render())}back(){this.engine&&(this.engine.back(),this.render())}async submit(){if(!this.engine||this.phase!=="ready")return;let e=this.engine.submit();this.render();try{await e}catch(r){this.handleError(De(r));return}this.render()}async uploadFiles(e,r){if(!this.schema)return;let s=e.maxFiles??1,n=r.slice(0,s);this.uploadProgress.set(e.id,0),this.queueRender();try{let i=[];for(let[a,o]of n.entries())this.options.client&&this.formId?i.push(await this.options.client.uploadFile(this.formId,o,{fieldId:e.id,onProgress:l=>{this.uploadProgress.set(e.id,(a+l.fraction)/n.length),this.queueRender()}})):i.push({fileId:`local:${o.name}:${o.size}`,name:o.name,size:o.size,mime:o.type||"application/octet-stream"});this.uploadProgress.delete(e.id),this.setValueInternal(e.id,i)}catch(i){this.uploadProgress.delete(e.id),this.handleError(De(i))}}destroy(){this.destroyed=!0,this.target.replaceChildren()}handleError(e){this.phase="error",this.options.onError?.(e),this.render(e)}queueRender(){this.renderQueued||this.destroyed||(this.renderQueued=!0,queueMicrotask(()=>{this.renderQueued=!1,this.render()}))}render(e){if(!this.destroyed){if(this.element.replaceChildren(),this.phase==="loading"){let r=c("div",{className:`fillo-form fillo-form--loading ${this.options.className??""}`,attrs:{"aria-busy":"true"}});Ve(r,this.theme),V(r,[c("div",{className:"fillo-skeleton"}),c("div",{className:"fillo-skeleton"}),c("div",{className:"fillo-skeleton fillo-skeleton--short"})]),this.element.appendChild(r);return}if(this.phase==="error"&&e){this.element.appendChild(this.options.renderError?.(e)??c("div",{className:"fillo-form fillo-form--error",text:e.message}));return}if(this.phase==="closed"){let r=c("div",{className:`fillo-form fillo-form--closed ${this.options.className??""}`});Ve(r,this.theme),r.appendChild(c("p",{className:"fillo-closed",text:"This form is no longer accepting responses."})),this.element.appendChild(r);return}if(this.schema){if(this.engine?.getState().status==="submitted"){let r=this.api(),s=this.options.renderSuccess?.(r)??js(this.schema);Ve(s,this.theme),this.element.appendChild(s),this.brandingVisible()&&this.element.appendChild(Ot());return}!this.options.client&&Ps()&&this.element.appendChild(Ms()),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(Ot())}}}brandingVisible(){return this.options.poweredBy??this.fetchedPoweredBy??!0}renderForm(){let e=this.api(),r=c("form",{className:`fillo-form ${this.options.className??""}`});Ve(r,this.theme),r.noValidate=!0;let s=()=>{e.isLastPage?this.submit():this.next()};if(r.addEventListener("submit",l=>{l.preventDefault(),s()}),e.pageCount>1&&this.schema?.settings.showProgress!==!1){let l=c("div",{className:"fillo-progress-track",attrs:{role:"progressbar","aria-valuemin":"0","aria-valuemax":String(e.pageCount),"aria-valuenow":String(e.pageIndex+1)}});l.appendChild(c("div",{className:"fillo-progress-fill"})),l.firstElementChild?.style.setProperty("width",`${(e.pageIndex+1)/e.pageCount*100}%`),r.appendChild(l)}if(e.pageIndex===0){let l=c("header",{className:"fillo-header"});l.appendChild(c("h1",{className:"fillo-title",text:e.form.title})),e.form.description&&l.appendChild(c("p",{className:"fillo-form-description",text:e.form.description})),r.appendChild(l)}else e.page.title&&r.appendChild(c("h2",{className:"fillo-page-title",text:e.page.title}));let n=c("div",{className:"fillo-blocks"});for(let l of e.blocks){let d=this.renderBlock(Ft(l,this.mutableData,e.form),e);d&&n.appendChild(d)}r.appendChild(n);let i=c("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});i.addEventListener("input",()=>{this.hpValue=i.value}),r.appendChild(i);let a=c("footer",{className:"fillo-footer"});if(e.pageCount>1&&!e.isFirstPage){let l=c("button",{className:"fillo-button fillo-button--ghost",text:"Back",attrs:{type:"button"}});l.addEventListener("click",()=>this.back()),a.appendChild(l)}let o=c("button",{className:"fillo-button fillo-button--primary",text:e.status==="submitting"?"Submitting...":e.isLastPage?e.form.settings.submitLabel??"Submit":"Next",attrs:{type:"submit"}});return o.toggleAttribute("disabled",e.status==="submitting"||this.uploadProgress.size>0),o.addEventListener("click",l=>{l.preventDefault(),s()}),a.appendChild(o),r.appendChild(a),r}renderBlock(e,r){if(!Ae(e))return Ls(e);let s=(a,o)=>this.setValueInternal(e.id,a,o),n={field:e,value:r.data[e.id],error:r.errors[e.id],api:r,setValue:s,uploadFiles:(a,o)=>this.uploadFiles(a,o),uploadProgress:this.uploadProgress};return(e.kind==="custom"?this.options.customComponents?.[e.component]??this.options.components?.custom:this.options.components?.[e.kind]??$s)?.(n)??null}};function Ls(t){switch(t.kind){case"heading":return c("h3",{className:"fillo-heading",text:t.text});case"paragraph":return c("p",{className:"fillo-paragraph",text:t.text});case"divider":return c("hr",{className:"fillo-divider"})}return c("div")}function js(t){let e=c("div",{className:"fillo-form fillo-form--success"}),r=c("div",{className:"fillo-success"});return V(r,[c("div",{className:"fillo-success-mark",text:"\u2713",attrs:{"aria-hidden":"true"}}),c("h2",{className:"fillo-success-title",text:t.settings.successTitle??"Thanks!"}),c("p",{className:"fillo-success-message",text:t.settings.successMessage??"Your response has been recorded."})]),e.appendChild(r),e}function Ot(){return c("a",{className:"fillo-powered",text:"Powered by Fillo",attrs:{href:"https://fillo.so?utm_source=form_badge",target:"_blank",rel:"noopener"}})}function Ps(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Ms(){return c("div",{className:"fillo-devwarning",text:"No Fillo client connected \u2014 this form is render-only and won't save responses. Pass a client to collect them in Fillo, or forward with webhooks. (Shown only in development.)",attrs:{role:"alert"}})}function De(t){return t instanceof S?t:new S(t instanceof Error?t.message:String(t),0)}function Ue(t,e){let r=typeof t=="string"?document.querySelector(t):t;if(!r)throw new S(`Fillo mount target not found: ${String(t)}`,0);return new st(r,{...e,initialData:e.initialData??{}})}function Rt(t){let e=c("div");return Ue(e,t),e}var nt=class extends HTMLElement{instance=null;assignedForm;assignedClient;assignedTheme;assignedInitialData;static get observedAttributes(){return["base-url","publishable-key","form-id"]}connectedCallback(){this.mount()}disconnectedCallback(){this.instance?.destroy(),this.instance=null}attributeChangedCallback(){this.isConnected&&this.mount()}set form(e){this.assignedForm=e,this.isConnected&&this.mount()}get form(){return this.assignedForm}set client(e){this.assignedClient=e,this.isConnected&&this.mount()}set theme(e){this.assignedTheme=e,this.isConnected&&this.mount()}set initialData(e){this.assignedInitialData=e,this.isConnected&&this.mount()}mount(){this.instance?.destroy();let e=this.getAttribute("base-url"),r=this.getAttribute("publishable-key")??void 0,s=this.getAttribute("form-id")??void 0,n=this.assignedClient??(s||r||e?Oe({baseUrl:e??void 0,key:r}):void 0);this.instance=Ue(this,{form:this.assignedForm,client:n,formId:s,theme:this.assignedTheme,initialData:this.assignedInitialData,onChange:i=>this.dispatchEvent(new CustomEvent("fillo-change",{detail:{data:i}})),onSubmitted:(i,a)=>this.dispatchEvent(new CustomEvent("fillo-submit",{detail:{responseId:i,data:a}})),onError:i=>this.dispatchEvent(new CustomEvent("fillo-error",{detail:{error:i}}))})}};function at(t="fillo-form"){customElements.get(t)||customElements.define(t,nt)}at();return Zt(Vs);})();
|
|
1
|
+
"use strict";var Fillo=(()=>{var ze=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ut=Object.prototype.hasOwnProperty;var ct=(t,e)=>{for(var r in e)ze(t,r,{get:e[r],enumerable:!0})},zt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Dt(e))!Ut.call(t,n)&&n!==r&&ze(t,n,{get:()=>e[n],enumerable:!(s=Vt(e,n))||s.enumerable});return t};var Zt=t=>zt(ze({},"__esModule",{value:!0}),t);var Vs={};ct(Vs,{FilloClient:()=>Me,FilloError:()=>S,createClient:()=>Oe,createFormElement:()=>Rt,defineForm:()=>et,registerFilloElement:()=>at,renderForm:()=>Ue});var w={};ct(w,{BRAND:()=>mr,DIRTY:()=>te,EMPTY_PATH:()=>Wt,INVALID:()=>y,NEVER:()=>Gr,OK:()=>A,ParseStatus:()=>F,Schema:()=>_,ZodAny:()=>G,ZodArray:()=>Y,ZodBigInt:()=>se,ZodBoolean:()=>ne,ZodBranded:()=>Ee,ZodCatch:()=>me,ZodDate:()=>ie,ZodDefault:()=>pe,ZodDiscriminatedUnion:()=>$e,ZodEffects:()=>M,ZodEnum:()=>fe,ZodError:()=>R,ZodFirstPartyTypeKind:()=>v,ZodFunction:()=>je,ZodIntersection:()=>de,ZodIssueCode:()=>u,ZodLazy:()=>ce,ZodLiteral:()=>ue,ZodMap:()=>we,ZodNaN:()=>Te,ZodNativeEnum:()=>he,ZodNever:()=>U,ZodNull:()=>oe,ZodNullable:()=>H,ZodNumber:()=>re,ZodObject:()=>I,ZodOptional:()=>j,ZodParsedType:()=>p,ZodPipeline:()=>Fe,ZodPromise:()=>ee,ZodReadonly:()=>ge,ZodRecord:()=>Le,ZodSchema:()=>_,ZodSet:()=>Ce,ZodString:()=>X,ZodSymbol:()=>xe,ZodTransformer:()=>M,ZodTuple:()=>B,ZodType:()=>_,ZodUndefined:()=>ae,ZodUnion:()=>le,ZodUnknown:()=>K,ZodVoid:()=>ke,addIssueToContext:()=>h,any:()=>Cr,array:()=>Er,bigint:()=>br,boolean:()=>xt,coerce:()=>Xr,custom:()=>vt,date:()=>_r,datetimeRegex:()=>gt,defaultErrorMap:()=>W,discriminatedUnion:()=>Rr,effect:()=>Br,enum:()=>Ur,function:()=>Mr,getErrorMap:()=>ve,getParsedType:()=>Z,instanceof:()=>yr,intersection:()=>Ir,isAborted:()=>Re,isAsync:()=>be,isDirty:()=>Ie,isValid:()=>Q,late:()=>gr,lazy:()=>Vr,literal:()=>Dr,makeIssue:()=>Se,map:()=>jr,nan:()=>vr,nativeEnum:()=>zr,never:()=>Nr,null:()=>wr,nullable:()=>qr,number:()=>_t,object:()=>Fr,objectUtil:()=>Ze,oboolean:()=>Qr,onumber:()=>Yr,optional:()=>Hr,ostring:()=>Kr,pipeline:()=>Jr,preprocess:()=>Wr,promise:()=>Zr,quotelessJson:()=>Bt,record:()=>Lr,set:()=>Pr,setErrorMap:()=>qt,strictObject:()=>Ar,string:()=>bt,symbol:()=>xr,transformer:()=>Br,tuple:()=>$r,undefined:()=>kr,union:()=>Or,unknown:()=>Tr,util:()=>k,void:()=>Sr});var k;(function(t){t.assertEqual=n=>{};function e(n){}t.assertIs=e;function r(n){throw new Error}t.assertNever=r,t.arrayToEnum=n=>{let i={};for(let a of n)i[a]=a;return i},t.getValidEnumValues=n=>{let i=t.objectKeys(n).filter(o=>typeof n[n[o]]!="number"),a={};for(let o of i)a[o]=n[o];return t.objectValues(a)},t.objectValues=n=>t.objectKeys(n).map(function(i){return n[i]}),t.objectKeys=typeof Object.keys=="function"?n=>Object.keys(n):n=>{let i=[];for(let a in n)Object.prototype.hasOwnProperty.call(n,a)&&i.push(a);return i},t.find=(n,i)=>{for(let a of n)if(i(a))return a},t.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function s(n,i=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(i)}t.joinValues=s,t.jsonStringifyReplacer=(n,i)=>typeof i=="bigint"?i.toString():i})(k||(k={}));var Ze;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(Ze||(Ze={}));var p=k.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Z=t=>{switch(typeof t){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(t)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(t)?p.array:t===null?p.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?p.promise:typeof Map<"u"&&t instanceof Map?p.map:typeof Set<"u"&&t instanceof Set?p.set:typeof Date<"u"&&t instanceof Date?p.date:p.object;default:return p.unknown}};var u=k.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Bt=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),R=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=s=>{this.issues=[...this.issues,s]},this.addIssues=(s=[])=>{this.issues=[...this.issues,...s]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(i){return i.message},s={_errors:[]},n=i=>{for(let a of i.issues)if(a.code==="invalid_union")a.unionErrors.map(n);else if(a.code==="invalid_return_type")n(a.returnTypeError);else if(a.code==="invalid_arguments")n(a.argumentsError);else if(a.path.length===0)s._errors.push(r(a));else{let o=s,l=0;for(;l<a.path.length;){let d=a.path[l];l===a.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(r(a))):o[d]=o[d]||{_errors:[]},o=o[d],l++}}};return n(this),s}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,k.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},s=[];for(let n of this.issues)if(n.path.length>0){let i=n.path[0];r[i]=r[i]||[],r[i].push(e(n))}else s.push(e(n));return{formErrors:s,fieldErrors:r}}get formErrors(){return this.flatten()}};R.create=t=>new R(t);var Ht=(t,e)=>{let r;switch(t.code){case u.invalid_type:t.received===p.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case u.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,k.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:r=`Unrecognized key(s) in object: ${k.joinValues(t.keys,", ")}`;break;case u.invalid_union:r="Invalid input";break;case u.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${k.joinValues(t.options)}`;break;case u.invalid_enum_value:r=`Invalid enum value. Expected ${k.joinValues(t.options)}, received '${t.received}'`;break;case u.invalid_arguments:r="Invalid function arguments";break;case u.invalid_return_type:r="Invalid function return type";break;case u.invalid_date:r="Invalid date";break;case u.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:k.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case u.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case u.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case u.custom:r="Invalid input";break;case u.invalid_intersection_types:r="Intersection results could not be merged";break;case u.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case u.not_finite:r="Number must be finite";break;default:r=e.defaultError,k.assertNever(t)}return{message:r}},W=Ht;var ut=W;function qt(t){ut=t}function ve(){return ut}var Se=t=>{let{data:e,path:r,errorMaps:s,issueData:n}=t,i=[...r,...n.path||[]],a={...n,path:i};if(n.message!==void 0)return{...n,path:i,message:n.message};let o="",l=s.filter(d=>!!d).slice().reverse();for(let d of l)o=d(a,{data:e,defaultError:o}).message;return{...n,path:i,message:o}},Wt=[];function h(t,e){let r=ve(),s=Se({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===W?void 0:W].filter(n=>!!n)});t.common.issues.push(s)}var F=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let s=[];for(let n of r){if(n.status==="aborted")return y;n.status==="dirty"&&e.dirty(),s.push(n.value)}return{status:e.value,value:s}}static async mergeObjectAsync(e,r){let s=[];for(let n of r){let i=await n.key,a=await n.value;s.push({key:i,value:a})}return t.mergeObjectSync(e,s)}static mergeObjectSync(e,r){let s={};for(let n of r){let{key:i,value:a}=n;if(i.status==="aborted"||a.status==="aborted")return y;i.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(s[i.value]=a.value)}return{status:e.value,value:s}}},y=Object.freeze({status:"aborted"}),te=t=>({status:"dirty",value:t}),A=t=>({status:"valid",value:t}),Re=t=>t.status==="aborted",Ie=t=>t.status==="dirty",Q=t=>t.status==="valid",be=t=>typeof Promise<"u"&&t instanceof Promise;var m;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var P=class{constructor(e,r,s,n){this._cachedPath=[],this.parent=e,this.data=r,this._path=s,this._key=n}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}},ft=(t,e)=>{if(Q(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new R(t.common.issues);return this._error=r,this._error}}};function b(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:s,description:n}=t;if(e&&(r||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(a,o)=>{let{message:l}=t;return a.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:l??s??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:l??r??o.defaultError}},description:n}}var _=class{get description(){return this._def.description}_getType(e){return Z(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new F,ctx:{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(be(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let s=this.safeParse(e,r);if(s.success)return s.data;throw s.error}safeParse(e,r){let s={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},n=this._parseSync({data:e,path:s.path,parent:s});return ft(s,n)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)};if(!this["~standard"].async)try{let s=this._parseSync({data:e,path:[],parent:r});return Q(s)?{value:s.value}:{issues:r.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(s=>Q(s)?{value:s.value}:{issues:r.common.issues})}async parseAsync(e,r){let s=await this.safeParseAsync(e,r);if(s.success)return s.data;throw s.error}async safeParseAsync(e,r){let s={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},n=this._parse({data:e,path:s.path,parent:s}),i=await(be(n)?n:Promise.resolve(n));return ft(s,i)}refine(e,r){let s=n=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(n):r;return this._refinement((n,i)=>{let a=e(n),o=()=>i.addIssue({code:u.custom,...s(n)});return typeof Promise<"u"&&a instanceof Promise?a.then(l=>l?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,r){return this._refinement((s,n)=>e(s)?!0:(n.addIssue(typeof r=="function"?r(s,n):r),!1))}_refinement(e){return new M({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return j.create(this,this._def)}nullable(){return H.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Y.create(this)}promise(){return ee.create(this,this._def)}or(e){return le.create([this,e],this._def)}and(e){return de.create(this,e,this._def)}transform(e){return new M({...b(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new pe({...b(this._def),innerType:this,defaultValue:r,typeName:v.ZodDefault})}brand(){return new Ee({typeName:v.ZodBranded,type:this,...b(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new me({...b(this._def),innerType:this,catchValue:r,typeName:v.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return Fe.create(this,e)}readonly(){return ge.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Jt=/^c[^\s-]{8,}$/i,Kt=/^[0-9a-z]+$/,Yt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Qt=/^[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,Xt=/^[a-z0-9_-]{21}$/i,Gt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,er=/^[-+]?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)?)??$/,tr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,rr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Be,sr=/^(?:(?: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])$/,nr=/^(?:(?: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])$/,ir=/^(([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]))$/,ar=/^(([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])$/,or=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,lr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,pt="((\\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])))",dr=new RegExp(`^${pt}$`);function mt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function cr(t){return new RegExp(`^${mt(t)}$`)}function gt(t){let e=`${pt}T${mt(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function ur(t,e){return!!((e==="v4"||!e)&&sr.test(t)||(e==="v6"||!e)&&ir.test(t))}function fr(t,e){if(!Gt.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),n=JSON.parse(atob(s));return!(typeof n!="object"||n===null||"typ"in n&&n?.typ!=="JWT"||!n.alg||e&&n.alg!==e)}catch{return!1}}function hr(t,e){return!!((e==="v4"||!e)&&nr.test(t)||(e==="v6"||!e)&&ar.test(t))}var X=class t extends _{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.string,received:i.parsedType}),y}let s=new F,n;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),s.dirty());else if(i.kind==="max")e.data.length>i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),s.dirty());else if(i.kind==="length"){let a=e.data.length>i.value,o=e.data.length<i.value;(a||o)&&(n=this._getOrReturnCtx(e,n),a?h(n,{code:u.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):o&&h(n,{code:u.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),s.dirty())}else if(i.kind==="email")tr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"email",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="emoji")Be||(Be=new RegExp(rr,"u")),Be.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"emoji",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="uuid")Qt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"uuid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="nanoid")Xt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"nanoid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="cuid")Jt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cuid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="cuid2")Kt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cuid2",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="ulid")Yt.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"ulid",code:u.invalid_string,message:i.message}),s.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),h(n,{validation:"url",code:u.invalid_string,message:i.message}),s.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"regex",code:u.invalid_string,message:i.message}),s.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),s.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{startsWith:i.value},message:i.message}),s.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:{endsWith:i.value},message:i.message}),s.dirty()):i.kind==="datetime"?gt(i).test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"datetime",message:i.message}),s.dirty()):i.kind==="date"?dr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"date",message:i.message}),s.dirty()):i.kind==="time"?cr(i).test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{code:u.invalid_string,validation:"time",message:i.message}),s.dirty()):i.kind==="duration"?er.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"duration",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="ip"?ur(e.data,i.version)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"ip",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="jwt"?fr(e.data,i.alg)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"jwt",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="cidr"?hr(e.data,i.version)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"cidr",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="base64"?or.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"base64",code:u.invalid_string,message:i.message}),s.dirty()):i.kind==="base64url"?lr.test(e.data)||(n=this._getOrReturnCtx(e,n),h(n,{validation:"base64url",code:u.invalid_string,message:i.message}),s.dirty()):k.assertNever(i);return{status:s.value,value:e.data}}_regex(e,r,s){return this.refinement(n=>e.test(n),{validation:r,code:u.invalid_string,...m.errToObj(s)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.errToObj(e)})}datetime(e){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,...m.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...m.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...m.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...m.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...m.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...m.errToObj(r)})}nonempty(e){return this.min(1,m.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(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};X.create=t=>new X({checks:[],typeName:v.ZodString,coerce:t?.coerce??!1,...b(t)});function pr(t,e){let r=(t.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,n=r>s?r:s,i=Number.parseInt(t.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return i%a/10**n}var re=class t extends _{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)!==p.number){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.number,received:i.parsedType}),y}let s,n=new F;for(let i of this._def.checks)i.kind==="int"?k.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:u.invalid_type,expected:"integer",received:"float",message:i.message}),n.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),n.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),n.dirty()):i.kind==="multipleOf"?pr(e.data,i.value)!==0&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),n.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_finite,message:i.message}),n.dirty()):k.assertNever(i);return{status:n.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,s,n){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.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,r=null;for(let s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(r===null||s.value>r)&&(r=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(r)&&Number.isFinite(e)}};re.create=t=>new re({checks:[],typeName:v.ZodNumber,coerce:t?.coerce||!1,...b(t)});var se=class t extends _{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)!==p.bigint)return this._getInvalidInput(e);let s,n=new F;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),n.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),n.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(s=this._getOrReturnCtx(e,s),h(s,{code:u.not_multiple_of,multipleOf:i.value,message:i.message}),n.dirty()):k.assertNever(i);return{status:n.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return h(r,{code:u.invalid_type,expected:p.bigint,received:r.parsedType}),y}gte(e,r){return this.setLimit("min",e,!0,m.toString(r))}gt(e,r){return this.setLimit("min",e,!1,m.toString(r))}lte(e,r){return this.setLimit("max",e,!0,m.toString(r))}lt(e,r){return this.setLimit("max",e,!1,m.toString(r))}setLimit(e,r,s,n){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};se.create=t=>new se({checks:[],typeName:v.ZodBigInt,coerce:t?.coerce??!1,...b(t)});var ne=class extends _{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.boolean,received:s.parsedType}),y}return A(e.data)}};ne.create=t=>new ne({typeName:v.ZodBoolean,coerce:t?.coerce||!1,...b(t)});var ie=class t extends _{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_type,expected:p.date,received:i.parsedType}),y}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return h(i,{code:u.invalid_date}),y}let s=new F,n;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),s.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(n=this._getOrReturnCtx(e,n),h(n,{code:u.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),s.dirty()):k.assertNever(i);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};ie.create=t=>new ie({checks:[],coerce:t?.coerce||!1,typeName:v.ZodDate,...b(t)});var xe=class extends _{_parse(e){if(this._getType(e)!==p.symbol){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.symbol,received:s.parsedType}),y}return A(e.data)}};xe.create=t=>new xe({typeName:v.ZodSymbol,...b(t)});var ae=class extends _{_parse(e){if(this._getType(e)!==p.undefined){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.undefined,received:s.parsedType}),y}return A(e.data)}};ae.create=t=>new ae({typeName:v.ZodUndefined,...b(t)});var oe=class extends _{_parse(e){if(this._getType(e)!==p.null){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.null,received:s.parsedType}),y}return A(e.data)}};oe.create=t=>new oe({typeName:v.ZodNull,...b(t)});var G=class extends _{constructor(){super(...arguments),this._any=!0}_parse(e){return A(e.data)}};G.create=t=>new G({typeName:v.ZodAny,...b(t)});var K=class extends _{constructor(){super(...arguments),this._unknown=!0}_parse(e){return A(e.data)}};K.create=t=>new K({typeName:v.ZodUnknown,...b(t)});var U=class extends _{_parse(e){let r=this._getOrReturnCtx(e);return h(r,{code:u.invalid_type,expected:p.never,received:r.parsedType}),y}};U.create=t=>new U({typeName:v.ZodNever,...b(t)});var ke=class extends _{_parse(e){if(this._getType(e)!==p.undefined){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.void,received:s.parsedType}),y}return A(e.data)}};ke.create=t=>new ke({typeName:v.ZodVoid,...b(t)});var Y=class t extends _{_parse(e){let{ctx:r,status:s}=this._processInputParams(e),n=this._def;if(r.parsedType!==p.array)return h(r,{code:u.invalid_type,expected:p.array,received:r.parsedType}),y;if(n.exactLength!==null){let a=r.data.length>n.exactLength.value,o=r.data.length<n.exactLength.value;(a||o)&&(h(r,{code:a?u.too_big:u.too_small,minimum:o?n.exactLength.value:void 0,maximum:a?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),s.dirty())}if(n.minLength!==null&&r.data.length<n.minLength.value&&(h(r,{code:u.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),s.dirty()),n.maxLength!==null&&r.data.length>n.maxLength.value&&(h(r,{code:u.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),s.dirty()),r.common.async)return Promise.all([...r.data].map((a,o)=>n.type._parseAsync(new P(r,a,r.path,o)))).then(a=>F.mergeArray(s,a));let i=[...r.data].map((a,o)=>n.type._parseSync(new P(r,a,r.path,o)));return F.mergeArray(s,i)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:m.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:m.toString(r)}})}nonempty(e){return this.min(1,e)}};Y.create=(t,e)=>new Y({type:t,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,...b(e)});function _e(t){if(t instanceof I){let e={};for(let r in t.shape){let s=t.shape[r];e[r]=j.create(_e(s))}return new I({...t._def,shape:()=>e})}else return t instanceof Y?new Y({...t._def,type:_e(t.element)}):t instanceof j?j.create(_e(t.unwrap())):t instanceof H?H.create(_e(t.unwrap())):t instanceof B?B.create(t.items.map(e=>_e(e))):t}var I=class t extends _{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=k.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==p.object){let d=this._getOrReturnCtx(e);return h(d,{code:u.invalid_type,expected:p.object,received:d.parsedType}),y}let{status:s,ctx:n}=this._processInputParams(e),{shape:i,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof U&&this._def.unknownKeys==="strip"))for(let d in n.data)a.includes(d)||o.push(d);let l=[];for(let d of a){let f=i[d],g=n.data[d];l.push({key:{status:"valid",value:d},value:f._parse(new P(n,g,n.path,d)),alwaysSet:d in n.data})}if(this._def.catchall instanceof U){let d=this._def.unknownKeys;if(d==="passthrough")for(let f of o)l.push({key:{status:"valid",value:f},value:{status:"valid",value:n.data[f]}});else if(d==="strict")o.length>0&&(h(n,{code:u.unrecognized_keys,keys:o}),s.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let d=this._def.catchall;for(let f of o){let g=n.data[f];l.push({key:{status:"valid",value:f},value:d._parse(new P(n,g,n.path,f)),alwaysSet:f in n.data})}}return n.common.async?Promise.resolve().then(async()=>{let d=[];for(let f of l){let g=await f.key,T=await f.value;d.push({key:g,value:T,alwaysSet:f.alwaysSet})}return d}).then(d=>F.mergeObjectSync(s,d)):F.mergeObjectSync(s,l)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,s)=>{let n=this._def.errorMap?.(r,s).message??s.defaultError;return r.code==="unrecognized_keys"?{message:m.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let s of k.objectKeys(e))e[s]&&this.shape[s]&&(r[s]=this.shape[s]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let s of k.objectKeys(this.shape))e[s]||(r[s]=this.shape[s]);return new t({...this._def,shape:()=>r})}deepPartial(){return _e(this)}partial(e){let r={};for(let s of k.objectKeys(this.shape)){let n=this.shape[s];e&&!e[s]?r[s]=n:r[s]=n.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let s of k.objectKeys(this.shape))if(e&&!e[s])r[s]=this.shape[s];else{let i=this.shape[s];for(;i instanceof j;)i=i._def.innerType;r[s]=i}return new t({...this._def,shape:()=>r})}keyof(){return yt(k.objectKeys(this.shape))}};I.create=(t,e)=>new I({shape:()=>t,unknownKeys:"strip",catchall:U.create(),typeName:v.ZodObject,...b(e)});I.strictCreate=(t,e)=>new I({shape:()=>t,unknownKeys:"strict",catchall:U.create(),typeName:v.ZodObject,...b(e)});I.lazycreate=(t,e)=>new I({shape:t,unknownKeys:"strip",catchall:U.create(),typeName:v.ZodObject,...b(e)});var le=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=this._def.options;function n(i){for(let o of i)if(o.result.status==="valid")return o.result;for(let o of i)if(o.result.status==="dirty")return r.common.issues.push(...o.ctx.common.issues),o.result;let a=i.map(o=>new R(o.ctx.common.issues));return h(r,{code:u.invalid_union,unionErrors:a}),y}if(r.common.async)return Promise.all(s.map(async i=>{let a={...r,common:{...r.common,issues:[]},parent:null};return{result:await i._parseAsync({data:r.data,path:r.path,parent:a}),ctx:a}})).then(n);{let i,a=[];for(let l of s){let d={...r,common:{...r.common,issues:[]},parent:null},f=l._parseSync({data:r.data,path:r.path,parent:d});if(f.status==="valid")return f;f.status==="dirty"&&!i&&(i={result:f,ctx:d}),d.common.issues.length&&a.push(d.common.issues)}if(i)return r.common.issues.push(...i.ctx.common.issues),i.result;let o=a.map(l=>new R(l));return h(r,{code:u.invalid_union,unionErrors:o}),y}}get options(){return this._def.options}};le.create=(t,e)=>new le({options:t,typeName:v.ZodUnion,...b(e)});var J=t=>t instanceof ce?J(t.schema):t instanceof M?J(t.innerType()):t instanceof ue?[t.value]:t instanceof fe?t.options:t instanceof he?k.objectValues(t.enum):t instanceof pe?J(t._def.innerType):t instanceof ae?[void 0]:t instanceof oe?[null]:t instanceof j?[void 0,...J(t.unwrap())]:t instanceof H?[null,...J(t.unwrap())]:t instanceof Ee||t instanceof ge?J(t.unwrap()):t instanceof me?J(t._def.innerType):[],$e=class t extends _{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.object)return h(r,{code:u.invalid_type,expected:p.object,received:r.parsedType}),y;let s=this.discriminator,n=r.data[s],i=this.optionsMap.get(n);return i?r.common.async?i._parseAsync({data:r.data,path:r.path,parent:r}):i._parseSync({data:r.data,path:r.path,parent:r}):(h(r,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),y)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,s){let n=new Map;for(let i of r){let a=J(i.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let o of a){if(n.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);n.set(o,i)}}return new t({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:n,...b(s)})}};function He(t,e){let r=Z(t),s=Z(e);if(t===e)return{valid:!0,data:t};if(r===p.object&&s===p.object){let n=k.objectKeys(e),i=k.objectKeys(t).filter(o=>n.indexOf(o)!==-1),a={...t,...e};for(let o of i){let l=He(t[o],e[o]);if(!l.valid)return{valid:!1};a[o]=l.data}return{valid:!0,data:a}}else if(r===p.array&&s===p.array){if(t.length!==e.length)return{valid:!1};let n=[];for(let i=0;i<t.length;i++){let a=t[i],o=e[i],l=He(a,o);if(!l.valid)return{valid:!1};n.push(l.data)}return{valid:!0,data:n}}else return r===p.date&&s===p.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var de=class extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e),n=(i,a)=>{if(Re(i)||Re(a))return y;let o=He(i.value,a.value);return o.valid?((Ie(i)||Ie(a))&&r.dirty(),{status:r.value,value:o.data}):(h(s,{code:u.invalid_intersection_types}),y)};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(([i,a])=>n(i,a)):n(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}};de.create=(t,e,r)=>new de({left:t,right:e,typeName:v.ZodIntersection,...b(r)});var B=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.array)return h(s,{code:u.invalid_type,expected:p.array,received:s.parsedType}),y;if(s.data.length<this._def.items.length)return h(s,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),y;!this._def.rest&&s.data.length>this._def.items.length&&(h(s,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let i=[...s.data].map((a,o)=>{let l=this._def.items[o]||this._def.rest;return l?l._parse(new P(s,a,s.path,o)):null}).filter(a=>!!a);return s.common.async?Promise.all(i).then(a=>F.mergeArray(r,a)):F.mergeArray(r,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};B.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new B({items:t,typeName:v.ZodTuple,rest:null,...b(e)})};var Le=class t extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.object)return h(s,{code:u.invalid_type,expected:p.object,received:s.parsedType}),y;let n=[],i=this._def.keyType,a=this._def.valueType;for(let o in s.data)n.push({key:i._parse(new P(s,o,s.path,o)),value:a._parse(new P(s,s.data[o],s.path,o)),alwaysSet:o in s.data});return s.common.async?F.mergeObjectAsync(r,n):F.mergeObjectSync(r,n)}get element(){return this._def.valueType}static create(e,r,s){return r instanceof _?new t({keyType:e,valueType:r,typeName:v.ZodRecord,...b(s)}):new t({keyType:X.create(),valueType:e,typeName:v.ZodRecord,...b(r)})}},we=class extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.map)return h(s,{code:u.invalid_type,expected:p.map,received:s.parsedType}),y;let n=this._def.keyType,i=this._def.valueType,a=[...s.data.entries()].map(([o,l],d)=>({key:n._parse(new P(s,o,s.path,[d,"key"])),value:i._parse(new P(s,l,s.path,[d,"value"]))}));if(s.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let l of a){let d=await l.key,f=await l.value;if(d.status==="aborted"||f.status==="aborted")return y;(d.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(d.value,f.value)}return{status:r.value,value:o}})}else{let o=new Map;for(let l of a){let d=l.key,f=l.value;if(d.status==="aborted"||f.status==="aborted")return y;(d.status==="dirty"||f.status==="dirty")&&r.dirty(),o.set(d.value,f.value)}return{status:r.value,value:o}}}};we.create=(t,e,r)=>new we({valueType:e,keyType:t,typeName:v.ZodMap,...b(r)});var Ce=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.parsedType!==p.set)return h(s,{code:u.invalid_type,expected:p.set,received:s.parsedType}),y;let n=this._def;n.minSize!==null&&s.data.size<n.minSize.value&&(h(s,{code:u.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),r.dirty()),n.maxSize!==null&&s.data.size>n.maxSize.value&&(h(s,{code:u.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),r.dirty());let i=this._def.valueType;function a(l){let d=new Set;for(let f of l){if(f.status==="aborted")return y;f.status==="dirty"&&r.dirty(),d.add(f.value)}return{status:r.value,value:d}}let o=[...s.data.values()].map((l,d)=>i._parse(new P(s,l,s.path,d)));return s.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,r){return new t({...this._def,minSize:{value:e,message:m.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:m.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Ce.create=(t,e)=>new Ce({valueType:t,minSize:null,maxSize:null,typeName:v.ZodSet,...b(e)});var je=class t extends _{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.function)return h(r,{code:u.invalid_type,expected:p.function,received:r.parsedType}),y;function s(o,l){return Se({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),W].filter(d=>!!d),issueData:{code:u.invalid_arguments,argumentsError:l}})}function n(o,l){return Se({data:o,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,ve(),W].filter(d=>!!d),issueData:{code:u.invalid_return_type,returnTypeError:l}})}let i={errorMap:r.common.contextualErrorMap},a=r.data;if(this._def.returns instanceof ee){let o=this;return A(async function(...l){let d=new R([]),f=await o._def.args.parseAsync(l,i).catch(C=>{throw d.addIssue(s(l,C)),d}),g=await Reflect.apply(a,this,f);return await o._def.returns._def.type.parseAsync(g,i).catch(C=>{throw d.addIssue(n(g,C)),d})})}else{let o=this;return A(function(...l){let d=o._def.args.safeParse(l,i);if(!d.success)throw new R([s(l,d.error)]);let f=Reflect.apply(a,this,d.data),g=o._def.returns.safeParse(f,i);if(!g.success)throw new R([n(f,g.error)]);return g.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:B.create(e).rest(K.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,s){return new t({args:e||B.create([]).rest(K.create()),returns:r||K.create(),typeName:v.ZodFunction,...b(s)})}},ce=class extends _{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};ce.create=(t,e)=>new ce({getter:t,typeName:v.ZodLazy,...b(e)});var ue=class extends _{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return h(r,{received:r.data,code:u.invalid_literal,expected:this._def.value}),y}return{status:"valid",value:e.data}}get value(){return this._def.value}};ue.create=(t,e)=>new ue({value:t,typeName:v.ZodLiteral,...b(e)});function yt(t,e){return new fe({values:t,typeName:v.ZodEnum,...b(e)})}var fe=class t extends _{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),s=this._def.values;return h(r,{expected:k.joinValues(s),received:r.parsedType,code:u.invalid_type}),y}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),s=this._def.values;return h(r,{received:r.data,code:u.invalid_enum_value,options:s}),y}return A(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(s=>!e.includes(s)),{...this._def,...r})}};fe.create=yt;var he=class extends _{_parse(e){let r=k.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==p.string&&s.parsedType!==p.number){let n=k.objectValues(r);return h(s,{expected:k.joinValues(n),received:s.parsedType,code:u.invalid_type}),y}if(this._cache||(this._cache=new Set(k.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let n=k.objectValues(r);return h(s,{received:s.data,code:u.invalid_enum_value,options:n}),y}return A(e.data)}get enum(){return this._def.values}};he.create=(t,e)=>new he({values:t,typeName:v.ZodNativeEnum,...b(e)});var ee=class extends _{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.promise&&r.common.async===!1)return h(r,{code:u.invalid_type,expected:p.promise,received:r.parsedType}),y;let s=r.parsedType===p.promise?r.data:Promise.resolve(r.data);return A(s.then(n=>this._def.type.parseAsync(n,{path:r.path,errorMap:r.common.contextualErrorMap})))}};ee.create=(t,e)=>new ee({type:t,typeName:v.ZodPromise,...b(e)});var M=class extends _{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:s}=this._processInputParams(e),n=this._def.effect||null,i={addIssue:a=>{h(s,a),a.fatal?r.abort():r.dirty()},get path(){return s.path}};if(i.addIssue=i.addIssue.bind(i),n.type==="preprocess"){let a=n.transform(s.data,i);if(s.common.async)return Promise.resolve(a).then(async o=>{if(r.value==="aborted")return y;let l=await this._def.schema._parseAsync({data:o,path:s.path,parent:s});return l.status==="aborted"?y:l.status==="dirty"?te(l.value):r.value==="dirty"?te(l.value):l});{if(r.value==="aborted")return y;let o=this._def.schema._parseSync({data:a,path:s.path,parent:s});return o.status==="aborted"?y:o.status==="dirty"?te(o.value):r.value==="dirty"?te(o.value):o}}if(n.type==="refinement"){let a=o=>{let l=n.refinement(o,i);if(s.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(s.common.async===!1){let o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return o.status==="aborted"?y:(o.status==="dirty"&&r.dirty(),a(o.value),{status:r.value,value:o.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>o.status==="aborted"?y:(o.status==="dirty"&&r.dirty(),a(o.value).then(()=>({status:r.value,value:o.value}))))}if(n.type==="transform")if(s.common.async===!1){let a=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!Q(a))return y;let o=n.transform(a.value,i);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:o}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(a=>Q(a)?Promise.resolve(n.transform(a.value,i)).then(o=>({status:r.value,value:o})):y);k.assertNever(n)}};M.create=(t,e,r)=>new M({schema:t,typeName:v.ZodEffects,effect:e,...b(r)});M.createWithPreprocess=(t,e,r)=>new M({schema:e,effect:{type:"preprocess",transform:t},typeName:v.ZodEffects,...b(r)});var j=class extends _{_parse(e){return this._getType(e)===p.undefined?A(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};j.create=(t,e)=>new j({innerType:t,typeName:v.ZodOptional,...b(e)});var H=class extends _{_parse(e){return this._getType(e)===p.null?A(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};H.create=(t,e)=>new H({innerType:t,typeName:v.ZodNullable,...b(e)});var pe=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=r.data;return r.parsedType===p.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};pe.create=(t,e)=>new pe({innerType:t,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...b(e)});var me=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s={...r,common:{...r.common,issues:[]}},n=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return be(n)?n.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new R(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}};me.create=(t,e)=>new me({innerType:t,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...b(e)});var Te=class extends _{_parse(e){if(this._getType(e)!==p.nan){let s=this._getOrReturnCtx(e);return h(s,{code:u.invalid_type,expected:p.nan,received:s.parsedType}),y}return{status:"valid",value:e.data}}};Te.create=t=>new Te({typeName:v.ZodNaN,...b(t)});var mr=Symbol("zod_brand"),Ee=class extends _{_parse(e){let{ctx:r}=this._processInputParams(e),s=r.data;return this._def.type._parse({data:s,path:r.path,parent:r})}unwrap(){return this._def.type}},Fe=class t extends _{_parse(e){let{status:r,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return i.status==="aborted"?y:i.status==="dirty"?(r.dirty(),te(i.value)):this._def.out._parseAsync({data:i.value,path:s.path,parent:s})})();{let n=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return n.status==="aborted"?y:n.status==="dirty"?(r.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:s.path,parent:s})}}static create(e,r){return new t({in:e,out:r,typeName:v.ZodPipeline})}},ge=class extends _{_parse(e){let r=this._def.innerType._parse(e),s=n=>(Q(n)&&(n.value=Object.freeze(n.value)),n);return be(r)?r.then(n=>s(n)):s(r)}unwrap(){return this._def.innerType}};ge.create=(t,e)=>new ge({innerType:t,typeName:v.ZodReadonly,...b(e)});function ht(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function vt(t,e={},r){return t?G.create().superRefine((s,n)=>{let i=t(s);if(i instanceof Promise)return i.then(a=>{if(!a){let o=ht(e,s),l=o.fatal??r??!0;n.addIssue({code:"custom",...o,fatal:l})}});if(!i){let a=ht(e,s),o=a.fatal??r??!0;n.addIssue({code:"custom",...a,fatal:o})}}):G.create()}var gr={object:I.lazycreate},v;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(v||(v={}));var yr=(t,e={message:`Input not instance of ${t.name}`})=>vt(r=>r instanceof t,e),bt=X.create,_t=re.create,vr=Te.create,br=se.create,xt=ne.create,_r=ie.create,xr=xe.create,kr=ae.create,wr=oe.create,Cr=G.create,Tr=K.create,Nr=U.create,Sr=ke.create,Er=Y.create,Fr=I.create,Ar=I.strictCreate,Or=le.create,Rr=$e.create,Ir=de.create,$r=B.create,Lr=Le.create,jr=we.create,Pr=Ce.create,Mr=je.create,Vr=ce.create,Dr=ue.create,Ur=fe.create,zr=he.create,Zr=ee.create,Br=M.create,Hr=j.create,qr=H.create,Wr=M.createWithPreprocess,Jr=Fe.create,Kr=()=>bt().optional(),Yr=()=>_t().optional(),Qr=()=>xt().optional(),Xr={string:(t=>X.create({...t,coerce:!0})),number:(t=>re.create({...t,coerce:!0})),boolean:(t=>ne.create({...t,coerce:!0})),bigint:(t=>se.create({...t,coerce:!0})),date:(t=>ie.create({...t,coerce:!0}))};var Gr=y;var es=["heading","paragraph","divider"];function Ae(t){return!es.includes(t.kind)}function kt(t){return t==null?!1:typeof t=="string"?t.trim()!=="":Array.isArray(t)?t.length>0:typeof t=="boolean"?t:typeof t=="object"?Object.keys(t).length>0:!0}function ts(t,e){let r=e[t.fieldId];switch(t.op){case"answered":return kt(r);case"not_answered":return!kt(r);case"eq":return Array.isArray(r)?r.some(s=>s===t.value):r===t.value;case"neq":return Array.isArray(r)?!r.some(s=>s===t.value):r!==t.value;case"contains":return typeof r=="string"?r.toLowerCase().includes(String(t.value??"").toLowerCase()):Array.isArray(r)?r.some(s=>s===t.value):!1;case"gt":return typeof r=="number"&&r>Number(t.value);case"lt":return typeof r=="number"&&r<Number(t.value)}}function rs(t,e){return!t.visibleIf||t.visibleIf.length===0?!0:t.visibleIf.every(r=>ts(r,e))}function Qe(t,e){return t.blocks.filter(r=>rs(r,e))}function ss(t){return t.pages.flatMap(e=>e.blocks.filter(Ae))}function ns(t,e){return t.pages.flatMap(r=>Qe(r,e).filter(Ae))}var is=w.object({fileId:w.string().min(1),name:w.string(),size:w.number().nonnegative(),mime:w.string(),url:w.string().optional()});function Ct(t){return t==null?!0:typeof t=="string"?t.trim()==="":Array.isArray(t)?t.length===0:typeof t=="boolean"?t===!1:typeof t=="object"?Object.keys(t).length===0:!1}function Tt(t,e){if(Ct(e))return t.required?"This field is required":null;switch(t.kind){case"short_text":case"long_text":{if(typeof e!="string")return"Expected text";if(t.maxLength&&e.length>t.maxLength)return`Must be at most ${t.maxLength} characters`;let r=t.kind==="long_text"?2e4:2e3;return!t.maxLength&&e.length>r?"Answer is too long":null}case"email":return w.string().email().safeParse(e).success?null:"Enter a valid email address";case"url":{if(typeof e!="string")return"Enter a valid URL (including https://)";try{let r=new URL(e);if(r.protocol!=="http:"&&r.protocol!=="https:")return"Enter an http(s) URL"}catch{return"Enter a valid URL (including https://)"}return null}case"phone":return typeof e!="string"||!/^[+\d][\d\s\-().]{4,}$/.test(e)?"Enter a valid phone number":null;case"number":{let r=typeof e=="string"?Number(e):e;return typeof r!="number"||Number.isNaN(r)?"Enter a number":t.min!==void 0&&r<t.min?`Must be at least ${t.min}`:t.max!==void 0&&r>t.max?`Must be at most ${t.max}`:null}case"select":case"dropdown":return typeof e!="string"||e===""?"Pick an option":t.options.some(r=>r.id===e)||t.allowOther&&e.length<=500?null:"Pick a valid option";case"multi_select":{if(!Array.isArray(e))return"Pick at least one option";let r=new Set(t.options.map(i=>i.id)),s=e,n=0;for(let i of s)if(!r.has(i)){if(t.allowOther!==!0||typeof i!="string"||i.length===0||i.length>500)return"Pick valid options";if(++n>1)return"Only one 'Other' answer is allowed"}return null}case"checkbox":return typeof e=="boolean"?null:"Invalid value";case"rating":{let r=t.max??5,s=typeof e=="string"?Number(e):e;return typeof s!="number"||!Number.isInteger(s)||s<1||s>r?`Pick a rating between 1 and ${r}`:null}case"linear_scale":{let r=t.min??1,s=t.max??10,n=typeof e=="string"?Number(e):e;return typeof n!="number"||!Number.isInteger(n)||n<r||n>s?`Pick a value between ${r} and ${s}`:null}case"ranking":{if(!Array.isArray(e))return"Drag the options into order";let r=t.options.map(n=>n.id).sort(),s=[...e].sort();return r.length!==s.length||r.some((n,i)=>n!==s[i])?"Rank every option":null}case"matrix":{if(typeof e!="object"||e===null||Array.isArray(e))return"Answer the grid";let r=e,s=new Set(t.columns.map(i=>i.id)),n=new Set(t.rows.map(i=>i.id));for(let[i,a]of Object.entries(r))if(!n.has(i)||!s.has(a))return"Invalid grid answer";return t.required&&Object.keys(r).length<t.rows.length?"Answer every row":null}case"signature":return typeof e!="string"||!e.startsWith("data:image/")?"Sign in the box":null;case"hidden":return typeof e=="string"?null:"Invalid value";case"custom":return null;case"date":return typeof e!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(e)?"Enter a valid date":null;case"file_upload":{let r=w.array(is).safeParse(e);if(!r.success)return"Upload did not complete";let s=t.maxFiles??1;return r.data.length>s?`At most ${s} file${s===1?"":"s"}`:null}}}function as(t,e){let r=ns(t,e),s={},n={};for(let i of r){let a=os(i,e[i.id]),o=Tt(i,a);o?s[i.id]=o:Ct(a)||(n[i.id]=a)}return{ok:Object.keys(s).length===0,errors:s,data:n}}function os(t,e){if(e==null)return e;if(t.kind==="number"&&typeof e=="string"&&e.trim()!==""){let r=Number(e);return Number.isNaN(r)?e:r}if(t.kind==="rating"&&typeof e=="string"){let r=Number(e);return Number.isNaN(r)?e:r}return typeof e=="string"?e.trim():e}var ls=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","custom"],ds=["heading","paragraph","divider"],cs=[...ls,...ds],Xe=w.string().min(1).max(128),qe=w.object({id:Xe,label:w.string().max(1e3)}).passthrough(),us=w.object({id:Xe,kind:w.enum(cs),label:w.string().max(2e3).optional(),options:w.array(qe).max(200).optional(),rows:w.array(qe).max(200).optional(),columns:w.array(qe).max(200).optional()}).passthrough(),fs=w.object({id:Xe,title:w.string().max(500).optional(),blocks:w.array(us).max(500)}),gn=w.object({version:w.literal(1),title:w.string().max(2e3).optional().default(""),description:w.string().max(5e3).optional(),pages:w.array(fs).min(1).max(50),settings:w.record(w.unknown()).optional().default({})});var hs="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",yn=256-256%hs.length;var Nt=class{h0=1732584193;h1=4023233417;h2=2562383102;h3=271733878;h4=3285377520;block=new Uint8Array(64);blockLen=0;totalLen=0;w=new Int32Array(80);update(t){this.totalLen+=t.length;let e=0;if(this.blockLen>0){for(;e<t.length&&this.blockLen<64;)this.block[this.blockLen++]=t[e++];this.blockLen===64&&(this.process(this.block),this.blockLen=0)}for(;e+64<=t.length;)this.process(t.subarray(e,e+64)),e+=64;for(;e<t.length;)this.block[this.blockLen++]=t[e++];return this}digest(){let t=Math.floor(this.totalLen/536870912),e=this.totalLen*8>>>0,r=[128],s=this.blockLen+1;for(;s%64!==56;)r.push(0),s++;r.push(t>>>24&255,t>>>16&255,t>>>8&255,t&255),r.push(e>>>24&255,e>>>16&255,e>>>8&255,e&255),this.update(new Uint8Array(r));let n=new Uint8Array(20),i=[this.h0,this.h1,this.h2,this.h3,this.h4];for(let a=0;a<5;a++)n[a*4]=i[a]>>>24&255,n[a*4+1]=i[a]>>>16&255,n[a*4+2]=i[a]>>>8&255,n[a*4+3]=i[a]&255;return n}process(t){let e=this.w;for(let o=0;o<16;o++)e[o]=t[o*4]<<24|t[o*4+1]<<16|t[o*4+2]<<8|t[o*4+3];for(let o=16;o<80;o++){let l=e[o-3]^e[o-8]^e[o-14]^e[o-16];e[o]=l<<1|l>>>31}let r=this.h0,s=this.h1,n=this.h2,i=this.h3,a=this.h4;for(let o=0;o<80;o++){let l,d;o<20?(l=s&n|~s&i,d=1518500249):o<40?(l=s^n^i,d=1859775393):o<60?(l=s&n|s&i|n&i,d=2400959708):(l=s^n^i,d=3395469782);let f=(r<<5|r>>>27)+l+a+d+e[o]|0;a=i,i=n,n=s<<30|s>>>2,s=r,r=f}this.h0=this.h0+r|0,this.h1=this.h1+s|0,this.h2=this.h2+n|0,this.h3=this.h3+i|0,this.h4=this.h4+a|0}},Pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Ge(t){let e="";for(let r=0;r<t.length;r+=3){let s=t[r],n=r+1<t.length?t[r+1]:0,i=r+2<t.length?t[r+2]:0;e+=Pe[s>>2],e+=Pe[(s&3)<<4|n>>4],e+=r+1<t.length?Pe[(n&15)<<2|i>>6]:"=",e+=r+2<t.length?Pe[i&63]:"="}return e}var ps=t=>Ge(new Nt().update(t).digest()),S=class extends Error{constructor(t,e){super(t),this.status=e,this.name="FilloError"}status},We=3;function Je(t,e){return r=>e.onProgress?.({uploadedBytes:r,totalBytes:t,fraction:t===0?1:r/t})}async function ms(t){let e=globalThis.crypto?.subtle;if(e){let r=await e.digest("SHA-1",t);return Ge(new Uint8Array(r))}return ps(t)}var gs="https://fillo.so",Me=class{baseUrl;fetch;key;constructor(t={}){this.baseUrl=t.sameOrigin?"":gs,this.key=t.key,this.fetch=t.fetch??((...e)=>globalThis.fetch(...e))}url(t){return`${this.baseUrl}/api/v1${t}`}async json(t,e){let r=await this.fetch(this.url(t),{...e,headers:{"Content-Type":"application/json",...e?.headers}});if(!r.ok){let s=await r.text().catch(()=>"");throw new S(s||`Request failed: ${r.status}`,r.status)}return await r.json()}getForm(t){return this.json(`/forms/${encodeURIComponent(t)}`)}syncForm(t,e,r){return this.key?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:t,schema:e,theme:r})}):Promise.reject(new S("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401))}async submit(t,e,r){let s=await this.fetch(this.url(`/forms/${encodeURIComponent(t)}/responses`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:e,meta:r})});if(s.status===422)return{ok:!1,errors:(await s.json()).errors};if(!s.ok)throw new S(`Submit failed: ${s.status}`,s.status);return{ok:!0,responseId:(await s.json()).id}}async startSession(t,e){try{let r=await this.fetch(this.url(`/forms/${encodeURIComponent(t)}/sessions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageCount:e})});return r.ok?(await r.json()).id:null}catch{return null}}reportProgress(t,e){try{this.fetch(this.url(`/sessions/${encodeURIComponent(t)}/progress`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0}).catch(()=>{})}catch{}}getUploadSession(t,e){return this.json(`/uploads/${encodeURIComponent(t)}`,e?{headers:{"X-Fillo-Upload-Token":e}}:void 0)}async uploadFile(t,e,r){let s=e instanceof File?e.name:"upload.bin",n=e.type||"application/octet-stream",i;r.sessionId?i=await this.getUploadSession(r.sessionId,r.uploadToken):i=await this.json(`/forms/${encodeURIComponent(t)}/uploads`,{method:"POST",body:JSON.stringify({fieldId:r.fieldId,fileName:s,size:e.size,mime:n})});let a;if(i.transport?.type==="gdrive")await this.driveUploadLoop(i,i.transport.uploadUrl,e,r);else if(i.transport?.type==="s3-put")await this.s3PutUpload(i.transport.uploadUrl,e,r);else if(i.transport?.type==="box")a=await this.boxUpload(i.transport,e,r);else throw new S("This form's storage doesn't support uploads \u2014 connect Drive, S3, or Box.");let o=await this.json(`/uploads/${encodeURIComponent(i.id)}/complete`,{method:"POST",headers:i.token?{"X-Fillo-Upload-Token":i.token}:void 0,...a?{body:JSON.stringify(a)}:{}});if(!o.file)throw new S("Upload completed but no file was returned");return o.file}async boxUpload(t,e,r){let s=Je(e.size,r);s(0);let n={Authorization:`Bearer ${t.token}`};if(t.mode==="simple"){let T=new FormData;T.append("attributes",JSON.stringify({name:t.fileName,parent:{id:t.folderId}})),T.append("file",e,t.fileName);let C=await this.retry(r,()=>this.fetch(t.uploadUrl,{method:"POST",headers:n,body:T,signal:r.signal}));if(!C.ok)throw new S(`Box upload failed: ${C.status}`,C.status);let D=await C.json();return s(e.size),{providerFileId:D.entries?.[0]?.id}}if(t.size!==e.size)throw new S(`File size changed since the upload was requested (${e.size} vs ${t.size}).`,400);let i=await this.retry(r,()=>this.fetch(t.sessionUrl,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({folder_id:t.folderId,file_size:t.size,file_name:t.fileName}),signal:r.signal}));if(!i.ok)throw new S(`Box session failed: ${i.status}`,i.status);let a=await i.json(),o=new Nt,l=[],d=0;for(;d<e.size;){r.signal?.throwIfAborted();let T=Math.min(d+a.part_size,e.size),C=new Uint8Array(await e.slice(d,T).arrayBuffer());o.update(C);let D=await ms(C),$=await this.retry(r,()=>this.fetch(a.session_endpoints.upload_part,{method:"PUT",headers:{...n,"Content-Type":"application/octet-stream",Digest:`sha=${D}`,"Content-Range":`bytes ${d}-${T-1}/${e.size}`},body:C,signal:r.signal}));if(!$.ok)throw new S(`Box part failed: ${$.status}`,$.status);l.push((await $.json()).part),d=T,s(d)}let f=await this.retry(r,()=>this.fetch(a.session_endpoints.commit,{method:"POST",headers:{...n,"Content-Type":"application/json",Digest:`sha=${Ge(o.digest())}`},body:JSON.stringify({parts:l}),signal:r.signal}));if(!f.ok)throw new S(`Box commit failed: ${f.status}`,f.status);return{providerFileId:(await f.json()).entries?.[0]?.id}}async retry(t,e){let r=0;for(;;)try{return await e()}catch(s){if(t.signal?.aborted||(r+=1,r>=We))throw s;await new Promise(n=>setTimeout(n,500*2**r))}}async driveUploadLoop(t,e,r,s){let n=t.uploadedBytes,i=Je(r.size,s);for(i(n);n<r.size;){s.signal?.throwIfAborted();let a=Math.min(n+t.chunkSize,r.size),o=r.slice(n,a),l=0;for(;;)try{let d=await this.fetch(e,{method:"PUT",headers:{"Content-Range":`bytes ${n}-${a-1}/${r.size}`},body:o,signal:s.signal});if(d.status===308){let f=d.headers.get("Range")??d.headers.get("range"),g=f?.match(/bytes=0-(\d+)/);g?n=Number(g[1])+1:f==null?n=0:n=(await this.getUploadSession(t.id,t.token)).uploadedBytes;break}if(d.ok){n=r.size;break}throw new S(`Drive chunk failed: ${d.status}`,d.status)}catch(d){if(s.signal?.aborted||(l+=1,l>=We))throw d;await new Promise(g=>setTimeout(g,500*2**l)),n=(await this.getUploadSession(t.id,t.token)).uploadedBytes}i(n)}}async s3PutUpload(t,e,r){let s=Je(e.size,r);s(0);let n=0;for(;;)try{let i=await this.fetch(t,{method:"PUT",headers:{"Content-Type":e.type||"application/octet-stream"},body:e,signal:r.signal});if(!i.ok)throw new S(`S3 upload failed: ${i.status}`,i.status);s(e.size);return}catch(i){if(r.signal?.aborted||(n+=1,n>=We))throw i;await new Promise(a=>setTimeout(a,500*2**n))}}};function Oe(t={}){return new Me(t)}var ys={id:"empty",blocks:[]},wt=!1;function vs(){wt||(wt=!0,console.warn("[fillo] This form has no `client`, so responses can't be submitted \u2014 it's render-only. Pass a client (createClient) to collect responses in Fillo, or forward them to your own backend with webhooks: https://fillo.so/docs"))}function St(t){let{onChange:e,onSubmitted:r}=t,s=t.form,n=t.formId,i=t.client,a={...t.initialData??{}},o={},l=0,d="idle",f=new Set,g=new Set,T=Date.now(),C=null,D=!1;function $(){let x=s.pages.length,N=Math.min(l,Math.max(x-1,0)),E=s.pages[N]??ys;return{data:a,errors:o,status:d,pageIndex:N,pageCount:x,page:E,blocks:Qe(E,a),isFirstPage:N===0,isLastPage:N===x-1,uploading:f.size>0}}let ot=$();function L(){ot=$();for(let x of g)x()}function lt(x,N){try{r?.(x,N)}catch(E){console.error("[fillo] onSubmitted handler threw:",E)}}function It(x){let N=s.pages[x];if(!N)return{};let E={};for(let ye of Qe(N,a)){if(!Ae(ye))continue;let dt=Tt(ye,a[ye.id]);dt&&(E[ye.id]=dt)}return E}function $t(x,N){!D&&i&&n&&(D=!0,i.startSession(n,s.pages.length).then(E=>C=E)),a={...a,[x]:N},e?.(a),x in o&&(o=Object.fromEntries(Object.entries(o).filter(([E])=>E!==x))),L()}function Lt(x,N){N?f.add(x):f.delete(x),L()}function jt(){let x=s.pages.length,N=Math.min(l,Math.max(x-1,0));if(!t.skipValidation){let E=It(N);if(o=E,Object.keys(E).length>0){L();return}}l=Math.min(N+1,x-1),C&&i&&i.reportProgress(C,{furthestPage:l}),L()}function Pt(){o={},l=Math.max(Math.min(l,s.pages.length-1)-1,0),L()}async function Mt(){if(d==="submitting"||d==="submitted")return;let x=as(s,a);if(!x.ok){o=x.errors;let N=s.pages.findIndex(E=>E.blocks.some(ye=>ye.id in x.errors));N>=0&&(l=N),L();return}if(i&&n){d="submitting",L();let N;try{N=await i.submit(n,x.data,{hp:t.getHoneypot?.()??"",elapsedMs:Date.now()-T,surface:t.surface??"default"})}catch(E){throw d="idle",L(),E}if(!N.ok){o=N.errors??{},d="idle",L();return}C&&i.reportProgress(C,{completed:!0}),d="submitted",L(),lt(N.responseId,x.data);return}if(t.skipValidation){d="submitted",L(),lt(void 0,x.data);return}vs(),d="error",L()}return{getState:()=>ot,subscribe(x){return g.add(x),()=>{g.delete(x)}},setValue:$t,setUploading:Lt,next:jt,back:Pt,submit:Mt,setContext(x){"formId"in x&&(n=x.formId),"client"in x&&(i=x.client),x.form&&x.form!==s&&(s=x.form,L())},destroy(){g.clear()}}}function et(t){return{id:t.id,theme:t.theme,schema:{version:1,title:t.title??"",description:t.description,pages:t.pages,settings:t.settings??{}},__filloCodeForm:!0}}function tt(t){return typeof t=="object"&&t!==null&&"__filloCodeForm"in t}var Ke=new Map;function bs(t){let e=5381;for(let r=0;r<t.length;r++)e=(e<<5)+e+t.charCodeAt(r)|0;return(e>>>0).toString(36)}function Et(t,e){let r=JSON.stringify(e.schema)+JSON.stringify(e.theme??null),s=`${t.baseUrl}:${t.key}:${e.id}:${bs(r)}`,n=Ke.get(s);return n||(n=t.syncForm(e.id,e.schema,e.theme??null),Ke.set(s,n),n.catch(()=>Ke.delete(s))),n}var _s=/\{\{\s*([\w-]+)\s*\}\}/g;function Ye(t,e,r){if(!t.includes("{{"))return t;let s=ss(r);return t.replace(_s,(n,i)=>{let a=s.find(d=>d.id===i),o=e[i];if(o==null||o==="")return"";let l=d=>a&&"options"in a?a.options.find(f=>f.id===d)?.label??d:d;return Array.isArray(o)?o.map(d=>l(String(d))).join(", "):typeof o=="string"?l(o):String(o)})}function Ft(t,e,r){let s=n=>n===void 0?n:Ye(n,e,r);switch(t.kind){case"heading":case"paragraph":return{...t,text:Ye(t.text,e,r)};case"divider":return t;default:return{...t,label:Ye(t.label,e,r),description:s(t.description)}}}var O="fillo-";function c(t,e={}){let r=document.createElement(t);e.className&&(r.className=e.className),e.text!==void 0&&(r.textContent=e.text);for(let[s,n]of Object.entries(e.attrs??{}))r.setAttribute(s,n);return r}function Ve(t,e){e&&(e.primary&&t.style.setProperty("--fillo-primary",e.primary),e.background&&t.style.setProperty("--fillo-bg",e.background),e.text&&t.style.setProperty("--fillo-text",e.text),e.radius&&t.style.setProperty("--fillo-radius",e.radius),e.fontFamily&&t.style.setProperty("--fillo-font",e.fontFamily))}function xs(t){return typeof t=="string"||typeof t=="number"?String(t):""}function V(t,e){for(let r of e)r&&t.appendChild(r);return t}function q(t,e,r){r&&t.setAttribute("aria-invalid","true"),e.required&&t.setAttribute("aria-required","true");let s=[e.description?`${O}${e.id}-desc`:null,r?`${O}${e.id}-error`:null].filter(Boolean).join(" ");s&&t.setAttribute("aria-describedby",s)}function z(t,e,r){let s=c("div",{className:`fillo-field fillo-field--${t.kind}${e?" fillo-field--error":""}`,attrs:{"data-field":t.id}}),n=c("label",{className:"fillo-label",text:t.label,attrs:{id:`${O}${t.id}-label`,for:`${O}${t.id}`}});return t.required||n.appendChild(c("span",{className:"fillo-optional",text:" (optional)"})),s.appendChild(n),t.description&&s.appendChild(c("p",{className:"fillo-description",text:t.description,attrs:{id:`${O}${t.id}-desc`}})),s.appendChild(r),e&&s.appendChild(c("p",{className:"fillo-error",text:e,attrs:{role:"alert",id:`${O}${t.id}-error`}})),s}function Ne(t,e){let r=c("input",{className:"fillo-input",attrs:{id:`${O}${e.field.id}`,type:t}});return r.value=xs(e.value),e.field.placeholder&&(r.placeholder=e.field.placeholder),r.addEventListener("input",()=>e.setValue(r.value,{render:!1})),r.addEventListener("change",()=>e.setValue(r.value)),q(r,e.field,e.error),z(e.field,e.error,r)}function ks(t){let e=c("textarea",{className:"fillo-input fillo-textarea",attrs:{id:`${O}${t.field.id}`,rows:"4"}});return e.value=typeof t.value=="string"?t.value:"",t.field.placeholder&&(e.placeholder=t.field.placeholder),e.addEventListener("input",()=>t.setValue(e.value,{render:!1})),e.addEventListener("change",()=>t.setValue(e.value)),q(e,t.field,t.error),z(t.field,t.error,e)}function ws(t){let e=t.field,r=it(e),s=typeof t.value=="string"?t.value:"",n=s!==""&&!e.options.some(a=>a.id===s),i=c("div",{className:"fillo-options",attrs:{role:"radiogroup","aria-labelledby":`${O}${e.id}-label`}});q(i,e,t.error);for(let a of r){let o=c("label",{className:`fillo-option${s===a.id?" fillo-option--selected":""}`,attrs:{"data-option":a.id}}),l=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}`}});l.checked=s===a.id,l.addEventListener("change",()=>t.setValue(a.id)),V(o,[l,c("span",{className:"fillo-option-label",text:a.label})]),i.appendChild(o)}if(e.allowOther){let a=c("label",{className:`fillo-option${n?" fillo-option--selected":""}`}),o=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}`}});if(o.checked=n,o.addEventListener("change",()=>t.setValue("",{render:!0})),a.appendChild(o),a.appendChild(c("span",{className:"fillo-option-label",text:"Other"})),n){let l=c("input",{className:"fillo-input fillo-other-input",attrs:{type:"text"}});l.value=s,l.placeholder="Your answer",l.addEventListener("input",()=>t.setValue(l.value,{render:!1})),l.addEventListener("change",()=>t.setValue(l.value)),a.appendChild(l)}i.appendChild(a)}return z(e,t.error,i)}function Cs(t){let e=t.field,r=it(e),s=Array.isArray(t.value)?t.value:[],n=new Set(e.options.map(l=>l.id)),i=s.find(l=>!n.has(l)),a=c("div",{className:"fillo-options",attrs:{role:"group","aria-labelledby":`${O}${e.id}-label`}});q(a,e,t.error);let o=l=>t.setValue(l);for(let l of r){let d=c("label",{className:`fillo-option${s.includes(l.id)?" fillo-option--selected":""}`,attrs:{"data-option":l.id}}),f=c("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});f.checked=s.includes(l.id),f.addEventListener("change",()=>{o(f.checked?[...s,l.id]:s.filter(g=>g!==l.id))}),V(d,[f,c("span",{className:"fillo-option-label",text:l.label})]),a.appendChild(d)}if(e.allowOther){let l=i!==void 0,d=c("label",{className:`fillo-option${l?" fillo-option--selected":""}`}),f=c("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(f.checked=l,f.addEventListener("change",()=>{let g=s.filter(T=>n.has(T));o(f.checked?[...g,i??""]:g)}),V(d,[f,c("span",{className:"fillo-option-label",text:"Other"})]),l){let g=c("input",{className:"fillo-input fillo-other-input",attrs:{type:"text"}});g.value=i??"",g.placeholder="Your answer",g.addEventListener("input",()=>{let T=s.filter(C=>n.has(C));t.setValue(g.value?[...T,g.value]:T,{render:!1})}),g.addEventListener("change",()=>{let T=s.filter(C=>n.has(C));t.setValue(g.value?[...T,g.value]:T)}),d.appendChild(g)}a.appendChild(d)}return z(e,t.error,a)}var rt="__fillo_other__";function Ts(t){let e=t.field,r=typeof t.value=="string"?t.value:"",s=r!==""&&!e.options.some(a=>a.id===r),n=c("div"),i=c("select",{className:"fillo-input fillo-select",attrs:{id:`${O}${e.id}`}});i.appendChild(c("option",{text:e.placeholder??"Choose...",attrs:{value:""}}));for(let a of it(e))i.appendChild(c("option",{text:a.label,attrs:{value:a.id}}));if(e.allowOther&&i.appendChild(c("option",{text:"Other...",attrs:{value:rt}})),i.value=s?rt:r,i.addEventListener("change",()=>{t.setValue(i.value===rt?"":i.value||null)}),q(i,e,t.error),n.appendChild(i),s){let a=c("input",{className:"fillo-input fillo-other-input fillo-other-input--block",attrs:{type:"text"}});a.value=r,a.placeholder="Your answer",a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value)),n.appendChild(a)}return z(e,t.error,n)}function Ns(t){let e=c("div",{className:`fillo-field fillo-field--checkbox${t.error?" fillo-field--error":""}`,attrs:{"data-field":t.field.id}}),r=c("label",{className:"fillo-option"}),s=c("input",{className:"fillo-option-input",attrs:{id:`${O}${t.field.id}`,type:"checkbox"}});s.checked=t.value===!0,s.addEventListener("change",()=>t.setValue(s.checked)),q(s,t.field,t.error);let n=c("span",{className:"fillo-option-label",text:t.field.label});return t.field.required||n.appendChild(c("span",{className:"fillo-optional",text:" (optional)"})),V(r,[s,n]),e.appendChild(r),t.field.description&&e.appendChild(c("p",{className:"fillo-description",text:t.field.description,attrs:{id:`${O}${t.field.id}-desc`}})),t.error&&e.appendChild(c("p",{className:"fillo-error",text:t.error,attrs:{role:"alert",id:`${O}${t.field.id}-error`}})),e}function Ss(t){if(t.field.kind!=="rating")return c("div");let e=typeof t.field.max=="number"?t.field.max:5,r=typeof t.value=="number"?t.value:0,s=c("div",{className:"fillo-rating",attrs:{role:"radiogroup","aria-label":t.field.label}});q(s,t.field,t.error);for(let n=1;n<=e;n++){let i=c("button",{className:`fillo-star${n<=r?" fillo-star--active":""}`,text:"*",attrs:{type:"button","aria-label":`${n} of ${e}`,"aria-pressed":String(n===r)}});i.addEventListener("click",()=>t.setValue(n===r?null:n)),s.appendChild(i)}return z(t.field,t.error,s)}function Es(t){if(t.field.kind!=="linear_scale")return c("div");let e=typeof t.field.min=="number"?t.field.min:1,r=typeof t.field.max=="number"?t.field.max:10,s=c("div"),n=c("div",{className:"fillo-scale",attrs:{role:"radiogroup","aria-label":t.field.label}});q(n,t.field,t.error);for(let i=e;i<=r;i++){let a=c("button",{className:`fillo-scale-step${t.value===i?" fillo-scale-step--active":""}`,text:String(i),attrs:{type:"button","aria-pressed":String(t.value===i)}});a.addEventListener("click",()=>t.setValue(t.value===i?null:i)),n.appendChild(a)}return s.appendChild(n),("minLabel"in t.field||"maxLabel"in t.field)&&V(s,[V(c("div",{className:"fillo-scale-labels"}),[c("span",{text:String(t.field.minLabel??"")}),c("span",{text:String(t.field.maxLabel??"")})])]),z(t.field,t.error,s)}function Fs(t){let e=t.field;if(e.kind!=="ranking")return null;let r=Array.isArray(t.value)?t.value:[],s=[...r.filter(i=>e.options.some(a=>a.id===i)),...e.options.map(i=>i.id).filter(i=>!r.includes(i))],n=c("ol",{className:"fillo-ranking"});for(let[i,a]of s.entries()){let o=e.options.find(C=>C.id===a);if(!o)continue;let l=c("li",{className:"fillo-ranking-item"}),d=c("span",{className:"fillo-ranking-controls"}),f=C=>{let D=i+C;if(D<0||D>=s.length)return;let $=[...s];[$[i],$[D]]=[$[D],$[i]],t.setValue($)},g=c("button",{className:"fillo-ranking-move",text:"Up",attrs:{type:"button"}});g.toggleAttribute("disabled",i===0),g.addEventListener("click",()=>f(-1));let T=c("button",{className:"fillo-ranking-move",text:"Down",attrs:{type:"button"}});T.toggleAttribute("disabled",i===s.length-1),T.addEventListener("click",()=>f(1)),V(d,[g,T]),V(l,[c("span",{className:"fillo-ranking-index",text:String(i+1)}),c("span",{className:"fillo-ranking-label",text:o.label}),d]),n.appendChild(l)}return z(t.field,t.error,n)}function As(t){let e=t.field;if(e.kind!=="matrix")return null;let r=t.value&&typeof t.value=="object"&&!Array.isArray(t.value)?t.value:{},s=c("table",{className:"fillo-matrix"}),n=document.createElement("thead"),i=document.createElement("tr");i.appendChild(document.createElement("th"));for(let o of e.columns)i.appendChild(c("th",{text:o.label,attrs:{scope:"col"}}));n.appendChild(i),s.appendChild(n);let a=document.createElement("tbody");for(let o of e.rows){let l=document.createElement("tr");l.appendChild(c("th",{text:o.label,attrs:{scope:"row"}}));for(let d of e.columns){let f=document.createElement("td"),g=c("input",{className:"fillo-option-input",attrs:{type:"radio",name:`fillo-${e.id}-${o.id}`,"aria-label":`${o.label}: ${d.label}`}});g.checked=r[o.id]===d.id,g.addEventListener("change",()=>t.setValue({...r,[o.id]:d.id})),f.appendChild(g),l.appendChild(f)}a.appendChild(l)}return s.appendChild(a),z(t.field,t.error,V(c("div",{className:"fillo-matrix-wrap"}),[s]))}function Os(t){let e=c("div",{className:"fillo-signature"}),r=c("canvas",{className:"fillo-signature-canvas",attrs:{id:`${O}${t.field.id}`}});q(r,t.field,t.error);let s=c("button",{className:"fillo-signature-clear",text:"Clear",attrs:{type:"button"}}),n=c("div",{className:"fillo-signature-hint",text:"Sign here"});r.width=720,r.height=220;let i=r.getContext("2d"),a=!1,o=typeof t.value=="string"&&t.value.startsWith("data:image/");if(o&&i){let f=new Image;f.onload=()=>i.drawImage(f,0,0,r.width,r.height),f.src=String(t.value),n.style.display="none"}let l=f=>{let g=r.getBoundingClientRect();return{x:(f.clientX-g.left)/g.width*r.width,y:(f.clientY-g.top)/g.height*r.height}};r.addEventListener("pointerdown",f=>{if(!i)return;a=!0,o=!0,n.style.display="none",r.setPointerCapture(f.pointerId);let g=l(f);i.beginPath(),i.moveTo(g.x,g.y)}),r.addEventListener("pointermove",f=>{if(!a||!i)return;let g=l(f);i.lineWidth=2.4,i.lineCap="round",i.strokeStyle=getComputedStyle(r).color||"#18181b",i.lineTo(g.x,g.y),i.stroke()});let d=()=>{a&&(a=!1,o&&t.setValue(r.toDataURL("image/png")))};return r.addEventListener("pointerup",d),r.addEventListener("pointercancel",d),s.addEventListener("click",()=>{i?.clearRect(0,0,r.width,r.height),o=!1,n.style.display="",t.setValue(null)}),V(e,[r,n,s]),z(t.field,t.error,e)}function Rs(t){let e=t.field;if(e.kind!=="file_upload")return null;let r=c("input",{className:"fillo-input",attrs:{id:`${O}${e.id}`,type:"file"}});(e.maxFiles??1)>1&&(r.multiple=!0),e.accept?.length&&(r.accept=e.accept.join(",")),q(r,e,t.error),r.addEventListener("change",()=>{let a=Array.from(r.files??[]);t.uploadFiles?.(e,a)});let s=c("div");s.appendChild(r);let n=t.uploadProgress?.get(e.id);if(n!==void 0){let a=c("div",{className:"fillo-upload-progress"});a.appendChild(c("div",{className:"fillo-upload-progress-fill"})),a.firstElementChild?.style.setProperty("width",`${Math.round(n*100)}%`),s.appendChild(a)}let i=Array.isArray(t.value)?t.value:[];for(let a of i)s.appendChild(c("p",{className:"fillo-description",text:`${a.name} (${Math.round(a.size/1024)} KB)`}));return z(e,t.error,s)}var At=new Map;function it(t){if(!t.shuffleOptions)return t.options;let e=`${t.id}|${t.options.map(i=>i.id).join(",")}`,r=At.get(e);if(!r){r=t.options.map(i=>i.id);for(let i=r.length-1;i>0;i--){let a=Math.floor(Math.random()*(i+1));[r[i],r[a]]=[r[a],r[i]]}At.set(e,r)}let s=new Map(t.options.map(i=>[i.id,i])),n=r.flatMap(i=>s.get(i)??[]);return n.length===t.options.length?n:t.options}var Is={short_text:t=>Ne("text",t),email:t=>Ne("email",t),url:t=>Ne("url",t),phone:t=>Ne("tel",t),number:t=>Ne("number",t),date:t=>Ne("date",t),long_text:ks,select:ws,multi_select:Cs,dropdown:Ts,checkbox:Ns,rating:Ss,linear_scale:Es,ranking:Fs,matrix:As,signature:Os,file_upload:Rs};function $s(t){if(t.field.kind==="hidden"||t.field.kind==="custom")return null;let e=Is[t.field.kind];return e?e(t):null}var st=class{constructor(e,r){this.target=e;this.options=r;this.element.className="fillo-dom-root",e.replaceChildren(this.element),this.resolve()}target;options;element=c("div");schema=null;theme;formId;closed=!1;fetchedPoweredBy=null;fetchedBrandLabel;fetchedBrandHref;phase="loading";engine=null;destroyed=!1;renderQueued=!1;hpValue="";uploadProgress=new Map;get status(){return this.phase==="ready"?this.engine?.getState().status??"idle":this.phase}get data(){return this.engine?.getState().data??this.options.initialData??{}}get form(){return this.schema}get mutableData(){return this.engine?.getState().data??this.options.initialData??{}}api(){let e=this.schema??{version:1,title:"",pages:[],settings:{}},r=this.engine?.getState(),s=r?.pageCount??e.pages.length;return{form:e,formId:this.formId,client:this.options.client,data:r?.data??this.mutableData,errors:r?.errors??{},status:this.status,pageIndex:r?.pageIndex??0,pageCount:s,page:r?.page??e.pages[0]??{id:"empty",blocks:[]},blocks:r?.blocks??[],isFirstPage:r?.isFirstPage??!0,isLastPage:r?.isLastPage??s<=1,setValue:(n,i,a)=>this.setValueInternal(n,i,a),next:()=>this.next(),back:()=>this.back(),submit:()=>this.submit()}}async resolve(){try{let e=tt(this.options.form)?this.options.form:null;if(e){this.setSchema(e.schema,this.options.theme??e.theme,this.options.formId),this.options.client?.key&&Et(this.options.client,e).then(({formId:n,branding:i})=>{this.formId=n,this.engine?.setContext({formId:n}),i&&(this.fetchedPoweredBy=i.poweredBy,this.fetchedBrandLabel=i.label,this.fetchedBrandHref=i.href,this.render())}).catch(n=>this.handleError(De(n)));return}let r=this.options.form&&!tt(this.options.form)?this.options.form:null;if(r){this.setSchema(r,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new S("Provide either `form`, or a `formId`.",0);this.options.client??=Oe(),this.render();let s=await this.options.client.getForm(this.options.formId);this.closed=!!s.closed,this.fetchedPoweredBy=s.branding?.poweredBy??null,this.fetchedBrandLabel=s.branding?.label,this.fetchedBrandHref=s.branding?.href,this.setSchema(s.schema,this.options.theme??s.theme??void 0,s.id)}catch(e){this.handleError(De(e))}}setSchema(e,r,s){this.schema=e,this.theme=r,this.formId=s,this.engine=St({form:e,formId:s,client:this.options.client,initialData:this.options.initialData,onChange:this.options.onChange,onSubmitted:this.options.onSubmitted,getHoneypot:()=>this.hpValue,surface:"default"}),this.phase=this.closed?"closed":"ready",this.render()}setValue(e,r){this.setValueInternal(e,r)}setValueInternal(e,r,s={}){this.engine?.setValue(e,r),s.render!==!1&&this.queueRender()}next(){this.engine&&(this.engine.next(),this.render())}back(){this.engine&&(this.engine.back(),this.render())}async submit(){if(!this.engine||this.phase!=="ready")return;let e=this.engine.submit();this.render();try{await e}catch(r){this.handleError(De(r));return}this.render()}async uploadFiles(e,r){if(!this.schema)return;let s=e.maxFiles??1,n=r.slice(0,s);this.uploadProgress.set(e.id,0),this.queueRender();try{let i=[];for(let[a,o]of n.entries())this.options.client&&this.formId?i.push(await this.options.client.uploadFile(this.formId,o,{fieldId:e.id,onProgress:l=>{this.uploadProgress.set(e.id,(a+l.fraction)/n.length),this.queueRender()}})):i.push({fileId:`local:${o.name}:${o.size}`,name:o.name,size:o.size,mime:o.type||"application/octet-stream"});this.uploadProgress.delete(e.id),this.setValueInternal(e.id,i)}catch(i){this.uploadProgress.delete(e.id),this.handleError(De(i))}}destroy(){this.destroyed=!0,this.target.replaceChildren()}handleError(e){this.phase="error",this.options.onError?.(e),this.render(e)}queueRender(){this.renderQueued||this.destroyed||(this.renderQueued=!0,queueMicrotask(()=>{this.renderQueued=!1,this.render()}))}render(e){if(!this.destroyed){if(this.element.replaceChildren(),this.phase==="loading"){let r=c("div",{className:`fillo-form fillo-form--loading ${this.options.className??""}`,attrs:{"aria-busy":"true"}});Ve(r,this.theme),V(r,[c("div",{className:"fillo-skeleton"}),c("div",{className:"fillo-skeleton"}),c("div",{className:"fillo-skeleton fillo-skeleton--short"})]),this.element.appendChild(r);return}if(this.phase==="error"&&e){this.element.appendChild(this.options.renderError?.(e)??c("div",{className:"fillo-form fillo-form--error",text:e.message}));return}if(this.phase==="closed"){let r=c("div",{className:`fillo-form fillo-form--closed ${this.options.className??""}`});Ve(r,this.theme),r.appendChild(c("p",{className:"fillo-closed",text:"This form is no longer accepting responses."})),this.element.appendChild(r);return}if(this.schema){if(this.engine?.getState().status==="submitted"){let r=this.api(),s=this.options.renderSuccess?.(r)??js(this.schema);Ve(s,this.theme),this.element.appendChild(s),this.brandingVisible()&&this.element.appendChild(Ot(this.fetchedBrandLabel,this.fetchedBrandHref));return}!this.options.client&&Ps()&&this.element.appendChild(Ms()),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(Ot())}}}brandingVisible(){return this.options.poweredBy??this.fetchedPoweredBy??!0}renderForm(){let e=this.api(),r=c("form",{className:`fillo-form ${this.options.className??""}`});Ve(r,this.theme),r.noValidate=!0;let s=()=>{e.isLastPage?this.submit():this.next()};if(r.addEventListener("submit",l=>{l.preventDefault(),s()}),e.pageCount>1&&this.schema?.settings.showProgress!==!1){let l=c("div",{className:"fillo-progress-track",attrs:{role:"progressbar","aria-valuemin":"0","aria-valuemax":String(e.pageCount),"aria-valuenow":String(e.pageIndex+1)}});l.appendChild(c("div",{className:"fillo-progress-fill"})),l.firstElementChild?.style.setProperty("width",`${(e.pageIndex+1)/e.pageCount*100}%`),r.appendChild(l)}if(e.pageIndex===0){let l=c("header",{className:"fillo-header"});l.appendChild(c("h1",{className:"fillo-title",text:e.form.title})),e.form.description&&l.appendChild(c("p",{className:"fillo-form-description",text:e.form.description})),r.appendChild(l)}else e.page.title&&r.appendChild(c("h2",{className:"fillo-page-title",text:e.page.title}));let n=c("div",{className:"fillo-blocks"});for(let l of e.blocks){let d=this.renderBlock(Ft(l,this.mutableData,e.form),e);d&&n.appendChild(d)}r.appendChild(n);let i=c("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});i.addEventListener("input",()=>{this.hpValue=i.value}),r.appendChild(i);let a=c("footer",{className:"fillo-footer"});if(e.pageCount>1&&!e.isFirstPage){let l=c("button",{className:"fillo-button fillo-button--ghost",text:"Back",attrs:{type:"button"}});l.addEventListener("click",()=>this.back()),a.appendChild(l)}let o=c("button",{className:"fillo-button fillo-button--primary",text:e.status==="submitting"?"Submitting...":e.isLastPage?e.form.settings.submitLabel??"Submit":"Next",attrs:{type:"submit"}});return o.toggleAttribute("disabled",e.status==="submitting"||this.uploadProgress.size>0),o.addEventListener("click",l=>{l.preventDefault(),s()}),a.appendChild(o),r.appendChild(a),r}renderBlock(e,r){if(!Ae(e))return Ls(e);let s=(a,o)=>this.setValueInternal(e.id,a,o),n={field:e,value:r.data[e.id],error:r.errors[e.id],api:r,setValue:s,uploadFiles:(a,o)=>this.uploadFiles(a,o),uploadProgress:this.uploadProgress};return(e.kind==="custom"?this.options.customComponents?.[e.component]??this.options.components?.custom:this.options.components?.[e.kind]??$s)?.(n)??null}};function Ls(t){switch(t.kind){case"heading":return c("h3",{className:"fillo-heading",text:t.text});case"paragraph":return c("p",{className:"fillo-paragraph",text:t.text});case"divider":return c("hr",{className:"fillo-divider"})}return c("div")}function js(t){let e=c("div",{className:"fillo-form fillo-form--success"}),r=c("div",{className:"fillo-success"});return V(r,[c("div",{className:"fillo-success-mark",text:"\u2713",attrs:{"aria-hidden":"true"}}),c("h2",{className:"fillo-success-title",text:t.settings.successTitle??"Thanks!"}),c("p",{className:"fillo-success-message",text:t.settings.successMessage??"Your response has been recorded."})]),e.appendChild(r),e}function Ot(t,e){let r=e??"https://fillo.so",s=`${r}${r.includes("?")?"&":"?"}utm_source=form_badge`;return c("a",{className:"fillo-powered",text:t??"Powered by Fillo",attrs:{href:s,target:"_blank",rel:"noopener"}})}function Ps(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Ms(){return c("div",{className:"fillo-devwarning",text:"No Fillo client connected \u2014 this form is render-only and won't save responses. Pass a client to collect them in Fillo, or forward with webhooks. (Shown only in development.)",attrs:{role:"alert"}})}function De(t){return t instanceof S?t:new S(t instanceof Error?t.message:String(t),0)}function Ue(t,e){let r=typeof t=="string"?document.querySelector(t):t;if(!r)throw new S(`Fillo mount target not found: ${String(t)}`,0);return new st(r,{...e,initialData:e.initialData??{}})}function Rt(t){let e=c("div");return Ue(e,t),e}var nt=class extends HTMLElement{instance=null;assignedForm;assignedClient;assignedTheme;assignedInitialData;static get observedAttributes(){return["publishable-key","form-id"]}connectedCallback(){this.mount()}disconnectedCallback(){this.instance?.destroy(),this.instance=null}attributeChangedCallback(){this.isConnected&&this.mount()}set form(e){this.assignedForm=e,this.isConnected&&this.mount()}get form(){return this.assignedForm}set client(e){this.assignedClient=e,this.isConnected&&this.mount()}set theme(e){this.assignedTheme=e,this.isConnected&&this.mount()}set initialData(e){this.assignedInitialData=e,this.isConnected&&this.mount()}mount(){this.instance?.destroy();let e=this.getAttribute("publishable-key")??void 0,r=this.getAttribute("form-id")??void 0,s=this.assignedClient??(r||e?Oe({key:e}):void 0);this.instance=Ue(this,{form:this.assignedForm,client:s,formId:r,theme:this.assignedTheme,initialData:this.assignedInitialData,onChange:n=>this.dispatchEvent(new CustomEvent("fillo-change",{detail:{data:n}})),onSubmitted:(n,i)=>this.dispatchEvent(new CustomEvent("fillo-submit",{detail:{responseId:n,data:i}})),onError:n=>this.dispatchEvent(new CustomEvent("fillo-error",{detail:{error:n}}))})}};function at(t="fillo-form"){customElements.get(t)||customElements.define(t,nt)}at();return Zt(Vs);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usefillo/dom",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Framework-agnostic DOM renderer and web component for embedding Fillo forms.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@usefillo/core": "^0.3.
|
|
37
|
+
"@usefillo/core": "^0.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"jsdom": "^25.0.1",
|