@usefillo/dom 0.13.0 → 0.14.0

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 Dt=Object.defineProperty;var po=Object.getOwnPropertyDescriptor;var fo=Object.getOwnPropertyNames;var ho=Object.prototype.hasOwnProperty;var mo=(e,t)=>{for(var n in t)Dt(e,n,{get:t[n],enumerable:!0})},go=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fo(t))!ho.call(e,i)&&i!==n&&Dt(e,i,{get:()=>t[i],enumerable:!(r=po(t,i))||r.enumerable});return e};var bo=e=>go(Dt({},"__esModule",{value:!0}),e);var el={};mo(el,{FilloClient:()=>Nt,FilloError:()=>S,createClient:()=>Ne,createFormElement:()=>oo,defineForm:()=>On,registerFilloElement:()=>qn,renderForm:()=>Rt});var Yn;function C(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 f=u[p];f in a||(a[f]=c[f].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 ge=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Yn=globalThis).__zod_globalConfig??(Yn.__zod_globalConfig={});var Ut=globalThis.__zod_globalConfig;function we(e){return e&&Object.assign(Ut,e),Ut}function er(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 tr(e,t){return typeof t=="bigint"?t.toString():t}function nr(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function jt(e){return e==null}function rr(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Qn=Symbol("evaluating");function _e(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Qn)return r===void 0&&(r=Qn,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var Vt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function bt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ht(e){if(bt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(bt(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Gt(e){return Ht(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var ir=new Set(["string","number","symbol"]);function qe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qt(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function G(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 or(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var vo={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 sr(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 xe(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function gt(e){return typeof e=="string"?e:e?.message}function $e(e,t,n){let r=e.message?e.message:gt(e.inst?._zod.def?.error?.(e))??gt(t?.error?.(e))??gt(n.customError?.(e))??gt(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 Wt(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var ar=(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,tr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},lr=C("$ZodError",ar),Ke=C("$ZodError",ar,{Parent:Error});var wo=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 ge;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>$e(l,o,we())));throw Vt(a,i?.callee),a}return s.value},vt=wo(Ke),_o=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,we())));throw Vt(a,i?.callee),a}return s.value},yt=_o(Ke),xo=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 ge;return o.issues.length?{success:!1,error:new(e??lr)(o.issues.map(s=>$e(s,i,we())))}:{success:!0,data:o.value}},Je=xo(Ke),$o=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,we())))}:{success:!0,data:o.value}},Xe=$o(Ke);var cr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var ko="(?:(?:\\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])))",So=new RegExp(`^${ko}$`);var ur=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Kt=/^-?\d+(?:\.\d+)?$/;var Ce=C("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),zo={number:"number",bigint:"bigint",object:"date"};var pr=C("$ZodCheckGreaterThan",(e,t)=>{Ce.init(e,t);let n=zo[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 fr=C("$ZodCheckMaxLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!jt(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=Wt(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),hr=C("$ZodCheckMinLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!jt(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=Wt(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var mr=C("$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 br={major:4,minor:4,patch:3};var se=C("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=br;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(sr(s)||!p._zod.def.when(s))continue}else if(c)continue;let f=s.issues.length,m=p._zod.check(s);if(m instanceof Promise&&l?.async===!1)throw new ge;if(u||m instanceof Promise)u=(u??Promise.resolve()).then(async()=>{await m,s.issues.length!==f&&(c||(c=We(s,f)))});else{if(s.issues.length===f)continue;c||(c=We(s,f))}}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 ge;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 ge;return l.then(c=>i(c,r,a))}return i(l,r,a)}}_e(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}))}),Jt=C("$ZodString",(e,t)=>{se.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??ur(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}}),Xt=C("$ZodStringFormat",(e,t)=>{mr.init(e,t),Jt.init(e,t)});var _r=C("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=cr),Xt.init(e,t)});var xr=C("$ZodNumber",(e,t)=>{se.init(e,t),e._zod.pattern=e._zod.bag.pattern??Kt,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 $r=C("$ZodUnknown",(e,t)=>{se.init(e,t),e._zod.parse=n=>n});function vr(e,t,n){e.issues.length&&t.issues.push(...xe(n,e.issues)),t.value[n]=e.value}var kr=C("$ZodArray",(e,t)=>{se.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=>vr(c,n,s))):vr(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function wt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...xe(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 Ao(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=or(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Co(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 f in t){if(f==="__proto__"||a.has(f))continue;if(c==="never"){s.push(f);continue}let m=l.run({value:t[f],issues:[]},r);m instanceof Promise?e.push(m.then(h=>wt(h,n,f,t,u,p))):wt(m,n,f,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 Sr=C("$ZodObject",(e,t)=>{if(se.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=nr(()=>Ao(t));_e(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=bt,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 f of s.keys){let m=p[f],h=m._zod.optin==="optional",b=m._zod.optout==="optional",g=m._zod.run({value:c[f],issues:[]},l);g instanceof Promise?u.push(g.then(v=>wt(v,a,f,c,h,b))):wt(g,a,f,c,h,b)}return o?Co(u,c,a,l,r.value,e):u.length?Promise.all(u).then(()=>a):a}});var zr=C("$ZodRecord",(e,t)=>{se.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Ht(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(m=>$e(m,r,we())),input:c,path:[c],inst:e});continue}let p=u.value,f=t.valueType._zod.run({value:i[c],issues:[]},r);f instanceof Promise?o.push(f.then(m=>{m.issues.length&&n.issues.push(...xe(c,m.issues)),n.value[p]=m.value})):(f.issues.length&&n.issues.push(...xe(c,f.issues)),n.value[p]=f.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"&&Kt.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=>$e(p,r,we())),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(...xe(a,p.issues)),n.value[l.value]=p.value})):(u.issues.length&&n.issues.push(...xe(a,u.issues)),n.value[l.value]=u.value)}}return o.length?Promise.all(o).then(()=>n):n}});var Er=C("$ZodEnum",(e,t)=>{se.init(e,t);let n=er(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>ir.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}}),Ar=C("$ZodLiteral",(e,t)=>{if(se.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 yr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Cr=C("$ZodOptional",(e,t)=>{se.init(e,t),e._zod.optin="optional",e._zod.optout="optional",_e(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),_e(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${rr(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=>yr(s,i)):yr(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var Fr=C("$ZodDefault",(e,t)=>{se.init(e,t),e._zod.optin="optional",_e(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=>wr(o,t)):wr(i,t)}});function wr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function Ir(e,t){return new e({type:"string",...G(t)})}function Lr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Nr(e,t){return new e({type:"number",checks:[],...G(t)})}function Mr(e){return new e({type:"unknown"})}function Yt(e,t){return new pr({check:"greater_than",...G(t),value:e,inclusive:!0})}function Qt(e){return Yt(0,e)}function X(e,t){return new fr({check:"max_length",...G(t),maximum:e})}function Oe(e,t){return new hr({check:"min_length",...G(t),minimum:e})}var de=C("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");se.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>vt(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Je(e,n,r),e.parseAsync=async(n,r)=>yt(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)=>qt(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.apply=n=>n(e)}),Pr=C("ZodMiniString",(e,t)=>{Jt.init(e,t),de.init(e,t)});function Y(e){return Ir(Pr,e)}var Io=C("ZodMiniStringFormat",(e,t)=>{Xt.init(e,t),Pr.init(e,t)}),Lo=C("ZodMiniEmail",(e,t)=>{_r.init(e,t),Io.init(e,t)});function _t(e){return Lr(Lo,e)}var No=C("ZodMiniNumber",(e,t)=>{xr.init(e,t),de.init(e,t)});function Rr(e){return Nr(No,e)}var Mo=C("ZodMiniUnknown",(e,t)=>{$r.init(e,t),de.init(e,t)});function Ye(){return Mr(Mo)}var To=C("ZodMiniArray",(e,t)=>{kr.init(e,t),de.init(e,t)});function ke(e,t){return new To({type:"array",element:e,...G(t)})}var Or=C("ZodMiniObject",(e,t)=>{Sr.init(e,t),de.init(e,t),_e(e,"shape",()=>t.shape)});function Qe(e,t){let n={type:"object",shape:e??{},...G(t)};return new Or(n)}function en(e,t){return new Or({type:"object",shape:e,catchall:Ye(),...G(t)})}var Tr=C("ZodMiniRecord",(e,t)=>{zr.init(e,t),de.init(e,t)});function Zr(e,t,n){return!t||!t._zod?new Tr({type:"record",keyType:Y(),valueType:e,...G(t)}):new Tr({type:"record",keyType:e,valueType:t,...G(n)})}var Po=C("ZodMiniEnum",(e,t)=>{Er.init(e,t),de.init(e,t),e.options=Object.values(t.entries)});function Dr(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Po({type:"enum",entries:n,...G(t)})}var Ro=C("ZodMiniLiteral",(e,t)=>{Ar.init(e,t),de.init(e,t)});function Ur(e,t){return new Ro({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var Oo=C("ZodMiniOptional",(e,t)=>{Cr.init(e,t),de.init(e,t)});function te(e){return new Oo({type:"optional",innerType:e})}var Zo=C("ZodMiniDefault",(e,t)=>{Fr.init(e,t),de.init(e,t)});function tn(e,t){return new Zo({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Gt(t)}})}var Bo=["heading","paragraph","divider"];function Q(e){return!Bo.includes(e.kind)}function It(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 jo(e,t){if(!Array.isArray(t))return;let n=new Map(e.fields.map(o=>[o.id,o])),r=!1,i=t.map(o=>{if(!o||typeof o!="object"||Array.isArray(o))return o;let s=!1,a={};for(let[l,c]of Object.entries(o)){let u=n.get(l);if(!u){s=!0;continue}let p=li(u,c);if(p===void 0){s=!0;continue}a[l]=p,p!==c&&(s=!0)}return s?(r=!0,a):o});return r?i:t}function ai(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="repeating_group")return jo(e,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 li(e,t){let n=ai(e,t);return It(n)?void 0:n}function ci(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function ui(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 gn(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(ui(n,ci(e.decimals)))}case"if":return Ue(kn(e.when,t)?e.then:e.else,t)}}function Vo(e,t){let n=Ue(e.calc,t);return n===null||e.decimals===void 0?n:Fe(ui(n,ci(e.decimals)))}function Ze(e,t){let n=ve(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=vn(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=vn(e,r)}let o=rt(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 nn(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 Br(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 gn(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 Ho(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return nn(n);case"not_answered":return!nn(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):Br(n,e.value);case"neq":return nn(n)?Array.isArray(n)?!n.some(r=>r===e.value):!Br(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=gn(n),i=gn(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function kn(e,t){return e.length===0?!0:e.every(n=>Ho(n,t))}function di(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:kn(e.visibleIf,t)}function rn(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 rt(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=li(l,t[l.id]);c!==void 0&&(l.kind==="repeating_group"&&(Array.isArray(c)?c.length:0)<Math.max(1,l.minInstances??1)||(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 m=rn(o,t,n,s,i,c);for(let h of r){let b=s.has(h.id)?Vo(h,m):null;b===null?delete c[h.id]:c[h.id]=b}}let u=rn(o,t,n,s,i,c),p=new Set;for(let m of e)di(m,u)&&p.add(m.id);let f=p.size===s.size&&[...p].every(m=>s.has(m))&&Go(a,c);if(s=p,a=c,f)break}return{visible:s,calc:a,calcIds:i,resolve:rn(o,t,n,s,i,a)}}function Go(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function pi(e,t){return rt(e,t).visible}function xt(e,t,n){let r=rt(ve(e),n);return t.blocks.filter(i=>Q(i)?r.visible.has(i.id):di(i,r.resolve))}function ve(e){return e.pages.flatMap(t=>t.blocks.filter(Q))}function fi(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 hi(e,t){let n=ve(e),r=pi(n,t);return n.filter(i=>r.has(i.id))}function Sn(e,t){let n=t&&typeof t=="object"&&!Array.isArray(t)?t:{},r=rt(e.fields,n);return e.fields.filter(i=>r.visible.has(i.id))}function qo(e,t){return rt(ve(e),t).resolve}function mi(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=qo(e,n);for(let s of i)if(kn(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=mi(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 Wo(e,t){return new Set(Be(e,t))}function bn(e,t,n){if("end"in mi(e,t,n))return!0;let r=Be(e,n);return r.length>0&&r[r.length-1]===t}function vn(e,t){let n=Wo(e,t),r=pi(ve(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)Q(s)&&r.has(s.id)&&i.add(s.id);return i}function gi(e,t){let n=vn(e,t);return ve(e).filter(r=>n.has(r.id))}var De;function Ko(){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 bi(e){try{return Ko()?.of(e)??e}catch{return e}}var w=(e,t,n=[],r=[],i="")=>({iso2:e,name:bi(e),dialCode:t,lengths:n,groups:r,example:i}),Jo=[w("US","1",[10],[3,3,4],"2015550123"),w("CA","1",[10],[3,3,4],"5145550123"),w("GB","44",[10],[4,6],"7400123456"),w("AU","61",[9],[3,3,3],"412345678"),w("DE","49",[10,11],[4,7],"15123456789"),w("FR","33",[9],[1,2,2,2,2],"612345678"),w("IN","91",[10],[5,5],"8123456789"),w("DK","45",[8],[2,2,2,2],"32123456"),w("SE","46",[9],[2,3,4],"701234567"),w("NO","47",[8],[3,2,3],"40612345"),w("FI","358",[9,10],[2,3,4],"412345678"),w("NL","31",[9],[1,4,4],"612345678"),w("BE","32",[9],[3,2,2,2],"470123456"),w("ES","34",[9],[3,3,3],"612345678"),w("IT","39",[9,10],[3,3,4],"3123456789"),w("PT","351",[9],[3,3,3],"912345678"),w("IE","353",[9],[2,3,4],"851234567"),w("CH","41",[9],[2,3,2,2],"781234567"),w("AT","43",[10,11],[3,7],"6641234567"),w("PL","48",[9],[3,3,3],"512345678"),w("CZ","420",[9],[3,3,3],"601123456"),w("GR","30",[10],[3,3,4],"6912345678"),w("RO","40",[9],[3,3,3],"712345678"),w("HU","36",[9],[2,3,4],"201234567"),w("UA","380",[9],[2,3,2,2],"501234567"),w("RU","7",[10],[3,3,2,2],"9123456789"),w("TR","90",[10],[3,3,2,2],"5012345678"),w("IL","972",[9],[2,3,4],"501234567"),w("AE","971",[9],[2,3,4],"501234567"),w("SA","966",[9],[2,3,4],"512345678"),w("ZA","27",[9],[2,3,4],"711234567"),w("NG","234",[10],[3,3,4],"8021234567"),w("KE","254",[9],[3,3,3],"712123456"),w("EG","20",[10],[3,3,4],"1001234567"),w("BR","55",[10,11],[2,5,4],"11961234567"),w("MX","52",[10],[3,3,4],"2221234567"),w("AR","54",[10],[4,6],"1123456789"),w("CL","56",[9],[1,4,4],"221234567"),w("CO","57",[10],[3,3,4],"3211234567"),w("PE","51",[9],[3,3,3],"912345678"),w("CN","86",[11],[3,4,4],"13123456789"),w("JP","81",[10],[2,4,4],"9012345678"),w("KR","82",[9,10],[2,4,4],"1023456789"),w("SG","65",[8],[4,4],"81234567"),w("HK","852",[8],[4,4],"51234567"),w("TW","886",[9],[3,3,3],"912345678"),w("MY","60",[9,10],[2,3,4],"123456789"),w("ID","62",[10,11],[3,4,4],"81234567890"),w("TH","66",[9],[2,3,4],"812345678"),w("PH","63",[10],[3,3,4],"9171234567"),w("VN","84",[9],[3,3,3],"912345678"),w("PK","92",[10],[3,3,4],"3012345678"),w("BD","880",[10],[2,4,4],"1812345678"),w("NZ","64",[9,10],[2,3,4],"211234567"),w("SK","421",[9],[3,3,3],"912123456"),w("BG","359",[9],[2,3,4],"481234567"),w("HR","385",[8,9],[2,3,4],"921234567"),w("RS","381",[8,9],[2,3,4],"601234567"),w("SI","386",[8],[2,3,3],"31234567"),w("LT","370",[8],[3,2,3],"61234567"),w("LV","371",[8],[2,3,3],"21234567"),w("EE","372",[7,8],[3,4],"51234567"),w("IS","354",[7],[3,4],"6111234"),w("LU","352",[9],[3,3,3],"628123456"),w("MA","212",[9],[3,3,3],"650123456"),w("CR","506",[8],[4,4],"83123456"),w("EC","593",[9],[2,3,4],"991234567"),w("UY","598",[8],[1,3,4],"94231234"),w("QA","974",[8],[4,4],"33123456"),w("KW","965",[8],[4,4],"50012345")],Xo="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 Yo(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:bi(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var it=[...Jo,...Yo(Xo)],je=Qo(it);function Qo(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 es=new Map(it.map(e=>[e.iso2,e])),ts={"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 zn(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 Lt(e){return e?es.get(e.toUpperCase()):void 0}function vi(e){return Lt(e?ts[e]:void 0)}function ns(e){let t;for(let n of it)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function he(e){return e.replace(/[^\d]/g,"")}function ot(e,t){let n=he(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 yi(e,t){let n=he(t);return n?`+${e.dialCode}${n}`:""}function st(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=he(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?he(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=ns(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 rs(e){let{country:t,national:n,e164:r}=st(e);if(!r)return!1;let i=he(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var is=8;function wi(e,t){if(!e||!t||typeof window>"u")return"below";let n=is,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 f=Math.min(t.offsetWidth,p),h=getComputedStyle(e).direction==="rtl"?o.right-f:o.left,b=0,g=h+f-(r-n);g>0&&(b-=g);let v=n-(h+b);return v>0&&(b+=v),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(b)}px`),l}var at="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."},os={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 ss(e){return os[e.kind]??at}var M={required:at,requiredForField:ss,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}`,groupAdd:"Add another",groupInstanceLabel:(e,t,n)=>`${e} ${t} of ${n}`,groupRemoveLabel:(e,t)=>`Remove ${e} ${t}`,groupInstanceAdded:(e,t,n)=>`${e} ${t} added, ${t} of ${n}`,groupInstanceRemoved:(e,t)=>t===0?`${e} removed, none left`:`${e} removed, ${t} remaining`,phoneCountrySelected:e=>`${e} selected`,phoneResultsCount:e=>`${e} ${e===1?"result":"results"}`,signatureEmpty:"No signature yet",signatureSigned:"Signature saved"};function _i(e,t){return t.requiredForField?.(e)??t.required}var as=Qe({fileId:Y().check(Oe(1)),name:Y(),size:Rr().check(Qt()),mime:Y(),url:te(Y())});function on(e,t){let n=Math.max(0,e.minInstances??1);return t<n?`Add at least ${n} ${n===1?"entry":"entries"}`:Number.isFinite(e.maxInstances)&&t>e.maxInstances?`At most ${e.maxInstances} ${e.maxInstances===1?"entry":"entries"}`:null}function Ft(e,t){if(It(t))return e.kind==="calculated"?null:e.kind==="repeating_group"?on(e,0):e.required?at: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`:_t().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"||!rs(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"repeating_group":{if(!Array.isArray(t))return on(e,0);let n=t;for(let r of n)if(!r||typeof r!="object"||Array.isArray(r))return"Invalid value";return on(e,n.length)}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=ke(as).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 xi(e,t){let n=gi(e,t),r={},i={};for(let o of n){if(o.kind==="calculated")continue;let s=ai(o,t[o.id]);if(o.kind==="repeating_group"){ls(o,s,r,i);continue}let a=Ft(o,s);a?r[o.id]=a:It(s)||(i[o.id]=s)}return{ok:Object.keys(r).length===0,errors:r,data:i}}function ls(e,t,n,r){let i=Ft(e,t);if(i&&(n[e.id]=i),!Array.isArray(t))return;let o=t,s=[];for(let a=0;a<o.length;a++){let l=o[a];if(!l||typeof l!="object"||Array.isArray(l))continue;let c={};for(let u of Sn(e,l)){let p=l[u.id],f=Ft(u,p);f?n[`${e.id}.${a}.${u.id}`]=f:It(p)||(c[u.id]=p)}s.push(c)}!i&&s.length>0&&(r[e.id]=s)}var cs=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","calculated","repeating_group","custom"],us=["heading","paragraph","divider"],ds=[...cs,...us],En=Y().check(Oe(1),X(128)),sn=en({id:En,label:Y().check(X(1e3)),icon:te(Ye())}),ps=en({id:En,kind:Dr(ds),label:te(Y().check(X(2e3))),options:te(ke(sn).check(X(200))),rows:te(ke(sn).check(X(200))),columns:te(ke(sn).check(X(200)))}),fs=Qe({id:En,title:te(Y().check(X(500))),blocks:ke(ps).check(X(500)),next:te(Ye())}),hs=Qe({version:Ur(1),title:tn(te(Y().check(X(2e3))),""),description:te(Y().check(X(5e3))),pages:ke(fs).check(Oe(1),X(50)),settings:tn(te(Zr(Y(),Ye())),{})}),ms=1,yn=1,wn="0.13.0";function ae(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function D(e,t){let n=ae(e,t);return n===""?void 0:n}function $t(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function be(e){return typeof e=="boolean"?e:void 0}function ce(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function fe(e,t,n,r){let i=ce(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function kt(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=ae(r.id,128),o=ae(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[R({id:i,label:o,icon:s})]:[]}):[]}function Ct(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function An(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=ae(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 $i(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(!$i(o,t,n,r))return!1;return!0}function gs(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=An(c);return Array.isArray(c)&&c.length>0&&u===void 0?[]:u&&u.some(p=>!$i(p.fieldId,i,r,new Set))?[]:[{when:u??[],to:l}]});return o.length?o:void 0}var bs=["number","rating","linear_scale","calculated"];function ze(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=ae(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=ce(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=ze(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=ze(n.left,t+1),i=ze(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=ze(n.arg,t+1);return r?R({op:"round",arg:r,decimals:ce(n.decimals)===void 0?void 0:fe(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=An(n.when)??[];if(r.length!==n.when.length)return null;let i=ze(n.then,t+1),o=ze(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function Ee(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)Ee(r,t,n);return;case"sub":case"div":Ee(e.left,t,n),Ee(e.right,t,n);return;case"round":Ee(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);Ee(e.then,t,n),Ee(e.else,t,n);return}}function vs(e,t){let n=new Map;for(let s of e)for(let a of s.blocks)Q(a)&&n.set(a.id,a.kind);let r=new Map;for(let s of e)for(let a of s.blocks){if(a.kind!=="calculated")continue;let l=ze(a.calc);if(!l)return`Field ${a.id} has a malformed calc expression \u2014 build it from value/const/add/sub/mul/div/min/max/round/if nodes`;a.calc=l;let c=new Set,u=new Set;Ee(l,c,u);for(let p of c){let f=n.get(p);if(f===void 0){let m=t.get(p);return m!==void 0?`Calculated field ${a.id} references ${p}, which is a child of repeating group ${m} \u2014 calculations can't reach inside a repeating group (calc operands must be top-level fields)`:`Calculated field ${a.id} references a missing field: ${p} \u2014 remove the reference or restore that field`}if(!bs.includes(f))return`Calculated field ${a.id} references non-numeric field ${p} (${f}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}r.set(a.id,[...c,...u].filter(p=>n.get(p)==="calculated"))}let i=new Map,o=(s,a)=>{let l=i.get(s);if(l==="done")return null;if(l==="visiting"){let c=[...a.slice(a.indexOf(s)),s].join(" \u2192 ");return`Calculated field ${s} depends on its own result (${c}) \u2014 break the cycle so the value can be computed`}i.set(s,"visiting");for(let c of r.get(s)??[]){let u=o(c,[...a,s]);if(u)return u}return i.set(s,"done"),null};for(let s of r.keys()){let a=o(s,[]);if(a)return a}return null}var jr=100,Vr=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 ys(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>jr?`Form has ${t} calculated fields \u2014 the maximum is ${jr}; remove some or consolidate them into fewer expressions`:n>Vr?`Calculated expressions total ${n} operations \u2014 the maximum is ${Vr} across the form; simplify or split up the calculations`:null}var Hr=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","date","rating","linear_scale"],Gr=12,qr=18e4;function ws(e){let t=e.id.length+20;switch(e.kind){case"short_text":case"email":case"url":return t+(e.maxLength??2e3);case"long_text":return t+(e.maxLength??2e4);case"phone":return t+32;case"number":return t+32;case"select":case"dropdown":{let n=e.options.reduce((r,i)=>Math.max(r,i.id.length),0);return t+Math.max(n,e.allowOther?500:0)}case"multi_select":{let n=e.options.reduce((r,i)=>r+i.id.length+3,0);return t+n+(e.allowOther?500:0)}case"checkbox":return t+8;case"date":return t+16;case"rating":case"linear_scale":return t+8;default:return t+64}}function _s(e){return e.fields.reduce((n,r)=>n+ws(r),24)*(Number.isFinite(e.maxInstances)?e.maxInstances:0)}function xs(e){for(let t of e)for(let n of t.blocks){if(n.kind!=="repeating_group")continue;if(!Number.isInteger(n.maxInstances)||n.maxInstances<1||n.maxInstances>20)return`Repeating group ${n.id} needs maxInstances to be a whole number between 1 and 20`;let r=n.minInstances??1;if(!Number.isInteger(r)||r<0||r>n.maxInstances)return`Repeating group ${n.id} needs minInstances to be a whole number between 0 and maxInstances (${n.maxInstances})`;if(n.minInstances=r,n.fields.length===0)return`Repeating group ${n.id} has no template fields \u2014 add at least one field to repeat`;if(n.fields.length>Gr)return`Repeating group ${n.id} has ${n.fields.length} template fields \u2014 the maximum is ${Gr}; split it into fewer fields`;for(let a of n.fields)if(!Hr.includes(a.kind))return`Repeating group ${n.id} has a "${a.kind}" child (${a.id}) \u2014 allowed child kinds are ${Hr.join(", ")}`;let i=Ct(n.fields);if(i)return`Duplicate child id in repeating group ${n.id}: ${i}`;let o=new Set(n.fields.map(a=>a.id));for(let a of n.fields)for(let l of a.visibleIf??[])if(!o.has(l.fieldId))return`Field ${a.id} in repeating group ${n.id} has a visibleIf referencing "${l.fieldId}" \u2014 a child's visibleIf can only reference another field in the SAME group`;let s=_s(n);if(s>qr)return`Repeating group ${n.id} could reach ~${Math.ceil(s/1e3)}KB at ${n.maxInstances} instances \u2014 the maximum is ~${Math.round(qr/1e3)}KB; lower maxInstances, shorten text limits, or trim the template`}return null}function $s(e){let t=new Set;for(let r of e)for(let i of r.blocks)Q(i)&&t.add(i.id);let n=new Map;for(let r of e)for(let i of r.blocks)if(i.kind==="repeating_group")for(let o of i.fields)!t.has(o.id)&&!n.has(o.id)&&n.set(o.id,i.id);return n}function ks(e,t,n){for(let r of e)for(let i of r.blocks)for(let o of i.visibleIf??[]){let s=n.get(o.fieldId);if(s!==void 0)return`Field ${i.id}'s visibleIf references "${o.fieldId}", which is a child of repeating group ${s} \u2014 fields outside a repeating group can't reference its children`}for(let r of t)if(Array.isArray(r.next))for(let i of r.next){if(!i||typeof i!="object")continue;let o=i.when;if(Array.isArray(o))for(let s of o){if(!s||typeof s!="object")continue;let a=s.fieldId;if(typeof a!="string")continue;let l=n.get(a);if(l!==void 0)return`A jump rule on page ${r.id} references "${a}", which is a child of repeating group ${l} \u2014 jumps can't reference a repeating group's children`}}return null}function ki(e){return{id:ae(e.id,128),visibleIf:An(e.visibleIf)}}function V(e,t){return{...ki(e),kind:t,label:ae(e.label,2e3,"Untitled field"),description:D(e.description,5e3),required:be(e.required),placeholder:D(e.placeholder,500)}}function Wr(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 Ss(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 zs(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 Es(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:Wr(t.redirectUrl),showProgress:be(t.showProgress),responseLimit:Ss(t.responseLimit),trust:zs(t.trust),notifyEmail:_t().check(X(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,sendReceipt:be(t.sendReceipt),saveProgress:be(t.saveProgress),draftAnswersVisible:be(t.draftAnswersVisible),resumeEmails:be(t.resumeEmails),resumeUrl:Wr(t.resumeUrl),draftDigest:be(t.draftDigest)}}function R(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Si(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=ki(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return R({...r,kind:n,text:ae(t.text,2e3,"Section")});case"paragraph":return R({...r,kind:n,text:ae(t.text,5e3)});case"divider":return R({...r,kind:n});case"short_text":case"email":case"url":return R({...V(t,n),maxLength:ce(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e3,2e3)});case"phone":{let i=D(t.defaultCountry,2)?.toUpperCase();return R({...V(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return R({...V(t,n),maxLength:ce(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e4,2e4)});case"number":return R({...V(t,n),min:ce(t.min),max:ce(t.max),decimals:ce(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:$t(t.prefix,100),suffix:$t(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=kt(t.options);return i.length===0?null:R({...V(t,n),options:i,allowOther:be(t.allowOther),shuffleOptions:be(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return R({...V(t,n),appearance:i})}case"signature":case"date":return R(V(t,n));case"rating":{let i=fe(t.max,1,10,5);return R({...V(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=fe(t.min,0,9,1),o=fe(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 R({...V(t,n),min:i,max:o,minLabel:D(t.minLabel,100),maxLabel:D(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=kt(t.options);return i.length<2?null:R({...V(t,n),options:i})}case"matrix":{let i=kt(t.rows),o=kt(t.columns);return i.length===0||o.length===0?null:R({...V(t,n),rows:i,columns:o})}case"hidden":return R({...V(t,n),required:!1,paramName:D(t.paramName,128),defaultValue:D(t.defaultValue,1e3)});case"calculated":return R({...V(t,n),required:!1,calc:t.calc,decimals:ce(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:$t(t.prefix,100),suffix:$t(t.suffix,100)});case"file_upload":return R({...V(t,n),maxFiles:fe(t.maxFiles,1,20,1),maxFileSizeMb:fe(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"repeating_group":{let o=(Array.isArray(t.fields)?t.fields:[]).slice(0,50).flatMap(s=>{let a=Si(s);return a&&Q(a)?[a]:[]});return R({...V(t,n),required:!1,fields:o,maxInstances:ce(t.maxInstances)??Number.NaN,minInstances:ce(t.minInstances),addLabel:D(t.addLabel,100),itemLabel:D(t.itemLabel,100)})}case"custom":return R({...V(t,n),component:ae(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function Le(e){let t=hs.safeParse(e);if(!t.success){let g=t.error.issues[0],v=g?.path.join(".");return{ok:!1,error:g?`${v?`${v}: `:""}${g.message}`:"Invalid schema"}}if(t.data.version>ms)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(g=>{let v=g.blocks.flatMap(z=>{let E=Si(z);return E?[E]:[]});return{id:ae(g.id,128),title:D(g.title,500),blocks:v,next:g.next}}),r=new Set(n.map(g=>g.id)),i=new Map;for(let g of n)for(let v of g.blocks){if(v.kind!=="calculated")continue;let z=new Set,E=ze(v.calc);if(E){let j=new Set,H=new Set;Ee(E,j,H);for(let ee of j)z.add(ee);for(let ee of H)z.add(ee)}i.set(v.id,z)}let o=new Set,s=n.map(g=>{for(let v of g.blocks)Q(v)&&o.add(v.id);return R({id:g.id,title:g.title,blocks:g.blocks,next:gs(g.next,r,g.id,new Set(o),i)})}),a=new Set,l=new Set;for(let g of s){if(!g.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(g.id))return{ok:!1,error:`Duplicate page id: ${g.id}`};a.add(g.id);for(let v of g.blocks){if(l.has(v.id))return{ok:!1,error:`Duplicate block id: ${v.id}`};if(l.add(v.id),v.kind==="number"&&v.min!==void 0&&v.max!==void 0&&v.min>v.max)return{ok:!1,error:`Field ${v.id} has min greater than max`};if(v.kind==="select"||v.kind==="multi_select"||v.kind==="dropdown"||v.kind==="ranking"){let z=Ct(v.options);if(z)return{ok:!1,error:`Duplicate option id in field ${v.id}: ${z}`}}else if(v.kind==="matrix"){let z=Ct(v.rows);if(z)return{ok:!1,error:`Duplicate matrix row id in field ${v.id}: ${z}`};let E=Ct(v.columns);if(E)return{ok:!1,error:`Duplicate matrix column id in field ${v.id}: ${E}`}}}}let c=xs(s);if(c)return{ok:!1,error:c};let u=$s(s),p=ks(s,n,u);if(p)return{ok:!1,error:p};let f=vs(s,u);if(f)return{ok:!1,error:f};let m=ys(s);if(m)return{ok:!1,error:m};if(s.every(g=>g.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let h={version:yn,title:ae(t.data.title,2e3),pages:s,settings:Es(t.data.settings)},b=D(t.data.description,5e3);return b&&(h.description=b),{ok:!0,schema:h}}function et(e,t){let n=D(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function Cn(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=R({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 As(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function Fn(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"repeating_group":{if(!Array.isArray(t))return String(t);let n=t;if(n.length===0)return"";let r=e.itemLabel??e.label,i=`${n.length} \xD7 ${r}`,o=e.fields[0];if(!o)return i;let s=n.map(a=>a&&typeof a=="object"&&!Array.isArray(a)?Fn(o,a[o.id]):"").filter(a=>a!=="");return s.length>0?`${i}: ${s.join(", ")}`:i}case"phone":{let{country:n,national:r,e164:i}=st(String(t));if(!i)return String(t);let o=ot(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 As(e)}}function Cs(e){return Math.max(0,Math.min(6,Math.round(e)))}function zi(e){switch(e){case"grouped-comma":return"en-US";case"grouped-dot":return"de-DE";case"grouped":case void 0:return}}function Ei(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:Cs(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 Ai(e,t){return t?e.split(t).join(""):e}function Kr(e,t){return t==="."?e:e.split(t).join(".")}function Fs(e,t,n){if(n!==t&&e.includes(n)){let o=e.lastIndexOf(n),s=Ai(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 In(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=Kr(o.replace(/\s/g,""),i):r==="."||r===","?o=Fs(o,r,i):o=Kr(Ai(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function lt(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 _n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Is=256-256%_n.length;function Jr(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<Is&&(n+=_n[o%_n.length])}}return n}var Ci=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}},St="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Ln(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+=St[r>>2],t+=St[(r&3)<<4|i>>4],t+=n+1<e.length?St[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?St[o&63]:"="}return t}var Ls=e=>Ln(new Ci().update(e).digest()),S=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 ne(e){return e instanceof Error&&e.name==="FilloError"}async function Xr(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 Yr(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var tt=3,nt=3e4,Ns=5*6e4,pe=10*6e4;function Qr(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 an(e,t=!1){let n=ne(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&ne(e)&&e.retryAfterSec!==void 0}function zt(e){return e>=500||e===429||e===408}function ei(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new S("Request timed out",0):e}function Ms(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 Ts(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==yn)throw new S(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${yn}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&Ms(wn,e.minSdkVersion)<0)throw new S(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${wn}.`,426)}function Et(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function Ps(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return Ln(new Uint8Array(n))}return Ls(e)}var Rs="https://fillo.so",ti={"X-Fillo-Client":`@usefillo/core@${wn}`},Nt=class{baseUrl;fetch;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":Rs,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",...ti,...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 ei(i)}if(!r.ok){let{message:i,code:o}=await Xr(r,`Request failed: ${r.status}`);throw new S(i,r.status,Yr(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return Ts(t),t}syncForm(e,t,n){if(!this.key)return Promise.reject(new S("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401));let r=Le(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:Cn(n)})}):Promise.reject(new S(`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",...ti},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(nt)})}catch(o){throw ei(o)}if(r.status===422)return{ok:!1,errors:(await r.json()).errors};if(!r.ok){let{message:o,code:s}=await Xr(r,`Submit failed: ${r.status}`);throw new S(o,r.status,Yr(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(ne(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(pe)){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,pe));if(c.formId!==e||c.fieldId!==n.fieldId||c.fileName!==r||c.size!==t.size||c.mime.trim().toLowerCase()!==i)throw new S("File does not match this upload session",400);o=c,o.token||=n.uploadToken}else{let c=Jr(24),u=Jr(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,pe)}),f=Date.now()+pe,m=250;for(;;)try{o=await p();break}catch(h){if(n.signal?.aborted||!an(h,!0))throw h;let b=f-Date.now();if(b<=0)throw h;await Qr(Math.min(m,b),n.signal),m=Math.min(m*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 S("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 S("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,pe)}),l;try{l=await a()}catch(c){if(n.signal?.aborted||!an(c))throw c;let u=Date.now()+pe,p=250;for(;;){let f=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,u-Date.now())));if(f.status==="complete"&&f.file)return f.file;if(f.status==="aborted")throw c;try{l=await a();break}catch(h){if(n.signal?.aborted||!an(h,!0))throw h}let m=u-Date.now();if(m<=0)throw c;await Qr(Math.min(p,m),n.signal),p=Math.min(p*2,5e3)}}if(!l.file)throw new S("Upload completed but no file was returned");return l.file}async boxUpload(e,t,n){let r=Et(t.size,n);r(0);let i={Authorization:`Bearer ${e.token}`};if(e.mode==="simple"){let f=new FormData;f.append("attributes",JSON.stringify({name:e.fileName,parent:{id:e.folderId}})),f.append("file",t,e.fileName);let m=await this.retry(n,async()=>{let b=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:f,signal:this.uploadSignal(n)});if(!b.ok&&zt(b.status))throw new S(`Box upload failed: ${b.status}`,b.status);return b});if(!m.ok)throw new S(`Box upload failed: ${m.status}`,m.status);let h=await m.json();return r(t.size),{providerFileId:h.entries?.[0]?.id}}if(e.size!==t.size)throw new S(`File size changed since the upload was requested (${t.size} vs ${e.size}).`,400);let o=await this.retry(n,async()=>{let f=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(!f.ok&&zt(f.status))throw new S(`Box session failed: ${f.status}`,f.status);return f});if(!o.ok)throw new S(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new Ci,l=[],c=0;for(;c<t.size;){n.signal?.throwIfAborted();let f=Math.min(c+s.part_size,t.size),m=new Uint8Array(await t.slice(c,f).arrayBuffer());a.update(m);let h=await Ps(m),b=await this.retry(n,async()=>{let g=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${h}`,"Content-Range":`bytes ${c}-${f-1}/${t.size}`},body:m,signal:this.uploadSignal(n)});if(!g.ok&&zt(g.status))throw new S(`Box part failed: ${g.status}`,g.status);return g});if(!b.ok)throw new S(`Box part failed: ${b.status}`,b.status);l.push((await b.json()).part),c=f,r(c)}let u=await this.retry(n,async()=>{let f=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:{...i,"Content-Type":"application/json",Digest:`sha=${Ln(a.digest())}`},body:JSON.stringify({parts:l}),signal:this.uploadSignal(n)});if(!f.ok&&zt(f.status))throw new S(`Box commit failed: ${f.status}`,f.status);return f});if(!u.ok)throw new S(`Box commit failed: ${u.status}`,u.status);return{providerFileId:(await u.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=Et(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 f=p.headers.get("Range")??p.headers.get("range"),m=f?.match(/bytes=0-(\d+)/);m?i=Number(m[1])+1:f==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,pe))).uploadedBytes;break}if(p.ok){i=n.size;break}throw new S(`Drive chunk failed: ${p.status}`,p.status)}catch(p){if(r.signal?.aborted||(u+=1,u>=tt))throw p;if(await new Promise(m=>setTimeout(m,500*2**u)),i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,pe))).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>=tt)throw new S("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 S("S3 upload session returned invalid progress",502);let r=Et(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 S("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,pe)});if(typeof u.uploadUrl!="string"||!u.uploadUrl)throw new S("S3 part URL was unavailable",502);c=u.uploadUrl;let p=await this.fetch(c,{method:"PUT",body:a,signal:this.uploadSignal(n,Ns)});if(!p.ok)throw new S(`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,pe));if(p.status==="aborted")throw new S("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 S("S3 upload session returned invalid progress",502);if(p.uploadedBytes>i){i=p.uploadedBytes,r(i);break}if(l+=1,l>=tt)throw u;await new Promise(f=>setTimeout(f,500*2**l))}}}}async s3PutUpload(e,t,n){let r=Et(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 S(`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 Ne(e={}){return new Nt(e)}function ln(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function ni(e,t){let n={};for(let r of ve(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=ln(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=ln(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=ln(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;case"repeating_group":break;default:n[r.id]=i}}return n}var Os={id:"empty",blocks:[]},ri=!1,ii=!1;function Zs(){ii||(ii=!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 Ds(){ri||(ri=!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 Fi=new Map;function Nn(){try{return globalThis.localStorage??null}catch{return null}}function Ii(e){return`fillo:submission:${e}`}function Mn(){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 Li(e,t,n,r){let i=Nn();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 Ni(e,t,n,r){e.set(n,r);let i=Nn();if(i)try{i.setItem(t,JSON.stringify(r))}catch{}}function Tn(e){return Li(Fi,Ii(e),e,t=>typeof t.key=="string")}function Mi(e,t){Ni(Fi,Ii(e),e,t)}function Us(e){let t=Tn(e);if(t?.key)return t.key;let n={key:Mn()};return Mi(e,n),n.key}function Bs(e,t){let n=Tn(e);Mi(e,{key:n?.key??Mn(),submittedAt:new Date().toISOString(),responseId:t})}function xn(e,t,n){let r=fi(e.settings,n);return r===null?t:`${t}::${r}`}function oi(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!Tn(xn(e,t,n))?.submittedAt}var Pn=new Map;function Rn(e){return`fillo:draft:${e}`}function At(e){return Li(Pn,Rn(e),e,t=>{let n=t;return typeof n.id=="string"&&typeof n.token=="string"})}function cn(e,t){Ni(Pn,Rn(e),e,t)}function un(e){Pn.delete(e);let t=Nn();if(t)try{t.removeItem(Rn(e))}catch{}}function dn(e){return ne(e)&&(e.status===401||e.status===403||e.status===404)}var js=1500,Vs="Please complete the verification check, then submit.",Hs="That verification didn't go through. Please complete the check again and resubmit.";function Ti(e){return ne(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 Gs(e,t){if(ne(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 Ti(e)}function Pi(e){let{onChange:t,onSubmitted:n}=e,r=Le(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",f=!1,m=!1;queueMicrotask(()=>{if(typeof location<"u"&&location.search){let $=Object.fromEntries(new URLSearchParams(location.search)),_=null;for(let[x,L]of Object.entries(ni(i,$)))l[x]===void 0&&(_=_??{...l},_[x]=L);_&&p==="idle"&&(l=Ze(i,_),A())}p==="idle"&&oi(i,o,l)&&(p="submitted",f=!0,A());let y=!1;if(i.settings.saveProgress&&o&&s&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let $=/fillo-draft=([^&]+)/.exec(location.hash),_=$?.[1]?decodeURIComponent($[1]):"",x=_.indexOf(".");if(x>0){y=!0;let L=_.slice(0,x),I=_.slice(x+1);s.getDraft(L,I,!0).then(N=>{cn(o,{id:L,token:N.token??I});try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(N=>{dn(N)&&(m=!0,A())}).finally(()=>oe())}}y||oe()});let h,b=new Set,g=new Set,v=Date.now(),z=Mn(),E=null,j=!1,H=!1,ee=!1,W="created",ue=!1,Z=null,U=null,ie=Promise.resolve(),K=!1,Ge=!1,Me=!1,k=!1;function le(){let y=i.pages.length,$=Math.min(u,Math.max(y-1,0)),_=i.pages[$]??Os;return{data:l,errors:c,status:p,pageIndex:$,pageCount:y,page:_,blocks:xt(i,_,l),isFirstPage:$===0,isLastPage:bn(i,_.id,l),uploading:b.size>0,submitError:h,restoredSubmission:f,resumedDraft:H,editingPrevious:ee,duplicateSubmission:W==="duplicate",updatedSubmission:W==="updated",resumeLinkFailed:m}}let B=le();function A(){B=le();for(let y of g)y()}function Te(y,$){try{n?.(y,$)}catch(_){console.error("[fillo] onSubmitted handler threw:",_)}}function Pe(y){let $=i.pages[y];if(!$)return{};let _={};for(let x of xt(i,$,l)){if(!Q(x))continue;let L=Ft(x,l[x.id]);L&&(_[x.id]=L)}return _}function Ae(){return!!(i.settings.saveProgress&&s&&o&&!Ge)}function P(){let y=new Set;for(let $ of i.pages)for(let _ of $.blocks)Q(_)&&y.add(_.id);return y}function J(y){if(p!=="idle"||j)return;let $=P(),_=null;for(let[I,N]of Object.entries(y.data??{}))l[I]===void 0&&$.has(I)&&(_=_??{...l},_[I]=N);let x=typeof y.page=="number"&&Number.isFinite(y.page)?Math.max(0,Math.min(Math.floor(y.page),i.pages.length-1)):0,L=x>0&&u===0;!_&&!L||(_&&(l=Ze(i,_)),L&&(u=x),H=!0,A())}function oe(){if(p!=="idle")return;if(!Ae()){ye();return}let y=o,$=s,_=Z??At(y);if(_&&!Me){Me=!0,Z=_,$.getDraft(_.id,_.token).then(J).catch(x=>{dn(x)&&(un(y),Z=null)});return}!_&&!k&&a?.hash&&(k=!0,$.createDraft(y,{data:{},page:0,respondent:a}).then(x=>{if(!Z){if(Z={id:x.id,token:x.token},cn(y,Z),x.existing)return $.getDraft(x.id,x.token).then(J);ye()}}).catch(x=>{ne(x)&&x.status!==void 0&&x.status>=400&&x.status<500||(k=!1)}))}function ye(){if(ue||i.settings.responseLimit?.onRepeat!=="update"||!s||!o||!a?.hash||p!=="idle")return;ue=!0;let y=s,$=fi(i.settings,l)??void 0;y.fetchOwnResponse(o,a,$).then(_=>{!_||p!=="idle"||j||H||(J({data:_.data,page:0}),H&&(H=!1,ee=!0,A()))}).catch(()=>{})}function Ot(y=!1){if(U&&(clearTimeout(U),U=null),!Ae()||p!=="idle"||!K)return;let $=o,_=s;K=!1,ie=ie.then(async()=>{let x={data:l,page:Math.max(0,Math.min(u,i.pages.length-1))},L=Z??At($);try{if(L)try{await _.saveDraft(L.id,L.token,x,y?{keepalive:!0}:void 0),Z=L;return}catch(N){if(!dn(N))throw N;un($),Z=null}let I=await _.createDraft($,a?.hash?{...x,respondent:a}:x);Z={id:I.id,token:I.token},cn($,Z),I.existing&&(K=!0)}catch(I){ne(I)&&I.status!==void 0&&I.status>=400&&I.status<500&&I.status!==429?Ge=!0:K=!0}})}function so(){!Ae()||p!=="idle"||(K=!0,U&&clearTimeout(U),U=setTimeout(()=>{U=null,Ot()},js))}function Wn(){!Ae()||!j&&!Z||(K=!0,Ot())}function Kn(){U&&(clearTimeout(U),U=null),K=!1,o&&un(o),Z=null}function ao(y,$){!j&&s&&o&&(j=!0,s.startSession(o,i.pages.length).then(x=>E=x)),l=Ze(i,{...l,[y]:$}),t?.(l),h=void 0;let _=`${y}.`;(y in c||Object.keys(c).some(x=>x.startsWith(_)))&&(c=Object.fromEntries(Object.entries(c).filter(([x])=>x!==y&&!x.startsWith(_)))),A(),so()}function lo(y,$){$?(b.add(y),y in c&&(c=Object.fromEntries(Object.entries(c).filter(([_])=>_!==y)))):b.delete(y),A()}function Jn(y){if(y.length===0)return-1;let $=i.pages.length,_=Math.min(u,Math.max($-1,0)),x=i.pages[_]?.id,L=x===void 0?-1:y.indexOf(x);if(L>=0)return L;let I=0;for(let N=0;N<y.length;N++){let me=i.pages.findIndex(Zt=>Zt.id===y[N]);me>=0&&me<=_&&(I=N)}return I}function co(){let y=i.pages.length,$=Math.min(u,Math.max(y-1,0));if(!e.skipValidation){let me=Pe($);if(c=me,Object.keys(me).length>0){A();return}}let _=i.pages[$],x=Be(i,l),L=Jn(x);if((_?bn(i,_.id,l):!0)||L<0||L+1>=x.length){Xn();return}let N=i.pages.findIndex(me=>me.id===x[L+1]);u=N>=0?N:Math.min($+1,y-1),E&&s&&s.reportProgress(E,{furthestPage:u}),A(),Wn()}function uo(){c={};let y=Be(i,l),$=Jn(y);if($>0){let _=i.pages.findIndex(x=>x.id===y[$-1]);u=_>=0?_:Math.max(Math.min(u,i.pages.length-1)-1,0)}else if(y.length>0){let _=i.pages.findIndex(x=>x.id===y[0]);u=_>=0?_:0}A(),Wn()}async function Xn(){if(p==="submitting"||p==="submitted")return;let y=xi(i,l);if(!y.ok){let $=e.skipValidation&&!(s&&o),_=$?Object.fromEntries(Object.entries(y.errors).filter(([L])=>i.pages.every(I=>I.blocks.every(N=>!(Q(N)&&N.id===L&&N.kind==="file_upload"))))):y.errors;if($&&Object.keys(_).length===0){c={},p="submitted",A(),Te(void 0,l);return}c=_;let x=i.pages.findIndex(L=>xt(i,L,l).some(I=>I.id in _));x>=0&&(u=x),A();return}if(s&&e.resolveFormId){p="submitting",h=void 0,A();try{o=await e.resolveFormId()}catch($){throw p="idle",h=Gs($,e.verboseResolutionErrors===!0),A(),$}}if(s&&o){let $=i.settings.responseLimit?.by==="browser"?Us(xn(i,o,y.data)):void 0,_=$??z,x=i.settings.saveProgress?Z??At(o):null,L=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!L){p="idle",h=Vs,A();return}p="submitting",h=void 0,A();let I;try{I=await s.submit(o,y.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-v,surface:e.surface??"headless",submissionKey:_,draft:x?{id:x.id,token:x.token}:void 0,respondent:a,challengeToken:L})}catch(N){if(p="idle",ne(N)&&N.code==="challenge_failed"){h=Hs,e.onChallengeFailed?.(),A();return}throw h=Ti(N),A(),N}if(!I.ok){c=I.errors??{};let N=i.pages.findIndex(me=>xt(i,me,l).some(Zt=>Zt.id in c));N>=0?u=N:h="We couldn't submit \u2014 please review your answers.",p="idle",A();return}W=I.duplicate?"duplicate":I.updated?"updated":"created",E&&s.reportProgress(E,{completed:!0}),$&&Bs(xn(i,o,y.data),I.responseId),Kn(),p="submitted",A(),Te(I.responseId,y.data);return}if(e.skipValidation){p="submitted",A(),Te(void 0,y.data);return}s&&!o?Zs():Ds(),p="error",A()}return{getState:()=>B,subscribe(y){return g.add(y),()=>{g.delete(y)}},setValue:ao,setUploading:lo,next:co,back:uo,submit:Xn,setContext(y){if("formId"in y&&(o=y.formId),"client"in y&&(s=y.client),"respondent"in y&&(a=y.respondent),y.form&&y.form!==i){let $=Le(y.form);if(!$.ok)throw new Error(`Invalid form schema: ${$.error}`);i=$.schema,l=Ze(i,l)}p==="idle"&&oi(i,o,l)&&(p="submitted",f=!0),oe(),A()},flushDraft(){Ot(!0)},resetDraft(){if(p==="submitting")return;let y=Z??(o?At(o):null);if(Kn(),y&&s&&s.deleteDraft(y.id,y.token).catch(()=>{}),l={...e.initialData??{}},typeof location<"u"&&location.search){let $=Object.fromEntries(new URLSearchParams(location.search));for(let[_,x]of Object.entries(ni(i,$)))l[_]===void 0&&(l[_]=x)}l=Ze(i,l),c={},u=0,h=void 0,H=!1,ee=!1,A()},destroy(){U&&(clearTimeout(U),U=null),g.clear()}}}function qs(e){return Q(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function Ri(e){let t=e.filter(n=>Q(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!qs(t[0])}function Oi(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||!bn(n.form,o.id,i))return!1;let s=gi(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:xi(n.form,i).ok}function Zi(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 Ws=Math.sqrt(1.05*.05)-.05,Ks=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Js=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function pn(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Xs(e){let t=e.trim(),n=null,r=Ks.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=Js.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*pn(i)+.7152*pn(o)+.0722*pn(s)}function Di(e){if(!e||e.colorScheme||!e.background||!e.text)return e;let t=Xs(e.background);return t==null?e:{...e,colorScheme:t>Ws?"light":"dark"}}function On(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 Zn(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var Se=new Map,Ys=e=>new Promise(t=>setTimeout(t,e));function Qs(e){if(!ne(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function ea(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(!Qs(i)||r>=2)throw i;let o=ne(i)?i.retryAfterSec:void 0;await Ys(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function ta(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 Ui(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 $n=e=>e==="published"?36e5:6e4,na=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function Bi(e,t){return`fillo:sync:v4:${e.baseUrl}|${e.key}|${t}`}function ra(e,t,n){try{let r=globalThis.localStorage?.getItem(Bi(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=$n(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function ia(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(Bi(e,t),JSON.stringify({formId:r.formId,slug:r.slug,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function Dn(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=ta(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=ve(t.schema).some(u=>u.kind==="file_upload"),a=Se.get(o);if(a&&!n?.bypassCache){if(a.expiresAt===null||!s&&a.expiresAt>Date.now())return a.promise;Se.delete(o)}if(!n?.bypassCache&&!s){let u=ra(e,t.id,i);if(u){let p=Promise.resolve({formId:u.formId,slug:u.slug,status:u.status,uploadFileSizeLimitMb:u.uploadFileSizeLimitMb});return Se.set(o,{promise:p,expiresAt:u.ts+$n(u.status)}),p}}let l=ea(e,t),c={promise:l,expiresAt:null};return Se.set(o,c),l.then(u=>{if(Se.get(o)===c){if(s||na(u)){Se.delete(o);return}c.expiresAt=Date.now()+$n(u.status),ia(e,t.id,i,u)}},()=>{Se.get(o)===c&&Se.delete(o)}),l}var oa=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},sa=Symbol.for("fillo.block");var aa=["label","description","required","placeholder"],O=(e,t,n,r={})=>({name:e,kind:t,props:[...aa,...n],...r}),si=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),fn=["options","allowOther","shuffleOptions"],la=[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",fn,{optionChildren:!0}),O("MultiSelect","multi_select",fn,{optionChildren:!0}),O("Dropdown","dropdown",fn,{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("RepeatingGroup","repeating_group",["minInstances","maxInstances","addLabel","itemLabel"],{blockChildren:!0}),O("Custom","custom",["component","config"]),si("Heading","heading",!0),si("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],ca={name:"Page",kind:"__page",props:["title"]},ua={name:"Option",kind:"__option",props:["label","icon"]};function hn(e){let t=()=>{throw new oa("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[sa]=e,t}var Bd=Object.fromEntries([...la.map(e=>[e.name,hn(e)]),["Page",hn(ca)],["Option",hn(ua)]]);function da(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 Un(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function ji(){if(Un())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&da(e)}var pa=/\{\{\s*([\w-]+)\s*\}\}/g;function mn(e,t,n){if(!e.includes("{{"))return e;let r=ve(n);return e.replace(pa,(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 Vi(e,t,n){let r=i=>i===void 0?i:mn(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:mn(e.text,t,n)};case"divider":return e;default:return{...e,label:mn(e.label,t,n),description:r(e.description)}}}var fa="fillo-",ha=0,ht='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function ma(e){return e.matches(ht)?e:e.querySelector(ht)}function ga(e){return Array.from(e.querySelectorAll(ht)).find(n=>!n.closest(".fillo-group-instance-header"))??null}function to(e,t){let n=`${fa}${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=Di(Cn(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 ft(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 ba(e){let t=new URL(ft(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function Pt(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Hi(e,t,n){let r=Pt(e);if(r==="")return r;let i=Number(r);return Number.isFinite(i)?Ei(i,{locale:n,decimals:t}):r}function F(e,t){for(let n of t)n&&e.appendChild(n);return e}var Gi="http://www.w3.org/2000/svg",va={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 no(e){if(!e)return null;let t=document.createElementNS(Gi,"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(Gi,"path");return n.setAttribute("d",va[e]),t.appendChild(n),t}function q(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 ro(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=Zi(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 re(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&&!(e.kind==="repeating_group"&&(e.minInstances??1)>0)&&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 ct(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation!==void 0,o=zi(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?Hi(t.value,r?.decimals,o):Pt(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 c=a.value,u=a.value.length,p=()=>{a.value=c,a.setSelectionRange(u,u)};i?(a.addEventListener("input",()=>{if(!lt(a.value,o))return p();c=a.value,u=a.selectionStart??a.value.length,t.setValue(In(a.value,o),{render:!1})}),a.addEventListener("change",()=>{if(!lt(a.value,o))return p();c=a.value,t.setValue(In(a.value,o))}),a.addEventListener("blur",()=>{let f=t.getValue?.()??t.value;a.value=Hi(f,r?.decimals,o),c=a.value,u=a.value.length})):(a.addEventListener("input",()=>{if(!lt(a.value,o))return p();c=a.value,u=a.selectionStart??a.value.length,t.setValue(a.value,{render:!1})}),a.addEventListener("change",()=>{if(!lt(a.value,o))return p();c=a.value,t.setValue(a.value)}))}else a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value));q(a,n,t.error,t.ids);let l=a;return r&&(r.prefix||r.suffix)&&(l=F(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])),re(n,t.error,l,t.ids)}function ya(){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 wa(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function _a(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 xa(e){let t=e.field,n=st(Pt(e.value)).country??Lt(t.defaultCountry)??vi(wa())??Lt(ya())??it[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"});F(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),F(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"}});q(l,e.field,e.error,e.ids);let c=()=>e.getValue?.()??e.value,u=()=>{let k=he(Pt(c()));return k.startsWith(n.dialCode)?k.slice(n.dialCode.length):k},p=()=>{s.textContent=zn(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},f=()=>{l.value=ot(n,u()),l.placeholder=ot(n,n.example)},m=k=>e.setValue(k?yi(n,k):"",{render:!1}),h=k=>e.setValue(k,{render:!1});p(),f(),l.addEventListener("input",()=>{let k=l.value,le=l.selectionStart??k.length,B=he(k.slice(0,le)).length;if(k.trimStart().startsWith("+")){let A=st(k,n,{previousDigits:u()});if(A.pending){h(A.raw??k);return}A.country&&(n=A.country,p()),m(A.country?A.national:he(k))}else m(he(k));l.value=ot(n,u()),_a(l,B)});let b=e.registerOverlay,g=e.announce,v=null,z=0,E=je,j=null,H=null,ee,W=`${e.ids.inputId}-countries`,ue=()=>{if(!v)return;let k=wi(i,v);v.classList.toggle("fillo-phone-popover--above",k==="above"),v.classList.toggle("fillo-phone-popover--below",k==="below")},Z=()=>{j?.();let k=()=>ue();ue(),window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),j=()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},U=k=>{let le=k.relatedTarget;if(le){i.contains(le)||ie();return}queueMicrotask(()=>{v&&!i.contains(document.activeElement)&&ie()})},ie=()=>{clearTimeout(ee),j?.(),j=null,v?.remove(),v=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",K),i.removeEventListener("focusout",U),H?.(),H=null},K=k=>{i.contains(k.target)||ie()},Ge=k=>{k&&(n=k,p(),m(u()),f(),ie(),g?.(M.phoneCountrySelected(k.name)),l.focus())},Me=k=>{let le=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),B=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":W,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});k&&(B.value=k);let A=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:W,"aria-label":"Country"}}),Te=()=>{if(A.replaceChildren(),E.length===0){A.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),B.removeAttribute("aria-activedescendant"),ue();return}E.forEach((P,J)=>{let oe=d("li",{className:`fillo-phone-option${J===z?" fillo-phone-option--active":""}`,attrs:{id:`${W}-opt-${J}`,role:"option","aria-selected":String(P.iso2===n.iso2)}});F(oe,[d("span",{className:"fillo-phone-flag-emoji",text:zn(P.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:P.name}),d("span",{className:"fillo-phone-option-dial",text:`+${P.dialCode}`})]),oe.addEventListener("mouseenter",()=>{z=J,B.setAttribute("aria-activedescendant",oe.id),Pe()}),oe.addEventListener("mousedown",ye=>{ye.preventDefault(),Ge(P)}),A.appendChild(oe)}),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`),ue()},Pe=()=>{[...A.children].forEach((P,J)=>P.classList.toggle("fillo-phone-option--active",J===z)),document.getElementById(`${W}-opt-${z}`)?.scrollIntoView({block:"nearest"})},Ae=P=>{let J=P.trim().toLowerCase(),oe=J.replace(/[^\d]/g,"");E=J?je.filter(ye=>ye.name.toLowerCase().includes(J)||ye.iso2.toLowerCase()===J||oe.length>0&&ye.dialCode.startsWith(oe)):je,z=0,Te(),clearTimeout(ee),ee=setTimeout(()=>g?.(M.phoneResultsCount(E.length)),300)};B.addEventListener("input",()=>Ae(B.value)),B.addEventListener("keydown",P=>{if(P.key==="ArrowDown"){if(P.preventDefault(),E.length===0)return;z=Math.min(z+1,E.length-1),Pe(),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`)}else if(P.key==="ArrowUp"){if(P.preventDefault(),E.length===0)return;z=Math.max(z-1,0),Pe(),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`)}else P.key==="Enter"?(P.preventDefault(),Ge(E[z])):P.key==="Escape"&&(P.preventDefault(),ie(),o.focus())}),F(le,[B,A]),v=le,i.appendChild(le),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",W),k?Ae(k):(E=je,z=Math.max(0,je.indexOf(n)),Te()),Z(),Pe(),document.addEventListener("mousedown",K),i.addEventListener("focusout",U),H=b?.(ie)??null,requestAnimationFrame(()=>{if(B.focus(),k){let P=B.value.length;B.setSelectionRange(P,P)}})};return o.addEventListener("click",()=>v?ie():Me()),o.addEventListener("keydown",k=>{if(!v){if(k.key==="ArrowDown"||k.key==="ArrowUp"){k.preventDefault(),Me();return}k.key.length===1&&k.key!==" "&&!k.ctrlKey&&!k.metaKey&&!k.altKey&&(k.preventDefault(),Me(k.key))}}),F(r,[i,l]),re(e.field,e.error,r,e.ids)}function $a(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)),q(t,e.field,e.error,e.ids),re(e.field,e.error,t,e.ids)}function ka(e){let t=e.field,n=Gn(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"}});q(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)}),F(c,[u,no(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})}),F(l,[F(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 re(t,e.error,a,e.ids)}function Sa(e){let t=e.field,n=Gn(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"}});q(l,t,e.error,e.ids,{requiredSupported:!1});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 f=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});f.checked=r.includes(u.id),f.addEventListener("change",()=>{let m=a();c(f.checked?[...m,u.id]:m.filter(h=>h!==u.id))}),F(p,[f,no(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 f=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(f.checked=u,f.addEventListener("change",()=>{let m=a().filter(h=>i.has(h));f.checked?(s?.add(t.id),c(m)):(s?.delete(t.id),c(m))}),F(p,[F(d("span",{className:"fillo-option-main"}),[f,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),u){let m=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});m.value=o??"",m.placeholder=T.otherPlaceholder,m.addEventListener("input",()=>{s?.add(t.id);let h=a().filter(b=>i.has(b));e.setValue(m.value?[...h,m.value]:h,{render:!1})}),m.addEventListener("change",()=>{s?.add(t.id);let h=a().filter(b=>i.has(b));e.setValue(m.value?[...h,m.value]:h)}),p.appendChild(m),o===void 0&&queueMicrotask(()=>m.focus())}l.appendChild(p)}return re(t,e.error,l,e.ids)}function za(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function Ea(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=za(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 Gn(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))}),q(c,t,e.error,e.ids),F(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 re(t,e.error,a,e.ids)}function Aa(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)}),q(c,e.field,e.error,e.ids),F(s,[l,c,F(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)),q(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)"})),F(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 Ca(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"}});q(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 ro(s,r,i,a=>e.setValue(a)),re(e.field,e.error,s,e.ids)}function Fa(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,f)=>t+f),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"}});q(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,f]of i.entries()){let m=d("button",{className:`fillo-scale-step${e.value===f?" fillo-scale-step--active":""}`,text:String(f),attrs:{type:"button",role:"radio","aria-label":String(f),"aria-checked":String(e.value===f),tabindex:String(p===o?0:-1),"data-fillo":"option"}});m.toggleAttribute("data-selected",e.value===f),m.addEventListener("click",h=>{h.detail===0&&e.value===f||e.setValue(e.value===f?null:f)}),c.appendChild(m)}return ro(c,i,r,p=>e.setValue(p)),l.appendChild(c),("minLabel"in e.field||"maxLabel"in e.field)&&F(l,[F(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}})])]),re(e.field,e.error,l,e.ids)}function Ia(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"}});q(o,e.field,e.error,e.ids,{requiredSupported:!1});let s=d("ol",{className:"fillo-ranking"});for(let[a,l]of i.entries()){let c=t.options.find(b=>b.id===l);if(!c)continue;let u=d("li",{className:"fillo-ranking-item"}),p=d("span",{className:"fillo-ranking-controls"}),f=b=>{let g=a+b;if(g<0||g>=i.length)return;let v=[...i];[v[a],v[g]]=[v[g],v[a]],e.setValue(v),n?.(M.rankingPosition(c.label,g+1,i.length))},m=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`}});m.toggleAttribute("disabled",a===0),m.addEventListener("click",()=>f(-1));let h=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`}});h.toggleAttribute("disabled",a===i.length-1),h.addEventListener("click",()=>f(1)),F(p,[m,h]),F(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),re(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("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 c=`${e.ids.inputId}-${l.id}`,u=n[l.id]!==void 0,p=!!e.error&&!!t.required&&!u,f=g=>`${e.ids.inputId}-${l.id}-${g.id}`,m=document.createElement("tr"),h=d("th",{attrs:{scope:"row"}}),b=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${c}`,"aria-owns":t.columns.map(f).join(" ")}});b.appendChild(d("span",{text:l.label,attrs:{id:c}})),h.appendChild(b),m.appendChild(h);for(let g of t.columns){let v=d("td",{attrs:{"data-label":g.label}}),z=d("label",{className:"fillo-matrix-cell"}),E=d("input",{className:"fillo-option-input",attrs:{id:f(g),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${g.label}`}});t.required&&E.setAttribute("aria-required","true"),p&&E.setAttribute("aria-invalid","true"),E.checked=n[l.id]===g.id,E.addEventListener("change",()=>e.setValue({...n,[l.id]:g.id})),z.appendChild(E),v.appendChild(z),m.appendChild(v)}s.appendChild(m)}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 q(a,e.field,e.error,e.ids,{requiredSupported:!1}),a.appendChild(r),re(e.field,e.error,a,e.ids)}function Na(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?M.signatureSigned:M.signatureEmpty)};if(c(),l&&s){let g=new Image;g.onload=()=>s.drawImage(g,0,0,r.width,r.height),g.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"}});q(u,e.field,e.error,e.ids);let p=g=>{s&&(s.clearRect(0,0,r.width,r.height),g.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(g,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 f=g=>{let v=r.getBoundingClientRect();return{x:(g.clientX-v.left)/v.width*r.width,y:(g.clientY-v.top)/v.height*r.height}};r.addEventListener("pointerdown",g=>{if(!s)return;a=!0,l=!0,o.style.display="none",c(),u.value&&(u.value=""),r.setPointerCapture(g.pointerId);let v=f(g);s.beginPath(),s.moveTo(v.x,v.y)}),r.addEventListener("pointermove",g=>{if(!a||!s)return;let v=f(g);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(v.x,v.y),s.stroke()});let m=()=>{a&&(a=!1,l&&e.setValue(r.toDataURL("image/png"),{render:!1}))};r.addEventListener("pointerup",m),r.addEventListener("pointercancel",m),i.addEventListener("click",()=>{s?.clearRect(0,0,r.width,r.height),l=!1,o.style.display="",u.value="",c(),e.setValue(null,{render:!1})}),F(n,[r,o,i]);let h=d("div",{className:"fillo-signature-type"}),b=d("label",{className:"fillo-signature-type-label",text:"Or type your full name to sign",attrs:{for:e.ids.inputId}});return F(h,[b,u]),F(t,[n,h]),re(e.field,e.error,t,e.ids)}function qi(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 Tt(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 Wi(e){let t=d("span",{className:`fillo-file-state fillo-file-state--${e}`,attrs:{"aria-hidden":"true"}});return t.appendChild(Tt(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 Bn(){let e=Tt(["m7 7 10 10M17 7 7 17"],16);return e.setAttribute("class","fillo-file-action-icon"),e}function Mt(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 Ma(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??[],c=o-a.length-l.filter(f=>f.error===void 0).length,u=d("div");if(c>0){let f=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file",hidden:""}});o>1&&(f.multiple=!0),t.accept?.length&&(f.accept=t.accept.join(",")),f.disabled=!i,f.addEventListener("change",()=>{if(!i)return;let h=Array.from(f.files??[]);f.value="",e.uploadFiles?.(t,h)});let m=d("div",{className:`fillo-dropzone${i?"":" fillo-dropzone--disabled"}`,attrs:{role:"button",tabindex:"0","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});if(q(m,t,e.error,e.ids,{requiredSupported:!1}),i||m.setAttribute("aria-disabled","true"),m.addEventListener("dragover",h=>{h.preventDefault(),m.classList.add("fillo-dropzone--over"),m.setAttribute("data-drag-over","")}),m.addEventListener("dragleave",()=>{m.classList.remove("fillo-dropzone--over"),m.removeAttribute("data-drag-over")}),m.addEventListener("drop",h=>{h.preventDefault(),m.classList.remove("fillo-dropzone--over"),m.removeAttribute("data-drag-over"),i&&e.uploadFiles?.(t,Array.from(h.dataTransfer?.files??[]))}),m.addEventListener("click",()=>{i&&f.click()}),m.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),i&&f.click())}),m.appendChild(f),i)F(m,[d("span",{className:"fillo-dropzone-title",text:M.dropzoneTitle(o>1)}),d("span",{className:"fillo-dropzone-hint",text:M.dropzoneHint(s)})]);else if(r==="render_only")m.appendChild(d("span",{className:"fillo-dropzone-hint",text:M.uploadsRenderOnly}));else if(n.storageFixUrl){let h=d("span",{className:"fillo-dropzone-hint",text:"Connect file storage to enable uploads"});h.append(" \u2014 "),h.appendChild(d("a",{text:n.storageFixUrl,attrs:{href:n.storageFixUrl,target:"_blank",rel:"noopener noreferrer"}})),m.appendChild(h)}else m.appendChild(d("span",{className:"fillo-dropzone-hint",text:M.uploadsUnavailable}));u.appendChild(m)}if(a.length>0||l.length>0){let f=d("ul",{className:"fillo-files"});for(let m of a){let h=d("li",{className:"fillo-file fillo-file--done"}),b=d("span",{className:"fillo-file-content"});F(b,[d("span",{className:"fillo-file-name",text:m.name}),d("span",{className:"fillo-file-meta",text:M.uploadedFile(qi(m.size))})]);let g=d("span",{className:"fillo-file-actions"});g.appendChild(Mt("fillo-file-remove",`${M.uploadRemove} ${m.name}`,Bn(),()=>e.setValue(a.filter(v=>v.fileId!==m.fileId)))),F(h,[Wi("done"),b,g]),f.appendChild(h)}for(let m of l){let h=m.error!==void 0,b=d("li",{className:`fillo-file${h?" fillo-file--failed":""}`});b.appendChild(Wi(h?"failed":"uploading"));let g=d("span",{className:"fillo-file-content"});if(g.appendChild(d("span",{className:"fillo-file-name",text:m.name})),h){let v=d("span",{className:"fillo-file-actions"});g.appendChild(d("span",{className:"fillo-file-error",text:m.error??""})),b.appendChild(g),!m.tooLarge&&c>0&&v.appendChild(Mt("fillo-file-retry",`${M.uploadRetry} ${m.name}`,M.uploadRetry,()=>n.uploadAction?.(m.key,"retry"))),v.appendChild(Mt("fillo-file-remove",`${M.uploadDismiss} ${m.name}`,Bn(),()=>n.uploadAction?.(m.key,"dismiss"))),b.appendChild(v)}else{let v=d("span",{className:"fillo-progress-bar"});v.style.width=`${m.fraction*100}%`,g.appendChild(d("span",{className:"fillo-file-meta",text:M.uploadingFile(Math.round(m.fraction*100),qi(m.size))}));let z=d("span",{className:"fillo-file-actions"});z.appendChild(Mt("fillo-file-remove",`${M.uploadCancel} ${m.name}`,Bn(),()=>n.uploadAction?.(m.key,"cancel"))),F(b,[g,z,F(d("span",{className:"fillo-progress",attrs:{role:"progressbar","aria-label":`Uploading ${m.name}`,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(Math.round(m.fraction*100))}}),[v])])}f.appendChild(b)}u.appendChild(f)}let p=n.uploadNotice;return p&&u.appendChild(d("p",{className:"fillo-upload-notice",text:p})),re(t,e.error,u,e.ids)}function Ta(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?Fn(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var Ki=new Map;function Gn(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=Ki.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]]}Ki.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}function ut(e){let t=e.getValue?.()??e.value;return Array.isArray(t)?t:[]}function Pa(e,t){return Math.max(t.length,e.minInstances??1)}function Ra(e){return Math.max(e.minInstances??1,0)}function jn(e,t){let n=[...e];for(;n.length<t;)n.push({});return n}function Oa(e){let t=e.field;if(t.kind!=="repeating_group")return null;let n=e,r=n.announce,i=n.instanceId??"",o=t.itemLabel||t.label,s=ut(e),a=Pa(t,s),l=Ra(t),c=d("div",{className:"fillo-group",attrs:{id:e.ids.inputId,"data-fillo":"control"}});q(c,t,e.error,e.ids,{requiredSupported:!1});for(let f=0;f<a;f++){let m=s[f]??{},h=M.groupInstanceLabel(o,f+1,a),b=d("div",{className:"fillo-group-instance",attrs:{role:"group","aria-label":h,tabindex:"-1"}}),g=d("div",{className:"fillo-group-instance-header"}),v=d("button",{className:"fillo-group-remove",text:"\xD7",attrs:{type:"button","aria-label":M.groupRemoveLabel(o,f+1)}}),z=a>l;v.toggleAttribute("disabled",!z),z||(v.setAttribute("aria-disabled","true"),v.setAttribute("title",`At least ${l} ${l===1?"entry":"entries"} required`)),v.addEventListener("click",()=>{if(a<=l)return;let E=jn(ut(e),a);E.splice(f,1),e.setValue(E),n.setGroupFocus?.({groupId:t.id,cardIndex:f-1,intoControl:!1}),r?.(M.groupInstanceRemoved(o,E.length))}),F(g,[d("p",{className:"fillo-group-instance-title",text:h}),v]),b.appendChild(g);for(let E of Sn(t,m)){let j=`${t.id}.${f}.${E.id}`,H={...E,id:j},ee=to(i,j),W=(U,ie)=>{let K=jn(ut(e),a);K[f]={...K[f]??{},[E.id]:U},e.setValue(K,ie)},ue={field:H,value:m[E.id],error:e.api.errors[j],ids:ee,api:e.api,setValue:W,getValue:()=>ut(e)[f]?.[E.id],announce:n.announce,announceAlert:n.announceAlert,registerOverlay:n.registerOverlay,activeOtherFields:n.activeOtherFields},Z=n.renderChildField?.(ue)??io(ue);Z&&b.appendChild(Z)}c.appendChild(b)}let u=a>=t.maxInstances,p=d("button",{className:"fillo-group-add",text:t.addLabel||M.groupAdd,attrs:{type:"button"}});return p.toggleAttribute("disabled",u),u&&(p.setAttribute("aria-disabled","true"),p.setAttribute("title",`Maximum ${t.maxInstances} ${t.maxInstances===1?"entry":"entries"}`)),p.addEventListener("click",()=>{if(a>=t.maxInstances)return;let f=jn(ut(e),a);f.push({}),e.setValue(f),n.setGroupFocus?.({groupId:t.id,cardIndex:f.length-1,intoControl:!0}),r?.(M.groupInstanceAdded(o,f.length,f.length))}),c.appendChild(p),re(t,e.error,c,e.ids)}var Za={short_text:e=>ct("text",e),email:e=>ct("email",e),url:e=>ct("url",e),phone:xa,number:e=>ct("number",e),date:e=>ct("date",e),long_text:$a,select:ka,multi_select:Sa,dropdown:Ea,checkbox:Aa,rating:Ca,linear_scale:Fa,ranking:Ia,matrix:La,signature:Na,file_upload:Ma,calculated:Ta,repeating_group:Oa};function io(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=Za[e.field.kind];return t?t(e):null}var Da="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",Ji="fillo-turnstile-script",dt=null;function He(){return globalThis.turnstile}function Ua(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):He()?Promise.resolve():dt||(dt=new Promise((e,t)=>{let n=()=>{He()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(Ji);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=Ji,i.src=Da,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),dt=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),dt)}function Xi(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var mt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&Ja(),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${++ha}`;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=Xi();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.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=Zn(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=Ne());let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await Dn(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 S("This form is no longer published. Submission was stopped before sending answers.",403,void 0,"form_not_published");if(o.accepting===!1)throw new S("This form is no longer accepting responses. Submission was stopped before sending answers.",403,void 0,o.acceptingReason??"form_not_accepting");let s=Le(o.resolvedSchema??t.schema);if(!s.ok)throw new S(`The canonical form schema was invalid: ${s.error}`,502,void 0,"invalid_sync_schema");if(this.schema&&!Ui(this.schema,s.schema))throw new S("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 S(o.syncError.message,403,void 0,o.syncError.code)),this.resolutionFailureCode=null,o.formId}catch(o){let s=pt(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(),eo();if(i&&!i.key&&!this.options.formId){this.reportSyncFailure(new S('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 Dn(i,t);if(this.destroyed)return;if((o.staged||o.syncError)&&!o.resolvedSchema)throw new S("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?Yi(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 S(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(pt(o))}return}let n=this.options.form&&!Zn(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(),eo();this.options.client??=Ne(),this.setSchema(n,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new S("Provide either `form`, or a `formId`.",0);this.options.client??=Ne(),this.render();let r=await this.options.client.getForm(this.options.formId);if(this.destroyed)return;if(r.accepting===!1?this.notOpenVariant=Yi(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 S(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(pt(t))}}setSchema(t,n,r){if(this.destroyed)return;let i=Le(t);if(!i.ok)throw new S(`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=Pi({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 c=this.engine.getState().status,u=this.engine.getState().resumedDraft,p=this.engine.getState().editingPrevious;this.engine.subscribe(()=>{let f=this.engine?.getState();f&&(f.status!==c||f.resumedDraft!==u||f.editingPrevious!==p)&&(f.editingPrevious&&!p?this.announce(T.editNotice):f.resumedDraft&&!u&&this.announce(T.resumeNotice),c=f.status,u=f.resumedDraft,p=f.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=Le(t);if(!i.ok)throw new S(`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(M.submittingAnnouncement),this.render();try{await t}catch(n){this.options.onError?.(pt(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 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=pt(s),l=a.status!==void 0&&a.status>=500?M.uploadUnavailable:a.message||M.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(h=>h.size<=c),p=s.filter(h=>h.size>c),f=n.length-s.length,m=s.length-u.length;if(f>0||m>0){let h=[];f>0&&h.push(`You can attach up to ${r} file${r===1?"":"s"}. ${f} ${f===1?"file was":"files were"} not added.`);let b=h.join(" ");b?this.uploadNotices.set(t.id,b):this.uploadNotices.delete(t.id),b&&this.announce(b)}else this.uploadNotices.delete(t.id);for(let h of p){let b=M.fileTooLarge(l),g=`${h.name}-${h.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;this.inFlight.set(g,{fieldId:t.id,name:h.name,size:h.size,fraction:0,error:b,tooLarge:!0,file:h,controller:new AbortController,maxFiles:r}),this.announceAlert(b)}if(u.length===0){this.queueRender();return}await Promise.all(u.map(h=>this.startUpload(t.id,h,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;Ua().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=Xi(),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(ht)).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(ht))[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&&ma(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}if(t){this.applyGroupFocus(t);return}n&&this.restoreFocus(n)}}applyGroupFocus(t){let n=Array.from(this.element.querySelectorAll("[data-field]")).find(o=>o.getAttribute("data-field")===t.groupId),r=n?Array.from(n.querySelectorAll(".fillo-group-instance")):[],i=t.cardIndex>=0?r[t.cardIndex]:void 0;if(i){(t.intoControl?ga(i)??i:i).focus();return}n?.querySelector(".fillo-group-add")?.focus()}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),F(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.":Ya(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(Vn(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)??ja(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(Vn(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let c=ft(this.schema.settings.redirectUrl);c&&typeof window<"u"?window.location.assign(c):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&F(this.element,Xa({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(Vn(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})),F(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 h=o;h.noValidate=!0,h.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 h=d("div",{className:"fillo-resume",attrs:{"data-fillo":"resume"}});h.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()),h.appendChild(b),a.appendChild(h)}if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let h=Be(t.form,t.data),b=Math.max(h.length,1),g=h.indexOf(t.page.id),v=g>=0?g+1:Math.min(t.pageIndex+1,b),z=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(v)}});z.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),z.firstElementChild?.style.setProperty("--fillo-progress-value",`${v/b*100}%`),a.appendChild(z)}if(t.pageIndex===0){let h=d("header",{className:"fillo-header",attrs:{"data-fillo":"header"}});t.form.title&&h.appendChild(d("h1",{className:"fillo-title",text:t.form.title,attrs:{"data-fillo":"title"}})),t.form.description&&h.appendChild(d("p",{className:"fillo-form-description",text:t.form.description,attrs:{"data-fillo":"description"}})),a.appendChild(h)}else t.page.title&&a.appendChild(d("h2",{className:"fillo-page-title",text:t.page.title,attrs:{"data-fillo":"pageTitle"}}));let c=d("div",{className:"fillo-blocks",attrs:{"data-fillo":"blocks"}});for(let h of t.blocks){let b=this.renderBlock(Vi(h,this.mutableData,t.form),t);b&&c.appendChild(b)}if(a.appendChild(c),!n){let h=d("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});h.style.position="absolute",h.style.left="-9999px",h.style.top="auto",h.style.width="1px",h.style.height="1px",h.style.opacity="0",h.style.overflow="hidden",h.style.pointerEvents="none",h.addEventListener("input",()=>{this.hpValue=h.value}),a.appendChild(h)}if(i){let h=d("div",{className:"fillo-turnstile-slot",attrs:{"data-fillo":"turnstile-slot"}});h.appendChild(this.turnstileContainer),this.challengeError&&h.appendChild(d("p",{className:"fillo-turnstile-error",attrs:{role:"alert"},text:T.challengeUnavailable})),a.appendChild(h),this.ensureTurnstileWidget(this.challenge.siteKey)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight)&&this.teardownTurnstileWidget();let u=t.status==="error"?"This form can't submit right now. Please try again in a moment.":this.engine?.getState().submitError;if(u){let h=d("p",{className:"fillo-submit-error",attrs:{role:"alert"},text:u}),b=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?ft(this.syncWarningUrl):null;b&&(h.append(" Connect storage: "),h.appendChild(d("a",{text:b,attrs:{href:b,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(h)}let f=!(t.form.settings.submitMode==="auto")||!t.isLastPage||Ri(hi(t.form,t.data))||i;if(f||t.pageCount>1&&!t.isFirstPage){let h=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()),h.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",g=>{g.preventDefault(),s()}),h.appendChild(b)}a.appendChild(h)}return o}fieldRenderer(t){return t.kind==="custom"?this.options.customComponents?.[t.component]??this.options.components?.custom:this.options.components?.[t.kind]??io}renderChildField=t=>this.fieldRenderer(t.field)?.(t)??null;setGroupFocus=t=>{this.focusIntent=t};renderBlock(t,n){if(!Q(t))return Ba(t);let r=(o,s)=>{if(this.setValueInternal(t.id,o,s),s?.render===!1)return;let a={form:n.form,data:n.data,status:n.status,isLastPage:n.isLastPage,uploading:this.engine?.getState().uploading===!0};Oi(t,o,a)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id]===at?_i(t,M):n.errors[t.id],ids:to(this.instanceId,t.id),api:n,setValue:r,uploadFiles:(o,s)=>this.uploadFiles(o,s),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()?ft(this.syncWarningUrl):null,announce:this.announce,announceAlert:this.announceAlert,instanceId:this.instanceId,renderChildField:this.renderChildField,setGroupFocus:this.setGroupFocus};return this.fieldRenderer(t)?.(i)??null}};function Ba(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 ja(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return F(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 Vn(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:ba(t),target:"_blank",rel:"noopener noreferrer"}})}function Yi(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function Va(){return ji()}function Ha(){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 Ga(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 qa(){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 Wa(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=ft(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 Qi=!1;function Ja(){Qi||Un()||(Qi=!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 Xa(e){let t=[];return e.preview&&t.push(Ka()),e.devNotices===!1||(e.syncError?t.push(Ga(e.syncError)):e.staged?t.push(qa()):e.draft?t.push(Wa(e.warningUrl)):e.noClient&&t.push(Ha())),t}function Ya(e){return e.status===404?T.loadFailedNotFound:e.status===0?T.loadFailedNetwork:e.status===422?T.renderFailed:T.loadFailed}function eo(){return new S("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 pt(e){return ne(e)?e:new S(e instanceof Error?e.message:String(e),0)}function Rt(e,t){let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new S(`Fillo mount target not found: ${String(e)}`,0);let r={...t,initialData:t.initialData??{}};return new mt(n,r)}function oo(e){let t=d("div");return Rt(t,e),t}var Qa=typeof HTMLElement<"u"?HTMLElement:class{},Hn=class extends Qa{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 mt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof mt&&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?Ne({key:t}):void 0);this.instance=Rt(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 qn(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,Hn)}typeof customElements<"u"&&qn();return bo(el);})();
1
+ "use strict";var Fillo=(()=>{var Dt=Object.defineProperty;var po=Object.getOwnPropertyDescriptor;var fo=Object.getOwnPropertyNames;var ho=Object.prototype.hasOwnProperty;var mo=(e,t)=>{for(var n in t)Dt(e,n,{get:t[n],enumerable:!0})},go=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fo(t))!ho.call(e,i)&&i!==n&&Dt(e,i,{get:()=>t[i],enumerable:!(r=po(t,i))||r.enumerable});return e};var bo=e=>go(Dt({},"__esModule",{value:!0}),e);var tl={};mo(tl,{FilloClient:()=>Nt,FilloError:()=>S,createClient:()=>Ne,createFormElement:()=>oo,defineForm:()=>On,registerFilloElement:()=>qn,renderForm:()=>Rt});var Yn;function C(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 f=u[p];f in a||(a[f]=c[f].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 ge=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Yn=globalThis).__zod_globalConfig??(Yn.__zod_globalConfig={});var Ut=globalThis.__zod_globalConfig;function we(e){return e&&Object.assign(Ut,e),Ut}function er(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 tr(e,t){return typeof t=="bigint"?t.toString():t}function nr(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function jt(e){return e==null}function rr(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Qn=Symbol("evaluating");function _e(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Qn)return r===void 0&&(r=Qn,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var Vt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function bt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ht(e){if(bt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(bt(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Gt(e){return Ht(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var ir=new Set(["string","number","symbol"]);function qe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qt(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function G(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 or(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var vo={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 sr(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 xe(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function gt(e){return typeof e=="string"?e:e?.message}function $e(e,t,n){let r=e.message?e.message:gt(e.inst?._zod.def?.error?.(e))??gt(t?.error?.(e))??gt(n.customError?.(e))??gt(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 Wt(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var ar=(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,tr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},lr=C("$ZodError",ar),Ke=C("$ZodError",ar,{Parent:Error});var wo=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 ge;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>$e(l,o,we())));throw Vt(a,i?.callee),a}return s.value},vt=wo(Ke),_o=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,we())));throw Vt(a,i?.callee),a}return s.value},yt=_o(Ke),xo=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 ge;return o.issues.length?{success:!1,error:new(e??lr)(o.issues.map(s=>$e(s,i,we())))}:{success:!0,data:o.value}},Je=xo(Ke),$o=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,we())))}:{success:!0,data:o.value}},Xe=$o(Ke);var cr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var ko="(?:(?:\\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])))",So=new RegExp(`^${ko}$`);var ur=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Kt=/^-?\d+(?:\.\d+)?$/;var Ce=C("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),zo={number:"number",bigint:"bigint",object:"date"};var pr=C("$ZodCheckGreaterThan",(e,t)=>{Ce.init(e,t);let n=zo[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 fr=C("$ZodCheckMaxLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!jt(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=Wt(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),hr=C("$ZodCheckMinLength",(e,t)=>{var n;Ce.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!jt(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=Wt(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var mr=C("$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 br={major:4,minor:4,patch:3};var se=C("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=br;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(sr(s)||!p._zod.def.when(s))continue}else if(c)continue;let f=s.issues.length,m=p._zod.check(s);if(m instanceof Promise&&l?.async===!1)throw new ge;if(u||m instanceof Promise)u=(u??Promise.resolve()).then(async()=>{await m,s.issues.length!==f&&(c||(c=We(s,f)))});else{if(s.issues.length===f)continue;c||(c=We(s,f))}}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 ge;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 ge;return l.then(c=>i(c,r,a))}return i(l,r,a)}}_e(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}))}),Jt=C("$ZodString",(e,t)=>{se.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??ur(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}}),Xt=C("$ZodStringFormat",(e,t)=>{mr.init(e,t),Jt.init(e,t)});var _r=C("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=cr),Xt.init(e,t)});var xr=C("$ZodNumber",(e,t)=>{se.init(e,t),e._zod.pattern=e._zod.bag.pattern??Kt,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 $r=C("$ZodUnknown",(e,t)=>{se.init(e,t),e._zod.parse=n=>n});function vr(e,t,n){e.issues.length&&t.issues.push(...xe(n,e.issues)),t.value[n]=e.value}var kr=C("$ZodArray",(e,t)=>{se.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=>vr(c,n,s))):vr(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function wt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...xe(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 Ao(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=or(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Co(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 f in t){if(f==="__proto__"||a.has(f))continue;if(c==="never"){s.push(f);continue}let m=l.run({value:t[f],issues:[]},r);m instanceof Promise?e.push(m.then(h=>wt(h,n,f,t,u,p))):wt(m,n,f,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 Sr=C("$ZodObject",(e,t)=>{if(se.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=nr(()=>Ao(t));_e(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=bt,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 f of s.keys){let m=p[f],h=m._zod.optin==="optional",b=m._zod.optout==="optional",g=m._zod.run({value:c[f],issues:[]},l);g instanceof Promise?u.push(g.then(v=>wt(v,a,f,c,h,b))):wt(g,a,f,c,h,b)}return o?Co(u,c,a,l,r.value,e):u.length?Promise.all(u).then(()=>a):a}});var zr=C("$ZodRecord",(e,t)=>{se.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Ht(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(m=>$e(m,r,we())),input:c,path:[c],inst:e});continue}let p=u.value,f=t.valueType._zod.run({value:i[c],issues:[]},r);f instanceof Promise?o.push(f.then(m=>{m.issues.length&&n.issues.push(...xe(c,m.issues)),n.value[p]=m.value})):(f.issues.length&&n.issues.push(...xe(c,f.issues)),n.value[p]=f.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"&&Kt.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=>$e(p,r,we())),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(...xe(a,p.issues)),n.value[l.value]=p.value})):(u.issues.length&&n.issues.push(...xe(a,u.issues)),n.value[l.value]=u.value)}}return o.length?Promise.all(o).then(()=>n):n}});var Er=C("$ZodEnum",(e,t)=>{se.init(e,t);let n=er(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>ir.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}}),Ar=C("$ZodLiteral",(e,t)=>{if(se.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 yr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Cr=C("$ZodOptional",(e,t)=>{se.init(e,t),e._zod.optin="optional",e._zod.optout="optional",_e(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),_e(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${rr(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=>yr(s,i)):yr(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var Fr=C("$ZodDefault",(e,t)=>{se.init(e,t),e._zod.optin="optional",_e(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=>wr(o,t)):wr(i,t)}});function wr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function Ir(e,t){return new e({type:"string",...G(t)})}function Lr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Nr(e,t){return new e({type:"number",checks:[],...G(t)})}function Mr(e){return new e({type:"unknown"})}function Yt(e,t){return new pr({check:"greater_than",...G(t),value:e,inclusive:!0})}function Qt(e){return Yt(0,e)}function X(e,t){return new fr({check:"max_length",...G(t),maximum:e})}function Oe(e,t){return new hr({check:"min_length",...G(t),minimum:e})}var de=C("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");se.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>vt(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Je(e,n,r),e.parseAsync=async(n,r)=>yt(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)=>qt(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.apply=n=>n(e)}),Pr=C("ZodMiniString",(e,t)=>{Jt.init(e,t),de.init(e,t)});function Y(e){return Ir(Pr,e)}var Io=C("ZodMiniStringFormat",(e,t)=>{Xt.init(e,t),Pr.init(e,t)}),Lo=C("ZodMiniEmail",(e,t)=>{_r.init(e,t),Io.init(e,t)});function _t(e){return Lr(Lo,e)}var No=C("ZodMiniNumber",(e,t)=>{xr.init(e,t),de.init(e,t)});function Rr(e){return Nr(No,e)}var Mo=C("ZodMiniUnknown",(e,t)=>{$r.init(e,t),de.init(e,t)});function Ye(){return Mr(Mo)}var To=C("ZodMiniArray",(e,t)=>{kr.init(e,t),de.init(e,t)});function ke(e,t){return new To({type:"array",element:e,...G(t)})}var Or=C("ZodMiniObject",(e,t)=>{Sr.init(e,t),de.init(e,t),_e(e,"shape",()=>t.shape)});function Qe(e,t){let n={type:"object",shape:e??{},...G(t)};return new Or(n)}function en(e,t){return new Or({type:"object",shape:e,catchall:Ye(),...G(t)})}var Tr=C("ZodMiniRecord",(e,t)=>{zr.init(e,t),de.init(e,t)});function Zr(e,t,n){return!t||!t._zod?new Tr({type:"record",keyType:Y(),valueType:e,...G(t)}):new Tr({type:"record",keyType:e,valueType:t,...G(n)})}var Po=C("ZodMiniEnum",(e,t)=>{Er.init(e,t),de.init(e,t),e.options=Object.values(t.entries)});function Dr(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Po({type:"enum",entries:n,...G(t)})}var Ro=C("ZodMiniLiteral",(e,t)=>{Ar.init(e,t),de.init(e,t)});function Ur(e,t){return new Ro({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var Oo=C("ZodMiniOptional",(e,t)=>{Cr.init(e,t),de.init(e,t)});function te(e){return new Oo({type:"optional",innerType:e})}var Zo=C("ZodMiniDefault",(e,t)=>{Fr.init(e,t),de.init(e,t)});function tn(e,t){return new Zo({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Gt(t)}})}var Bo=["heading","paragraph","divider"];function Q(e){return!Bo.includes(e.kind)}function It(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 jo(e,t){if(!Array.isArray(t))return;let n=new Map(e.fields.map(o=>[o.id,o])),r=!1,i=t.map(o=>{if(!o||typeof o!="object"||Array.isArray(o))return o;let s=!1,a={};for(let[l,c]of Object.entries(o)){let u=n.get(l);if(!u){s=!0;continue}let p=li(u,c);if(p===void 0){s=!0;continue}a[l]=p,p!==c&&(s=!0)}return s?(r=!0,a):o});return r?i:t}function ai(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="repeating_group")return jo(e,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 li(e,t){let n=ai(e,t);return It(n)?void 0:n}function ci(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function ui(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 gn(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(ui(n,ci(e.decimals)))}case"if":return Ue(kn(e.when,t)?e.then:e.else,t)}}function Vo(e,t){let n=Ue(e.calc,t);return n===null||e.decimals===void 0?n:Fe(ui(n,ci(e.decimals)))}function Ze(e,t){let n=ve(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=vn(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=vn(e,r)}let o=rt(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 nn(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 Br(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 gn(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 Ho(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return nn(n);case"not_answered":return!nn(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):Br(n,e.value);case"neq":return nn(n)?Array.isArray(n)?!n.some(r=>r===e.value):!Br(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=gn(n),i=gn(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function kn(e,t){return e.length===0?!0:e.every(n=>Ho(n,t))}function di(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:kn(e.visibleIf,t)}function rn(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 rt(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=li(l,t[l.id]);c!==void 0&&(l.kind==="repeating_group"&&(Array.isArray(c)?c.length:0)<Math.max(1,l.minInstances??1)||(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 m=rn(o,t,n,s,i,c);for(let h of r){let b=s.has(h.id)?Vo(h,m):null;b===null?delete c[h.id]:c[h.id]=b}}let u=rn(o,t,n,s,i,c),p=new Set;for(let m of e)di(m,u)&&p.add(m.id);let f=p.size===s.size&&[...p].every(m=>s.has(m))&&Go(a,c);if(s=p,a=c,f)break}return{visible:s,calc:a,calcIds:i,resolve:rn(o,t,n,s,i,a)}}function Go(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function pi(e,t){return rt(e,t).visible}function xt(e,t,n){let r=rt(ve(e),n);return t.blocks.filter(i=>Q(i)?r.visible.has(i.id):di(i,r.resolve))}function ve(e){return e.pages.flatMap(t=>t.blocks.filter(Q))}function fi(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 hi(e,t){let n=ve(e),r=pi(n,t);return n.filter(i=>r.has(i.id))}function Sn(e,t){let n=t&&typeof t=="object"&&!Array.isArray(t)?t:{},r=rt(e.fields,n);return e.fields.filter(i=>r.visible.has(i.id))}function qo(e,t){return rt(ve(e),t).resolve}function mi(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=qo(e,n);for(let s of i)if(kn(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=mi(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 Wo(e,t){return new Set(Be(e,t))}function bn(e,t,n){if("end"in mi(e,t,n))return!0;let r=Be(e,n);return r.length>0&&r[r.length-1]===t}function vn(e,t){let n=Wo(e,t),r=pi(ve(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)Q(s)&&r.has(s.id)&&i.add(s.id);return i}function gi(e,t){let n=vn(e,t);return ve(e).filter(r=>n.has(r.id))}var De;function Ko(){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 bi(e){try{return Ko()?.of(e)??e}catch{return e}}var w=(e,t,n=[],r=[],i="")=>({iso2:e,name:bi(e),dialCode:t,lengths:n,groups:r,example:i}),Jo=[w("US","1",[10],[3,3,4],"2015550123"),w("CA","1",[10],[3,3,4],"5145550123"),w("GB","44",[10],[4,6],"7400123456"),w("AU","61",[9],[3,3,3],"412345678"),w("DE","49",[10,11],[4,7],"15123456789"),w("FR","33",[9],[1,2,2,2,2],"612345678"),w("IN","91",[10],[5,5],"8123456789"),w("DK","45",[8],[2,2,2,2],"32123456"),w("SE","46",[9],[2,3,4],"701234567"),w("NO","47",[8],[3,2,3],"40612345"),w("FI","358",[9,10],[2,3,4],"412345678"),w("NL","31",[9],[1,4,4],"612345678"),w("BE","32",[9],[3,2,2,2],"470123456"),w("ES","34",[9],[3,3,3],"612345678"),w("IT","39",[9,10],[3,3,4],"3123456789"),w("PT","351",[9],[3,3,3],"912345678"),w("IE","353",[9],[2,3,4],"851234567"),w("CH","41",[9],[2,3,2,2],"781234567"),w("AT","43",[10,11],[3,7],"6641234567"),w("PL","48",[9],[3,3,3],"512345678"),w("CZ","420",[9],[3,3,3],"601123456"),w("GR","30",[10],[3,3,4],"6912345678"),w("RO","40",[9],[3,3,3],"712345678"),w("HU","36",[9],[2,3,4],"201234567"),w("UA","380",[9],[2,3,2,2],"501234567"),w("RU","7",[10],[3,3,2,2],"9123456789"),w("TR","90",[10],[3,3,2,2],"5012345678"),w("IL","972",[9],[2,3,4],"501234567"),w("AE","971",[9],[2,3,4],"501234567"),w("SA","966",[9],[2,3,4],"512345678"),w("ZA","27",[9],[2,3,4],"711234567"),w("NG","234",[10],[3,3,4],"8021234567"),w("KE","254",[9],[3,3,3],"712123456"),w("EG","20",[10],[3,3,4],"1001234567"),w("BR","55",[10,11],[2,5,4],"11961234567"),w("MX","52",[10],[3,3,4],"2221234567"),w("AR","54",[10],[4,6],"1123456789"),w("CL","56",[9],[1,4,4],"221234567"),w("CO","57",[10],[3,3,4],"3211234567"),w("PE","51",[9],[3,3,3],"912345678"),w("CN","86",[11],[3,4,4],"13123456789"),w("JP","81",[10],[2,4,4],"9012345678"),w("KR","82",[9,10],[2,4,4],"1023456789"),w("SG","65",[8],[4,4],"81234567"),w("HK","852",[8],[4,4],"51234567"),w("TW","886",[9],[3,3,3],"912345678"),w("MY","60",[9,10],[2,3,4],"123456789"),w("ID","62",[10,11],[3,4,4],"81234567890"),w("TH","66",[9],[2,3,4],"812345678"),w("PH","63",[10],[3,3,4],"9171234567"),w("VN","84",[9],[3,3,3],"912345678"),w("PK","92",[10],[3,3,4],"3012345678"),w("BD","880",[10],[2,4,4],"1812345678"),w("NZ","64",[9,10],[2,3,4],"211234567"),w("SK","421",[9],[3,3,3],"912123456"),w("BG","359",[9],[2,3,4],"481234567"),w("HR","385",[8,9],[2,3,4],"921234567"),w("RS","381",[8,9],[2,3,4],"601234567"),w("SI","386",[8],[2,3,3],"31234567"),w("LT","370",[8],[3,2,3],"61234567"),w("LV","371",[8],[2,3,3],"21234567"),w("EE","372",[7,8],[3,4],"51234567"),w("IS","354",[7],[3,4],"6111234"),w("LU","352",[9],[3,3,3],"628123456"),w("MA","212",[9],[3,3,3],"650123456"),w("CR","506",[8],[4,4],"83123456"),w("EC","593",[9],[2,3,4],"991234567"),w("UY","598",[8],[1,3,4],"94231234"),w("QA","974",[8],[4,4],"33123456"),w("KW","965",[8],[4,4],"50012345")],Xo="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 Yo(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:bi(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var it=[...Jo,...Yo(Xo)],je=Qo(it);function Qo(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 es=new Map(it.map(e=>[e.iso2,e])),ts={"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 zn(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 Lt(e){return e?es.get(e.toUpperCase()):void 0}function vi(e){return Lt(e?ts[e]:void 0)}function ns(e){let t;for(let n of it)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function he(e){return e.replace(/[^\d]/g,"")}function ot(e,t){let n=he(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 yi(e,t){let n=he(t);return n?`+${e.dialCode}${n}`:""}function st(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=he(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?he(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=ns(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 rs(e){let{country:t,national:n,e164:r}=st(e);if(!r)return!1;let i=he(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var is=8;function wi(e,t){if(!e||!t||typeof window>"u")return"below";let n=is,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 f=Math.min(t.offsetWidth,p),h=getComputedStyle(e).direction==="rtl"?o.right-f:o.left,b=0,g=h+f-(r-n);g>0&&(b-=g);let v=n-(h+b);return v>0&&(b+=v),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(b)}px`),l}var at="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."},os={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 ss(e){return os[e.kind]??at}var M={required:at,requiredForField:ss,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}`,groupAdd:"Add another",groupInstanceLabel:(e,t,n)=>`${e} ${t} of ${n}`,groupRemoveLabel:(e,t)=>`Remove ${e} ${t}`,groupInstanceAdded:(e,t,n)=>`${e} ${t} added, ${t} of ${n}`,groupInstanceRemoved:(e,t)=>t===0?`${e} removed, none left`:`${e} removed, ${t} remaining`,phoneCountrySelected:e=>`${e} selected`,phoneResultsCount:e=>`${e} ${e===1?"result":"results"}`,signatureEmpty:"No signature yet",signatureSigned:"Signature saved"};function _i(e,t){return t.requiredForField?.(e)??t.required}var as=Qe({fileId:Y().check(Oe(1)),name:Y(),size:Rr().check(Qt()),mime:Y(),url:te(Y())});function on(e,t){let n=Math.max(0,e.minInstances??1);return t<n?`Add at least ${n} ${n===1?"entry":"entries"}`:Number.isFinite(e.maxInstances)&&t>e.maxInstances?`At most ${e.maxInstances} ${e.maxInstances===1?"entry":"entries"}`:null}function Ft(e,t){if(It(t))return e.kind==="calculated"?null:e.kind==="repeating_group"?on(e,0):e.required?at: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`:_t().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"||!rs(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"repeating_group":{if(!Array.isArray(t))return on(e,0);let n=t;for(let r of n)if(!r||typeof r!="object"||Array.isArray(r))return"Invalid value";return on(e,n.length)}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=ke(as).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 xi(e,t){let n=gi(e,t),r={},i={};for(let o of n){if(o.kind==="calculated")continue;let s=ai(o,t[o.id]);if(o.kind==="repeating_group"){ls(o,s,r,i);continue}let a=Ft(o,s);a?r[o.id]=a:It(s)||(i[o.id]=s)}return{ok:Object.keys(r).length===0,errors:r,data:i}}function ls(e,t,n,r){let i=Ft(e,t);if(i&&(n[e.id]=i),!Array.isArray(t))return;let o=t,s=[];for(let a=0;a<o.length;a++){let l=o[a];if(!l||typeof l!="object"||Array.isArray(l))continue;let c={};for(let u of Sn(e,l)){let p=l[u.id],f=Ft(u,p);f?n[`${e.id}.${a}.${u.id}`]=f:It(p)||(c[u.id]=p)}s.push(c)}!i&&s.length>0&&(r[e.id]=s)}var cs=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","rating","linear_scale","ranking","matrix","signature","date","file_upload","hidden","calculated","repeating_group","custom"],us=["heading","paragraph","divider"],ds=[...cs,...us],En=Y().check(Oe(1),X(128)),sn=en({id:En,label:Y().check(X(1e3)),icon:te(Ye())}),ps=en({id:En,kind:Dr(ds),label:te(Y().check(X(2e3))),options:te(ke(sn).check(X(200))),rows:te(ke(sn).check(X(200))),columns:te(ke(sn).check(X(200)))}),fs=Qe({id:En,title:te(Y().check(X(500))),blocks:ke(ps).check(X(500)),next:te(Ye())}),hs=Qe({version:Ur(1),title:tn(te(Y().check(X(2e3))),""),description:te(Y().check(X(5e3))),pages:ke(fs).check(Oe(1),X(50)),settings:tn(te(Zr(Y(),Ye())),{})}),ms=1,yn=1,wn="0.14.0";function ae(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function D(e,t){let n=ae(e,t);return n===""?void 0:n}function $t(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function be(e){return typeof e=="boolean"?e:void 0}function ce(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function fe(e,t,n,r){let i=ce(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function kt(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=ae(r.id,128),o=ae(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[R({id:i,label:o,icon:s})]:[]}):[]}function Ct(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function An(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=ae(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 $i(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(!$i(o,t,n,r))return!1;return!0}function gs(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=An(c);return Array.isArray(c)&&c.length>0&&u===void 0?[]:u&&u.some(p=>!$i(p.fieldId,i,r,new Set))?[]:[{when:u??[],to:l}]});return o.length?o:void 0}var bs=["number","rating","linear_scale","calculated"];function ze(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=ae(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=ce(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=ze(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=ze(n.left,t+1),i=ze(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=ze(n.arg,t+1);return r?R({op:"round",arg:r,decimals:ce(n.decimals)===void 0?void 0:fe(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=An(n.when)??[];if(r.length!==n.when.length)return null;let i=ze(n.then,t+1),o=ze(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function Ee(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)Ee(r,t,n);return;case"sub":case"div":Ee(e.left,t,n),Ee(e.right,t,n);return;case"round":Ee(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);Ee(e.then,t,n),Ee(e.else,t,n);return}}function vs(e,t){let n=new Map;for(let s of e)for(let a of s.blocks)Q(a)&&n.set(a.id,a.kind);let r=new Map;for(let s of e)for(let a of s.blocks){if(a.kind!=="calculated")continue;let l=ze(a.calc);if(!l)return`Field ${a.id} has a malformed calc expression \u2014 build it from value/const/add/sub/mul/div/min/max/round/if nodes`;a.calc=l;let c=new Set,u=new Set;Ee(l,c,u);for(let p of c){let f=n.get(p);if(f===void 0){let m=t.get(p);return m!==void 0?`Calculated field ${a.id} references ${p}, which is a child of repeating group ${m} \u2014 calculations can't reach inside a repeating group (calc operands must be top-level fields)`:`Calculated field ${a.id} references a missing field: ${p} \u2014 remove the reference or restore that field`}if(!bs.includes(f))return`Calculated field ${a.id} references non-numeric field ${p} (${f}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}r.set(a.id,[...c,...u].filter(p=>n.get(p)==="calculated"))}let i=new Map,o=(s,a)=>{let l=i.get(s);if(l==="done")return null;if(l==="visiting"){let c=[...a.slice(a.indexOf(s)),s].join(" \u2192 ");return`Calculated field ${s} depends on its own result (${c}) \u2014 break the cycle so the value can be computed`}i.set(s,"visiting");for(let c of r.get(s)??[]){let u=o(c,[...a,s]);if(u)return u}return i.set(s,"done"),null};for(let s of r.keys()){let a=o(s,[]);if(a)return a}return null}var jr=100,Vr=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 ys(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>jr?`Form has ${t} calculated fields \u2014 the maximum is ${jr}; remove some or consolidate them into fewer expressions`:n>Vr?`Calculated expressions total ${n} operations \u2014 the maximum is ${Vr} across the form; simplify or split up the calculations`:null}var Hr=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","date","rating","linear_scale"],Gr=12,qr=18e4;function ws(e){let t=e.id.length+20;switch(e.kind){case"short_text":case"email":case"url":return t+(e.maxLength??2e3);case"long_text":return t+(e.maxLength??2e4);case"phone":return t+32;case"number":return t+32;case"select":case"dropdown":{let n=e.options.reduce((r,i)=>Math.max(r,i.id.length),0);return t+Math.max(n,e.allowOther?500:0)}case"multi_select":{let n=e.options.reduce((r,i)=>r+i.id.length+3,0);return t+n+(e.allowOther?500:0)}case"checkbox":return t+8;case"date":return t+16;case"rating":case"linear_scale":return t+8;default:return t+64}}function _s(e){return e.fields.reduce((n,r)=>n+ws(r),24)*(Number.isFinite(e.maxInstances)?e.maxInstances:0)}function xs(e){for(let t of e)for(let n of t.blocks){if(n.kind!=="repeating_group")continue;if(!Number.isInteger(n.maxInstances)||n.maxInstances<1||n.maxInstances>20)return`Repeating group ${n.id} needs maxInstances to be a whole number between 1 and 20`;let r=n.minInstances??1;if(!Number.isInteger(r)||r<0||r>n.maxInstances)return`Repeating group ${n.id} needs minInstances to be a whole number between 0 and maxInstances (${n.maxInstances})`;if(n.minInstances=r,n.fields.length===0)return`Repeating group ${n.id} has no template fields \u2014 add at least one field to repeat`;if(n.fields.length>Gr)return`Repeating group ${n.id} has ${n.fields.length} template fields \u2014 the maximum is ${Gr}; split it into fewer fields`;for(let a of n.fields)if(!Hr.includes(a.kind))return`Repeating group ${n.id} has a "${a.kind}" child (${a.id}) \u2014 allowed child kinds are ${Hr.join(", ")}`;let i=Ct(n.fields);if(i)return`Duplicate child id in repeating group ${n.id}: ${i}`;let o=new Set(n.fields.map(a=>a.id));for(let a of n.fields)for(let l of a.visibleIf??[])if(!o.has(l.fieldId))return`Field ${a.id} in repeating group ${n.id} has a visibleIf referencing "${l.fieldId}" \u2014 a child's visibleIf can only reference another field in the SAME group`;let s=_s(n);if(s>qr)return`Repeating group ${n.id} could reach ~${Math.ceil(s/1e3)}KB at ${n.maxInstances} instances \u2014 the maximum is ~${Math.round(qr/1e3)}KB; lower maxInstances, shorten text limits, or trim the template`}return null}function $s(e){let t=new Set;for(let r of e)for(let i of r.blocks)Q(i)&&t.add(i.id);let n=new Map;for(let r of e)for(let i of r.blocks)if(i.kind==="repeating_group")for(let o of i.fields)!t.has(o.id)&&!n.has(o.id)&&n.set(o.id,i.id);return n}function ks(e,t,n){for(let r of e)for(let i of r.blocks)for(let o of i.visibleIf??[]){let s=n.get(o.fieldId);if(s!==void 0)return`Field ${i.id}'s visibleIf references "${o.fieldId}", which is a child of repeating group ${s} \u2014 fields outside a repeating group can't reference its children`}for(let r of t)if(Array.isArray(r.next))for(let i of r.next){if(!i||typeof i!="object")continue;let o=i.when;if(Array.isArray(o))for(let s of o){if(!s||typeof s!="object")continue;let a=s.fieldId;if(typeof a!="string")continue;let l=n.get(a);if(l!==void 0)return`A jump rule on page ${r.id} references "${a}", which is a child of repeating group ${l} \u2014 jumps can't reference a repeating group's children`}}return null}function ki(e){return{id:ae(e.id,128),visibleIf:An(e.visibleIf)}}function V(e,t){return{...ki(e),kind:t,label:ae(e.label,2e3,"Untitled field"),description:D(e.description,5e3),required:be(e.required),placeholder:D(e.placeholder,500)}}function Wr(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 Ss(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 zs(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 Es(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:Wr(t.redirectUrl),showProgress:be(t.showProgress),responseLimit:Ss(t.responseLimit),trust:zs(t.trust),notifyEmail:_t().check(X(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,sendReceipt:be(t.sendReceipt),saveProgress:be(t.saveProgress),draftAnswersVisible:be(t.draftAnswersVisible),resumeEmails:be(t.resumeEmails),resumeUrl:Wr(t.resumeUrl),draftDigest:be(t.draftDigest)}}function R(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Si(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=ki(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return R({...r,kind:n,text:ae(t.text,2e3,"Section")});case"paragraph":return R({...r,kind:n,text:ae(t.text,5e3)});case"divider":return R({...r,kind:n});case"short_text":case"email":case"url":return R({...V(t,n),maxLength:ce(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e3,2e3)});case"phone":{let i=D(t.defaultCountry,2)?.toUpperCase();return R({...V(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return R({...V(t,n),maxLength:ce(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e4,2e4)});case"number":return R({...V(t,n),min:ce(t.min),max:ce(t.max),decimals:ce(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:$t(t.prefix,100),suffix:$t(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=kt(t.options);return i.length===0?null:R({...V(t,n),options:i,allowOther:be(t.allowOther),shuffleOptions:be(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return R({...V(t,n),appearance:i})}case"signature":case"date":return R(V(t,n));case"rating":{let i=fe(t.max,1,10,5);return R({...V(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=fe(t.min,0,9,1),o=fe(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 R({...V(t,n),min:i,max:o,minLabel:D(t.minLabel,100),maxLabel:D(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=kt(t.options);return i.length<2?null:R({...V(t,n),options:i})}case"matrix":{let i=kt(t.rows),o=kt(t.columns);return i.length===0||o.length===0?null:R({...V(t,n),rows:i,columns:o})}case"hidden":return R({...V(t,n),required:!1,paramName:D(t.paramName,128),defaultValue:D(t.defaultValue,1e3)});case"calculated":return R({...V(t,n),required:!1,calc:t.calc,decimals:ce(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:$t(t.prefix,100),suffix:$t(t.suffix,100)});case"file_upload":return R({...V(t,n),maxFiles:fe(t.maxFiles,1,20,1),maxFileSizeMb:fe(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"repeating_group":{let o=(Array.isArray(t.fields)?t.fields:[]).slice(0,50).flatMap(s=>{let a=Si(s);return a&&Q(a)?[a]:[]});return R({...V(t,n),required:!1,fields:o,maxInstances:ce(t.maxInstances)??Number.NaN,minInstances:ce(t.minInstances),addLabel:D(t.addLabel,100),itemLabel:D(t.itemLabel,100)})}case"custom":return R({...V(t,n),component:ae(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function Le(e){let t=hs.safeParse(e);if(!t.success){let g=t.error.issues[0],v=g?.path.join(".");return{ok:!1,error:g?`${v?`${v}: `:""}${g.message}`:"Invalid schema"}}if(t.data.version>ms)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(g=>{let v=g.blocks.flatMap(z=>{let E=Si(z);return E?[E]:[]});return{id:ae(g.id,128),title:D(g.title,500),blocks:v,next:g.next}}),r=new Set(n.map(g=>g.id)),i=new Map;for(let g of n)for(let v of g.blocks){if(v.kind!=="calculated")continue;let z=new Set,E=ze(v.calc);if(E){let j=new Set,H=new Set;Ee(E,j,H);for(let ee of j)z.add(ee);for(let ee of H)z.add(ee)}i.set(v.id,z)}let o=new Set,s=n.map(g=>{for(let v of g.blocks)Q(v)&&o.add(v.id);return R({id:g.id,title:g.title,blocks:g.blocks,next:gs(g.next,r,g.id,new Set(o),i)})}),a=new Set,l=new Set;for(let g of s){if(!g.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(g.id))return{ok:!1,error:`Duplicate page id: ${g.id}`};a.add(g.id);for(let v of g.blocks){if(l.has(v.id))return{ok:!1,error:`Duplicate block id: ${v.id}`};if(l.add(v.id),v.kind==="number"&&v.min!==void 0&&v.max!==void 0&&v.min>v.max)return{ok:!1,error:`Field ${v.id} has min greater than max`};if(v.kind==="select"||v.kind==="multi_select"||v.kind==="dropdown"||v.kind==="ranking"){let z=Ct(v.options);if(z)return{ok:!1,error:`Duplicate option id in field ${v.id}: ${z}`}}else if(v.kind==="matrix"){let z=Ct(v.rows);if(z)return{ok:!1,error:`Duplicate matrix row id in field ${v.id}: ${z}`};let E=Ct(v.columns);if(E)return{ok:!1,error:`Duplicate matrix column id in field ${v.id}: ${E}`}}}}let c=xs(s);if(c)return{ok:!1,error:c};let u=$s(s),p=ks(s,n,u);if(p)return{ok:!1,error:p};let f=vs(s,u);if(f)return{ok:!1,error:f};let m=ys(s);if(m)return{ok:!1,error:m};if(s.every(g=>g.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let h={version:yn,title:ae(t.data.title,2e3),pages:s,settings:Es(t.data.settings)},b=D(t.data.description,5e3);return b&&(h.description=b),{ok:!0,schema:h}}function et(e,t){let n=D(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function Cn(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=R({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 As(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function Fn(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"repeating_group":{if(!Array.isArray(t))return String(t);let n=t;if(n.length===0)return"";let r=e.itemLabel??e.label,i=`${n.length} \xD7 ${r}`,o=e.fields[0];if(!o)return i;let s=n.map(a=>a&&typeof a=="object"&&!Array.isArray(a)?Fn(o,a[o.id]):"").filter(a=>a!=="");return s.length>0?`${i}: ${s.join(", ")}`:i}case"phone":{let{country:n,national:r,e164:i}=st(String(t));if(!i)return String(t);let o=ot(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 As(e)}}function Cs(e){return Math.max(0,Math.min(6,Math.round(e)))}function zi(e){switch(e){case"grouped-comma":return"en-US";case"grouped-dot":return"de-DE";case"grouped":case void 0:return}}function Ei(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:Cs(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 Ai(e,t){return t?e.split(t).join(""):e}function Kr(e,t){return t==="."?e:e.split(t).join(".")}function Fs(e,t,n){if(n!==t&&e.includes(n)){let o=e.lastIndexOf(n),s=Ai(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 In(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=Kr(o.replace(/\s/g,""),i):r==="."||r===","?o=Fs(o,r,i):o=Kr(Ai(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function lt(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 _n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Is=256-256%_n.length;function Jr(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<Is&&(n+=_n[o%_n.length])}}return n}var Ci=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}},St="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Ln(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+=St[r>>2],t+=St[(r&3)<<4|i>>4],t+=n+1<e.length?St[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?St[o&63]:"="}return t}var Ls=e=>Ln(new Ci().update(e).digest()),S=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 ne(e){return e instanceof Error&&e.name==="FilloError"}async function Xr(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 Yr(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var tt=3,nt=3e4,Ns=5*6e4,pe=10*6e4;function Qr(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 an(e,t=!1){let n=ne(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&ne(e)&&e.retryAfterSec!==void 0}function zt(e){return e>=500||e===429||e===408}function ei(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new S("Request timed out",0):e}function Ms(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 Ts(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==yn)throw new S(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${yn}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&Ms(wn,e.minSdkVersion)<0)throw new S(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${wn}.`,426)}function Et(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function Ps(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return Ln(new Uint8Array(n))}return Ls(e)}var Rs="https://fillo.so",ti={"X-Fillo-Client":`@usefillo/core@${wn}`},Nt=class{baseUrl;fetch;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":Rs,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",...ti,...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 ei(i)}if(!r.ok){let{message:i,code:o}=await Xr(r,`Request failed: ${r.status}`);throw new S(i,r.status,Yr(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return Ts(t),t}syncForm(e,t,n){if(!this.key)return Promise.reject(new S("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401));let r=Le(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:Cn(n)})}):Promise.reject(new S(`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",...ti},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(nt)})}catch(o){throw ei(o)}if(r.status===422)return{ok:!1,errors:(await r.json()).errors};if(!r.ok){let{message:o,code:s}=await Xr(r,`Submit failed: ${r.status}`);throw new S(o,r.status,Yr(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(ne(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(pe)){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,pe));if(c.formId!==e||c.fieldId!==n.fieldId||c.fileName!==r||c.size!==t.size||c.mime.trim().toLowerCase()!==i)throw new S("File does not match this upload session",400);o=c,o.token||=n.uploadToken}else{let c=Jr(24),u=Jr(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,pe)}),f=Date.now()+pe,m=250;for(;;)try{o=await p();break}catch(h){if(n.signal?.aborted||!an(h,!0))throw h;let b=f-Date.now();if(b<=0)throw h;await Qr(Math.min(m,b),n.signal),m=Math.min(m*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 S("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 S("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,pe)}),l;try{l=await a()}catch(c){if(n.signal?.aborted||!an(c))throw c;let u=Date.now()+pe,p=250;for(;;){let f=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,u-Date.now())));if(f.status==="complete"&&f.file)return f.file;if(f.status==="aborted")throw c;try{l=await a();break}catch(h){if(n.signal?.aborted||!an(h,!0))throw h}let m=u-Date.now();if(m<=0)throw c;await Qr(Math.min(p,m),n.signal),p=Math.min(p*2,5e3)}}if(!l.file)throw new S("Upload completed but no file was returned");return l.file}async boxUpload(e,t,n){let r=Et(t.size,n);r(0);let i={Authorization:`Bearer ${e.token}`};if(e.mode==="simple"){let f=new FormData;f.append("attributes",JSON.stringify({name:e.fileName,parent:{id:e.folderId}})),f.append("file",t,e.fileName);let m=await this.retry(n,async()=>{let b=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:f,signal:this.uploadSignal(n)});if(!b.ok&&zt(b.status))throw new S(`Box upload failed: ${b.status}`,b.status);return b});if(!m.ok)throw new S(`Box upload failed: ${m.status}`,m.status);let h=await m.json();return r(t.size),{providerFileId:h.entries?.[0]?.id}}if(e.size!==t.size)throw new S(`File size changed since the upload was requested (${t.size} vs ${e.size}).`,400);let o=await this.retry(n,async()=>{let f=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(!f.ok&&zt(f.status))throw new S(`Box session failed: ${f.status}`,f.status);return f});if(!o.ok)throw new S(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new Ci,l=[],c=0;for(;c<t.size;){n.signal?.throwIfAborted();let f=Math.min(c+s.part_size,t.size),m=new Uint8Array(await t.slice(c,f).arrayBuffer());a.update(m);let h=await Ps(m),b=await this.retry(n,async()=>{let g=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${h}`,"Content-Range":`bytes ${c}-${f-1}/${t.size}`},body:m,signal:this.uploadSignal(n)});if(!g.ok&&zt(g.status))throw new S(`Box part failed: ${g.status}`,g.status);return g});if(!b.ok)throw new S(`Box part failed: ${b.status}`,b.status);l.push((await b.json()).part),c=f,r(c)}let u=await this.retry(n,async()=>{let f=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:{...i,"Content-Type":"application/json",Digest:`sha=${Ln(a.digest())}`},body:JSON.stringify({parts:l}),signal:this.uploadSignal(n)});if(!f.ok&&zt(f.status))throw new S(`Box commit failed: ${f.status}`,f.status);return f});if(!u.ok)throw new S(`Box commit failed: ${u.status}`,u.status);return{providerFileId:(await u.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=Et(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 f=p.headers.get("Range")??p.headers.get("range"),m=f?.match(/bytes=0-(\d+)/);m?i=Number(m[1])+1:f==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,pe))).uploadedBytes;break}if(p.ok){i=n.size;break}throw new S(`Drive chunk failed: ${p.status}`,p.status)}catch(p){if(r.signal?.aborted||(u+=1,u>=tt))throw p;if(await new Promise(m=>setTimeout(m,500*2**u)),i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,pe))).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>=tt)throw new S("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 S("S3 upload session returned invalid progress",502);let r=Et(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 S("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,pe)});if(typeof u.uploadUrl!="string"||!u.uploadUrl)throw new S("S3 part URL was unavailable",502);c=u.uploadUrl;let p=await this.fetch(c,{method:"PUT",body:a,signal:this.uploadSignal(n,Ns)});if(!p.ok)throw new S(`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,pe));if(p.status==="aborted")throw new S("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 S("S3 upload session returned invalid progress",502);if(p.uploadedBytes>i){i=p.uploadedBytes,r(i);break}if(l+=1,l>=tt)throw u;await new Promise(f=>setTimeout(f,500*2**l))}}}}async s3PutUpload(e,t,n){let r=Et(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 S(`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 Ne(e={}){return new Nt(e)}function ln(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function ni(e,t){let n={};for(let r of ve(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=ln(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=ln(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=ln(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;case"repeating_group":break;default:n[r.id]=i}}return n}function Os(){if(!(typeof document>"u"||typeof window>"u"))try{let e=new URL(window.location.href);e.hash="";let t=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("hubspotutk="))?.slice(11),n={pageUri:e.href.slice(0,2048),pageName:document.title.trim().slice(0,200)||void 0,hubspotutk:t&&/^[a-f0-9]{32}$/i.test(t)?t:void 0};return Object.values(n).some(Boolean)?n:void 0}catch{return}}var Zs={id:"empty",blocks:[]},ri=!1,ii=!1;function Ds(){ii||(ii=!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 Us(){ri||(ri=!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 Fi=new Map;function Nn(){try{return globalThis.localStorage??null}catch{return null}}function Ii(e){return`fillo:submission:${e}`}function Mn(){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 Li(e,t,n,r){let i=Nn();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 Ni(e,t,n,r){e.set(n,r);let i=Nn();if(i)try{i.setItem(t,JSON.stringify(r))}catch{}}function Tn(e){return Li(Fi,Ii(e),e,t=>typeof t.key=="string")}function Mi(e,t){Ni(Fi,Ii(e),e,t)}function Bs(e){let t=Tn(e);if(t?.key)return t.key;let n={key:Mn()};return Mi(e,n),n.key}function js(e,t){let n=Tn(e);Mi(e,{key:n?.key??Mn(),submittedAt:new Date().toISOString(),responseId:t})}function xn(e,t,n){let r=fi(e.settings,n);return r===null?t:`${t}::${r}`}function oi(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!Tn(xn(e,t,n))?.submittedAt}var Pn=new Map;function Rn(e){return`fillo:draft:${e}`}function At(e){return Li(Pn,Rn(e),e,t=>{let n=t;return typeof n.id=="string"&&typeof n.token=="string"})}function cn(e,t){Ni(Pn,Rn(e),e,t)}function un(e){Pn.delete(e);let t=Nn();if(t)try{t.removeItem(Rn(e))}catch{}}function dn(e){return ne(e)&&(e.status===401||e.status===403||e.status===404)}var Vs=1500,Hs="Please complete the verification check, then submit.",Gs="That verification didn't go through. Please complete the check again and resubmit.";function Ti(e){return ne(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 qs(e,t){if(ne(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 Ti(e)}function Pi(e){let{onChange:t,onSubmitted:n}=e,r=Le(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",f=!1,m=!1;queueMicrotask(()=>{if(typeof location<"u"&&location.search){let $=Object.fromEntries(new URLSearchParams(location.search)),_=null;for(let[x,L]of Object.entries(ni(i,$)))l[x]===void 0&&(_=_??{...l},_[x]=L);_&&p==="idle"&&(l=Ze(i,_),A())}p==="idle"&&oi(i,o,l)&&(p="submitted",f=!0,A());let y=!1;if(i.settings.saveProgress&&o&&s&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let $=/fillo-draft=([^&]+)/.exec(location.hash),_=$?.[1]?decodeURIComponent($[1]):"",x=_.indexOf(".");if(x>0){y=!0;let L=_.slice(0,x),I=_.slice(x+1);s.getDraft(L,I,!0).then(N=>{cn(o,{id:L,token:N.token??I});try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(N=>{dn(N)&&(m=!0,A())}).finally(()=>oe())}}y||oe()});let h,b=new Set,g=new Set,v=Date.now(),z=Mn(),E=null,j=!1,H=!1,ee=!1,W="created",ue=!1,Z=null,U=null,ie=Promise.resolve(),K=!1,Ge=!1,Me=!1,k=!1;function le(){let y=i.pages.length,$=Math.min(u,Math.max(y-1,0)),_=i.pages[$]??Zs;return{data:l,errors:c,status:p,pageIndex:$,pageCount:y,page:_,blocks:xt(i,_,l),isFirstPage:$===0,isLastPage:bn(i,_.id,l),uploading:b.size>0,submitError:h,restoredSubmission:f,resumedDraft:H,editingPrevious:ee,duplicateSubmission:W==="duplicate",updatedSubmission:W==="updated",resumeLinkFailed:m}}let B=le();function A(){B=le();for(let y of g)y()}function Te(y,$){try{n?.(y,$)}catch(_){console.error("[fillo] onSubmitted handler threw:",_)}}function Pe(y){let $=i.pages[y];if(!$)return{};let _={};for(let x of xt(i,$,l)){if(!Q(x))continue;let L=Ft(x,l[x.id]);L&&(_[x.id]=L)}return _}function Ae(){return!!(i.settings.saveProgress&&s&&o&&!Ge)}function P(){let y=new Set;for(let $ of i.pages)for(let _ of $.blocks)Q(_)&&y.add(_.id);return y}function J(y){if(p!=="idle"||j)return;let $=P(),_=null;for(let[I,N]of Object.entries(y.data??{}))l[I]===void 0&&$.has(I)&&(_=_??{...l},_[I]=N);let x=typeof y.page=="number"&&Number.isFinite(y.page)?Math.max(0,Math.min(Math.floor(y.page),i.pages.length-1)):0,L=x>0&&u===0;!_&&!L||(_&&(l=Ze(i,_)),L&&(u=x),H=!0,A())}function oe(){if(p!=="idle")return;if(!Ae()){ye();return}let y=o,$=s,_=Z??At(y);if(_&&!Me){Me=!0,Z=_,$.getDraft(_.id,_.token).then(J).catch(x=>{dn(x)&&(un(y),Z=null)});return}!_&&!k&&a?.hash&&(k=!0,$.createDraft(y,{data:{},page:0,respondent:a}).then(x=>{if(!Z){if(Z={id:x.id,token:x.token},cn(y,Z),x.existing)return $.getDraft(x.id,x.token).then(J);ye()}}).catch(x=>{ne(x)&&x.status!==void 0&&x.status>=400&&x.status<500||(k=!1)}))}function ye(){if(ue||i.settings.responseLimit?.onRepeat!=="update"||!s||!o||!a?.hash||p!=="idle")return;ue=!0;let y=s,$=fi(i.settings,l)??void 0;y.fetchOwnResponse(o,a,$).then(_=>{!_||p!=="idle"||j||H||(J({data:_.data,page:0}),H&&(H=!1,ee=!0,A()))}).catch(()=>{})}function Ot(y=!1){if(U&&(clearTimeout(U),U=null),!Ae()||p!=="idle"||!K)return;let $=o,_=s;K=!1,ie=ie.then(async()=>{let x={data:l,page:Math.max(0,Math.min(u,i.pages.length-1))},L=Z??At($);try{if(L)try{await _.saveDraft(L.id,L.token,x,y?{keepalive:!0}:void 0),Z=L;return}catch(N){if(!dn(N))throw N;un($),Z=null}let I=await _.createDraft($,a?.hash?{...x,respondent:a}:x);Z={id:I.id,token:I.token},cn($,Z),I.existing&&(K=!0)}catch(I){ne(I)&&I.status!==void 0&&I.status>=400&&I.status<500&&I.status!==429?Ge=!0:K=!0}})}function so(){!Ae()||p!=="idle"||(K=!0,U&&clearTimeout(U),U=setTimeout(()=>{U=null,Ot()},Vs))}function Wn(){!Ae()||!j&&!Z||(K=!0,Ot())}function Kn(){U&&(clearTimeout(U),U=null),K=!1,o&&un(o),Z=null}function ao(y,$){!j&&s&&o&&(j=!0,s.startSession(o,i.pages.length).then(x=>E=x)),l=Ze(i,{...l,[y]:$}),t?.(l),h=void 0;let _=`${y}.`;(y in c||Object.keys(c).some(x=>x.startsWith(_)))&&(c=Object.fromEntries(Object.entries(c).filter(([x])=>x!==y&&!x.startsWith(_)))),A(),so()}function lo(y,$){$?(b.add(y),y in c&&(c=Object.fromEntries(Object.entries(c).filter(([_])=>_!==y)))):b.delete(y),A()}function Jn(y){if(y.length===0)return-1;let $=i.pages.length,_=Math.min(u,Math.max($-1,0)),x=i.pages[_]?.id,L=x===void 0?-1:y.indexOf(x);if(L>=0)return L;let I=0;for(let N=0;N<y.length;N++){let me=i.pages.findIndex(Zt=>Zt.id===y[N]);me>=0&&me<=_&&(I=N)}return I}function co(){let y=i.pages.length,$=Math.min(u,Math.max(y-1,0));if(!e.skipValidation){let me=Pe($);if(c=me,Object.keys(me).length>0){A();return}}let _=i.pages[$],x=Be(i,l),L=Jn(x);if((_?bn(i,_.id,l):!0)||L<0||L+1>=x.length){Xn();return}let N=i.pages.findIndex(me=>me.id===x[L+1]);u=N>=0?N:Math.min($+1,y-1),E&&s&&s.reportProgress(E,{furthestPage:u}),A(),Wn()}function uo(){c={};let y=Be(i,l),$=Jn(y);if($>0){let _=i.pages.findIndex(x=>x.id===y[$-1]);u=_>=0?_:Math.max(Math.min(u,i.pages.length-1)-1,0)}else if(y.length>0){let _=i.pages.findIndex(x=>x.id===y[0]);u=_>=0?_:0}A(),Wn()}async function Xn(){if(p==="submitting"||p==="submitted")return;let y=xi(i,l);if(!y.ok){let $=e.skipValidation&&!(s&&o),_=$?Object.fromEntries(Object.entries(y.errors).filter(([L])=>i.pages.every(I=>I.blocks.every(N=>!(Q(N)&&N.id===L&&N.kind==="file_upload"))))):y.errors;if($&&Object.keys(_).length===0){c={},p="submitted",A(),Te(void 0,l);return}c=_;let x=i.pages.findIndex(L=>xt(i,L,l).some(I=>I.id in _));x>=0&&(u=x),A();return}if(s&&e.resolveFormId){p="submitting",h=void 0,A();try{o=await e.resolveFormId()}catch($){throw p="idle",h=qs($,e.verboseResolutionErrors===!0),A(),$}}if(s&&o){let $=i.settings.responseLimit?.by==="browser"?Bs(xn(i,o,y.data)):void 0,_=$??z,x=i.settings.saveProgress?Z??At(o):null,L=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!L){p="idle",h=Hs,A();return}p="submitting",h=void 0,A();let I;try{I=await s.submit(o,y.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-v,surface:e.surface??"headless",attribution:Os(),submissionKey:_,draft:x?{id:x.id,token:x.token}:void 0,respondent:a,challengeToken:L})}catch(N){if(p="idle",ne(N)&&N.code==="challenge_failed"){h=Gs,e.onChallengeFailed?.(),A();return}throw h=Ti(N),A(),N}if(!I.ok){c=I.errors??{};let N=i.pages.findIndex(me=>xt(i,me,l).some(Zt=>Zt.id in c));N>=0?u=N:h="We couldn't submit \u2014 please review your answers.",p="idle",A();return}W=I.duplicate?"duplicate":I.updated?"updated":"created",E&&s.reportProgress(E,{completed:!0}),$&&js(xn(i,o,y.data),I.responseId),Kn(),p="submitted",A(),Te(I.responseId,y.data);return}if(e.skipValidation){p="submitted",A(),Te(void 0,y.data);return}s&&!o?Ds():Us(),p="error",A()}return{getState:()=>B,subscribe(y){return g.add(y),()=>{g.delete(y)}},setValue:ao,setUploading:lo,next:co,back:uo,submit:Xn,setContext(y){if("formId"in y&&(o=y.formId),"client"in y&&(s=y.client),"respondent"in y&&(a=y.respondent),y.form&&y.form!==i){let $=Le(y.form);if(!$.ok)throw new Error(`Invalid form schema: ${$.error}`);i=$.schema,l=Ze(i,l)}p==="idle"&&oi(i,o,l)&&(p="submitted",f=!0),oe(),A()},flushDraft(){Ot(!0)},resetDraft(){if(p==="submitting")return;let y=Z??(o?At(o):null);if(Kn(),y&&s&&s.deleteDraft(y.id,y.token).catch(()=>{}),l={...e.initialData??{}},typeof location<"u"&&location.search){let $=Object.fromEntries(new URLSearchParams(location.search));for(let[_,x]of Object.entries(ni(i,$)))l[_]===void 0&&(l[_]=x)}l=Ze(i,l),c={},u=0,h=void 0,H=!1,ee=!1,A()},destroy(){U&&(clearTimeout(U),U=null),g.clear()}}}function Ws(e){return Q(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function Ri(e){let t=e.filter(n=>Q(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!Ws(t[0])}function Oi(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||!bn(n.form,o.id,i))return!1;let s=gi(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:xi(n.form,i).ok}function Zi(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 Ks=Math.sqrt(1.05*.05)-.05,Js=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Xs=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function pn(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Ys(e){let t=e.trim(),n=null,r=Js.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=Xs.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*pn(i)+.7152*pn(o)+.0722*pn(s)}function Di(e){if(!e||e.colorScheme||!e.background||!e.text)return e;let t=Ys(e.background);return t==null?e:{...e,colorScheme:t>Ks?"light":"dark"}}function On(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 Zn(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var Se=new Map,Qs=e=>new Promise(t=>setTimeout(t,e));function ea(e){if(!ne(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function ta(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(!ea(i)||r>=2)throw i;let o=ne(i)?i.retryAfterSec:void 0;await Qs(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function na(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 Ui(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 $n=e=>e==="published"?36e5:6e4,ra=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function Bi(e,t){return`fillo:sync:v4:${e.baseUrl}|${e.key}|${t}`}function ia(e,t,n){try{let r=globalThis.localStorage?.getItem(Bi(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=$n(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function oa(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(Bi(e,t),JSON.stringify({formId:r.formId,slug:r.slug,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function Dn(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=na(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=ve(t.schema).some(u=>u.kind==="file_upload"),a=Se.get(o);if(a&&!n?.bypassCache){if(a.expiresAt===null||!s&&a.expiresAt>Date.now())return a.promise;Se.delete(o)}if(!n?.bypassCache&&!s){let u=ia(e,t.id,i);if(u){let p=Promise.resolve({formId:u.formId,slug:u.slug,status:u.status,uploadFileSizeLimitMb:u.uploadFileSizeLimitMb});return Se.set(o,{promise:p,expiresAt:u.ts+$n(u.status)}),p}}let l=ta(e,t),c={promise:l,expiresAt:null};return Se.set(o,c),l.then(u=>{if(Se.get(o)===c){if(s||ra(u)){Se.delete(o);return}c.expiresAt=Date.now()+$n(u.status),oa(e,t.id,i,u)}},()=>{Se.get(o)===c&&Se.delete(o)}),l}var sa=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},aa=Symbol.for("fillo.block");var la=["label","description","required","placeholder"],O=(e,t,n,r={})=>({name:e,kind:t,props:[...la,...n],...r}),si=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),fn=["options","allowOther","shuffleOptions"],ca=[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",fn,{optionChildren:!0}),O("MultiSelect","multi_select",fn,{optionChildren:!0}),O("Dropdown","dropdown",fn,{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("RepeatingGroup","repeating_group",["minInstances","maxInstances","addLabel","itemLabel"],{blockChildren:!0}),O("Custom","custom",["component","config"]),si("Heading","heading",!0),si("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],ua={name:"Page",kind:"__page",props:["title"]},da={name:"Option",kind:"__option",props:["label","icon"]};function hn(e){let t=()=>{throw new sa("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[aa]=e,t}var jd=Object.fromEntries([...ca.map(e=>[e.name,hn(e)]),["Page",hn(ua)],["Option",hn(da)]]);function pa(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 Un(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function ji(){if(Un())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&pa(e)}var fa=/\{\{\s*([\w-]+)\s*\}\}/g;function mn(e,t,n){if(!e.includes("{{"))return e;let r=ve(n);return e.replace(fa,(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 Vi(e,t,n){let r=i=>i===void 0?i:mn(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:mn(e.text,t,n)};case"divider":return e;default:return{...e,label:mn(e.label,t,n),description:r(e.description)}}}var ha="fillo-",ma=0,ht='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function ga(e){return e.matches(ht)?e:e.querySelector(ht)}function ba(e){return Array.from(e.querySelectorAll(ht)).find(n=>!n.closest(".fillo-group-instance-header"))??null}function to(e,t){let n=`${ha}${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=Di(Cn(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 ft(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 va(e){let t=new URL(ft(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function Pt(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Hi(e,t,n){let r=Pt(e);if(r==="")return r;let i=Number(r);return Number.isFinite(i)?Ei(i,{locale:n,decimals:t}):r}function F(e,t){for(let n of t)n&&e.appendChild(n);return e}var Gi="http://www.w3.org/2000/svg",ya={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 no(e){if(!e)return null;let t=document.createElementNS(Gi,"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(Gi,"path");return n.setAttribute("d",ya[e]),t.appendChild(n),t}function q(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 ro(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=Zi(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 re(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&&!(e.kind==="repeating_group"&&(e.minInstances??1)>0)&&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 ct(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation!==void 0,o=zi(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?Hi(t.value,r?.decimals,o):Pt(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 c=a.value,u=a.value.length,p=()=>{a.value=c,a.setSelectionRange(u,u)};i?(a.addEventListener("input",()=>{if(!lt(a.value,o))return p();c=a.value,u=a.selectionStart??a.value.length,t.setValue(In(a.value,o),{render:!1})}),a.addEventListener("change",()=>{if(!lt(a.value,o))return p();c=a.value,t.setValue(In(a.value,o))}),a.addEventListener("blur",()=>{let f=t.getValue?.()??t.value;a.value=Hi(f,r?.decimals,o),c=a.value,u=a.value.length})):(a.addEventListener("input",()=>{if(!lt(a.value,o))return p();c=a.value,u=a.selectionStart??a.value.length,t.setValue(a.value,{render:!1})}),a.addEventListener("change",()=>{if(!lt(a.value,o))return p();c=a.value,t.setValue(a.value)}))}else a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value));q(a,n,t.error,t.ids);let l=a;return r&&(r.prefix||r.suffix)&&(l=F(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])),re(n,t.error,l,t.ids)}function wa(){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 _a(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function xa(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 $a(e){let t=e.field,n=st(Pt(e.value)).country??Lt(t.defaultCountry)??vi(_a())??Lt(wa())??it[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"});F(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),F(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"}});q(l,e.field,e.error,e.ids);let c=()=>e.getValue?.()??e.value,u=()=>{let k=he(Pt(c()));return k.startsWith(n.dialCode)?k.slice(n.dialCode.length):k},p=()=>{s.textContent=zn(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},f=()=>{l.value=ot(n,u()),l.placeholder=ot(n,n.example)},m=k=>e.setValue(k?yi(n,k):"",{render:!1}),h=k=>e.setValue(k,{render:!1});p(),f(),l.addEventListener("input",()=>{let k=l.value,le=l.selectionStart??k.length,B=he(k.slice(0,le)).length;if(k.trimStart().startsWith("+")){let A=st(k,n,{previousDigits:u()});if(A.pending){h(A.raw??k);return}A.country&&(n=A.country,p()),m(A.country?A.national:he(k))}else m(he(k));l.value=ot(n,u()),xa(l,B)});let b=e.registerOverlay,g=e.announce,v=null,z=0,E=je,j=null,H=null,ee,W=`${e.ids.inputId}-countries`,ue=()=>{if(!v)return;let k=wi(i,v);v.classList.toggle("fillo-phone-popover--above",k==="above"),v.classList.toggle("fillo-phone-popover--below",k==="below")},Z=()=>{j?.();let k=()=>ue();ue(),window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),j=()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},U=k=>{let le=k.relatedTarget;if(le){i.contains(le)||ie();return}queueMicrotask(()=>{v&&!i.contains(document.activeElement)&&ie()})},ie=()=>{clearTimeout(ee),j?.(),j=null,v?.remove(),v=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",K),i.removeEventListener("focusout",U),H?.(),H=null},K=k=>{i.contains(k.target)||ie()},Ge=k=>{k&&(n=k,p(),m(u()),f(),ie(),g?.(M.phoneCountrySelected(k.name)),l.focus())},Me=k=>{let le=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),B=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":W,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});k&&(B.value=k);let A=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:W,"aria-label":"Country"}}),Te=()=>{if(A.replaceChildren(),E.length===0){A.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),B.removeAttribute("aria-activedescendant"),ue();return}E.forEach((P,J)=>{let oe=d("li",{className:`fillo-phone-option${J===z?" fillo-phone-option--active":""}`,attrs:{id:`${W}-opt-${J}`,role:"option","aria-selected":String(P.iso2===n.iso2)}});F(oe,[d("span",{className:"fillo-phone-flag-emoji",text:zn(P.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:P.name}),d("span",{className:"fillo-phone-option-dial",text:`+${P.dialCode}`})]),oe.addEventListener("mouseenter",()=>{z=J,B.setAttribute("aria-activedescendant",oe.id),Pe()}),oe.addEventListener("mousedown",ye=>{ye.preventDefault(),Ge(P)}),A.appendChild(oe)}),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`),ue()},Pe=()=>{[...A.children].forEach((P,J)=>P.classList.toggle("fillo-phone-option--active",J===z)),document.getElementById(`${W}-opt-${z}`)?.scrollIntoView({block:"nearest"})},Ae=P=>{let J=P.trim().toLowerCase(),oe=J.replace(/[^\d]/g,"");E=J?je.filter(ye=>ye.name.toLowerCase().includes(J)||ye.iso2.toLowerCase()===J||oe.length>0&&ye.dialCode.startsWith(oe)):je,z=0,Te(),clearTimeout(ee),ee=setTimeout(()=>g?.(M.phoneResultsCount(E.length)),300)};B.addEventListener("input",()=>Ae(B.value)),B.addEventListener("keydown",P=>{if(P.key==="ArrowDown"){if(P.preventDefault(),E.length===0)return;z=Math.min(z+1,E.length-1),Pe(),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`)}else if(P.key==="ArrowUp"){if(P.preventDefault(),E.length===0)return;z=Math.max(z-1,0),Pe(),B.setAttribute("aria-activedescendant",`${W}-opt-${z}`)}else P.key==="Enter"?(P.preventDefault(),Ge(E[z])):P.key==="Escape"&&(P.preventDefault(),ie(),o.focus())}),F(le,[B,A]),v=le,i.appendChild(le),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",W),k?Ae(k):(E=je,z=Math.max(0,je.indexOf(n)),Te()),Z(),Pe(),document.addEventListener("mousedown",K),i.addEventListener("focusout",U),H=b?.(ie)??null,requestAnimationFrame(()=>{if(B.focus(),k){let P=B.value.length;B.setSelectionRange(P,P)}})};return o.addEventListener("click",()=>v?ie():Me()),o.addEventListener("keydown",k=>{if(!v){if(k.key==="ArrowDown"||k.key==="ArrowUp"){k.preventDefault(),Me();return}k.key.length===1&&k.key!==" "&&!k.ctrlKey&&!k.metaKey&&!k.altKey&&(k.preventDefault(),Me(k.key))}}),F(r,[i,l]),re(e.field,e.error,r,e.ids)}function ka(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)),q(t,e.field,e.error,e.ids),re(e.field,e.error,t,e.ids)}function Sa(e){let t=e.field,n=Gn(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"}});q(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)}),F(c,[u,no(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})}),F(l,[F(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 re(t,e.error,a,e.ids)}function za(e){let t=e.field,n=Gn(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"}});q(l,t,e.error,e.ids,{requiredSupported:!1});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 f=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});f.checked=r.includes(u.id),f.addEventListener("change",()=>{let m=a();c(f.checked?[...m,u.id]:m.filter(h=>h!==u.id))}),F(p,[f,no(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 f=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(f.checked=u,f.addEventListener("change",()=>{let m=a().filter(h=>i.has(h));f.checked?(s?.add(t.id),c(m)):(s?.delete(t.id),c(m))}),F(p,[F(d("span",{className:"fillo-option-main"}),[f,d("span",{className:"fillo-option-label",text:T.other,attrs:{"data-fillo":"optionLabel"}})])]),u){let m=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":T.otherPrompt}});m.value=o??"",m.placeholder=T.otherPlaceholder,m.addEventListener("input",()=>{s?.add(t.id);let h=a().filter(b=>i.has(b));e.setValue(m.value?[...h,m.value]:h,{render:!1})}),m.addEventListener("change",()=>{s?.add(t.id);let h=a().filter(b=>i.has(b));e.setValue(m.value?[...h,m.value]:h)}),p.appendChild(m),o===void 0&&queueMicrotask(()=>m.focus())}l.appendChild(p)}return re(t,e.error,l,e.ids)}function Ea(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function Aa(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=Ea(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 Gn(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))}),q(c,t,e.error,e.ids),F(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 re(t,e.error,a,e.ids)}function Ca(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)}),q(c,e.field,e.error,e.ids),F(s,[l,c,F(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)),q(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)"})),F(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"}});q(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 ro(s,r,i,a=>e.setValue(a)),re(e.field,e.error,s,e.ids)}function Ia(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,f)=>t+f),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"}});q(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,f]of i.entries()){let m=d("button",{className:`fillo-scale-step${e.value===f?" fillo-scale-step--active":""}`,text:String(f),attrs:{type:"button",role:"radio","aria-label":String(f),"aria-checked":String(e.value===f),tabindex:String(p===o?0:-1),"data-fillo":"option"}});m.toggleAttribute("data-selected",e.value===f),m.addEventListener("click",h=>{h.detail===0&&e.value===f||e.setValue(e.value===f?null:f)}),c.appendChild(m)}return ro(c,i,r,p=>e.setValue(p)),l.appendChild(c),("minLabel"in e.field||"maxLabel"in e.field)&&F(l,[F(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}})])]),re(e.field,e.error,l,e.ids)}function La(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"}});q(o,e.field,e.error,e.ids,{requiredSupported:!1});let s=d("ol",{className:"fillo-ranking"});for(let[a,l]of i.entries()){let c=t.options.find(b=>b.id===l);if(!c)continue;let u=d("li",{className:"fillo-ranking-item"}),p=d("span",{className:"fillo-ranking-controls"}),f=b=>{let g=a+b;if(g<0||g>=i.length)return;let v=[...i];[v[a],v[g]]=[v[g],v[a]],e.setValue(v),n?.(M.rankingPosition(c.label,g+1,i.length))},m=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`}});m.toggleAttribute("disabled",a===0),m.addEventListener("click",()=>f(-1));let h=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`}});h.toggleAttribute("disabled",a===i.length-1),h.addEventListener("click",()=>f(1)),F(p,[m,h]),F(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),re(e.field,e.error,o,e.ids)}function Na(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 c=`${e.ids.inputId}-${l.id}`,u=n[l.id]!==void 0,p=!!e.error&&!!t.required&&!u,f=g=>`${e.ids.inputId}-${l.id}-${g.id}`,m=document.createElement("tr"),h=d("th",{attrs:{scope:"row"}}),b=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${c}`,"aria-owns":t.columns.map(f).join(" ")}});b.appendChild(d("span",{text:l.label,attrs:{id:c}})),h.appendChild(b),m.appendChild(h);for(let g of t.columns){let v=d("td",{attrs:{"data-label":g.label}}),z=d("label",{className:"fillo-matrix-cell"}),E=d("input",{className:"fillo-option-input",attrs:{id:f(g),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${g.label}`}});t.required&&E.setAttribute("aria-required","true"),p&&E.setAttribute("aria-invalid","true"),E.checked=n[l.id]===g.id,E.addEventListener("change",()=>e.setValue({...n,[l.id]:g.id})),z.appendChild(E),v.appendChild(z),m.appendChild(v)}s.appendChild(m)}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 q(a,e.field,e.error,e.ids,{requiredSupported:!1}),a.appendChild(r),re(e.field,e.error,a,e.ids)}function Ma(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?M.signatureSigned:M.signatureEmpty)};if(c(),l&&s){let g=new Image;g.onload=()=>s.drawImage(g,0,0,r.width,r.height),g.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"}});q(u,e.field,e.error,e.ids);let p=g=>{s&&(s.clearRect(0,0,r.width,r.height),g.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(g,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 f=g=>{let v=r.getBoundingClientRect();return{x:(g.clientX-v.left)/v.width*r.width,y:(g.clientY-v.top)/v.height*r.height}};r.addEventListener("pointerdown",g=>{if(!s)return;a=!0,l=!0,o.style.display="none",c(),u.value&&(u.value=""),r.setPointerCapture(g.pointerId);let v=f(g);s.beginPath(),s.moveTo(v.x,v.y)}),r.addEventListener("pointermove",g=>{if(!a||!s)return;let v=f(g);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(v.x,v.y),s.stroke()});let m=()=>{a&&(a=!1,l&&e.setValue(r.toDataURL("image/png"),{render:!1}))};r.addEventListener("pointerup",m),r.addEventListener("pointercancel",m),i.addEventListener("click",()=>{s?.clearRect(0,0,r.width,r.height),l=!1,o.style.display="",u.value="",c(),e.setValue(null,{render:!1})}),F(n,[r,o,i]);let h=d("div",{className:"fillo-signature-type"}),b=d("label",{className:"fillo-signature-type-label",text:"Or type your full name to sign",attrs:{for:e.ids.inputId}});return F(h,[b,u]),F(t,[n,h]),re(e.field,e.error,t,e.ids)}function qi(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 Tt(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 Wi(e){let t=d("span",{className:`fillo-file-state fillo-file-state--${e}`,attrs:{"aria-hidden":"true"}});return t.appendChild(Tt(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 Bn(){let e=Tt(["m7 7 10 10M17 7 7 17"],16);return e.setAttribute("class","fillo-file-action-icon"),e}function Mt(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 Ta(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??[],c=o-a.length-l.filter(f=>f.error===void 0).length,u=d("div");if(c>0){let f=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file",hidden:""}});o>1&&(f.multiple=!0),t.accept?.length&&(f.accept=t.accept.join(",")),f.disabled=!i,f.addEventListener("change",()=>{if(!i)return;let h=Array.from(f.files??[]);f.value="",e.uploadFiles?.(t,h)});let m=d("div",{className:`fillo-dropzone${i?"":" fillo-dropzone--disabled"}`,attrs:{role:"button",tabindex:"0","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});if(q(m,t,e.error,e.ids,{requiredSupported:!1}),i||m.setAttribute("aria-disabled","true"),m.addEventListener("dragover",h=>{h.preventDefault(),m.classList.add("fillo-dropzone--over"),m.setAttribute("data-drag-over","")}),m.addEventListener("dragleave",()=>{m.classList.remove("fillo-dropzone--over"),m.removeAttribute("data-drag-over")}),m.addEventListener("drop",h=>{h.preventDefault(),m.classList.remove("fillo-dropzone--over"),m.removeAttribute("data-drag-over"),i&&e.uploadFiles?.(t,Array.from(h.dataTransfer?.files??[]))}),m.addEventListener("click",()=>{i&&f.click()}),m.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),i&&f.click())}),m.appendChild(f),i)F(m,[d("span",{className:"fillo-dropzone-title",text:M.dropzoneTitle(o>1)}),d("span",{className:"fillo-dropzone-hint",text:M.dropzoneHint(s)})]);else if(r==="render_only")m.appendChild(d("span",{className:"fillo-dropzone-hint",text:M.uploadsRenderOnly}));else if(n.storageFixUrl){let h=d("span",{className:"fillo-dropzone-hint",text:"Connect file storage to enable uploads"});h.append(" \u2014 "),h.appendChild(d("a",{text:n.storageFixUrl,attrs:{href:n.storageFixUrl,target:"_blank",rel:"noopener noreferrer"}})),m.appendChild(h)}else m.appendChild(d("span",{className:"fillo-dropzone-hint",text:M.uploadsUnavailable}));u.appendChild(m)}if(a.length>0||l.length>0){let f=d("ul",{className:"fillo-files"});for(let m of a){let h=d("li",{className:"fillo-file fillo-file--done"}),b=d("span",{className:"fillo-file-content"});F(b,[d("span",{className:"fillo-file-name",text:m.name}),d("span",{className:"fillo-file-meta",text:M.uploadedFile(qi(m.size))})]);let g=d("span",{className:"fillo-file-actions"});g.appendChild(Mt("fillo-file-remove",`${M.uploadRemove} ${m.name}`,Bn(),()=>e.setValue(a.filter(v=>v.fileId!==m.fileId)))),F(h,[Wi("done"),b,g]),f.appendChild(h)}for(let m of l){let h=m.error!==void 0,b=d("li",{className:`fillo-file${h?" fillo-file--failed":""}`});b.appendChild(Wi(h?"failed":"uploading"));let g=d("span",{className:"fillo-file-content"});if(g.appendChild(d("span",{className:"fillo-file-name",text:m.name})),h){let v=d("span",{className:"fillo-file-actions"});g.appendChild(d("span",{className:"fillo-file-error",text:m.error??""})),b.appendChild(g),!m.tooLarge&&c>0&&v.appendChild(Mt("fillo-file-retry",`${M.uploadRetry} ${m.name}`,M.uploadRetry,()=>n.uploadAction?.(m.key,"retry"))),v.appendChild(Mt("fillo-file-remove",`${M.uploadDismiss} ${m.name}`,Bn(),()=>n.uploadAction?.(m.key,"dismiss"))),b.appendChild(v)}else{let v=d("span",{className:"fillo-progress-bar"});v.style.width=`${m.fraction*100}%`,g.appendChild(d("span",{className:"fillo-file-meta",text:M.uploadingFile(Math.round(m.fraction*100),qi(m.size))}));let z=d("span",{className:"fillo-file-actions"});z.appendChild(Mt("fillo-file-remove",`${M.uploadCancel} ${m.name}`,Bn(),()=>n.uploadAction?.(m.key,"cancel"))),F(b,[g,z,F(d("span",{className:"fillo-progress",attrs:{role:"progressbar","aria-label":`Uploading ${m.name}`,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(Math.round(m.fraction*100))}}),[v])])}f.appendChild(b)}u.appendChild(f)}let p=n.uploadNotice;return p&&u.appendChild(d("p",{className:"fillo-upload-notice",text:p})),re(t,e.error,u,e.ids)}function Pa(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?Fn(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var Ki=new Map;function Gn(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=Ki.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]]}Ki.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}function ut(e){let t=e.getValue?.()??e.value;return Array.isArray(t)?t:[]}function Ra(e,t){return Math.max(t.length,e.minInstances??1)}function Oa(e){return Math.max(e.minInstances??1,0)}function jn(e,t){let n=[...e];for(;n.length<t;)n.push({});return n}function Za(e){let t=e.field;if(t.kind!=="repeating_group")return null;let n=e,r=n.announce,i=n.instanceId??"",o=t.itemLabel||t.label,s=ut(e),a=Ra(t,s),l=Oa(t),c=d("div",{className:"fillo-group",attrs:{id:e.ids.inputId,"data-fillo":"control"}});q(c,t,e.error,e.ids,{requiredSupported:!1});for(let f=0;f<a;f++){let m=s[f]??{},h=M.groupInstanceLabel(o,f+1,a),b=d("div",{className:"fillo-group-instance",attrs:{role:"group","aria-label":h,tabindex:"-1"}}),g=d("div",{className:"fillo-group-instance-header"}),v=d("button",{className:"fillo-group-remove",text:"\xD7",attrs:{type:"button","aria-label":M.groupRemoveLabel(o,f+1)}}),z=a>l;v.toggleAttribute("disabled",!z),z||(v.setAttribute("aria-disabled","true"),v.setAttribute("title",`At least ${l} ${l===1?"entry":"entries"} required`)),v.addEventListener("click",()=>{if(a<=l)return;let E=jn(ut(e),a);E.splice(f,1),e.setValue(E),n.setGroupFocus?.({groupId:t.id,cardIndex:f-1,intoControl:!1}),r?.(M.groupInstanceRemoved(o,E.length))}),F(g,[d("p",{className:"fillo-group-instance-title",text:h}),v]),b.appendChild(g);for(let E of Sn(t,m)){let j=`${t.id}.${f}.${E.id}`,H={...E,id:j},ee=to(i,j),W=(U,ie)=>{let K=jn(ut(e),a);K[f]={...K[f]??{},[E.id]:U},e.setValue(K,ie)},ue={field:H,value:m[E.id],error:e.api.errors[j],ids:ee,api:e.api,setValue:W,getValue:()=>ut(e)[f]?.[E.id],announce:n.announce,announceAlert:n.announceAlert,registerOverlay:n.registerOverlay,activeOtherFields:n.activeOtherFields},Z=n.renderChildField?.(ue)??io(ue);Z&&b.appendChild(Z)}c.appendChild(b)}let u=a>=t.maxInstances,p=d("button",{className:"fillo-group-add",text:t.addLabel||M.groupAdd,attrs:{type:"button"}});return p.toggleAttribute("disabled",u),u&&(p.setAttribute("aria-disabled","true"),p.setAttribute("title",`Maximum ${t.maxInstances} ${t.maxInstances===1?"entry":"entries"}`)),p.addEventListener("click",()=>{if(a>=t.maxInstances)return;let f=jn(ut(e),a);f.push({}),e.setValue(f),n.setGroupFocus?.({groupId:t.id,cardIndex:f.length-1,intoControl:!0}),r?.(M.groupInstanceAdded(o,f.length,f.length))}),c.appendChild(p),re(t,e.error,c,e.ids)}var Da={short_text:e=>ct("text",e),email:e=>ct("email",e),url:e=>ct("url",e),phone:$a,number:e=>ct("number",e),date:e=>ct("date",e),long_text:ka,select:Sa,multi_select:za,dropdown:Aa,checkbox:Ca,rating:Fa,linear_scale:Ia,ranking:La,matrix:Na,signature:Ma,file_upload:Ta,calculated:Pa,repeating_group:Za};function io(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=Da[e.field.kind];return t?t(e):null}var Ua="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",Ji="fillo-turnstile-script",dt=null;function He(){return globalThis.turnstile}function Ba(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):He()?Promise.resolve():dt||(dt=new Promise((e,t)=>{let n=()=>{He()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(Ji);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=Ji,i.src=Ua,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),dt=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),dt)}function Xi(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var mt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&Xa(),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${++ma}`;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=Xi();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||Ha()}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=Zn(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=Ne());let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await Dn(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 S("This form is no longer published. Submission was stopped before sending answers.",403,void 0,"form_not_published");if(o.accepting===!1)throw new S("This form is no longer accepting responses. Submission was stopped before sending answers.",403,void 0,o.acceptingReason??"form_not_accepting");let s=Le(o.resolvedSchema??t.schema);if(!s.ok)throw new S(`The canonical form schema was invalid: ${s.error}`,502,void 0,"invalid_sync_schema");if(this.schema&&!Ui(this.schema,s.schema))throw new S("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 S(o.syncError.message,403,void 0,o.syncError.code)),this.resolutionFailureCode=null,o.formId}catch(o){let s=pt(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(),eo();if(i&&!i.key&&!this.options.formId){this.reportSyncFailure(new S('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 Dn(i,t);if(this.destroyed)return;if((o.staged||o.syncError)&&!o.resolvedSchema)throw new S("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?Yi(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 S(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(pt(o))}return}let n=this.options.form&&!Zn(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(),eo();this.options.client??=Ne(),this.setSchema(n,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new S("Provide either `form`, or a `formId`.",0);this.options.client??=Ne(),this.render();let r=await this.options.client.getForm(this.options.formId);if(this.destroyed)return;if(r.accepting===!1?this.notOpenVariant=Yi(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 S(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(pt(t))}}setSchema(t,n,r){if(this.destroyed)return;let i=Le(t);if(!i.ok)throw new S(`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=Pi({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 c=this.engine.getState().status,u=this.engine.getState().resumedDraft,p=this.engine.getState().editingPrevious;this.engine.subscribe(()=>{let f=this.engine?.getState();f&&(f.status!==c||f.resumedDraft!==u||f.editingPrevious!==p)&&(f.editingPrevious&&!p?this.announce(T.editNotice):f.resumedDraft&&!u&&this.announce(T.resumeNotice),c=f.status,u=f.resumedDraft,p=f.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=Le(t);if(!i.ok)throw new S(`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(M.submittingAnnouncement),this.render();try{await t}catch(n){this.options.onError?.(pt(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 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=pt(s),l=a.status!==void 0&&a.status>=500?M.uploadUnavailable:a.message||M.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(h=>h.size<=c),p=s.filter(h=>h.size>c),f=n.length-s.length,m=s.length-u.length;if(f>0||m>0){let h=[];f>0&&h.push(`You can attach up to ${r} file${r===1?"":"s"}. ${f} ${f===1?"file was":"files were"} not added.`);let b=h.join(" ");b?this.uploadNotices.set(t.id,b):this.uploadNotices.delete(t.id),b&&this.announce(b)}else this.uploadNotices.delete(t.id);for(let h of p){let b=M.fileTooLarge(l),g=`${h.name}-${h.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;this.inFlight.set(g,{fieldId:t.id,name:h.name,size:h.size,fraction:0,error:b,tooLarge:!0,file:h,controller:new AbortController,maxFiles:r}),this.announceAlert(b)}if(u.length===0){this.queueRender();return}await Promise.all(u.map(h=>this.startUpload(t.id,h,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;Ba().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=Xi(),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(ht)).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(ht))[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&&ga(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}if(t){this.applyGroupFocus(t);return}n&&this.restoreFocus(n)}}applyGroupFocus(t){let n=Array.from(this.element.querySelectorAll("[data-field]")).find(o=>o.getAttribute("data-field")===t.groupId),r=n?Array.from(n.querySelectorAll(".fillo-group-instance")):[],i=t.cardIndex>=0?r[t.cardIndex]:void 0;if(i){(t.intoControl?ba(i)??i:i).focus();return}n?.querySelector(".fillo-group-add")?.focus()}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),F(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.":Qa(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(Vn(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)??Va(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(Vn(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let c=ft(this.schema.settings.redirectUrl);c&&typeof window<"u"?window.location.assign(c):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&F(this.element,Ya({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(Vn(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})),F(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 h=o;h.noValidate=!0,h.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 h=d("div",{className:"fillo-resume",attrs:{"data-fillo":"resume"}});h.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()),h.appendChild(b),a.appendChild(h)}if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let h=Be(t.form,t.data),b=Math.max(h.length,1),g=h.indexOf(t.page.id),v=g>=0?g+1:Math.min(t.pageIndex+1,b),z=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(v)}});z.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),z.firstElementChild?.style.setProperty("--fillo-progress-value",`${v/b*100}%`),a.appendChild(z)}if(t.pageIndex===0){let h=d("header",{className:"fillo-header",attrs:{"data-fillo":"header"}});t.form.title&&h.appendChild(d("h1",{className:"fillo-title",text:t.form.title,attrs:{"data-fillo":"title"}})),t.form.description&&h.appendChild(d("p",{className:"fillo-form-description",text:t.form.description,attrs:{"data-fillo":"description"}})),a.appendChild(h)}else t.page.title&&a.appendChild(d("h2",{className:"fillo-page-title",text:t.page.title,attrs:{"data-fillo":"pageTitle"}}));let c=d("div",{className:"fillo-blocks",attrs:{"data-fillo":"blocks"}});for(let h of t.blocks){let b=this.renderBlock(Vi(h,this.mutableData,t.form),t);b&&c.appendChild(b)}if(a.appendChild(c),!n){let h=d("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});h.style.position="absolute",h.style.left="-9999px",h.style.top="auto",h.style.width="1px",h.style.height="1px",h.style.opacity="0",h.style.overflow="hidden",h.style.pointerEvents="none",h.addEventListener("input",()=>{this.hpValue=h.value}),a.appendChild(h)}if(i){let h=d("div",{className:"fillo-turnstile-slot",attrs:{"data-fillo":"turnstile-slot"}});h.appendChild(this.turnstileContainer),this.challengeError&&h.appendChild(d("p",{className:"fillo-turnstile-error",attrs:{role:"alert"},text:T.challengeUnavailable})),a.appendChild(h),this.ensureTurnstileWidget(this.challenge.siteKey)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight)&&this.teardownTurnstileWidget();let u=t.status==="error"?"This form can't submit right now. Please try again in a moment.":this.engine?.getState().submitError;if(u){let h=d("p",{className:"fillo-submit-error",attrs:{role:"alert"},text:u}),b=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?ft(this.syncWarningUrl):null;b&&(h.append(" Connect storage: "),h.appendChild(d("a",{text:b,attrs:{href:b,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(h)}let f=!(t.form.settings.submitMode==="auto")||!t.isLastPage||Ri(hi(t.form,t.data))||i;if(f||t.pageCount>1&&!t.isFirstPage){let h=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()),h.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",g=>{g.preventDefault(),s()}),h.appendChild(b)}a.appendChild(h)}return o}fieldRenderer(t){return t.kind==="custom"?this.options.customComponents?.[t.component]??this.options.components?.custom:this.options.components?.[t.kind]??io}renderChildField=t=>this.fieldRenderer(t.field)?.(t)??null;setGroupFocus=t=>{this.focusIntent=t};renderBlock(t,n){if(!Q(t))return ja(t);let r=(o,s)=>{if(this.setValueInternal(t.id,o,s),s?.render===!1)return;let a={form:n.form,data:n.data,status:n.status,isLastPage:n.isLastPage,uploading:this.engine?.getState().uploading===!0};Oi(t,o,a)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id]===at?_i(t,M):n.errors[t.id],ids:to(this.instanceId,t.id),api:n,setValue:r,uploadFiles:(o,s)=>this.uploadFiles(o,s),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()?ft(this.syncWarningUrl):null,announce:this.announce,announceAlert:this.announceAlert,instanceId:this.instanceId,renderChildField:this.renderChildField,setGroupFocus:this.setGroupFocus};return this.fieldRenderer(t)?.(i)??null}};function ja(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 Va(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return F(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 Vn(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:va(t),target:"_blank",rel:"noopener noreferrer"}})}function Yi(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function Ha(){return ji()}function Ga(){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 qa(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 Wa(){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 Ka(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=ft(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 Ja(){return d("span",{className:"fillo-preview-badge",text:"Preview",attrs:{"data-fillo":"preview-badge"}})}var Qi=!1;function Xa(){Qi||Un()||(Qi=!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 Ya(e){let t=[];return e.preview&&t.push(Ja()),e.devNotices===!1||(e.syncError?t.push(qa(e.syncError)):e.staged?t.push(Wa()):e.draft?t.push(Ka(e.warningUrl)):e.noClient&&t.push(Ga())),t}function Qa(e){return e.status===404?T.loadFailedNotFound:e.status===0?T.loadFailedNetwork:e.status===422?T.renderFailed:T.loadFailed}function eo(){return new S("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 pt(e){return ne(e)?e:new S(e instanceof Error?e.message:String(e),0)}function Rt(e,t){let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new S(`Fillo mount target not found: ${String(e)}`,0);let r={...t,initialData:t.initialData??{}};return new mt(n,r)}function oo(e){let t=d("div");return Rt(t,e),t}var el=typeof HTMLElement<"u"?HTMLElement:class{},Hn=class extends el{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 mt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof mt&&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?Ne({key:t}):void 0);this.instance=Rt(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 qn(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,Hn)}typeof customElements<"u"&&qn();return bo(tl);})();
package/dist/styles.css CHANGED
@@ -831,20 +831,23 @@
831
831
  }
832
832
 
833
833
  /* ---------- Success ---------- */
834
- .fillo-success { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; text-align: center; padding: 1.4rem 1rem; }
834
+ .fillo-success { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.55rem; text-align: center; padding: 2rem 1rem; }
835
+ /* An affirming, filled mark: a solid primary disc with a contrast-colored
836
+ check — reads as "done and good", not a faint gray ring. Both tokens flip
837
+ per theme, so it stays legible on light and dark and honors the host's
838
+ --fillo-primary override. */
835
839
  .fillo-success-mark {
836
- width: 2.25rem; height: 2.25rem;
840
+ width: 2.5rem; height: 2.5rem;
837
841
  display: grid; place-items: center;
838
842
  border-radius: 999px;
839
- border: 1px solid color-mix(in srgb, var(--fillo-primary) 18%, transparent);
840
- background: color-mix(in srgb, var(--fillo-primary) 8%, transparent);
843
+ background: var(--fillo-primary);
841
844
  }
842
845
  .fillo-success-mark::before {
843
846
  content: "";
844
- width: 0.65rem; height: 0.35rem;
845
- border-left: 2px solid var(--fillo-primary);
846
- border-bottom: 2px solid var(--fillo-primary);
847
- transform: translateY(-0.08rem) rotate(-45deg);
847
+ width: 0.7rem; height: 0.38rem;
848
+ border-left: 2.5px solid var(--fillo-primary-contrast);
849
+ border-bottom: 2.5px solid var(--fillo-primary-contrast);
850
+ transform: translateY(-0.09rem) rotate(-45deg);
848
851
  }
849
852
  .fillo-success-title { margin: 0; font-size: 1.05rem; letter-spacing: 0; }
850
853
  .fillo-success-message { margin: 0; font-size: 0.875rem; color: var(--fillo-muted); }
@@ -831,20 +831,23 @@
831
831
  }
832
832
 
833
833
  /* ---------- Success ---------- */
834
- .fillo-success { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; text-align: center; padding: 1.4rem 1rem; }
834
+ .fillo-success { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.55rem; text-align: center; padding: 2rem 1rem; }
835
+ /* An affirming, filled mark: a solid primary disc with a contrast-colored
836
+ check — reads as "done and good", not a faint gray ring. Both tokens flip
837
+ per theme, so it stays legible on light and dark and honors the host's
838
+ --fillo-primary override. */
835
839
  .fillo-success-mark {
836
- width: 2.25rem; height: 2.25rem;
840
+ width: 2.5rem; height: 2.5rem;
837
841
  display: grid; place-items: center;
838
842
  border-radius: 999px;
839
- border: 1px solid color-mix(in srgb, var(--fillo-primary) 18%, transparent);
840
- background: color-mix(in srgb, var(--fillo-primary) 8%, transparent);
843
+ background: var(--fillo-primary);
841
844
  }
842
845
  .fillo-success-mark::before {
843
846
  content: "";
844
- width: 0.65rem; height: 0.35rem;
845
- border-left: 2px solid var(--fillo-primary);
846
- border-bottom: 2px solid var(--fillo-primary);
847
- transform: translateY(-0.08rem) rotate(-45deg);
847
+ width: 0.7rem; height: 0.38rem;
848
+ border-left: 2.5px solid var(--fillo-primary-contrast);
849
+ border-bottom: 2.5px solid var(--fillo-primary-contrast);
850
+ transform: translateY(-0.09rem) rotate(-45deg);
848
851
  }
849
852
  .fillo-success-title { margin: 0; font-size: 1.05rem; letter-spacing: 0; }
850
853
  .fillo-success-message { margin: 0; font-size: 0.875rem; color: var(--fillo-muted); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefillo/dom",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Framework-agnostic DOM renderer and web component for embedding Fillo forms.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@usefillo/core": "^0.13.0"
39
+ "@usefillo/core": "^0.14.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "axe-core": "^4.10.0",