@usefillo/dom 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var Fillo=(()=>{var Pt=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Xi=Object.getOwnPropertyNames;var Yi=Object.prototype.hasOwnProperty;var Qi=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},eo=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Xi(t))!Yi.call(e,i)&&i!==n&&Pt(e,i,{get:()=>t[i],enumerable:!(r=Ji(t,i))||r.enumerable});return e};var to=e=>eo(Pt({},"__esModule",{value:!0}),e);var Aa={};Qi(Aa,{FilloClient:()=>Et,FilloError:()=>$,createClient:()=>st,createFormElement:()=>Vi,defineForm:()=>In,registerFilloElement:()=>Rn,renderForm:()=>It});var jn;function S(e,t,n){function r(a,l){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:l,constr:s,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,l);let c=s.prototype,u=Object.keys(c);for(let p=0;p<u.length;p++){let h=u[p];h in a||(a[h]=c[h].bind(a))}}let i=n?.Parent??Object;class o extends i{}Object.defineProperty(o,"name",{value:e});function s(a){var l;let c=n?.Parent?new o:this;r(c,a),(l=c._zod).deferred??(l.deferred=[]);for(let u of c._zod.deferred)u();return c}return Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}var fe=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(jn=globalThis).__zod_globalConfig??(jn.__zod_globalConfig={});var Mt=globalThis.__zod_globalConfig;function be(e){return e&&Object.assign(Mt,e),Mt}function Hn(e){let t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,i])=>t.indexOf(+r)===-1).map(([r,i])=>i)}function qn(e,t){return typeof t=="bigint"?t.toString():t}function Wn(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Zt(e){return e==null}function Kn(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Vn=Symbol("evaluating");function ve(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Vn)return r===void 0&&(r=Vn,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var Rt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ft(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ot(e){if(ft(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(ft(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Dt(e){return Ot(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var Gn=new Set(["string","number","symbol"]);function qe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ut(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function B(e){let t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Jn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var no={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function We(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Xn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function ye(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function pt(e){return typeof e=="string"?e:e?.message}function we(e,t,n){let r=e.message?e.message:pt(e.inst?._zod.def?.error?.(e))??pt(t?.error?.(e))??pt(n.customError?.(e))??pt(n.localeError?.(e))??"Invalid input",{inst:i,continue:o,input:s,...a}=e;return a.path??(a.path=[]),a.message=r,t?.reportInput&&(a.input=s),a}function Bt(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var Yn=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,qn,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Qn=S("$ZodError",Yn),Ke=S("$ZodError",Yn,{Parent:Error});var io=e=>(t,n,r,i)=>{let o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new fe;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>we(l,o,be())));throw Rt(a,i?.callee),a}return s.value},ht=io(Ke),oo=e=>async(t,n,r,i)=>{let o=r?{...r,async:!0}:{async:!0},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>we(l,o,be())));throw Rt(a,i?.callee),a}return s.value},mt=oo(Ke),so=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new fe;return o.issues.length?{success:!1,error:new(e??Qn)(o.issues.map(s=>we(s,i,be())))}:{success:!0,data:o.value}},Ge=so(Ke),ao=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(s=>we(s,i,be())))}:{success:!0,data:o.value}},Je=ao(Ke);var er=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var lo="(?:(?:\\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])))",co=new RegExp(`^${lo}$`);var tr=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var jt=/^-?\d+(?:\.\d+)?$/;var Ce=S("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),uo={number:"number",bigint:"bigint",object:"date"};var rr=S("$ZodCheckGreaterThan",(e,t)=>{Ce.init(e,t);let n=uo[typeof t.value];e._zod.onattach.push(r=>{let i=r._zod.bag,o=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>o&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}});var ir=S("$ZodCheckMaxLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Zt(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{let i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{let i=r.value;if(i.length<=t.maximum)return;let s=Bt(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),or=S("$ZodCheckMinLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Zt(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{let i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{let i=r.value;if(i.length>=t.minimum)return;let s=Bt(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var sr=S("$ZodCheckStringFormat",(e,t)=>{var n,r;Ce.init(e,t),e._zod.onattach.push(i=>{let o=i._zod.bag;o.format=t.format,t.pattern&&(o.patterns??(o.patterns=new Set),o.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})});var lr={major:4,minor:4,patch:3};var Q=S("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=lr;let r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(let i of r)for(let o of i._zod.onattach)o(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(s,a,l)=>{let c=We(s),u;for(let p of a){if(p._zod.def.when){if(Xn(s)||!p._zod.def.when(s))continue}else if(c)continue;let h=s.issues.length,f=p._zod.check(s);if(f instanceof Promise&&l?.async===!1)throw new fe;if(u||f instanceof Promise)u=(u??Promise.resolve()).then(async()=>{await f,s.issues.length!==h&&(c||(c=We(s,h)))});else{if(s.issues.length===h)continue;c||(c=We(s,h))}}return u?u.then(()=>s):s},o=(s,a,l)=>{if(We(s))return s.aborted=!0,s;let c=i(a,r,l);if(c instanceof Promise){if(l.async===!1)throw new fe;return c.then(u=>e._zod.parse(u,l))}return e._zod.parse(c,l)};e._zod.run=(s,a)=>{if(a.skipChecks)return e._zod.parse(s,a);if(a.direction==="backward"){let c=e._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});return c instanceof Promise?c.then(u=>o(u,s,a)):o(c,s,a)}let l=e._zod.parse(s,a);if(l instanceof Promise){if(a.async===!1)throw new fe;return l.then(c=>i(c,r,a))}return i(l,r,a)}}ve(e,"~standard",()=>({validate:i=>{try{let o=Ge(e,i);return o.success?{value:o.data}:{issues:o.error?.issues}}catch{return Je(e,i).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}))}),Vt=S("$ZodString",(e,t)=>{Q.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??tr(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Ht=S("$ZodStringFormat",(e,t)=>{sr.init(e,t),Vt.init(e,t)});var pr=S("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=er),Ht.init(e,t)});var fr=S("$ZodNumber",(e,t)=>{Q.init(e,t),e._zod.pattern=e._zod.bag.pattern??jt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;let o=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}});var hr=S("$ZodUnknown",(e,t)=>{Q.init(e,t),e._zod.parse=n=>n});function cr(e,t,n){e.issues.length&&t.issues.push(...ye(n,e.issues)),t.value[n]=e.value}var mr=S("$ZodArray",(e,t)=>{Q.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);let o=[];for(let s=0;s<i.length;s++){let a=i[s],l=t.element._zod.run({value:a,issues:[]},r);l instanceof Promise?o.push(l.then(c=>cr(c,n,s))):cr(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function gt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...ye(n,e.issues))}if(!s&&!i){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?s&&(t.value[n]=void 0):t.value[n]=e.value}function fo(e){let t=Object.keys(e.shape);for(let r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);let n=Jn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function ho(e,t,n,r,i,o){let s=[],a=i.keySet,l=i.catchall._zod,c=l.def.type,u=l.optin==="optional",p=l.optout==="optional";for(let h in t){if(h==="__proto__"||a.has(h))continue;if(c==="never"){s.push(h);continue}let f=l.run({value:t[h],issues:[]},r);f instanceof Promise?e.push(f.then(m=>gt(m,n,h,t,u,p))):gt(f,n,h,t,u,p)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}var gr=S("$ZodObject",(e,t)=>{if(Q.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){let a=t.shape;Object.defineProperty(t,"shape",{get:()=>{let l={...a};return Object.defineProperty(t,"shape",{value:l}),l}})}let r=Wn(()=>fo(t));ve(e._zod,"propValues",()=>{let a=t.shape,l={};for(let c in a){let u=a[c]._zod;if(u.values){l[c]??(l[c]=new Set);for(let p of u.values)l[c].add(p)}}return l});let i=ft,o=t.catchall,s;e._zod.parse=(a,l)=>{s??(s=r.value);let c=a.value;if(!i(c))return a.issues.push({expected:"object",code:"invalid_type",input:c,inst:e}),a;a.value={};let u=[],p=s.shape;for(let h of s.keys){let f=p[h],m=f._zod.optin==="optional",g=f._zod.optout==="optional",b=f._zod.run({value:c[h],issues:[]},l);b instanceof Promise?u.push(b.then(z=>gt(z,a,h,c,m,g))):gt(b,a,h,c,m,g)}return o?ho(u,c,a,l,r.value,e):u.length?Promise.all(u).then(()=>a):a}});var br=S("$ZodRecord",(e,t)=>{Q.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Ot(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;let o=[],s=t.keyType._zod.values;if(s){n.value={};let a=new Set;for(let c of s)if(typeof c=="string"||typeof c=="number"||typeof c=="symbol"){a.add(typeof c=="number"?c.toString():c);let u=t.keyType._zod.run({value:c,issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(u.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:u.issues.map(f=>we(f,r,be())),input:c,path:[c],inst:e});continue}let p=u.value,h=t.valueType._zod.run({value:i[c],issues:[]},r);h instanceof Promise?o.push(h.then(f=>{f.issues.length&&n.issues.push(...ye(c,f.issues)),n.value[p]=f.value})):(h.issues.length&&n.issues.push(...ye(c,h.issues)),n.value[p]=h.value)}let l;for(let c in i)a.has(c)||(l=l??[],l.push(c));l&&l.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:l})}else{n.value={};for(let a of Reflect.ownKeys(i)){if(a==="__proto__"||!Object.prototype.propertyIsEnumerable.call(i,a))continue;let l=t.keyType._zod.run({value:a,issues:[]},r);if(l instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&jt.test(a)&&l.issues.length){let p=t.keyType._zod.run({value:Number(a),issues:[]},r);if(p instanceof Promise)throw new Error("Async schemas not supported in object keys currently");p.issues.length===0&&(l=p)}if(l.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(p=>we(p,r,be())),input:a,path:[a],inst:e});continue}let u=t.valueType._zod.run({value:i[a],issues:[]},r);u instanceof Promise?o.push(u.then(p=>{p.issues.length&&n.issues.push(...ye(a,p.issues)),n.value[l.value]=p.value})):(u.issues.length&&n.issues.push(...ye(a,u.issues)),n.value[l.value]=u.value)}}return o.length?Promise.all(o).then(()=>n):n}});var vr=S("$ZodEnum",(e,t)=>{Q.init(e,t);let n=Hn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>Gn.has(typeof i)).map(i=>typeof i=="string"?qe(i):i.toString()).join("|")})$`),e._zod.parse=(i,o)=>{let s=i.value;return r.has(s)||i.issues.push({code:"invalid_value",values:n,input:s,inst:e}),i}}),yr=S("$ZodLiteral",(e,t)=>{if(Q.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");let n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?qe(r):r?qe(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,i)=>{let o=r.value;return n.has(o)||r.issues.push({code:"invalid_value",values:t.values,input:o,inst:e}),r}});function ur(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var wr=S("$ZodOptional",(e,t)=>{Q.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ve(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ve(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Kn(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){let i=n.value,o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>ur(s,i)):ur(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var _r=S("$ZodDefault",(e,t)=>{Q.init(e,t),e._zod.optin="optional",ve(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(o=>dr(o,t)):dr(i,t)}});function dr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function xr(e,t){return new e({type:"string",...B(t)})}function kr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...B(t)})}function $r(e,t){return new e({type:"number",checks:[],...B(t)})}function zr(e){return new e({type:"unknown"})}function qt(e,t){return new rr({check:"greater_than",...B(t),value:e,inclusive:!0})}function Wt(e){return qt(0,e)}function H(e,t){return new ir({check:"max_length",...B(t),maximum:e})}function Le(e,t){return new or({check:"min_length",...B(t),minimum:e})}var le=S("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");Q.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>ht(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Ge(e,n,r),e.parseAsync=async(n,r)=>mt(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>Je(e,n,r),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0}),e.with=e.check,e.clone=(n,r)=>Ut(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.apply=n=>n(e)}),Er=S("ZodMiniString",(e,t)=>{Vt.init(e,t),le.init(e,t)});function q(e){return xr(Er,e)}var go=S("ZodMiniStringFormat",(e,t)=>{Ht.init(e,t),Er.init(e,t)}),bo=S("ZodMiniEmail",(e,t)=>{pr.init(e,t),go.init(e,t)});function bt(e){return kr(bo,e)}var vo=S("ZodMiniNumber",(e,t)=>{fr.init(e,t),le.init(e,t)});function Ar(e){return $r(vo,e)}var yo=S("ZodMiniUnknown",(e,t)=>{hr.init(e,t),le.init(e,t)});function Xe(){return zr(yo)}var wo=S("ZodMiniArray",(e,t)=>{mr.init(e,t),le.init(e,t)});function _e(e,t){return new wo({type:"array",element:e,...B(t)})}var Cr=S("ZodMiniObject",(e,t)=>{gr.init(e,t),le.init(e,t),ve(e,"shape",()=>t.shape)});function Ye(e,t){let n={type:"object",shape:e??{},...B(t)};return new Cr(n)}function Kt(e,t){return new Cr({type:"object",shape:e,catchall:Xe(),...B(t)})}var Sr=S("ZodMiniRecord",(e,t)=>{br.init(e,t),le.init(e,t)});function Fr(e,t,n){return!t||!t._zod?new Sr({type:"record",keyType:q(),valueType:e,...B(t)}):new Sr({type:"record",keyType:e,valueType:t,...B(n)})}var _o=S("ZodMiniEnum",(e,t)=>{vr.init(e,t),le.init(e,t),e.options=Object.values(t.entries)});function Ir(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new _o({type:"enum",entries:n,...B(t)})}var xo=S("ZodMiniLiteral",(e,t)=>{yr.init(e,t),le.init(e,t)});function Nr(e,t){return new xo({type:"literal",values:Array.isArray(e)?e:[e],...B(t)})}var ko=S("ZodMiniOptional",(e,t)=>{wr.init(e,t),le.init(e,t)});function K(e){return new ko({type:"optional",innerType:e})}var $o=S("ZodMiniDefault",(e,t)=>{_r.init(e,t),le.init(e,t)});function Gt(e,t){return new $o({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Dt(t)}})}var Eo=["heading","paragraph","divider"];function te(e){return!Eo.includes(e.kind)}function vn(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:typeof e=="boolean"?e===!1:typeof e=="object"?Object.keys(e).length===0:!1}function Gr(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="number"&&typeof t=="string"&&t.trim()!==""){let n=Number(t);return Number.isNaN(n)?t:n}if((e.kind==="rating"||e.kind==="linear_scale")&&typeof t=="string"){let n=Number(t);return Number.isNaN(n)?t:n}return typeof t=="string"?t.trim():t}function Ao(e,t){let n=Gr(e,t);return vn(n)?void 0:n}function Jr(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function Xr(e,t){let n=10**t,r=Math.round(Math.abs(e)*n)/n;return e<0?-r:r}function Fe(e){return Number.isFinite(e)?e:null}function Oe(e,t){switch(e.op){case"value":return un(t(e.fieldId));case"const":return Fe(e.value);case"add":case"mul":case"min":case"max":{if(e.args.length===0)return null;let n=[];for(let r of e.args){let i=Oe(r,t);if(i===null)return null;n.push(i)}return e.op==="add"?Fe(n.reduce((r,i)=>r+i,0)):e.op==="mul"?Fe(n.reduce((r,i)=>r*i,1)):e.op==="min"?Math.min(...n):Math.max(...n)}case"sub":case"div":{let n=Oe(e.left,t);if(n===null)return null;let r=Oe(e.right,t);return r===null?null:e.op==="sub"?Fe(n-r):r===0?null:Fe(n/r)}case"round":{let n=Oe(e.arg,t);return n===null?null:Fe(Xr(n,Jr(e.decimals)))}case"if":return Oe(yn(e.when,t)?e.then:e.else,t)}}function Co(e,t){let n=Oe(e.calc,t);return n===null||e.decimals===void 0?n:Fe(Xr(n,Jr(e.decimals)))}function Ze(e,t){let n=ze(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=pn(e,r);for(let a=0;a<=n.length;a++){let l={},c=!1;for(let[u,p]of Object.entries(r))i.has(u)?l[u]=p:c=!0;if(!c)break;r=l,i=pn(e,r)}let o=zt(n,r),s={};for(let[a,l]of Object.entries(t))o.calcIds.has(a)||(s[a]=l);for(let[a,l]of Object.entries(o.calc))i.has(a)&&(s[a]=l);return s}function Jt(e){return e==null?!1:typeof e=="string"?e.trim()!=="":Array.isArray(e)?e.length>0:typeof e=="boolean"?e:typeof e=="object"?Object.keys(e).length>0:!0}function Tr(e,t){return e===t?!0:typeof e=="number"&&typeof t=="string"&&t.trim()!==""?Number(t)===e:typeof t=="number"&&typeof e=="string"&&e.trim()!==""?Number(e)===t:!1}function un(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e!="string"||e.trim()==="")return null;let t=Number(e);return Number.isFinite(t)?t:null}function Fo(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return Jt(n);case"not_answered":return!Jt(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):Tr(n,e.value);case"neq":return Jt(n)?Array.isArray(n)?!n.some(r=>r===e.value):!Tr(n,e.value):!1;case"contains":return typeof n=="string"?n.toLowerCase().includes(String(e.value??"").toLowerCase()):Array.isArray(n)?n.some(r=>r===e.value):!1;case"gt":case"lt":{let r=un(n),i=un(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function yn(e,t){return e.length===0?!0:e.every(n=>Fo(n,t))}function Yr(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:yn(e.visibleIf,t)}function Xt(e,t,n,r,i,o){return s=>n.has(s)?r.has(s)?i.has(s)?o[s]:e[s]:void 0:t[s]}function zt(e,t){let n=new Set(e.map(l=>l.id)),r=e.filter(l=>l.kind==="calculated"),i=new Set(r.map(l=>l.id)),o={};for(let l of e){if(l.kind==="calculated")continue;let c=Ao(l,t[l.id]);c!==void 0&&(o[l.id]=c)}let s=n,a={};for(let l=0;l<=e.length;l++){let c=a;if(r.length>0){c={...a};let f=Xt(o,t,n,s,i,c);for(let m of r){let g=s.has(m.id)?Co(m,f):null;g===null?delete c[m.id]:c[m.id]=g}}let u=Xt(o,t,n,s,i,c),p=new Set;for(let f of e)Yr(f,u)&&p.add(f.id);let h=p.size===s.size&&[...p].every(f=>s.has(f))&&Io(a,c);if(s=p,a=c,h)break}return{visible:s,calc:a,calcIds:i,resolve:Xt(o,t,n,s,i,a)}}function Io(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function Qr(e,t){return zt(e,t).visible}function vt(e,t,n){let r=zt(ze(e),n);return t.blocks.filter(i=>te(i)?r.visible.has(i.id):Yr(i,r.resolve))}function ze(e){return e.pages.flatMap(t=>t.blocks.filter(te))}function ei(e,t){let n=e.responseLimit?.scopeField;if(!n)return null;let r=t[n];return typeof r=="number"?Number.isFinite(r)?String(r):null:typeof r!="string"?null:r.trim()||null}function ti(e,t){let n=ze(e),r=Qr(n,t);return n.filter(i=>r.has(i.id))}function No(e,t){return zt(ze(e),t).resolve}function ni(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=No(e,n);for(let s of i)if(yn(s.when,o))return s.to==="end"?{end:!0}:{to:s.to};return{linear:!0}}function De(e,t){let n=[];if(e.pages.length===0)return n;let r=new Set,i=0;for(let o=0;o<=e.pages.length;o++){let s=e.pages[i];if(!s||r.has(s.id))break;r.add(s.id),n.push(s.id);let a=ni(e,s.id,t);if("end"in a)break;if("to"in a){let l=e.pages.findIndex(c=>c.id===a.to);if(l<0)break;i=l}else if(i+=1,i>=e.pages.length)break}return n}function To(e,t){return new Set(De(e,t))}function dn(e,t,n){if("end"in ni(e,t,n))return!0;let r=De(e,n);return r.length>0&&r[r.length-1]===t}function pn(e,t){let n=To(e,t),r=Qr(ze(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)te(s)&&r.has(s.id)&&i.add(s.id);return i}function ri(e,t){let n=pn(e,t);return ze(e).filter(r=>n.has(r.id))}var Re;function Po(){if(Re!==void 0)return Re??void 0;if(typeof Intl>"u"||typeof Intl.DisplayNames>"u"){Re=null;return}try{Re=new Intl.DisplayNames(void 0,{type:"region"})}catch{Re=null}return Re??void 0}function ii(e){try{return Po()?.of(e)??e}catch{return e}}var y=(e,t,n=[],r=[],i="")=>({iso2:e,name:ii(e),dialCode:t,lengths:n,groups:r,example:i}),Mo=[y("US","1",[10],[3,3,4],"2015550123"),y("CA","1",[10],[3,3,4],"5145550123"),y("GB","44",[10],[4,6],"7400123456"),y("AU","61",[9],[3,3,3],"412345678"),y("DE","49",[10,11],[4,7],"15123456789"),y("FR","33",[9],[1,2,2,2,2],"612345678"),y("IN","91",[10],[5,5],"8123456789"),y("DK","45",[8],[2,2,2,2],"32123456"),y("SE","46",[9],[2,3,4],"701234567"),y("NO","47",[8],[3,2,3],"40612345"),y("FI","358",[9,10],[2,3,4],"412345678"),y("NL","31",[9],[1,4,4],"612345678"),y("BE","32",[9],[3,2,2,2],"470123456"),y("ES","34",[9],[3,3,3],"612345678"),y("IT","39",[9,10],[3,3,4],"3123456789"),y("PT","351",[9],[3,3,3],"912345678"),y("IE","353",[9],[2,3,4],"851234567"),y("CH","41",[9],[2,3,2,2],"781234567"),y("AT","43",[10,11],[3,7],"6641234567"),y("PL","48",[9],[3,3,3],"512345678"),y("CZ","420",[9],[3,3,3],"601123456"),y("GR","30",[10],[3,3,4],"6912345678"),y("RO","40",[9],[3,3,3],"712345678"),y("HU","36",[9],[2,3,4],"201234567"),y("UA","380",[9],[2,3,2,2],"501234567"),y("RU","7",[10],[3,3,2,2],"9123456789"),y("TR","90",[10],[3,3,2,2],"5012345678"),y("IL","972",[9],[2,3,4],"501234567"),y("AE","971",[9],[2,3,4],"501234567"),y("SA","966",[9],[2,3,4],"512345678"),y("ZA","27",[9],[2,3,4],"711234567"),y("NG","234",[10],[3,3,4],"8021234567"),y("KE","254",[9],[3,3,3],"712123456"),y("EG","20",[10],[3,3,4],"1001234567"),y("BR","55",[10,11],[2,5,4],"11961234567"),y("MX","52",[10],[3,3,4],"2221234567"),y("AR","54",[10],[4,6],"1123456789"),y("CL","56",[9],[1,4,4],"221234567"),y("CO","57",[10],[3,3,4],"3211234567"),y("PE","51",[9],[3,3,3],"912345678"),y("CN","86",[11],[3,4,4],"13123456789"),y("JP","81",[10],[2,4,4],"9012345678"),y("KR","82",[9,10],[2,4,4],"1023456789"),y("SG","65",[8],[4,4],"81234567"),y("HK","852",[8],[4,4],"51234567"),y("TW","886",[9],[3,3,3],"912345678"),y("MY","60",[9,10],[2,3,4],"123456789"),y("ID","62",[10,11],[3,4,4],"81234567890"),y("TH","66",[9],[2,3,4],"812345678"),y("PH","63",[10],[3,3,4],"9171234567"),y("VN","84",[9],[3,3,3],"912345678"),y("PK","92",[10],[3,3,4],"3012345678"),y("BD","880",[10],[2,4,4],"1812345678"),y("NZ","64",[9,10],[2,3,4],"211234567"),y("SK","421",[9],[3,3,3],"912123456"),y("BG","359",[9],[2,3,4],"481234567"),y("HR","385",[8,9],[2,3,4],"921234567"),y("RS","381",[8,9],[2,3,4],"601234567"),y("SI","386",[8],[2,3,3],"31234567"),y("LT","370",[8],[3,2,3],"61234567"),y("LV","371",[8],[2,3,3],"21234567"),y("EE","372",[7,8],[3,4],"51234567"),y("IS","354",[7],[3,4],"6111234"),y("LU","352",[9],[3,3,3],"628123456"),y("MA","212",[9],[3,3,3],"650123456"),y("CR","506",[8],[4,4],"83123456"),y("EC","593",[9],[2,3,4],"991234567"),y("UY","598",[8],[1,3,4],"94231234"),y("QA","974",[8],[4,4],"33123456"),y("KW","965",[8],[4,4],"50012345")],Lo="AD376 AF93 AG1 AI1 AL355 AM374 AO244 AS1 AW297 AX358 AZ994 BA387 BB1 BF226 BH973 BI257 BJ229 BL590 BM1 BN673 BO591 BQ599 BS1 BT975 BV47 BW267 BY375 BZ501 CC61 CD243 CF236 CG242 CI225 CK682 CM237 CU53 CV238 CW599 CX61 CY357 DJ253 DM1 DO1 DZ213 EH212 ER291 ET251 FJ679 FK500 FM691 FO298 GA241 GD1 GE995 GF594 GG44 GH233 GI350 GL299 GM220 GN224 GP590 GQ240 GS500 GT502 GU1 GW245 GY592 HN504 HT509 IM44 IO246 IQ964 IR98 JE44 JM1 JO962 KG996 KH855 KI686 KM269 KN1 KP850 KY1 KZ7 LA856 LB961 LC1 LI423 LK94 LR231 LS266 LY218 MC377 MD373 ME382 MF590 MG261 MH692 MK389 ML223 MM95 MN976 MO853 MP1 MQ596 MR222 MS1 MT356 MU230 MV960 MW265 MZ258 NA264 NC687 NE227 NF672 NI505 NP977 NR674 NU683 OM968 PA507 PF689 PG675 PM508 PN64 PR1 PS970 PW680 PY595 RE262 RW250 SB677 SC248 SD249 SH290 SJ47 SL232 SM378 SN221 SO252 SR597 SS211 ST239 SV503 SX1 SY963 SZ268 TC1 TD235 TF262 TG228 TJ992 TK690 TL670 TM993 TN216 TO676 TT1 TV688 TZ255 UG256 UZ998 VA379 VC1 VE58 VG1 VI1 VU678 WF681 WS685 XK383 YE967 YT262 ZM260 ZW263";function Zo(e){let t=[];for(let n of e.trim().split(/\s+/)){let r=n.slice(0,2),i=n.slice(2);t.push({iso2:r,name:ii(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var nt=[...Mo,...Zo(Lo)],Ue=Ro(nt);function Ro(e){if(typeof Intl>"u"||typeof Intl.Collator>"u")return[...e].sort((n,r)=>n.iso2<r.iso2?-1:n.iso2>r.iso2?1:0);let t=new Intl.Collator(void 0,{sensitivity:"base"});return[...e].sort((n,r)=>t.compare(n.name,r.name))}var Oo=new Map(nt.map(e=>[e.iso2,e])),Do={"Africa/Cairo":"EG","Africa/Casablanca":"MA","Africa/Johannesburg":"ZA","Africa/Lagos":"NG","Africa/Nairobi":"KE","America/Adak":"US","America/Anchorage":"US","America/Argentina/Buenos_Aires":"AR","America/Argentina/Cordoba":"AR","America/Argentina/Mendoza":"AR","America/Bahia":"BR","America/Belem":"BR","America/Bogota":"CO","America/Boise":"US","America/Boa_Vista":"BR","America/Cancun":"MX","America/Chicago":"US","America/Chihuahua":"MX","America/Campo_Grande":"BR","America/Costa_Rica":"CR","America/Cuiaba":"BR","America/Denver":"US","America/Detroit":"US","America/Edmonton":"CA","America/Fortaleza":"BR","America/Guayaquil":"EC","America/Halifax":"CA","America/Hermosillo":"MX","America/Indiana/Indianapolis":"US","America/Indianapolis":"US","America/Juneau":"US","America/Kentucky/Louisville":"US","America/Lima":"PE","America/Los_Angeles":"US","America/Maceio":"BR","America/Manaus":"BR","America/Matamoros":"MX","America/Mazatlan":"MX","America/Merida":"MX","America/Mexico_City":"MX","America/Moncton":"CA","America/Monterrey":"MX","America/Montevideo":"UY","America/New_York":"US","America/Noronha":"BR","America/Nome":"US","America/North_Dakota/Center":"US","America/Ojinaga":"MX","America/Phoenix":"US","America/Porto_Velho":"BR","America/Punta_Arenas":"CL","America/Recife":"BR","America/Regina":"CA","America/Rio_Branco":"BR","America/Santiago":"CL","America/Sao_Paulo":"BR","America/Sitka":"US","America/St_Johns":"CA","America/Tijuana":"MX","America/Toronto":"CA","America/Vancouver":"CA","America/Whitehorse":"CA","America/Winnipeg":"CA","America/Yakutat":"US","Asia/Bangkok":"TH","Asia/Calcutta":"IN","Asia/Dacca":"BD","Asia/Dhaka":"BD","Asia/Dubai":"AE","Asia/Hong_Kong":"HK","Asia/Ho_Chi_Minh":"VN","Asia/Jakarta":"ID","Asia/Jerusalem":"IL","Asia/Karachi":"PK","Asia/Kolkata":"IN","Asia/Kuala_Lumpur":"MY","Asia/Kuwait":"KW","Asia/Manila":"PH","Asia/Qatar":"QA","Asia/Riyadh":"SA","Asia/Seoul":"KR","Asia/Shanghai":"CN","Asia/Saigon":"VN","Asia/Singapore":"SG","Asia/Taipei":"TW","Asia/Tel_Aviv":"IL","Asia/Tokyo":"JP","Asia/Urumqi":"CN","Atlantic/Reykjavik":"IS","Australia/Adelaide":"AU","Australia/Brisbane":"AU","Australia/Darwin":"AU","Australia/Hobart":"AU","Australia/Melbourne":"AU","Australia/Perth":"AU","Australia/Sydney":"AU","Europe/Amsterdam":"NL","Europe/Athens":"GR","Europe/Belgrade":"RS","Europe/Berlin":"DE","Europe/Bratislava":"SK","Europe/Brussels":"BE","Europe/Bucharest":"RO","Europe/Budapest":"HU","Europe/Copenhagen":"DK","Europe/Dublin":"IE","Europe/Helsinki":"FI","Europe/Zagreb":"HR","Europe/Istanbul":"TR","Europe/Kiev":"UA","Europe/Kyiv":"UA","Europe/Lisbon":"PT","Europe/Ljubljana":"SI","Europe/London":"GB","Europe/Luxembourg":"LU","Europe/Madrid":"ES","Europe/Moscow":"RU","Europe/Oslo":"NO","Europe/Paris":"FR","Europe/Prague":"CZ","Europe/Riga":"LV","Europe/Rome":"IT","Europe/Sofia":"BG","Europe/Stockholm":"SE","Europe/Tallinn":"EE","Europe/Vienna":"AT","Europe/Vilnius":"LT","Europe/Warsaw":"PL","Europe/Zurich":"CH","Pacific/Auckland":"NZ"};function wn(e){let t=e.toUpperCase();return/^[A-Z]{2}$/.test(t)?String.fromCodePoint(...[...t].map(n=>127462+n.charCodeAt(0)-65)):"\u{1F3F3}\uFE0F"}function St(e){return e?Oo.get(e.toUpperCase()):void 0}function oi(e){return St(e?Do[e]:void 0)}function Uo(e){let t;for(let n of nt)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function de(e){return e.replace(/[^\d]/g,"")}function rt(e,t){let n=de(t);if(!n)return"";let r=e?.groups?.length?e.groups:[],i=[],o=0;for(let s of r){if(o>=n.length)break;i.push(n.slice(o,o+s)),o+=s}for(;o<n.length;)i.push(n.slice(o,o+3)),o+=3;return i.join(" ")}function si(e,t){let n=de(t);return n?`+${e.dialCode}${n}`:""}function it(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=de(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?de(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=Uo(o);if(a){let l=o.slice(a.dialCode.length);return{country:a,national:l,e164:`+${o}`}}return{national:o,e164:`+${o}`,pending:!0,raw:r}}if(!o)return{country:t,national:"",e164:""};if(t){let s=o.startsWith(t.dialCode)?o.slice(t.dialCode.length):o;return{country:t,national:s,e164:`+${t.dialCode}${s}`}}return{national:o,e164:`+${o}`}}function Bo(e){let{country:t,national:n,e164:r}=it(e);if(!r)return!1;let i=de(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var jo=8;function ai(e,t){if(!e||!t||typeof window>"u")return"below";let n=jo,r=document.documentElement.clientWidth||window.innerWidth,i=document.documentElement.clientHeight||window.innerHeight,o=e.getBoundingClientRect(),s=Math.max(0,i-o.bottom-n),a=Math.max(0,o.top-n),l=s<t.scrollHeight&&a>s?"above":"below",u=Math.max(0,Math.min(l==="above"?a:s,i-n*2)),p=Math.max(0,r-n*2);t.style.setProperty("--fillo-phone-popover-max-height",`${Math.floor(u)}px`),t.style.setProperty("--fillo-phone-popover-max-width",`${Math.floor(p)}px`),t.style.setProperty("--fillo-phone-popover-offset-x","0px");let h=Math.min(t.offsetWidth,p),f=0,m=o.left+h-(r-n);m>0&&(f-=m);let g=n-(o.left+f);return g>0&&(f+=g),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(f)}px`),l}var li="This field is required",T={back:"Back",next:"Next",submit:"Submit",submitting:"Submitting\u2026",uploading:"Uploading\u2026",optional:" (optional)",other:"Other",otherPrompt:"Other \u2014 please specify",otherPlaceholder:"Your answer",choosePlaceholder:"Choose\u2026",successTitle:"Thanks!",successMessage:"Your response has been recorded.",closed:"This form is no longer accepting responses.",notLive:"This form isn't live yet.",notOpenTitle:"This form isn't open yet",notOpenBody:"The form owner is still setting things up. Please check back soon.",closedTitle:"Responses are closed",submitFailed:"This form can't submit right now. Please try again in a moment.",loadFailedNotFound:"Form not found \u2014 check the form id and that it's published.",loadFailedNetwork:"Couldn't reach the server \u2014 check your connection or CORS.",loadFailed:"This form could not be loaded.",renderFailed:"This form could not be rendered.",resumeNotice:"Picked up where you left off.",editNotice:"You're updating your earlier response.",resumeStartOver:"Start over",challengeUnavailable:"The verification check couldn't load. Refresh the page, or check that challenges.cloudflare.com isn't blocked."},J={required:li,resumeLinkExpired:"That saved-progress link expired or was already used \u2014 start again below.",alreadyAnswered:"You've already answered this form.",uploadRetry:"Retry",uploadsDisabled:"Uploads are disabled in preview",uploadsUnavailable:"Uploads are temporarily unavailable",uploadUnavailable:"We couldn't upload this file right now. Try again in a moment.",uploadFailed:"Upload failed \u2014 try again",dropzoneTitle:e=>`Drop ${e?"files":"a file"} here or click to browse`,dropzoneHint:e=>`Up to ${e} MB per file`,fileTooLarge:e=>`Larger than ${e} MB limit`,filesUploading:e=>`Uploading ${e} ${e===1?"file":"files"}, please wait\u2026`,uploadsFailed:e=>`${e} ${e===1?"upload":"uploads"} failed.`,filesUploaded:e=>`${e} ${e===1?"file":"files"} uploaded.`,submittingAnnouncement:"Submitting your response\u2026",errorSummaryTitle:"Please fix the following:",rankingPosition:(e,t,n)=>`${e}, position ${t} of ${n}`,phoneCountrySelected:e=>`${e} selected`,phoneResultsCount:e=>`${e} ${e===1?"result":"results"}`,signatureEmpty:"No signature yet",signatureSigned:"Signature saved"};var Vo=Ye({fileId:q().check(Le(1)),name:q(),size:Ar().check(Wt()),mime:q(),url:K(q())});function ci(e,t){if(vn(t))return e.kind==="calculated"?null:e.required?li:null;switch(e.kind){case"short_text":case"long_text":{if(typeof t!="string")return"Expected text";if(e.maxLength&&t.length>e.maxLength)return`Must be at most ${e.maxLength} characters`;let n=e.kind==="long_text"?2e4:2e3;return!e.maxLength&&t.length>n?"Answer is too long":null}case"email":return typeof t!="string"?"Enter a valid email address":e.maxLength&&t.length>e.maxLength?`Must be at most ${e.maxLength} characters`:bt().safeParse(t).success?null:"Enter a valid email address";case"url":{if(typeof t!="string")return"Enter a valid URL (including https://)";if(e.maxLength&&t.length>e.maxLength)return`Must be at most ${e.maxLength} characters`;try{let n=new URL(t);if(n.protocol!=="http:"&&n.protocol!=="https:")return"Enter an http(s) URL"}catch{return"Enter a valid URL (including https://)"}return null}case"phone":return typeof t!="string"||!Bo(t)?"Enter a valid phone number":null;case"number":{let n=typeof t=="string"?Number(t):t;return typeof n!="number"||!Number.isFinite(n)?"Enter a number":e.min!==void 0&&n<e.min?`Must be at least ${e.min}`:e.max!==void 0&&n>e.max?`Must be at most ${e.max}`:null}case"select":case"dropdown":return typeof t!="string"||t===""?"Pick an option":e.options.some(n=>n.id===t)||e.allowOther&&t.length<=500?null:"Pick a valid option";case"multi_select":{if(!Array.isArray(t))return"Pick at least one option";let n=new Set(e.options.map(s=>s.id)),r=t,i=0,o=new Set;for(let s of r){if(typeof s!="string")return"Pick valid options";if(o.has(s))return"Pick each option only once";if(o.add(s),!n.has(s)){if(e.allowOther!==!0||s.length===0||s.length>500)return"Pick valid options";if(++i>1)return"Only one 'Other' answer is allowed"}}return null}case"checkbox":return typeof t=="boolean"?null:"Invalid value";case"rating":{let n=e.max??5,r=typeof t=="string"?Number(t):t;return typeof r!="number"||!Number.isInteger(r)||r<1||r>n?`Pick a rating between 1 and ${n}`:null}case"linear_scale":{let n=e.min??1,r=e.max??10,i=typeof t=="string"?Number(t):t;return typeof i!="number"||!Number.isInteger(i)||i<n||i>r?`Pick a value between ${n} and ${r}`:null}case"ranking":{if(!Array.isArray(t))return"Drag the options into order";let n=e.options.map(i=>i.id).sort(),r=[...t].sort();return n.length!==r.length||n.some((i,o)=>i!==r[o])?"Rank every option":null}case"matrix":{if(typeof t!="object"||t===null||Array.isArray(t))return"Answer the grid";let n=t,r=new Set(e.columns.map(o=>o.id)),i=new Set(e.rows.map(o=>o.id));for(let[o,s]of Object.entries(n))if(!i.has(o)||!r.has(s))return"Invalid grid answer";return e.required&&Object.keys(n).length<e.rows.length?"Answer every row":null}case"signature":return typeof t!="string"||!t.startsWith("data:image/")?"Sign in the box":null;case"hidden":return typeof t=="string"?null:"Invalid value";case"calculated":return null;case"custom":return null;case"date":{if(typeof t!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(t))return"Enter a valid date";let[n,r,i]=t.split("-").map(Number),o=new Date(Date.UTC(n,r-1,i));return o.getUTCFullYear()!==n||o.getUTCMonth()!==r-1||o.getUTCDate()!==i?"Enter a valid date":null}case"file_upload":{let n=_e(Vo).safeParse(t);if(!n.success)return"Upload did not complete";let r=e.maxFiles??1;return n.data.length>r?`At most ${r} file${r===1?"":"s"}`:null}}}function ui(e,t){let n=ri(e,t),r={},i={};for(let o of n){if(o.kind==="calculated")continue;let s=Gr(o,t[o.id]),a=ci(o,s);a?r[o.id]=a:vn(s)||(i[o.id]=s)}return{ok:Object.keys(r).length===0,errors:r,data:i}}var Ho=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","calculated","custom"],qo=["heading","paragraph","divider"],Wo=[...Ho,...qo],_n=q().check(Le(1),H(128)),Yt=Kt({id:_n,label:q().check(H(1e3)),icon:K(Xe())}),Ko=Kt({id:_n,kind:Ir(Wo),label:K(q().check(H(2e3))),options:K(_e(Yt).check(H(200))),rows:K(_e(Yt).check(H(200))),columns:K(_e(Yt).check(H(200)))}),Go=Ye({id:_n,title:K(q().check(H(500))),blocks:_e(Ko).check(H(500)),next:K(Xe())}),Jo=Ye({version:Nr(1),title:Gt(K(q().check(H(2e3))),""),description:K(q().check(H(5e3))),pages:_e(Go).check(Le(1),H(50)),settings:Gt(K(Fr(q(),Xe())),{})}),Xo=1,fn=1,hn="0.11.0";function ee(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function D(e,t){let n=ee(e,t);return n===""?void 0:n}function yt(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function he(e){return typeof e=="boolean"?e:void 0}function me(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function ue(e,t,n,r){let i=me(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function wt(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=ee(r.id,128),o=ee(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[L({id:i,label:o,icon:s})]:[]}):[]}function Qt(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function xn(e){if(!Array.isArray(e))return;let t=e.slice(0,20).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=r.op;if(i!=="eq"&&i!=="neq"&&i!=="contains"&&i!=="gt"&&i!=="lt"&&i!=="answered"&&i!=="not_answered")return[];let o=ee(r.fieldId,128);if(!o)return[];let s=r.value,a=typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:void 0;return[{fieldId:o,op:i,...a!==void 0?{value:a}:{}}]});return t.length?t:void 0}function di(e,t,n,r){let i=t.get(e);if(i===void 0)return n.has(e);if(r.has(e))return!0;r.add(e);for(let o of i)if(!di(o,t,n,r))return!1;return!0}function Yo(e,t,n,r,i){if(!Array.isArray(e))return;let o=e.slice(0,50).flatMap(s=>{if(!s||typeof s!="object")return[];let a=s,l=typeof a.to=="string"?a.to:void 0;if(!l||l!=="end"&&!t.has(l))return[];if(l===n)return[];let c=a.when;if(c!==void 0&&!Array.isArray(c))return[];let u=xn(c);return Array.isArray(c)&&c.length>0&&u===void 0?[]:u&&u.some(p=>!di(p.fieldId,i,r,new Set))?[]:[{when:u??[],to:l}]});return o.length?o:void 0}var Qo=["number","rating","linear_scale","calculated"];function ke(e,t=0){if(t>32||!e||typeof e!="object"||Array.isArray(e))return null;let n=e;switch(n.op){case"value":{let r=ee(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=me(n.value);return r===void 0?null:{op:"const",value:r}}case"add":case"mul":case"min":case"max":{if(!Array.isArray(n.args)||n.args.length<1||n.args.length>50)return null;let r=[];for(let i of n.args){let o=ke(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=ke(n.left,t+1),i=ke(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=ke(n.arg,t+1);return r?L({op:"round",arg:r,decimals:me(n.decimals)===void 0?void 0:ue(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=xn(n.when)??[];if(r.length!==n.when.length)return null;let i=ke(n.then,t+1),o=ke(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function $e(e,t,n){switch(e.op){case"value":t.add(e.fieldId);return;case"const":return;case"add":case"mul":case"min":case"max":for(let r of e.args)$e(r,t,n);return;case"sub":case"div":$e(e.left,t,n),$e(e.right,t,n);return;case"round":$e(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);$e(e.then,t,n),$e(e.else,t,n);return}}function es(e){let t=new Map;for(let o of e)for(let s of o.blocks)te(s)&&t.set(s.id,s.kind);let n=new Map;for(let o of e)for(let s of o.blocks){if(s.kind!=="calculated")continue;let a=ke(s.calc);if(!a)return`Field ${s.id} has a malformed calc expression \u2014 build it from value/const/add/sub/mul/div/min/max/round/if nodes`;s.calc=a;let l=new Set,c=new Set;$e(a,l,c);for(let u of l){let p=t.get(u);if(p===void 0)return`Calculated field ${s.id} references a missing field: ${u} \u2014 remove the reference or restore that field`;if(!Qo.includes(p))return`Calculated field ${s.id} references non-numeric field ${u} (${p}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}n.set(s.id,[...l,...c].filter(u=>t.get(u)==="calculated"))}let r=new Map,i=(o,s)=>{let a=r.get(o);if(a==="done")return null;if(a==="visiting"){let l=[...s.slice(s.indexOf(o)),o].join(" \u2192 ");return`Calculated field ${o} depends on its own result (${l}) \u2014 break the cycle so the value can be computed`}r.set(o,"visiting");for(let l of n.get(o)??[]){let c=i(l,[...s,o]);if(c)return c}return r.set(o,"done"),null};for(let o of n.keys()){let s=i(o,[]);if(s)return s}return null}var Pr=100,Mr=5e3;function Ie(e){switch(e.op){case"value":case"const":return 1;case"add":case"mul":case"min":case"max":return 1+e.args.reduce((t,n)=>t+Ie(n),0);case"sub":case"div":return 1+Ie(e.left)+Ie(e.right);case"round":return 1+Ie(e.arg);case"if":return 1+Ie(e.then)+Ie(e.else)}}function ts(e){let t=0,n=0;for(let r of e)for(let i of r.blocks)i.kind==="calculated"&&(t+=1,n+=Ie(i.calc));return t>Pr?`Form has ${t} calculated fields \u2014 the maximum is ${Pr}; remove some or consolidate them into fewer expressions`:n>Mr?`Calculated expressions total ${n} operations \u2014 the maximum is ${Mr} across the form; simplify or split up the calculations`:null}function pi(e){return{id:ee(e.id,128),visibleIf:xn(e.visibleIf)}}function j(e,t){return{...pi(e),kind:t,label:ee(e.label,2e3,"Untitled field"),description:D(e.description,5e3),required:he(e.required),placeholder:D(e.placeholder,500)}}function Lr(e){let t=D(e,2e3);if(t)try{let n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"?t:void 0}catch{return}}function ns(e){if(!e||typeof e!="object")return;let t=e,n=t.by==="browser"||t.by==="field"||t.by==="identify"?t.by:void 0;if(!n)return;let r=n==="field"?D(t.field,128):void 0;if(n==="field"&&!r)return;let i=D(t.scopeField,128),o=t.onRepeat==="update"&&n==="identify"?"update":"keep";return{by:n,...r?{field:r}:{},...i?{scopeField:i}:{},onRepeat:o}}function rs(e){if(!e||typeof e!="object")return;let t=e,n=t.unverified==="allow"||t.unverified==="quarantine"?t.unverified:void 0,r=t.challenge==="turnstile"?"turnstile":void 0;if(!(!n&&!r))return{...n?{unverified:n}:{},...r?{challenge:r}:{}}}function is(e){let t=e&&typeof e=="object"?e:{};return{submitMode:t.submitMode==="button"||t.submitMode==="auto"?t.submitMode:void 0,submitLabel:D(t.submitLabel,100),successTitle:D(t.successTitle,200),successMessage:D(t.successMessage,5e3),redirectUrl:Lr(t.redirectUrl),showProgress:he(t.showProgress),responseLimit:ns(t.responseLimit),trust:rs(t.trust),notifyEmail:bt().check(H(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,sendReceipt:he(t.sendReceipt),saveProgress:he(t.saveProgress),draftAnswersVisible:he(t.draftAnswersVisible),resumeEmails:he(t.resumeEmails),resumeUrl:Lr(t.resumeUrl),draftDigest:he(t.draftDigest)}}function L(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function os(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=pi(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return L({...r,kind:n,text:ee(t.text,2e3,"Section")});case"paragraph":return L({...r,kind:n,text:ee(t.text,5e3)});case"divider":return L({...r,kind:n});case"short_text":case"email":case"url":return L({...j(t,n),maxLength:me(t.maxLength)===void 0?void 0:ue(t.maxLength,1,2e3,2e3)});case"phone":{let i=D(t.defaultCountry,2)?.toUpperCase();return L({...j(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return L({...j(t,n),maxLength:me(t.maxLength)===void 0?void 0:ue(t.maxLength,1,2e4,2e4)});case"number":return L({...j(t,n),min:me(t.min),max:me(t.max),decimals:me(t.decimals)===void 0?void 0:ue(t.decimals,0,6,0),prefix:yt(t.prefix,100),suffix:yt(t.suffix,100),notation:t.notation==="grouped"?"grouped":void 0});case"select":case"multi_select":case"dropdown":{let i=wt(t.options);return i.length===0?null:L({...j(t,n),options:i,allowOther:he(t.allowOther),shuffleOptions:he(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return L({...j(t,n),appearance:i})}case"signature":case"date":return L(j(t,n));case"rating":{let i=ue(t.max,1,10,5);return L({...j(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=ue(t.min,0,9,1),o=ue(t.max,i+1,10,10),s=t.insightsMetric==="nps"&&i===0&&o===10?"nps":t.insightsMetric==="csat"&&i===1&&o===5?"csat":void 0;return L({...j(t,n),min:i,max:o,minLabel:D(t.minLabel,100),maxLabel:D(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=wt(t.options);return i.length<2?null:L({...j(t,n),options:i})}case"matrix":{let i=wt(t.rows),o=wt(t.columns);return i.length===0||o.length===0?null:L({...j(t,n),rows:i,columns:o})}case"hidden":return L({...j(t,n),required:!1,paramName:D(t.paramName,128),defaultValue:D(t.defaultValue,1e3)});case"calculated":return L({...j(t,n),required:!1,calc:t.calc,decimals:me(t.decimals)===void 0?void 0:ue(t.decimals,0,6,0),prefix:yt(t.prefix,100),suffix:yt(t.suffix,100)});case"file_upload":return L({...j(t,n),maxFiles:ue(t.maxFiles,1,20,1),maxFileSizeMb:ue(t.maxFileSizeMb,1,5e3,500),accept:Array.isArray(t.accept)?t.accept.flatMap(i=>{let o=D(i,100);return o?[o]:[]}).slice(0,50):void 0});case"custom":return L({...j(t,n),component:ee(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function Ne(e){let t=Jo.safeParse(e);if(!t.success){let f=t.error.issues[0],m=f?.path.join(".");return{ok:!1,error:f?`${m?`${m}: `:""}${f.message}`:"Invalid schema"}}if(t.data.version>Xo)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(f=>{let m=f.blocks.flatMap(g=>{let b=os(g);return b?[b]:[]});return{id:ee(f.id,128),title:D(f.title,500),blocks:m,next:f.next}}),r=new Set(n.map(f=>f.id)),i=new Map;for(let f of n)for(let m of f.blocks){if(m.kind!=="calculated")continue;let g=new Set,b=ke(m.calc);if(b){let z=new Set,I=new Set;$e(b,z,I);for(let C of z)g.add(C);for(let C of I)g.add(C)}i.set(m.id,g)}let o=new Set,s=n.map(f=>{for(let m of f.blocks)te(m)&&o.add(m.id);return L({id:f.id,title:f.title,blocks:f.blocks,next:Yo(f.next,r,f.id,new Set(o),i)})}),a=new Set,l=new Set;for(let f of s){if(!f.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(f.id))return{ok:!1,error:`Duplicate page id: ${f.id}`};a.add(f.id);for(let m of f.blocks){if(l.has(m.id))return{ok:!1,error:`Duplicate block id: ${m.id}`};if(l.add(m.id),m.kind==="number"&&m.min!==void 0&&m.max!==void 0&&m.min>m.max)return{ok:!1,error:`Field ${m.id} has min greater than max`};if(m.kind==="select"||m.kind==="multi_select"||m.kind==="dropdown"||m.kind==="ranking"){let g=Qt(m.options);if(g)return{ok:!1,error:`Duplicate option id in field ${m.id}: ${g}`}}else if(m.kind==="matrix"){let g=Qt(m.rows);if(g)return{ok:!1,error:`Duplicate matrix row id in field ${m.id}: ${g}`};let b=Qt(m.columns);if(b)return{ok:!1,error:`Duplicate matrix column id in field ${m.id}: ${b}`}}}}let c=es(s);if(c)return{ok:!1,error:c};let u=ts(s);if(u)return{ok:!1,error:u};if(s.every(f=>f.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let p={version:fn,title:ee(t.data.title,2e3),pages:s,settings:is(t.data.settings)},h=D(t.data.description,5e3);return h&&(p.description=h),{ok:!0,schema:p}}function Qe(e,t){let n=D(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function kn(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=t.colorScheme==="light"||t.colorScheme==="dark"||t.colorScheme==="auto"?t.colorScheme:void 0,r=L({colorScheme:n,primary:Qe(t.primary,200),background:Qe(t.background,200),text:Qe(t.text,200),radius:Qe(t.radius,64),fontFamily:Qe(t.fontFamily,200)});return Object.keys(r).length>0?r:null}function ss(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function fi(e,t){if(t==null||t==="")return"";switch(e.kind){case"file_upload":return Array.isArray(t)?t.map(n=>n.name).join(", "):String(t);case"select":case"dropdown":return e.options.find(n=>n.id===t)?.label??String(t);case"multi_select":return Array.isArray(t)?t.map(n=>e.options.find(r=>r.id===n)?.label??n).join(", "):String(t);case"ranking":return Array.isArray(t)?t.map((n,r)=>`${r+1}. ${e.options.find(i=>i.id===n)?.label??n}`).join(", "):String(t);case"matrix":{if(typeof t!="object"||t===null||Array.isArray(t))return String(t);let n=t;return e.rows.filter(r=>n[r.id]).map(r=>`${r.label}: ${e.columns.find(i=>i.id===n[r.id])?.label??""}`).join(", ")}case"signature":return typeof t=="string"&&t.startsWith("data:image/")?"\u270D signed":"";case"checkbox":return t===!0?"Yes":"No";case"rating":case"linear_scale":return String(t);case"number":{let n=typeof t=="number"?t:Number(t);if(!Number.isFinite(n))return String(t);let r=e.decimals===void 0?String(n):n.toFixed(Math.max(0,Math.min(6,e.decimals)));return`${e.prefix??""}${r}${e.suffix??""}`}case"calculated":{let n=typeof t=="number"?t:Number(t);if(!Number.isFinite(n))return String(t);let r=e.decimals===void 0?String(n):n.toFixed(Math.max(0,Math.min(6,e.decimals)));return`${e.prefix??""}${r}${e.suffix??""}`}case"phone":{let{country:n,national:r,e164:i}=it(String(t));if(!i)return String(t);let o=rt(n,r),s=n?`+${n.dialCode}`:i.replace(r,"");return o?`${s} ${o}`:i}case"short_text":case"long_text":case"email":case"url":case"date":case"hidden":return String(t);case"custom":return typeof t=="object"?JSON.stringify(t):String(t);default:return ss(e)}}function as(e){return Math.max(0,Math.min(6,Math.round(e)))}function hi(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:as(t.decimals);if(typeof Intl>"u")return n===void 0?String(e):e.toFixed(n);let r={useGrouping:!0};return n===void 0?r.maximumFractionDigits=20:(r.minimumFractionDigits=n,r.maximumFractionDigits=n),new Intl.NumberFormat(t?.locale,r).format(e)}function mi(e,t){return t?e.split(t).join(""):e}function Zr(e,t){return t==="."?e:e.split(t).join(".")}function ls(e,t){if(t!=="."&&e.includes(t)){let i=e.lastIndexOf(t),o=mi(e.slice(0,i),"."),s=e.slice(i+t.length);return`${o}.${s}`}let n=e.split(".");return n.length===1?e:n.every((i,o)=>o===0?/^\d{1,3}$/.test(i):/^\d{3}$/.test(i))?n.join(""):`${n.slice(0,-1).join("")}.${n.at(-1)??""}`}function $n(e,t){if(typeof Intl>"u"||e.trim()==="")return e;let n=new Intl.NumberFormat(t).formatToParts(12345678e-1),r=n.find(a=>a.type==="group")?.value??",",i=n.find(a=>a.type==="decimal")?.value??".",o=e.trim(),s=o.startsWith("-");return s&&(o=o.slice(1)),/^\s$/.test(r)?o=Zr(o.replace(/\s/g,""),i):r==="."?o=ls(o,i):o=Zr(mi(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function ot(e,t){let r=e.startsWith("-")?e.slice(1):e;if(r.includes("-"))return!1;if(r==="")return!0;if(typeof Intl>"u")return/^[\d.,]*$/.test(r);let i=new Intl.NumberFormat(t).formatToParts(12345678e-1),o=i.find(p=>p.type==="group")?.value??",",s=i.find(p=>p.type==="decimal")?.value??".",a=o===".",l=/^\s$/.test(o),c=a?[s]:Array.from(new Set([".",s])),u=0;for(let p of r)if(!/\d/.test(p)){if(c.includes(p)){if(++u>1)return!1;continue}if(!(l?/\s/.test(p):p===o))return!1}return!0}var mn="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",cs=256-256%mn.length;function Rr(e=12){if(!Number.isSafeInteger(e)||e<=0)throw new RangeError("createId size must be a positive safe integer");let t=globalThis.crypto;if(typeof t>"u"||typeof t.getRandomValues!="function")throw new Error("createId requires Web Crypto (globalThis.crypto.getRandomValues)");let n="";for(;n.length<e;){let r=new Uint8Array(e);t.getRandomValues(r);for(let i=0;i<e&&n.length<e;i++){let o=r[i];o<cs&&(n+=mn[o%mn.length])}}return n}var gi=class{h0=1732584193;h1=4023233417;h2=2562383102;h3=271733878;h4=3285377520;block=new Uint8Array(64);blockLen=0;totalLen=0;w=new Int32Array(80);update(e){this.totalLen+=e.length;let t=0;if(this.blockLen>0){for(;t<e.length&&this.blockLen<64;)this.block[this.blockLen++]=e[t++];this.blockLen===64&&(this.process(this.block),this.blockLen=0)}for(;t+64<=e.length;)this.process(e.subarray(t,t+64)),t+=64;for(;t<e.length;)this.block[this.blockLen++]=e[t++];return this}digest(){let e=Math.floor(this.totalLen/536870912),t=this.totalLen*8>>>0,n=[128],r=this.blockLen+1;for(;r%64!==56;)n.push(0),r++;n.push(e>>>24&255,e>>>16&255,e>>>8&255,e&255),n.push(t>>>24&255,t>>>16&255,t>>>8&255,t&255),this.update(new Uint8Array(n));let i=new Uint8Array(20),o=[this.h0,this.h1,this.h2,this.h3,this.h4];for(let s=0;s<5;s++)i[s*4]=o[s]>>>24&255,i[s*4+1]=o[s]>>>16&255,i[s*4+2]=o[s]>>>8&255,i[s*4+3]=o[s]&255;return i}process(e){let t=this.w;for(let a=0;a<16;a++)t[a]=e[a*4]<<24|e[a*4+1]<<16|e[a*4+2]<<8|e[a*4+3];for(let a=16;a<80;a++){let l=t[a-3]^t[a-8]^t[a-14]^t[a-16];t[a]=l<<1|l>>>31}let n=this.h0,r=this.h1,i=this.h2,o=this.h3,s=this.h4;for(let a=0;a<80;a++){let l,c;a<20?(l=r&i|~r&o,c=1518500249):a<40?(l=r^i^o,c=1859775393):a<60?(l=r&i|r&o|i&o,c=2400959708):(l=r^i^o,c=3395469782);let u=(n<<5|n>>>27)+l+s+c+t[a]|0;s=o,o=i,i=r<<30|r>>>2,r=n,n=u}this.h0=this.h0+n|0,this.h1=this.h1+r|0,this.h2=this.h2+i|0,this.h3=this.h3+o|0,this.h4=this.h4+s|0}},_t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function zn(e){let t="";for(let n=0;n<e.length;n+=3){let r=e[n],i=n+1<e.length?e[n+1]:0,o=n+2<e.length?e[n+2]:0;t+=_t[r>>2],t+=_t[(r&3)<<4|i>>4],t+=n+1<e.length?_t[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?_t[o&63]:"="}return t}var us=e=>zn(new gi().update(e).digest()),$=class extends Error{constructor(e,t,n,r){super(e),this.status=t,this.retryAfterSec=n,this.code=r,this.name="FilloError"}status;retryAfterSec;code};function G(e){return e instanceof Error&&e.name==="FilloError"}async function Or(e,t){try{let n=await e.json();return{message:typeof n.error=="string"&&n.error?n.error:t,code:typeof n.code=="string"&&n.code?n.code:void 0}}catch{}return{message:t}}function Dr(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var et=3,tt=3e4,ds=5*6e4,ce=10*6e4;function Ur(e,t){return t?.throwIfAborted(),new Promise((n,r)=>{let i=()=>{clearTimeout(o),r(t?.reason)},o=setTimeout(()=>{t?.removeEventListener("abort",i),n()},e);t?.addEventListener("abort",i,{once:!0})})}function en(e,t=!1){let n=G(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&G(e)&&e.retryAfterSec!==void 0}function xt(e){return e>=500||e===429||e===408}function Br(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new $("Request timed out",0):e}function ps(e,t){let n=e.split(".").map(i=>Number(i)||0),r=t.split(".").map(i=>Number(i)||0);for(let i=0;i<Math.max(n.length,r.length);i++){let o=(n[i]??0)-(r[i]??0);if(o!==0)return o}return 0}function fs(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==fn)throw new $(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${fn}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&ps(hn,e.minSdkVersion)<0)throw new $(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${hn}.`,426)}function kt(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function hs(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return zn(new Uint8Array(n))}return us(e)}var ms="https://fillo.so",jr={"X-Fillo-Client":`@usefillo/core@${hn}`},Et=class{baseUrl;fetch;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":ms,this.key=e.key,this.fetch=e.fetch??((...t)=>globalThis.fetch(...t))}url(e){return`${this.baseUrl}/api/v1${e}`}async json(e,t){let n=t?.body!=null?{"Content-Type":"application/json",...jr,...t?.headers}:t?.headers,r;try{r=await this.fetch(this.url(e),{...t,headers:n,signal:t?.signal??AbortSignal.timeout(tt)})}catch(i){throw Br(i)}if(!r.ok){let{message:i,code:o}=await Or(r,`Request failed: ${r.status}`);throw new $(i,r.status,Dr(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return fs(t),t}syncForm(e,t,n){if(!this.key)return Promise.reject(new $("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401));let r=Ne(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:kn(n)})}):Promise.reject(new $(`Invalid form schema: ${r.error}`,400))}async submit(e,t,n){let r;try{r=await this.fetch(this.url(`/forms/${encodeURIComponent(e)}/responses`),{method:"POST",headers:{"Content-Type":"application/json",...jr},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(tt)})}catch(o){throw Br(o)}if(r.status===422)return{ok:!1,errors:(await r.json()).errors};if(!r.ok){let{message:o,code:s}=await Or(r,`Submit failed: ${r.status}`);throw new $(o,r.status,Dr(r),s)}let i=await r.json();return{ok:!0,responseId:i.id,duplicate:i.duplicate,updated:i.updated}}async fetchOwnResponse(e,t,n){try{return await this.json(`/forms/${encodeURIComponent(e)}/respondent-response`,{method:"POST",body:JSON.stringify({respondent:t,scopeValue:n})})}catch(r){if(G(r)&&(r.status===404||r.status===403))return null;throw r}}async startSession(e,t){try{let n=await this.fetch(this.url(`/forms/${encodeURIComponent(e)}/sessions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageCount:t}),signal:AbortSignal.timeout(tt)});return n.ok?(await n.json()).id:null}catch{return null}}reportProgress(e,t){try{this.fetch(this.url(`/sessions/${encodeURIComponent(e)}/progress`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0,signal:AbortSignal.timeout(tt)}).catch(()=>{})}catch{}}createDraft(e,t){return this.json(`/forms/${encodeURIComponent(e)}/drafts`,{method:"POST",body:JSON.stringify(t)})}getDraft(e,t,n){return this.json(`/drafts/${encodeURIComponent(e)}`,{headers:n?{"X-Fillo-Draft-Token":t,"X-Fillo-Draft-Adopt":"1"}:{"X-Fillo-Draft-Token":t}})}async saveDraft(e,t,n,r){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"X-Fillo-Draft-Token":t},body:JSON.stringify(n),...r?.keepalive?{keepalive:!0}:{}})}async deleteDraft(e,t){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-Fillo-Draft-Token":t}})}getUploadSession(e,t,n=AbortSignal.timeout(ce)){return this.json(`/uploads/${encodeURIComponent(e)}`,{...t?{headers:{"X-Fillo-Upload-Token":t}}:{},signal:n})}async uploadFile(e,t,n){let r=typeof File<"u"&&t instanceof File?t.name:"upload.bin",i=(t.type||"application/octet-stream").trim().toLowerCase(),o;if(n.sessionId){let c=await this.getUploadSession(n.sessionId,n.uploadToken,this.uploadSignal(n,ce));if(c.formId!==e||c.fieldId!==n.fieldId||c.fileName!==r||c.size!==t.size||c.mime.trim().toLowerCase()!==i)throw new $("File does not match this upload session",400);o=c,o.token||=n.uploadToken}else{let c=Rr(24),u=Rr(32),p=()=>this.json(`/forms/${encodeURIComponent(e)}/uploads`,{method:"POST",body:JSON.stringify({requestId:c,uploadToken:u,fieldId:n.fieldId,fileName:r,size:t.size,mime:i}),signal:this.uploadSignal(n,ce)}),h=Date.now()+ce,f=250;for(;;)try{o=await p();break}catch(m){if(n.signal?.aborted||!en(m,!0))throw m;let g=h-Date.now();if(g<=0)throw m;await Ur(Math.min(f,g),n.signal),f=Math.min(f*2,5e3)}}if(n.onSession?.({sessionId:o.id,uploadToken:o.token}),o.status==="complete"&&o.file)return o.file;if(o.status==="aborted")throw new $("This upload session was cancelled",409);let s;if(o.transport?.type==="gdrive")await this.driveUploadLoop(o,o.transport.uploadUrl,t,n);else if(o.transport?.type==="s3-multipart")await this.s3MultipartUploadLoop(o,t,n);else if(o.transport?.type==="s3-put")await this.s3PutUpload(o.transport.uploadUrl,t,n);else if(o.transport?.type==="box")s=await this.boxUpload(o.transport,t,n);else throw new $("This form's storage doesn't support uploads \u2014 connect Drive, S3, or Box.");let a=()=>this.json(`/uploads/${encodeURIComponent(o.id)}/complete`,{method:"POST",headers:o.token?{"X-Fillo-Upload-Token":o.token}:void 0,...s?{body:JSON.stringify(s)}:{},signal:this.uploadSignal(n,ce)}),l;try{l=await a()}catch(c){if(n.signal?.aborted||!en(c))throw c;let u=Date.now()+ce,p=250;for(;;){let h=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,u-Date.now())));if(h.status==="complete"&&h.file)return h.file;if(h.status==="aborted")throw c;try{l=await a();break}catch(m){if(n.signal?.aborted||!en(m,!0))throw m}let f=u-Date.now();if(f<=0)throw c;await Ur(Math.min(p,f),n.signal),p=Math.min(p*2,5e3)}}if(!l.file)throw new $("Upload completed but no file was returned");return l.file}async boxUpload(e,t,n){let r=kt(t.size,n);r(0);let i={Authorization:`Bearer ${e.token}`};if(e.mode==="simple"){let h=new FormData;h.append("attributes",JSON.stringify({name:e.fileName,parent:{id:e.folderId}})),h.append("file",t,e.fileName);let f=await this.retry(n,async()=>{let g=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:h,signal:this.uploadSignal(n)});if(!g.ok&&xt(g.status))throw new $(`Box upload failed: ${g.status}`,g.status);return g});if(!f.ok)throw new $(`Box upload failed: ${f.status}`,f.status);let m=await f.json();return r(t.size),{providerFileId:m.entries?.[0]?.id}}if(e.size!==t.size)throw new $(`File size changed since the upload was requested (${t.size} vs ${e.size}).`,400);let o=await this.retry(n,async()=>{let h=await this.fetch(e.sessionUrl,{method:"POST",headers:{...i,"Content-Type":"application/json"},body:JSON.stringify({folder_id:e.folderId,file_size:e.size,file_name:e.fileName}),signal:this.uploadSignal(n)});if(!h.ok&&xt(h.status))throw new $(`Box session failed: ${h.status}`,h.status);return h});if(!o.ok)throw new $(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new gi,l=[],c=0;for(;c<t.size;){n.signal?.throwIfAborted();let h=Math.min(c+s.part_size,t.size),f=new Uint8Array(await t.slice(c,h).arrayBuffer());a.update(f);let m=await hs(f),g=await this.retry(n,async()=>{let b=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${m}`,"Content-Range":`bytes ${c}-${h-1}/${t.size}`},body:f,signal:this.uploadSignal(n)});if(!b.ok&&xt(b.status))throw new $(`Box part failed: ${b.status}`,b.status);return b});if(!g.ok)throw new $(`Box part failed: ${g.status}`,g.status);l.push((await g.json()).part),c=h,r(c)}let u=await this.retry(n,async()=>{let h=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:{...i,"Content-Type":"application/json",Digest:`sha=${zn(a.digest())}`},body:JSON.stringify({parts:l}),signal:this.uploadSignal(n)});if(!h.ok&&xt(h.status))throw new $(`Box commit failed: ${h.status}`,h.status);return h});if(!u.ok)throw new $(`Box commit failed: ${u.status}`,u.status);return{providerFileId:(await u.json()).entries?.[0]?.id}}uploadSignal(e,t=tt){let n=AbortSignal.timeout(t);return e.signal?AbortSignal.any([e.signal,n]):n}async retry(e,t){let n=0;for(;;)try{return await t()}catch(r){if(e.signal?.aborted||(n+=1,n>=et))throw r;await new Promise(i=>setTimeout(i,500*2**n))}}async driveUploadLoop(e,t,n,r){let i=e.uploadedBytes,o=kt(n.size,r);o(i);let s=0;for(;i<n.size;){r.signal?.throwIfAborted();let a=i,l=Math.min(i+e.chunkSize,n.size),c=n.slice(i,l),u=0;for(;;)try{let p=await this.fetch(t,{method:"PUT",headers:{"Content-Range":`bytes ${i}-${l-1}/${n.size}`},body:c,signal:this.uploadSignal(r)});if(p.status===308){let h=p.headers.get("Range")??p.headers.get("range"),f=h?.match(/bytes=0-(\d+)/);f?i=Number(f[1])+1:h==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ce))).uploadedBytes;break}if(p.ok){i=n.size;break}throw new $(`Drive chunk failed: ${p.status}`,p.status)}catch(p){if(r.signal?.aborted||(u+=1,u>=et))throw p;if(await new Promise(f=>setTimeout(f,500*2**u)),i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ce))).uploadedBytes,i>=n.size)break;l=Math.min(i+e.chunkSize,n.size),c=n.slice(i,l)}if(o(i),i<=a){if(++s>=et)throw new $("Drive upload stalled \u2014 the storage endpoint stopped accepting progress",0)}else s=0}}async s3MultipartUploadLoop(e,t,n){if(!Number.isSafeInteger(e.chunkSize)||e.chunkSize<=0||!Number.isSafeInteger(e.uploadedBytes)||e.uploadedBytes<0||e.uploadedBytes>t.size||e.uploadedBytes<t.size&&e.uploadedBytes%e.chunkSize!==0)throw new $("S3 upload session returned invalid progress",502);let r=kt(t.size,n),i=e.uploadedBytes;for(r(i);i<t.size;){n.signal?.throwIfAborted();let o=Math.floor(i/e.chunkSize)+1;if(o>1e4)throw new $("S3 upload needs too many parts",413);let s=Math.min(i+e.chunkSize,t.size),a=t.slice(i,s),l=0;for(;;){let c;try{let u=await this.json(`/uploads/${encodeURIComponent(e.id)}/parts`,{method:"POST",headers:e.token?{"X-Fillo-Upload-Token":e.token}:void 0,body:JSON.stringify({partNumber:o}),signal:this.uploadSignal(n,ce)});if(typeof u.uploadUrl!="string"||!u.uploadUrl)throw new $("S3 part URL was unavailable",502);c=u.uploadUrl;let p=await this.fetch(c,{method:"PUT",body:a,signal:this.uploadSignal(n,ds)});if(!p.ok)throw new $(`S3 part upload failed: ${p.status}`,p.status);i=s,r(i);break}catch(u){if(n.signal?.aborted)throw u;let p=await this.getUploadSession(e.id,e.token,this.uploadSignal(n,ce));if(p.status==="aborted")throw new $("This upload session was cancelled",409);if(!Number.isSafeInteger(p.uploadedBytes)||p.uploadedBytes<i||p.uploadedBytes>t.size||p.uploadedBytes<t.size&&p.uploadedBytes%e.chunkSize!==0)throw new $("S3 upload session returned invalid progress",502);if(p.uploadedBytes>i){i=p.uploadedBytes,r(i);break}if(l+=1,l>=et)throw u;await new Promise(h=>setTimeout(h,500*2**l))}}}}async s3PutUpload(e,t,n){let r=kt(t.size,n);r(0);let i=0;for(;;)try{let o=await this.fetch(e,{method:"PUT",headers:{"Content-Type":t.type||"application/octet-stream"},body:t,signal:this.uploadSignal(n)});if(!o.ok)throw new $(`S3 upload failed: ${o.status}`,o.status);r(t.size);return}catch(o){if(n.signal?.aborted||(i+=1,i>=et))throw o;await new Promise(s=>setTimeout(s,500*2**i))}}};function st(e={}){return new Et(e)}function tn(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function Vr(e,t){let n={};for(let r of ze(e)){let i=r.kind==="hidden"?t[r.paramName??r.id]??r.defaultValue:t[r.id];if(!(i===void 0||i===""))switch(r.kind){case"number":{let o=tn(i);if(o===null||r.min!==void 0&&o<r.min||r.max!==void 0&&o>r.max)break;n[r.id]=o;break}case"rating":{let o=tn(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=tn(i),s=r.min??1,a=r.max??10;o!==null&&Number.isInteger(o)&&o>=s&&o<=a&&(n[r.id]=o);break}case"checkbox":n[r.id]=i==="true"||i==="1"||i==="yes";break;case"select":case"dropdown":{r.options.some(o=>o.id===i)&&(n[r.id]=i);break}case"multi_select":{let o=new Set(r.options.map(a=>a.id)),s=[...new Set(i.split(",").filter(a=>o.has(a)))];s.length>0&&(n[r.id]=s);break}case"file_upload":case"ranking":case"matrix":case"signature":case"custom":break;case"calculated":break;default:n[r.id]=i}}return n}var gs={id:"empty",blocks:[]},Hr=!1,qr=!1;function bs(){qr||(qr=!0,console.warn("[fillo] This form has a client but no submission target \u2014 a bare schema can't sync. Wrap it in defineForm({ id, pages }) (or author it with <Fillo.Form id=\u2026>) so it gets a workspace handle, or pass formId for a dashboard-built form: https://fillo.so/docs"))}function vs(){Hr||(Hr=!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"))}var bi=new Map;function Sn(){try{return globalThis.localStorage??null}catch{return null}}function vi(e){return`fillo:submission:${e}`}function En(){let e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();let t=new Uint8Array(16);return e?.getRandomValues?(e.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")):`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function yi(e,t,n,r){let i=Sn();if(!i)return e.get(n)??null;try{let o=JSON.parse(i.getItem(t)??"null");if(o&&r(o))return o}catch{}return null}function wi(e,t,n,r){e.set(n,r);let i=Sn();if(i)try{i.setItem(t,JSON.stringify(r))}catch{}}function An(e){return yi(bi,vi(e),e,t=>typeof t.key=="string")}function _i(e,t){wi(bi,vi(e),e,t)}function ys(e){let t=An(e);if(t?.key)return t.key;let n={key:En()};return _i(e,n),n.key}function ws(e,t){let n=An(e);_i(e,{key:n?.key??En(),submittedAt:new Date().toISOString(),responseId:t})}function gn(e,t,n){let r=ei(e.settings,n);return r===null?t:`${t}::${r}`}function Wr(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!An(gn(e,t,n))?.submittedAt}var Cn=new Map;function Fn(e){return`fillo:draft:${e}`}function $t(e){return yi(Cn,Fn(e),e,t=>{let n=t;return typeof n.id=="string"&&typeof n.token=="string"})}function nn(e,t){wi(Cn,Fn(e),e,t)}function rn(e){Cn.delete(e);let t=Sn();if(t)try{t.removeItem(Fn(e))}catch{}}function on(e){return G(e)&&(e.status===401||e.status===403||e.status===404)}var _s=1500,xs="Please complete the verification check, then submit.",ks="That verification didn't go through. Please complete the check again and resubmit.";function xi(e){return G(e)&&e.status&&e.status>0&&e.message?e.message:"Couldn't reach the server \u2014 check your connection and try again. If this keeps happening, a browser extension, firewall, or the site's Content-Security-Policy may be blocking the request."}function $s(e,t){if(G(e)){let n=e.status??0;if(t&&n>0&&e.message)return e.code?`${e.message} (${e.code})`:e.message;if(n>0&&n<500&&n!==408&&n!==429)return"This form is unavailable."}return xi(e)}function ki(e){let{onChange:t,onSubmitted:n}=e,r=Ne(e.form);if(!r.ok)throw new Error(`Invalid form schema: ${r.error}`);let i=r.schema,o=e.formId,s=e.client,a=e.respondent,l=Ze(i,{...e.initialData??{}}),c={},u=0,p="idle",h=!1,f=!1;queueMicrotask(()=>{if(typeof location<"u"&&location.search){let _=Object.fromEntries(new URLSearchParams(location.search)),w=null;for(let[k,N]of Object.entries(Vr(i,_)))l[k]===void 0&&(w=w??{...l},w[k]=N);w&&p==="idle"&&(l=Ze(i,w),E())}p==="idle"&&Wr(i,o,l)&&(p="submitted",h=!0,E());let v=!1;if(i.settings.saveProgress&&o&&s&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let _=/fillo-draft=([^&]+)/.exec(location.hash),w=_?.[1]?decodeURIComponent(_[1]):"",k=w.indexOf(".");if(k>0){v=!0;let N=w.slice(0,k),F=w.slice(k+1);s.getDraft(N,F,!0).then(P=>{nn(o,{id:N,token:P.token??F});try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(P=>{on(P)&&(f=!0,E())}).finally(()=>Y())}}v||Y()});let m,g=new Set,b=new Set,z=Date.now(),I=En(),C=null,ie=!1,oe=!1,Se=!1,X="created",Ee=!1,O=null,U=null,se=Promise.resolve(),ae=!1,Ve=!1,Te=!1,x=!1;function re(){let v=i.pages.length,_=Math.min(u,Math.max(v-1,0)),w=i.pages[_]??gs;return{data:l,errors:c,status:p,pageIndex:_,pageCount:v,page:w,blocks:vt(i,w,l),isFirstPage:_===0,isLastPage:dn(i,w.id,l),uploading:g.size>0,submitError:m,restoredSubmission:h,resumedDraft:oe,editingPrevious:Se,duplicateSubmission:X==="duplicate",updatedSubmission:X==="updated",resumeLinkFailed:f}}let R=re();function E(){R=re();for(let v of b)v()}function He(v,_){try{n?.(v,_)}catch(w){console.error("[fillo] onSubmitted handler threw:",w)}}function Pe(v){let _=i.pages[v];if(!_)return{};let w={};for(let k of vt(i,_,l)){if(!te(k))continue;let N=ci(k,l[k.id]);N&&(w[k.id]=N)}return w}function Ae(){return!!(i.settings.saveProgress&&s&&o&&!Ve)}function M(){let v=new Set;for(let _ of i.pages)for(let w of _.blocks)te(w)&&v.add(w.id);return v}function V(v){if(p!=="idle"||ie)return;let _=M(),w=null;for(let[F,P]of Object.entries(v.data??{}))l[F]===void 0&&_.has(F)&&(w=w??{...l},w[F]=P);let k=typeof v.page=="number"&&Number.isFinite(v.page)?Math.max(0,Math.min(Math.floor(v.page),i.pages.length-1)):0,N=k>0&&u===0;!w&&!N||(w&&(l=Ze(i,w)),N&&(u=k),oe=!0,E())}function Y(){if(p!=="idle")return;if(!Ae()){ge();return}let v=o,_=s,w=O??$t(v);if(w&&!Te){Te=!0,O=w,_.getDraft(w.id,w.token).then(V).catch(k=>{on(k)&&(rn(v),O=null)});return}!w&&!x&&a?.hash&&(x=!0,_.createDraft(v,{data:{},page:0,respondent:a}).then(k=>{if(!O){if(O={id:k.id,token:k.token},nn(v,O),k.existing)return _.getDraft(k.id,k.token).then(V);ge()}}).catch(k=>{G(k)&&k.status!==void 0&&k.status>=400&&k.status<500||(x=!1)}))}function ge(){if(Ee||i.settings.responseLimit?.onRepeat!=="update"||!s||!o||!a?.hash||p!=="idle")return;Ee=!0;let v=s,_=ei(i.settings,l)??void 0;v.fetchOwnResponse(o,a,_).then(w=>{!w||p!=="idle"||ie||oe||(V({data:w.data,page:0}),oe&&(oe=!1,Se=!0,E()))}).catch(()=>{})}function Nt(v=!1){if(U&&(clearTimeout(U),U=null),!Ae()||p!=="idle"||!ae)return;let _=o,w=s;ae=!1,se=se.then(async()=>{let k={data:l,page:Math.max(0,Math.min(u,i.pages.length-1))},N=O??$t(_);try{if(N)try{await w.saveDraft(N.id,N.token,k,v?{keepalive:!0}:void 0),O=N;return}catch(P){if(!on(P))throw P;rn(_),O=null}let F=await w.createDraft(_,a?.hash?{...k,respondent:a}:k);O={id:F.id,token:F.token},nn(_,O),F.existing&&(ae=!0)}catch(F){G(F)&&F.status!==void 0&&F.status>=400&&F.status<500&&F.status!==429?Ve=!0:ae=!0}})}function Hi(){!Ae()||p!=="idle"||(ae=!0,U&&clearTimeout(U),U=setTimeout(()=>{U=null,Nt()},_s))}function On(){!Ae()||!ie&&!O||(ae=!0,Nt())}function Dn(){U&&(clearTimeout(U),U=null),ae=!1,o&&rn(o),O=null}function qi(v,_){!ie&&s&&o&&(ie=!0,s.startSession(o,i.pages.length).then(w=>C=w)),l=Ze(i,{...l,[v]:_}),t?.(l),m=void 0,v in c&&(c=Object.fromEntries(Object.entries(c).filter(([w])=>w!==v))),E(),Hi()}function Wi(v,_){_?g.add(v):g.delete(v),E()}function Un(v){if(v.length===0)return-1;let _=i.pages.length,w=Math.min(u,Math.max(_-1,0)),k=i.pages[w]?.id,N=k===void 0?-1:v.indexOf(k);if(N>=0)return N;let F=0;for(let P=0;P<v.length;P++){let pe=i.pages.findIndex(Tt=>Tt.id===v[P]);pe>=0&&pe<=w&&(F=P)}return F}function Ki(){let v=i.pages.length,_=Math.min(u,Math.max(v-1,0));if(!e.skipValidation){let pe=Pe(_);if(c=pe,Object.keys(pe).length>0){E();return}}let w=i.pages[_],k=De(i,l),N=Un(k);if((w?dn(i,w.id,l):!0)||N<0||N+1>=k.length){Bn();return}let P=i.pages.findIndex(pe=>pe.id===k[N+1]);u=P>=0?P:Math.min(_+1,v-1),C&&s&&s.reportProgress(C,{furthestPage:u}),E(),On()}function Gi(){c={};let v=De(i,l),_=Un(v);if(_>0){let w=i.pages.findIndex(k=>k.id===v[_-1]);u=w>=0?w:Math.max(Math.min(u,i.pages.length-1)-1,0)}else if(v.length>0){let w=i.pages.findIndex(k=>k.id===v[0]);u=w>=0?w:0}E(),On()}async function Bn(){if(p==="submitting"||p==="submitted")return;let v=ui(i,l);if(!v.ok){c=v.errors;let _=i.pages.findIndex(w=>vt(i,w,l).some(k=>k.id in v.errors));_>=0&&(u=_),E();return}if(s&&e.resolveFormId){p="submitting",m=void 0,E();try{o=await e.resolveFormId()}catch(_){throw p="idle",m=$s(_,e.verboseResolutionErrors===!0),E(),_}}if(s&&o){let _=i.settings.responseLimit?.by==="browser"?ys(gn(i,o,v.data)):void 0,w=_??I,k=i.settings.saveProgress?O??$t(o):null,N=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!N){p="idle",m=xs,E();return}p="submitting",m=void 0,E();let F;try{F=await s.submit(o,v.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-z,surface:e.surface??"headless",submissionKey:w,draft:k?{id:k.id,token:k.token}:void 0,respondent:a,challengeToken:N})}catch(P){if(p="idle",G(P)&&P.code==="challenge_failed"){m=ks,e.onChallengeFailed?.(),E();return}throw m=xi(P),E(),P}if(!F.ok){c=F.errors??{};let P=i.pages.findIndex(pe=>vt(i,pe,l).some(Tt=>Tt.id in c));P>=0?u=P:m="We couldn't submit \u2014 please review your answers.",p="idle",E();return}X=F.duplicate?"duplicate":F.updated?"updated":"created",C&&s.reportProgress(C,{completed:!0}),_&&ws(gn(i,o,v.data),F.responseId),Dn(),p="submitted",E(),He(F.responseId,v.data);return}if(e.skipValidation){p="submitted",E(),He(void 0,v.data);return}s&&!o?bs():vs(),p="error",E()}return{getState:()=>R,subscribe(v){return b.add(v),()=>{b.delete(v)}},setValue:qi,setUploading:Wi,next:Ki,back:Gi,submit:Bn,setContext(v){if("formId"in v&&(o=v.formId),"client"in v&&(s=v.client),"respondent"in v&&(a=v.respondent),v.form&&v.form!==i){let _=Ne(v.form);if(!_.ok)throw new Error(`Invalid form schema: ${_.error}`);i=_.schema,l=Ze(i,l)}p==="idle"&&Wr(i,o,l)&&(p="submitted",h=!0),Y(),E()},flushDraft(){Nt(!0)},resetDraft(){if(p==="submitting")return;let v=O??(o?$t(o):null);if(Dn(),v&&s&&s.deleteDraft(v.id,v.token).catch(()=>{}),l={...e.initialData??{}},typeof location<"u"&&location.search){let _=Object.fromEntries(new URLSearchParams(location.search));for(let[w,k]of Object.entries(Vr(i,_)))l[w]===void 0&&(l[w]=k)}l=Ze(i,l),c={},u=0,m=void 0,oe=!1,Se=!1,E()},destroy(){U&&(clearTimeout(U),U=null),b.clear()}}}function zs(e){return te(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function $i(e){let t=e.filter(n=>te(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!zs(t[0])}function zi(e,t,n){if(n.form.settings.submitMode!=="auto"||n.status!=="idle"||n.uploading||!(()=>{switch(e.kind){case"select":case"dropdown":return typeof t=="string"&&e.options.some(a=>a.id===t);case"checkbox":return t===!0;case"rating":case"linear_scale":return typeof t=="number";default:return!1}})()||t===n.data[e.id])return!1;let i={...n.data,[e.id]:t},o=n.form.pages.find(a=>a.blocks.some(l=>l.id===e.id));if(!o||!dn(n.form,o.id,i))return!1;let s=ri(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:ui(n.form,i).ok}function Si(e,t,n,r){if(n<=0)return null;let i=r?.rtl??!1;if(e==="Home")return 0;if(e==="End")return n-1;let o;switch(e){case"ArrowRight":o=i?-1:1;break;case"ArrowLeft":o=i?1:-1;break;case"ArrowDown":o=1;break;case"ArrowUp":o=-1;break;default:return null}let s=t+o;return Math.min(n-1,Math.max(0,s))}var Ss=Math.sqrt(1.05*.05)-.05,Es=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,As=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function sn(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Cs(e){let t=e.trim(),n=null,r=Es.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=As.exec(t);a&&(n=`${a[1]}${a[1]}${a[2]}${a[2]}${a[3]}${a[3]}`)}if(!n)return null;let i=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),s=parseInt(n.slice(4,6),16);return .2126*sn(i)+.7152*sn(o)+.0722*sn(s)}function Ei(e){if(!e||e.colorScheme||!e.background||!e.text)return e;let t=Cs(e.background);return t==null?e:{...e,colorScheme:t>Ss?"light":"dark"}}function In(e){return{id:e.id,theme:e.theme,schema:{version:1,title:e.title??"",description:e.description,pages:e.pages,settings:e.settings??{}},__filloCodeForm:!0}}function Nn(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var xe=new Map,Fs=e=>new Promise(t=>setTimeout(t,e));function Is(e){if(!G(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function Ns(e,t){let n=800;for(let r=0;;r++)try{return await e.syncForm(t.id,t.schema,t.theme??null)}catch(i){if(!Is(i)||r>=2)throw i;let o=G(i)?i.retryAfterSec:void 0;await Fs(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function Ts(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Ai(e,t){let n=r=>{if(Array.isArray(r))return r.map(n);if(r&&typeof r=="object"){let i=r;return Object.fromEntries(Object.keys(i).sort().map(o=>[o,n(i[o])]))}return r};return JSON.stringify(n(e))===JSON.stringify(n(t))}var bn=e=>e==="published"?36e5:6e4,Ps=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function Ci(e,t){return`fillo:sync:v4:${e.baseUrl}|${e.key}|${t}`}function Ms(e,t,n){try{let r=globalThis.localStorage?.getItem(Ci(e,t));if(!r)return null;let i=JSON.parse(r);if(typeof i.formId!="string"||typeof i.slug!="string"||i.hash!==n||typeof i.ts!="number"||i.uploadFileSizeLimitMb!==void 0&&(typeof i.uploadFileSizeLimitMb!="number"||!Number.isFinite(i.uploadFileSizeLimitMb)||i.uploadFileSizeLimitMb<=0)||i.status!==void 0&&i.status!=="draft"&&i.status!=="published")return null;let o=bn(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function Ls(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(Ci(e,t),JSON.stringify({formId:r.formId,slug:r.slug,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function Tn(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=Ts(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=xe.get(o);if(s&&!n?.bypassCache){if(s.expiresAt===null||s.expiresAt>Date.now())return s.promise;xe.delete(o)}if(!n?.bypassCache){let c=Ms(e,t.id,i);if(c){let u=Promise.resolve({formId:c.formId,slug:c.slug,status:c.status,uploadFileSizeLimitMb:c.uploadFileSizeLimitMb});return xe.set(o,{promise:u,expiresAt:c.ts+bn(c.status)}),u}}let a=Ns(e,t),l={promise:a,expiresAt:null};return xe.set(o,l),a.then(c=>{if(xe.get(o)===l){if(Ps(c)){xe.delete(o);return}l.expiresAt=Date.now()+bn(c.status),Ls(e,t.id,i,c)}},()=>{xe.get(o)===l&&xe.delete(o)}),a}var Zs=class extends Error{constructor(e,t){super(`[fillo] ${t} \u2014 https://fillo.so/docs/troubleshooting#jsx-${e.toLowerCase()}`),this.code=e,this.name="FilloJsxError"}code},Rs=Symbol.for("fillo.block");var Os=["label","description","required","placeholder"],Z=(e,t,n,r={})=>({name:e,kind:t,props:[...Os,...n],...r}),Kr=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),an=["options","allowOther","shuffleOptions"],Ds=[Z("Text","short_text",["maxLength"]),Z("LongText","long_text",["maxLength"]),Z("Email","email",["maxLength"]),Z("Url","url",["maxLength"]),Z("Phone","phone",["defaultCountry"]),Z("Number","number",["min","max","decimals","prefix","suffix","notation"]),Z("Select","select",an,{optionChildren:!0}),Z("MultiSelect","multi_select",an,{optionChildren:!0}),Z("Dropdown","dropdown",an,{optionChildren:!0}),Z("Checkbox","checkbox",["appearance"]),Z("Rating","rating",["max","insightsMetric"]),Z("Scale","linear_scale",["min","max","minLabel","maxLabel","insightsMetric"]),Z("Ranking","ranking",["options"],{optionChildren:!0}),Z("Matrix","matrix",["rows","columns"]),Z("Signature","signature",[]),Z("Date","date",[]),Z("FileUpload","file_upload",["maxFiles","maxFileSizeMb","accept"]),Z("Hidden","hidden",["paramName","defaultValue"]),Z("Calculated","calculated",["calc","decimals","prefix","suffix"]),Z("Custom","custom",["component","config"]),Kr("Heading","heading",!0),Kr("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],Us={name:"Page",kind:"__page",props:["title"]},Bs={name:"Option",kind:"__option",props:["label","icon"]};function ln(e){let t=()=>{throw new Zs("RENDERED_INERT",`<Fillo.${e.name}> was rendered by React. Fillo fields are schema declarations, valid only inside <Fillo.Form> or Fillo.defineForm(). If this form lives in a server component, move it to a client module ("use client")`)};return t[Rs]=e,t}var gd=Object.fromEntries([...Ds.map(e=>[e.name,ln(e)]),["Page",ln(Us)],["Option",ln(Bs)]]);function js(e){let t=e.toLowerCase();return t==="localhost"||t.endsWith(".localhost")||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t)||t==="::1"||t==="[::1]"||t==="0.0.0.0"}function Pn(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Fi(){if(Pn())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&js(e)}var Vs=/\{\{\s*([\w-]+)\s*\}\}/g;function cn(e,t,n){if(!e.includes("{{"))return e;let r=ze(n);return e.replace(Vs,(i,o)=>{let s=r.find(c=>c.id===o),a=t[o];if(a==null||a==="")return"";let l=c=>s&&"options"in s?s.options.find(u=>u.id===c)?.label??c:c;return Array.isArray(a)?a.map(c=>l(String(c))).join(", "):typeof a=="string"?l(a):String(a)})}function Ii(e,t,n){let r=i=>i===void 0?i:cn(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:cn(e.text,t,n)};case"divider":return e;default:return{...e,label:cn(e.label,t,n),description:r(e.description)}}}var Hs="fillo-",qs=0,Ct='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ni(e){return e.matches(Ct)?e:e.querySelector(Ct)}function Ti(e,t){let n=`${Hs}${e}-${t}`;return{inputId:n,labelId:`${n}-label`,descriptionId:`${n}-desc`,errorId:`${n}-error`,name:n}}function d(e,t={}){let n=document.createElement(e);t.className&&(n.className=t.className),t.text!==void 0&&(n.textContent=t.text);for(let[r,i]of Object.entries(t.attrs??{}))n.setAttribute(r,i);return n}function Be(e,t){let n=Ei(kn(t));n&&(n.colorScheme&&e.setAttribute("data-fillo-color-scheme",n.colorScheme),n.primary&&e.style.setProperty("--fillo-primary",n.primary),n.background&&e.style.setProperty("--fillo-bg",n.background),n.text&&e.style.setProperty("--fillo-text",n.text),n.radius&&e.style.setProperty("--fillo-radius",n.radius),n.fontFamily&&e.style.setProperty("--fillo-font",n.fontFamily),(n.primary||n.background||n.text)&&e.setAttribute("data-fillo-has-color-theme",""))}function ut(e){try{if(!e)return null;let t=new URL(e);return t.protocol!=="http:"&&t.protocol!=="https:"?null:t.toString()}catch{return null}}function Ws(e){let t=new URL(ut(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function Ft(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Pi(e,t){let n=Ft(e);if(n==="")return n;let r=Number(n);return Number.isFinite(r)?hi(r,{decimals:t}):n}function A(e,t){for(let n of t)n&&e.appendChild(n);return e}var Mi="http://www.w3.org/2000/svg",Ks={thumbs_up:"M7 10v10M7 10l4.8-6.1a2 2 0 0 1 3.5 1.7L14.6 10h4.8a2.1 2.1 0 0 1 2 2.5l-1.1 5.4A3 3 0 0 1 17.4 20H7M3 10h4v10H3z",thumbs_down:"M7 14V4M7 14l4.8 6.1a2 2 0 0 0 3.5-1.7L14.6 14h4.8a2.1 2.1 0 0 0 2-2.5l-1.1-5.4A3 3 0 0 0 17.4 4H7M3 4h4v10H3z"};function Bi(e){if(!e)return null;let t=document.createElementNS(Mi,"svg");t.setAttribute("class","fillo-option-icon"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none"),t.setAttribute("stroke","currentColor"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linecap","round"),t.setAttribute("stroke-linejoin","round"),t.setAttribute("aria-hidden","true");let n=document.createElementNS(Mi,"path");return n.setAttribute("d",Ks[e]),t.appendChild(n),t}function W(e,t,n,r){n&&e.setAttribute("aria-invalid","true"),t.required&&e.setAttribute("aria-required","true");let i=[t.description?r.descriptionId:null,n?r.errorId:null].filter(Boolean).join(" ");i&&e.setAttribute("aria-describedby",i)}function ji(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=Si(i.key,s,t.length,{rtl:o});if(a===null)return;i.preventDefault();let l=t[a];l!==void 0&&(r(l),e.querySelectorAll('[role="radio"]')[a]?.focus())})}function ne(e,t,n,r){let i=d("div",{className:`fillo-field fillo-field--${e.kind}${t?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.id,"data-kind":e.kind}});i.toggleAttribute("data-invalid",!!t),i.toggleAttribute("data-required",!!e.required);let o=d("label",{className:"fillo-label",text:e.label,attrs:{id:r.labelId,for:r.inputId,"data-fillo":"label"}});return e.required||o.appendChild(d("span",{className:"fillo-optional",text:" (optional)"})),i.appendChild(o),e.description&&i.appendChild(d("p",{className:"fillo-description",text:e.description,attrs:{id:r.descriptionId,"data-fillo":"fieldDescription"}})),i.appendChild(n),t&&i.appendChild(d("p",{className:"fillo-error",text:t,attrs:{id:r.errorId,"data-fillo":"error"}})),i}function at(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation==="grouped",o=i||!!r?.prefix||!!r?.suffix,s=d("input",{className:"fillo-input",attrs:{id:t.ids.inputId,type:o?"text":e,"data-fillo":"control"}});if(o&&s.setAttribute("inputmode","decimal"),e==="email"?s.setAttribute("autocomplete","email"):e==="url"&&s.setAttribute("autocomplete","url"),s.value=i?Pi(t.value,r?.decimals):Ft(t.value),n.placeholder&&(s.placeholder=n.placeholder),"maxLength"in n&&n.maxLength!==void 0&&(s.maxLength=n.maxLength),r&&!o&&(r.min!==void 0&&(s.min=String(r.min)),r.max!==void 0&&(s.max=String(r.max))),o){let l=s.value,c=s.value.length,u=()=>{s.value=l,s.setSelectionRange(c,c)};i?(s.addEventListener("input",()=>{if(!ot(s.value))return u();l=s.value,c=s.selectionStart??s.value.length,t.setValue($n(s.value),{render:!1})}),s.addEventListener("change",()=>{if(!ot(s.value))return u();l=s.value,t.setValue($n(s.value))}),s.addEventListener("blur",()=>{let p=t.getValue?.()??t.value;s.value=Pi(p,r?.decimals),l=s.value,c=s.value.length})):(s.addEventListener("input",()=>{if(!ot(s.value))return u();l=s.value,c=s.selectionStart??s.value.length,t.setValue(s.value,{render:!1})}),s.addEventListener("change",()=>{if(!ot(s.value))return u();l=s.value,t.setValue(s.value)}))}else s.addEventListener("input",()=>t.setValue(s.value,{render:!1})),s.addEventListener("change",()=>t.setValue(s.value));W(s,n,t.error,t.ids);let a=s;return r&&(r.prefix||r.suffix)&&(a=A(d("div",{className:"fillo-number"}),[r.prefix?d("span",{className:"fillo-number-prefix",text:r.prefix}):null,s,r.suffix?d("span",{className:"fillo-number-suffix",text:r.suffix}):null])),ne(n,t.error,a,t.ids)}function Gs(){if(typeof navigator>"u")return;let t=(navigator.languages?.[0]||navigator.language||"").split("-")[1];return t&&/^[A-Za-z]{2}$/.test(t)?t.toUpperCase():void 0}function Js(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function Xs(e,t){if(t<=0)return e.setSelectionRange(0,0);let n=e.value,r=0,i=n.length;for(let o=0;o<n.length;o++)if(/\d/.test(n[o])&&++r===t){i=o+1;break}e.setSelectionRange(i,i)}function Ys(e){let t=e.field,n=it(Ft(e.value)).country??St(t.defaultCountry)??oi(Js())??St(Gs())??nt[0],r=d("div",{className:"fillo-phone"}),i=d("div",{className:"fillo-phone-country"}),o=d("button",{className:"fillo-phone-flag",attrs:{type:"button","aria-haspopup":"listbox","aria-expanded":"false"}}),s=d("span",{className:"fillo-phone-flag-emoji",attrs:{"aria-hidden":"true"}}),a=d("span",{className:"fillo-phone-dial"});A(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),A(i,[o]);let l=d("input",{className:"fillo-input fillo-phone-input",attrs:{id:e.ids.inputId,type:"tel",inputmode:"tel",autocomplete:"tel-national","data-fillo":"control"}});W(l,e.field,e.error,e.ids);let c=()=>e.getValue?.()??e.value,u=()=>{let x=de(Ft(c()));return x.startsWith(n.dialCode)?x.slice(n.dialCode.length):x},p=()=>{s.textContent=wn(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},h=()=>{l.value=rt(n,u()),l.placeholder=rt(n,n.example)},f=x=>e.setValue(x?si(n,x):"",{render:!1}),m=x=>e.setValue(x,{render:!1});p(),h(),l.addEventListener("input",()=>{let x=l.value,re=l.selectionStart??x.length,R=de(x.slice(0,re)).length;if(x.trimStart().startsWith("+")){let E=it(x,n,{previousDigits:u()});if(E.pending){m(E.raw??x);return}E.country&&(n=E.country,p()),f(E.country?E.national:de(x))}else f(de(x));l.value=rt(n,u()),Xs(l,R)});let g=e.registerOverlay,b=e.announce,z=null,I=0,C=Ue,ie=null,oe=null,Se,X=`${e.ids.inputId}-countries`,Ee=()=>{if(!z)return;let x=ai(i,z);z.classList.toggle("fillo-phone-popover--above",x==="above"),z.classList.toggle("fillo-phone-popover--below",x==="below")},O=()=>{ie?.();let x=()=>Ee();Ee(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),ie=()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},U=x=>{let re=x.relatedTarget;if(re){i.contains(re)||se();return}queueMicrotask(()=>{z&&!i.contains(document.activeElement)&&se()})},se=()=>{clearTimeout(Se),ie?.(),ie=null,z?.remove(),z=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",ae),i.removeEventListener("focusout",U),oe?.(),oe=null},ae=x=>{i.contains(x.target)||se()},Ve=x=>{x&&(n=x,p(),f(u()),h(),se(),b?.(J.phoneCountrySelected(x.name)),l.focus())},Te=x=>{let re=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),R=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":X,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});x&&(R.value=x);let E=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:X,"aria-label":"Country"}}),He=()=>{if(E.replaceChildren(),C.length===0){E.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),R.removeAttribute("aria-activedescendant"),Ee();return}C.forEach((M,V)=>{let Y=d("li",{className:`fillo-phone-option${V===I?" fillo-phone-option--active":""}`,attrs:{id:`${X}-opt-${V}`,role:"option","aria-selected":String(M.iso2===n.iso2)}});A(Y,[d("span",{className:"fillo-phone-flag-emoji",text:wn(M.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:M.name}),d("span",{className:"fillo-phone-option-dial",text:`+${M.dialCode}`})]),Y.addEventListener("mouseenter",()=>{I=V,R.setAttribute("aria-activedescendant",Y.id),Pe()}),Y.addEventListener("mousedown",ge=>{ge.preventDefault(),Ve(M)}),E.appendChild(Y)}),R.setAttribute("aria-activedescendant",`${X}-opt-${I}`),Ee()},Pe=()=>{[...E.children].forEach((M,V)=>M.classList.toggle("fillo-phone-option--active",V===I)),document.getElementById(`${X}-opt-${I}`)?.scrollIntoView({block:"nearest"})},Ae=M=>{let V=M.trim().toLowerCase(),Y=V.replace(/[^\d]/g,"");C=V?Ue.filter(ge=>ge.name.toLowerCase().includes(V)||ge.iso2.toLowerCase()===V||Y.length>0&&ge.dialCode.startsWith(Y)):Ue,I=0,He(),clearTimeout(Se),Se=setTimeout(()=>b?.(J.phoneResultsCount(C.length)),300)};R.addEventListener("input",()=>Ae(R.value)),R.addEventListener("keydown",M=>{if(M.key==="ArrowDown"){if(M.preventDefault(),C.length===0)return;I=Math.min(I+1,C.length-1),Pe(),R.setAttribute("aria-activedescendant",`${X}-opt-${I}`)}else if(M.key==="ArrowUp"){if(M.preventDefault(),C.length===0)return;I=Math.max(I-1,0),Pe(),R.setAttribute("aria-activedescendant",`${X}-opt-${I}`)}else M.key==="Enter"?(M.preventDefault(),Ve(C[I])):M.key==="Escape"&&(M.preventDefault(),se(),o.focus())}),A(re,[R,E]),z=re,i.appendChild(re),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",X),x?Ae(x):(C=Ue,I=Math.max(0,Ue.indexOf(n)),He()),O(),Pe(),document.addEventListener("mousedown",ae),i.addEventListener("focusout",U),oe=g?.(se)??null,requestAnimationFrame(()=>{if(R.focus(),x){let M=R.value.length;R.setSelectionRange(M,M)}})};return o.addEventListener("click",()=>z?se():Te()),o.addEventListener("keydown",x=>{if(!z){if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault(),Te();return}x.key.length===1&&x.key!==" "&&!x.ctrlKey&&!x.metaKey&&!x.altKey&&(x.preventDefault(),Te(x.key))}}),A(r,[i,l]),ne(e.field,e.error,r,e.ids)}function Qs(e){let t=d("textarea",{className:"fillo-input fillo-textarea",attrs:{id:e.ids.inputId,rows:"4","data-fillo":"control"}});return t.value=typeof e.value=="string"?e.value:"",e.field.placeholder&&(t.placeholder=e.field.placeholder),"maxLength"in e.field&&e.field.maxLength!==void 0&&(t.maxLength=e.field.maxLength),t.addEventListener("input",()=>e.setValue(t.value,{render:!1})),t.addEventListener("change",()=>e.setValue(t.value)),W(t,e.field,e.error,e.ids),ne(e.field,e.error,t,e.ids)}function ea(e){let t=e.field,n=Zn(t),r=typeof e.value=="string"?e.value:"",i=e.activeOtherFields,o=r!==""&&!t.options.some(l=>l.id===r),s=o||r===""&&i?.has(t.id)===!0,a=d("div",{className:"fillo-options",attrs:{role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"options"}});W(a,t,e.error,e.ids);for(let l of n){let c=d("label",{className:`fillo-option${l.icon?" fillo-option--has-icon":""}${r===l.id?" fillo-option--selected":""}`,attrs:{"data-option":l.id,"data-fillo":"option"}});c.toggleAttribute("data-selected",r===l.id);let u=d("input",{className:"fillo-option-input",attrs:{type:"radio",name:e.ids.name}});u.checked=r===l.id,u.addEventListener("change",()=>{i?.delete(t.id),e.setValue(l.id)}),A(c,[u,Bi(l.icon),d("span",{className:"fillo-option-label",text:l.label,attrs:{"data-fillo":"optionLabel"}}),l.icon&&r===l.id?d("span",{className:"fillo-option-check",text:"\u2713",attrs:{"aria-hidden":"true"}}):null]),a.appendChild(c)}if(t.allowOther){let l=d("label",{className:`fillo-option fillo-option--other${s?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});l.toggleAttribute("data-selected",s);let c=d("input",{className:"fillo-option-input",attrs:{type:"radio",name:e.ids.name}});if(c.checked=s,c.addEventListener("change",()=>{i?.add(t.id),e.setValue("",{render:!0})}),A(l,[A(d("span",{className:"fillo-option-main"}),[c,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),s){let u=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});u.value=o?r:"",u.placeholder=T.otherPlaceholder,u.addEventListener("input",()=>{i?.add(t.id),e.setValue(u.value,{render:!1})}),u.addEventListener("change",()=>{i?.add(t.id),e.setValue(u.value)}),l.appendChild(u),o||queueMicrotask(()=>u.focus())}a.appendChild(l)}return ne(t,e.error,a,e.ids)}function ta(e){let t=e.field,n=Zn(t),r=Array.isArray(e.value)?e.value:[],i=new Set(t.options.map(u=>u.id)),o=r.find(u=>!i.has(u)),s=e.activeOtherFields,a=()=>{let u=e.getValue?.()??e.value;return Array.isArray(u)?u:[]},l=d("div",{className:"fillo-options",attrs:{role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"options"}});W(l,t,e.error,e.ids);let c=u=>e.setValue(u);for(let u of n){let p=d("label",{className:`fillo-option${u.icon?" fillo-option--has-icon":""}${r.includes(u.id)?" fillo-option--selected":""}`,attrs:{"data-option":u.id,"data-fillo":"option"}});p.toggleAttribute("data-selected",r.includes(u.id));let h=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});h.checked=r.includes(u.id),h.addEventListener("change",()=>{let f=a();c(h.checked?[...f,u.id]:f.filter(m=>m!==u.id))}),A(p,[h,Bi(u.icon),d("span",{className:"fillo-option-label",text:u.label,attrs:{"data-fillo":"optionLabel"}}),u.icon&&r.includes(u.id)?d("span",{className:"fillo-option-check",text:"\u2713",attrs:{"aria-hidden":"true"}}):null]),l.appendChild(p)}if(t.allowOther){let u=o!==void 0||s?.has(t.id)===!0,p=d("label",{className:`fillo-option fillo-option--other${u?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});p.toggleAttribute("data-selected",u);let h=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(h.checked=u,h.addEventListener("change",()=>{let f=a().filter(m=>i.has(m));h.checked?(s?.add(t.id),c(f)):(s?.delete(t.id),c(f))}),A(p,[A(d("span",{className:"fillo-option-main"}),[h,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),u){let f=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});f.value=o??"",f.placeholder=T.otherPlaceholder,f.addEventListener("input",()=>{s?.add(t.id);let m=a().filter(g=>i.has(g));e.setValue(f.value?[...m,f.value]:m,{render:!1})}),f.addEventListener("change",()=>{s?.add(t.id);let m=a().filter(g=>i.has(g));e.setValue(f.value?[...m,f.value]:m)}),p.appendChild(f),o===void 0&&queueMicrotask(()=>f.focus())}l.appendChild(p)}return ne(t,e.error,l,e.ids)}function na(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function ra(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=na(t),i=e.activeOtherFields,o=n!==""&&!t.options.some(u=>u.id===n),s=o||n===""&&i?.has(t.id)===!0,a=d("div"),l=d("div",{className:"fillo-select-wrap"}),c=d("select",{className:"fillo-input fillo-select",attrs:{id:e.ids.inputId,"data-fillo":"control"}});c.appendChild(d("option",{text:t.placeholder??"Choose...",attrs:{value:""}}));for(let u of Zn(t))c.appendChild(d("option",{text:u.label,attrs:{value:u.id}}));if(t.allowOther&&c.appendChild(d("option",{text:`${T.other}\u2026`,attrs:{value:r}})),c.value=s?r:n,c.addEventListener("change",()=>{c.value===r?(i?.add(t.id),e.setValue("",{render:!0})):(i?.delete(t.id),e.setValue(c.value||null))}),W(c,t,e.error,e.ids),A(l,[c,d("span",{className:"fillo-select-icon",attrs:{"aria-hidden":"true"}})]),a.appendChild(l),s){let u=d("input",{className:"fillo-input fillo-other-input fillo-other-input--block",attrs:{type:"text","aria-label":T.otherPrompt}});u.value=o?n:"",u.placeholder=T.otherPlaceholder,u.addEventListener("input",()=>{i?.add(t.id),e.setValue(u.value,{render:!1})}),u.addEventListener("change",()=>{i?.add(t.id),e.setValue(u.value)}),a.appendChild(u),o||queueMicrotask(()=>u.focus())}return ne(t,e.error,a,e.ids)}function ia(e){if(e.field.kind==="checkbox"&&e.field.appearance==="toggle"){let o=d("div",{className:`fillo-field fillo-field--checkbox fillo-field--toggle${e.error?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.field.id,"data-kind":e.field.kind}});o.toggleAttribute("data-invalid",!!e.error),o.toggleAttribute("data-required",!!e.field.required);let s=d("label",{className:"fillo-toggle",attrs:{"data-fillo":"option"}});s.toggleAttribute("data-checked",e.value===!0);let a=d("span",{className:"fillo-option-label",text:e.field.label,attrs:{"data-fillo":"optionLabel"}});e.field.required||a.appendChild(d("span",{className:"fillo-optional",text:" (optional)"}));let l=d("span",{className:"fillo-toggle-copy"});l.appendChild(a);let c=d("input",{className:"fillo-toggle-input",attrs:{id:e.ids.inputId,type:"checkbox"}});return c.checked=e.value===!0,c.addEventListener("change",()=>{e.setValue(c.checked)}),W(c,e.field,e.error,e.ids),A(s,[l,c,A(d("span",{className:"fillo-toggle-track",attrs:{"aria-hidden":"true"}}),[d("span",{className:"fillo-toggle-thumb"})])]),o.appendChild(s),e.field.description&&o.appendChild(d("p",{className:"fillo-description",text:e.field.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}})),e.error&&o.appendChild(d("p",{className:"fillo-error",text:e.error,attrs:{id:e.ids.errorId,"data-fillo":"error"}})),o}let t=d("div",{className:`fillo-field fillo-field--checkbox${e.error?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.field.id,"data-kind":e.field.kind}});t.toggleAttribute("data-invalid",!!e.error),t.toggleAttribute("data-required",!!e.field.required);let n=d("label",{className:"fillo-option",attrs:{"data-fillo":"option"}});n.toggleAttribute("data-checked",e.value===!0);let r=d("input",{className:"fillo-option-input",attrs:{id:e.ids.inputId,type:"checkbox"}});r.checked=e.value===!0,r.addEventListener("change",()=>e.setValue(r.checked)),W(r,e.field,e.error,e.ids);let i=d("span",{className:"fillo-option-label",text:e.field.label,attrs:{"data-fillo":"optionLabel"}});return e.field.required||i.appendChild(d("span",{className:"fillo-optional",text:" (optional)"})),A(n,[r,i]),t.appendChild(n),e.field.description&&t.appendChild(d("p",{className:"fillo-description",text:e.field.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}})),e.error&&t.appendChild(d("p",{className:"fillo-error",text:e.error,attrs:{role:"alert",id:e.ids.errorId,"data-fillo":"error"}})),t}function oa(e){if(e.field.kind!=="rating")return d("div");let t=typeof e.field.max=="number"?e.field.max:5,n=typeof e.value=="number"?e.value:0,r=Array.from({length:t},(a,l)=>l+1),i=n>0?n:null,o=i===null?0:Math.max(0,r.indexOf(i)),s=d("div",{className:"fillo-rating",attrs:{id:e.ids.inputId,role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});W(s,e.field,e.error,e.ids);for(let[a,l]of r.entries()){let c=d("button",{className:`fillo-star${l<=n?" fillo-star--active":""}`,text:l<=n?"\u2605":"\u2606",attrs:{type:"button",role:"radio","aria-label":`${l} of ${t}`,"aria-checked":String(l===n),tabindex:String(a===o?0:-1),"data-fillo":"option"}});c.toggleAttribute("data-selected",l<=n),c.addEventListener("click",u=>{u.detail===0&&l===n||e.setValue(l===n?null:l)}),s.appendChild(c)}return ji(s,r,i,a=>e.setValue(a)),ne(e.field,e.error,s,e.ids)}function sa(e){if(e.field.kind!=="linear_scale")return d("div");let t=typeof e.field.min=="number"?e.field.min:1,n=typeof e.field.max=="number"?e.field.max:10,r=typeof e.value=="number"?e.value:null,i=Array.from({length:n-t+1},(p,h)=>t+h),o=r===null?0:Math.max(0,i.indexOf(r)),s=`${e.ids.inputId}-min`,a=`${e.ids.inputId}-max`,l=d("div"),c=d("div",{className:"fillo-scale",attrs:{id:e.ids.inputId,role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});W(c,e.field,e.error,e.ids);let u=[e.field.minLabel?s:null,e.field.maxLabel?a:null,c.getAttribute("aria-describedby")].filter(Boolean).join(" ");u&&c.setAttribute("aria-describedby",u);for(let[p,h]of i.entries()){let f=d("button",{className:`fillo-scale-step${e.value===h?" fillo-scale-step--active":""}`,text:String(h),attrs:{type:"button",role:"radio","aria-label":String(h),"aria-checked":String(e.value===h),tabindex:String(p===o?0:-1),"data-fillo":"option"}});f.toggleAttribute("data-selected",e.value===h),f.addEventListener("click",m=>{m.detail===0&&e.value===h||e.setValue(e.value===h?null:h)}),c.appendChild(f)}return ji(c,i,r,p=>e.setValue(p)),l.appendChild(c),("minLabel"in e.field||"maxLabel"in e.field)&&A(l,[A(d("div",{className:"fillo-scale-labels"}),[d("span",{text:String(e.field.minLabel??""),attrs:{id:s}}),d("span",{text:String(e.field.maxLabel??""),attrs:{id:a}})])]),ne(e.field,e.error,l,e.ids)}function aa(e){let t=e.field;if(t.kind!=="ranking")return null;let n=e.announce,r=Array.isArray(e.value)?e.value:[],i=[...r.filter(a=>t.options.some(l=>l.id===a)),...t.options.map(a=>a.id).filter(a=>!r.includes(a))],o=d("div",{attrs:{id:e.ids.inputId,role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});W(o,e.field,e.error,e.ids);let s=d("ol",{className:"fillo-ranking"});for(let[a,l]of i.entries()){let c=t.options.find(g=>g.id===l);if(!c)continue;let u=d("li",{className:"fillo-ranking-item"}),p=d("span",{className:"fillo-ranking-controls"}),h=g=>{let b=a+g;if(b<0||b>=i.length)return;let z=[...i];[z[a],z[b]]=[z[b],z[a]],e.setValue(z),n?.(J.rankingPosition(c.label,b+1,i.length))},f=d("button",{className:"fillo-ranking-move",text:"\u2191",attrs:{type:"button","data-fillo-rank-opt":l,"data-fillo-rank-dir":"up","aria-label":`Move ${c.label} up`}});f.toggleAttribute("disabled",a===0),f.addEventListener("click",()=>h(-1));let m=d("button",{className:"fillo-ranking-move",text:"\u2193",attrs:{type:"button","data-fillo-rank-opt":l,"data-fillo-rank-dir":"down","aria-label":`Move ${c.label} down`}});m.toggleAttribute("disabled",a===i.length-1),m.addEventListener("click",()=>h(1)),A(p,[f,m]),A(u,[d("span",{className:"fillo-ranking-index",text:String(a+1)}),d("span",{className:"fillo-ranking-label",text:c.label}),p]),s.appendChild(u)}return o.appendChild(s),ne(e.field,e.error,o,e.ids)}function la(e){let t=e.field;if(t.kind!=="matrix")return null;let n=e.value&&typeof e.value=="object"&&!Array.isArray(e.value)?e.value:{},r=d("table",{className:"fillo-matrix"}),i=document.createElement("thead"),o=document.createElement("tr");o.appendChild(document.createElement("th"));for(let l of t.columns)o.appendChild(d("th",{text:l.label,attrs:{scope:"col"}}));i.appendChild(o),r.appendChild(i);let s=document.createElement("tbody");for(let l of t.rows){let c=`${e.ids.inputId}-${l.id}`,u=n[l.id]!==void 0,p=!!e.error&&!!t.required&&!u,h=b=>`${e.ids.inputId}-${l.id}-${b.id}`,f=document.createElement("tr"),m=d("th",{attrs:{scope:"row"}}),g=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${c}`,"aria-owns":t.columns.map(h).join(" ")}});g.appendChild(d("span",{text:l.label,attrs:{id:c}})),m.appendChild(g),f.appendChild(m);for(let b of t.columns){let z=d("td",{attrs:{"data-label":b.label}}),I=d("label",{className:"fillo-matrix-cell"}),C=d("input",{className:"fillo-option-input",attrs:{id:h(b),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${b.label}`}});t.required&&C.setAttribute("aria-required","true"),p&&C.setAttribute("aria-invalid","true"),C.checked=n[l.id]===b.id,C.addEventListener("change",()=>e.setValue({...n,[l.id]:b.id})),I.appendChild(C),z.appendChild(I),f.appendChild(z)}s.appendChild(f)}r.appendChild(s);let a=d("div",{className:"fillo-matrix-wrap",attrs:{id:e.ids.inputId,role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});return W(a,e.field,e.error,e.ids),a.appendChild(r),ne(e.field,e.error,a,e.ids)}function ca(e){let t=d("div",{className:"fillo-signature-field"}),n=d("div",{className:"fillo-signature",attrs:{"data-fillo":"control"}}),r=d("canvas",{className:"fillo-signature-canvas",attrs:{role:"img"}}),i=d("button",{className:"fillo-signature-clear",text:"Clear",attrs:{type:"button"}}),o=d("div",{className:"fillo-signature-hint",text:"Sign here",attrs:{"aria-hidden":"true"}});r.width=720,r.height=220;let s=r.getContext("2d"),a=!1,l=typeof e.value=="string"&&e.value.startsWith("data:image/"),c=()=>{r.setAttribute("aria-label",l?J.signatureSigned:J.signatureEmpty)};if(c(),l&&s){let b=new Image;b.onload=()=>s.drawImage(b,0,0,r.width,r.height),b.src=String(e.value),o.style.display="none"}let u=d("input",{className:"fillo-input fillo-signature-type-input",attrs:{id:e.ids.inputId,type:"text",autocomplete:"name"}});W(u,e.field,e.error,e.ids);let p=b=>{s&&(s.clearRect(0,0,r.width,r.height),b.trim()?(s.fillStyle=getComputedStyle(r).color||"#18181b",s.font=`italic ${Math.min(96,r.height*.45)}px "Segoe Script", "Brush Script MT", cursive`,s.textBaseline="middle",s.fillText(b,24,r.height/2),l=!0,o.style.display="none",e.setValue(r.toDataURL("image/png"),{render:!1})):(l=!1,o.style.display="",e.setValue(null,{render:!1})),c())};u.addEventListener("input",()=>p(u.value));let h=b=>{let z=r.getBoundingClientRect();return{x:(b.clientX-z.left)/z.width*r.width,y:(b.clientY-z.top)/z.height*r.height}};r.addEventListener("pointerdown",b=>{if(!s)return;a=!0,l=!0,o.style.display="none",c(),u.value&&(u.value=""),r.setPointerCapture(b.pointerId);let z=h(b);s.beginPath(),s.moveTo(z.x,z.y)}),r.addEventListener("pointermove",b=>{if(!a||!s)return;let z=h(b);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(z.x,z.y),s.stroke()});let f=()=>{a&&(a=!1,l&&e.setValue(r.toDataURL("image/png"),{render:!1}))};r.addEventListener("pointerup",f),r.addEventListener("pointercancel",f),i.addEventListener("click",()=>{s?.clearRect(0,0,r.width,r.height),l=!1,o.style.display="",u.value="",c(),e.setValue(null,{render:!1})}),A(n,[r,o,i]);let m=d("div",{className:"fillo-signature-type"}),g=d("label",{className:"fillo-signature-type-label",text:"Or type your full name to sign",attrs:{for:e.ids.inputId}});return A(m,[g,u]),A(t,[n,m]),ne(e.field,e.error,t,e.ids)}function Li(e){return e<1024?`${e} B`:e<1024**2?`${(e/1024).toFixed(0)} KB`:e<1024**3?`${(e/1024**2).toFixed(1)} MB`:`${(e/1024**3).toFixed(2)} GB`}function At(e,t,n,r){let i=d("button",{className:e,text:n,attrs:{type:"button","aria-label":t}});return i.addEventListener("click",r),i}function ua(e){let t=e.field;if(t.kind!=="file_upload")return null;let n=e,r=n.storageBlocked===!0,i=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file","data-fillo":"control"}});(t.maxFiles??1)>1&&(i.multiple=!0),t.accept?.length&&(i.accept=t.accept.join(",")),i.disabled=r,W(i,t,e.error,e.ids),i.addEventListener("change",()=>{if(r)return;let p=Array.from(i.files??[]);i.value="",e.uploadFiles?.(t,p)});let o=d("div");if(o.appendChild(i),r){let p=d("p",{className:"fillo-upload-notice",text:n.storageFixUrl?"Connect file storage to enable uploads":J.uploadsUnavailable});n.storageFixUrl&&(p.append(" \u2014 "),p.appendChild(d("a",{text:n.storageFixUrl,attrs:{href:n.storageFixUrl,target:"_blank",rel:"noopener noreferrer"}}))),o.appendChild(p)}let s=Array.isArray(e.value)?e.value:[],a=n.uploadRows??[],c=(t.maxFiles??1)-s.length-a.filter(p=>p.error===void 0).length;if(s.length>0||a.length>0){let p=d("ul",{className:"fillo-files"});for(let h of s){let f=d("li",{className:"fillo-file fillo-file--done"});A(f,[d("span",{className:"fillo-file-name",text:h.name}),d("span",{className:"fillo-file-meta",text:Li(h.size)}),d("span",{className:"fillo-sr-only",text:"Uploaded"}),At("fillo-file-remove",`Remove ${h.name}`,"\xD7",()=>e.setValue(s.filter(m=>m.fileId!==h.fileId)))]),p.appendChild(f)}for(let h of a){let f=h.error!==void 0,m=d("li",{className:`fillo-file${f?" fillo-file--failed":""}`,attrs:f?{}:{role:"progressbar","aria-label":`Uploading ${h.name}`,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(Math.round(h.fraction*100))}});if(m.appendChild(d("span",{className:"fillo-file-name",text:h.name})),f)m.appendChild(d("span",{className:"fillo-file-meta",text:h.error??""})),c>0&&m.appendChild(At("fillo-file-retry",`${J.uploadRetry} ${h.name}`,J.uploadRetry,()=>n.uploadAction?.(h.key,"retry"))),m.appendChild(At("fillo-file-remove","Dismiss","\xD7",()=>n.uploadAction?.(h.key,"dismiss")));else{let g=d("span",{className:"fillo-progress-bar"});g.style.width=`${h.fraction*100}%`,A(m,[d("span",{className:"fillo-file-meta",text:`${Math.round(h.fraction*100)}% of ${Li(h.size)}`}),A(d("span",{className:"fillo-progress",attrs:{"aria-hidden":"true"}}),[g]),At("fillo-file-remove",`Cancel ${h.name}`,"\xD7",()=>n.uploadAction?.(h.key,"cancel"))])}p.appendChild(m)}o.appendChild(p)}let u=n.uploadNotice;return u&&o.appendChild(d("p",{className:"fillo-upload-notice",text:u})),ne(t,e.error,o,e.ids)}function da(e){let t=e.field,n=d("div",{className:"fillo-field fillo-field--calculated fillo-calculated",attrs:{"data-fillo":"calculated","data-field":t.id,"data-kind":t.kind}});n.appendChild(d("label",{className:"fillo-label",text:t.label,attrs:{id:e.ids.labelId,for:e.ids.inputId,"data-fillo":"label"}})),t.description&&n.appendChild(d("p",{className:"fillo-description",text:t.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}}));let r=e.value,i=r!=null&&r!=="",o=d("output",{className:`fillo-calculated-value${i?"":" fillo-calculated-value--empty"}`,text:i?fi(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var Zi=new Map;function Zn(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=Zi.get(t);if(!n){n=e.options.map(o=>o.id);for(let o=n.length-1;o>0;o--){let s=Math.floor(Math.random()*(o+1));[n[o],n[s]]=[n[s],n[o]]}Zi.set(t,n)}let r=new Map(e.options.map(o=>[o.id,o])),i=n.flatMap(o=>r.get(o)??[]);return i.length===e.options.length?i:e.options}var pa={short_text:e=>at("text",e),email:e=>at("email",e),url:e=>at("url",e),phone:Ys,number:e=>at("number",e),date:e=>at("date",e),long_text:Qs,select:ea,multi_select:ta,dropdown:ra,checkbox:ia,rating:oa,linear_scale:sa,ranking:aa,matrix:la,signature:ca,file_upload:ua,calculated:da};function fa(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=pa[e.field.kind];return t?t(e):null}var ha="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",Ri="fillo-turnstile-script",lt=null;function je(){return globalThis.turnstile}function ma(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):je()?Promise.resolve():lt||(lt=new Promise((e,t)=>{let n=()=>{je()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(Ri);if(r){if(je()){e();return}r.addEventListener("load",n,{once:!0}),r.addEventListener("error",()=>t(new Error("Turnstile script failed to load")),{once:!0});return}let i=document.createElement("script");i.id=Ri,i.src=ha,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),lt=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),lt)}function Oi(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var dt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&$a(),t.replaceChildren(this.element,this.statusEl,this.alertEl),this.resolve()}target;options;element=d("div");statusEl=d("span",{className:"fillo-sr-only",attrs:{role:"status","aria-live":"polite","data-fillo":"announce"}});alertEl=d("span",{className:"fillo-sr-only",attrs:{role:"alert","data-fillo":"announce-alert"}});instanceId=`d${++qs}`;schema=null;theme;formId;closed=!1;fetchedPoweredBy=null;fetchedBrandLabel;fetchedBrandHref;phase="loading";engine=null;destroyed=!1;renderQueued=!1;hpValue="";liveSubmissionHandled=!1;activeOtherFields=new Set;inFlight=new Map;uploadNotices=new Map;focusIntent=null;overlays=new Set;challenge;challengeToken;challengeError=!1;turnstileContainer=Oi();turnstileWidgetId=null;turnstileSiteKey;turnstileLoadInFlight=!1;turnstileAttempt=0;announce=t=>{this.statusEl.textContent="",requestAnimationFrame(()=>{this.statusEl.textContent=t})};announceAlert=t=>{this.alertEl.textContent="",requestAnimationFrame(()=>{this.alertEl.textContent=t})};devChrome(){return this.options.preview===!0||va()}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 t=this.schema??{version:1,title:"",pages:[],settings:{}},n=this.engine?.getState(),r=n?.pageCount??t.pages.length;return{form:t,formId:this.formId,client:this.options.client,data:n?.data??this.mutableData,errors:n?.errors??{},status:this.status,pageIndex:n?.pageIndex??0,pageCount:r,page:n?.page??t.pages[0]??{id:"empty",blocks:[]},blocks:n?.blocks??[],isFirstPage:n?.isFirstPage??!0,isLastPage:n?.isLastPage??r<=1,setValue:(i,o,s)=>this.setValueInternal(i,o,s),next:()=>this.next(),back:()=>this.back(),submit:()=>this.submit()}}resolveFormIdFn;notOpenVariant=null;fatalError=null;genericUnavailable=!1;syncErrorNotice=null;stagedNotice=!1;draftNotice=!1;syncWarningCode;syncWarningUrl;uploadsAvailable;uploadFileSizeLimitMb;resolutionFailureCode=null;async resolve(){try{this.challenge=this.options.challenge;let t=Nn(this.options.form)?this.options.form:null;if(t){let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await Tn(i,t,{bypassCache:!0});if(this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.uploadsAvailable=o.uploadsAvailable,this.uploadFileSizeLimitMb=o.uploadFileSizeLimitMb,o.status==="draft")throw new $("This form is no longer published. Submission was stopped before sending answers.",403,void 0,"form_not_published");if(o.accepting===!1)throw new $("This form is no longer accepting responses. Submission was stopped before sending answers.",403,void 0,o.acceptingReason??"form_not_accepting");let s=Ne(o.resolvedSchema??t.schema);if(!s.ok)throw new $(`The canonical form schema was invalid: ${s.error}`,502,void 0,"invalid_sync_schema");if(this.schema&&!Ai(this.schema,s.schema))throw new $("The live form changed after this page loaded. Submission stopped before incompatible answers were sent. Reload to use the published schema.",409,void 0,"form_schema_changed");return o.syncError&&this.reportSyncNotice(new $(o.syncError.message,403,void 0,o.syncError.code)),this.resolutionFailureCode=null,o.formId}catch(o){let s=ct(o);throw this.resolutionFailureCode=s.code??"sync_failed",this.reportSubmitSyncFailure(s),s}}),i?.key||this.setSchema(t.schema,this.options.theme??t.theme,this.options.formId),i&&!i.key&&!this.options.formId){this.reportSyncFailure(new $('Code forms need createClient({ key: "pk_\u2026" }) to resolve the live form. Pass a publishable key or a published formId.',401,void 0,"sync_key_required"));return}if(!i?.key)return;this.devChrome()?this.setSchema(t.schema,this.options.theme??t.theme,this.options.formId):(this.theme=this.options.theme??t.theme,this.render());try{let o=await Tn(i,t);if(this.destroyed)return;if((o.staged||o.syncError)&&!o.resolvedSchema)throw new $("Sync did not return the live schema needed to render safely. Publish changes before deploy, and update @usefillo/* or your API.",409,void 0,"sync_snapshot_required");let s=this.devChrome();if(this.notOpenVariant=s?null:o.status==="draft"?"notOpen":o.accepting===!1?Di(o.acceptingReason):null,this.stagedNotice=!!o.staged,this.draftNotice=o.status==="draft",this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.uploadsAvailable=o.uploadsAvailable,this.uploadFileSizeLimitMb=o.uploadFileSizeLimitMb,this.challenge=this.options.challenge??o.challenge,o.branding&&(this.fetchedPoweredBy=o.branding.poweredBy,this.fetchedBrandLabel=o.branding.label,this.fetchedBrandHref=o.branding.href),s&&o.resolvedSchema)this.formId=o.formId,this.engine?.setContext({formId:o.formId}),this.render();else{let l=o.resolvedSchema??t.schema,c=this.options.theme??(o.resolvedSchema?o.resolvedTheme??void 0:t.theme);this.applyCanonicalSchema(l,c,o.formId)}o.warning&&console.warn(`[fillo] ${o.warning}`),o.syncError&&this.reportSyncNotice(new $(o.syncError.message,403,void 0,o.syncError.code));let a=o.warningUrl?` \u2014 connect storage to publish: ${o.warningUrl}`:"";o.staged?console.info(`[fillo] "${t.id}" changes staged as a draft \u2014 rendering the live version until you publish them in your Fillo dashboard${a}`):o.status==="draft"&&console.info(`[fillo] "${t.id}" is a draft \u2014 it renders here but won't accept responses until published${a}`)}catch(o){if(this.destroyed)return;this.reportSyncFailure(ct(o))}return}let n=this.options.form&&!Nn(this.options.form)?this.options.form:null;if(n){this.setSchema(n,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new $("Provide either `form`, or a `formId`.",0);this.options.client??=st(),this.render();let r=await this.options.client.getForm(this.options.formId);if(this.destroyed)return;if(r.accepting===!1?this.notOpenVariant=Di(r.acceptingReason):this.closed=!!r.closed,this.uploadsAvailable=r.uploadsAvailable,this.uploadFileSizeLimitMb=r.uploadFileSizeLimitMb,this.fetchedPoweredBy=r.branding?.poweredBy??null,this.fetchedBrandLabel=r.branding?.label,this.fetchedBrandHref=r.branding?.href,this.challenge=this.options.challenge??r.challenge,r.accepting===!1&&this.options.renderError){let i=this.notOpenVariant==="closed"?"This form is no longer accepting responses.":"This form isn't accepting responses yet.";this.fatalError=new $(i,403,void 0,r.acceptingReason),this.phase="error",this.render(this.fatalError);return}this.setSchema(r.schema,this.options.theme??r.theme??void 0,r.id)}catch(t){if(this.destroyed)return;this.handleError(ct(t))}}setSchema(t,n,r){if(this.destroyed)return;let i=Ne(t);if(!i.ok)throw new $(`This form could not be rendered: ${i.error}`,422);let o=i.schema;this.schema=o,this.theme=n,this.formId=r;let s=this.notOpenVariant!==null;this.engine=ki({form:o,formId:s?void 0:r,client:s?void 0:this.options.client,initialData:this.options.initialData,onChange:s?void 0:this.options.onChange,onSubmitted:s?void 0:this.options.onSubmitted,getHoneypot:()=>this.element.querySelector('input[name="fillo_hp_field"]')?.value??this.hpValue,surface:"default",resolveFormId:s?void 0:this.resolveFormIdFn,verboseResolutionErrors:this.devChrome(),respondent:s?void 0:this.options.respondent,challengeRequired:s?!1:!!this.challenge,getChallengeToken:()=>this.challengeToken,onChallengeFailed:()=>this.resetChallengeWidget()});let a=this.engine.getState().status,l=this.engine.getState().resumedDraft,c=this.engine.getState().editingPrevious;this.engine.subscribe(()=>{let u=this.engine?.getState();u&&(u.status!==a||u.resumedDraft!==l||u.editingPrevious!==c)&&(u.editingPrevious&&!c?this.announce(T.editNotice):u.resumedDraft&&!l&&this.announce(T.resumeNotice),a=u.status,l=u.resumedDraft,c=u.editingPrevious,this.queueRender())}),s||this.configureDraftFlush(o),this.phase=this.closed?"closed":"ready",this.render()}applyCanonicalSchema(t,n,r){if(!this.engine){this.setSchema(t,n,r);return}let i=Ne(t);if(!i.ok)throw new $(`This form could not be rendered: ${i.error}`,422);let o=i.schema;this.schema=o,this.theme=n,this.formId=r,this.engine.setContext({form:o,formId:r}),this.notOpenVariant===null&&this.configureDraftFlush(o),this.phase=this.closed?"closed":"ready",this.render()}draftFlushWired=!1;flushDraftBound=()=>this.engine?.flushDraft();visibilityFlushBound=()=>{document.visibilityState==="hidden"&&this.engine?.flushDraft()};configureDraftFlush(t){this.teardownDraftFlush(),t.settings.saveProgress&&typeof window<"u"&&(window.addEventListener("pagehide",this.flushDraftBound),document.addEventListener("visibilitychange",this.visibilityFlushBound),this.draftFlushWired=!0)}teardownDraftFlush(){!this.draftFlushWired||typeof window>"u"||(window.removeEventListener("pagehide",this.flushDraftBound),document.removeEventListener("visibilitychange",this.visibilityFlushBound),this.draftFlushWired=!1)}flushDraft(){this.engine?.flushDraft()}resetDraft(){this.engine?.resetDraft(),this.queueRender()}setValue(t,n){this.setValueInternal(t,n)}setValueInternal(t,n,r={}){this.notOpenVariant||(this.engine?.setValue(t,n),r.render!==!1&&this.queueRender())}next(){if(!this.engine||this.notOpenVariant)return;let t=this.engine.getState().pageIndex;this.engine.next(),this.focusIntent=this.engine.getState().pageIndex!==t?"page":"error",this.render()}back(){!this.engine||this.notOpenVariant||(this.engine.back(),this.focusIntent="page",this.render())}async submit(){if(!this.engine||this.phase!=="ready"||this.notOpenVariant)return;let t=this.engine.submit();this.hasErrors()?this.focusIntent="error":this.engine.getState().status==="submitting"&&this.announce(J.submittingAnnouncement),this.render();try{await t}catch(n){this.options.onError?.(ct(n)),this.focusIntent="error",this.render();return}this.hasErrors()&&(this.focusIntent="error"),this.render()}hasErrors(){return Object.keys(this.engine?.getState().errors??{}).length>0}setTheme(t){this.options.theme=t,this.theme=t,this.render()}setClient(t){this.options.client=t,this.engine?.setContext({client:t}),this.render()}setRespondent(t){this.options.respondent=t,this.engine?.setContext({respondent:t})}fieldActive(t){let n=0;for(let r of this.inFlight.values())r.fieldId===t&&r.error===void 0&&n++;return n}uploadRowsFor(t){let n=[];for(let[r,i]of this.inFlight)i.fieldId===t&&n.push({key:r,name:i.name,size:i.size,fraction:i.fraction,error:i.error});return n}uploadAction=(t,n)=>{let r=this.inFlight.get(t);r&&(n==="cancel"?(r.controller.abort(),this.inFlight.delete(t)):n==="dismiss"?this.inFlight.delete(t):(this.inFlight.delete(t),this.startUpload(r.fieldId,r.file,r.maxFiles)),this.fieldActive(r.fieldId)===0&&this.engine?.setUploading(r.fieldId,!1),this.queueRender())};async startUpload(t,n,r){let i=`${n.name}-${n.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,o=new AbortController;this.inFlight.set(i,{fieldId:t,name:n.name,size:n.size,fraction:0,file:n,controller:o,maxFiles:r}),this.engine?.setUploading(t,!0),this.queueRender();try{let s=this.options.client&&this.formId?await this.options.client.uploadFile(this.formId,n,{fieldId:t,signal:o.signal,onProgress:l=>{let c=this.inFlight.get(i);c&&(c.fraction=l.fraction,this.queueRender())}}):{fileId:`local:${n.name}:${n.size}`,name:n.name,size:n.size,mime:n.type||"application/octet-stream"};if(this.destroyed)return;this.inFlight.delete(i);let a=r>1&&Array.isArray(this.mutableData[t])?this.mutableData[t]:[];this.setValueInternal(t,[...a,s])}catch(s){if(this.destroyed||o.signal.aborted)return;let a=ct(s),l=a.status!==void 0&&a.status>=500?J.uploadUnavailable:a.message||J.uploadFailed,c=this.inFlight.get(i);c&&(c.error=l),this.announceAlert(l),this.options.onError?.(a)}finally{this.fieldActive(t)===0&&this.engine?.setUploading(t,!1),this.queueRender()}}async uploadFiles(t,n){if(!this.schema||this.notOpenVariant)return;let r=t.maxFiles??1,i=r>1&&Array.isArray(this.mutableData[t.id])?this.mutableData[t.id].length:0,o=Math.max(0,r-i-this.fieldActive(t.id)),s=n.slice(0,o),a=t.maxFileSizeMb??500,l=this.uploadFileSizeLimitMb?Math.min(a,this.uploadFileSizeLimitMb):a,c=l*1024*1024,u=s.filter(f=>f.size<=c),p=n.length-s.length,h=s.length-u.length;if(p>0||h>0){let f=[];p>0&&f.push(`You can attach up to ${r} file${r===1?"":"s"}. ${p} ${p===1?"file was":"files were"} not added.`),h>0&&f.push(`${h} ${h===1?"file exceeds":"files exceed"} the ${l} MB limit.`);let m=f.join(" ");this.uploadNotices.set(t.id,m),this.announce(m)}else this.uploadNotices.delete(t.id);if(u.length===0){this.queueRender();return}await Promise.all(u.map(f=>this.startUpload(t.id,f,r)))}destroy(){this.destroyed=!0,this.teardownDraftFlush(),this.closeOverlays(),this.teardownTurnstileWidget();for(let t of this.inFlight.values())t.controller.abort();this.inFlight.clear(),this.engine?.destroy(),this.engine=null,this.target.replaceChildren()}storageBlocked(){return this.uploadsAvailable===!1}registerOverlay=t=>(this.overlays.add(t),()=>this.overlays.delete(t));closeOverlays(){if(this.overlays.size!==0){for(let t of Array.from(this.overlays))try{t()}catch{}this.overlays.clear()}}ensureTurnstileWidget(t){if(this.turnstileSiteKey!==t&&(this.teardownTurnstileWidget(),this.turnstileSiteKey=t),this.turnstileWidgetId!==null||this.turnstileLoadInFlight||this.challengeError)return;this.turnstileLoadInFlight=!0;let n=++this.turnstileAttempt;ma().then(()=>{if(this.destroyed||n!==this.turnstileAttempt)return;let r=je();if(!r){this.turnstileLoadInFlight=!1,this.handleChallengeError();return}this.turnstileWidgetId=r.render(this.turnstileContainer,{sitekey:t,theme:"auto",callback:i=>this.handleChallengeToken(i),"error-callback":()=>{this.handleChallengeToken(void 0),this.handleChallengeError()},"expired-callback":()=>this.resetChallengeWidget(),"timeout-callback":()=>this.resetChallengeWidget()}),this.turnstileLoadInFlight=!1}).catch(()=>{this.destroyed||n!==this.turnstileAttempt||(this.turnstileLoadInFlight=!1,this.handleChallengeError())})}handleChallengeToken(t){this.challengeToken=t,t&&(this.challengeError=!1),this.queueRender()}handleChallengeError(){this.challengeError=!0,this.announceAlert(T.challengeUnavailable),this.queueRender()}resetChallengeWidget(){this.challengeToken=void 0,this.turnstileWidgetId&&je()?.reset(this.turnstileWidgetId),this.queueRender()}teardownTurnstileWidget(){if(this.turnstileWidgetId===null&&!this.turnstileLoadInFlight)return;this.turnstileAttempt++;let t=je();if(this.turnstileWidgetId&&t)try{t.remove(this.turnstileWidgetId)}catch{}this.turnstileWidgetId=null,this.turnstileLoadInFlight=!1,this.challengeError=!1,this.turnstileContainer=Oi(),this.challengeToken=void 0}captureFocus(){if(typeof document>"u")return null;let t=document.activeElement;if(!t||!this.element.contains(t))return null;let n={};t.id&&(n.id=t.id);let r=t.getAttribute("data-fillo-rank-opt");r&&(n.rankOpt=r,n.rankDir=t.getAttribute("data-fillo-rank-dir")??void 0);let i=t.closest("[data-field]");if(i&&(n.fieldId=i.getAttribute("data-field")??void 0,n.controlIndex=Array.from(i.querySelectorAll(Ct)).indexOf(t)),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)try{n.selStart=t.selectionStart,n.selEnd=t.selectionEnd}catch{}return n.id||n.rankOpt||n.fieldId?n:null}restoreFocus(t){if(typeof document>"u")return;let n=null;if(t.rankOpt){let r=Array.from(this.element.querySelectorAll("[data-fillo-rank-opt]")).filter(i=>i.getAttribute("data-fillo-rank-opt")===t.rankOpt);n=r.find(i=>i.getAttribute("data-fillo-rank-dir")===t.rankDir&&!i.disabled)??r.find(i=>!i.disabled)??null}if(!n&&t.id&&(n=document.getElementById(t.id)),!n&&t.fieldId!=null&&t.controlIndex!=null&&t.controlIndex>=0){let r=Array.from(this.element.querySelectorAll("[data-field]")).find(i=>i.getAttribute("data-field")===t.fieldId);r&&(n=Array.from(r.querySelectorAll(Ct))[t.controlIndex]??null)}if(!(!n||typeof n.focus!="function")&&(n.focus(),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&t.selStart!=null))try{n.setSelectionRange(t.selStart,t.selEnd??t.selStart)}catch{}}applyFocus(t,n){if(!(typeof document>"u")){if(t==="error"){let r=this.element.querySelector(".fillo-error-summary");if(r){r.focus();return}let i=this.element.querySelector('[aria-invalid="true"]');i&&Ni(i)?.focus();return}if(t==="page"){let i=this.element.querySelector(".fillo-page-title, .fillo-title")??this.element.querySelector(".fillo-blocks");i&&(i.hasAttribute("tabindex")||i.setAttribute("tabindex","-1"),i.focus?.());return}n&&this.restoreFocus(n)}}handleError(t){this.destroyed||(this.fatalError=t,this.phase="error",this.options.onError?.(t),this.render(t))}reportSyncFailure(t){if(this.destroyed)return;console.warn(`[fillo] form sync failed${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t;let n=this.devChrome();if(!n||this.options.renderError){this.genericUnavailable=!n,this.handleError(t);return}this.options.onError?.(t),n&&this.render()}reportSyncNotice(t){this.destroyed||(console.warn(`[fillo] form sync needs attention${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t,this.options.onError?.(t),this.devChrome()&&this.render())}reportSubmitSyncFailure(t){this.destroyed||(console.warn(`[fillo] form sync failed${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t)}queueRender(){this.renderQueued||this.destroyed||(this.renderQueued=!0,queueMicrotask(()=>{this.renderQueued=!1,this.render()}))}render(t){if(this.destroyed)return;let n=this.focusIntent;this.focusIntent=null;let r=n?null:this.captureFocus();if(this.closeOverlays(),this.phase==="ready"&&this.engine?.getState().status!=="submitted"||this.teardownTurnstileWidget(),this.element.replaceChildren(),this.phase==="loading"){let s=d("div",{className:`fillo-form fillo-form--loading ${this.options.className??""}`,attrs:{"aria-busy":"true","data-fillo":"root","data-state":"loading"}});Be(s,this.theme),A(s,[d("div",{className:"fillo-skeleton"}),d("div",{className:"fillo-skeleton"}),d("div",{className:"fillo-skeleton fillo-skeleton--short"})]),this.element.appendChild(s);return}let o=t??this.fatalError;if(this.phase==="error"&&o){let s=this.options.renderError?.(o)??d("div",{className:"fillo-form fillo-form--error",text:this.genericUnavailable?"This form is unavailable.":Sa(o)});s.hasAttribute("data-fillo")||s.setAttribute("data-fillo","root"),s.hasAttribute("data-state")||s.setAttribute("data-state","error"),s.hasAttribute("role")||s.setAttribute("role","alert"),Be(s,this.theme),this.element.appendChild(s);return}if(this.phase==="closed"){let s=d("div",{className:`fillo-form fillo-form--closed ${this.options.className??""}`,attrs:{"data-fillo":"root","data-state":"closed"}});Be(s,this.theme),s.appendChild(d("p",{className:"fillo-closed",text:"This form is no longer accepting responses."})),this.element.appendChild(s);return}if(this.notOpenVariant&&this.schema){this.element.appendChild(this.renderNotOpen(this.notOpenVariant)),this.brandingVisible()&&this.element.appendChild(Mn(this.fetchedBrandLabel,this.fetchedBrandHref));return}if(this.schema){if(this.engine?.getState().status==="submitted"){let s=this.api(),a=this.engine.getState(),l=this.options.renderSuccess?.(s)??ba(this.schema);if(l.setAttribute("data-fillo",l.getAttribute("data-fillo")??"root"),l.setAttribute("data-state",l.getAttribute("data-state")??"submitted"),l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1"),Be(l,this.theme),this.element.appendChild(l),this.brandingVisible()&&this.element.appendChild(Mn(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let c=ut(this.schema.settings.redirectUrl);c&&typeof window<"u"?window.location.assign(c):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&A(this.element,za({preview:this.options.preview===!0,devNotices:this.options.devNotices,syncError:this.syncErrorNotice,staged:this.stagedNotice,draft:this.draftNotice,warningUrl:this.syncWarningUrl,noClient:!this.options.client})),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(Mn(this.fetchedBrandLabel,this.fetchedBrandHref)),this.applyFocus(n,r)}}brandingVisible(){return this.fetchedPoweredBy??!0}renderNotOpen(t){let n=d("div",{className:`fillo-form fillo-form--not-open ${this.options.className??""}`,attrs:{"data-fillo":"root","data-state":"closed"}});Be(n,this.theme);let r=d("div",{className:"fillo-not-open-preview",attrs:{"aria-hidden":"true",inert:""}});r.appendChild(this.renderForm());let i=d("div",{className:"fillo-not-open-card",attrs:{role:"status","data-fillo":"not-open-card"}});return i.appendChild(d("h2",{className:"fillo-not-open-title",text:t==="closed"?T.closedTitle:T.notOpenTitle})),i.appendChild(d("p",{className:"fillo-not-open-body",text:t==="closed"?T.closed:T.notOpenBody})),A(n,[r,i]),n}renderForm(){let t=this.api(),n=this.notOpenVariant!==null,r=!!this.challenge,i=!n&&r&&t.isLastPage,o=d(n?"div":"form",{className:`fillo-form ${this.options.className??""}`,attrs:{"data-fillo":n?"preview-form":"root","data-state":n?"preview":t.status,"data-page":String(t.pageIndex+1)}});o.toggleAttribute("data-last-page",t.isLastPage),Be(o,this.theme);let s=()=>{t.isLastPage?this.submit():this.next()};if(!n){let g=o;g.noValidate=!0,g.addEventListener("submit",b=>{b.preventDefault(),s()})}let a=n?o.appendChild(d("fieldset",{className:"fillo-not-open-fields",attrs:{disabled:""}})):o,l=this.engine?.getState();if(l?.resumedDraft||l?.editingPrevious){let g=d("div",{className:"fillo-resume",attrs:{"data-fillo":"resume"}});g.appendChild(d("span",{className:"fillo-resume-text",text:l.editingPrevious?T.editNotice:T.resumeNotice}));let b=d("button",{className:"fillo-resume-clear",text:T.resumeStartOver,attrs:{type:"button"}});b.addEventListener("click",()=>this.resetDraft()),g.appendChild(b),a.appendChild(g)}if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let g=De(t.form,t.data),b=Math.max(g.length,1),z=g.indexOf(t.page.id),I=z>=0?z+1:Math.min(t.pageIndex+1,b),C=d("div",{className:"fillo-progress-track",attrs:{role:"progressbar","data-fillo":"progress","aria-label":t.form.title||"Form progress","aria-valuemin":"1","aria-valuemax":String(b),"aria-valuenow":String(I)}});C.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),C.firstElementChild?.style.setProperty("--fillo-progress-value",`${I/b*100}%`),a.appendChild(C)}if(t.pageIndex===0){let g=d("header",{className:"fillo-header",attrs:{"data-fillo":"header"}});t.form.title&&g.appendChild(d("h1",{className:"fillo-title",text:t.form.title,attrs:{"data-fillo":"title"}})),t.form.description&&g.appendChild(d("p",{className:"fillo-form-description",text:t.form.description,attrs:{"data-fillo":"description"}})),a.appendChild(g)}else t.page.title&&a.appendChild(d("h2",{className:"fillo-page-title",text:t.page.title,attrs:{"data-fillo":"pageTitle"}}));let c=this.renderErrorSummary(t);c&&a.appendChild(c);let u=d("div",{className:"fillo-blocks",attrs:{"data-fillo":"blocks"}});for(let g of t.blocks){let b=this.renderBlock(Ii(g,this.mutableData,t.form),t);b&&u.appendChild(b)}if(a.appendChild(u),!n){let g=d("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});g.style.position="absolute",g.style.left="-9999px",g.style.top="auto",g.style.width="1px",g.style.height="1px",g.style.opacity="0",g.style.overflow="hidden",g.style.pointerEvents="none",g.addEventListener("input",()=>{this.hpValue=g.value}),a.appendChild(g)}if(i){let g=d("div",{className:"fillo-turnstile-slot",attrs:{"data-fillo":"turnstile-slot"}});g.appendChild(this.turnstileContainer),this.challengeError&&g.appendChild(d("p",{className:"fillo-turnstile-error",attrs:{role:"alert"},text:T.challengeUnavailable})),a.appendChild(g),this.ensureTurnstileWidget(this.challenge.siteKey)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight)&&this.teardownTurnstileWidget();let p=t.status==="error"?"This form can't submit right now. Please try again in a moment.":this.engine?.getState().submitError;if(p){let g=d("p",{className:"fillo-submit-error",attrs:{role:"alert"},text:p}),b=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?ut(this.syncWarningUrl):null;b&&(g.append(" Connect storage: "),g.appendChild(d("a",{text:b,attrs:{href:b,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(g)}let f=!(t.form.settings.submitMode==="auto")||!t.isLastPage||$i(ti(t.form,t.data))||i;if(f||t.pageCount>1&&!t.isFirstPage){let g=d("footer",{className:"fillo-footer",attrs:{"data-fillo":"footer"}});if(t.pageCount>1&&!t.isFirstPage){let b=d("button",{className:"fillo-button fillo-button--ghost",text:"Back",attrs:{type:"button","data-fillo":"button"}});b.addEventListener("click",()=>this.back()),g.appendChild(b)}if(f){let b=d("button",{className:"fillo-button fillo-button--primary",text:t.status==="submitting"?"Submitting...":t.isLastPage?t.form.settings.submitLabel??"Submit":"Next",attrs:{type:"submit","data-fillo":"button"}});b.toggleAttribute("disabled",t.status==="submitting"||this.engine?.getState().uploading===!0||i&&!this.challengeToken),b.addEventListener("click",z=>{z.preventDefault(),s()}),g.appendChild(b)}a.appendChild(g)}return o}renderErrorSummary(t){let n=t.blocks.filter(te).filter(o=>t.errors[o.id]);if(n.length===0)return null;let r=d("div",{className:"fillo-error-summary",attrs:{role:"alert",tabindex:"-1","data-fillo":"error-summary"}});r.appendChild(d("p",{className:"fillo-error-summary-title",text:J.errorSummaryTitle}));let i=d("ul");for(let o of n){let s=d("a",{text:`${o.label}: ${t.errors[o.id]}`,attrs:{href:`#${Ti(this.instanceId,o.id).inputId}`}});s.addEventListener("click",l=>{l.preventDefault();let c=Array.from(this.element.querySelectorAll("[data-field]")).find(p=>p.getAttribute("data-field")===o.id);if(!c)return;let u=c.querySelector('[aria-invalid="true"]')??c;Ni(u)?.focus()});let a=d("li");a.appendChild(s),i.appendChild(a)}return r.appendChild(i),r}renderBlock(t,n){if(!te(t))return ga(t);let r=(s,a)=>{if(this.setValueInternal(t.id,s,a),a?.render===!1)return;let l={form:n.form,data:n.data,status:n.status,isLastPage:n.isLastPage,uploading:this.engine?.getState().uploading===!0};zi(t,s,l)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id],ids:Ti(this.instanceId,t.id),api:n,setValue:r,uploadFiles:(s,a)=>this.uploadFiles(s,a),uploadRows:this.uploadRowsFor(t.id),uploadAction:this.uploadAction,activeOtherFields:this.activeOtherFields,getValue:()=>this.engine?.getState().data[t.id],registerOverlay:this.registerOverlay,uploadNotice:this.uploadNotices.get(t.id),storageBlocked:this.storageBlocked(),storageFixUrl:this.storageBlocked()&&this.devChrome()?ut(this.syncWarningUrl):null,announce:this.announce,announceAlert:this.announceAlert};return(t.kind==="custom"?this.options.customComponents?.[t.component]??this.options.components?.custom:this.options.components?.[t.kind]??fa)?.(i)??null}};function ga(e){switch(e.kind){case"heading":return d("h3",{className:"fillo-heading",text:e.text});case"paragraph":return d("p",{className:"fillo-paragraph",text:e.text});case"divider":return d("hr",{className:"fillo-divider"})}return d("div")}function ba(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return A(n,[d("div",{className:"fillo-success-mark",attrs:{"aria-hidden":"true"}}),d("h2",{className:"fillo-success-title",text:e.settings.successTitle??"Thanks!"}),d("p",{className:"fillo-success-message",text:e.settings.successMessage??"Your response has been recorded."})]),t.appendChild(n),t}function Mn(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:Ws(t),target:"_blank",rel:"noopener noreferrer"}})}function Di(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function va(){return Fi()}function ya(){return d("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 and preview.)",attrs:{role:"alert"}})}function wa(e){return d("div",{className:"fillo-devwarning",text:`Form sync needs attention${e.code?` (${e.code})`:""}: ${e.message} The safe form remains available for development.`,attrs:{role:"alert"}})}function _a(){return d("div",{className:"fillo-devwarning",text:"Code changes are staged. Local preview only. Publish in Fillo before deploying for respondents.",attrs:{role:"alert"}})}function xa(e){let t=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});t.append("Draft form \u2014 it renders here, but it won't accept responses until you publish it in your Fillo dashboard. ");let n=ut(e);return n&&(t.append("Connect storage to publish: "),t.appendChild(d("a",{text:n,attrs:{href:n,target:"_blank",rel:"noopener noreferrer"}})),t.append(". ")),t.append("(Shown only in development and preview.)"),t}function ka(){return d("span",{className:"fillo-preview-badge",text:"Preview",attrs:{"data-fillo":"preview-badge"}})}var Ui=!1;function $a(){Ui||Pn()||(Ui=!0,console.warn("[fillo] `preview` is enabled in a production build. Preview is cosmetic only \u2014 it shows developer chrome and never changes where submissions go or whether they are accepted \u2014 but remove it before respondents see this page."))}function za(e){let t=[];return e.preview&&t.push(ka()),e.devNotices===!1||(e.syncError?t.push(wa(e.syncError)):e.staged?t.push(_a()):e.draft?t.push(xa(e.warningUrl)):e.noClient&&t.push(ya())),t}function Sa(e){return e.status===404?T.loadFailedNotFound:e.status===0?T.loadFailedNetwork:e.status===422?T.renderFailed:T.loadFailed}function ct(e){return G(e)?e:new $(e instanceof Error?e.message:String(e),0)}function It(e,t){let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new $(`Fillo mount target not found: ${String(e)}`,0);return new dt(n,{...t,initialData:t.initialData??{}})}function Vi(e){let t=d("div");return It(t,e),t}var Ea=typeof HTMLElement<"u"?HTMLElement:class{},Ln=class extends Ea{instance=null;assignedForm;assignedClient;assignedTheme;assignedInitialData;mounted=!1;mountScheduled=!1;static get observedAttributes(){return["publishable-key","form-id","data-preview"]}connectedCallback(){this.scheduleMount()}disconnectedCallback(){this.instance?.destroy(),this.instance=null,this.mounted=!1}attributeChangedCallback(){this.mounted&&this.isConnected&&this.scheduleMount()}set form(t){this.assignedForm=t,this.mounted&&this.scheduleMount()}get form(){return this.assignedForm}set client(t){this.assignedClient=t,this.mounted&&this.instance instanceof dt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof dt&&this.instance.setTheme(t)}set initialData(t){this.assignedInitialData=t,this.mounted&&this.scheduleMount()}scheduleMount(){this.mountScheduled||(this.mountScheduled=!0,queueMicrotask(()=>{this.mountScheduled=!1,this.isConnected&&this.mount()}))}previewAttrEnabled(){let t=this.getAttribute("data-preview");return t!==null&&t!=="false"&&t!=="0"}mount(){this.instance?.destroy();let t=this.getAttribute("publishable-key")??void 0,n=this.getAttribute("form-id")??void 0,r=this.assignedClient??(n||t?st({key:t}):void 0);this.instance=It(this,{form:this.assignedForm,client:r,formId:n,theme:this.assignedTheme,initialData:this.assignedInitialData,preview:this.previewAttrEnabled()?!0:void 0,onChange:i=>this.dispatchEvent(new CustomEvent("fillo-change",{detail:{data:i}})),onSubmitted:(i,o)=>this.dispatchEvent(new CustomEvent("fillo-submit",{detail:{responseId:i,data:o}})),onError:i=>this.dispatchEvent(new CustomEvent("fillo-error",{detail:{error:i}}))}),this.mounted=!0}};function Rn(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,Ln)}typeof customElements<"u"&&Rn();return to(Aa);})();
1
+ "use strict";var Fillo=(()=>{var Pt=Object.defineProperty;var eo=Object.getOwnPropertyDescriptor;var to=Object.getOwnPropertyNames;var no=Object.prototype.hasOwnProperty;var ro=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},io=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of to(t))!no.call(e,i)&&i!==n&&Pt(e,i,{get:()=>t[i],enumerable:!(r=eo(t,i))||r.enumerable});return e};var oo=e=>io(Pt({},"__esModule",{value:!0}),e);var Pa={};ro(Pa,{FilloClient:()=>At,FilloError:()=>z,createClient:()=>Me,createFormElement:()=>Ki,defineForm:()=>Mn,registerFilloElement:()=>Un,renderForm:()=>Mt});var qn;function E(e,t,n){function r(a,l){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:l,constr:s,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,l);let u=s.prototype,c=Object.keys(u);for(let h=0;h<c.length;h++){let m=c[h];m in a||(a[m]=u[m].bind(a))}}let i=n?.Parent??Object;class o extends i{}Object.defineProperty(o,"name",{value:e});function s(a){var l;let u=n?.Parent?new o:this;r(u,a),(l=u._zod).deferred??(l.deferred=[]);for(let c of u._zod.deferred)c();return u}return Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}var fe=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(qn=globalThis).__zod_globalConfig??(qn.__zod_globalConfig={});var Zt=globalThis.__zod_globalConfig;function ve(e){return e&&Object.assign(Zt,e),Zt}function Kn(e){let t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,i])=>t.indexOf(+r)===-1).map(([r,i])=>i)}function Gn(e,t){return typeof t=="bigint"?t.toString():t}function Jn(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Rt(e){return e==null}function Xn(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Wn=Symbol("evaluating");function ye(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Wn)return r===void 0&&(r=Wn,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var Dt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ht(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ut(e){if(ht(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(ht(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Bt(e){return Ut(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var Yn=new Set(["string","number","symbol"]);function We(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function jt(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function j(e){let t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Qn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var so={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ke(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function er(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function we(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function ft(e){return typeof e=="string"?e:e?.message}function _e(e,t,n){let r=e.message?e.message:ft(e.inst?._zod.def?.error?.(e))??ft(t?.error?.(e))??ft(n.customError?.(e))??ft(n.localeError?.(e))??"Invalid input",{inst:i,continue:o,input:s,...a}=e;return a.path??(a.path=[]),a.message=r,t?.reportInput&&(a.input=s),a}function Vt(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var tr=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Gn,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},nr=E("$ZodError",tr),Ge=E("$ZodError",tr,{Parent:Error});var lo=e=>(t,n,r,i)=>{let o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new fe;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>_e(l,o,ve())));throw Dt(a,i?.callee),a}return s.value},mt=lo(Ge),uo=e=>async(t,n,r,i)=>{let o=r?{...r,async:!0}:{async:!0},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>_e(l,o,ve())));throw Dt(a,i?.callee),a}return s.value},gt=uo(Ge),co=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new fe;return o.issues.length?{success:!1,error:new(e??nr)(o.issues.map(s=>_e(s,i,ve())))}:{success:!0,data:o.value}},Je=co(Ge),po=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(s=>_e(s,i,ve())))}:{success:!0,data:o.value}},Xe=po(Ge);var rr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var fo="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",ho=new RegExp(`^${fo}$`);var ir=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Ht=/^-?\d+(?:\.\d+)?$/;var Ce=E("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),mo={number:"number",bigint:"bigint",object:"date"};var sr=E("$ZodCheckGreaterThan",(e,t)=>{Ce.init(e,t);let n=mo[typeof t.value];e._zod.onattach.push(r=>{let i=r._zod.bag,o=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>o&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}});var ar=E("$ZodCheckMaxLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Rt(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{let i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{let i=r.value;if(i.length<=t.maximum)return;let s=Vt(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),lr=E("$ZodCheckMinLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Rt(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{let i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{let i=r.value;if(i.length>=t.minimum)return;let s=Vt(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var ur=E("$ZodCheckStringFormat",(e,t)=>{var n,r;Ce.init(e,t),e._zod.onattach.push(i=>{let o=i._zod.bag;o.format=t.format,t.pattern&&(o.patterns??(o.patterns=new Set),o.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})});var dr={major:4,minor:4,patch:3};var Q=E("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=dr;let r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(let i of r)for(let o of i._zod.onattach)o(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(s,a,l)=>{let u=Ke(s),c;for(let h of a){if(h._zod.def.when){if(er(s)||!h._zod.def.when(s))continue}else if(u)continue;let m=s.issues.length,f=h._zod.check(s);if(f instanceof Promise&&l?.async===!1)throw new fe;if(c||f instanceof Promise)c=(c??Promise.resolve()).then(async()=>{await f,s.issues.length!==m&&(u||(u=Ke(s,m)))});else{if(s.issues.length===m)continue;u||(u=Ke(s,m))}}return c?c.then(()=>s):s},o=(s,a,l)=>{if(Ke(s))return s.aborted=!0,s;let u=i(a,r,l);if(u instanceof Promise){if(l.async===!1)throw new fe;return u.then(c=>e._zod.parse(c,l))}return e._zod.parse(u,l)};e._zod.run=(s,a)=>{if(a.skipChecks)return e._zod.parse(s,a);if(a.direction==="backward"){let u=e._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});return u instanceof Promise?u.then(c=>o(c,s,a)):o(u,s,a)}let l=e._zod.parse(s,a);if(l instanceof Promise){if(a.async===!1)throw new fe;return l.then(u=>i(u,r,a))}return i(l,r,a)}}ye(e,"~standard",()=>({validate:i=>{try{let o=Je(e,i);return o.success?{value:o.data}:{issues:o.error?.issues}}catch{return Xe(e,i).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}))}),qt=E("$ZodString",(e,t)=>{Q.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??ir(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Wt=E("$ZodStringFormat",(e,t)=>{ur.init(e,t),qt.init(e,t)});var mr=E("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=rr),Wt.init(e,t)});var gr=E("$ZodNumber",(e,t)=>{Q.init(e,t),e._zod.pattern=e._zod.bag.pattern??Ht,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;let o=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}});var br=E("$ZodUnknown",(e,t)=>{Q.init(e,t),e._zod.parse=n=>n});function pr(e,t,n){e.issues.length&&t.issues.push(...we(n,e.issues)),t.value[n]=e.value}var vr=E("$ZodArray",(e,t)=>{Q.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);let o=[];for(let s=0;s<i.length;s++){let a=i[s],l=t.element._zod.run({value:a,issues:[]},r);l instanceof Promise?o.push(l.then(u=>pr(u,n,s))):pr(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function bt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...we(n,e.issues))}if(!s&&!i){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?s&&(t.value[n]=void 0):t.value[n]=e.value}function bo(e){let t=Object.keys(e.shape);for(let r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);let n=Qn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function vo(e,t,n,r,i,o){let s=[],a=i.keySet,l=i.catchall._zod,u=l.def.type,c=l.optin==="optional",h=l.optout==="optional";for(let m in t){if(m==="__proto__"||a.has(m))continue;if(u==="never"){s.push(m);continue}let f=l.run({value:t[m],issues:[]},r);f instanceof Promise?e.push(f.then(p=>bt(p,n,m,t,c,h))):bt(f,n,m,t,c,h)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}var yr=E("$ZodObject",(e,t)=>{if(Q.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){let a=t.shape;Object.defineProperty(t,"shape",{get:()=>{let l={...a};return Object.defineProperty(t,"shape",{value:l}),l}})}let r=Jn(()=>bo(t));ye(e._zod,"propValues",()=>{let a=t.shape,l={};for(let u in a){let c=a[u]._zod;if(c.values){l[u]??(l[u]=new Set);for(let h of c.values)l[u].add(h)}}return l});let i=ht,o=t.catchall,s;e._zod.parse=(a,l)=>{s??(s=r.value);let u=a.value;if(!i(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),a;a.value={};let c=[],h=s.shape;for(let m of s.keys){let f=h[m],p=f._zod.optin==="optional",g=f._zod.optout==="optional",v=f._zod.run({value:u[m],issues:[]},l);v instanceof Promise?c.push(v.then(k=>bt(k,a,m,u,p,g))):bt(v,a,m,u,p,g)}return o?vo(c,u,a,l,r.value,e):c.length?Promise.all(c).then(()=>a):a}});var wr=E("$ZodRecord",(e,t)=>{Q.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Ut(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;let o=[],s=t.keyType._zod.values;if(s){n.value={};let a=new Set;for(let u of s)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){a.add(typeof u=="number"?u.toString():u);let c=t.keyType._zod.run({value:u,issues:[]},r);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(c.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(f=>_e(f,r,ve())),input:u,path:[u],inst:e});continue}let h=c.value,m=t.valueType._zod.run({value:i[u],issues:[]},r);m instanceof Promise?o.push(m.then(f=>{f.issues.length&&n.issues.push(...we(u,f.issues)),n.value[h]=f.value})):(m.issues.length&&n.issues.push(...we(u,m.issues)),n.value[h]=m.value)}let l;for(let u in i)a.has(u)||(l=l??[],l.push(u));l&&l.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:l})}else{n.value={};for(let a of Reflect.ownKeys(i)){if(a==="__proto__"||!Object.prototype.propertyIsEnumerable.call(i,a))continue;let l=t.keyType._zod.run({value:a,issues:[]},r);if(l instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&Ht.test(a)&&l.issues.length){let h=t.keyType._zod.run({value:Number(a),issues:[]},r);if(h instanceof Promise)throw new Error("Async schemas not supported in object keys currently");h.issues.length===0&&(l=h)}if(l.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(h=>_e(h,r,ve())),input:a,path:[a],inst:e});continue}let c=t.valueType._zod.run({value:i[a],issues:[]},r);c instanceof Promise?o.push(c.then(h=>{h.issues.length&&n.issues.push(...we(a,h.issues)),n.value[l.value]=h.value})):(c.issues.length&&n.issues.push(...we(a,c.issues)),n.value[l.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}});var _r=E("$ZodEnum",(e,t)=>{Q.init(e,t);let n=Kn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>Yn.has(typeof i)).map(i=>typeof i=="string"?We(i):i.toString()).join("|")})$`),e._zod.parse=(i,o)=>{let s=i.value;return r.has(s)||i.issues.push({code:"invalid_value",values:n,input:s,inst:e}),i}}),xr=E("$ZodLiteral",(e,t)=>{if(Q.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");let n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?We(r):r?We(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,i)=>{let o=r.value;return n.has(o)||r.issues.push({code:"invalid_value",values:t.values,input:o,inst:e}),r}});function fr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var kr=E("$ZodOptional",(e,t)=>{Q.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ye(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ye(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Xn(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){let i=n.value,o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>fr(s,i)):fr(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var $r=E("$ZodDefault",(e,t)=>{Q.init(e,t),e._zod.optin="optional",ye(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(o=>hr(o,t)):hr(i,t)}});function hr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function zr(e,t){return new e({type:"string",...j(t)})}function Sr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...j(t)})}function Er(e,t){return new e({type:"number",checks:[],...j(t)})}function Ar(e){return new e({type:"unknown"})}function Kt(e,t){return new sr({check:"greater_than",...j(t),value:e,inclusive:!0})}function Gt(e){return Kt(0,e)}function q(e,t){return new ar({check:"max_length",...j(t),maximum:e})}function Oe(e,t){return new lr({check:"min_length",...j(t),minimum:e})}var le=E("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");Q.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>mt(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Je(e,n,r),e.parseAsync=async(n,r)=>gt(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>Xe(e,n,r),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0}),e.with=e.check,e.clone=(n,r)=>jt(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.apply=n=>n(e)}),Fr=E("ZodMiniString",(e,t)=>{qt.init(e,t),le.init(e,t)});function W(e){return zr(Fr,e)}var wo=E("ZodMiniStringFormat",(e,t)=>{Wt.init(e,t),Fr.init(e,t)}),_o=E("ZodMiniEmail",(e,t)=>{mr.init(e,t),wo.init(e,t)});function vt(e){return Sr(_o,e)}var xo=E("ZodMiniNumber",(e,t)=>{gr.init(e,t),le.init(e,t)});function Ir(e){return Er(xo,e)}var ko=E("ZodMiniUnknown",(e,t)=>{br.init(e,t),le.init(e,t)});function Ye(){return Ar(ko)}var $o=E("ZodMiniArray",(e,t)=>{vr.init(e,t),le.init(e,t)});function xe(e,t){return new $o({type:"array",element:e,...j(t)})}var Nr=E("ZodMiniObject",(e,t)=>{yr.init(e,t),le.init(e,t),ye(e,"shape",()=>t.shape)});function Qe(e,t){let n={type:"object",shape:e??{},...j(t)};return new Nr(n)}function Jt(e,t){return new Nr({type:"object",shape:e,catchall:Ye(),...j(t)})}var Cr=E("ZodMiniRecord",(e,t)=>{wr.init(e,t),le.init(e,t)});function Mr(e,t,n){return!t||!t._zod?new Cr({type:"record",keyType:W(),valueType:e,...j(t)}):new Cr({type:"record",keyType:e,valueType:t,...j(n)})}var zo=E("ZodMiniEnum",(e,t)=>{_r.init(e,t),le.init(e,t),e.options=Object.values(t.entries)});function Tr(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new zo({type:"enum",entries:n,...j(t)})}var So=E("ZodMiniLiteral",(e,t)=>{xr.init(e,t),le.init(e,t)});function Lr(e,t){return new So({type:"literal",values:Array.isArray(e)?e:[e],...j(t)})}var Eo=E("ZodMiniOptional",(e,t)=>{kr.init(e,t),le.init(e,t)});function G(e){return new Eo({type:"optional",innerType:e})}var Ao=E("ZodMiniDefault",(e,t)=>{$r.init(e,t),le.init(e,t)});function Xt(e,t){return new Ao({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Bt(t)}})}var Io=["heading","paragraph","divider"];function ee(e){return!Io.includes(e.kind)}function wn(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:typeof e=="boolean"?e===!1:typeof e=="object"?Object.keys(e).length===0:!1}function Yr(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="number"&&typeof t=="string"&&t.trim()!==""){let n=Number(t);return Number.isNaN(n)?t:n}if((e.kind==="rating"||e.kind==="linear_scale")&&typeof t=="string"){let n=Number(t);return Number.isNaN(n)?t:n}return typeof t=="string"?t.trim():t}function No(e,t){let n=Yr(e,t);return wn(n)?void 0:n}function Qr(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function ei(e,t){let n=10**t,r=Math.round(Math.abs(e)*n)/n;return e<0?-r:r}function Fe(e){return Number.isFinite(e)?e:null}function Ue(e,t){switch(e.op){case"value":return pn(t(e.fieldId));case"const":return Fe(e.value);case"add":case"mul":case"min":case"max":{if(e.args.length===0)return null;let n=[];for(let r of e.args){let i=Ue(r,t);if(i===null)return null;n.push(i)}return e.op==="add"?Fe(n.reduce((r,i)=>r+i,0)):e.op==="mul"?Fe(n.reduce((r,i)=>r*i,1)):e.op==="min"?Math.min(...n):Math.max(...n)}case"sub":case"div":{let n=Ue(e.left,t);if(n===null)return null;let r=Ue(e.right,t);return r===null?null:e.op==="sub"?Fe(n-r):r===0?null:Fe(n/r)}case"round":{let n=Ue(e.arg,t);return n===null?null:Fe(ei(n,Qr(e.decimals)))}case"if":return Ue(_n(e.when,t)?e.then:e.else,t)}}function Mo(e,t){let n=Ue(e.calc,t);return n===null||e.decimals===void 0?n:Fe(ei(n,Qr(e.decimals)))}function Re(e,t){let n=ge(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=hn(e,r);for(let a=0;a<=n.length;a++){let l={},u=!1;for(let[c,h]of Object.entries(r))i.has(c)?l[c]=h:u=!0;if(!u)break;r=l,i=hn(e,r)}let o=St(n,r),s={};for(let[a,l]of Object.entries(t))o.calcIds.has(a)||(s[a]=l);for(let[a,l]of Object.entries(o.calc))i.has(a)&&(s[a]=l);return s}function Yt(e){return e==null?!1:typeof e=="string"?e.trim()!=="":Array.isArray(e)?e.length>0:typeof e=="boolean"?e:typeof e=="object"?Object.keys(e).length>0:!0}function Pr(e,t){return e===t?!0:typeof e=="number"&&typeof t=="string"&&t.trim()!==""?Number(t)===e:typeof t=="number"&&typeof e=="string"&&e.trim()!==""?Number(e)===t:!1}function pn(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e!="string"||e.trim()==="")return null;let t=Number(e);return Number.isFinite(t)?t:null}function To(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return Yt(n);case"not_answered":return!Yt(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):Pr(n,e.value);case"neq":return Yt(n)?Array.isArray(n)?!n.some(r=>r===e.value):!Pr(n,e.value):!1;case"contains":return typeof n=="string"?n.toLowerCase().includes(String(e.value??"").toLowerCase()):Array.isArray(n)?n.some(r=>r===e.value):!1;case"gt":case"lt":{let r=pn(n),i=pn(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function _n(e,t){return e.length===0?!0:e.every(n=>To(n,t))}function ti(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:_n(e.visibleIf,t)}function Qt(e,t,n,r,i,o){return s=>n.has(s)?r.has(s)?i.has(s)?o[s]:e[s]:void 0:t[s]}function St(e,t){let n=new Set(e.map(l=>l.id)),r=e.filter(l=>l.kind==="calculated"),i=new Set(r.map(l=>l.id)),o={};for(let l of e){if(l.kind==="calculated")continue;let u=No(l,t[l.id]);u!==void 0&&(o[l.id]=u)}let s=n,a={};for(let l=0;l<=e.length;l++){let u=a;if(r.length>0){u={...a};let f=Qt(o,t,n,s,i,u);for(let p of r){let g=s.has(p.id)?Mo(p,f):null;g===null?delete u[p.id]:u[p.id]=g}}let c=Qt(o,t,n,s,i,u),h=new Set;for(let f of e)ti(f,c)&&h.add(f.id);let m=h.size===s.size&&[...h].every(f=>s.has(f))&&Lo(a,u);if(s=h,a=u,m)break}return{visible:s,calc:a,calcIds:i,resolve:Qt(o,t,n,s,i,a)}}function Lo(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function ni(e,t){return St(e,t).visible}function yt(e,t,n){let r=St(ge(e),n);return t.blocks.filter(i=>ee(i)?r.visible.has(i.id):ti(i,r.resolve))}function ge(e){return e.pages.flatMap(t=>t.blocks.filter(ee))}function ri(e,t){let n=e.responseLimit?.scopeField;if(!n)return null;let r=t[n];return typeof r=="number"?Number.isFinite(r)?String(r):null:typeof r!="string"?null:r.trim()||null}function ii(e,t){let n=ge(e),r=ni(n,t);return n.filter(i=>r.has(i.id))}function Po(e,t){return St(ge(e),t).resolve}function oi(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=Po(e,n);for(let s of i)if(_n(s.when,o))return s.to==="end"?{end:!0}:{to:s.to};return{linear:!0}}function Be(e,t){let n=[];if(e.pages.length===0)return n;let r=new Set,i=0;for(let o=0;o<=e.pages.length;o++){let s=e.pages[i];if(!s||r.has(s.id))break;r.add(s.id),n.push(s.id);let a=oi(e,s.id,t);if("end"in a)break;if("to"in a){let l=e.pages.findIndex(u=>u.id===a.to);if(l<0)break;i=l}else if(i+=1,i>=e.pages.length)break}return n}function Zo(e,t){return new Set(Be(e,t))}function fn(e,t,n){if("end"in oi(e,t,n))return!0;let r=Be(e,n);return r.length>0&&r[r.length-1]===t}function hn(e,t){let n=Zo(e,t),r=ni(ge(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)ee(s)&&r.has(s.id)&&i.add(s.id);return i}function si(e,t){let n=hn(e,t);return ge(e).filter(r=>n.has(r.id))}var De;function Oo(){if(De!==void 0)return De??void 0;if(typeof Intl>"u"||typeof Intl.DisplayNames>"u"){De=null;return}try{De=new Intl.DisplayNames(void 0,{type:"region"})}catch{De=null}return De??void 0}function ai(e){try{return Oo()?.of(e)??e}catch{return e}}var y=(e,t,n=[],r=[],i="")=>({iso2:e,name:ai(e),dialCode:t,lengths:n,groups:r,example:i}),Ro=[y("US","1",[10],[3,3,4],"2015550123"),y("CA","1",[10],[3,3,4],"5145550123"),y("GB","44",[10],[4,6],"7400123456"),y("AU","61",[9],[3,3,3],"412345678"),y("DE","49",[10,11],[4,7],"15123456789"),y("FR","33",[9],[1,2,2,2,2],"612345678"),y("IN","91",[10],[5,5],"8123456789"),y("DK","45",[8],[2,2,2,2],"32123456"),y("SE","46",[9],[2,3,4],"701234567"),y("NO","47",[8],[3,2,3],"40612345"),y("FI","358",[9,10],[2,3,4],"412345678"),y("NL","31",[9],[1,4,4],"612345678"),y("BE","32",[9],[3,2,2,2],"470123456"),y("ES","34",[9],[3,3,3],"612345678"),y("IT","39",[9,10],[3,3,4],"3123456789"),y("PT","351",[9],[3,3,3],"912345678"),y("IE","353",[9],[2,3,4],"851234567"),y("CH","41",[9],[2,3,2,2],"781234567"),y("AT","43",[10,11],[3,7],"6641234567"),y("PL","48",[9],[3,3,3],"512345678"),y("CZ","420",[9],[3,3,3],"601123456"),y("GR","30",[10],[3,3,4],"6912345678"),y("RO","40",[9],[3,3,3],"712345678"),y("HU","36",[9],[2,3,4],"201234567"),y("UA","380",[9],[2,3,2,2],"501234567"),y("RU","7",[10],[3,3,2,2],"9123456789"),y("TR","90",[10],[3,3,2,2],"5012345678"),y("IL","972",[9],[2,3,4],"501234567"),y("AE","971",[9],[2,3,4],"501234567"),y("SA","966",[9],[2,3,4],"512345678"),y("ZA","27",[9],[2,3,4],"711234567"),y("NG","234",[10],[3,3,4],"8021234567"),y("KE","254",[9],[3,3,3],"712123456"),y("EG","20",[10],[3,3,4],"1001234567"),y("BR","55",[10,11],[2,5,4],"11961234567"),y("MX","52",[10],[3,3,4],"2221234567"),y("AR","54",[10],[4,6],"1123456789"),y("CL","56",[9],[1,4,4],"221234567"),y("CO","57",[10],[3,3,4],"3211234567"),y("PE","51",[9],[3,3,3],"912345678"),y("CN","86",[11],[3,4,4],"13123456789"),y("JP","81",[10],[2,4,4],"9012345678"),y("KR","82",[9,10],[2,4,4],"1023456789"),y("SG","65",[8],[4,4],"81234567"),y("HK","852",[8],[4,4],"51234567"),y("TW","886",[9],[3,3,3],"912345678"),y("MY","60",[9,10],[2,3,4],"123456789"),y("ID","62",[10,11],[3,4,4],"81234567890"),y("TH","66",[9],[2,3,4],"812345678"),y("PH","63",[10],[3,3,4],"9171234567"),y("VN","84",[9],[3,3,3],"912345678"),y("PK","92",[10],[3,3,4],"3012345678"),y("BD","880",[10],[2,4,4],"1812345678"),y("NZ","64",[9,10],[2,3,4],"211234567"),y("SK","421",[9],[3,3,3],"912123456"),y("BG","359",[9],[2,3,4],"481234567"),y("HR","385",[8,9],[2,3,4],"921234567"),y("RS","381",[8,9],[2,3,4],"601234567"),y("SI","386",[8],[2,3,3],"31234567"),y("LT","370",[8],[3,2,3],"61234567"),y("LV","371",[8],[2,3,3],"21234567"),y("EE","372",[7,8],[3,4],"51234567"),y("IS","354",[7],[3,4],"6111234"),y("LU","352",[9],[3,3,3],"628123456"),y("MA","212",[9],[3,3,3],"650123456"),y("CR","506",[8],[4,4],"83123456"),y("EC","593",[9],[2,3,4],"991234567"),y("UY","598",[8],[1,3,4],"94231234"),y("QA","974",[8],[4,4],"33123456"),y("KW","965",[8],[4,4],"50012345")],Do="AD376 AF93 AG1 AI1 AL355 AM374 AO244 AS1 AW297 AX358 AZ994 BA387 BB1 BF226 BH973 BI257 BJ229 BL590 BM1 BN673 BO591 BQ599 BS1 BT975 BV47 BW267 BY375 BZ501 CC61 CD243 CF236 CG242 CI225 CK682 CM237 CU53 CV238 CW599 CX61 CY357 DJ253 DM1 DO1 DZ213 EH212 ER291 ET251 FJ679 FK500 FM691 FO298 GA241 GD1 GE995 GF594 GG44 GH233 GI350 GL299 GM220 GN224 GP590 GQ240 GS500 GT502 GU1 GW245 GY592 HN504 HT509 IM44 IO246 IQ964 IR98 JE44 JM1 JO962 KG996 KH855 KI686 KM269 KN1 KP850 KY1 KZ7 LA856 LB961 LC1 LI423 LK94 LR231 LS266 LY218 MC377 MD373 ME382 MF590 MG261 MH692 MK389 ML223 MM95 MN976 MO853 MP1 MQ596 MR222 MS1 MT356 MU230 MV960 MW265 MZ258 NA264 NC687 NE227 NF672 NI505 NP977 NR674 NU683 OM968 PA507 PF689 PG675 PM508 PN64 PR1 PS970 PW680 PY595 RE262 RW250 SB677 SC248 SD249 SH290 SJ47 SL232 SM378 SN221 SO252 SR597 SS211 ST239 SV503 SX1 SY963 SZ268 TC1 TD235 TF262 TG228 TJ992 TK690 TL670 TM993 TN216 TO676 TT1 TV688 TZ255 UG256 UZ998 VA379 VC1 VE58 VG1 VI1 VU678 WF681 WS685 XK383 YE967 YT262 ZM260 ZW263";function Uo(e){let t=[];for(let n of e.trim().split(/\s+/)){let r=n.slice(0,2),i=n.slice(2);t.push({iso2:r,name:ai(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var rt=[...Ro,...Uo(Do)],je=Bo(rt);function Bo(e){if(typeof Intl>"u"||typeof Intl.Collator>"u")return[...e].sort((n,r)=>n.iso2<r.iso2?-1:n.iso2>r.iso2?1:0);let t=new Intl.Collator(void 0,{sensitivity:"base"});return[...e].sort((n,r)=>t.compare(n.name,r.name))}var jo=new Map(rt.map(e=>[e.iso2,e])),Vo={"Africa/Cairo":"EG","Africa/Casablanca":"MA","Africa/Johannesburg":"ZA","Africa/Lagos":"NG","Africa/Nairobi":"KE","America/Adak":"US","America/Anchorage":"US","America/Argentina/Buenos_Aires":"AR","America/Argentina/Cordoba":"AR","America/Argentina/Mendoza":"AR","America/Bahia":"BR","America/Belem":"BR","America/Bogota":"CO","America/Boise":"US","America/Boa_Vista":"BR","America/Cancun":"MX","America/Chicago":"US","America/Chihuahua":"MX","America/Campo_Grande":"BR","America/Costa_Rica":"CR","America/Cuiaba":"BR","America/Denver":"US","America/Detroit":"US","America/Edmonton":"CA","America/Fortaleza":"BR","America/Guayaquil":"EC","America/Halifax":"CA","America/Hermosillo":"MX","America/Indiana/Indianapolis":"US","America/Indianapolis":"US","America/Juneau":"US","America/Kentucky/Louisville":"US","America/Lima":"PE","America/Los_Angeles":"US","America/Maceio":"BR","America/Manaus":"BR","America/Matamoros":"MX","America/Mazatlan":"MX","America/Merida":"MX","America/Mexico_City":"MX","America/Moncton":"CA","America/Monterrey":"MX","America/Montevideo":"UY","America/New_York":"US","America/Noronha":"BR","America/Nome":"US","America/North_Dakota/Center":"US","America/Ojinaga":"MX","America/Phoenix":"US","America/Porto_Velho":"BR","America/Punta_Arenas":"CL","America/Recife":"BR","America/Regina":"CA","America/Rio_Branco":"BR","America/Santiago":"CL","America/Sao_Paulo":"BR","America/Sitka":"US","America/St_Johns":"CA","America/Tijuana":"MX","America/Toronto":"CA","America/Vancouver":"CA","America/Whitehorse":"CA","America/Winnipeg":"CA","America/Yakutat":"US","Asia/Bangkok":"TH","Asia/Calcutta":"IN","Asia/Dacca":"BD","Asia/Dhaka":"BD","Asia/Dubai":"AE","Asia/Hong_Kong":"HK","Asia/Ho_Chi_Minh":"VN","Asia/Jakarta":"ID","Asia/Jerusalem":"IL","Asia/Karachi":"PK","Asia/Kolkata":"IN","Asia/Kuala_Lumpur":"MY","Asia/Kuwait":"KW","Asia/Manila":"PH","Asia/Qatar":"QA","Asia/Riyadh":"SA","Asia/Seoul":"KR","Asia/Shanghai":"CN","Asia/Saigon":"VN","Asia/Singapore":"SG","Asia/Taipei":"TW","Asia/Tel_Aviv":"IL","Asia/Tokyo":"JP","Asia/Urumqi":"CN","Atlantic/Reykjavik":"IS","Australia/Adelaide":"AU","Australia/Brisbane":"AU","Australia/Darwin":"AU","Australia/Hobart":"AU","Australia/Melbourne":"AU","Australia/Perth":"AU","Australia/Sydney":"AU","Europe/Amsterdam":"NL","Europe/Athens":"GR","Europe/Belgrade":"RS","Europe/Berlin":"DE","Europe/Bratislava":"SK","Europe/Brussels":"BE","Europe/Bucharest":"RO","Europe/Budapest":"HU","Europe/Copenhagen":"DK","Europe/Dublin":"IE","Europe/Helsinki":"FI","Europe/Zagreb":"HR","Europe/Istanbul":"TR","Europe/Kiev":"UA","Europe/Kyiv":"UA","Europe/Lisbon":"PT","Europe/Ljubljana":"SI","Europe/London":"GB","Europe/Luxembourg":"LU","Europe/Madrid":"ES","Europe/Moscow":"RU","Europe/Oslo":"NO","Europe/Paris":"FR","Europe/Prague":"CZ","Europe/Riga":"LV","Europe/Rome":"IT","Europe/Sofia":"BG","Europe/Stockholm":"SE","Europe/Tallinn":"EE","Europe/Vienna":"AT","Europe/Vilnius":"LT","Europe/Warsaw":"PL","Europe/Zurich":"CH","Pacific/Auckland":"NZ"};function xn(e){let t=e.toUpperCase();return/^[A-Z]{2}$/.test(t)?String.fromCodePoint(...[...t].map(n=>127462+n.charCodeAt(0)-65)):"\u{1F3F3}\uFE0F"}function Et(e){return e?jo.get(e.toUpperCase()):void 0}function li(e){return Et(e?Vo[e]:void 0)}function Ho(e){let t;for(let n of rt)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function de(e){return e.replace(/[^\d]/g,"")}function it(e,t){let n=de(t);if(!n)return"";let r=e?.groups?.length?e.groups:[],i=[],o=0;for(let s of r){if(o>=n.length)break;i.push(n.slice(o,o+s)),o+=s}for(;o<n.length;)i.push(n.slice(o,o+3)),o+=3;return i.join(" ")}function ui(e,t){let n=de(t);return n?`+${e.dialCode}${n}`:""}function ot(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=de(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?de(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=Ho(o);if(a){let l=o.slice(a.dialCode.length);return{country:a,national:l,e164:`+${o}`}}return{national:o,e164:`+${o}`,pending:!0,raw:r}}if(!o)return{country:t,national:"",e164:""};if(t){let s=o.startsWith(t.dialCode)?o.slice(t.dialCode.length):o;return{country:t,national:s,e164:`+${t.dialCode}${s}`}}return{national:o,e164:`+${o}`}}function qo(e){let{country:t,national:n,e164:r}=ot(e);if(!r)return!1;let i=de(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var Wo=8;function ci(e,t){if(!e||!t||typeof window>"u")return"below";let n=Wo,r=document.documentElement.clientWidth||window.innerWidth,i=document.documentElement.clientHeight||window.innerHeight,o=e.getBoundingClientRect(),s=Math.max(0,i-o.bottom-n),a=Math.max(0,o.top-n),l=s<t.scrollHeight&&a>s?"above":"below",c=Math.max(0,Math.min(l==="above"?a:s,i-n*2)),h=Math.max(0,r-n*2);t.style.setProperty("--fillo-phone-popover-max-height",`${Math.floor(c)}px`),t.style.setProperty("--fillo-phone-popover-max-width",`${Math.floor(h)}px`),t.style.setProperty("--fillo-phone-popover-offset-x","0px");let m=Math.min(t.offsetWidth,h),p=getComputedStyle(e).direction==="rtl"?o.right-m:o.left,g=0,v=p+m-(r-n);v>0&&(g-=v);let k=n-(p+g);return k>0&&(g+=k),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(g)}px`),l}var st="This field is required",T={back:"Back",next:"Next",submit:"Submit",submitting:"Submitting\u2026",uploading:"Uploading\u2026",optional:" (optional)",other:"Other",otherPrompt:"Other \u2014 please specify",otherPlaceholder:"Your answer",choosePlaceholder:"Choose\u2026",successTitle:"Thanks!",successMessage:"Your response has been recorded.",closed:"This form is no longer accepting responses.",notLive:"This form isn't live yet.",notOpenTitle:"This form isn't open yet",notOpenBody:"The form owner is still setting things up. Please check back soon.",closedTitle:"Responses are closed",submitFailed:"This form can't submit right now. Please try again in a moment.",loadFailedNotFound:"Form not found \u2014 check the form id and that it's published.",loadFailedNetwork:"Couldn't reach the server \u2014 check your connection or CORS.",loadFailed:"This form could not be loaded.",renderFailed:"This form could not be rendered.",resumeNotice:"Picked up where you left off.",editNotice:"You're updating your earlier response.",resumeStartOver:"Start over",challengeUnavailable:"The verification check couldn't load. Refresh the page, or check that challenges.cloudflare.com isn't blocked."},Ko={short_text:"Enter your answer",long_text:"Enter your answer",email:"Enter an email address",url:"Enter a URL",phone:"Enter a phone number",number:"Enter a number",select:"Choose an option",dropdown:"Choose an option",multi_select:"Select at least one option",checkbox:"Select this checkbox",rating:"Choose a rating",linear_scale:"Choose a value",ranking:"Rank every option",matrix:"Answer every row",signature:"Add your signature",date:"Enter a date",file_upload:"Add a file"};function Go(e){return Ko[e.kind]??st}var Z={required:st,requiredForField:Go,resumeLinkExpired:"That saved-progress link expired or was already used \u2014 start again below.",alreadyAnswered:"You've already answered this form.",uploadRetry:"Retry",uploadCancel:"Cancel",uploadRemove:"Remove",uploadDismiss:"Dismiss",uploadingFile:(e,t)=>`Uploading \xB7 ${e}% \xB7 ${t}`,uploadedFile:e=>`Uploaded \xB7 ${e}`,uploadsDisabled:"Connect this form to Fillo to enable uploads",uploadsRenderOnly:"Uploads are unavailable in this render-only preview",uploadsUnavailable:"Uploads are temporarily unavailable",uploadUnavailable:"We couldn't upload this file right now. Try again in a moment.",uploadFailed:"Upload failed \u2014 try again",dropzoneTitle:e=>`Drop ${e?"files":"a file"} here or click to browse`,dropzoneHint:e=>`Up to ${e} MB per file`,fileTooLarge:e=>`Larger than ${e} MB limit`,filesUploading:e=>`Uploading ${e} ${e===1?"file":"files"}, please wait\u2026`,uploadsFailed:e=>`${e} ${e===1?"upload":"uploads"} failed.`,filesUploaded:e=>`${e} ${e===1?"file":"files"} uploaded.`,submittingAnnouncement:"Submitting your response\u2026",errorSummaryTitle:"Check these fields",rankingPosition:(e,t,n)=>`${e}, position ${t} of ${n}`,phoneCountrySelected:e=>`${e} selected`,phoneResultsCount:e=>`${e} ${e===1?"result":"results"}`,signatureEmpty:"No signature yet",signatureSigned:"Signature saved"};function di(e,t){return t.requiredForField?.(e)??t.required}var Jo=Qe({fileId:W().check(Oe(1)),name:W(),size:Ir().check(Gt()),mime:W(),url:G(W())});function pi(e,t){if(wn(t))return e.kind==="calculated"?null:e.required?st:null;switch(e.kind){case"short_text":case"long_text":{if(typeof t!="string")return"Expected text";if(e.maxLength&&t.length>e.maxLength)return`Must be at most ${e.maxLength} characters`;let n=e.kind==="long_text"?2e4:2e3;return!e.maxLength&&t.length>n?"Answer is too long":null}case"email":return typeof t!="string"?"Enter a valid email address":e.maxLength&&t.length>e.maxLength?`Must be at most ${e.maxLength} characters`:vt().safeParse(t).success?null:"Enter a valid email address";case"url":{if(typeof t!="string")return"Enter a valid URL (including https://)";if(e.maxLength&&t.length>e.maxLength)return`Must be at most ${e.maxLength} characters`;try{let n=new URL(t);if(n.protocol!=="http:"&&n.protocol!=="https:")return"Enter an http(s) URL"}catch{return"Enter a valid URL (including https://)"}return null}case"phone":return typeof t!="string"||!qo(t)?"Enter a valid phone number":null;case"number":{let n=typeof t=="string"?Number(t):t;return typeof n!="number"||!Number.isFinite(n)?"Enter a number":e.min!==void 0&&n<e.min?`Must be at least ${e.min}`:e.max!==void 0&&n>e.max?`Must be at most ${e.max}`:null}case"select":case"dropdown":return typeof t!="string"||t===""?"Pick an option":e.options.some(n=>n.id===t)||e.allowOther&&t.length<=500?null:"Pick a valid option";case"multi_select":{if(!Array.isArray(t))return"Pick at least one option";let n=new Set(e.options.map(s=>s.id)),r=t,i=0,o=new Set;for(let s of r){if(typeof s!="string")return"Pick valid options";if(o.has(s))return"Pick each option only once";if(o.add(s),!n.has(s)){if(e.allowOther!==!0||s.length===0||s.length>500)return"Pick valid options";if(++i>1)return"Only one 'Other' answer is allowed"}}return null}case"checkbox":return typeof t=="boolean"?null:"Invalid value";case"rating":{let n=e.max??5,r=typeof t=="string"?Number(t):t;return typeof r!="number"||!Number.isInteger(r)||r<1||r>n?`Pick a rating between 1 and ${n}`:null}case"linear_scale":{let n=e.min??1,r=e.max??10,i=typeof t=="string"?Number(t):t;return typeof i!="number"||!Number.isInteger(i)||i<n||i>r?`Pick a value between ${n} and ${r}`:null}case"ranking":{if(!Array.isArray(t))return"Drag the options into order";let n=e.options.map(i=>i.id).sort(),r=[...t].sort();return n.length!==r.length||n.some((i,o)=>i!==r[o])?"Rank every option":null}case"matrix":{if(typeof t!="object"||t===null||Array.isArray(t))return"Answer the grid";let n=t,r=new Set(e.columns.map(o=>o.id)),i=new Set(e.rows.map(o=>o.id));for(let[o,s]of Object.entries(n))if(!i.has(o)||!r.has(s))return"Invalid grid answer";return e.required&&Object.keys(n).length<e.rows.length?"Answer every row":null}case"signature":return typeof t!="string"||!t.startsWith("data:image/")?"Sign in the box":null;case"hidden":return typeof t=="string"?null:"Invalid value";case"calculated":return null;case"custom":return null;case"date":{if(typeof t!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(t))return"Enter a valid date";let[n,r,i]=t.split("-").map(Number),o=new Date(Date.UTC(n,r-1,i));return o.getUTCFullYear()!==n||o.getUTCMonth()!==r-1||o.getUTCDate()!==i?"Enter a valid date":null}case"file_upload":{let n=xe(Jo).safeParse(t);if(!n.success)return"Upload did not complete";let r=e.maxFiles??1;return n.data.length>r?`At most ${r} file${r===1?"":"s"}`:null}}}function fi(e,t){let n=si(e,t),r={},i={};for(let o of n){if(o.kind==="calculated")continue;let s=Yr(o,t[o.id]),a=pi(o,s);a?r[o.id]=a:wn(s)||(i[o.id]=s)}return{ok:Object.keys(r).length===0,errors:r,data:i}}var Xo=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","calculated","custom"],Yo=["heading","paragraph","divider"],Qo=[...Xo,...Yo],kn=W().check(Oe(1),q(128)),en=Jt({id:kn,label:W().check(q(1e3)),icon:G(Ye())}),es=Jt({id:kn,kind:Tr(Qo),label:G(W().check(q(2e3))),options:G(xe(en).check(q(200))),rows:G(xe(en).check(q(200))),columns:G(xe(en).check(q(200)))}),ts=Qe({id:kn,title:G(W().check(q(500))),blocks:xe(es).check(q(500)),next:G(Ye())}),ns=Qe({version:Lr(1),title:Xt(G(W().check(q(2e3))),""),description:G(W().check(q(5e3))),pages:xe(ts).check(Oe(1),q(50)),settings:Xt(G(Mr(W(),Ye())),{})}),rs=1,mn=1,gn="0.12.1";function te(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function U(e,t){let n=te(e,t);return n===""?void 0:n}function wt(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function he(e){return typeof e=="boolean"?e:void 0}function me(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function ce(e,t,n,r){let i=me(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function _t(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=te(r.id,128),o=te(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[P({id:i,label:o,icon:s})]:[]}):[]}function tn(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function $n(e){if(!Array.isArray(e))return;let t=e.slice(0,20).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=r.op;if(i!=="eq"&&i!=="neq"&&i!=="contains"&&i!=="gt"&&i!=="lt"&&i!=="answered"&&i!=="not_answered")return[];let o=te(r.fieldId,128);if(!o)return[];let s=r.value,a=typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:void 0;return[{fieldId:o,op:i,...a!==void 0?{value:a}:{}}]});return t.length?t:void 0}function hi(e,t,n,r){let i=t.get(e);if(i===void 0)return n.has(e);if(r.has(e))return!0;r.add(e);for(let o of i)if(!hi(o,t,n,r))return!1;return!0}function is(e,t,n,r,i){if(!Array.isArray(e))return;let o=e.slice(0,50).flatMap(s=>{if(!s||typeof s!="object")return[];let a=s,l=typeof a.to=="string"?a.to:void 0;if(!l||l!=="end"&&!t.has(l))return[];if(l===n)return[];let u=a.when;if(u!==void 0&&!Array.isArray(u))return[];let c=$n(u);return Array.isArray(u)&&u.length>0&&c===void 0?[]:c&&c.some(h=>!hi(h.fieldId,i,r,new Set))?[]:[{when:c??[],to:l}]});return o.length?o:void 0}var os=["number","rating","linear_scale","calculated"];function $e(e,t=0){if(t>32||!e||typeof e!="object"||Array.isArray(e))return null;let n=e;switch(n.op){case"value":{let r=te(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=me(n.value);return r===void 0?null:{op:"const",value:r}}case"add":case"mul":case"min":case"max":{if(!Array.isArray(n.args)||n.args.length<1||n.args.length>50)return null;let r=[];for(let i of n.args){let o=$e(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=$e(n.left,t+1),i=$e(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=$e(n.arg,t+1);return r?P({op:"round",arg:r,decimals:me(n.decimals)===void 0?void 0:ce(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=$n(n.when)??[];if(r.length!==n.when.length)return null;let i=$e(n.then,t+1),o=$e(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function ze(e,t,n){switch(e.op){case"value":t.add(e.fieldId);return;case"const":return;case"add":case"mul":case"min":case"max":for(let r of e.args)ze(r,t,n);return;case"sub":case"div":ze(e.left,t,n),ze(e.right,t,n);return;case"round":ze(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);ze(e.then,t,n),ze(e.else,t,n);return}}function ss(e){let t=new Map;for(let o of e)for(let s of o.blocks)ee(s)&&t.set(s.id,s.kind);let n=new Map;for(let o of e)for(let s of o.blocks){if(s.kind!=="calculated")continue;let a=$e(s.calc);if(!a)return`Field ${s.id} has a malformed calc expression \u2014 build it from value/const/add/sub/mul/div/min/max/round/if nodes`;s.calc=a;let l=new Set,u=new Set;ze(a,l,u);for(let c of l){let h=t.get(c);if(h===void 0)return`Calculated field ${s.id} references a missing field: ${c} \u2014 remove the reference or restore that field`;if(!os.includes(h))return`Calculated field ${s.id} references non-numeric field ${c} (${h}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}n.set(s.id,[...l,...u].filter(c=>t.get(c)==="calculated"))}let r=new Map,i=(o,s)=>{let a=r.get(o);if(a==="done")return null;if(a==="visiting"){let l=[...s.slice(s.indexOf(o)),o].join(" \u2192 ");return`Calculated field ${o} depends on its own result (${l}) \u2014 break the cycle so the value can be computed`}r.set(o,"visiting");for(let l of n.get(o)??[]){let u=i(l,[...s,o]);if(u)return u}return r.set(o,"done"),null};for(let o of n.keys()){let s=i(o,[]);if(s)return s}return null}var Zr=100,Or=5e3;function Ie(e){switch(e.op){case"value":case"const":return 1;case"add":case"mul":case"min":case"max":return 1+e.args.reduce((t,n)=>t+Ie(n),0);case"sub":case"div":return 1+Ie(e.left)+Ie(e.right);case"round":return 1+Ie(e.arg);case"if":return 1+Ie(e.then)+Ie(e.else)}}function as(e){let t=0,n=0;for(let r of e)for(let i of r.blocks)i.kind==="calculated"&&(t+=1,n+=Ie(i.calc));return t>Zr?`Form has ${t} calculated fields \u2014 the maximum is ${Zr}; remove some or consolidate them into fewer expressions`:n>Or?`Calculated expressions total ${n} operations \u2014 the maximum is ${Or} across the form; simplify or split up the calculations`:null}function mi(e){return{id:te(e.id,128),visibleIf:$n(e.visibleIf)}}function V(e,t){return{...mi(e),kind:t,label:te(e.label,2e3,"Untitled field"),description:U(e.description,5e3),required:he(e.required),placeholder:U(e.placeholder,500)}}function Rr(e){let t=U(e,2e3);if(t)try{let n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"?t:void 0}catch{return}}function ls(e){if(!e||typeof e!="object")return;let t=e,n=t.by==="browser"||t.by==="field"||t.by==="identify"?t.by:void 0;if(!n)return;let r=n==="field"?U(t.field,128):void 0;if(n==="field"&&!r)return;let i=U(t.scopeField,128),o=t.onRepeat==="update"&&n==="identify"?"update":"keep";return{by:n,...r?{field:r}:{},...i?{scopeField:i}:{},onRepeat:o}}function us(e){if(!e||typeof e!="object")return;let t=e,n=t.unverified==="allow"||t.unverified==="quarantine"?t.unverified:void 0,r=t.challenge==="turnstile"?"turnstile":void 0;if(!(!n&&!r))return{...n?{unverified:n}:{},...r?{challenge:r}:{}}}function cs(e){let t=e&&typeof e=="object"?e:{};return{submitMode:t.submitMode==="button"||t.submitMode==="auto"?t.submitMode:void 0,submitLabel:U(t.submitLabel,100),successTitle:U(t.successTitle,200),successMessage:U(t.successMessage,5e3),redirectUrl:Rr(t.redirectUrl),showProgress:he(t.showProgress),responseLimit:ls(t.responseLimit),trust:us(t.trust),notifyEmail:vt().check(q(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,sendReceipt:he(t.sendReceipt),saveProgress:he(t.saveProgress),draftAnswersVisible:he(t.draftAnswersVisible),resumeEmails:he(t.resumeEmails),resumeUrl:Rr(t.resumeUrl),draftDigest:he(t.draftDigest)}}function P(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function ds(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=mi(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return P({...r,kind:n,text:te(t.text,2e3,"Section")});case"paragraph":return P({...r,kind:n,text:te(t.text,5e3)});case"divider":return P({...r,kind:n});case"short_text":case"email":case"url":return P({...V(t,n),maxLength:me(t.maxLength)===void 0?void 0:ce(t.maxLength,1,2e3,2e3)});case"phone":{let i=U(t.defaultCountry,2)?.toUpperCase();return P({...V(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return P({...V(t,n),maxLength:me(t.maxLength)===void 0?void 0:ce(t.maxLength,1,2e4,2e4)});case"number":return P({...V(t,n),min:me(t.min),max:me(t.max),decimals:me(t.decimals)===void 0?void 0:ce(t.decimals,0,6,0),prefix:wt(t.prefix,100),suffix:wt(t.suffix,100),notation:t.notation==="grouped"?"grouped":t.notation==="grouped-comma"?"grouped-comma":t.notation==="grouped-dot"?"grouped-dot":void 0});case"select":case"multi_select":case"dropdown":{let i=_t(t.options);return i.length===0?null:P({...V(t,n),options:i,allowOther:he(t.allowOther),shuffleOptions:he(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return P({...V(t,n),appearance:i})}case"signature":case"date":return P(V(t,n));case"rating":{let i=ce(t.max,1,10,5);return P({...V(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=ce(t.min,0,9,1),o=ce(t.max,i+1,10,10),s=t.insightsMetric==="nps"&&i===0&&o===10?"nps":t.insightsMetric==="csat"&&i===1&&o===5?"csat":void 0;return P({...V(t,n),min:i,max:o,minLabel:U(t.minLabel,100),maxLabel:U(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=_t(t.options);return i.length<2?null:P({...V(t,n),options:i})}case"matrix":{let i=_t(t.rows),o=_t(t.columns);return i.length===0||o.length===0?null:P({...V(t,n),rows:i,columns:o})}case"hidden":return P({...V(t,n),required:!1,paramName:U(t.paramName,128),defaultValue:U(t.defaultValue,1e3)});case"calculated":return P({...V(t,n),required:!1,calc:t.calc,decimals:me(t.decimals)===void 0?void 0:ce(t.decimals,0,6,0),prefix:wt(t.prefix,100),suffix:wt(t.suffix,100)});case"file_upload":return P({...V(t,n),maxFiles:ce(t.maxFiles,1,20,1),maxFileSizeMb:ce(t.maxFileSizeMb,1,5e3,500),accept:Array.isArray(t.accept)?t.accept.flatMap(i=>{let o=U(i,100);return o?[o]:[]}).slice(0,50):void 0});case"custom":return P({...V(t,n),component:te(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function Ne(e){let t=ns.safeParse(e);if(!t.success){let f=t.error.issues[0],p=f?.path.join(".");return{ok:!1,error:f?`${p?`${p}: `:""}${f.message}`:"Invalid schema"}}if(t.data.version>rs)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(f=>{let p=f.blocks.flatMap(g=>{let v=ds(g);return v?[v]:[]});return{id:te(f.id,128),title:U(f.title,500),blocks:p,next:f.next}}),r=new Set(n.map(f=>f.id)),i=new Map;for(let f of n)for(let p of f.blocks){if(p.kind!=="calculated")continue;let g=new Set,v=$e(p.calc);if(v){let k=new Set,F=new Set;ze(v,k,F);for(let M of k)g.add(M);for(let M of F)g.add(M)}i.set(p.id,g)}let o=new Set,s=n.map(f=>{for(let p of f.blocks)ee(p)&&o.add(p.id);return P({id:f.id,title:f.title,blocks:f.blocks,next:is(f.next,r,f.id,new Set(o),i)})}),a=new Set,l=new Set;for(let f of s){if(!f.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(f.id))return{ok:!1,error:`Duplicate page id: ${f.id}`};a.add(f.id);for(let p of f.blocks){if(l.has(p.id))return{ok:!1,error:`Duplicate block id: ${p.id}`};if(l.add(p.id),p.kind==="number"&&p.min!==void 0&&p.max!==void 0&&p.min>p.max)return{ok:!1,error:`Field ${p.id} has min greater than max`};if(p.kind==="select"||p.kind==="multi_select"||p.kind==="dropdown"||p.kind==="ranking"){let g=tn(p.options);if(g)return{ok:!1,error:`Duplicate option id in field ${p.id}: ${g}`}}else if(p.kind==="matrix"){let g=tn(p.rows);if(g)return{ok:!1,error:`Duplicate matrix row id in field ${p.id}: ${g}`};let v=tn(p.columns);if(v)return{ok:!1,error:`Duplicate matrix column id in field ${p.id}: ${v}`}}}}let u=ss(s);if(u)return{ok:!1,error:u};let c=as(s);if(c)return{ok:!1,error:c};if(s.every(f=>f.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let h={version:mn,title:te(t.data.title,2e3),pages:s,settings:cs(t.data.settings)},m=U(t.data.description,5e3);return m&&(h.description=m),{ok:!0,schema:h}}function et(e,t){let n=U(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function zn(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=t.colorScheme==="light"||t.colorScheme==="dark"||t.colorScheme==="auto"?t.colorScheme:void 0,r=P({colorScheme:n,primary:et(t.primary,200),background:et(t.background,200),text:et(t.text,200),radius:et(t.radius,64),fontFamily:et(t.fontFamily,200)});return Object.keys(r).length>0?r:null}function ps(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function gi(e,t){if(t==null||t==="")return"";switch(e.kind){case"file_upload":return Array.isArray(t)?t.map(n=>n.name).join(", "):String(t);case"select":case"dropdown":return e.options.find(n=>n.id===t)?.label??String(t);case"multi_select":return Array.isArray(t)?t.map(n=>e.options.find(r=>r.id===n)?.label??n).join(", "):String(t);case"ranking":return Array.isArray(t)?t.map((n,r)=>`${r+1}. ${e.options.find(i=>i.id===n)?.label??n}`).join(", "):String(t);case"matrix":{if(typeof t!="object"||t===null||Array.isArray(t))return String(t);let n=t;return e.rows.filter(r=>n[r.id]).map(r=>`${r.label}: ${e.columns.find(i=>i.id===n[r.id])?.label??""}`).join(", ")}case"signature":return typeof t=="string"&&t.startsWith("data:image/")?"\u270D signed":"";case"checkbox":return t===!0?"Yes":"No";case"rating":case"linear_scale":return String(t);case"number":{let n=typeof t=="number"?t:Number(t);if(!Number.isFinite(n))return String(t);let r=e.decimals===void 0?String(n):n.toFixed(Math.max(0,Math.min(6,e.decimals)));return`${e.prefix??""}${r}${e.suffix??""}`}case"calculated":{let n=typeof t=="number"?t:Number(t);if(!Number.isFinite(n))return String(t);let r=e.decimals===void 0?String(n):n.toFixed(Math.max(0,Math.min(6,e.decimals)));return`${e.prefix??""}${r}${e.suffix??""}`}case"phone":{let{country:n,national:r,e164:i}=ot(String(t));if(!i)return String(t);let o=it(n,r),s=n?`+${n.dialCode}`:i.replace(r,"");return o?`${s} ${o}`:i}case"short_text":case"long_text":case"email":case"url":case"date":case"hidden":return String(t);case"custom":return typeof t=="object"?JSON.stringify(t):String(t);default:return ps(e)}}function fs(e){return Math.max(0,Math.min(6,Math.round(e)))}function bi(e){switch(e){case"grouped-comma":return"en-US";case"grouped-dot":return"de-DE";case"grouped":case void 0:return}}function vi(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:fs(t.decimals);if(typeof Intl>"u")return n===void 0?String(e):e.toFixed(n);let r={useGrouping:!0};return n===void 0?r.maximumFractionDigits=20:(r.minimumFractionDigits=n,r.maximumFractionDigits=n),new Intl.NumberFormat(t?.locale,r).format(e)}function yi(e,t){return t?e.split(t).join(""):e}function Dr(e,t){return t==="."?e:e.split(t).join(".")}function hs(e,t,n){if(n!==t&&e.includes(n)){let o=e.lastIndexOf(n),s=yi(e.slice(0,o),t),a=e.slice(o+n.length);return`${s}.${a}`}let r=e.split(t);return r.length===1?e:r.every((o,s)=>s===0?/^[1-9]\d{0,2}$/.test(o):/^\d{3}$/.test(o))?r.join(""):`${r.slice(0,-1).join("")}.${r.at(-1)??""}`}function Sn(e,t){if(typeof Intl>"u"||e.trim()==="")return e;let n=new Intl.NumberFormat(t).formatToParts(12345678e-1),r=n.find(a=>a.type==="group")?.value??",",i=n.find(a=>a.type==="decimal")?.value??".",o=e.trim(),s=o.startsWith("-");return s&&(o=o.slice(1)),/^\s$/.test(r)?o=Dr(o.replace(/\s/g,""),i):r==="."||r===","?o=hs(o,r,i):o=Dr(yi(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function at(e,t){let r=e.startsWith("-")?e.slice(1):e;if(r.includes("-"))return!1;if(r==="")return!0;if(typeof Intl>"u")return/^[\d.,]*$/.test(r);let i=new Intl.NumberFormat(t).formatToParts(12345678e-1),o=i.find(h=>h.type==="group")?.value??",",s=i.find(h=>h.type==="decimal")?.value??".",a=o===".",l=/^\s$/.test(o),u=a?[s]:Array.from(new Set([".",s])),c=0;for(let h of r)if(!/\d/.test(h)){if(u.includes(h)){if(++c>1)return!1;continue}if(!(l?/\s/.test(h):h===o))return!1}return!0}var bn="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",ms=256-256%bn.length;function Ur(e=12){if(!Number.isSafeInteger(e)||e<=0)throw new RangeError("createId size must be a positive safe integer");let t=globalThis.crypto;if(typeof t>"u"||typeof t.getRandomValues!="function")throw new Error("createId requires Web Crypto (globalThis.crypto.getRandomValues)");let n="";for(;n.length<e;){let r=new Uint8Array(e);t.getRandomValues(r);for(let i=0;i<e&&n.length<e;i++){let o=r[i];o<ms&&(n+=bn[o%bn.length])}}return n}var wi=class{h0=1732584193;h1=4023233417;h2=2562383102;h3=271733878;h4=3285377520;block=new Uint8Array(64);blockLen=0;totalLen=0;w=new Int32Array(80);update(e){this.totalLen+=e.length;let t=0;if(this.blockLen>0){for(;t<e.length&&this.blockLen<64;)this.block[this.blockLen++]=e[t++];this.blockLen===64&&(this.process(this.block),this.blockLen=0)}for(;t+64<=e.length;)this.process(e.subarray(t,t+64)),t+=64;for(;t<e.length;)this.block[this.blockLen++]=e[t++];return this}digest(){let e=Math.floor(this.totalLen/536870912),t=this.totalLen*8>>>0,n=[128],r=this.blockLen+1;for(;r%64!==56;)n.push(0),r++;n.push(e>>>24&255,e>>>16&255,e>>>8&255,e&255),n.push(t>>>24&255,t>>>16&255,t>>>8&255,t&255),this.update(new Uint8Array(n));let i=new Uint8Array(20),o=[this.h0,this.h1,this.h2,this.h3,this.h4];for(let s=0;s<5;s++)i[s*4]=o[s]>>>24&255,i[s*4+1]=o[s]>>>16&255,i[s*4+2]=o[s]>>>8&255,i[s*4+3]=o[s]&255;return i}process(e){let t=this.w;for(let a=0;a<16;a++)t[a]=e[a*4]<<24|e[a*4+1]<<16|e[a*4+2]<<8|e[a*4+3];for(let a=16;a<80;a++){let l=t[a-3]^t[a-8]^t[a-14]^t[a-16];t[a]=l<<1|l>>>31}let n=this.h0,r=this.h1,i=this.h2,o=this.h3,s=this.h4;for(let a=0;a<80;a++){let l,u;a<20?(l=r&i|~r&o,u=1518500249):a<40?(l=r^i^o,u=1859775393):a<60?(l=r&i|r&o|i&o,u=2400959708):(l=r^i^o,u=3395469782);let c=(n<<5|n>>>27)+l+s+u+t[a]|0;s=o,o=i,i=r<<30|r>>>2,r=n,n=c}this.h0=this.h0+n|0,this.h1=this.h1+r|0,this.h2=this.h2+i|0,this.h3=this.h3+o|0,this.h4=this.h4+s|0}},xt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function En(e){let t="";for(let n=0;n<e.length;n+=3){let r=e[n],i=n+1<e.length?e[n+1]:0,o=n+2<e.length?e[n+2]:0;t+=xt[r>>2],t+=xt[(r&3)<<4|i>>4],t+=n+1<e.length?xt[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?xt[o&63]:"="}return t}var gs=e=>En(new wi().update(e).digest()),z=class extends Error{constructor(e,t,n,r){super(e),this.status=t,this.retryAfterSec=n,this.code=r,this.name="FilloError"}status;retryAfterSec;code};function J(e){return e instanceof Error&&e.name==="FilloError"}async function Br(e,t){try{let n=await e.json();return{message:typeof n.error=="string"&&n.error?n.error:t,code:typeof n.code=="string"&&n.code?n.code:void 0}}catch{}return{message:t}}function jr(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var tt=3,nt=3e4,bs=5*6e4,ue=10*6e4;function Vr(e,t){return t?.throwIfAborted(),new Promise((n,r)=>{let i=()=>{clearTimeout(o),r(t?.reason)},o=setTimeout(()=>{t?.removeEventListener("abort",i),n()},e);t?.addEventListener("abort",i,{once:!0})})}function nn(e,t=!1){let n=J(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&J(e)&&e.retryAfterSec!==void 0}function kt(e){return e>=500||e===429||e===408}function Hr(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new z("Request timed out",0):e}function vs(e,t){let n=e.split(".").map(i=>Number(i)||0),r=t.split(".").map(i=>Number(i)||0);for(let i=0;i<Math.max(n.length,r.length);i++){let o=(n[i]??0)-(r[i]??0);if(o!==0)return o}return 0}function ys(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==mn)throw new z(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${mn}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&vs(gn,e.minSdkVersion)<0)throw new z(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${gn}.`,426)}function $t(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function ws(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return En(new Uint8Array(n))}return gs(e)}var _s="https://fillo.so",qr={"X-Fillo-Client":`@usefillo/core@${gn}`},At=class{baseUrl;fetch;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":_s,this.key=e.key,this.fetch=e.fetch??((...t)=>globalThis.fetch(...t))}url(e){return`${this.baseUrl}/api/v1${e}`}async json(e,t){let n=t?.body!=null?{"Content-Type":"application/json",...qr,...t?.headers}:t?.headers,r;try{r=await this.fetch(this.url(e),{...t,headers:n,signal:t?.signal??AbortSignal.timeout(nt)})}catch(i){throw Hr(i)}if(!r.ok){let{message:i,code:o}=await Br(r,`Request failed: ${r.status}`);throw new z(i,r.status,jr(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return ys(t),t}syncForm(e,t,n){if(!this.key)return Promise.reject(new z("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401));let r=Ne(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:zn(n)})}):Promise.reject(new z(`Invalid form schema: ${r.error}`,400))}async submit(e,t,n){let r;try{r=await this.fetch(this.url(`/forms/${encodeURIComponent(e)}/responses`),{method:"POST",headers:{"Content-Type":"application/json",...qr},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(nt)})}catch(o){throw Hr(o)}if(r.status===422)return{ok:!1,errors:(await r.json()).errors};if(!r.ok){let{message:o,code:s}=await Br(r,`Submit failed: ${r.status}`);throw new z(o,r.status,jr(r),s)}let i=await r.json();return{ok:!0,responseId:i.id,duplicate:i.duplicate,updated:i.updated}}async fetchOwnResponse(e,t,n){try{return await this.json(`/forms/${encodeURIComponent(e)}/respondent-response`,{method:"POST",body:JSON.stringify({respondent:t,scopeValue:n})})}catch(r){if(J(r)&&(r.status===404||r.status===403))return null;throw r}}async startSession(e,t){try{let n=await this.fetch(this.url(`/forms/${encodeURIComponent(e)}/sessions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageCount:t}),signal:AbortSignal.timeout(nt)});return n.ok?(await n.json()).id:null}catch{return null}}reportProgress(e,t){try{this.fetch(this.url(`/sessions/${encodeURIComponent(e)}/progress`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0,signal:AbortSignal.timeout(nt)}).catch(()=>{})}catch{}}createDraft(e,t){return this.json(`/forms/${encodeURIComponent(e)}/drafts`,{method:"POST",body:JSON.stringify(t)})}getDraft(e,t,n){return this.json(`/drafts/${encodeURIComponent(e)}`,{headers:n?{"X-Fillo-Draft-Token":t,"X-Fillo-Draft-Adopt":"1"}:{"X-Fillo-Draft-Token":t}})}async saveDraft(e,t,n,r){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"X-Fillo-Draft-Token":t},body:JSON.stringify(n),...r?.keepalive?{keepalive:!0}:{}})}async deleteDraft(e,t){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-Fillo-Draft-Token":t}})}getUploadSession(e,t,n=AbortSignal.timeout(ue)){return this.json(`/uploads/${encodeURIComponent(e)}`,{...t?{headers:{"X-Fillo-Upload-Token":t}}:{},signal:n})}async uploadFile(e,t,n){let r=typeof File<"u"&&t instanceof File?t.name:"upload.bin",i=(t.type||"application/octet-stream").trim().toLowerCase(),o;if(n.sessionId){let u=await this.getUploadSession(n.sessionId,n.uploadToken,this.uploadSignal(n,ue));if(u.formId!==e||u.fieldId!==n.fieldId||u.fileName!==r||u.size!==t.size||u.mime.trim().toLowerCase()!==i)throw new z("File does not match this upload session",400);o=u,o.token||=n.uploadToken}else{let u=Ur(24),c=Ur(32),h=()=>this.json(`/forms/${encodeURIComponent(e)}/uploads`,{method:"POST",body:JSON.stringify({requestId:u,uploadToken:c,fieldId:n.fieldId,fileName:r,size:t.size,mime:i}),signal:this.uploadSignal(n,ue)}),m=Date.now()+ue,f=250;for(;;)try{o=await h();break}catch(p){if(n.signal?.aborted||!nn(p,!0))throw p;let g=m-Date.now();if(g<=0)throw p;await Vr(Math.min(f,g),n.signal),f=Math.min(f*2,5e3)}}if(n.onSession?.({sessionId:o.id,uploadToken:o.token}),o.status==="complete"&&o.file)return o.file;if(o.status==="aborted")throw new z("This upload session was cancelled",409);let s;if(o.transport?.type==="gdrive")await this.driveUploadLoop(o,o.transport.uploadUrl,t,n);else if(o.transport?.type==="s3-multipart")await this.s3MultipartUploadLoop(o,t,n);else if(o.transport?.type==="s3-put")await this.s3PutUpload(o.transport.uploadUrl,t,n);else if(o.transport?.type==="box")s=await this.boxUpload(o.transport,t,n);else throw new z("This form's storage doesn't support uploads \u2014 connect Drive, S3, or Box.");let a=()=>this.json(`/uploads/${encodeURIComponent(o.id)}/complete`,{method:"POST",headers:o.token?{"X-Fillo-Upload-Token":o.token}:void 0,...s?{body:JSON.stringify(s)}:{},signal:this.uploadSignal(n,ue)}),l;try{l=await a()}catch(u){if(n.signal?.aborted||!nn(u))throw u;let c=Date.now()+ue,h=250;for(;;){let m=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,c-Date.now())));if(m.status==="complete"&&m.file)return m.file;if(m.status==="aborted")throw u;try{l=await a();break}catch(p){if(n.signal?.aborted||!nn(p,!0))throw p}let f=c-Date.now();if(f<=0)throw u;await Vr(Math.min(h,f),n.signal),h=Math.min(h*2,5e3)}}if(!l.file)throw new z("Upload completed but no file was returned");return l.file}async boxUpload(e,t,n){let r=$t(t.size,n);r(0);let i={Authorization:`Bearer ${e.token}`};if(e.mode==="simple"){let m=new FormData;m.append("attributes",JSON.stringify({name:e.fileName,parent:{id:e.folderId}})),m.append("file",t,e.fileName);let f=await this.retry(n,async()=>{let g=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:m,signal:this.uploadSignal(n)});if(!g.ok&&kt(g.status))throw new z(`Box upload failed: ${g.status}`,g.status);return g});if(!f.ok)throw new z(`Box upload failed: ${f.status}`,f.status);let p=await f.json();return r(t.size),{providerFileId:p.entries?.[0]?.id}}if(e.size!==t.size)throw new z(`File size changed since the upload was requested (${t.size} vs ${e.size}).`,400);let o=await this.retry(n,async()=>{let m=await this.fetch(e.sessionUrl,{method:"POST",headers:{...i,"Content-Type":"application/json"},body:JSON.stringify({folder_id:e.folderId,file_size:e.size,file_name:e.fileName}),signal:this.uploadSignal(n)});if(!m.ok&&kt(m.status))throw new z(`Box session failed: ${m.status}`,m.status);return m});if(!o.ok)throw new z(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new wi,l=[],u=0;for(;u<t.size;){n.signal?.throwIfAborted();let m=Math.min(u+s.part_size,t.size),f=new Uint8Array(await t.slice(u,m).arrayBuffer());a.update(f);let p=await ws(f),g=await this.retry(n,async()=>{let v=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${p}`,"Content-Range":`bytes ${u}-${m-1}/${t.size}`},body:f,signal:this.uploadSignal(n)});if(!v.ok&&kt(v.status))throw new z(`Box part failed: ${v.status}`,v.status);return v});if(!g.ok)throw new z(`Box part failed: ${g.status}`,g.status);l.push((await g.json()).part),u=m,r(u)}let c=await this.retry(n,async()=>{let m=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:{...i,"Content-Type":"application/json",Digest:`sha=${En(a.digest())}`},body:JSON.stringify({parts:l}),signal:this.uploadSignal(n)});if(!m.ok&&kt(m.status))throw new z(`Box commit failed: ${m.status}`,m.status);return m});if(!c.ok)throw new z(`Box commit failed: ${c.status}`,c.status);return{providerFileId:(await c.json()).entries?.[0]?.id}}uploadSignal(e,t=nt){let n=AbortSignal.timeout(t);return e.signal?AbortSignal.any([e.signal,n]):n}async retry(e,t){let n=0;for(;;)try{return await t()}catch(r){if(e.signal?.aborted||(n+=1,n>=tt))throw r;await new Promise(i=>setTimeout(i,500*2**n))}}async driveUploadLoop(e,t,n,r){let i=e.uploadedBytes,o=$t(n.size,r);o(i);let s=0;for(;i<n.size;){r.signal?.throwIfAborted();let a=i,l=Math.min(i+e.chunkSize,n.size),u=n.slice(i,l),c=0;for(;;)try{let h=await this.fetch(t,{method:"PUT",headers:{"Content-Range":`bytes ${i}-${l-1}/${n.size}`},body:u,signal:this.uploadSignal(r)});if(h.status===308){let m=h.headers.get("Range")??h.headers.get("range"),f=m?.match(/bytes=0-(\d+)/);f?i=Number(f[1])+1:m==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ue))).uploadedBytes;break}if(h.ok){i=n.size;break}throw new z(`Drive chunk failed: ${h.status}`,h.status)}catch(h){if(r.signal?.aborted||(c+=1,c>=tt))throw h;if(await new Promise(f=>setTimeout(f,500*2**c)),i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ue))).uploadedBytes,i>=n.size)break;l=Math.min(i+e.chunkSize,n.size),u=n.slice(i,l)}if(o(i),i<=a){if(++s>=tt)throw new z("Drive upload stalled \u2014 the storage endpoint stopped accepting progress",0)}else s=0}}async s3MultipartUploadLoop(e,t,n){if(!Number.isSafeInteger(e.chunkSize)||e.chunkSize<=0||!Number.isSafeInteger(e.uploadedBytes)||e.uploadedBytes<0||e.uploadedBytes>t.size||e.uploadedBytes<t.size&&e.uploadedBytes%e.chunkSize!==0)throw new z("S3 upload session returned invalid progress",502);let r=$t(t.size,n),i=e.uploadedBytes;for(r(i);i<t.size;){n.signal?.throwIfAborted();let o=Math.floor(i/e.chunkSize)+1;if(o>1e4)throw new z("S3 upload needs too many parts",413);let s=Math.min(i+e.chunkSize,t.size),a=t.slice(i,s),l=0;for(;;){let u;try{let c=await this.json(`/uploads/${encodeURIComponent(e.id)}/parts`,{method:"POST",headers:e.token?{"X-Fillo-Upload-Token":e.token}:void 0,body:JSON.stringify({partNumber:o}),signal:this.uploadSignal(n,ue)});if(typeof c.uploadUrl!="string"||!c.uploadUrl)throw new z("S3 part URL was unavailable",502);u=c.uploadUrl;let h=await this.fetch(u,{method:"PUT",body:a,signal:this.uploadSignal(n,bs)});if(!h.ok)throw new z(`S3 part upload failed: ${h.status}`,h.status);i=s,r(i);break}catch(c){if(n.signal?.aborted)throw c;let h=await this.getUploadSession(e.id,e.token,this.uploadSignal(n,ue));if(h.status==="aborted")throw new z("This upload session was cancelled",409);if(!Number.isSafeInteger(h.uploadedBytes)||h.uploadedBytes<i||h.uploadedBytes>t.size||h.uploadedBytes<t.size&&h.uploadedBytes%e.chunkSize!==0)throw new z("S3 upload session returned invalid progress",502);if(h.uploadedBytes>i){i=h.uploadedBytes,r(i);break}if(l+=1,l>=tt)throw c;await new Promise(m=>setTimeout(m,500*2**l))}}}}async s3PutUpload(e,t,n){let r=$t(t.size,n);r(0);let i=0;for(;;)try{let o=await this.fetch(e,{method:"PUT",headers:{"Content-Type":t.type||"application/octet-stream"},body:t,signal:this.uploadSignal(n)});if(!o.ok)throw new z(`S3 upload failed: ${o.status}`,o.status);r(t.size);return}catch(o){if(n.signal?.aborted||(i+=1,i>=tt))throw o;await new Promise(s=>setTimeout(s,500*2**i))}}};function Me(e={}){return new At(e)}function rn(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function Wr(e,t){let n={};for(let r of ge(e)){let i=r.kind==="hidden"?t[r.paramName??r.id]??r.defaultValue:t[r.id];if(!(i===void 0||i===""))switch(r.kind){case"number":{let o=rn(i);if(o===null||r.min!==void 0&&o<r.min||r.max!==void 0&&o>r.max)break;n[r.id]=o;break}case"rating":{let o=rn(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=rn(i),s=r.min??1,a=r.max??10;o!==null&&Number.isInteger(o)&&o>=s&&o<=a&&(n[r.id]=o);break}case"checkbox":n[r.id]=i==="true"||i==="1"||i==="yes";break;case"select":case"dropdown":{r.options.some(o=>o.id===i)&&(n[r.id]=i);break}case"multi_select":{let o=new Set(r.options.map(a=>a.id)),s=[...new Set(i.split(",").filter(a=>o.has(a)))];s.length>0&&(n[r.id]=s);break}case"file_upload":case"ranking":case"matrix":case"signature":case"custom":break;case"calculated":break;default:n[r.id]=i}}return n}var xs={id:"empty",blocks:[]},Kr=!1,Gr=!1;function ks(){Gr||(Gr=!0,console.warn("[fillo] This form has a client but no submission target \u2014 a bare schema can't sync. Wrap it in defineForm({ id, pages }) (or author it with <Fillo.Form id=\u2026>) so it gets a workspace handle, or pass formId for a dashboard-built form: https://fillo.so/docs"))}function $s(){Kr||(Kr=!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"))}var _i=new Map;function An(){try{return globalThis.localStorage??null}catch{return null}}function xi(e){return`fillo:submission:${e}`}function Cn(){let e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();let t=new Uint8Array(16);return e?.getRandomValues?(e.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")):`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function ki(e,t,n,r){let i=An();if(!i)return e.get(n)??null;try{let o=JSON.parse(i.getItem(t)??"null");if(o&&r(o))return o}catch{}return null}function $i(e,t,n,r){e.set(n,r);let i=An();if(i)try{i.setItem(t,JSON.stringify(r))}catch{}}function Fn(e){return ki(_i,xi(e),e,t=>typeof t.key=="string")}function zi(e,t){$i(_i,xi(e),e,t)}function zs(e){let t=Fn(e);if(t?.key)return t.key;let n={key:Cn()};return zi(e,n),n.key}function Ss(e,t){let n=Fn(e);zi(e,{key:n?.key??Cn(),submittedAt:new Date().toISOString(),responseId:t})}function vn(e,t,n){let r=ri(e.settings,n);return r===null?t:`${t}::${r}`}function Jr(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!Fn(vn(e,t,n))?.submittedAt}var In=new Map;function Nn(e){return`fillo:draft:${e}`}function zt(e){return ki(In,Nn(e),e,t=>{let n=t;return typeof n.id=="string"&&typeof n.token=="string"})}function on(e,t){$i(In,Nn(e),e,t)}function sn(e){In.delete(e);let t=An();if(t)try{t.removeItem(Nn(e))}catch{}}function an(e){return J(e)&&(e.status===401||e.status===403||e.status===404)}var Es=1500,As="Please complete the verification check, then submit.",Cs="That verification didn't go through. Please complete the check again and resubmit.";function Si(e){return J(e)&&e.status&&e.status>0&&e.message?e.message:"Couldn't reach the server \u2014 check your connection and try again. If this keeps happening, a browser extension, firewall, or the site's Content-Security-Policy may be blocking the request."}function Fs(e,t){if(J(e)){let n=e.status??0;if(t&&n>0&&e.message)return e.code?`${e.message} (${e.code})`:e.message;if(n>0&&n<500&&n!==408&&n!==429)return"This form is unavailable."}return Si(e)}function Ei(e){let{onChange:t,onSubmitted:n}=e,r=Ne(e.form);if(!r.ok)throw new Error(`Invalid form schema: ${r.error}`);let i=r.schema,o=e.formId,s=e.client,a=e.respondent,l=Re(i,{...e.initialData??{}}),u={},c=0,h="idle",m=!1,f=!1;queueMicrotask(()=>{if(typeof location<"u"&&location.search){let _=Object.fromEntries(new URLSearchParams(location.search)),w=null;for(let[$,I]of Object.entries(Wr(i,_)))l[$]===void 0&&(w=w??{...l},w[$]=I);w&&h==="idle"&&(l=Re(i,w),S())}h==="idle"&&Jr(i,o,l)&&(h="submitted",m=!0,S());let b=!1;if(i.settings.saveProgress&&o&&s&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let _=/fillo-draft=([^&]+)/.exec(location.hash),w=_?.[1]?decodeURIComponent(_[1]):"",$=w.indexOf(".");if($>0){b=!0;let I=w.slice(0,$),A=w.slice($+1);s.getDraft(I,A,!0).then(N=>{on(o,{id:I,token:N.token??A});try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(N=>{an(N)&&(f=!0,S())}).finally(()=>Y())}}b||Y()});let p,g=new Set,v=new Set,k=Date.now(),F=Cn(),M=null,ie=!1,oe=!1,Se=!1,X="created",Ee=!1,D=null,B=null,se=Promise.resolve(),ae=!1,qe=!1,Te=!1,x=!1;function re(){let b=i.pages.length,_=Math.min(c,Math.max(b-1,0)),w=i.pages[_]??xs;return{data:l,errors:u,status:h,pageIndex:_,pageCount:b,page:w,blocks:yt(i,w,l),isFirstPage:_===0,isLastPage:fn(i,w.id,l),uploading:g.size>0,submitError:p,restoredSubmission:m,resumedDraft:oe,editingPrevious:Se,duplicateSubmission:X==="duplicate",updatedSubmission:X==="updated",resumeLinkFailed:f}}let R=re();function S(){R=re();for(let b of v)b()}function Le(b,_){try{n?.(b,_)}catch(w){console.error("[fillo] onSubmitted handler threw:",w)}}function Pe(b){let _=i.pages[b];if(!_)return{};let w={};for(let $ of yt(i,_,l)){if(!ee($))continue;let I=pi($,l[$.id]);I&&(w[$.id]=I)}return w}function Ae(){return!!(i.settings.saveProgress&&s&&o&&!qe)}function L(){let b=new Set;for(let _ of i.pages)for(let w of _.blocks)ee(w)&&b.add(w.id);return b}function H(b){if(h!=="idle"||ie)return;let _=L(),w=null;for(let[A,N]of Object.entries(b.data??{}))l[A]===void 0&&_.has(A)&&(w=w??{...l},w[A]=N);let $=typeof b.page=="number"&&Number.isFinite(b.page)?Math.max(0,Math.min(Math.floor(b.page),i.pages.length-1)):0,I=$>0&&c===0;!w&&!I||(w&&(l=Re(i,w)),I&&(c=$),oe=!0,S())}function Y(){if(h!=="idle")return;if(!Ae()){be();return}let b=o,_=s,w=D??zt(b);if(w&&!Te){Te=!0,D=w,_.getDraft(w.id,w.token).then(H).catch($=>{an($)&&(sn(b),D=null)});return}!w&&!x&&a?.hash&&(x=!0,_.createDraft(b,{data:{},page:0,respondent:a}).then($=>{if(!D){if(D={id:$.id,token:$.token},on(b,D),$.existing)return _.getDraft($.id,$.token).then(H);be()}}).catch($=>{J($)&&$.status!==void 0&&$.status>=400&&$.status<500||(x=!1)}))}function be(){if(Ee||i.settings.responseLimit?.onRepeat!=="update"||!s||!o||!a?.hash||h!=="idle")return;Ee=!0;let b=s,_=ri(i.settings,l)??void 0;b.fetchOwnResponse(o,a,_).then(w=>{!w||h!=="idle"||ie||oe||(H({data:w.data,page:0}),oe&&(oe=!1,Se=!0,S()))}).catch(()=>{})}function Tt(b=!1){if(B&&(clearTimeout(B),B=null),!Ae()||h!=="idle"||!ae)return;let _=o,w=s;ae=!1,se=se.then(async()=>{let $={data:l,page:Math.max(0,Math.min(c,i.pages.length-1))},I=D??zt(_);try{if(I)try{await w.saveDraft(I.id,I.token,$,b?{keepalive:!0}:void 0),D=I;return}catch(N){if(!an(N))throw N;sn(_),D=null}let A=await w.createDraft(_,a?.hash?{...$,respondent:a}:$);D={id:A.id,token:A.token},on(_,D),A.existing&&(ae=!0)}catch(A){J(A)&&A.status!==void 0&&A.status>=400&&A.status<500&&A.status!==429?qe=!0:ae=!0}})}function Gi(){!Ae()||h!=="idle"||(ae=!0,B&&clearTimeout(B),B=setTimeout(()=>{B=null,Tt()},Es))}function Bn(){!Ae()||!ie&&!D||(ae=!0,Tt())}function jn(){B&&(clearTimeout(B),B=null),ae=!1,o&&sn(o),D=null}function Ji(b,_){!ie&&s&&o&&(ie=!0,s.startSession(o,i.pages.length).then(w=>M=w)),l=Re(i,{...l,[b]:_}),t?.(l),p=void 0,b in u&&(u=Object.fromEntries(Object.entries(u).filter(([w])=>w!==b))),S(),Gi()}function Xi(b,_){_?(g.add(b),b in u&&(u=Object.fromEntries(Object.entries(u).filter(([w])=>w!==b)))):g.delete(b),S()}function Vn(b){if(b.length===0)return-1;let _=i.pages.length,w=Math.min(c,Math.max(_-1,0)),$=i.pages[w]?.id,I=$===void 0?-1:b.indexOf($);if(I>=0)return I;let A=0;for(let N=0;N<b.length;N++){let pe=i.pages.findIndex(Lt=>Lt.id===b[N]);pe>=0&&pe<=w&&(A=N)}return A}function Yi(){let b=i.pages.length,_=Math.min(c,Math.max(b-1,0));if(!e.skipValidation){let pe=Pe(_);if(u=pe,Object.keys(pe).length>0){S();return}}let w=i.pages[_],$=Be(i,l),I=Vn($);if((w?fn(i,w.id,l):!0)||I<0||I+1>=$.length){Hn();return}let N=i.pages.findIndex(pe=>pe.id===$[I+1]);c=N>=0?N:Math.min(_+1,b-1),M&&s&&s.reportProgress(M,{furthestPage:c}),S(),Bn()}function Qi(){u={};let b=Be(i,l),_=Vn(b);if(_>0){let w=i.pages.findIndex($=>$.id===b[_-1]);c=w>=0?w:Math.max(Math.min(c,i.pages.length-1)-1,0)}else if(b.length>0){let w=i.pages.findIndex($=>$.id===b[0]);c=w>=0?w:0}S(),Bn()}async function Hn(){if(h==="submitting"||h==="submitted")return;let b=fi(i,l);if(!b.ok){let _=e.skipValidation&&!(s&&o),w=_?Object.fromEntries(Object.entries(b.errors).filter(([I])=>i.pages.every(A=>A.blocks.every(N=>!(ee(N)&&N.id===I&&N.kind==="file_upload"))))):b.errors;if(_&&Object.keys(w).length===0){u={},h="submitted",S(),Le(void 0,l);return}u=w;let $=i.pages.findIndex(I=>yt(i,I,l).some(A=>A.id in w));$>=0&&(c=$),S();return}if(s&&e.resolveFormId){h="submitting",p=void 0,S();try{o=await e.resolveFormId()}catch(_){throw h="idle",p=Fs(_,e.verboseResolutionErrors===!0),S(),_}}if(s&&o){let _=i.settings.responseLimit?.by==="browser"?zs(vn(i,o,b.data)):void 0,w=_??F,$=i.settings.saveProgress?D??zt(o):null,I=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!I){h="idle",p=As,S();return}h="submitting",p=void 0,S();let A;try{A=await s.submit(o,b.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-k,surface:e.surface??"headless",submissionKey:w,draft:$?{id:$.id,token:$.token}:void 0,respondent:a,challengeToken:I})}catch(N){if(h="idle",J(N)&&N.code==="challenge_failed"){p=Cs,e.onChallengeFailed?.(),S();return}throw p=Si(N),S(),N}if(!A.ok){u=A.errors??{};let N=i.pages.findIndex(pe=>yt(i,pe,l).some(Lt=>Lt.id in u));N>=0?c=N:p="We couldn't submit \u2014 please review your answers.",h="idle",S();return}X=A.duplicate?"duplicate":A.updated?"updated":"created",M&&s.reportProgress(M,{completed:!0}),_&&Ss(vn(i,o,b.data),A.responseId),jn(),h="submitted",S(),Le(A.responseId,b.data);return}if(e.skipValidation){h="submitted",S(),Le(void 0,b.data);return}s&&!o?ks():$s(),h="error",S()}return{getState:()=>R,subscribe(b){return v.add(b),()=>{v.delete(b)}},setValue:Ji,setUploading:Xi,next:Yi,back:Qi,submit:Hn,setContext(b){if("formId"in b&&(o=b.formId),"client"in b&&(s=b.client),"respondent"in b&&(a=b.respondent),b.form&&b.form!==i){let _=Ne(b.form);if(!_.ok)throw new Error(`Invalid form schema: ${_.error}`);i=_.schema,l=Re(i,l)}h==="idle"&&Jr(i,o,l)&&(h="submitted",m=!0),Y(),S()},flushDraft(){Tt(!0)},resetDraft(){if(h==="submitting")return;let b=D??(o?zt(o):null);if(jn(),b&&s&&s.deleteDraft(b.id,b.token).catch(()=>{}),l={...e.initialData??{}},typeof location<"u"&&location.search){let _=Object.fromEntries(new URLSearchParams(location.search));for(let[w,$]of Object.entries(Wr(i,_)))l[w]===void 0&&(l[w]=$)}l=Re(i,l),u={},c=0,p=void 0,oe=!1,Se=!1,S()},destroy(){B&&(clearTimeout(B),B=null),v.clear()}}}function Is(e){return ee(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function Ai(e){let t=e.filter(n=>ee(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!Is(t[0])}function Ci(e,t,n){if(n.form.settings.submitMode!=="auto"||n.status!=="idle"||n.uploading||!(()=>{switch(e.kind){case"select":case"dropdown":return typeof t=="string"&&e.options.some(a=>a.id===t);case"checkbox":return t===!0;case"rating":case"linear_scale":return typeof t=="number";default:return!1}})()||t===n.data[e.id])return!1;let i={...n.data,[e.id]:t},o=n.form.pages.find(a=>a.blocks.some(l=>l.id===e.id));if(!o||!fn(n.form,o.id,i))return!1;let s=si(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:fi(n.form,i).ok}function Fi(e,t,n,r){if(n<=0)return null;let i=r?.rtl??!1;if(e==="Home")return 0;if(e==="End")return n-1;let o;switch(e){case"ArrowRight":o=i?-1:1;break;case"ArrowLeft":o=i?1:-1;break;case"ArrowDown":o=1;break;case"ArrowUp":o=-1;break;default:return null}let s=t+o;return Math.min(n-1,Math.max(0,s))}var Ns=Math.sqrt(1.05*.05)-.05,Ms=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Ts=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function ln(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Ls(e){let t=e.trim(),n=null,r=Ms.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=Ts.exec(t);a&&(n=`${a[1]}${a[1]}${a[2]}${a[2]}${a[3]}${a[3]}`)}if(!n)return null;let i=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),s=parseInt(n.slice(4,6),16);return .2126*ln(i)+.7152*ln(o)+.0722*ln(s)}function Ii(e){if(!e||e.colorScheme||!e.background||!e.text)return e;let t=Ls(e.background);return t==null?e:{...e,colorScheme:t>Ns?"light":"dark"}}function Mn(e){return{id:e.id,theme:e.theme,schema:{version:1,title:e.title??"",description:e.description,pages:e.pages,settings:e.settings??{}},__filloCodeForm:!0}}function Tn(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var ke=new Map,Ps=e=>new Promise(t=>setTimeout(t,e));function Zs(e){if(!J(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function Os(e,t){let n=800;for(let r=0;;r++)try{return await e.syncForm(t.id,t.schema,t.theme??null)}catch(i){if(!Zs(i)||r>=2)throw i;let o=J(i)?i.retryAfterSec:void 0;await Ps(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function Rs(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function Ni(e,t){let n=r=>{if(Array.isArray(r))return r.map(n);if(r&&typeof r=="object"){let i=r;return Object.fromEntries(Object.keys(i).sort().map(o=>[o,n(i[o])]))}return r};return JSON.stringify(n(e))===JSON.stringify(n(t))}var yn=e=>e==="published"?36e5:6e4,Ds=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function Mi(e,t){return`fillo:sync:v4:${e.baseUrl}|${e.key}|${t}`}function Us(e,t,n){try{let r=globalThis.localStorage?.getItem(Mi(e,t));if(!r)return null;let i=JSON.parse(r);if(typeof i.formId!="string"||typeof i.slug!="string"||i.hash!==n||typeof i.ts!="number"||i.uploadFileSizeLimitMb!==void 0&&(typeof i.uploadFileSizeLimitMb!="number"||!Number.isFinite(i.uploadFileSizeLimitMb)||i.uploadFileSizeLimitMb<=0)||i.status!==void 0&&i.status!=="draft"&&i.status!=="published")return null;let o=yn(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function Bs(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(Mi(e,t),JSON.stringify({formId:r.formId,slug:r.slug,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function Ln(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=Rs(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=ge(t.schema).some(c=>c.kind==="file_upload"),a=ke.get(o);if(a&&!n?.bypassCache){if(a.expiresAt===null||!s&&a.expiresAt>Date.now())return a.promise;ke.delete(o)}if(!n?.bypassCache&&!s){let c=Us(e,t.id,i);if(c){let h=Promise.resolve({formId:c.formId,slug:c.slug,status:c.status,uploadFileSizeLimitMb:c.uploadFileSizeLimitMb});return ke.set(o,{promise:h,expiresAt:c.ts+yn(c.status)}),h}}let l=Os(e,t),u={promise:l,expiresAt:null};return ke.set(o,u),l.then(c=>{if(ke.get(o)===u){if(s||Ds(c)){ke.delete(o);return}u.expiresAt=Date.now()+yn(c.status),Bs(e,t.id,i,c)}},()=>{ke.get(o)===u&&ke.delete(o)}),l}var js=class extends Error{constructor(e,t){super(`[fillo] ${t} \u2014 https://fillo.so/docs/troubleshooting#jsx-${e.toLowerCase()}`),this.code=e,this.name="FilloJsxError"}code},Vs=Symbol.for("fillo.block");var Hs=["label","description","required","placeholder"],O=(e,t,n,r={})=>({name:e,kind:t,props:[...Hs,...n],...r}),Xr=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),un=["options","allowOther","shuffleOptions"],qs=[O("Text","short_text",["maxLength"]),O("LongText","long_text",["maxLength"]),O("Email","email",["maxLength"]),O("Url","url",["maxLength"]),O("Phone","phone",["defaultCountry"]),O("Number","number",["min","max","decimals","prefix","suffix","notation"]),O("Select","select",un,{optionChildren:!0}),O("MultiSelect","multi_select",un,{optionChildren:!0}),O("Dropdown","dropdown",un,{optionChildren:!0}),O("Checkbox","checkbox",["appearance"]),O("Rating","rating",["max","insightsMetric"]),O("Scale","linear_scale",["min","max","minLabel","maxLabel","insightsMetric"]),O("Ranking","ranking",["options"],{optionChildren:!0}),O("Matrix","matrix",["rows","columns"]),O("Signature","signature",[]),O("Date","date",[]),O("FileUpload","file_upload",["maxFiles","maxFileSizeMb","accept"]),O("Hidden","hidden",["paramName","defaultValue"]),O("Calculated","calculated",["calc","decimals","prefix","suffix"]),O("Custom","custom",["component","config"]),Xr("Heading","heading",!0),Xr("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],Ws={name:"Page",kind:"__page",props:["title"]},Ks={name:"Option",kind:"__option",props:["label","icon"]};function cn(e){let t=()=>{throw new js("RENDERED_INERT",`<Fillo.${e.name}> was rendered by React. Fillo fields are schema declarations, valid only inside <Fillo.Form> or Fillo.defineForm(). If this form lives in a server component, move it to a client module ("use client")`)};return t[Vs]=e,t}var $d=Object.fromEntries([...qs.map(e=>[e.name,cn(e)]),["Page",cn(Ws)],["Option",cn(Ks)]]);function Gs(e){let t=e.toLowerCase();return t==="localhost"||t.endsWith(".localhost")||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t)||t==="::1"||t==="[::1]"||t==="0.0.0.0"}function Pn(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Ti(){if(Pn())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&Gs(e)}var Js=/\{\{\s*([\w-]+)\s*\}\}/g;function dn(e,t,n){if(!e.includes("{{"))return e;let r=ge(n);return e.replace(Js,(i,o)=>{let s=r.find(u=>u.id===o),a=t[o];if(a==null||a==="")return"";let l=u=>s&&"options"in s?s.options.find(c=>c.id===u)?.label??u:u;return Array.isArray(a)?a.map(u=>l(String(u))).join(", "):typeof a=="string"?l(a):String(a)})}function Li(e,t,n){let r=i=>i===void 0?i:dn(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:dn(e.text,t,n)};case"divider":return e;default:return{...e,label:dn(e.label,t,n),description:r(e.description)}}}var Xs="fillo-",Ys=0,It='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Qs(e){return e.matches(It)?e:e.querySelector(It)}function ea(e,t){let n=`${Xs}${e}-${t}`;return{inputId:n,labelId:`${n}-label`,descriptionId:`${n}-desc`,errorId:`${n}-error`,name:n}}function d(e,t={}){let n=document.createElement(e);t.className&&(n.className=t.className),t.text!==void 0&&(n.textContent=t.text);for(let[r,i]of Object.entries(t.attrs??{}))n.setAttribute(r,i);return n}function Ve(e,t){let n=Ii(zn(t));n&&(n.colorScheme&&e.setAttribute("data-fillo-color-scheme",n.colorScheme),n.primary&&e.style.setProperty("--fillo-primary",n.primary),n.background&&e.style.setProperty("--fillo-bg",n.background),n.text&&e.style.setProperty("--fillo-text",n.text),n.radius&&e.style.setProperty("--fillo-radius",n.radius),n.fontFamily&&e.style.setProperty("--fillo-font",n.fontFamily),(n.primary||n.background||n.text)&&e.setAttribute("data-fillo-has-color-theme",""))}function dt(e){try{if(!e)return null;let t=new URL(e);return t.protocol!=="http:"&&t.protocol!=="https:"?null:t.toString()}catch{return null}}function ta(e){let t=new URL(dt(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function Nt(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Pi(e,t,n){let r=Nt(e);if(r==="")return r;let i=Number(r);return Number.isFinite(i)?vi(i,{locale:n,decimals:t}):r}function C(e,t){for(let n of t)n&&e.appendChild(n);return e}var Zi="http://www.w3.org/2000/svg",na={thumbs_up:"M7 10v10M7 10l4.8-6.1a2 2 0 0 1 3.5 1.7L14.6 10h4.8a2.1 2.1 0 0 1 2 2.5l-1.1 5.4A3 3 0 0 1 17.4 20H7M3 10h4v10H3z",thumbs_down:"M7 14V4M7 14l4.8 6.1a2 2 0 0 0 3.5-1.7L14.6 14h4.8a2.1 2.1 0 0 0 2-2.5l-1.1-5.4A3 3 0 0 0 17.4 4H7M3 4h4v10H3z"};function qi(e){if(!e)return null;let t=document.createElementNS(Zi,"svg");t.setAttribute("class","fillo-option-icon"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none"),t.setAttribute("stroke","currentColor"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linecap","round"),t.setAttribute("stroke-linejoin","round"),t.setAttribute("aria-hidden","true");let n=document.createElementNS(Zi,"path");return n.setAttribute("d",na[e]),t.appendChild(n),t}function K(e,t,n,r,i={}){n&&e.setAttribute("aria-invalid","true"),(i.requiredSupported??!0)&&t.required&&e.setAttribute("aria-required","true");let o=[t.description?r.descriptionId:null,n?r.errorId:null].filter(Boolean).join(" ");o&&e.setAttribute("aria-describedby",o)}function Wi(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=Fi(i.key,s,t.length,{rtl:o});if(a===null)return;i.preventDefault();let l=t[a];l!==void 0&&(r(l),e.querySelectorAll('[role="radio"]')[a]?.focus())})}function ne(e,t,n,r){let i=d("div",{className:`fillo-field fillo-field--${e.kind}${t?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.id,"data-kind":e.kind}});i.toggleAttribute("data-invalid",!!t),i.toggleAttribute("data-required",!!e.required);let o=d("label",{className:"fillo-label",text:e.label,attrs:{id:r.labelId,for:r.inputId,"data-fillo":"label"}});return e.required||o.appendChild(d("span",{className:"fillo-optional",text:" (optional)"})),i.appendChild(o),e.description&&i.appendChild(d("p",{className:"fillo-description",text:e.description,attrs:{id:r.descriptionId,"data-fillo":"fieldDescription"}})),i.appendChild(n),t&&i.appendChild(d("p",{className:"fillo-error",text:t,attrs:{id:r.errorId,"data-fillo":"error"}})),i}function lt(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation!==void 0,o=bi(r?.notation),s=i||!!r?.prefix||!!r?.suffix,a=d("input",{className:"fillo-input",attrs:{id:t.ids.inputId,type:s?"text":e,"data-fillo":"control"}});if(s&&a.setAttribute("inputmode","decimal"),e==="email"?a.setAttribute("autocomplete","email"):e==="url"&&a.setAttribute("autocomplete","url"),a.value=i?Pi(t.value,r?.decimals,o):Nt(t.value),n.placeholder&&(a.placeholder=n.placeholder),"maxLength"in n&&n.maxLength!==void 0&&(a.maxLength=n.maxLength),r&&!s&&(r.min!==void 0&&(a.min=String(r.min)),r.max!==void 0&&(a.max=String(r.max))),s){let u=a.value,c=a.value.length,h=()=>{a.value=u,a.setSelectionRange(c,c)};i?(a.addEventListener("input",()=>{if(!at(a.value,o))return h();u=a.value,c=a.selectionStart??a.value.length,t.setValue(Sn(a.value,o),{render:!1})}),a.addEventListener("change",()=>{if(!at(a.value,o))return h();u=a.value,t.setValue(Sn(a.value,o))}),a.addEventListener("blur",()=>{let m=t.getValue?.()??t.value;a.value=Pi(m,r?.decimals,o),u=a.value,c=a.value.length})):(a.addEventListener("input",()=>{if(!at(a.value,o))return h();u=a.value,c=a.selectionStart??a.value.length,t.setValue(a.value,{render:!1})}),a.addEventListener("change",()=>{if(!at(a.value,o))return h();u=a.value,t.setValue(a.value)}))}else a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value));K(a,n,t.error,t.ids);let l=a;return r&&(r.prefix||r.suffix)&&(l=C(d("div",{className:"fillo-number"}),[r.prefix?d("span",{className:"fillo-number-prefix",text:r.prefix}):null,a,r.suffix?d("span",{className:"fillo-number-suffix",text:r.suffix}):null])),ne(n,t.error,l,t.ids)}function ra(){if(typeof navigator>"u")return;let t=(navigator.languages?.[0]||navigator.language||"").split("-")[1];return t&&/^[A-Za-z]{2}$/.test(t)?t.toUpperCase():void 0}function ia(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function oa(e,t){if(t<=0)return e.setSelectionRange(0,0);let n=e.value,r=0,i=n.length;for(let o=0;o<n.length;o++)if(/\d/.test(n[o])&&++r===t){i=o+1;break}e.setSelectionRange(i,i)}function sa(e){let t=e.field,n=ot(Nt(e.value)).country??Et(t.defaultCountry)??li(ia())??Et(ra())??rt[0],r=d("div",{className:"fillo-phone"}),i=d("div",{className:"fillo-phone-country"}),o=d("button",{className:"fillo-phone-flag",attrs:{type:"button","aria-haspopup":"listbox","aria-expanded":"false"}}),s=d("span",{className:"fillo-phone-flag-emoji",attrs:{"aria-hidden":"true"}}),a=d("span",{className:"fillo-phone-dial"});C(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),C(i,[o]);let l=d("input",{className:"fillo-input fillo-phone-input",attrs:{id:e.ids.inputId,type:"tel",inputmode:"tel",autocomplete:"tel-national","data-fillo":"control"}});K(l,e.field,e.error,e.ids);let u=()=>e.getValue?.()??e.value,c=()=>{let x=de(Nt(u()));return x.startsWith(n.dialCode)?x.slice(n.dialCode.length):x},h=()=>{s.textContent=xn(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},m=()=>{l.value=it(n,c()),l.placeholder=it(n,n.example)},f=x=>e.setValue(x?ui(n,x):"",{render:!1}),p=x=>e.setValue(x,{render:!1});h(),m(),l.addEventListener("input",()=>{let x=l.value,re=l.selectionStart??x.length,R=de(x.slice(0,re)).length;if(x.trimStart().startsWith("+")){let S=ot(x,n,{previousDigits:c()});if(S.pending){p(S.raw??x);return}S.country&&(n=S.country,h()),f(S.country?S.national:de(x))}else f(de(x));l.value=it(n,c()),oa(l,R)});let g=e.registerOverlay,v=e.announce,k=null,F=0,M=je,ie=null,oe=null,Se,X=`${e.ids.inputId}-countries`,Ee=()=>{if(!k)return;let x=ci(i,k);k.classList.toggle("fillo-phone-popover--above",x==="above"),k.classList.toggle("fillo-phone-popover--below",x==="below")},D=()=>{ie?.();let x=()=>Ee();Ee(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),ie=()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},B=x=>{let re=x.relatedTarget;if(re){i.contains(re)||se();return}queueMicrotask(()=>{k&&!i.contains(document.activeElement)&&se()})},se=()=>{clearTimeout(Se),ie?.(),ie=null,k?.remove(),k=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",ae),i.removeEventListener("focusout",B),oe?.(),oe=null},ae=x=>{i.contains(x.target)||se()},qe=x=>{x&&(n=x,h(),f(c()),m(),se(),v?.(Z.phoneCountrySelected(x.name)),l.focus())},Te=x=>{let re=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),R=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":X,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});x&&(R.value=x);let S=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:X,"aria-label":"Country"}}),Le=()=>{if(S.replaceChildren(),M.length===0){S.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),R.removeAttribute("aria-activedescendant"),Ee();return}M.forEach((L,H)=>{let Y=d("li",{className:`fillo-phone-option${H===F?" fillo-phone-option--active":""}`,attrs:{id:`${X}-opt-${H}`,role:"option","aria-selected":String(L.iso2===n.iso2)}});C(Y,[d("span",{className:"fillo-phone-flag-emoji",text:xn(L.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:L.name}),d("span",{className:"fillo-phone-option-dial",text:`+${L.dialCode}`})]),Y.addEventListener("mouseenter",()=>{F=H,R.setAttribute("aria-activedescendant",Y.id),Pe()}),Y.addEventListener("mousedown",be=>{be.preventDefault(),qe(L)}),S.appendChild(Y)}),R.setAttribute("aria-activedescendant",`${X}-opt-${F}`),Ee()},Pe=()=>{[...S.children].forEach((L,H)=>L.classList.toggle("fillo-phone-option--active",H===F)),document.getElementById(`${X}-opt-${F}`)?.scrollIntoView({block:"nearest"})},Ae=L=>{let H=L.trim().toLowerCase(),Y=H.replace(/[^\d]/g,"");M=H?je.filter(be=>be.name.toLowerCase().includes(H)||be.iso2.toLowerCase()===H||Y.length>0&&be.dialCode.startsWith(Y)):je,F=0,Le(),clearTimeout(Se),Se=setTimeout(()=>v?.(Z.phoneResultsCount(M.length)),300)};R.addEventListener("input",()=>Ae(R.value)),R.addEventListener("keydown",L=>{if(L.key==="ArrowDown"){if(L.preventDefault(),M.length===0)return;F=Math.min(F+1,M.length-1),Pe(),R.setAttribute("aria-activedescendant",`${X}-opt-${F}`)}else if(L.key==="ArrowUp"){if(L.preventDefault(),M.length===0)return;F=Math.max(F-1,0),Pe(),R.setAttribute("aria-activedescendant",`${X}-opt-${F}`)}else L.key==="Enter"?(L.preventDefault(),qe(M[F])):L.key==="Escape"&&(L.preventDefault(),se(),o.focus())}),C(re,[R,S]),k=re,i.appendChild(re),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",X),x?Ae(x):(M=je,F=Math.max(0,je.indexOf(n)),Le()),D(),Pe(),document.addEventListener("mousedown",ae),i.addEventListener("focusout",B),oe=g?.(se)??null,requestAnimationFrame(()=>{if(R.focus(),x){let L=R.value.length;R.setSelectionRange(L,L)}})};return o.addEventListener("click",()=>k?se():Te()),o.addEventListener("keydown",x=>{if(!k){if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault(),Te();return}x.key.length===1&&x.key!==" "&&!x.ctrlKey&&!x.metaKey&&!x.altKey&&(x.preventDefault(),Te(x.key))}}),C(r,[i,l]),ne(e.field,e.error,r,e.ids)}function aa(e){let t=d("textarea",{className:"fillo-input fillo-textarea",attrs:{id:e.ids.inputId,rows:"4","data-fillo":"control"}});return t.value=typeof e.value=="string"?e.value:"",e.field.placeholder&&(t.placeholder=e.field.placeholder),"maxLength"in e.field&&e.field.maxLength!==void 0&&(t.maxLength=e.field.maxLength),t.addEventListener("input",()=>e.setValue(t.value,{render:!1})),t.addEventListener("change",()=>e.setValue(t.value)),K(t,e.field,e.error,e.ids),ne(e.field,e.error,t,e.ids)}function la(e){let t=e.field,n=Dn(t),r=typeof e.value=="string"?e.value:"",i=e.activeOtherFields,o=r!==""&&!t.options.some(l=>l.id===r),s=o||r===""&&i?.has(t.id)===!0,a=d("div",{className:"fillo-options",attrs:{role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"options"}});K(a,t,e.error,e.ids);for(let l of n){let u=d("label",{className:`fillo-option${l.icon?" fillo-option--has-icon":""}${r===l.id?" fillo-option--selected":""}`,attrs:{"data-option":l.id,"data-fillo":"option"}});u.toggleAttribute("data-selected",r===l.id);let c=d("input",{className:"fillo-option-input",attrs:{type:"radio",name:e.ids.name}});c.checked=r===l.id,c.addEventListener("change",()=>{i?.delete(t.id),e.setValue(l.id)}),C(u,[c,qi(l.icon),d("span",{className:"fillo-option-label",text:l.label,attrs:{"data-fillo":"optionLabel"}}),l.icon&&r===l.id?d("span",{className:"fillo-option-check",text:"\u2713",attrs:{"aria-hidden":"true"}}):null]),a.appendChild(u)}if(t.allowOther){let l=d("label",{className:`fillo-option fillo-option--other${s?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});l.toggleAttribute("data-selected",s);let u=d("input",{className:"fillo-option-input",attrs:{type:"radio",name:e.ids.name}});if(u.checked=s,u.addEventListener("change",()=>{i?.add(t.id),e.setValue("",{render:!0})}),C(l,[C(d("span",{className:"fillo-option-main"}),[u,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),s){let c=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});c.value=o?r:"",c.placeholder=T.otherPlaceholder,c.addEventListener("input",()=>{i?.add(t.id),e.setValue(c.value,{render:!1})}),c.addEventListener("change",()=>{i?.add(t.id),e.setValue(c.value)}),l.appendChild(c),o||queueMicrotask(()=>c.focus())}a.appendChild(l)}return ne(t,e.error,a,e.ids)}function ua(e){let t=e.field,n=Dn(t),r=Array.isArray(e.value)?e.value:[],i=new Set(t.options.map(c=>c.id)),o=r.find(c=>!i.has(c)),s=e.activeOtherFields,a=()=>{let c=e.getValue?.()??e.value;return Array.isArray(c)?c:[]},l=d("div",{className:"fillo-options",attrs:{role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"options"}});K(l,t,e.error,e.ids,{requiredSupported:!1});let u=c=>e.setValue(c);for(let c of n){let h=d("label",{className:`fillo-option${c.icon?" fillo-option--has-icon":""}${r.includes(c.id)?" fillo-option--selected":""}`,attrs:{"data-option":c.id,"data-fillo":"option"}});h.toggleAttribute("data-selected",r.includes(c.id));let m=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});m.checked=r.includes(c.id),m.addEventListener("change",()=>{let f=a();u(m.checked?[...f,c.id]:f.filter(p=>p!==c.id))}),C(h,[m,qi(c.icon),d("span",{className:"fillo-option-label",text:c.label,attrs:{"data-fillo":"optionLabel"}}),c.icon&&r.includes(c.id)?d("span",{className:"fillo-option-check",text:"\u2713",attrs:{"aria-hidden":"true"}}):null]),l.appendChild(h)}if(t.allowOther){let c=o!==void 0||s?.has(t.id)===!0,h=d("label",{className:`fillo-option fillo-option--other${c?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});h.toggleAttribute("data-selected",c);let m=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(m.checked=c,m.addEventListener("change",()=>{let f=a().filter(p=>i.has(p));m.checked?(s?.add(t.id),u(f)):(s?.delete(t.id),u(f))}),C(h,[C(d("span",{className:"fillo-option-main"}),[m,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),c){let f=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});f.value=o??"",f.placeholder=T.otherPlaceholder,f.addEventListener("input",()=>{s?.add(t.id);let p=a().filter(g=>i.has(g));e.setValue(f.value?[...p,f.value]:p,{render:!1})}),f.addEventListener("change",()=>{s?.add(t.id);let p=a().filter(g=>i.has(g));e.setValue(f.value?[...p,f.value]:p)}),h.appendChild(f),o===void 0&&queueMicrotask(()=>f.focus())}l.appendChild(h)}return ne(t,e.error,l,e.ids)}function ca(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function da(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=ca(t),i=e.activeOtherFields,o=n!==""&&!t.options.some(c=>c.id===n),s=o||n===""&&i?.has(t.id)===!0,a=d("div"),l=d("div",{className:"fillo-select-wrap"}),u=d("select",{className:"fillo-input fillo-select",attrs:{id:e.ids.inputId,"data-fillo":"control"}});u.appendChild(d("option",{text:t.placeholder??"Choose...",attrs:{value:""}}));for(let c of Dn(t))u.appendChild(d("option",{text:c.label,attrs:{value:c.id}}));if(t.allowOther&&u.appendChild(d("option",{text:`${T.other}\u2026`,attrs:{value:r}})),u.value=s?r:n,u.addEventListener("change",()=>{u.value===r?(i?.add(t.id),e.setValue("",{render:!0})):(i?.delete(t.id),e.setValue(u.value||null))}),K(u,t,e.error,e.ids),C(l,[u,d("span",{className:"fillo-select-icon",attrs:{"aria-hidden":"true"}})]),a.appendChild(l),s){let c=d("input",{className:"fillo-input fillo-other-input fillo-other-input--block",attrs:{type:"text","aria-label":T.otherPrompt}});c.value=o?n:"",c.placeholder=T.otherPlaceholder,c.addEventListener("input",()=>{i?.add(t.id),e.setValue(c.value,{render:!1})}),c.addEventListener("change",()=>{i?.add(t.id),e.setValue(c.value)}),a.appendChild(c),o||queueMicrotask(()=>c.focus())}return ne(t,e.error,a,e.ids)}function pa(e){if(e.field.kind==="checkbox"&&e.field.appearance==="toggle"){let o=d("div",{className:`fillo-field fillo-field--checkbox fillo-field--toggle${e.error?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.field.id,"data-kind":e.field.kind}});o.toggleAttribute("data-invalid",!!e.error),o.toggleAttribute("data-required",!!e.field.required);let s=d("label",{className:"fillo-toggle",attrs:{"data-fillo":"option"}});s.toggleAttribute("data-checked",e.value===!0);let a=d("span",{className:"fillo-option-label",text:e.field.label,attrs:{"data-fillo":"optionLabel"}});e.field.required||a.appendChild(d("span",{className:"fillo-optional",text:" (optional)"}));let l=d("span",{className:"fillo-toggle-copy"});l.appendChild(a);let u=d("input",{className:"fillo-toggle-input",attrs:{id:e.ids.inputId,type:"checkbox"}});return u.checked=e.value===!0,u.addEventListener("change",()=>{e.setValue(u.checked)}),K(u,e.field,e.error,e.ids),C(s,[l,u,C(d("span",{className:"fillo-toggle-track",attrs:{"aria-hidden":"true"}}),[d("span",{className:"fillo-toggle-thumb"})])]),o.appendChild(s),e.field.description&&o.appendChild(d("p",{className:"fillo-description",text:e.field.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}})),e.error&&o.appendChild(d("p",{className:"fillo-error",text:e.error,attrs:{id:e.ids.errorId,"data-fillo":"error"}})),o}let t=d("div",{className:`fillo-field fillo-field--checkbox${e.error?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.field.id,"data-kind":e.field.kind}});t.toggleAttribute("data-invalid",!!e.error),t.toggleAttribute("data-required",!!e.field.required);let n=d("label",{className:"fillo-option",attrs:{"data-fillo":"option"}});n.toggleAttribute("data-checked",e.value===!0);let r=d("input",{className:"fillo-option-input",attrs:{id:e.ids.inputId,type:"checkbox"}});r.checked=e.value===!0,r.addEventListener("change",()=>e.setValue(r.checked)),K(r,e.field,e.error,e.ids);let i=d("span",{className:"fillo-option-label",text:e.field.label,attrs:{"data-fillo":"optionLabel"}});return e.field.required||i.appendChild(d("span",{className:"fillo-optional",text:" (optional)"})),C(n,[r,i]),t.appendChild(n),e.field.description&&t.appendChild(d("p",{className:"fillo-description",text:e.field.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}})),e.error&&t.appendChild(d("p",{className:"fillo-error",text:e.error,attrs:{id:e.ids.errorId,"data-fillo":"error"}})),t}function fa(e){if(e.field.kind!=="rating")return d("div");let t=typeof e.field.max=="number"?e.field.max:5,n=typeof e.value=="number"?e.value:0,r=Array.from({length:t},(a,l)=>l+1),i=n>0?n:null,o=i===null?0:Math.max(0,r.indexOf(i)),s=d("div",{className:"fillo-rating",attrs:{id:e.ids.inputId,role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});K(s,e.field,e.error,e.ids);for(let[a,l]of r.entries()){let u=d("button",{className:`fillo-star${l<=n?" fillo-star--active":""}`,text:l<=n?"\u2605":"\u2606",attrs:{type:"button",role:"radio","aria-label":`${l} of ${t}`,"aria-checked":String(l===n),tabindex:String(a===o?0:-1),"data-fillo":"option"}});u.toggleAttribute("data-selected",l<=n),u.addEventListener("click",c=>{c.detail===0&&l===n||e.setValue(l===n?null:l)}),s.appendChild(u)}return Wi(s,r,i,a=>e.setValue(a)),ne(e.field,e.error,s,e.ids)}function ha(e){if(e.field.kind!=="linear_scale")return d("div");let t=typeof e.field.min=="number"?e.field.min:1,n=typeof e.field.max=="number"?e.field.max:10,r=typeof e.value=="number"?e.value:null,i=Array.from({length:n-t+1},(h,m)=>t+m),o=r===null?0:Math.max(0,i.indexOf(r)),s=`${e.ids.inputId}-min`,a=`${e.ids.inputId}-max`,l=d("div"),u=d("div",{className:"fillo-scale",attrs:{id:e.ids.inputId,role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});K(u,e.field,e.error,e.ids);let c=[e.field.minLabel?s:null,e.field.maxLabel?a:null,u.getAttribute("aria-describedby")].filter(Boolean).join(" ");c&&u.setAttribute("aria-describedby",c);for(let[h,m]of i.entries()){let f=d("button",{className:`fillo-scale-step${e.value===m?" fillo-scale-step--active":""}`,text:String(m),attrs:{type:"button",role:"radio","aria-label":String(m),"aria-checked":String(e.value===m),tabindex:String(h===o?0:-1),"data-fillo":"option"}});f.toggleAttribute("data-selected",e.value===m),f.addEventListener("click",p=>{p.detail===0&&e.value===m||e.setValue(e.value===m?null:m)}),u.appendChild(f)}return Wi(u,i,r,h=>e.setValue(h)),l.appendChild(u),("minLabel"in e.field||"maxLabel"in e.field)&&C(l,[C(d("div",{className:"fillo-scale-labels"}),[d("span",{text:String(e.field.minLabel??""),attrs:{id:s}}),d("span",{text:String(e.field.maxLabel??""),attrs:{id:a}})])]),ne(e.field,e.error,l,e.ids)}function ma(e){let t=e.field;if(t.kind!=="ranking")return null;let n=e.announce,r=Array.isArray(e.value)?e.value:[],i=[...r.filter(a=>t.options.some(l=>l.id===a)),...t.options.map(a=>a.id).filter(a=>!r.includes(a))],o=d("div",{attrs:{id:e.ids.inputId,role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});K(o,e.field,e.error,e.ids,{requiredSupported:!1});let s=d("ol",{className:"fillo-ranking"});for(let[a,l]of i.entries()){let u=t.options.find(g=>g.id===l);if(!u)continue;let c=d("li",{className:"fillo-ranking-item"}),h=d("span",{className:"fillo-ranking-controls"}),m=g=>{let v=a+g;if(v<0||v>=i.length)return;let k=[...i];[k[a],k[v]]=[k[v],k[a]],e.setValue(k),n?.(Z.rankingPosition(u.label,v+1,i.length))},f=d("button",{className:"fillo-ranking-move",text:"\u2191",attrs:{type:"button","data-fillo-rank-opt":l,"data-fillo-rank-dir":"up","aria-label":`Move ${u.label} up`}});f.toggleAttribute("disabled",a===0),f.addEventListener("click",()=>m(-1));let p=d("button",{className:"fillo-ranking-move",text:"\u2193",attrs:{type:"button","data-fillo-rank-opt":l,"data-fillo-rank-dir":"down","aria-label":`Move ${u.label} down`}});p.toggleAttribute("disabled",a===i.length-1),p.addEventListener("click",()=>m(1)),C(h,[f,p]),C(c,[d("span",{className:"fillo-ranking-index",text:String(a+1)}),d("span",{className:"fillo-ranking-label",text:u.label}),h]),s.appendChild(c)}return o.appendChild(s),ne(e.field,e.error,o,e.ids)}function ga(e){let t=e.field;if(t.kind!=="matrix")return null;let n=e.value&&typeof e.value=="object"&&!Array.isArray(e.value)?e.value:{},r=d("table",{className:"fillo-matrix"}),i=document.createElement("thead"),o=document.createElement("tr");o.appendChild(document.createElement("td"));for(let l of t.columns)o.appendChild(d("th",{text:l.label,attrs:{scope:"col"}}));i.appendChild(o),r.appendChild(i);let s=document.createElement("tbody");for(let l of t.rows){let u=`${e.ids.inputId}-${l.id}`,c=n[l.id]!==void 0,h=!!e.error&&!!t.required&&!c,m=v=>`${e.ids.inputId}-${l.id}-${v.id}`,f=document.createElement("tr"),p=d("th",{attrs:{scope:"row"}}),g=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${u}`,"aria-owns":t.columns.map(m).join(" ")}});g.appendChild(d("span",{text:l.label,attrs:{id:u}})),p.appendChild(g),f.appendChild(p);for(let v of t.columns){let k=d("td",{attrs:{"data-label":v.label}}),F=d("label",{className:"fillo-matrix-cell"}),M=d("input",{className:"fillo-option-input",attrs:{id:m(v),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${v.label}`}});t.required&&M.setAttribute("aria-required","true"),h&&M.setAttribute("aria-invalid","true"),M.checked=n[l.id]===v.id,M.addEventListener("change",()=>e.setValue({...n,[l.id]:v.id})),F.appendChild(M),k.appendChild(F),f.appendChild(k)}s.appendChild(f)}r.appendChild(s);let a=d("div",{className:"fillo-matrix-wrap",attrs:{id:e.ids.inputId,role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});return K(a,e.field,e.error,e.ids,{requiredSupported:!1}),a.appendChild(r),ne(e.field,e.error,a,e.ids)}function ba(e){let t=d("div",{className:"fillo-signature-field"}),n=d("div",{className:"fillo-signature",attrs:{"data-fillo":"control"}}),r=d("canvas",{className:"fillo-signature-canvas",attrs:{role:"img"}}),i=d("button",{className:"fillo-signature-clear",text:"Clear",attrs:{type:"button"}}),o=d("div",{className:"fillo-signature-hint",text:"Sign here",attrs:{"aria-hidden":"true"}});r.width=720,r.height=220;let s=r.getContext("2d"),a=!1,l=typeof e.value=="string"&&e.value.startsWith("data:image/"),u=()=>{r.setAttribute("aria-label",l?Z.signatureSigned:Z.signatureEmpty)};if(u(),l&&s){let v=new Image;v.onload=()=>s.drawImage(v,0,0,r.width,r.height),v.src=String(e.value),o.style.display="none"}let c=d("input",{className:"fillo-input fillo-signature-type-input",attrs:{id:e.ids.inputId,type:"text",autocomplete:"name"}});K(c,e.field,e.error,e.ids);let h=v=>{s&&(s.clearRect(0,0,r.width,r.height),v.trim()?(s.fillStyle=getComputedStyle(r).color||"#18181b",s.font=`italic ${Math.min(96,r.height*.45)}px "Segoe Script", "Brush Script MT", cursive`,s.textBaseline="middle",s.fillText(v,24,r.height/2),l=!0,o.style.display="none",e.setValue(r.toDataURL("image/png"),{render:!1})):(l=!1,o.style.display="",e.setValue(null,{render:!1})),u())};c.addEventListener("input",()=>h(c.value));let m=v=>{let k=r.getBoundingClientRect();return{x:(v.clientX-k.left)/k.width*r.width,y:(v.clientY-k.top)/k.height*r.height}};r.addEventListener("pointerdown",v=>{if(!s)return;a=!0,l=!0,o.style.display="none",u(),c.value&&(c.value=""),r.setPointerCapture(v.pointerId);let k=m(v);s.beginPath(),s.moveTo(k.x,k.y)}),r.addEventListener("pointermove",v=>{if(!a||!s)return;let k=m(v);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(k.x,k.y),s.stroke()});let f=()=>{a&&(a=!1,l&&e.setValue(r.toDataURL("image/png"),{render:!1}))};r.addEventListener("pointerup",f),r.addEventListener("pointercancel",f),i.addEventListener("click",()=>{s?.clearRect(0,0,r.width,r.height),l=!1,o.style.display="",c.value="",u(),e.setValue(null,{render:!1})}),C(n,[r,o,i]);let p=d("div",{className:"fillo-signature-type"}),g=d("label",{className:"fillo-signature-type-label",text:"Or type your full name to sign",attrs:{for:e.ids.inputId}});return C(p,[g,c]),C(t,[n,p]),ne(e.field,e.error,t,e.ids)}function Oi(e){return e<1024?`${e} B`:e<1024**2?`${(e/1024).toFixed(0)} KB`:e<1024**3?`${(e/1024**2).toFixed(1)} MB`:`${(e/1024**3).toFixed(2)} GB`}function Ft(e,t=22){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("class","fillo-file-state-icon"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("width",String(t)),n.setAttribute("height",String(t)),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false");for(let r of e){let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",r),n.appendChild(i)}return n}function Ri(e){let t=d("span",{className:`fillo-file-state fillo-file-state--${e}`,attrs:{"aria-hidden":"true"}});return t.appendChild(Ft(e==="done"?["M3.75 12a8.25 8.25 0 1 0 16.5 0 8.25 8.25 0 1 0-16.5 0","m8.5 12 2.25 2.25 4.75-5"]:e==="failed"?["M3.75 12a8.25 8.25 0 1 0 16.5 0 8.25 8.25 0 1 0-16.5 0","M12 7.75v5.5","M12 16.5h.01"]:["M7.25 3.75h6.5l3 3v13.5h-9.5z","M13.75 3.75v3h3"])),t}function Zn(){let e=Ft(["m7 7 10 10M17 7 7 17"],16);return e.setAttribute("class","fillo-file-action-icon"),e}function Ct(e,t,n,r){let i=d("button",{className:e,attrs:{type:"button","aria-label":t}});return i.append(n),i.addEventListener("click",r),i}function va(e){let t=e.field;if(t.kind!=="file_upload")return null;let n=e,r=n.uploadDisabledReason,i=r===void 0,o=t.maxFiles??1,s=t.maxFileSizeMb??500,a=Array.isArray(e.value)?e.value:[],l=n.uploadRows??[],u=o-a.length-l.filter(m=>m.error===void 0).length,c=d("div");if(u>0){let m=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file",hidden:""}});o>1&&(m.multiple=!0),t.accept?.length&&(m.accept=t.accept.join(",")),m.disabled=!i,m.addEventListener("change",()=>{if(!i)return;let p=Array.from(m.files??[]);m.value="",e.uploadFiles?.(t,p)});let f=d("div",{className:`fillo-dropzone${i?"":" fillo-dropzone--disabled"}`,attrs:{role:"button",tabindex:"0","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});if(K(f,t,e.error,e.ids,{requiredSupported:!1}),i||f.setAttribute("aria-disabled","true"),f.addEventListener("dragover",p=>{p.preventDefault(),f.classList.add("fillo-dropzone--over"),f.setAttribute("data-drag-over","")}),f.addEventListener("dragleave",()=>{f.classList.remove("fillo-dropzone--over"),f.removeAttribute("data-drag-over")}),f.addEventListener("drop",p=>{p.preventDefault(),f.classList.remove("fillo-dropzone--over"),f.removeAttribute("data-drag-over"),i&&e.uploadFiles?.(t,Array.from(p.dataTransfer?.files??[]))}),f.addEventListener("click",()=>{i&&m.click()}),f.addEventListener("keydown",p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),i&&m.click())}),f.appendChild(m),i)C(f,[d("span",{className:"fillo-dropzone-title",text:Z.dropzoneTitle(o>1)}),d("span",{className:"fillo-dropzone-hint",text:Z.dropzoneHint(s)})]);else if(r==="render_only")f.appendChild(d("span",{className:"fillo-dropzone-hint",text:Z.uploadsRenderOnly}));else if(n.storageFixUrl){let p=d("span",{className:"fillo-dropzone-hint",text:"Connect file storage to enable uploads"});p.append(" \u2014 "),p.appendChild(d("a",{text:n.storageFixUrl,attrs:{href:n.storageFixUrl,target:"_blank",rel:"noopener noreferrer"}})),f.appendChild(p)}else f.appendChild(d("span",{className:"fillo-dropzone-hint",text:Z.uploadsUnavailable}));c.appendChild(f)}if(a.length>0||l.length>0){let m=d("ul",{className:"fillo-files"});for(let f of a){let p=d("li",{className:"fillo-file fillo-file--done"}),g=d("span",{className:"fillo-file-content"});C(g,[d("span",{className:"fillo-file-name",text:f.name}),d("span",{className:"fillo-file-meta",text:Z.uploadedFile(Oi(f.size))})]);let v=d("span",{className:"fillo-file-actions"});v.appendChild(Ct("fillo-file-remove",`${Z.uploadRemove} ${f.name}`,Zn(),()=>e.setValue(a.filter(k=>k.fileId!==f.fileId)))),C(p,[Ri("done"),g,v]),m.appendChild(p)}for(let f of l){let p=f.error!==void 0,g=d("li",{className:`fillo-file${p?" fillo-file--failed":""}`});g.appendChild(Ri(p?"failed":"uploading"));let v=d("span",{className:"fillo-file-content"});if(v.appendChild(d("span",{className:"fillo-file-name",text:f.name})),p){let k=d("span",{className:"fillo-file-actions"});v.appendChild(d("span",{className:"fillo-file-error",text:f.error??""})),g.appendChild(v),!f.tooLarge&&u>0&&k.appendChild(Ct("fillo-file-retry",`${Z.uploadRetry} ${f.name}`,Z.uploadRetry,()=>n.uploadAction?.(f.key,"retry"))),k.appendChild(Ct("fillo-file-remove",`${Z.uploadDismiss} ${f.name}`,Zn(),()=>n.uploadAction?.(f.key,"dismiss"))),g.appendChild(k)}else{let k=d("span",{className:"fillo-progress-bar"});k.style.width=`${f.fraction*100}%`,v.appendChild(d("span",{className:"fillo-file-meta",text:Z.uploadingFile(Math.round(f.fraction*100),Oi(f.size))}));let F=d("span",{className:"fillo-file-actions"});F.appendChild(Ct("fillo-file-remove",`${Z.uploadCancel} ${f.name}`,Zn(),()=>n.uploadAction?.(f.key,"cancel"))),C(g,[v,F,C(d("span",{className:"fillo-progress",attrs:{role:"progressbar","aria-label":`Uploading ${f.name}`,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(Math.round(f.fraction*100))}}),[k])])}m.appendChild(g)}c.appendChild(m)}let h=n.uploadNotice;return h&&c.appendChild(d("p",{className:"fillo-upload-notice",text:h})),ne(t,e.error,c,e.ids)}function ya(e){let t=e.field,n=d("div",{className:"fillo-field fillo-field--calculated fillo-calculated",attrs:{"data-fillo":"calculated","data-field":t.id,"data-kind":t.kind}});n.appendChild(d("label",{className:"fillo-label",text:t.label,attrs:{id:e.ids.labelId,for:e.ids.inputId,"data-fillo":"label"}})),t.description&&n.appendChild(d("p",{className:"fillo-description",text:t.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}}));let r=e.value,i=r!=null&&r!=="",o=d("output",{className:`fillo-calculated-value${i?"":" fillo-calculated-value--empty"}`,text:i?gi(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var Di=new Map;function Dn(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=Di.get(t);if(!n){n=e.options.map(o=>o.id);for(let o=n.length-1;o>0;o--){let s=Math.floor(Math.random()*(o+1));[n[o],n[s]]=[n[s],n[o]]}Di.set(t,n)}let r=new Map(e.options.map(o=>[o.id,o])),i=n.flatMap(o=>r.get(o)??[]);return i.length===e.options.length?i:e.options}var wa={short_text:e=>lt("text",e),email:e=>lt("email",e),url:e=>lt("url",e),phone:sa,number:e=>lt("number",e),date:e=>lt("date",e),long_text:aa,select:la,multi_select:ua,dropdown:da,checkbox:pa,rating:fa,linear_scale:ha,ranking:ma,matrix:ga,signature:ba,file_upload:va,calculated:ya};function _a(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=wa[e.field.kind];return t?t(e):null}var xa="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",Ui="fillo-turnstile-script",ut=null;function He(){return globalThis.turnstile}function ka(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):He()?Promise.resolve():ut||(ut=new Promise((e,t)=>{let n=()=>{He()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(Ui);if(r){if(He()){e();return}r.addEventListener("load",n,{once:!0}),r.addEventListener("error",()=>t(new Error("Turnstile script failed to load")),{once:!0});return}let i=document.createElement("script");i.id=Ui,i.src=xa,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),ut=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),ut)}function Bi(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var pt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&Na(),t.replaceChildren(this.element,this.statusEl,this.alertEl),this.resolve()}target;options;element=d("div");statusEl=d("span",{className:"fillo-sr-only",attrs:{role:"status","aria-live":"polite","data-fillo":"announce"}});alertEl=d("span",{className:"fillo-sr-only",attrs:{role:"alert","data-fillo":"announce-alert"}});instanceId=`d${++Ys}`;schema=null;theme;formId;closed=!1;fetchedPoweredBy=null;fetchedBrandLabel;fetchedBrandHref;phase="loading";engine=null;destroyed=!1;renderQueued=!1;hpValue="";liveSubmissionHandled=!1;activeOtherFields=new Set;inFlight=new Map;uploadNotices=new Map;focusIntent=null;overlays=new Set;challenge;challengeToken;challengeError=!1;turnstileContainer=Bi();turnstileWidgetId=null;turnstileSiteKey;turnstileLoadInFlight=!1;turnstileAttempt=0;announce=t=>{this.statusEl.textContent="",requestAnimationFrame(()=>{this.statusEl.textContent=t})};announceAlert=t=>{this.alertEl.textContent="",requestAnimationFrame(()=>{this.alertEl.textContent=t})};devChrome(){return this.options.preview===!0||Sa()}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 t=this.schema??{version:1,title:"",pages:[],settings:{}},n=this.engine?.getState(),r=n?.pageCount??t.pages.length;return{form:t,formId:this.formId,client:this.options.renderOnly?void 0:this.options.client,data:n?.data??this.mutableData,errors:n?.errors??{},status:this.status,pageIndex:n?.pageIndex??0,pageCount:r,page:n?.page??t.pages[0]??{id:"empty",blocks:[]},blocks:n?.blocks??[],isFirstPage:n?.isFirstPage??!0,isLastPage:n?.isLastPage??r<=1,setValue:(i,o,s)=>this.setValueInternal(i,o,s),next:()=>this.next(),back:()=>this.back(),submit:()=>this.submit()}}resolveFormIdFn;notOpenVariant=null;fatalError=null;genericUnavailable=!1;syncErrorNotice=null;stagedNotice=!1;draftNotice=!1;syncWarningCode;syncWarningUrl;uploadsAvailable;uploadFileSizeLimitMb;resolutionFailureCode=null;async resolve(){try{this.challenge=this.options.renderOnly?void 0:this.options.challenge;let t=Tn(this.options.form)?this.options.form:null;if(t){if(this.options.renderOnly){this.setSchema(t.schema,this.options.theme??t.theme,void 0);return}!this.options.client&&this.options.formId&&(this.options.client=Me());let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await Ln(i,t,{bypassCache:!0});if(this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.uploadsAvailable=o.uploadsAvailable,this.uploadFileSizeLimitMb=o.uploadFileSizeLimitMb,o.status==="draft")throw new z("This form is no longer published. Submission was stopped before sending answers.",403,void 0,"form_not_published");if(o.accepting===!1)throw new z("This form is no longer accepting responses. Submission was stopped before sending answers.",403,void 0,o.acceptingReason??"form_not_accepting");let s=Ne(o.resolvedSchema??t.schema);if(!s.ok)throw new z(`The canonical form schema was invalid: ${s.error}`,502,void 0,"invalid_sync_schema");if(this.schema&&!Ni(this.schema,s.schema))throw new z("The live form changed after this page loaded. Submission stopped before incompatible answers were sent. Reload to use the published schema.",409,void 0,"form_schema_changed");return o.syncError&&this.reportSyncNotice(new z(o.syncError.message,403,void 0,o.syncError.code)),this.resolutionFailureCode=null,o.formId}catch(o){let s=ct(o);throw this.resolutionFailureCode=s.code??"sync_failed",this.reportSubmitSyncFailure(s),s}}),!i?.key&&this.options.formId&&this.setSchema(t.schema,this.options.theme??t.theme,this.options.formId),!i&&!this.options.formId)throw this.genericUnavailable=!this.devChrome(),Hi();if(i&&!i.key&&!this.options.formId){this.reportSyncFailure(new z('Code forms need createClient({ key: "pk_\u2026" }) to resolve the live form. Pass a publishable key or a published formId.',401,void 0,"sync_key_required"));return}if(!i?.key)return;this.devChrome()?this.setSchema(t.schema,this.options.theme??t.theme,this.options.formId):(this.theme=this.options.theme??t.theme,this.render());try{let o=await Ln(i,t);if(this.destroyed)return;if((o.staged||o.syncError)&&!o.resolvedSchema)throw new z("Sync did not return the live schema needed to render safely. Publish changes before deploy, and update @usefillo/* or your API.",409,void 0,"sync_snapshot_required");let s=this.devChrome();if(this.notOpenVariant=s?null:o.status==="draft"?"notOpen":o.accepting===!1?ji(o.acceptingReason):null,this.stagedNotice=!!o.staged,this.draftNotice=o.status==="draft",this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.uploadsAvailable=o.uploadsAvailable,this.uploadFileSizeLimitMb=o.uploadFileSizeLimitMb,this.challenge=this.options.challenge??o.challenge,o.branding&&(this.fetchedPoweredBy=o.branding.poweredBy,this.fetchedBrandLabel=o.branding.label,this.fetchedBrandHref=o.branding.href),s&&o.resolvedSchema)this.formId=o.formId,this.engine?.setContext({formId:o.formId}),this.render();else{let l=o.resolvedSchema??t.schema,u=this.options.theme??(o.resolvedSchema?o.resolvedTheme??void 0:t.theme);this.applyCanonicalSchema(l,u,o.formId)}o.warning&&console.warn(`[fillo] ${o.warning}`),o.syncError&&this.reportSyncNotice(new z(o.syncError.message,403,void 0,o.syncError.code));let a=o.warningUrl?` \u2014 connect storage to publish: ${o.warningUrl}`:"";o.staged?console.info(`[fillo] "${t.id}" changes staged as a draft \u2014 rendering the live version until you publish them in your Fillo dashboard${a}`):o.status==="draft"&&console.info(`[fillo] "${t.id}" is a draft \u2014 it renders here but won't accept responses until published${a}`)}catch(o){if(this.destroyed)return;this.reportSyncFailure(ct(o))}return}let n=this.options.form&&!Tn(this.options.form)?this.options.form:null;if(n){if(this.options.renderOnly){this.setSchema(n,this.options.theme,void 0);return}if(!this.options.formId)throw this.genericUnavailable=!this.devChrome(),Hi();this.options.client??=Me(),this.setSchema(n,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new z("Provide either `form`, or a `formId`.",0);this.options.client??=Me(),this.render();let r=await this.options.client.getForm(this.options.formId);if(this.destroyed)return;if(r.accepting===!1?this.notOpenVariant=ji(r.acceptingReason):this.closed=!!r.closed,this.uploadsAvailable=r.uploadsAvailable,this.uploadFileSizeLimitMb=r.uploadFileSizeLimitMb,this.fetchedPoweredBy=r.branding?.poweredBy??null,this.fetchedBrandLabel=r.branding?.label,this.fetchedBrandHref=r.branding?.href,this.challenge=this.options.challenge??r.challenge,r.accepting===!1&&this.options.renderError){let i=this.notOpenVariant==="closed"?"This form is no longer accepting responses.":"This form isn't accepting responses yet.";this.fatalError=new z(i,403,void 0,r.acceptingReason),this.phase="error",this.render(this.fatalError);return}this.setSchema(r.schema,this.options.theme??r.theme??void 0,r.id)}catch(t){if(this.destroyed)return;this.handleError(ct(t))}}setSchema(t,n,r){if(this.destroyed)return;let i=Ne(t);if(!i.ok)throw new z(`This form could not be rendered: ${i.error}`,422);let o=i.schema;this.schema=o,this.theme=n;let s=this.options.renderOnly===!0;this.formId=s?void 0:r;let a=this.notOpenVariant!==null,l=a||s;this.engine=Ei({form:o,formId:l?void 0:r,client:l?void 0:this.options.client,initialData:this.options.initialData,onChange:a?void 0:this.options.onChange,onSubmitted:l?void 0:this.options.onSubmitted,getHoneypot:()=>this.element.querySelector('input[name="fillo_hp_field"]')?.value??this.hpValue,surface:"default",resolveFormId:l?void 0:this.resolveFormIdFn,skipValidation:s,verboseResolutionErrors:this.devChrome(),respondent:l?void 0:this.options.respondent,challengeRequired:l?!1:!!this.challenge,getChallengeToken:()=>this.challengeToken,onChallengeFailed:()=>this.resetChallengeWidget()});let u=this.engine.getState().status,c=this.engine.getState().resumedDraft,h=this.engine.getState().editingPrevious;this.engine.subscribe(()=>{let m=this.engine?.getState();m&&(m.status!==u||m.resumedDraft!==c||m.editingPrevious!==h)&&(m.editingPrevious&&!h?this.announce(T.editNotice):m.resumedDraft&&!c&&this.announce(T.resumeNotice),u=m.status,c=m.resumedDraft,h=m.editingPrevious,this.queueRender())}),l||this.configureDraftFlush(o),this.phase=this.closed?"closed":"ready",this.render()}applyCanonicalSchema(t,n,r){if(!this.engine){this.setSchema(t,n,r);return}let i=Ne(t);if(!i.ok)throw new z(`This form could not be rendered: ${i.error}`,422);let o=i.schema;this.schema=o,this.theme=n,this.formId=r,this.engine.setContext({form:o,formId:r}),this.notOpenVariant===null&&this.configureDraftFlush(o),this.phase=this.closed?"closed":"ready",this.render()}draftFlushWired=!1;flushDraftBound=()=>this.engine?.flushDraft();visibilityFlushBound=()=>{document.visibilityState==="hidden"&&this.engine?.flushDraft()};configureDraftFlush(t){this.teardownDraftFlush(),t.settings.saveProgress&&typeof window<"u"&&(window.addEventListener("pagehide",this.flushDraftBound),document.addEventListener("visibilitychange",this.visibilityFlushBound),this.draftFlushWired=!0)}teardownDraftFlush(){!this.draftFlushWired||typeof window>"u"||(window.removeEventListener("pagehide",this.flushDraftBound),document.removeEventListener("visibilitychange",this.visibilityFlushBound),this.draftFlushWired=!1)}flushDraft(){this.engine?.flushDraft()}resetDraft(){this.engine?.resetDraft(),this.queueRender()}setValue(t,n){this.setValueInternal(t,n)}setValueInternal(t,n,r={}){this.notOpenVariant||(this.engine?.setValue(t,n),r.render!==!1&&this.queueRender())}next(){if(!this.engine||this.notOpenVariant)return;let t=this.engine.getState().pageIndex;this.engine.next(),this.focusIntent=this.engine.getState().pageIndex!==t?"page":"error",this.render()}back(){!this.engine||this.notOpenVariant||(this.engine.back(),this.focusIntent="page",this.render())}async submit(){if(!this.engine||this.phase!=="ready"||this.notOpenVariant)return;let t=this.engine.submit();this.hasErrors()?this.focusIntent="error":this.engine.getState().status==="submitting"&&this.announce(Z.submittingAnnouncement),this.render();try{await t}catch(n){this.options.onError?.(ct(n)),this.focusIntent="error",this.render();return}this.hasErrors()&&(this.focusIntent="error"),this.render()}hasErrors(){return Object.keys(this.engine?.getState().errors??{}).length>0}setTheme(t){this.options.theme=t,this.theme=t,this.render()}setClient(t){this.options.client=t,this.engine?.setContext({client:t}),this.render()}setRespondent(t){this.options.respondent=t,this.engine?.setContext({respondent:t})}fieldActive(t){let n=0;for(let r of this.inFlight.values())r.fieldId===t&&r.error===void 0&&n++;return n}uploadRowsFor(t){let n=[];for(let[r,i]of this.inFlight)i.fieldId===t&&n.push({key:r,name:i.name,size:i.size,fraction:i.fraction,error:i.error,tooLarge:i.tooLarge});return n}uploadAction=(t,n)=>{let r=this.inFlight.get(t);if(r){if(n==="cancel")r.controller.abort(),this.inFlight.delete(t);else if(n==="dismiss")this.inFlight.delete(t);else{if(r.tooLarge)return;this.inFlight.delete(t),this.startUpload(r.fieldId,r.file,r.maxFiles)}this.fieldActive(r.fieldId)===0&&this.engine?.setUploading(r.fieldId,!1),this.queueRender()}};async startUpload(t,n,r){let i=`${n.name}-${n.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,o=new AbortController;this.inFlight.set(i,{fieldId:t,name:n.name,size:n.size,fraction:0,file:n,controller:o,maxFiles:r}),this.engine?.setUploading(t,!0),this.queueRender();try{let s=this.options.client&&this.formId?await this.options.client.uploadFile(this.formId,n,{fieldId:t,signal:o.signal,onProgress:l=>{let u=this.inFlight.get(i);u&&(u.fraction=l.fraction,this.queueRender())}}):{fileId:`local:${n.name}:${n.size}`,name:n.name,size:n.size,mime:n.type||"application/octet-stream"};if(this.destroyed)return;this.inFlight.delete(i);let a=r>1&&Array.isArray(this.mutableData[t])?this.mutableData[t]:[];this.setValueInternal(t,[...a,s])}catch(s){if(this.destroyed||o.signal.aborted)return;let a=ct(s),l=a.status!==void 0&&a.status>=500?Z.uploadUnavailable:a.message||Z.uploadFailed,u=this.inFlight.get(i);u&&(u.error=l),this.announceAlert(l),this.options.onError?.(a)}finally{this.fieldActive(t)===0&&this.engine?.setUploading(t,!1),this.queueRender()}}async uploadFiles(t,n){if(!this.schema||this.notOpenVariant)return;let r=t.maxFiles??1,i=r>1&&Array.isArray(this.mutableData[t.id])?this.mutableData[t.id].length:0,o=Math.max(0,r-i-this.fieldActive(t.id)),s=n.slice(0,o),a=t.maxFileSizeMb??500,l=this.uploadFileSizeLimitMb?Math.min(a,this.uploadFileSizeLimitMb):a,u=l*1024*1024,c=s.filter(p=>p.size<=u),h=s.filter(p=>p.size>u),m=n.length-s.length,f=s.length-c.length;if(m>0||f>0){let p=[];m>0&&p.push(`You can attach up to ${r} file${r===1?"":"s"}. ${m} ${m===1?"file was":"files were"} not added.`);let g=p.join(" ");g?this.uploadNotices.set(t.id,g):this.uploadNotices.delete(t.id),g&&this.announce(g)}else this.uploadNotices.delete(t.id);for(let p of h){let g=Z.fileTooLarge(l),v=`${p.name}-${p.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;this.inFlight.set(v,{fieldId:t.id,name:p.name,size:p.size,fraction:0,error:g,tooLarge:!0,file:p,controller:new AbortController,maxFiles:r}),this.announceAlert(g)}if(c.length===0){this.queueRender();return}await Promise.all(c.map(p=>this.startUpload(t.id,p,r)))}destroy(){this.destroyed=!0,this.teardownDraftFlush(),this.closeOverlays(),this.teardownTurnstileWidget();for(let t of this.inFlight.values())t.controller.abort();this.inFlight.clear(),this.engine?.destroy(),this.engine=null,this.target.replaceChildren()}storageBlocked(){return this.uploadsAvailable===!1}registerOverlay=t=>(this.overlays.add(t),()=>this.overlays.delete(t));closeOverlays(){if(this.overlays.size!==0){for(let t of Array.from(this.overlays))try{t()}catch{}this.overlays.clear()}}ensureTurnstileWidget(t){if(this.turnstileSiteKey!==t&&(this.teardownTurnstileWidget(),this.turnstileSiteKey=t),this.turnstileWidgetId!==null||this.turnstileLoadInFlight||this.challengeError)return;this.turnstileLoadInFlight=!0;let n=++this.turnstileAttempt;ka().then(()=>{if(this.destroyed||n!==this.turnstileAttempt)return;let r=He();if(!r){this.turnstileLoadInFlight=!1,this.handleChallengeError();return}this.turnstileWidgetId=r.render(this.turnstileContainer,{sitekey:t,theme:"auto",callback:i=>this.handleChallengeToken(i),"error-callback":()=>{this.handleChallengeToken(void 0),this.handleChallengeError()},"expired-callback":()=>this.resetChallengeWidget(),"timeout-callback":()=>this.resetChallengeWidget()}),this.turnstileLoadInFlight=!1}).catch(()=>{this.destroyed||n!==this.turnstileAttempt||(this.turnstileLoadInFlight=!1,this.handleChallengeError())})}handleChallengeToken(t){this.challengeToken=t,t&&(this.challengeError=!1),this.queueRender()}handleChallengeError(){this.challengeError=!0,this.announceAlert(T.challengeUnavailable),this.queueRender()}resetChallengeWidget(){this.challengeToken=void 0,this.turnstileWidgetId&&He()?.reset(this.turnstileWidgetId),this.queueRender()}teardownTurnstileWidget(){if(this.turnstileWidgetId===null&&!this.turnstileLoadInFlight)return;this.turnstileAttempt++;let t=He();if(this.turnstileWidgetId&&t)try{t.remove(this.turnstileWidgetId)}catch{}this.turnstileWidgetId=null,this.turnstileLoadInFlight=!1,this.challengeError=!1,this.turnstileContainer=Bi(),this.challengeToken=void 0}captureFocus(){if(typeof document>"u")return null;let t=document.activeElement;if(!t||!this.element.contains(t))return null;let n={};t.id&&(n.id=t.id);let r=t.getAttribute("data-fillo-rank-opt");r&&(n.rankOpt=r,n.rankDir=t.getAttribute("data-fillo-rank-dir")??void 0);let i=t.closest("[data-field]");if(i&&(n.fieldId=i.getAttribute("data-field")??void 0,n.controlIndex=Array.from(i.querySelectorAll(It)).indexOf(t)),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)try{n.selStart=t.selectionStart,n.selEnd=t.selectionEnd}catch{}return n.id||n.rankOpt||n.fieldId?n:null}restoreFocus(t){if(typeof document>"u")return;let n=null;if(t.rankOpt){let r=Array.from(this.element.querySelectorAll("[data-fillo-rank-opt]")).filter(i=>i.getAttribute("data-fillo-rank-opt")===t.rankOpt);n=r.find(i=>i.getAttribute("data-fillo-rank-dir")===t.rankDir&&!i.disabled)??r.find(i=>!i.disabled)??null}if(!n&&t.id&&(n=document.getElementById(t.id)),!n&&t.fieldId!=null&&t.controlIndex!=null&&t.controlIndex>=0){let r=Array.from(this.element.querySelectorAll("[data-field]")).find(i=>i.getAttribute("data-field")===t.fieldId);r&&(n=Array.from(r.querySelectorAll(It))[t.controlIndex]??null)}if(!(!n||typeof n.focus!="function")&&(n.focus(),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&t.selStart!=null))try{n.setSelectionRange(t.selStart,t.selEnd??t.selStart)}catch{}}applyFocus(t,n){if(!(typeof document>"u")){if(t==="error"){let r=this.element.querySelector('[aria-invalid="true"]');r&&Qs(r)?.focus();return}if(t==="page"){let i=this.element.querySelector(".fillo-page-title, .fillo-title")??this.element.querySelector(".fillo-blocks");i&&(i.hasAttribute("tabindex")||i.setAttribute("tabindex","-1"),i.focus?.());return}n&&this.restoreFocus(n)}}handleError(t){this.destroyed||(this.fatalError=t,this.phase="error",this.options.onError?.(t),this.render(t))}reportSyncFailure(t){if(this.destroyed)return;console.warn(`[fillo] form sync failed${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t;let n=this.devChrome();if(!n||this.options.renderError){this.genericUnavailable=!n,this.handleError(t);return}this.options.onError?.(t),n&&this.render()}reportSyncNotice(t){this.destroyed||(console.warn(`[fillo] form sync needs attention${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t,this.options.onError?.(t),this.devChrome()&&this.render())}reportSubmitSyncFailure(t){this.destroyed||(console.warn(`[fillo] form sync failed${t.code?` (${t.code})`:""}: ${t.message}`),this.syncErrorNotice=t)}queueRender(){this.renderQueued||this.destroyed||(this.renderQueued=!0,setTimeout(()=>{this.renderQueued=!1,this.render()},0))}render(t){if(this.destroyed)return;let n=this.focusIntent;this.focusIntent=null;let r=n?null:this.captureFocus();if(this.closeOverlays(),this.phase==="ready"&&this.engine?.getState().status!=="submitted"||this.teardownTurnstileWidget(),this.element.replaceChildren(),this.phase==="loading"){let s=d("div",{className:`fillo-form fillo-form--loading ${this.options.className??""}`,attrs:{"aria-busy":"true","data-fillo":"root","data-state":"loading"}});Ve(s,this.theme),C(s,[d("div",{className:"fillo-skeleton"}),d("div",{className:"fillo-skeleton"}),d("div",{className:"fillo-skeleton fillo-skeleton--short"})]),this.element.appendChild(s);return}let o=t??this.fatalError;if(this.phase==="error"&&o){let s=o.code==="form_target_required"&&this.devChrome()?`${o.message} (${o.code})`:null,a=this.options.renderError?.(o)??d("div",{className:"fillo-form fillo-form--error",text:s??(this.genericUnavailable?"This form is unavailable.":Ta(o))});a.hasAttribute("data-fillo")||a.setAttribute("data-fillo","root"),a.hasAttribute("data-state")||a.setAttribute("data-state","error"),o.code&&!a.hasAttribute("data-error-code")&&a.setAttribute("data-error-code",o.code),a.hasAttribute("role")||a.setAttribute("role","alert"),Ve(a,this.theme),this.element.appendChild(a);return}if(this.phase==="closed"){let s=d("div",{className:`fillo-form fillo-form--closed ${this.options.className??""}`,attrs:{"data-fillo":"root","data-state":"closed"}});Ve(s,this.theme),s.appendChild(d("p",{className:"fillo-closed",text:"This form is no longer accepting responses."})),this.element.appendChild(s);return}if(this.notOpenVariant&&this.schema){this.element.appendChild(this.renderNotOpen(this.notOpenVariant)),this.brandingVisible()&&this.element.appendChild(On(this.fetchedBrandLabel,this.fetchedBrandHref));return}if(this.schema){if(this.engine?.getState().status==="submitted"){let s=this.api(),a=this.engine.getState(),l=this.options.renderSuccess?.(s)??za(this.schema);if(l.setAttribute("data-fillo",l.getAttribute("data-fillo")??"root"),this.formId&&!l.hasAttribute("data-fillo-form-id")&&l.setAttribute("data-fillo-form-id",this.formId),l.setAttribute("data-state",l.getAttribute("data-state")??"submitted"),l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1"),Ve(l,this.theme),this.element.appendChild(l),this.brandingVisible()&&this.element.appendChild(On(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let u=dt(this.schema.settings.redirectUrl);u&&typeof window<"u"?window.location.assign(u):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&C(this.element,Ma({preview:this.options.preview===!0,devNotices:this.options.devNotices,syncError:this.syncErrorNotice,staged:this.stagedNotice,draft:this.draftNotice,warningUrl:this.syncWarningUrl,noClient:!this.options.client&&!this.options.renderOnly})),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(On(this.fetchedBrandLabel,this.fetchedBrandHref)),this.applyFocus(n,r)}}brandingVisible(){return this.fetchedPoweredBy??!0}renderNotOpen(t){let n=d("div",{className:`fillo-form fillo-form--not-open ${this.options.className??""}`,attrs:{"data-fillo":"root","data-state":"closed"}});Ve(n,this.theme);let r=d("div",{className:"fillo-not-open-preview",attrs:{"aria-hidden":"true",inert:""}});r.appendChild(this.renderForm());let i=d("div",{className:"fillo-not-open-card",attrs:{role:"status","data-fillo":"not-open-card"}});return i.appendChild(d("h2",{className:"fillo-not-open-title",text:t==="closed"?T.closedTitle:T.notOpenTitle})),i.appendChild(d("p",{className:"fillo-not-open-body",text:t==="closed"?T.closed:T.notOpenBody})),C(n,[r,i]),n}renderForm(){let t=this.api(),n=this.notOpenVariant!==null,r=!!this.challenge,i=!n&&r&&t.isLastPage,o=d(n?"div":"form",{className:`fillo-form ${this.options.className??""}`,attrs:{"data-fillo":n?"preview-form":"root","data-state":n?"preview":t.status,"data-page":String(t.pageIndex+1)}});!n&&this.formId&&o.setAttribute("data-fillo-form-id",this.formId),o.toggleAttribute("data-last-page",t.isLastPage),Ve(o,this.theme);let s=()=>{t.isLastPage?this.submit():this.next()};if(!n){let p=o;p.noValidate=!0,p.addEventListener("submit",g=>{g.preventDefault(),s()})}let a=n?o.appendChild(d("fieldset",{className:"fillo-not-open-fields",attrs:{disabled:""}})):o,l=this.engine?.getState();if(l?.resumedDraft||l?.editingPrevious){let p=d("div",{className:"fillo-resume",attrs:{"data-fillo":"resume"}});p.appendChild(d("span",{className:"fillo-resume-text",text:l.editingPrevious?T.editNotice:T.resumeNotice}));let g=d("button",{className:"fillo-resume-clear",text:T.resumeStartOver,attrs:{type:"button"}});g.addEventListener("click",()=>this.resetDraft()),p.appendChild(g),a.appendChild(p)}if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let p=Be(t.form,t.data),g=Math.max(p.length,1),v=p.indexOf(t.page.id),k=v>=0?v+1:Math.min(t.pageIndex+1,g),F=d("div",{className:"fillo-progress-track",attrs:{role:"progressbar","data-fillo":"progress","aria-label":t.form.title||"Form progress","aria-valuemin":"1","aria-valuemax":String(g),"aria-valuenow":String(k)}});F.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),F.firstElementChild?.style.setProperty("--fillo-progress-value",`${k/g*100}%`),a.appendChild(F)}if(t.pageIndex===0){let p=d("header",{className:"fillo-header",attrs:{"data-fillo":"header"}});t.form.title&&p.appendChild(d("h1",{className:"fillo-title",text:t.form.title,attrs:{"data-fillo":"title"}})),t.form.description&&p.appendChild(d("p",{className:"fillo-form-description",text:t.form.description,attrs:{"data-fillo":"description"}})),a.appendChild(p)}else t.page.title&&a.appendChild(d("h2",{className:"fillo-page-title",text:t.page.title,attrs:{"data-fillo":"pageTitle"}}));let u=d("div",{className:"fillo-blocks",attrs:{"data-fillo":"blocks"}});for(let p of t.blocks){let g=this.renderBlock(Li(p,this.mutableData,t.form),t);g&&u.appendChild(g)}if(a.appendChild(u),!n){let p=d("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});p.style.position="absolute",p.style.left="-9999px",p.style.top="auto",p.style.width="1px",p.style.height="1px",p.style.opacity="0",p.style.overflow="hidden",p.style.pointerEvents="none",p.addEventListener("input",()=>{this.hpValue=p.value}),a.appendChild(p)}if(i){let p=d("div",{className:"fillo-turnstile-slot",attrs:{"data-fillo":"turnstile-slot"}});p.appendChild(this.turnstileContainer),this.challengeError&&p.appendChild(d("p",{className:"fillo-turnstile-error",attrs:{role:"alert"},text:T.challengeUnavailable})),a.appendChild(p),this.ensureTurnstileWidget(this.challenge.siteKey)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight)&&this.teardownTurnstileWidget();let c=t.status==="error"?"This form can't submit right now. Please try again in a moment.":this.engine?.getState().submitError;if(c){let p=d("p",{className:"fillo-submit-error",attrs:{role:"alert"},text:c}),g=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?dt(this.syncWarningUrl):null;g&&(p.append(" Connect storage: "),p.appendChild(d("a",{text:g,attrs:{href:g,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(p)}let m=!(t.form.settings.submitMode==="auto")||!t.isLastPage||Ai(ii(t.form,t.data))||i;if(m||t.pageCount>1&&!t.isFirstPage){let p=d("footer",{className:"fillo-footer",attrs:{"data-fillo":"footer"}});if(t.pageCount>1&&!t.isFirstPage){let g=d("button",{className:"fillo-button fillo-button--ghost",text:"Back",attrs:{type:"button","data-fillo":"button"}});g.addEventListener("click",()=>this.back()),p.appendChild(g)}if(m){let g=d("button",{className:"fillo-button fillo-button--primary",text:t.status==="submitting"?"Submitting...":t.isLastPage?t.form.settings.submitLabel??"Submit":"Next",attrs:{type:"submit","data-fillo":"button"}});g.toggleAttribute("disabled",t.status==="submitting"||this.engine?.getState().uploading===!0||i&&!this.challengeToken),g.addEventListener("click",v=>{v.preventDefault(),s()}),p.appendChild(g)}a.appendChild(p)}return o}renderBlock(t,n){if(!ee(t))return $a(t);let r=(s,a)=>{if(this.setValueInternal(t.id,s,a),a?.render===!1)return;let l={form:n.form,data:n.data,status:n.status,isLastPage:n.isLastPage,uploading:this.engine?.getState().uploading===!0};Ci(t,s,l)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id]===st?di(t,Z):n.errors[t.id],ids:ea(this.instanceId,t.id),api:n,setValue:r,uploadFiles:(s,a)=>this.uploadFiles(s,a),uploadRows:this.uploadRowsFor(t.id),uploadAction:this.uploadAction,activeOtherFields:this.activeOtherFields,getValue:()=>this.engine?.getState().data[t.id],registerOverlay:this.registerOverlay,uploadNotice:this.uploadNotices.get(t.id),uploadDisabledReason:this.options.renderOnly?"render_only":this.storageBlocked()?"storage_unavailable":void 0,storageFixUrl:this.storageBlocked()&&this.devChrome()?dt(this.syncWarningUrl):null,announce:this.announce,announceAlert:this.announceAlert};return(t.kind==="custom"?this.options.customComponents?.[t.component]??this.options.components?.custom:this.options.components?.[t.kind]??_a)?.(i)??null}};function $a(e){switch(e.kind){case"heading":return d("h3",{className:"fillo-heading",text:e.text});case"paragraph":return d("p",{className:"fillo-paragraph",text:e.text});case"divider":return d("hr",{className:"fillo-divider"})}return d("div")}function za(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return C(n,[d("div",{className:"fillo-success-mark",attrs:{"aria-hidden":"true"}}),d("h2",{className:"fillo-success-title",text:e.settings.successTitle??"Thanks!"}),d("p",{className:"fillo-success-message",text:e.settings.successMessage??"Your response has been recorded."})]),t.appendChild(n),t}function On(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:ta(t),target:"_blank",rel:"noopener noreferrer"}})}function ji(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function Sa(){return Ti()}function Ea(){return d("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 and preview.)",attrs:{role:"alert"}})}function Aa(e){return d("div",{className:"fillo-devwarning",text:`Form sync needs attention${e.code?` (${e.code})`:""}: ${e.message} The safe form remains available for development.`,attrs:{role:"alert"}})}function Ca(){return d("div",{className:"fillo-devwarning",text:"Code changes are staged. Local preview only. Publish in Fillo before deploying for respondents.",attrs:{role:"alert"}})}function Fa(e){let t=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});t.append("Draft form \u2014 it renders here, but it won't accept responses until you publish it in your Fillo dashboard. ");let n=dt(e);return n&&(t.append("Connect storage to publish: "),t.appendChild(d("a",{text:n,attrs:{href:n,target:"_blank",rel:"noopener noreferrer"}})),t.append(". ")),t.append("(Shown only in development and preview.)"),t}function Ia(){return d("span",{className:"fillo-preview-badge",text:"Preview",attrs:{"data-fillo":"preview-badge"}})}var Vi=!1;function Na(){Vi||Pn()||(Vi=!0,console.warn("[fillo] `preview` is enabled in a production build. Preview is cosmetic only \u2014 it shows developer chrome and never changes where submissions go or whether they are accepted \u2014 but remove it before respondents see this page."))}function Ma(e){let t=[];return e.preview&&t.push(Ia()),e.devNotices===!1||(e.syncError?t.push(Aa(e.syncError)):e.staged?t.push(Ca()):e.draft?t.push(Fa(e.warningUrl)):e.noClient&&t.push(Ea())),t}function Ta(e){return e.status===404?T.loadFailedNotFound:e.status===0?T.loadFailedNetwork:e.status===422?T.renderFailed:T.loadFailed}function Hi(){return new z("This form has no Fillo target. Pass formId with the schema, use a defineForm() value with client, or set renderOnly for a non-submitting preview.",422,void 0,"form_target_required")}function ct(e){return J(e)?e:new z(e instanceof Error?e.message:String(e),0)}function Mt(e,t){let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new z(`Fillo mount target not found: ${String(e)}`,0);let r={...t,initialData:t.initialData??{}};return new pt(n,r)}function Ki(e){let t=d("div");return Mt(t,e),t}var La=typeof HTMLElement<"u"?HTMLElement:class{},Rn=class extends La{instance=null;assignedForm;assignedClient;assignedTheme;assignedInitialData;mounted=!1;mountScheduled=!1;static get observedAttributes(){return["publishable-key","form-id","data-preview","data-render-only"]}connectedCallback(){this.scheduleMount()}disconnectedCallback(){this.instance?.destroy(),this.instance=null,this.mounted=!1}attributeChangedCallback(){this.mounted&&this.isConnected&&this.scheduleMount()}set form(t){this.assignedForm=t,this.mounted&&this.scheduleMount()}get form(){return this.assignedForm}set client(t){this.assignedClient=t,this.mounted&&this.instance instanceof pt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof pt&&this.instance.setTheme(t)}set initialData(t){this.assignedInitialData=t,this.mounted&&this.scheduleMount()}scheduleMount(){this.mountScheduled||(this.mountScheduled=!0,queueMicrotask(()=>{this.mountScheduled=!1,this.isConnected&&this.mount()}))}previewAttrEnabled(){let t=this.getAttribute("data-preview");return t!==null&&t!=="false"&&t!=="0"}renderOnlyAttrEnabled(){let t=this.getAttribute("data-render-only");return t!==null&&t!=="false"&&t!=="0"}mount(){this.instance?.destroy();let t=this.getAttribute("publishable-key")??void 0,n=this.getAttribute("form-id")??void 0,r=this.assignedClient??(n||t?Me({key:t}):void 0);this.instance=Mt(this,{form:this.assignedForm,client:r,formId:n,theme:this.assignedTheme,initialData:this.assignedInitialData,preview:this.previewAttrEnabled()?!0:void 0,renderOnly:this.renderOnlyAttrEnabled()?!0:void 0,onChange:i=>this.dispatchEvent(new CustomEvent("fillo-change",{detail:{data:i}})),onSubmitted:(i,o)=>this.dispatchEvent(new CustomEvent("fillo-submit",{detail:{responseId:i,data:o}})),onError:i=>this.dispatchEvent(new CustomEvent("fillo-error",{detail:{error:i}}))}),this.mounted=!0}};function Un(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,Rn)}typeof customElements<"u"&&Un();return oo(Pa);})();