@usefillo/dom 0.28.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2274,6 +2274,7 @@ var DomFormController = class {
2274
2274
  this.formId = renderOnly ? void 0 : formId;
2275
2275
  const displayOnly = this.notOpenVariant !== null;
2276
2276
  const transportDisabled = displayOnly || renderOnly;
2277
+ const renderer = this;
2277
2278
  this.engine = coreCreateFormController({
2278
2279
  form: normalizedSchema,
2279
2280
  formId: transportDisabled ? void 0 : formId,
@@ -2290,25 +2291,32 @@ var DomFormController = class {
2290
2291
  verboseResolutionErrors: this.devChrome(),
2291
2292
  respondent: transportDisabled ? void 0 : this.options.respondent,
2292
2293
  // Challenge (Turnstile) — wired as react's useFilloController wires the
2293
- // core controller: challengeRequired captured once here (forced off for
2294
- // a not-open preview, which never submits regardless);
2294
+ // core controller: async code-form sync can add a challenge after mount;
2295
2295
  // getChallengeToken/onChallengeFailed stay live via `this`.
2296
- challengeRequired: transportDisabled ? false : Boolean(this.challenge),
2296
+ get challengeRequired() {
2297
+ return !transportDisabled && Boolean(renderer.challenge);
2298
+ },
2297
2299
  getChallengeToken: () => this.challengeToken,
2298
2300
  onChallengeFailed: () => this.resetChallengeWidget()
2299
2301
  });
2300
2302
  let lastStatus = this.engine.getState().status;
2301
2303
  let lastResumed = this.engine.getState().resumedDraft;
2302
2304
  let lastEditing = this.engine.getState().editingPrevious;
2305
+ let lastErrors = this.engine.getState().errors;
2306
+ let lastResumeLinkFailed = this.engine.getState().resumeLinkFailed;
2303
2307
  this.engine.subscribe(() => {
2304
2308
  const state = this.engine?.getState();
2305
2309
  if (!state) return;
2306
- if (state.status !== lastStatus || state.resumedDraft !== lastResumed || state.editingPrevious !== lastEditing) {
2310
+ if (state.status !== lastStatus || state.resumedDraft !== lastResumed || state.editingPrevious !== lastEditing || state.errors !== lastErrors || state.resumeLinkFailed !== lastResumeLinkFailed) {
2307
2311
  if (state.editingPrevious && !lastEditing) this.announce(DEFAULT_STRINGS.editNotice);
2308
2312
  else if (state.resumedDraft && !lastResumed) this.announce(DEFAULT_STRINGS.resumeNotice);
2313
+ else if (state.resumeLinkFailed && !lastResumeLinkFailed)
2314
+ this.announce(DEFAULT_FIELD_STRINGS.resumeLinkExpired);
2309
2315
  lastStatus = state.status;
2310
2316
  lastResumed = state.resumedDraft;
2311
2317
  lastEditing = state.editingPrevious;
2318
+ lastErrors = state.errors;
2319
+ lastResumeLinkFailed = state.resumeLinkFailed;
2312
2320
  this.queueRender();
2313
2321
  }
2314
2322
  });
@@ -3192,6 +3200,14 @@ var DomFormController = class {
3192
3200
  clear.addEventListener("click", () => this.resetDraft());
3193
3201
  resume.appendChild(clear);
3194
3202
  content.appendChild(resume);
3203
+ } else if (restoreState?.resumeLinkFailed) {
3204
+ content.appendChild(
3205
+ el("div", {
3206
+ className: "fillo-resume fillo-resume--expired",
3207
+ attrs: { "data-fillo": "resume" },
3208
+ text: DEFAULT_FIELD_STRINGS.resumeLinkExpired
3209
+ })
3210
+ );
3195
3211
  }
3196
3212
  if (api.pageCount > 1 && this.schema?.settings.showProgress !== false) {
3197
3213
  const seq = reachablePageSequence(api.form, api.data);
@@ -1 +1 @@
1
- "use strict";var Fillo=(()=>{var Gt=Object.defineProperty;var Ro=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Zo=Object.prototype.hasOwnProperty;var Do=(e,t)=>{for(var n in t)Gt(e,n,{get:t[n],enumerable:!0})},Uo=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Oo(t))!Zo.call(e,i)&&i!==n&&Gt(e,i,{get:()=>t[i],enumerable:!(r=Ro(t,i))||r.enumerable});return e};var Bo=e=>Uo(Gt({},"__esModule",{value:!0}),e);var Ll={};Do(Ll,{FilloClient:()=>Rt,FilloError:()=>S,createClient:()=>be,createFormElement:()=>zo,defineForm:()=>Kn,registerFilloElement:()=>ir,renderForm:()=>Ut});var dr;function E(e,t,n){function r(a,l){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:l,constr:s,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,l);let c=s.prototype,u=Object.keys(c);for(let f=0;f<u.length;f++){let p=u[f];p in a||(a[p]=c[p].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 we=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(dr=globalThis).__zod_globalConfig??(dr.__zod_globalConfig={});var qt=globalThis.__zod_globalConfig;function xe(e){return e&&Object.assign(qt,e),qt}function fr(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 hr(e,t){return typeof t=="bigint"?t.toString():t}function mr(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Kt(e){return e==null}function gr(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var pr=Symbol("evaluating");function ke(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==pr)return r===void 0&&(r=pr,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var Jt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function wt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xt(e){if(wt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(wt(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Yt(e){return Xt(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var br=new Set(["string","number","symbol"]);function Ke(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 vr(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var jo={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 Je(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 yr(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 $e(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function yt(e){return typeof e=="string"?e:e?.message}function Se(e,t,n){let r=e.message?e.message:yt(e.inst?._zod.def?.error?.(e))??yt(t?.error?.(e))??yt(n.customError?.(e))??yt(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 en(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var wr=(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,hr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},_r=E("$ZodError",wr),Xe=E("$ZodError",wr,{Parent:Error});var Ho=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 we;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>Se(l,o,xe())));throw Jt(a,i?.callee),a}return s.value},_t=Ho(Xe),Go=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=>Se(l,o,xe())));throw Jt(a,i?.callee),a}return s.value},xt=Go(Xe),qo=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 we;return o.issues.length?{success:!1,error:new(e??_r)(o.issues.map(s=>Se(s,i,xe())))}:{success:!0,data:o.value}},Ye=qo(Xe),Wo=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=>Se(s,i,xe())))}:{success:!0,data:o.value}},Qe=Wo(Xe);var xr=/^(?!\.)(?!.*\.\.)([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])))",Jo=new RegExp(`^${Ko}$`);var kr=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var tn=/^-?\d+(?:\.\d+)?$/;var Ie=E("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Xo={number:"number",bigint:"bigint",object:"date"};var Sr=E("$ZodCheckGreaterThan",(e,t)=>{Ie.init(e,t);let n=Xo[typeof t.value];e._zod.onattach.push(r=>{let i=r._zod.bag,o=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>o&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}});var Ar=E("$ZodCheckMaxLength",(e,t)=>{var n;Ie.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Kt(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=en(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),Er=E("$ZodCheckMinLength",(e,t)=>{var n;Ie.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Kt(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=en(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var nn=E("$ZodCheckStringFormat",(e,t)=>{var n,r;Ie.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=()=>{})}),Fr=E("$ZodCheckRegex",(e,t)=>{nn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}});var Cr={major:4,minor:4,patch:3};var oe=E("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Cr;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=Je(s),u;for(let f of a){if(f._zod.def.when){if(yr(s)||!f._zod.def.when(s))continue}else if(c)continue;let p=s.issues.length,m=f._zod.check(s);if(m instanceof Promise&&l?.async===!1)throw new we;if(u||m instanceof Promise)u=(u??Promise.resolve()).then(async()=>{await m,s.issues.length!==p&&(c||(c=Je(s,p)))});else{if(s.issues.length===p)continue;c||(c=Je(s,p))}}return u?u.then(()=>s):s},o=(s,a,l)=>{if(Je(s))return s.aborted=!0,s;let c=i(a,r,l);if(c instanceof Promise){if(l.async===!1)throw new we;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 we;return l.then(c=>i(c,r,a))}return i(l,r,a)}}ke(e,"~standard",()=>({validate:i=>{try{let o=Ye(e,i);return o.success?{value:o.data}:{issues:o.error?.issues}}catch{return Qe(e,i).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}))}),rn=E("$ZodString",(e,t)=>{oe.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??kr(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}}),on=E("$ZodStringFormat",(e,t)=>{nn.init(e,t),rn.init(e,t)});var Lr=E("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=xr),on.init(e,t)});var Mr=E("$ZodNumber",(e,t)=>{oe.init(e,t),e._zod.pattern=e._zod.bag.pattern??tn,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 Pr=E("$ZodUnknown",(e,t)=>{oe.init(e,t),e._zod.parse=n=>n});function Ir(e,t,n){e.issues.length&&t.issues.push(...$e(n,e.issues)),t.value[n]=e.value}var Rr=E("$ZodArray",(e,t)=>{oe.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=>Ir(c,n,s))):Ir(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function kt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...$e(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 Qo(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=vr(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function es(e,t,n,r,i,o){let s=[],a=i.keySet,l=i.catchall._zod,c=l.def.type,u=l.optin==="optional",f=l.optout==="optional";for(let p in t){if(p==="__proto__"||a.has(p))continue;if(c==="never"){s.push(p);continue}let m=l.run({value:t[p],issues:[]},r);m instanceof Promise?e.push(m.then(h=>kt(h,n,p,t,u,f))):kt(m,n,p,t,u,f)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}var Or=E("$ZodObject",(e,t)=>{if(oe.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=mr(()=>Qo(t));ke(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 f of u.values)l[c].add(f)}}return l});let i=wt,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=[],f=s.shape;for(let p of s.keys){let m=f[p],h=m._zod.optin==="optional",v=m._zod.optout==="optional",b=m._zod.run({value:c[p],issues:[]},l);b instanceof Promise?u.push(b.then(g=>kt(g,a,p,c,h,v))):kt(b,a,p,c,h,v)}return o?es(u,c,a,l,r.value,e):u.length?Promise.all(u).then(()=>a):a}});var Zr=E("$ZodRecord",(e,t)=>{oe.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Xt(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=>Se(m,r,xe())),input:c,path:[c],inst:e});continue}let f=u.value,p=t.valueType._zod.run({value:i[c],issues:[]},r);p instanceof Promise?o.push(p.then(m=>{m.issues.length&&n.issues.push(...$e(c,m.issues)),n.value[f]=m.value})):(p.issues.length&&n.issues.push(...$e(c,p.issues)),n.value[f]=p.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"&&tn.test(a)&&l.issues.length){let f=t.keyType._zod.run({value:Number(a),issues:[]},r);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(l=f)}if(l.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(f=>Se(f,r,xe())),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(f=>{f.issues.length&&n.issues.push(...$e(a,f.issues)),n.value[l.value]=f.value})):(u.issues.length&&n.issues.push(...$e(a,u.issues)),n.value[l.value]=u.value)}}return o.length?Promise.all(o).then(()=>n):n}});var Dr=E("$ZodEnum",(e,t)=>{oe.init(e,t);let n=fr(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>br.has(typeof i)).map(i=>typeof i=="string"?Ke(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}}),Ur=E("$ZodLiteral",(e,t)=>{if(oe.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"?Ke(r):r?Ke(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 Tr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Br=E("$ZodOptional",(e,t)=>{oe.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ke(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ke(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${gr(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=>Tr(s,i)):Tr(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var jr=E("$ZodDefault",(e,t)=>{oe.init(e,t),e._zod.optin="optional",ke(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=>Nr(o,t)):Nr(i,t)}});function Nr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function Vr(e,t){return new e({type:"string",...G(t)})}function Hr(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Gr(e,t){return new e({type:"number",checks:[],...G(t)})}function qr(e){return new e({type:"unknown"})}function sn(e,t){return new Sr({check:"greater_than",...G(t),value:e,inclusive:!0})}function an(e){return sn(0,e)}function q(e,t){return new Ar({check:"max_length",...G(t),maximum:e})}function Te(e,t){return new Er({check:"min_length",...G(t),minimum:e})}function ln(e,t){return new Fr({check:"string_format",format:"regex",...G(t),pattern:e})}var de=E("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");oe.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>_t(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Ye(e,n,r),e.parseAsync=async(n,r)=>xt(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>Qe(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)}),Kr=E("ZodMiniString",(e,t)=>{rn.init(e,t),de.init(e,t)});function W(e){return Vr(Kr,e)}var ns=E("ZodMiniStringFormat",(e,t)=>{on.init(e,t),Kr.init(e,t)}),rs=E("ZodMiniEmail",(e,t)=>{Lr.init(e,t),ns.init(e,t)});function $t(e){return Hr(rs,e)}var is=E("ZodMiniNumber",(e,t)=>{Mr.init(e,t),de.init(e,t)});function Jr(e){return Gr(is,e)}var os=E("ZodMiniUnknown",(e,t)=>{Pr.init(e,t),de.init(e,t)});function et(){return qr(os)}var ss=E("ZodMiniArray",(e,t)=>{Rr.init(e,t),de.init(e,t)});function _e(e,t){return new ss({type:"array",element:e,...G(t)})}var Xr=E("ZodMiniObject",(e,t)=>{Or.init(e,t),de.init(e,t),ke(e,"shape",()=>t.shape)});function tt(e,t){let n={type:"object",shape:e??{},...G(t)};return new Xr(n)}function cn(e,t){return new Xr({type:"object",shape:e,catchall:et(),...G(t)})}var Wr=E("ZodMiniRecord",(e,t)=>{Zr.init(e,t),de.init(e,t)});function Yr(e,t,n){return!t||!t._zod?new Wr({type:"record",keyType:W(),valueType:e,...G(t)}):new Wr({type:"record",keyType:e,valueType:t,...G(n)})}var as=E("ZodMiniEnum",(e,t)=>{Dr.init(e,t),de.init(e,t),e.options=Object.values(t.entries)});function Qr(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new as({type:"enum",entries:n,...G(t)})}var ls=E("ZodMiniLiteral",(e,t)=>{Ur.init(e,t),de.init(e,t)});function ei(e,t){return new ls({type:"literal",values:Array.isArray(e)?e:[e],...G(t)})}var cs=E("ZodMiniOptional",(e,t)=>{Br.init(e,t),de.init(e,t)});function ee(e){return new cs({type:"optional",innerType:e})}var us=E("ZodMiniDefault",(e,t)=>{jr.init(e,t),de.init(e,t)});function un(e,t){return new us({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Yt(t)}})}var fs=200,hs=["heading","paragraph","divider"];function X(e){return!hs.includes(e.kind)}function Mt(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 ms(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 f=Si(u,c);if(f===void 0){s=!0;continue}a[l]=f,f!==c&&(s=!0)}return s?(r=!0,a):o});return r?i:t}function $i(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="repeating_group")return ms(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 Si(e,t){let n=$i(e,t);return Mt(n)?void 0:n}function Ai(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function Ei(e,t){let n=10**t,r=Math.round(Math.abs(e)*n)/n;return e<0?-r:r}function Le(e){return Number.isFinite(e)?e:null}function je(e,t){switch(e.op){case"value":return En(t(e.fieldId));case"const":return Le(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=je(r,t);if(i===null)return null;n.push(i)}return e.op==="add"?Le(n.reduce((r,i)=>r+i,0)):e.op==="mul"?Le(n.reduce((r,i)=>r*i,1)):e.op==="min"?Math.min(...n):Math.max(...n)}case"sub":case"div":{let n=je(e.left,t);if(n===null)return null;let r=je(e.right,t);return r===null?null:e.op==="sub"?Le(n-r):r===0?null:Le(n/r)}case"round":{let n=je(e.arg,t);return n===null?null:Le(Ei(n,Ai(e.decimals)))}case"if":return je(Pn(e.when,t)?e.then:e.else,t)}}function gs(e,t){let n=je(e.calc,t);return n===null||e.decimals===void 0?n:Le(Ei(n,Ai(e.decimals)))}function Ne(e,t){let n=ge(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=zn(e,r);for(let a=0;a<=n.length;a++){let l={},c=!1;for(let[u,f]of Object.entries(r))i.has(u)?l[u]=f:c=!0;if(!c)break;r=l,i=zn(e,r)}let o=it(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 dn(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 ti(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 En(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 bs(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return dn(n);case"not_answered":return!dn(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):ti(n,e.value);case"neq":return dn(n)?Array.isArray(n)?!n.some(r=>r===e.value):!ti(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=En(n),i=En(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function Pn(e,t){return e.length===0?!0:e.every(n=>bs(n,t))}function Fi(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:Pn(e.visibleIf,t)}function pn(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 it(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=Si(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=pn(o,t,n,s,i,c);for(let h of r){let v=s.has(h.id)?gs(h,m):null;v===null?delete c[h.id]:c[h.id]=v}}let u=pn(o,t,n,s,i,c),f=new Set;for(let m of e)Fi(m,u)&&f.add(m.id);let p=f.size===s.size&&[...f].every(m=>s.has(m))&&vs(a,c);if(s=f,a=c,p)break}return{visible:s,calc:a,calcIds:i,resolve:pn(o,t,n,s,i,a)}}function vs(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function zi(e,t){return it(e,t).visible}function St(e,t,n){let r=it(ge(e),n);return t.blocks.filter(i=>X(i)?r.visible.has(i.id):Fi(i,r.resolve))}function ge(e){return e.pages.flatMap(t=>t.blocks.filter(X))}function Ci(e,t){let n=e.responseLimit?.scopeField;if(!n)return null;let r=t[n];return typeof r=="number"?Number.isFinite(r)?String(r):null:typeof r!="string"?null:r.trim()||null}function Ii(e,t){let n=ge(e),r=zi(n,t);return n.filter(i=>r.has(i.id))}function Rn(e,t){let n=t&&typeof t=="object"&&!Array.isArray(t)?t:{},r=it(e.fields,n);return e.fields.filter(i=>r.visible.has(i.id))}function ys(e,t){return it(ge(e),t).resolve}function Ti(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=ys(e,n);for(let s of i)if(Pn(s.when,o))return s.to==="end"?{end:!0}:{to:s.to};return{linear:!0}}function Ve(e,t,n){let r=[];if(e.pages.length===0)return r;let i=new Set,o=n===void 0?0:e.pages.findIndex(s=>s.id===n);for(let s=0;s<=e.pages.length;s++){let a=e.pages[o];if(!a||i.has(a.id))break;i.add(a.id),r.push(a.id);let l=Ti(e,a.id,t);if("end"in l)break;if("to"in l){let c=e.pages.findIndex(u=>u.id===l.to);if(c<0)break;o=c}else if(o+=1,o>=e.pages.length)break}return r}function ws(e,t){return new Set(Ve(e,t))}function Fn(e,t,n){if("end"in Ti(e,t,n))return!0;let r=Ve(e,n);return r.length>0&&r[r.length-1]===t}function zn(e,t){let n=ws(e,t),r=zi(ge(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)X(s)&&r.has(s.id)&&i.add(s.id);return i}function Ni(e,t){let n=zn(e,t);return ge(e).filter(r=>n.has(r.id))}var Ue;function _s(){if(Ue!==void 0)return Ue??void 0;if(typeof Intl>"u"||typeof Intl.DisplayNames>"u"){Ue=null;return}try{Ue=new Intl.DisplayNames(void 0,{type:"region"})}catch{Ue=null}return Ue??void 0}function Li(e){try{return _s()?.of(e)??e}catch{return e}}var w=(e,t,n=[],r=[],i="")=>({iso2:e,name:Li(e),dialCode:t,lengths:n,groups:r,example:i}),xs=[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")],ks="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 $s(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:Li(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var ot=[...xs,...$s(ks)],He=Ss(ot);function Ss(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 As=new Map(ot.map(e=>[e.iso2,e])),Es={"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 On(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 Pt(e){return e?As.get(e.toUpperCase()):void 0}function Mi(e){return Pt(e?Es[e]:void 0)}function Fs(e){let t;for(let n of ot)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function me(e){return e.replace(/[^\d]/g,"")}function st(e,t){let n=me(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 Pi(e,t){let n=me(t);return n?`+${e.dialCode}${n}`:""}function at(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=me(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?me(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=Fs(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 zs(e){let{country:t,national:n,e164:r}=at(e);if(!r)return!1;let i=me(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var Cs=8;function Ri(e,t){if(!e||!t||typeof window>"u")return"below";let n=Cs,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)),f=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(f)}px`),t.style.setProperty("--fillo-phone-popover-offset-x","0px");let p=Math.min(t.offsetWidth,f),h=getComputedStyle(e).direction==="rtl"?o.right-p:o.left,v=0,b=h+p-(r-n);b>0&&(v-=b);let g=n-(h+v);return g>0&&(v+=g),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(v)}px`),l}var lt="This field is required",N={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. Check the link or ask the form owner for help.",loadFailedNetwork:"Couldn't reach the server \u2014 check your connection and try again.",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 and try again."},ni={submitFailed:N.submitFailed,loadFailedNotFound:N.loadFailedNotFound,loadFailedNetwork:N.loadFailedNetwork,formUnavailable:"This form is unavailable.",formClosed:N.closed,submitRateLimited:"Too many responses are being submitted right now. Wait a moment, then try again.",respondentUnrecognized:"This form couldn't verify who is responding. Ask the form owner for help.",fileUnavailable:"One of the uploaded files is no longer available. Remove it and upload it again.",scopeMissing:"We couldn't tell which entry this response belongs to. Answer the required field and try again.",challengeIncomplete:"Please complete the verification check, then submit.",challengeRetry:"That verification didn't go through. Please complete the check again and resubmit.",reviewAnswers:"We couldn't submit \u2014 please review your answers."};var Is={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 Ts(e){return Is[e.kind]??lt}var M={previewSkip:"Skip",required:lt,requiredForField:Ts,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 Oi(e,t){return t.requiredForField?.(e)??t.required}var Ns=tt({fileId:W().check(Te(1)),name:W(),size:Jr().check(an()),mime:W(),url:ee(W())});function fn(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 Lt(e,t){if(Mt(t))return e.kind==="calculated"?null:e.kind==="repeating_group"?fn(e,0):e.required?lt: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"||!zs(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 fn(e,0);let n=t;for(let r of n)if(!r||typeof r!="object"||Array.isArray(r))return"Invalid value";return fn(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=_e(Ns).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 Zi(e,t){let n=Ni(e,t),r={},i={};for(let o of n){if(o.kind==="calculated")continue;let s=$i(o,t[o.id]);if(o.kind==="repeating_group"){Ls(o,s,r,i);continue}let a=Lt(o,s);a?r[o.id]=a:Mt(s)||(i[o.id]=s)}return{ok:Object.keys(r).length===0,errors:r,data:i}}function Ls(e,t,n,r){let i=Lt(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 Rn(e,l)){let f=l[u.id],p=Lt(u,f);p?n[`${e.id}.${a}.${u.id}`]=p:Mt(f)||(c[u.id]=f)}s.push(c)}!i&&s.length>0&&(r[e.id]=s)}var Ms=["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"],Ps=["heading","paragraph","divider"],Rs=[...Ms,...Ps],Zn=W().check(Te(1),q(128)),hn=cn({id:Zn,label:W().check(q(1e3)),icon:ee(et())}),Os=cn({id:Zn,kind:Qr(Rs),label:ee(W().check(q(2e3))),options:ee(_e(hn).check(q(200))),rows:ee(_e(hn).check(q(200))),columns:ee(_e(hn).check(q(200)))}),Zs=tt({id:Zn,title:ee(W().check(q(500))),blocks:_e(Os).check(q(500)),next:ee(et())}),Ds=tt({version:ei(1),title:un(ee(W().check(q(2e3))),""),description:ee(W().check(q(5e3))),pages:_e(Zs).check(Te(1),q(50)),settings:un(ee(Yr(W(),et())),{})}),Us=1,Cn=1,In="0.28.0";function se(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function B(e,t){let n=se(e,t);return n===""?void 0:n}function At(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function he(e){return typeof e=="boolean"?e:void 0}function ae(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function fe(e,t,n,r){let i=ae(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function Et(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=se(r.id,128),o=se(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[P({id:i,label:o,icon:s})]:[]}):[]}function Nt(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function Dn(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=se(r.fieldId,128);if(!o)return[];let s=r.value,a=typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:void 0;return[{fieldId:o,op:i,...a!==void 0?{value:a}:{}}]});return t.length?t:void 0}function Di(e,t,n,r){let i=t.get(e);if(i===void 0)return n.has(e);if(r.has(e))return!0;r.add(e);for(let o of i)if(!Di(o,t,n,r))return!1;return!0}function Bs(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=Dn(c);return Array.isArray(c)&&c.length>0&&u===void 0?[]:u&&u.some(f=>!Di(f.fieldId,i,r,new Set))?[]:[{when:u??[],to:l}]});return o.length?o:void 0}var js=["number","rating","linear_scale","calculated"];function Ee(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=se(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=ae(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=Ee(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=Ee(n.left,t+1),i=Ee(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=Ee(n.arg,t+1);return r?P({op:"round",arg:r,decimals:ae(n.decimals)===void 0?void 0:fe(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=Dn(n.when)??[];if(r.length!==n.when.length)return null;let i=Ee(n.then,t+1),o=Ee(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function Fe(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)Fe(r,t,n);return;case"sub":case"div":Fe(e.left,t,n),Fe(e.right,t,n);return;case"round":Fe(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);Fe(e.then,t,n),Fe(e.else,t,n);return}}function Vs(e,t){let n=new Map;for(let s of e)for(let a of s.blocks)X(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=Ee(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;Fe(l,c,u);for(let f of c){let p=n.get(f);if(p===void 0){let m=t.get(f);return m!==void 0?`Calculated field ${a.id} references ${f}, 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: ${f} \u2014 remove the reference or restore that field`}if(!js.includes(p))return`Calculated field ${a.id} references non-numeric field ${f} (${p}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}r.set(a.id,[...c,...u].filter(f=>n.get(f)==="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 ri=100,ii=5e3;function Me(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+Me(n),0);case"sub":case"div":return 1+Me(e.left)+Me(e.right);case"round":return 1+Me(e.arg);case"if":return 1+Me(e.then)+Me(e.else)}}function Hs(e){let t=0,n=0;for(let r of e)for(let i of r.blocks)i.kind==="calculated"&&(t+=1,n+=Me(i.calc));return t>ri?`Form has ${t} calculated fields \u2014 the maximum is ${ri}; remove some or consolidate them into fewer expressions`:n>ii?`Calculated expressions total ${n} operations \u2014 the maximum is ${ii} across the form; simplify or split up the calculations`:null}var oi=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","date","rating","linear_scale"],si=12,ai=18e4;function Gs(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 qs(e){return e.fields.reduce((n,r)=>n+Gs(r),24)*(Number.isFinite(e.maxInstances)?e.maxInstances:0)}function Ws(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>si)return`Repeating group ${n.id} has ${n.fields.length} template fields \u2014 the maximum is ${si}; split it into fewer fields`;for(let a of n.fields)if(!oi.includes(a.kind))return`Repeating group ${n.id} has a "${a.kind}" child (${a.id}) \u2014 allowed child kinds are ${oi.join(", ")}`;let i=Nt(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=qs(n);if(s>ai)return`Repeating group ${n.id} could reach ~${Math.ceil(s/1e3)}KB at ${n.maxInstances} instances \u2014 the maximum is ~${Math.round(ai/1e3)}KB; lower maxInstances, shorten text limits, or trim the template`}return null}function Ks(e){let t=new Set;for(let r of e)for(let i of r.blocks)X(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 Js(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 Ui(e){return{id:se(e.id,128),visibleIf:Dn(e.visibleIf)}}function V(e,t){return{...Ui(e),kind:t,label:se(e.label,2e3,"Untitled field"),description:B(e.description,5e3),required:he(e.required),placeholder:B(e.placeholder,500)}}function li(e){let t=B(e,2e3);if(t)try{let n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"?t:void 0}catch{return}}function Xs(e){if(!e||typeof e!="object")return;let t=e,n=t.by==="browser"||t.by==="field"||t.by==="identify"||t.by==="email"?t.by:void 0;if(!n)return;let r=n==="field"?B(t.field,128):void 0;if(n==="field"&&!r)return;let i=B(t.scopeField,128),o=t.onRepeat==="update"&&(n==="identify"||n==="email")?"update":"keep";return{by:n,...r?{field:r}:{},...i?{scopeField:i}:{},onRepeat:o}}function Ys(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 Qs(e){let t=e&&typeof e=="object"?e:{};return{submitMode:t.submitMode==="button"||t.submitMode==="auto"?t.submitMode:void 0,submitLabel:B(t.submitLabel,100),successTitle:B(t.successTitle,200),successMessage:B(t.successMessage,5e3),redirectUrl:li(t.redirectUrl),showProgress:he(t.showProgress),responseLimit:Xs(t.responseLimit),trust:Ys(t.trust),notifyEmail:$t().check(q(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,notifyEmailIncludeAnswers:he(t.notifyEmailIncludeAnswers),notifyEmailAnswerFields:_e(W().check(Te(1),q(128),ln(/\S/))).check(q(500)).safeParse(t.notifyEmailAnswerFields).success?[...new Set(t.notifyEmailAnswerFields.map(r=>r.trim()))]:void 0,notifyEmailReplyToField:B(t.notifyEmailReplyToField,128),sendReceipt:he(t.sendReceipt),saveProgress:he(t.saveProgress),draftAnswersVisible:he(t.draftAnswersVisible),resumeEmails:he(t.resumeEmails),resumeUrl:li(t.resumeUrl),draftDigest:he(t.draftDigest)}}function P(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Bi(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=Ui(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return P({...r,kind:n,text:se(t.text,2e3,"Section")});case"paragraph":return P({...r,kind:n,text:se(t.text,5e3)});case"divider":return P({...r,kind:n});case"short_text":case"email":case"url":return P({...V(t,n),maxLength:ae(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e3,2e3)});case"phone":{let i=B(t.defaultCountry,2)?.toUpperCase();return P({...V(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return P({...V(t,n),maxLength:ae(t.maxLength)===void 0?void 0:fe(t.maxLength,1,2e4,2e4)});case"number":return P({...V(t,n),min:ae(t.min),max:ae(t.max),decimals:ae(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:At(t.prefix,100),suffix:At(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=Et(t.options);return i.length===0?null:P({...V(t,n),options:i,allowOther:he(t.allowOther),shuffleOptions:he(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return P({...V(t,n),appearance:i})}case"signature":return P(V(t,n));case"date":return P({...V(t,n),defaultToday:t.defaultToday===!0?!0:void 0});case"rating":{let i=fe(t.max,1,10,5);return P({...V(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=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 P({...V(t,n),min:i,max:o,minLabel:B(t.minLabel,100),maxLabel:B(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=Et(t.options);return i.length<2?null:P({...V(t,n),options:i})}case"matrix":{let i=Et(t.rows),o=Et(t.columns);return i.length===0||o.length===0?null:P({...V(t,n),rows:i,columns:o})}case"hidden":return P({...V(t,n),required:!1,paramName:B(t.paramName,128),defaultValue:B(t.defaultValue,1e3)});case"calculated":return P({...V(t,n),required:!1,calc:t.calc,decimals:ae(t.decimals)===void 0?void 0:fe(t.decimals,0,6,0),prefix:At(t.prefix,100),suffix:At(t.suffix,100)});case"file_upload":return P({...V(t,n),maxFiles:fe(t.maxFiles,1,fs,1),maxFileSizeMb:fe(t.maxFileSizeMb,1,5e3,500),accept:Array.isArray(t.accept)?t.accept.flatMap(i=>{let o=B(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=Bi(s);return a&&X(a)?[a]:[]});return P({...V(t,n),required:!1,fields:o,maxInstances:ae(t.maxInstances)??Number.NaN,minInstances:ae(t.minInstances),addLabel:B(t.addLabel,100),itemLabel:B(t.itemLabel,100)})}case"custom":return P({...V(t,n),component:se(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function ze(e){let t=Ds.safeParse(e);if(!t.success){let b=t.error.issues[0],g=b?.path.join(".");return{ok:!1,error:b?`${g?`${g}: `:""}${b.message}`:"Invalid schema"}}if(t.data.version>Us)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(b=>{let g=b.blocks.flatMap(A=>{let F=Bi(A);return F?[F]:[]});return{id:se(b.id,128),title:B(b.title,500),blocks:g,next:b.next}}),r=new Set(n.map(b=>b.id)),i=new Map;for(let b of n)for(let g of b.blocks){if(g.kind!=="calculated")continue;let A=new Set,F=Ee(g.calc);if(F){let R=new Set,re=new Set;Fe(F,R,re);for(let J of R)A.add(J);for(let J of re)A.add(J)}i.set(g.id,A)}let o=new Set,s=n.map(b=>{for(let g of b.blocks)X(g)&&o.add(g.id);return P({id:b.id,title:b.title,blocks:b.blocks,next:Bs(b.next,r,b.id,new Set(o),i)})}),a=new Set,l=new Set;for(let b of s){if(!b.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(b.id))return{ok:!1,error:`Duplicate page id: ${b.id}`};a.add(b.id);for(let g of b.blocks){if(l.has(g.id))return{ok:!1,error:`Duplicate block id: ${g.id}`};if(l.add(g.id),g.kind==="number"&&g.min!==void 0&&g.max!==void 0&&g.min>g.max)return{ok:!1,error:`Field ${g.id} has min greater than max`};if(g.kind==="select"||g.kind==="multi_select"||g.kind==="dropdown"||g.kind==="ranking"){let A=Nt(g.options);if(A)return{ok:!1,error:`Duplicate option id in field ${g.id}: ${A}`}}else if(g.kind==="matrix"){let A=Nt(g.rows);if(A)return{ok:!1,error:`Duplicate matrix row id in field ${g.id}: ${A}`};let F=Nt(g.columns);if(F)return{ok:!1,error:`Duplicate matrix column id in field ${g.id}: ${F}`}}}}let c=Ws(s);if(c)return{ok:!1,error:c};let u=Ks(s),f=Js(s,n,u);if(f)return{ok:!1,error:f};let p=Vs(s,u);if(p)return{ok:!1,error:p};let m=Hs(s);if(m)return{ok:!1,error:m};if(s.every(b=>b.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let h={version:Cn,title:se(t.data.title,2e3),pages:s,settings:Qs(t.data.settings)},v=B(t.data.description,5e3);return v&&(h.description=v),{ok:!0,schema:h}}function rt(e,t){let n=B(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function ea(e){return typeof e=="string"&&/^[A-Za-z0-9_-]{8,64}$/.test(e)?e:void 0}function ci(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=P({primary:rt(t.primary,200),background:rt(t.background,200),text:rt(t.text,200),logo:ea(t.logo)});return Object.keys(n).length>0?n:void 0}function ji(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e,n=t.colorScheme==="light"||t.colorScheme==="dark"||t.colorScheme==="auto"?t.colorScheme:void 0,r=P({colorScheme:n,...ci(t),radius:rt(t.radius,64),fontFamily:rt(t.fontFamily,200),dark:ci(t.dark)});return Object.keys(r).length>0?r:null}function ta(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function Un(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)?Un(o,a[o.id]):"").filter(a=>a!=="");return s.length>0?`${i}: ${s.join(", ")}`:i}case"phone":{let{country:n,national:r,e164:i}=at(String(t));if(!i)return String(t);let o=st(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 ta(e)}}function na(e){return Math.max(0,Math.min(6,Math.round(e)))}function Vi(e){switch(e){case"grouped-comma":return"en-US";case"grouped-dot":return"de-DE";case"grouped":case void 0:return}}function Hi(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:na(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 Gi(e,t){return t?e.split(t).join(""):e}function ui(e,t){return t==="."?e:e.split(t).join(".")}function ra(e,t,n){if(n!==t&&e.includes(n)){let o=e.lastIndexOf(n),s=Gi(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 Bn(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=ui(o.replace(/\s/g,""),i):r==="."||r===","?o=ra(o,r,i):o=ui(Gi(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function ct(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(f=>f.type==="group")?.value??",",s=i.find(f=>f.type==="decimal")?.value??".",a=o===".",l=/^\s$/.test(o),c=a?[s]:Array.from(new Set([".",s])),u=0;for(let f of r)if(!/\d/.test(f)){if(c.includes(f)){if(++u>1)return!1;continue}if(!(l?/\s/.test(f):f===o))return!1}return!0}var Tn="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",ia=256-256%Tn.length;function di(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<ia&&(n+=Tn[o%Tn.length])}}return n}var qi=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}},Ft="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function jn(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+=Ft[r>>2],t+=Ft[(r&3)<<4|i>>4],t+=n+1<e.length?Ft[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?Ft[o&63]:"="}return t}var oa=e=>jn(new qi().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 te(e){return e instanceof Error&&e.name==="FilloError"}async function pi(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 mn(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var nt=3,sa=4,Be=3e4,aa=5*6e4,pe=10*6e4;function fi(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 gn(e,t=!1){let n=te(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&te(e)&&e.retryAfterSec!==void 0}function zt(e){return e>=500||e===429||e===408}function hi(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new S("Request timed out",0):e}function la(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 ca(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==Cn)throw new S(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${Cn}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&la(In,e.minSdkVersion)<0)throw new S(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${In}.`,426)}function Ct(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function ua(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return jn(new Uint8Array(n))}return oa(e)}var da="https://fillo.so",bn={"X-Fillo-Client":`@usefillo/core@${In}`},Rt=class{baseUrl;fetch;activeUploads=0;uploadQueue=new Set;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":da,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",...bn,...t?.headers}:t?.headers,r;try{r=await this.fetch(this.url(e),{...t,headers:n,signal:t?.signal??AbortSignal.timeout(Be)})}catch(i){throw hi(i)}if(!r.ok){let{message:i,code:o}=await pi(r,`Request failed: ${r.status}`);throw new S(i,r.status,mn(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return ca(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=ze(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:ji(n)})}):Promise.reject(new S(`Invalid form schema: ${r.error}`,400))}async reportInvalidDefinition(e,t){try{let n="formId"in e?{formId:e.formId}:this.key?{key:this.key,id:e.handle}:null;if(!n)return null;let r=await this.fetch(this.url("/forms/definition-report"),{method:"POST",headers:{"Content-Type":"application/json",...bn},body:JSON.stringify({...n,schema:t}),signal:AbortSignal.timeout(Be)});if(!r.ok)return null;let i=await r.json();return typeof i.formId=="string"&&i.formId?i.formId:null}catch{return null}}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",...bn},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(Be)})}catch(o){throw hi(o)}if(r.status===422){let o=await r.json().catch(()=>null);if(o?.errors&&typeof o.errors=="object"&&!Array.isArray(o.errors))return{ok:!1,errors:o.errors};throw new S(typeof o?.error=="string"&&o.error?o.error:"Submit failed: 422",422,mn(r),typeof o?.code=="string"&&o.code?o.code:void 0)}if(!r.ok){let{message:o,code:s}=await pi(r,`Submit failed: ${r.status}`);throw new S(o,r.status,mn(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(te(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(Be)});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(Be)}).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){await this.acquireUploadSlot(n.signal);try{return n.signal?.throwIfAborted(),await this.performUpload(e,t,n)}finally{this.activeUploads-=1;let r=this.uploadQueue.values().next().value;r&&(this.uploadQueue.delete(r),r())}}async acquireUploadSlot(e){if(e?.throwIfAborted(),this.activeUploads<sa){this.activeUploads+=1;return}await new Promise((t,n)=>{let r=()=>{e?.removeEventListener("abort",i),this.activeUploads+=1,t()},i=()=>{this.uploadQueue.delete(r),n(e?.reason)};this.uploadQueue.add(r),e?.addEventListener("abort",i,{once:!0})})}async performUpload(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=di(24),u=di(32),f=()=>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)}),p=Date.now()+pe,m=250;for(;;)try{o=await f();break}catch(h){if(n.signal?.aborted||!gn(h,!0))throw h;let v=p-Date.now();if(v<=0)throw h;await fi(Math.min(m,v),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||!gn(c))throw c;let u=Date.now()+pe,f=250;for(;;){let p=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,u-Date.now())));if(p.status==="complete"&&p.file)return p.file;if(p.status==="aborted")throw c;try{l=await a();break}catch(h){if(n.signal?.aborted||!gn(h,!0))throw h}let m=u-Date.now();if(m<=0)throw c;await fi(Math.min(f,m),n.signal),f=Math.min(f*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=Ct(t.size,n);r(0);let i={Authorization:`Bearer ${e.token}`};if(e.mode==="simple"){let p=new FormData;p.append("attributes",JSON.stringify({name:e.fileName,parent:{id:e.folderId}})),p.append("file",t,e.fileName);let m=await this.retry(n,async()=>{let v=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:p,signal:this.uploadSignal(n)});if(!v.ok&&zt(v.status))throw new S(`Box upload failed: ${v.status}`,v.status);return v});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 p=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(!p.ok&&zt(p.status))throw new S(`Box session failed: ${p.status}`,p.status);return p});if(!o.ok)throw new S(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new qi,l=[],c=0;for(;c<t.size;){n.signal?.throwIfAborted();let p=Math.min(c+s.part_size,t.size),m=new Uint8Array(await t.slice(c,p).arrayBuffer());a.update(m);let h=await ua(m),v=await this.retry(n,async()=>{let b=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${h}`,"Content-Range":`bytes ${c}-${p-1}/${t.size}`},body:m,signal:this.uploadSignal(n)});if(!b.ok&&zt(b.status))throw new S(`Box part failed: ${b.status}`,b.status);return b});if(!v.ok)throw new S(`Box part failed: ${v.status}`,v.status);l.push((await v.json()).part),c=p,r(c)}let u=await this.retry(n,async()=>{let p=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:{...i,"Content-Type":"application/json",Digest:`sha=${jn(a.digest())}`},body:JSON.stringify({parts:l}),signal:this.uploadSignal(n)});if(!p.ok&&zt(p.status))throw new S(`Box commit failed: ${p.status}`,p.status);return p});if(!u.ok)throw new S(`Box commit failed: ${u.status}`,u.status);return{providerFileId:(await u.json()).entries?.[0]?.id}}uploadSignal(e,t=Be){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>=nt))throw r;await new Promise(i=>setTimeout(i,500*2**n))}}async driveUploadLoop(e,t,n,r){let i=e.uploadedBytes,o=Ct(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 f=await this.fetch(t,{method:"PUT",headers:{"Content-Range":`bytes ${i}-${l-1}/${n.size}`},body:c,signal:this.uploadSignal(r)});if(f.status===308){let p=f.headers.get("Range")??f.headers.get("range"),m=p?.match(/bytes=0-(\d+)/);m?i=Number(m[1])+1:p==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,pe))).uploadedBytes;break}if(f.ok){i=n.size;break}throw new S(`Drive chunk failed: ${f.status}`,f.status)}catch(f){if(r.signal?.aborted||(u+=1,u>=nt))throw f;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>=nt)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=Ct(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 f=await this.fetch(c,{method:"PUT",body:a,signal:this.uploadSignal(n,aa)});if(!f.ok)throw new S(`S3 part upload failed: ${f.status}`,f.status);i=s,r(i);break}catch(u){if(n.signal?.aborted)throw u;let f=await this.getUploadSession(e.id,e.token,this.uploadSignal(n,pe));if(f.status==="aborted")throw new S("This upload session was cancelled",409);if(!Number.isSafeInteger(f.uploadedBytes)||f.uploadedBytes<i||f.uploadedBytes>t.size||f.uploadedBytes<t.size&&f.uploadedBytes%e.chunkSize!==0)throw new S("S3 upload session returned invalid progress",502);if(f.uploadedBytes>i){i=f.uploadedBytes,r(i);break}if(l+=1,l>=nt)throw u;await new Promise(p=>setTimeout(p,500*2**l))}}}}async s3PutUpload(e,t,n){let r=Ct(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>=nt))throw o;await new Promise(s=>setTimeout(s,500*2**i))}}};function be(e={}){return new Rt(e)}function vn(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function pa(e=new Date){let t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${e.getFullYear()}-${t}-${n}`}function mi(e,t,n=new Date){let r=null;for(let i of ge(e))i.kind!=="date"||!i.defaultToday||t[i.id]!==void 0||(r=r??{...t},r[i.id]=pa(n));return r??t}function gi(e,t){let n={};for(let r of ge(e)){let i=r.kind==="hidden"?t[r.paramName??r.id]??r.defaultValue:t[r.id];if(!(i===void 0||i===""))switch(r.kind){case"number":{let o=vn(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=vn(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=vn(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 fa(){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 ha={id:"empty",blocks:[]},bi=!1,vi=!1;function ma(){vi||(vi=!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 project handle, or pass formId for a dashboard-built form: https://fillo.so/docs"))}function ga(){bi||(bi=!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 Wi=new Map;function Vn(){try{return globalThis.localStorage??null}catch{return null}}function Ki(e){return`fillo:submission:${e}`}function Hn(){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 Ji(e,t,n,r){let i=Vn();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 Xi(e,t,n,r){e.set(n,r);let i=Vn();if(i)try{i.setItem(t,JSON.stringify(r))}catch{}}function Gn(e){return Ji(Wi,Ki(e),e,t=>typeof t.key=="string")}function Yi(e,t){Xi(Wi,Ki(e),e,t)}function ba(e){let t=Gn(e);if(t?.key)return t.key;let n={key:Hn()};return Yi(e,n),n.key}function va(e,t){let n=Gn(e);Yi(e,{key:n?.key??Hn(),submittedAt:new Date().toISOString(),responseId:t})}function Nn(e,t,n){let r=Ci(e.settings,n);return r===null?t:`${t}::${r}`}function yi(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!Gn(Nn(e,t,n))?.submittedAt}var qn=new Map;function Wn(e){return`fillo:draft:${e}`}function It(e){return Ji(qn,Wn(e),e,t=>{let n=t;return typeof n.id=="string"&&typeof n.token=="string"})}function yn(e,t){Xi(qn,Wn(e),e,t)}function wn(e){qn.delete(e);let t=Vn();if(t)try{t.removeItem(Wn(e))}catch{}}function _n(e){return te(e)&&(e.status===401||e.status===403||e.status===404)}var ya=1500;function Qi(e,t){if(te(e)){let n=e.status??0;if(n===404)return t.loadFailedNotFound;switch(e.code){case"submit_rate_limited":return t.submitRateLimited;case"workspace_unavailable":case"provision_closed":return t.formClosed;case"respondent_unrecognized":return t.respondentUnrecognized;case"invalid_file_reference":return t.fileUnavailable;case"response_scope_missing":return t.scopeMissing}if(n>0)return t.submitFailed}return t.loadFailedNetwork}function wa(e,t,n){if(te(e)){let r=e.status??0;if(t&&r>0&&e.message)return e.code?`${e.message} (${e.code})`:e.message;if(r>0&&r<500&&r!==408&&r!==429)return n.formUnavailable;if(r>0)return n.submitFailed}return Qi(e,n)}function eo(e){let{onChange:t,onSubmitted:n}=e,r={...ni,...e.respondentErrorStrings},i=ze(e.form);if(!i.ok)throw new Error(`Invalid form schema: ${i.error}`);let o=i.schema,s=e.formId,a=e.client,l=e.respondent,c=Ne(o,{...e.initialData??{}}),u={},f=0,p,m=[];function h(){return e.previewNavigation===!0&&e.skipValidation===!0&&!a&&!s&&!e.resolveFormId}function v(){return Ve(o,c,h()?p:void 0)}function b(){h()&&m.push({pageIndex:f,startPageId:p})}let g="idle",A=!1,F=!1;queueMicrotask(()=>{if(typeof location<"u"&&location.search){let k=Object.fromEntries(new URLSearchParams(location.search)),x=null;for(let[C,I]of Object.entries(gi(o,k)))c[C]===void 0&&(x=x??{...c},x[C]=I);x&&g==="idle"&&(c=Ne(o,x),z())}let y=mi(o,c);y!==c&&g==="idle"&&(c=Ne(o,y),z()),g==="idle"&&yi(o,s,c)&&(g="submitted",A=!0,z());let $=!1;if(o.settings.saveProgress&&s&&a&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let k=/fillo-draft=([^&]+)/.exec(location.hash),x=k?.[1]?decodeURIComponent(k[1]):"",C=x.indexOf(".");if(C>0){$=!0;let I=x.slice(0,C),L=x.slice(C+1);a.getDraft(I,L,!0).then(Q=>{yn(s,{id:I,token:Q.token??L});try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(Q=>{_n(Q)&&(F=!0,z())}).finally(()=>jt())}}$||jt()});let R,re=new Set,J=new Set,ie=Date.now(),ve=Hn(),le=null,ce=!1,H=!1,ue=!1,Re="created",Oe=!1,_=null,Z=null,j=Promise.resolve(),U=!1,We=!1,Ce=!1,Ze=!1;function O(){let y=o.pages.length,$=Math.min(f,Math.max(y-1,0)),k=o.pages[$]??ha;return{data:c,errors:u,status:g,pageIndex:$,pageCount:y,page:k,blocks:St(o,k,c),isFirstPage:$===0,isLastPage:h()&&p!==void 0?v().at(-1)===k.id:Fn(o,k.id,c),uploading:re.size>0,submitError:R,restoredSubmission:A,resumedDraft:H,editingPrevious:ue,duplicateSubmission:Re==="duplicate",updatedSubmission:Re==="updated",resumeLinkFailed:F}}let Y=O();function z(){Y=O();for(let y of J)y()}function ye(y,$){try{n?.(y,$)}catch(k){console.error("[fillo] onSubmitted handler threw:",k)}}function or(y){let $=o.pages[y];if(!$)return{};let k={};for(let x of St(o,$,c)){if(!X(x)||h()&&x.kind==="file_upload")continue;let C=Lt(x,c[x.id]);C&&(k[x.id]=C)}return k}function vt(){return!!(o.settings.saveProgress&&a&&s&&!We)}function Co(){let y=new Set;for(let $ of o.pages)for(let k of $.blocks)X(k)&&y.add(k.id);return y}function Bt(y){if(g!=="idle"||ce)return;let $=Co(),k=null;for(let[I,L]of Object.entries(y.data??{}))c[I]===void 0&&$.has(I)&&(k=k??{...c},k[I]=L);let x=typeof y.page=="number"&&Number.isFinite(y.page)?Math.max(0,Math.min(Math.floor(y.page),o.pages.length-1)):0,C=x>0&&f===0;!k&&!C||(k&&(c=Ne(o,k)),C&&(f=x),H=!0,z())}function jt(){if(g!=="idle")return;if(!vt()){sr();return}let y=s,$=a,k=_??It(y);if(k&&!Ce){Ce=!0,_=k,$.getDraft(k.id,k.token).then(Bt).catch(x=>{_n(x)&&(wn(y),_=null)});return}!k&&!Ze&&l?.hash&&(Ze=!0,$.createDraft(y,{data:{},page:0,respondent:l}).then(x=>{if(!_){if(_={id:x.id,token:x.token},yn(y,_),x.existing)return $.getDraft(x.id,x.token).then(Bt);sr()}}).catch(x=>{te(x)&&x.status!==void 0&&x.status>=400&&x.status<500||(Ze=!1)}))}function sr(){if(Oe||o.settings.responseLimit?.onRepeat!=="update"||!a||!s||!l?.hash||g!=="idle")return;Oe=!0;let y=a,$=Ci(o.settings,c)??void 0;y.fetchOwnResponse(s,l,$).then(k=>{!k||g!=="idle"||ce||H||(Bt({data:k.data,page:0}),H&&(H=!1,ue=!0,z()))}).catch(()=>{})}function Vt(y=!1){if(Z&&(clearTimeout(Z),Z=null),!vt()||g!=="idle"||!U)return;let $=s,k=a;U=!1,j=j.then(async()=>{let x={data:c,page:Math.max(0,Math.min(f,o.pages.length-1))},C=_??It($);try{if(C)try{await k.saveDraft(C.id,C.token,x,y?{keepalive:!0}:void 0),_=C;return}catch(L){if(!_n(L))throw L;wn($),_=null}let I=await k.createDraft($,l?.hash?{...x,respondent:l}:x);_={id:I.id,token:I.token},yn($,_),I.existing&&(U=!0)}catch(I){te(I)&&I.status!==void 0&&I.status>=400&&I.status<500&&I.status!==429?We=!0:U=!0}})}function Io(){!vt()||g!=="idle"||(U=!0,Z&&clearTimeout(Z),Z=setTimeout(()=>{Z=null,Vt()},ya))}function ar(){!vt()||!ce&&!_||(U=!0,Vt())}function lr(){Z&&(clearTimeout(Z),Z=null),U=!1,s&&wn(s),_=null}function To(y,$){!ce&&a&&s&&(ce=!0,a.startSession(s,o.pages.length).then(x=>le=x)),c=Ne(o,{...c,[y]:$}),t?.(c),R=void 0;let k=`${y}.`;(y in u||Object.keys(u).some(x=>x.startsWith(k)))&&(u=Object.fromEntries(Object.entries(u).filter(([x])=>x!==y&&!x.startsWith(k)))),z(),Io()}function No(y,$){$?(re.add(y),y in u&&(u=Object.fromEntries(Object.entries(u).filter(([k])=>k!==y)))):re.delete(y),z()}function cr(y){if(y.length===0)return-1;let $=o.pages.length,k=Math.min(f,Math.max($-1,0)),x=o.pages[k]?.id,C=x===void 0?-1:y.indexOf(x);if(C>=0)return C;let I=0;for(let L=0;L<y.length;L++){let Q=o.pages.findIndex(Ht=>Ht.id===y[L]);Q>=0&&Q<=k&&(I=L)}return I}function Lo(){let y=o.pages.length,$=Math.min(f,Math.max(y-1,0));if(!e.skipValidation||e.previewNavigation===!0){let Q=or($);if(u=Q,Object.keys(Q).length>0){z();return}}let k=o.pages[$],x=v(),C=cr(x);if((h()&&p!==void 0?x.at(-1)===k?.id:k?Fn(o,k.id,c):!0)||C<0||C+1>=x.length){ur();return}let L=o.pages.findIndex(Q=>Q.id===x[C+1]);b(),f=L>=0?L:Math.min($+1,y-1),le&&a&&a.reportProgress(le,{furthestPage:f}),z(),ar()}function Mo(){u={};let y=h()?m.pop():void 0;if(y){f=Math.min(y.pageIndex,o.pages.length-1),p=y.startPageId,R=void 0,z();return}let $=Ve(o,c),k=cr($);if(k>0){let x=o.pages.findIndex(C=>C.id===$[k-1]);f=x>=0?x:Math.max(Math.min(f,o.pages.length-1)-1,0)}else if($.length>0){let x=o.pages.findIndex(C=>C.id===$[0]);f=x>=0?x:0}z(),ar()}function Po(){!h()||g==="submitting"||g==="submitted"||f>=o.pages.length-1||(b(),f+=1,p=o.pages[f]?.id,u={},R=void 0,z())}async function ur(){if(g==="submitting"||g==="submitted")return;if(h()&&(u=or(f),Object.keys(u).length>0)){z();return}let y=Zi(o,c);if(!y.ok){let $=e.skipValidation&&!(a&&s),k=$?Object.fromEntries(Object.entries(y.errors).filter(([C])=>o.pages.every(I=>I.blocks.every(L=>!(X(L)&&L.id===C&&L.kind==="file_upload"))))):y.errors;if($&&Object.keys(k).length===0){u={},g="submitted",z(),ye(void 0,c);return}u=k;let x=o.pages.findIndex(C=>St(o,C,c).some(I=>I.id in k));x>=0&&(f=x,p=void 0,m.length=0),z();return}if(a&&e.resolveFormId){g="submitting",R=void 0,z();try{s=await e.resolveFormId()}catch($){throw g="idle",R=wa($,e.verboseResolutionErrors===!0,r),z(),$}}if(a&&s){let $=o.settings.responseLimit?.by==="browser"?ba(Nn(o,s,y.data)):void 0,k=$??ve,x=o.settings.saveProgress?_??It(s):null,C=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!C){g="idle",R=r.challengeIncomplete,z();return}g="submitting",R=void 0,z();let I;try{I=await a.submit(s,y.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-ie,surface:e.surface??"headless",attribution:fa(),submissionKey:k,draft:x?{id:x.id,token:x.token}:void 0,respondent:l,challengeToken:C})}catch(L){if(g="idle",te(L)&&L.code==="challenge_failed"){R=r.challengeRetry,e.onChallengeFailed?.(),z();return}throw R=Qi(L,r),z(),L}if(!I.ok){u=I.errors??{};let L=o.pages.findIndex(Q=>St(o,Q,c).some(Ht=>Ht.id in u));L>=0?f=L:R=r.reviewAnswers,g="idle",z();return}Re=I.duplicate?"duplicate":I.updated?"updated":"created",le&&a.reportProgress(le,{completed:!0}),$&&va(Nn(o,s,y.data),I.responseId),lr(),g="submitted",z(),ye(I.responseId,y.data);return}if(e.skipValidation){g="submitted",z(),ye(void 0,y.data);return}a&&!s?ma():ga(),g="error",z()}return{getState:()=>Y,subscribe(y){return J.add(y),()=>{J.delete(y)}},setValue:To,setUploading:No,next:Lo,skipPreviewPage:Po,back:Mo,submit:ur,setContext(y){if("formId"in y&&(s=y.formId),"client"in y&&(a=y.client),"respondent"in y&&(l=y.respondent),y.respondentErrorStrings&&(r={...ni,...y.respondentErrorStrings}),y.form&&y.form!==o){let $=ze(y.form);if(!$.ok)throw new Error(`Invalid form schema: ${$.error}`);o=$.schema,c=Ne(o,c)}g==="idle"&&yi(o,s,c)&&(g="submitted",A=!0),jt(),z()},flushDraft(){Vt(!0)},resetDraft(){if(g==="submitting")return;let y=_??(s?It(s):null);if(lr(),y&&a&&a.deleteDraft(y.id,y.token).catch(()=>{}),c={...e.initialData??{}},typeof location<"u"&&location.search){let $=Object.fromEntries(new URLSearchParams(location.search));for(let[k,x]of Object.entries(gi(o,$)))c[k]===void 0&&(c[k]=x)}c=mi(o,c),c=Ne(o,c),u={},f=0,p=void 0,m.length=0,R=void 0,H=!1,ue=!1,z()},destroy(){Z&&(clearTimeout(Z),Z=null),J.clear()}}}function _a(e){return X(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function to(e){let t=e.filter(n=>X(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!_a(t[0])}function no(e,t,n){if(n.form.settings.submitMode!=="auto"||n.status!=="idle"||n.uploading||!(()=>{switch(e.kind){case"select":case"dropdown":return typeof t=="string"&&e.options.some(a=>a.id===t);case"checkbox":return t===!0;case"rating":case"linear_scale":return typeof t=="number";default:return!1}})()||t===n.data[e.id])return!1;let i={...n.data,[e.id]:t},o=n.form.pages.find(a=>a.blocks.some(l=>l.id===e.id));if(!o||!Fn(n.form,o.id,i))return!1;let s=Ni(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:Zi(n.form,i).ok}function ro(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 xa=Math.sqrt(1.05*.05)-.05,ka=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,$a=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function xn(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Ln(e){let t=e.trim(),n=null,r=ka.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=$a.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*xn(i)+.7152*xn(o)+.0722*xn(s)}function Sa(e){if(!e||e.colorScheme==="light"||e.colorScheme==="dark"||!e.background||io(e))return e;let t=Ln(e.background);return t==null?e:{...e,colorScheme:t>xa?"light":"dark"}}function io(e){if(!e||e.colorScheme==="light"||e.colorScheme==="dark")return!1;let t=e.dark;return!!(t&&(t.primary||t.background||t.text))}var Aa="#18181b";function kn(e){let t=Ln(e);if(t==null)return null;let n=1.05/(t+.05),r=(t+.05)/((Ln(Aa)??0)+.05);return n>=r?"light":"dark"}var Ea=[["primary","--fillo-primary"],["background","--fillo-bg"],["text","--fillo-text"]],Tt={light:{primary:"#18181b",background:"transparent",text:"#18181b"},dark:{primary:"#fafafa",background:"transparent",text:"#f4f4f5"}};function oo(e){let t=Sa(ji(e));if(!t)return null;let n={},r={};t.colorScheme&&(r["data-fillo-color-scheme"]=t.colorScheme);let i=io(t)?t.dark:void 0;for(let[o,s]of Ea){let a=t[o];if(!i){a&&(n[s]=a);continue}let l=i[o];!a&&!l||(n[s]=`light-dark(${a??Tt.light[o]}, ${l??Tt.dark[o]})`)}if(t.radius&&(n["--fillo-radius"]=t.radius),t.fontFamily&&(n["--fillo-font"]=t.fontFamily),i){let o=kn(t.primary??Tt.light.primary),s=kn(i.primary??Tt.dark.primary);o&&s&&(r["data-fillo-on-primary"]=o,r["data-fillo-on-primary-dark"]=s)}else if(t.primary){let o=kn(t.primary);o&&(r["data-fillo-on-primary"]=o)}return(t.primary||t.background||t.text||i)&&(r["data-fillo-has-color-theme"]=""),{vars:n,attrs:r}}function Kn(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 Jn(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var Ae=new Map,Fa=e=>new Promise(t=>setTimeout(t,e));function za(e){if(!te(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function Ca(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(!za(i)||r>=2)throw i;let o=te(i)?i.retryAfterSec:void 0;await Fa(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function so(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 ao(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 Mn=e=>e==="published"?36e5:6e4,Ia=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function lo(e,t){return`fillo:sync:v5:${e.baseUrl}|${e.key}|${t}`}function Ta(e,t,n){try{let r=globalThis.localStorage?.getItem(lo(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.manageUrl!==void 0&&typeof i.manageUrl!="string"||i.status!==void 0&&i.status!=="draft"&&i.status!=="published")return null;let o=Mn(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function Na(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(lo(e,t),JSON.stringify({formId:r.formId,slug:r.slug,manageUrl:r.manageUrl,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function Xn(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=so(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=ge(t.schema).some(u=>u.kind==="file_upload"),a=Ae.get(o);if(a&&!n?.bypassCache){if(a.expiresAt===null||!s&&a.expiresAt>Date.now())return a.promise;Ae.delete(o)}if(!n?.bypassCache&&!s){let u=Ta(e,t.id,i);if(u){let f=Promise.resolve({formId:u.formId,slug:u.slug,manageUrl:u.manageUrl,status:u.status,uploadFileSizeLimitMb:u.uploadFileSizeLimitMb});return Ae.set(o,{promise:f,expiresAt:u.ts+Mn(u.status)}),f}}let l=Ca(e,t),c={promise:l,expiresAt:null};return Ae.set(o,c),l.then(u=>{if(Ae.get(o)===c){if(s||Ia(u)){Ae.delete(o);return}c.expiresAt=Date.now()+Mn(u.status),Na(e,t.id,i,u)}},()=>{Ae.get(o)===c&&Ae.delete(o)}),l}var La=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},Ma=Symbol.for("fillo.block");var Pa=["label","description","required","placeholder"],D=(e,t,n,r={})=>({name:e,kind:t,props:[...Pa,...n],...r}),wi=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),$n=["options","allowOther","shuffleOptions"],Ra=[D("Text","short_text",["maxLength"]),D("LongText","long_text",["maxLength"]),D("Email","email",["maxLength"]),D("Url","url",["maxLength"]),D("Phone","phone",["defaultCountry"]),D("Number","number",["min","max","decimals","prefix","suffix","notation"]),D("Select","select",$n,{optionChildren:!0}),D("MultiSelect","multi_select",$n,{optionChildren:!0}),D("Dropdown","dropdown",$n,{optionChildren:!0}),D("Checkbox","checkbox",["appearance"]),D("Rating","rating",["max","insightsMetric"]),D("Scale","linear_scale",["min","max","minLabel","maxLabel","insightsMetric"]),D("Ranking","ranking",["options"],{optionChildren:!0}),D("Matrix","matrix",["rows","columns"]),D("Signature","signature",[]),D("Date","date",["defaultToday"]),D("FileUpload","file_upload",["maxFiles","maxFileSizeMb","accept"]),D("Hidden","hidden",["paramName","defaultValue"]),D("Calculated","calculated",["calc","decimals","prefix","suffix"]),D("RepeatingGroup","repeating_group",["minInstances","maxInstances","addLabel","itemLabel"],{blockChildren:!0}),D("Custom","custom",["component","config"]),wi("Heading","heading",!0),wi("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],Oa={name:"Page",kind:"__page",props:["title"]},Za={name:"Option",kind:"__option",props:["label","icon"]};function Sn(e){let t=()=>{throw new La("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[Ma]=e,t}var wp=Object.fromEntries([...Ra.map(e=>[e.name,Sn(e)]),["Page",Sn(Oa)],["Option",Sn(Za)]]);var Da=1440*6e4,_i=new Map,xi=new Set;function Ua(e){try{return so(JSON.stringify(e)??"")}catch{return"unserializable"}}function Ba(e){let t=`fillo:definition-report:v1:${e}`;try{let n=Number(globalThis.localStorage?.getItem(t));if(Number.isFinite(n)&&Date.now()-n<Da)return!1;globalThis.localStorage?.setItem(t,String(Date.now()))}catch{}return!0}function ki(e,t,n){return typeof e.reportInvalidDefinition=="function"?e.reportInvalidDefinition(t,n):Promise.resolve(null)}function co(e,t){let n=t.formId??(t.handle?`handle:${t.handle}`:""),r=`${e?.baseUrl??""}|${e?.key??""}|${n}|${Ua(t.definition)}`,i=_i.get(r);if(i)return i;let o;return t.formId?(e&&Ba(r)&&ki(e,{formId:t.formId},t.definition),o=Promise.resolve(t.formId)):t.handle&&e?.key?o=ki(e,{handle:t.handle},t.definition):o=Promise.resolve(null),o=o.then(s=>{if(!xi.has(r)){xi.add(r);let a=s?t.formId?"Showing the version published on Fillo instead, or hiding the form if nothing is published":"Showing the version published on Fillo instead":"Nothing is published to show instead, so the form is hidden";console.error(`[fillo] This form's definition is invalid: ${t.reason}. ${a}. Fix the definition in your code.`)}return s}),_i.set(r,o),o}function ja(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 Yn(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function uo(){if(Yn())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&ja(e)}var Va=/\{\{\s*([\w-]+)\s*\}\}/g;function An(e,t,n){if(!e.includes("{{"))return e;let r=ge(n);return e.replace(Va,(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 po(e,t,n){let r=i=>i===void 0?i:An(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:An(e.text,t,n)};case"divider":return e;default:return{...e,label:An(e.label,t,n),description:r(e.description)}}}var Ha="fillo-",Ga=0,gt='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function qa(e){return e.matches(gt)?e:e.querySelector(gt)}function Wa(e){return Array.from(e.querySelectorAll(gt)).find(n=>!n.closest(".fillo-group-instance-header"))??null}function $o(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 Ge(e,t){let n=oo(t);if(n){for(let[r,i]of Object.entries(n.attrs))e.setAttribute(r,i);for(let[r,i]of Object.entries(n.vars))e.style.setProperty(r,i)}}function Pe(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 Ka(e){let t=new URL(Pe(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function Zt(e){return typeof e=="string"||typeof e=="number"?String(e):""}function fo(e,t,n){let r=Zt(e);if(r==="")return r;let i=Number(r);return Number.isFinite(i)?Hi(i,{locale:n,decimals:t}):r}function T(e,t){for(let n of t)n&&e.appendChild(n);return e}var Dt="http://www.w3.org/2000/svg",Ja={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 So(e){if(!e)return null;let t=document.createElementNS(Dt,"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(Dt,"path");return n.setAttribute("d",Ja[e]),t.appendChild(n),t}function Ao(){let e=document.createElementNS(Dt,"svg");e.setAttribute("class","fillo-option-check"),e.setAttribute("width","1em"),e.setAttribute("height","1em"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linecap","square"),e.setAttribute("stroke-linejoin","miter"),e.setAttribute("aria-hidden","true"),e.setAttribute("focusable","false");let t=document.createElementNS(Dt,"path");return t.setAttribute("d","M4 12l5 5L20 6"),e.appendChild(t),e}function K(e,t,n,r,i={}){n&&e.setAttribute("aria-invalid","true"),(i.requiredSupported??!0)&&t.required&&e.setAttribute("aria-required","true");let o=[t.description?r.descriptionId:null,n?r.errorId:null].filter(Boolean).join(" ");o&&e.setAttribute("aria-describedby",o)}function Eo(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=ro(i.key,s,t.length,{rtl:o});if(a===null)return;i.preventDefault();let l=t[a];l!==void 0&&(r(l),e.querySelectorAll('[role="radio"]')[a]?.focus())})}function ne(e,t,n,r){let i=d("div",{className:`fillo-field fillo-field--${e.kind}${t?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.id,"data-kind":e.kind}});i.toggleAttribute("data-invalid",!!t),i.toggleAttribute("data-required",!!e.required);let o=d("label",{className:"fillo-label",text:e.label,attrs:{id:r.labelId,for:r.inputId,"data-fillo":"label"}});return!e.required&&!(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 ut(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation!==void 0,o=Vi(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?fo(t.value,r?.decimals,o):Zt(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,f=()=>{a.value=c,a.setSelectionRange(u,u)};i?(a.addEventListener("input",()=>{if(!ct(a.value,o))return f();c=a.value,u=a.selectionStart??a.value.length,t.setValue(Bn(a.value,o),{render:!1})}),a.addEventListener("change",()=>{if(!ct(a.value,o))return f();c=a.value,t.setValue(Bn(a.value,o))}),a.addEventListener("blur",()=>{let p=t.getValue?.()??t.value;a.value=fo(p,r?.decimals,o),c=a.value,u=a.value.length})):(a.addEventListener("input",()=>{if(!ct(a.value,o))return f();c=a.value,u=a.selectionStart??a.value.length,t.setValue(a.value,{render:!1})}),a.addEventListener("change",()=>{if(!ct(a.value,o))return f();c=a.value,t.setValue(a.value)}))}else a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value));K(a,n,t.error,t.ids);let l=a;return r&&(r.prefix||r.suffix)&&(l=T(d("div",{className:"fillo-number"}),[r.prefix?d("span",{className:"fillo-number-prefix",text:r.prefix}):null,a,r.suffix?d("span",{className:"fillo-number-suffix",text:r.suffix}):null])),ne(n,t.error,l,t.ids)}function Xa(){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 Ya(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function Qa(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 el(e){let t=e.field,n=at(Zt(e.value)).country??Pt(t.defaultCountry)??Mi(Ya())??Pt(Xa())??ot[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"});T(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),T(i,[o]);let l=d("input",{className:"fillo-input fillo-phone-input",attrs:{id:e.ids.inputId,type:"tel",inputmode:"tel",autocomplete:"tel-national","data-fillo":"control"}});K(l,e.field,e.error,e.ids);let c=()=>e.getValue?.()??e.value,u=()=>{let _=me(Zt(c()));return _.startsWith(n.dialCode)?_.slice(n.dialCode.length):_},f=()=>{s.textContent=On(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},p=()=>{l.value=st(n,u()),l.placeholder=st(n,n.example)},m=_=>e.setValue(_?Pi(n,_):"",{render:!1}),h=_=>e.setValue(_,{render:!1});f(),p(),l.addEventListener("input",()=>{let _=l.value,Z=l.selectionStart??_.length,j=me(_.slice(0,Z)).length;if(_.trimStart().startsWith("+")){let U=at(_,n,{previousDigits:u()});if(U.pending){h(U.raw??_);return}U.country&&(n=U.country,f()),m(U.country?U.national:me(_))}else m(me(_));l.value=st(n,u()),Qa(l,j)});let v=e.registerOverlay,b=e.announce,g=null,A=0,F=He,R=null,re=null,J,ie=`${e.ids.inputId}-countries`,ve=()=>{if(!g)return;let _=Ri(i,g);g.classList.toggle("fillo-phone-popover--above",_==="above"),g.classList.toggle("fillo-phone-popover--below",_==="below")},le=()=>{R?.();let _=()=>ve();ve(),window.addEventListener("resize",_),window.addEventListener("scroll",_,!0),R=()=>{window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0)}},ce=_=>{let Z=_.relatedTarget;if(Z){i.contains(Z)||H();return}queueMicrotask(()=>{g&&!i.contains(document.activeElement)&&H()})},H=()=>{clearTimeout(J),R?.(),R=null,g?.remove(),g=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",ue),i.removeEventListener("focusout",ce),re?.(),re=null},ue=_=>{i.contains(_.target)||H()},Re=_=>{_&&(n=_,f(),m(u()),p(),H(),b?.(M.phoneCountrySelected(_.name)),l.focus())},Oe=_=>{let Z=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),j=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":ie,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});_&&(j.value=_);let U=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:ie,"aria-label":"Country"}}),We=()=>{if(U.replaceChildren(),F.length===0){U.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),j.removeAttribute("aria-activedescendant"),ve();return}F.forEach((O,Y)=>{let z=d("li",{className:`fillo-phone-option${Y===A?" fillo-phone-option--active":""}`,attrs:{id:`${ie}-opt-${Y}`,role:"option","aria-selected":String(O.iso2===n.iso2)}});T(z,[d("span",{className:"fillo-phone-flag-emoji",text:On(O.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:O.name}),d("span",{className:"fillo-phone-option-dial",text:`+${O.dialCode}`})]),z.addEventListener("mouseenter",()=>{A=Y,j.setAttribute("aria-activedescendant",z.id),Ce()}),z.addEventListener("mousedown",ye=>{ye.preventDefault(),Re(O)}),U.appendChild(z)}),j.setAttribute("aria-activedescendant",`${ie}-opt-${A}`),ve()},Ce=()=>{[...U.children].forEach((O,Y)=>O.classList.toggle("fillo-phone-option--active",Y===A)),document.getElementById(`${ie}-opt-${A}`)?.scrollIntoView({block:"nearest"})},Ze=O=>{let Y=O.trim().toLowerCase(),z=Y.replace(/[^\d]/g,"");F=Y?He.filter(ye=>ye.name.toLowerCase().includes(Y)||ye.iso2.toLowerCase()===Y||z.length>0&&ye.dialCode.startsWith(z)):He,A=0,We(),clearTimeout(J),J=setTimeout(()=>b?.(M.phoneResultsCount(F.length)),300)};j.addEventListener("input",()=>Ze(j.value)),j.addEventListener("keydown",O=>{if(O.key==="ArrowDown"){if(O.preventDefault(),F.length===0)return;A=Math.min(A+1,F.length-1),Ce(),j.setAttribute("aria-activedescendant",`${ie}-opt-${A}`)}else if(O.key==="ArrowUp"){if(O.preventDefault(),F.length===0)return;A=Math.max(A-1,0),Ce(),j.setAttribute("aria-activedescendant",`${ie}-opt-${A}`)}else O.key==="Enter"?(O.preventDefault(),Re(F[A])):O.key==="Escape"&&(O.preventDefault(),H(),o.focus())}),T(Z,[j,U]),g=Z,i.appendChild(Z),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",ie),_?Ze(_):(F=He,A=Math.max(0,He.indexOf(n)),We()),le(),Ce(),document.addEventListener("mousedown",ue),i.addEventListener("focusout",ce),re=v?.(H)??null,requestAnimationFrame(()=>{if(j.focus(),_){let O=j.value.length;j.setSelectionRange(O,O)}})};return o.addEventListener("click",()=>g?H():Oe()),o.addEventListener("keydown",_=>{if(!g){if(_.key==="ArrowDown"||_.key==="ArrowUp"){_.preventDefault(),Oe();return}_.key.length===1&&_.key!==" "&&!_.ctrlKey&&!_.metaKey&&!_.altKey&&(_.preventDefault(),Oe(_.key))}}),T(r,[i,l]),ne(e.field,e.error,r,e.ids)}function tl(e){let t=d("textarea",{className:"fillo-input fillo-textarea",attrs:{id:e.ids.inputId,rows:"4","data-fillo":"control"}});return t.value=typeof e.value=="string"?e.value:"",e.field.placeholder&&(t.placeholder=e.field.placeholder),"maxLength"in e.field&&e.field.maxLength!==void 0&&(t.maxLength=e.field.maxLength),t.addEventListener("input",()=>e.setValue(t.value,{render:!1})),t.addEventListener("change",()=>e.setValue(t.value)),K(t,e.field,e.error,e.ids),ne(e.field,e.error,t,e.ids)}function nl(e){let t=e.field,n=rr(t),r=typeof e.value=="string"?e.value:"",i=e.activeOtherFields,o=r!==""&&!t.options.some(l=>l.id===r),s=o||r===""&&i?.has(t.id)===!0,a=d("div",{className:"fillo-options",attrs:{role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"options"}});K(a,t,e.error,e.ids);for(let l of n){let 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)}),T(c,[u,So(l.icon),d("span",{className:"fillo-option-label",text:l.label,attrs:{"data-fillo":"optionLabel"}}),l.icon&&r===l.id?Ao():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})}),T(l,[T(d("span",{className:"fillo-option-main"}),[c,d("span",{className:"fillo-option-label",text:N.other,attrs:{"data-fillo":"optionLabel"}})])]),s){let u=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":N.otherPrompt}});u.value=o?r:"",u.placeholder=N.otherPlaceholder,u.addEventListener("input",()=>{i?.add(t.id),e.setValue(u.value,{render:!1})}),u.addEventListener("change",()=>{i?.add(t.id),e.setValue(u.value)}),l.appendChild(u),o||queueMicrotask(()=>u.focus())}a.appendChild(l)}return ne(t,e.error,a,e.ids)}function rl(e){let t=e.field,n=rr(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"}});K(l,t,e.error,e.ids,{requiredSupported:!1});let c=u=>e.setValue(u);for(let u of n){let f=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"}});f.toggleAttribute("data-selected",r.includes(u.id));let p=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});p.checked=r.includes(u.id),p.addEventListener("change",()=>{let m=a();c(p.checked?[...m,u.id]:m.filter(h=>h!==u.id))}),T(f,[p,So(u.icon),d("span",{className:"fillo-option-label",text:u.label,attrs:{"data-fillo":"optionLabel"}}),u.icon&&r.includes(u.id)?Ao():null]),l.appendChild(f)}if(t.allowOther){let u=o!==void 0||s?.has(t.id)===!0,f=d("label",{className:`fillo-option fillo-option--other${u?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});f.toggleAttribute("data-selected",u);let p=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(p.checked=u,p.addEventListener("change",()=>{let m=a().filter(h=>i.has(h));p.checked?(s?.add(t.id),c(m)):(s?.delete(t.id),c(m))}),T(f,[T(d("span",{className:"fillo-option-main"}),[p,d("span",{className:"fillo-option-label",text:N.other,attrs:{"data-fillo":"optionLabel"}})])]),u){let m=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":N.otherPrompt}});m.value=o??"",m.placeholder=N.otherPlaceholder,m.addEventListener("input",()=>{s?.add(t.id);let h=a().filter(v=>i.has(v));e.setValue(m.value?[...h,m.value]:h,{render:!1})}),m.addEventListener("change",()=>{s?.add(t.id);let h=a().filter(v=>i.has(v));e.setValue(m.value?[...h,m.value]:h)}),f.appendChild(m),o===void 0&&queueMicrotask(()=>m.focus())}l.appendChild(f)}return ne(t,e.error,l,e.ids)}function il(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function ol(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=il(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 rr(t))c.appendChild(d("option",{text:u.label,attrs:{value:u.id}}));if(t.allowOther&&c.appendChild(d("option",{text:`${N.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))}),K(c,t,e.error,e.ids),T(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":N.otherPrompt}});u.value=o?n:"",u.placeholder=N.otherPlaceholder,u.addEventListener("input",()=>{i?.add(t.id),e.setValue(u.value,{render:!1})}),u.addEventListener("change",()=>{i?.add(t.id),e.setValue(u.value)}),a.appendChild(u),o||queueMicrotask(()=>u.focus())}return ne(t,e.error,a,e.ids)}function sl(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)}),K(c,e.field,e.error,e.ids),T(s,[l,c,T(d("span",{className:"fillo-toggle-track",attrs:{"aria-hidden":"true"}}),[d("span",{className:"fillo-toggle-thumb"})])]),o.appendChild(s),e.field.description&&o.appendChild(d("p",{className:"fillo-description",text:e.field.description,attrs:{id:e.ids.descriptionId,"data-fillo":"fieldDescription"}})),e.error&&o.appendChild(d("p",{className:"fillo-error",text:e.error,attrs:{id:e.ids.errorId,"data-fillo":"error"}})),o}let t=d("div",{className:`fillo-field fillo-field--checkbox${e.error?" fillo-field--error":""}`,attrs:{"data-fillo":"field","data-field":e.field.id,"data-kind":e.field.kind}});t.toggleAttribute("data-invalid",!!e.error),t.toggleAttribute("data-required",!!e.field.required);let n=d("label",{className:"fillo-option",attrs:{"data-fillo":"option"}});n.toggleAttribute("data-checked",e.value===!0);let r=d("input",{className:"fillo-option-input",attrs:{id:e.ids.inputId,type:"checkbox"}});r.checked=e.value===!0,r.addEventListener("change",()=>e.setValue(r.checked)),K(r,e.field,e.error,e.ids);let i=d("span",{className:"fillo-option-label",text:e.field.label,attrs:{"data-fillo":"optionLabel"}});return e.field.required||i.appendChild(d("span",{className:"fillo-optional",text:" (optional)"})),T(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 al(e){if(e.field.kind!=="rating")return d("div");let t=typeof e.field.max=="number"?e.field.max:5,n=typeof e.value=="number"?e.value:0,r=Array.from({length:t},(a,l)=>l+1),i=n>0?n:null,o=i===null?0:Math.max(0,r.indexOf(i)),s=d("div",{className:"fillo-rating",attrs:{id:e.ids.inputId,role:"radiogroup","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});K(s,e.field,e.error,e.ids);for(let[a,l]of r.entries()){let 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 Eo(s,r,i,a=>e.setValue(a)),ne(e.field,e.error,s,e.ids)}function ll(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},(f,p)=>t+p),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"}});K(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[f,p]of i.entries()){let m=d("button",{className:`fillo-scale-step${e.value===p?" fillo-scale-step--active":""}`,text:String(p),attrs:{type:"button",role:"radio","aria-label":String(p),"aria-checked":String(e.value===p),tabindex:String(f===o?0:-1),"data-fillo":"option"}});m.toggleAttribute("data-selected",e.value===p),m.addEventListener("click",h=>{h.detail===0&&e.value===p||e.setValue(e.value===p?null:p)}),c.appendChild(m)}return Eo(c,i,r,f=>e.setValue(f)),l.appendChild(c),("minLabel"in e.field||"maxLabel"in e.field)&&T(l,[T(d("div",{className:"fillo-scale-labels"}),[d("span",{text:String(e.field.minLabel??""),attrs:{id:s}}),d("span",{text:String(e.field.maxLabel??""),attrs:{id:a}})])]),ne(e.field,e.error,l,e.ids)}function cl(e){let t=e.field;if(t.kind!=="ranking")return null;let n=e.announce,r=Array.isArray(e.value)?e.value:[],i=[...r.filter(a=>t.options.some(l=>l.id===a)),...t.options.map(a=>a.id).filter(a=>!r.includes(a))],o=d("div",{attrs:{id:e.ids.inputId,role:"group","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});K(o,e.field,e.error,e.ids,{requiredSupported:!1});let s=d("ol",{className:"fillo-ranking"});for(let[a,l]of i.entries()){let c=t.options.find(v=>v.id===l);if(!c)continue;let u=d("li",{className:"fillo-ranking-item"}),f=d("span",{className:"fillo-ranking-controls"}),p=v=>{let b=a+v;if(b<0||b>=i.length)return;let g=[...i];[g[a],g[b]]=[g[b],g[a]],e.setValue(g),n?.(M.rankingPosition(c.label,b+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",()=>p(-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",()=>p(1)),T(f,[m,h]),T(u,[d("span",{className:"fillo-ranking-index",text:String(a+1)}),d("span",{className:"fillo-ranking-label",text:c.label}),f]),s.appendChild(u)}return o.appendChild(s),ne(e.field,e.error,o,e.ids)}function ul(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,f=!!e.error&&!!t.required&&!u,p=b=>`${e.ids.inputId}-${l.id}-${b.id}`,m=document.createElement("tr"),h=d("th",{attrs:{scope:"row"}}),v=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${c}`,"aria-owns":t.columns.map(p).join(" ")}});v.appendChild(d("span",{text:l.label,attrs:{id:c}})),h.appendChild(v),m.appendChild(h);for(let b of t.columns){let g=d("td",{attrs:{"data-label":b.label}}),A=d("label",{className:"fillo-matrix-cell"}),F=d("input",{className:"fillo-option-input",attrs:{id:p(b),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${b.label}`}});t.required&&F.setAttribute("aria-required","true"),f&&F.setAttribute("aria-invalid","true"),F.checked=n[l.id]===b.id,F.addEventListener("change",()=>e.setValue({...n,[l.id]:b.id})),A.appendChild(F),g.appendChild(A),m.appendChild(g)}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 K(a,e.field,e.error,e.ids,{requiredSupported:!1}),a.appendChild(r),ne(e.field,e.error,a,e.ids)}function dl(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 b=new Image;b.onload=()=>s.drawImage(b,0,0,r.width,r.height),b.src=String(e.value),o.style.display="none"}let u=d("input",{className:"fillo-input fillo-signature-type-input",attrs:{id:e.ids.inputId,type:"text",autocomplete:"name"}});K(u,e.field,e.error,e.ids);let f=b=>{s&&(s.clearRect(0,0,r.width,r.height),b.trim()?(s.fillStyle=getComputedStyle(r).color||"#18181b",s.font=`italic ${Math.min(96,r.height*.45)}px "Segoe Script", "Brush Script MT", cursive`,s.textBaseline="middle",s.fillText(b,24,r.height/2),l=!0,o.style.display="none",e.setValue(r.toDataURL("image/png"),{render:!1})):(l=!1,o.style.display="",e.setValue(null,{render:!1})),c())};u.addEventListener("input",()=>f(u.value));let p=b=>{let g=r.getBoundingClientRect();return{x:(b.clientX-g.left)/g.width*r.width,y:(b.clientY-g.top)/g.height*r.height}};r.addEventListener("pointerdown",b=>{if(!s)return;a=!0,l=!0,o.style.display="none",c(),u.value&&(u.value=""),r.setPointerCapture(b.pointerId);let g=p(b);s.beginPath(),s.moveTo(g.x,g.y)}),r.addEventListener("pointermove",b=>{if(!a||!s)return;let g=p(b);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(g.x,g.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})}),T(n,[r,o,i]);let h=d("div",{className:"fillo-signature-type"}),v=d("label",{className:"fillo-signature-type-label",text:"Or type your full name to sign",attrs:{for:e.ids.inputId}});return T(h,[v,u]),T(t,[n,h]),ne(e.field,e.error,t,e.ids)}function ho(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 mt(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 mo(e){let t=d("span",{className:`fillo-file-state fillo-file-state--${e}`,attrs:{"aria-hidden":"true"}});return t.appendChild(mt(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 Qn(){let e=mt(["m7 7 10 10M17 7 7 17"],16);return e.setAttribute("class","fillo-file-action-icon"),e}function go(e){let t=mt([e],16);return t.setAttribute("class","fillo-group-icon"),t}function Ot(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 pl(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(p=>p.error===void 0).length,u=d("div");if(c>0){let p=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file",hidden:""}});o>1&&(p.multiple=!0),t.accept?.length&&(p.accept=t.accept.join(",")),p.disabled=!i,p.addEventListener("change",()=>{if(!i)return;let h=Array.from(p.files??[]);p.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(K(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&&p.click()}),m.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),i&&p.click())}),m.appendChild(p),i)T(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 p=d("ul",{className:"fillo-files"});for(let m of a){let h=d("li",{className:"fillo-file fillo-file--done"}),v=d("span",{className:"fillo-file-content"});T(v,[d("span",{className:"fillo-file-name",text:m.name}),d("span",{className:"fillo-file-meta",text:M.uploadedFile(ho(m.size))})]);let b=d("span",{className:"fillo-file-actions"});b.appendChild(Ot("fillo-file-remove",`${M.uploadRemove} ${m.name}`,Qn(),()=>e.setValue(a.filter(g=>g.fileId!==m.fileId)))),T(h,[mo("done"),v,b]),p.appendChild(h)}for(let m of l){let h=m.error!==void 0,v=d("li",{className:`fillo-file${h?" fillo-file--failed":""}`});v.appendChild(mo(h?"failed":"uploading"));let b=d("span",{className:"fillo-file-content"});if(b.appendChild(d("span",{className:"fillo-file-name",text:m.name})),h){let g=d("span",{className:"fillo-file-actions"});b.appendChild(d("span",{className:"fillo-file-error",text:m.error??""})),v.appendChild(b),!m.tooLarge&&c>0&&g.appendChild(Ot("fillo-file-retry",`${M.uploadRetry} ${m.name}`,M.uploadRetry,()=>n.uploadAction?.(m.key,"retry"))),g.appendChild(Ot("fillo-file-remove",`${M.uploadDismiss} ${m.name}`,Qn(),()=>n.uploadAction?.(m.key,"dismiss"))),v.appendChild(g)}else{let g=d("span",{className:"fillo-progress-bar"});g.style.width=`${m.fraction*100}%`,b.appendChild(d("span",{className:"fillo-file-meta",text:M.uploadingFile(Math.round(m.fraction*100),ho(m.size))}));let A=d("span",{className:"fillo-file-actions"});A.appendChild(Ot("fillo-file-remove",`${M.uploadCancel} ${m.name}`,Qn(),()=>n.uploadAction?.(m.key,"cancel"))),T(v,[b,A,T(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))}}),[g])])}p.appendChild(v)}u.appendChild(p)}let f=n.uploadNotice;return f&&u.appendChild(d("p",{className:"fillo-upload-notice",text:f})),ne(t,e.error,u,e.ids)}function fl(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?Un(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var bo=new Map;function rr(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=bo.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]]}bo.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 dt(e){let t=e.getValue?.()??e.value;return Array.isArray(t)?t:[]}function hl(e,t){return Math.max(t.length,e.minInstances??1)}function ml(e){return Math.max(e.minInstances??1,0)}function er(e,t){let n=[...e];for(;n.length<t;)n.push({});return n}function gl(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=dt(e),a=hl(t,s),l=ml(t),c=d("div",{className:"fillo-group",attrs:{id:e.ids.inputId,"data-fillo":"control"}});K(c,t,e.error,e.ids,{requiredSupported:!1});for(let p=0;p<a;p++){let m=s[p]??{},h=M.groupInstanceLabel(o,p+1,a),v=d("div",{className:"fillo-group-instance",attrs:{role:"group","aria-label":h,tabindex:"-1"}}),b=d("div",{className:"fillo-group-instance-header"}),g=d("button",{className:"fillo-group-remove",attrs:{type:"button","aria-label":M.groupRemoveLabel(o,p+1)}});g.appendChild(go("M6 6l12 12M18 6 6 18"));let A=a>l;g.toggleAttribute("disabled",!A),A||(g.setAttribute("aria-disabled","true"),g.setAttribute("title",`At least ${l} ${l===1?"entry":"entries"} required`)),g.addEventListener("click",()=>{if(a<=l)return;let F=er(dt(e),a);F.splice(p,1),e.setValue(F),n.setGroupFocus?.({groupId:t.id,cardIndex:p-1,intoControl:!1}),r?.(M.groupInstanceRemoved(o,F.length))}),T(b,[d("p",{className:"fillo-group-instance-title",text:h}),g]),v.appendChild(b);for(let F of Rn(t,m)){let R=`${t.id}.${p}.${F.id}`,re={...F,id:R},J=$o(i,R),ie=(ce,H)=>{let ue=er(dt(e),a);ue[p]={...ue[p]??{},[F.id]:ce},e.setValue(ue,H)},ve={field:re,value:m[F.id],error:e.api.errors[R],ids:J,api:e.api,setValue:ie,getValue:()=>dt(e)[p]?.[F.id],announce:n.announce,announceAlert:n.announceAlert,registerOverlay:n.registerOverlay,activeOtherFields:n.activeOtherFields},le=n.renderChildField?.(ve)??Fo(ve);le&&v.appendChild(le)}c.appendChild(v)}let u=a>=t.maxInstances,f=d("button",{className:"fillo-group-add",attrs:{type:"button"}});return f.append(go("M12 5v14M5 12h14"),t.addLabel||M.groupAdd),f.toggleAttribute("disabled",u),u&&(f.setAttribute("aria-disabled","true"),f.setAttribute("title",`Maximum ${t.maxInstances} ${t.maxInstances===1?"entry":"entries"}`)),f.addEventListener("click",()=>{if(a>=t.maxInstances)return;let p=er(dt(e),a);p.push({}),e.setValue(p),n.setGroupFocus?.({groupId:t.id,cardIndex:p.length-1,intoControl:!0}),r?.(M.groupInstanceAdded(o,p.length,p.length))}),c.appendChild(f),ne(t,e.error,c,e.ids)}var bl={short_text:e=>ut("text",e),email:e=>ut("email",e),url:e=>ut("url",e),phone:el,number:e=>ut("number",e),date:e=>ut("date",e),long_text:tl,select:nl,multi_select:rl,dropdown:ol,checkbox:sl,rating:al,linear_scale:ll,ranking:cl,matrix:ul,signature:dl,file_upload:pl,calculated:fl,repeating_group:gl};function Fo(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=bl[e.field.kind];return t?t(e):null}var vl="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",vo="fillo-turnstile-script",yl=2e4,wl=/^[A-Za-z0-9_-]{1,255}$/,pt=null;function qe(){return globalThis.turnstile}function _l(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):qe()?Promise.resolve():pt||(pt=new Promise((e,t)=>{let n=()=>{qe()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(vo);if(r){if(qe()){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=vo,i.src=vl,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),pt=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),pt)}function yo(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var bt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&Cl(),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${++Ga}`;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=yo();turnstileWidgetId=null;turnstileSiteKey;turnstileLoadInFlight=!1;turnstileAttempt=0;challengeFrame=null;challengeFrameSrc=null;challengeFrameOrigin=null;challengeMessageHandler=null;challengeWatchdog=null;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||$l()}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;syncFormUrl;uploadsAvailable;uploadFileSizeLimitMb;resolutionFailureCode=null;async resolve(){try{this.challenge=this.options.renderOnly?void 0:this.options.challenge;let t=Jn(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}let r=xo(t.schema);if(r){await this.showPublishedInstead(r,t.schema,t.id);return}!this.options.client&&this.options.formId&&(this.options.client=be());let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await Xn(i,t,{bypassCache:!0});if(this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.syncFormUrl=o.manageUrl,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=ze(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&&!ao(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=ht(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(),ko();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 Xn(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?wo(o.acceptingReason):null,this.stagedNotice=!!o.staged,this.draftNotice=o.status==="draft",this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.syncFormUrl=o.manageUrl,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(ht(o))}return}let n=this.options.form&&!Jn(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(),ko();this.options.client??=be();let r=xo(n);if(r){await this.showPublishedInstead(r,n,void 0);return}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??=be(),await this.loadPublished(this.options.formId)}catch(t){if(this.destroyed)return;this.handleError(ht(t))}}async showPublishedInstead(t,n,r){let i=new S(`This form's definition is invalid: ${t}. In production, Fillo shows the published version of this form instead.`,422,void 0,ft);if(this.devChrome()){this.handleError(i);return}this.options.onError?.(i),this.render(),!this.options.client&&this.options.formId&&(this.options.client=be());let o=await co(this.options.client,{formId:this.options.formId,handle:r,definition:n,reason:t});if(!this.destroyed){if(!o){this.fatalError=i,this.phase="error",this.render(i);return}this.options.client??=be();try{await this.loadPublished(o)}catch{if(this.destroyed)return;this.fatalError=i,this.phase="error",this.render(i)}}}async loadPublished(t){let n=this.options.client??be();this.options.client=n,this.render();let r=await n.getForm(t);if(!this.destroyed){if(r.accepting===!1?this.notOpenVariant=wo(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)}}setSchema(t,n,r){if(this.destroyed)return;let i=ze(t);if(!i.ok)throw new S(`This form could not be rendered: ${i.error}`,422,void 0,ft);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=eo({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,f=this.engine.getState().editingPrevious;this.engine.subscribe(()=>{let p=this.engine?.getState();p&&(p.status!==c||p.resumedDraft!==u||p.editingPrevious!==f)&&(p.editingPrevious&&!f?this.announce(N.editNotice):p.resumedDraft&&!u&&this.announce(N.resumeNotice),c=p.status,u=p.resumedDraft,f=p.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=ze(t);if(!i.ok)throw new S(`This form could not be rendered: ${i.error}`,422,void 0,ft);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?.(ht(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=ht(s),l=a.status===0||a.status!==void 0&&a.status>=500?M.uploadUnavailable: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),f=s.filter(h=>h.size>c),p=n.length-s.length,m=s.length-u.length;if(p>0||m>0){let h=[];p>0&&h.push(`You can attach up to ${r} file${r===1?"":"s"}. ${p} ${p===1?"file was":"files were"} not added.`);let v=h.join(" ");v?this.uploadNotices.set(t.id,v):this.uploadNotices.delete(t.id),v&&this.announce(v)}else this.uploadNotices.delete(t.id);for(let h of f){let v=M.fileTooLarge(l),b=`${h.name}-${h.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;this.inFlight.set(b,{fieldId:t.id,name:h.name,size:h.size,fraction:0,error:v,tooLarge:!0,file:h,controller:new AbortController,maxFiles:r}),this.announceAlert(v)}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()}}ensureChallengeWidget(t){t.bridgeUrl?this.ensureChallengeBridge(t.bridgeUrl):this.ensureTurnstileWidget(t.siteKey)}ensureChallengeBridge(t){if(typeof window>"u")return;let n;try{n=new URL(t)}catch{this.handleChallengeError();return}if(n.protocol!=="https:"&&n.protocol!=="http:"){this.handleChallengeError();return}n.searchParams.set("origin",window.location.origin),n.searchParams.set("theme",this.options.challengeTheme??"auto"),this.formId&&wl.test(this.formId)&&n.searchParams.set("cdata",this.formId),n.searchParams.set("appearance",(this.options.challengeAppearance??"interaction-only")==="interaction-only"?"interaction-only":"always");let r=n.toString();if(this.challengeFrame&&this.challengeFrameSrc===r)return;this.teardownTurnstileWidget();let i=++this.turnstileAttempt,o=d("iframe",{className:"fillo-turnstile-frame",attrs:{src:r,title:"Human verification",width:"300",height:"65",referrerpolicy:"no-referrer"}});this.challengeFrame=o,this.challengeFrameSrc=r,this.challengeFrameOrigin=n.origin,this.turnstileContainer.appendChild(o),this.setChallengeFrameVisible((this.options.challengeAppearance??"interaction-only")!=="interaction-only");let s=a=>{if(i!==this.turnstileAttempt||this.destroyed||a.origin!==this.challengeFrameOrigin||!this.challengeFrame||a.source!==this.challengeFrame.contentWindow)return;let l=a.data;switch(l?.type){case"fillo:challenge:ready":this.settleChallengeWatchdog();break;case"fillo:challenge:token":this.settleChallengeWatchdog(),typeof l.token=="string"&&l.token.length>0&&this.handleChallengeToken(l.token),(this.options.challengeAppearance??"interaction-only")==="interaction-only"&&this.setChallengeFrameVisible(!1);break;case"fillo:challenge:interactive":this.setChallengeFrameVisible(!0);break;case"fillo:challenge:interactive-done":(this.options.challengeAppearance??"interaction-only")==="interaction-only"&&this.setChallengeFrameVisible(!1);break;case"fillo:challenge:expired":this.handleChallengeToken(void 0);break;case"fillo:challenge:error":this.settleChallengeWatchdog(),this.handleChallengeToken(void 0),this.handleChallengeError();break}};this.challengeMessageHandler=s,window.addEventListener("message",s),this.challengeWatchdog=window.setTimeout(()=>{i!==this.turnstileAttempt||this.destroyed||(this.handleChallengeToken(void 0),this.handleChallengeError())},yl)}setChallengeFrameVisible(t){let n=this.challengeFrame;n&&(n.setAttribute("height",t?"65":"0"),t?(n.removeAttribute("aria-hidden"),n.removeAttribute("tabindex")):(n.setAttribute("aria-hidden","true"),n.setAttribute("tabindex","-1")),this.turnstileContainer.setAttribute("data-fillo-challenge-visible",t?"true":"false"))}settleChallengeWatchdog(){this.challengeWatchdog!==null&&typeof window<"u"&&window.clearTimeout(this.challengeWatchdog),this.challengeWatchdog=null}teardownChallengeBridge(){this.challengeMessageHandler&&typeof window<"u"&&window.removeEventListener("message",this.challengeMessageHandler),this.challengeMessageHandler=null,this.settleChallengeWatchdog(),this.challengeFrame?.remove(),this.challengeFrame=null,this.challengeFrameSrc=null,this.challengeFrameOrigin=null}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;_l().then(()=>{if(this.destroyed||n!==this.turnstileAttempt)return;let r=qe();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(N.challengeUnavailable),this.queueRender()}resetChallengeWidget(){this.challengeToken=void 0,this.challengeFrame&&this.challengeFrameOrigin?this.challengeFrame.contentWindow?.postMessage({type:"fillo:challenge:reset"},this.challengeFrameOrigin):this.turnstileWidgetId&&qe()?.reset(this.turnstileWidgetId),this.queueRender()}teardownTurnstileWidget(){if(this.turnstileWidgetId===null&&!this.turnstileLoadInFlight&&this.challengeFrame===null)return;this.turnstileAttempt++,this.teardownChallengeBridge();let t=qe();if(this.turnstileWidgetId&&t)try{t.remove(this.turnstileWidgetId)}catch{}this.turnstileWidgetId=null,this.turnstileLoadInFlight=!1,this.challengeError=!1,this.turnstileContainer=yo(),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(gt)).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(gt))[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&&qa(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?Wa(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"}});Ge(s,this.theme),T(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===ft;if(s&&!this.devChrome()&&!this.options.renderOnly&&!this.options.renderError){let c=d("div",{attrs:{"data-fillo":"root","data-state":"unavailable","data-error-code":ft}});c.hidden=!0,this.element.appendChild(c);return}let a=o.code==="form_target_required"&&this.devChrome()?`${o.message} (${o.code})`:s&&this.devChrome()?o.message:null,l=this.options.renderError?.(o)??d("div",{className:"fillo-form fillo-form--error",text:a??(this.genericUnavailable?"This form is unavailable.":Tl(o))});l.hasAttribute("data-fillo")||l.setAttribute("data-fillo","root"),l.hasAttribute("data-state")||l.setAttribute("data-state","error"),o.code&&!l.hasAttribute("data-error-code")&&l.setAttribute("data-error-code",o.code),l.hasAttribute("role")||l.setAttribute("role","alert"),Ge(l,this.theme),this.element.appendChild(l);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"}});Ge(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(tr(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)??kl(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"),Ge(l,this.theme),this.element.appendChild(l),this.brandingVisible()&&this.element.appendChild(tr(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let c=Pe(this.schema.settings.redirectUrl);c&&typeof window<"u"?window.location.assign(c):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&T(this.element,Il({preview:this.options.preview===!0,devNotices:this.options.devNotices,syncError:this.syncErrorNotice,staged:this.stagedNotice,draft:this.draftNotice,warningUrl:this.syncWarningUrl,formUrl:this.syncFormUrl,noClient:!this.options.client&&!this.options.renderOnly})),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(tr(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"}});Ge(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"?N.closedTitle:N.notOpenTitle})),i.appendChild(d("p",{className:"fillo-not-open-body",text:t==="closed"?N.closed:N.notOpenBody})),T(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),Ge(o,this.theme);let s=()=>{t.isLastPage?this.submit():this.next()};if(!n){let h=o;h.noValidate=!0,h.addEventListener("submit",v=>{v.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?N.editNotice:N.resumeNotice}));let v=d("button",{className:"fillo-resume-clear",text:N.resumeStartOver,attrs:{type:"button"}});v.addEventListener("click",()=>this.resetDraft()),h.appendChild(v),a.appendChild(h)}if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let h=Ve(t.form,t.data),v=Math.max(h.length,1),b=h.indexOf(t.page.id),g=b>=0?b+1:Math.min(t.pageIndex+1,v),A=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(v),"aria-valuenow":String(g)}});A.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),A.firstElementChild?.style.setProperty("--fillo-progress-value",`${g/v*100}%`),a.appendChild(A)}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 v=this.renderBlock(po(h,this.mutableData,t.form),t);v&&c.appendChild(v)}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:N.challengeUnavailable})),a.appendChild(h),this.ensureChallengeWidget(this.challenge)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight||this.challengeFrame!==null)&&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}),v=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?Pe(this.syncWarningUrl):null;v&&(h.append(" Connect storage: "),h.appendChild(d("a",{text:v,attrs:{href:v,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(h)}let p=!(t.form.settings.submitMode==="auto")||!t.isLastPage||to(Ii(t.form,t.data))||i;if(p||t.pageCount>1&&!t.isFirstPage){let h=d("footer",{className:"fillo-footer",attrs:{"data-fillo":"footer"}});if(t.pageCount>1&&!t.isFirstPage){let v=d("button",{className:"fillo-button fillo-button--ghost",text:"Back",attrs:{type:"button","data-fillo":"button"}});v.addEventListener("click",()=>this.back()),h.appendChild(v)}if(p){let v=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"}});v.toggleAttribute("disabled",t.status==="submitting"||this.engine?.getState().uploading===!0||i&&!this.challengeToken),v.addEventListener("click",b=>{b.preventDefault(),s()}),h.appendChild(v)}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]??Fo}renderChildField=t=>this.fieldRenderer(t.field)?.(t)??null;setGroupFocus=t=>{this.focusIntent=t};renderBlock(t,n){if(!X(t))return xl(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};no(t,o,a)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id]===lt?Oi(t,M):n.errors[t.id],ids:$o(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()?Pe(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 xl(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 kl(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return T(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 tr(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:Ka(t),target:"_blank",rel:"nofollow noopener noreferrer"}})}function wo(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function $l(){return uo()}function Sl(){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 Al(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 El(e){let t=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});t.append("Code changes are staged, not live. This page shows your draft, while respondents still get the live version. ");let n=Pe(e);return n?(t.appendChild(d("a",{text:"Review and publish in Fillo",attrs:{href:n,target:"_blank",rel:"noopener noreferrer"}})),t.append(".")):t.append("Review and publish the changes in Fillo."),t}function Fl(e,t){let n=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});n.append("Draft form preview \u2014 the form renders for local testing, but Fillo will reject the submission and save no response until you publish it. ");let r=Pe(e),i=Pe(t);return r?(n.appendChild(d("a",{text:"Connect storage to publish",attrs:{href:r,target:"_blank",rel:"noopener noreferrer"}})),n.append(". ")):i&&(n.appendChild(d("a",{text:"Open in Fillo to publish",attrs:{href:i,target:"_blank",rel:"noopener noreferrer"}})),n.append(". ")),n.append("(Shown only in development and preview.)"),n}function zl(){return d("span",{className:"fillo-preview-badge",text:"Preview",attrs:{"data-fillo":"preview-badge"}})}var _o=!1;function Cl(){_o||Yn()||(_o=!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 Il(e){let t=[];return e.preview&&t.push(zl()),e.devNotices===!1||(e.syncError?t.push(Al(e.syncError)):e.staged?t.push(El(e.formUrl)):e.draft?t.push(Fl(e.warningUrl,e.formUrl)):e.noClient&&t.push(Sl())),t}var ft="invalid_form_definition";function xo(e){let t=ze(e);return t.ok?null:t.error??"invalid form definition"}function Tl(e){return e.status===404?N.loadFailedNotFound:e.status===0?N.loadFailedNetwork:e.status===422?N.renderFailed:N.loadFailed}function ko(){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 ht(e){return te(e)?e:new S(e instanceof Error?e.message:String(e),0)}function Ut(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 bt(n,r)}function zo(e){let t=d("div");return Ut(t,e),t}var Nl=typeof HTMLElement<"u"?HTMLElement:class{},nr=class extends Nl{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 bt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof bt&&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?be({key:t}):void 0);this.instance=Ut(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 ir(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,nr)}typeof customElements<"u"&&ir();return Bo(Ll);})();
1
+ "use strict";var Fillo=(()=>{var $n=Object.defineProperty;var _s=Object.getOwnPropertyDescriptor;var xs=Object.getOwnPropertyNames;var ks=Object.prototype.hasOwnProperty;var $s=(e,t)=>{for(var n in t)$n(e,n,{get:t[n],enumerable:!0})},Ss=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of xs(t))!ks.call(e,i)&&i!==n&&$n(e,i,{get:()=>t[i],enumerable:!(r=_s(t,i))||r.enumerable});return e};var As=e=>Ss($n({},"__esModule",{value:!0}),e);var vc={};$s(vc,{FilloClient:()=>hn,FilloError:()=>E,createClient:()=>Me,createFormElement:()=>fs,defineForm:()=>Fr,registerFilloElement:()=>Pr,renderForm:()=>vn});var Jr;function N(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 m=0;m<u.length;m++){let p=u[m];p in a||(a[p]=c[p].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 Te=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Jr=globalThis).__zod_globalConfig??(Jr.__zod_globalConfig={});var Sn=globalThis.__zod_globalConfig;function Ue(e){return e&&Object.assign(Sn,e),Sn}function Yr(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 Qr(e,t){return typeof t=="bigint"?t.toString():t}function ei(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Fn(e){return e==null}function ti(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Xr=Symbol("evaluating");function Be(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Xr)return r===void 0&&(r=Xr,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}var En="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function qt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function zn(e){if(qt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let n=t.prototype;return!(qt(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Cn(e){return zn(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var ni=new Set(["string","number","symbol"]);function vt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function In(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function ie(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 ri(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var Fs={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 yt(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 ii(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 je(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 Ve(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 Nn(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}var oi=(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,Qr,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},si=N("$ZodError",oi),wt=N("$ZodError",oi,{Parent:Error});var zs=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 Te;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(l=>Ve(l,o,Ue())));throw En(a,i?.callee),a}return s.value},Wt=zs(wt),Cs=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=>Ve(l,o,Ue())));throw En(a,i?.callee),a}return s.value},Kt=Cs(wt),Is=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 Te;return o.issues.length?{success:!1,error:new(e??si)(o.issues.map(s=>Ve(s,i,Ue())))}:{success:!0,data:o.value}},_t=Is(wt),Ns=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=>Ve(s,i,Ue())))}:{success:!0,data:o.value}},xt=Ns(wt);var ai=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var Ms="(?:(?:\\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])))",Ls=new RegExp(`^${Ms}$`);var li=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Mn=/^-?\d+(?:\.\d+)?$/;var Ye=N("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Ts={number:"number",bigint:"bigint",object:"date"};var ui=N("$ZodCheckGreaterThan",(e,t)=>{Ye.init(e,t);let n=Ts[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 di=N("$ZodCheckMaxLength",(e,t)=>{var n;Ye.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Fn(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=Nn(i);r.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),fi=N("$ZodCheckMinLength",(e,t)=>{var n;Ye.init(e,t),(n=e._zod.def).when??(n.when=r=>{let i=r.value;return!Fn(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=Nn(i);r.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}});var Ln=N("$ZodCheckStringFormat",(e,t)=>{var n,r;Ye.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=()=>{})}),pi=N("$ZodCheckRegex",(e,t)=>{Ln.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}});var mi={major:4,minor:4,patch:3};var ye=N("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=mi;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=yt(s),u;for(let m of a){if(m._zod.def.when){if(ii(s)||!m._zod.def.when(s))continue}else if(c)continue;let p=s.issues.length,h=m._zod.check(s);if(h instanceof Promise&&l?.async===!1)throw new Te;if(u||h instanceof Promise)u=(u??Promise.resolve()).then(async()=>{await h,s.issues.length!==p&&(c||(c=yt(s,p)))});else{if(s.issues.length===p)continue;c||(c=yt(s,p))}}return u?u.then(()=>s):s},o=(s,a,l)=>{if(yt(s))return s.aborted=!0,s;let c=i(a,r,l);if(c instanceof Promise){if(l.async===!1)throw new Te;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 Te;return l.then(c=>i(c,r,a))}return i(l,r,a)}}Be(e,"~standard",()=>({validate:i=>{try{let o=_t(e,i);return o.success?{value:o.data}:{issues:o.error?.issues}}catch{return xt(e,i).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}))}),Tn=N("$ZodString",(e,t)=>{ye.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??li(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}}),Pn=N("$ZodStringFormat",(e,t)=>{Ln.init(e,t),Tn.init(e,t)});var yi=N("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=ai),Pn.init(e,t)});var wi=N("$ZodNumber",(e,t)=>{ye.init(e,t),e._zod.pattern=e._zod.bag.pattern??Mn,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 _i=N("$ZodUnknown",(e,t)=>{ye.init(e,t),e._zod.parse=n=>n});function gi(e,t,n){e.issues.length&&t.issues.push(...je(n,e.issues)),t.value[n]=e.value}var xi=N("$ZodArray",(e,t)=>{ye.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=>gi(c,n,s))):gi(l,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function Jt(e,t,n,r,i,o){let s=n in r;if(e.issues.length){if(i&&o&&!s)return;t.issues.push(...je(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 Rs(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=ri(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Os(e,t,n,r,i,o){let s=[],a=i.keySet,l=i.catchall._zod,c=l.def.type,u=l.optin==="optional",m=l.optout==="optional";for(let p in t){if(p==="__proto__"||a.has(p))continue;if(c==="never"){s.push(p);continue}let h=l.run({value:t[p],issues:[]},r);h instanceof Promise?e.push(h.then(f=>Jt(f,n,p,t,u,m))):Jt(h,n,p,t,u,m)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}var ki=N("$ZodObject",(e,t)=>{if(ye.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=ei(()=>Rs(t));Be(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 m of u.values)l[c].add(m)}}return l});let i=qt,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=[],m=s.shape;for(let p of s.keys){let h=m[p],f=h._zod.optin==="optional",b=h._zod.optout==="optional",w=h._zod.run({value:c[p],issues:[]},l);w instanceof Promise?u.push(w.then(v=>Jt(v,a,p,c,f,b))):Jt(w,a,p,c,f,b)}return o?Os(u,c,a,l,r.value,e):u.length?Promise.all(u).then(()=>a):a}});var $i=N("$ZodRecord",(e,t)=>{ye.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!zn(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(h=>Ve(h,r,Ue())),input:c,path:[c],inst:e});continue}let m=u.value,p=t.valueType._zod.run({value:i[c],issues:[]},r);p instanceof Promise?o.push(p.then(h=>{h.issues.length&&n.issues.push(...je(c,h.issues)),n.value[m]=h.value})):(p.issues.length&&n.issues.push(...je(c,p.issues)),n.value[m]=p.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"&&Mn.test(a)&&l.issues.length){let m=t.keyType._zod.run({value:Number(a),issues:[]},r);if(m instanceof Promise)throw new Error("Async schemas not supported in object keys currently");m.issues.length===0&&(l=m)}if(l.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(m=>Ve(m,r,Ue())),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(m=>{m.issues.length&&n.issues.push(...je(a,m.issues)),n.value[l.value]=m.value})):(u.issues.length&&n.issues.push(...je(a,u.issues)),n.value[l.value]=u.value)}}return o.length?Promise.all(o).then(()=>n):n}});var Si=N("$ZodEnum",(e,t)=>{ye.init(e,t);let n=Yr(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>ni.has(typeof i)).map(i=>typeof i=="string"?vt(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}}),Ai=N("$ZodLiteral",(e,t)=>{if(ye.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"?vt(r):r?vt(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 bi(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Fi=N("$ZodOptional",(e,t)=>{ye.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Be(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Be(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${ti(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=>bi(s,i)):bi(o,i)}return n.value===void 0?n:t.innerType._zod.run(n,r)}});var Ei=N("$ZodDefault",(e,t)=>{ye.init(e,t),e._zod.optin="optional",Be(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=>vi(o,t)):vi(i,t)}});function vi(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function zi(e,t){return new e({type:"string",...ie(t)})}function Ci(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ie(t)})}function Ii(e,t){return new e({type:"number",checks:[],...ie(t)})}function Ni(e){return new e({type:"unknown"})}function Rn(e,t){return new ui({check:"greater_than",...ie(t),value:e,inclusive:!0})}function On(e){return Rn(0,e)}function oe(e,t){return new di({check:"max_length",...ie(t),maximum:e})}function Qe(e,t){return new fi({check:"min_length",...ie(t),minimum:e})}function Zn(e,t){return new pi({check:"string_format",format:"regex",...ie(t),pattern:e})}var Ee=N("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");ye.init(e,t),e.def=t,e.type=t.type,e.parse=(n,r)=>Wt(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>_t(e,n,r),e.parseAsync=async(n,r)=>Kt(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>xt(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)=>In(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.apply=n=>n(e)}),Li=N("ZodMiniString",(e,t)=>{Tn.init(e,t),Ee.init(e,t)});function le(e){return zi(Li,e)}var Ds=N("ZodMiniStringFormat",(e,t)=>{Pn.init(e,t),Li.init(e,t)}),Us=N("ZodMiniEmail",(e,t)=>{yi.init(e,t),Ds.init(e,t)});function Xt(e){return Ci(Us,e)}var Bs=N("ZodMiniNumber",(e,t)=>{wi.init(e,t),Ee.init(e,t)});function Ti(e){return Ii(Bs,e)}var js=N("ZodMiniUnknown",(e,t)=>{_i.init(e,t),Ee.init(e,t)});function kt(){return Ni(js)}var Vs=N("ZodMiniArray",(e,t)=>{xi.init(e,t),Ee.init(e,t)});function Pe(e,t){return new Vs({type:"array",element:e,...ie(t)})}var Pi=N("ZodMiniObject",(e,t)=>{ki.init(e,t),Ee.init(e,t),Be(e,"shape",()=>t.shape)});function $t(e,t){let n={type:"object",shape:e??{},...ie(t)};return new Pi(n)}function Dn(e,t){return new Pi({type:"object",shape:e,catchall:kt(),...ie(t)})}var Mi=N("ZodMiniRecord",(e,t)=>{$i.init(e,t),Ee.init(e,t)});function Ri(e,t,n){return!t||!t._zod?new Mi({type:"record",keyType:le(),valueType:e,...ie(t)}):new Mi({type:"record",keyType:e,valueType:t,...ie(n)})}var Hs=N("ZodMiniEnum",(e,t)=>{Si.init(e,t),Ee.init(e,t),e.options=Object.values(t.entries)});function Oi(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Hs({type:"enum",entries:n,...ie(t)})}var Gs=N("ZodMiniLiteral",(e,t)=>{Ai.init(e,t),Ee.init(e,t)});function Zi(e,t){return new Gs({type:"literal",values:Array.isArray(e)?e:[e],...ie(t)})}var qs=N("ZodMiniOptional",(e,t)=>{Fi.init(e,t),Ee.init(e,t)});function ge(e){return new qs({type:"optional",innerType:e})}var Ws=N("ZodMiniDefault",(e,t)=>{Ei.init(e,t),Ee.init(e,t)});function Un(e,t){return new Ws({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Cn(t)}})}var Xs=200,Ys=["heading","paragraph","divider"];function he(e){return!Ys.includes(e.kind)}function dn(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 Qs(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 m=ao(u,c);if(m===void 0){s=!0;continue}a[l]=m,m!==c&&(s=!0)}return s?(r=!0,a):o});return r?i:t}function so(e,t){if(t==null||e.kind==="custom")return t;if(e.kind==="repeating_group")return Qs(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 ao(e,t){let n=so(e,t);return dn(n)?void 0:n}function lo(e){return e===void 0||!Number.isFinite(e)?0:Math.max(0,Math.min(6,Math.round(e)))}function co(e,t){let n=10**t,r=Math.round(Math.abs(e)*n)/n;return e<0?-r:r}function nt(e){return Number.isFinite(e)?e:null}function dt(e,t){switch(e.op){case"value":return or(t(e.fieldId));case"const":return nt(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=dt(r,t);if(i===null)return null;n.push(i)}return e.op==="add"?nt(n.reduce((r,i)=>r+i,0)):e.op==="mul"?nt(n.reduce((r,i)=>r*i,1)):e.op==="min"?Math.min(...n):Math.max(...n)}case"sub":case"div":{let n=dt(e.left,t);if(n===null)return null;let r=dt(e.right,t);return r===null?null:e.op==="sub"?nt(n-r):r===0?null:nt(n/r)}case"round":{let n=dt(e.arg,t);return n===null?null:nt(co(n,lo(e.decimals)))}case"if":return dt(mr(e.when,t)?e.then:e.else,t)}}function ea(e,t){let n=dt(e.calc,t);return n===null||e.decimals===void 0?n:nt(co(n,lo(e.decimals)))}function et(e,t){let n=Ne(e);if(!n.some(a=>a.kind==="calculated"))return t;let r=t,i=ar(e,r);for(let a=0;a<=n.length;a++){let l={},c=!1;for(let[u,m]of Object.entries(r))i.has(u)?l[u]=m:c=!0;if(!c)break;r=l,i=ar(e,r)}let o=At(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 Bn(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 Di(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 or(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 ta(e,t){let n=t(e.fieldId);switch(e.op){case"answered":return Bn(n);case"not_answered":return!Bn(n);case"eq":return Array.isArray(n)?n.some(r=>r===e.value):Di(n,e.value);case"neq":return Bn(n)?Array.isArray(n)?!n.some(r=>r===e.value):!Di(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=or(n),i=or(e.value);return r!==null&&i!==null&&(e.op==="gt"?r>i:r<i)}}}function mr(e,t){return e.length===0?!0:e.every(n=>ta(n,t))}function uo(e,t){return!e.visibleIf||e.visibleIf.length===0?!0:mr(e.visibleIf,t)}function jn(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 At(e,t){let n=new Set(e.map(l=>l.id)),r=e.filter(l=>l.kind==="calculated"),i=new Set(r.map(l=>l.id)),o={};for(let l of e){if(l.kind==="calculated")continue;let c=ao(l,t[l.id]);c!==void 0&&(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 h=jn(o,t,n,s,i,c);for(let f of r){let b=s.has(f.id)?ea(f,h):null;b===null?delete c[f.id]:c[f.id]=b}}let u=jn(o,t,n,s,i,c),m=new Set;for(let h of e)uo(h,u)&&m.add(h.id);let p=m.size===s.size&&[...m].every(h=>s.has(h))&&na(a,c);if(s=m,a=c,p)break}return{visible:s,calc:a,calcIds:i,resolve:jn(o,t,n,s,i,a)}}function na(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}function fo(e,t){return At(e,t).visible}function Vn(e,t,n){let r=At(Ne(e),n);return t.blocks.filter(i=>he(i)?r.visible.has(i.id):uo(i,r.resolve))}function Ne(e){return e.pages.flatMap(t=>t.blocks.filter(he))}function po(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 ho(e,t){let n=Ne(e),r=fo(n,t);return n.filter(i=>r.has(i.id))}function fn(e,t){let n=t&&typeof t=="object"&&!Array.isArray(t)?t:{},r=At(e.fields,n);return e.fields.filter(i=>r.visible.has(i.id))}function ra(e,t){return At(Ne(e),t).resolve}function mo(e,t,n){let i=e.pages.find(s=>s.id===t)?.next;if(!i||i.length===0)return{linear:!0};let o=ra(e,n);for(let s of i)if(mr(s.when,o))return s.to==="end"?{end:!0}:{to:s.to};return{linear:!0}}function ft(e,t,n){let r=[];if(e.pages.length===0)return r;let i=new Set,o=n===void 0?0:e.pages.findIndex(s=>s.id===n);for(let s=0;s<=e.pages.length;s++){let a=e.pages[o];if(!a||i.has(a.id))break;i.add(a.id),r.push(a.id);let l=mo(e,a.id,t);if("end"in l)break;if("to"in l){let c=e.pages.findIndex(u=>u.id===l.to);if(c<0)break;o=c}else if(o+=1,o>=e.pages.length)break}return r}function ia(e,t){return new Set(ft(e,t))}function sr(e,t,n){if("end"in mo(e,t,n))return!0;let r=ft(e,n);return r.length>0&&r[r.length-1]===t}function ar(e,t){let n=ia(e,t),r=fo(Ne(e),t),i=new Set;for(let o of e.pages)if(n.has(o.id))for(let s of o.blocks)he(s)&&r.has(s.id)&&i.add(s.id);return i}function go(e,t){let n=ar(e,t);return Ne(e).filter(r=>n.has(r.id))}var lt;function oa(){if(lt!==void 0)return lt??void 0;if(typeof Intl>"u"||typeof Intl.DisplayNames>"u"){lt=null;return}try{lt=new Intl.DisplayNames(void 0,{type:"region"})}catch{lt=null}return lt??void 0}function bo(e){try{return oa()?.of(e)??e}catch{return e}}var k=(e,t,n=[],r=[],i="")=>({iso2:e,name:bo(e),dialCode:t,lengths:n,groups:r,example:i}),sa=[k("US","1",[10],[3,3,4],"2015550123"),k("CA","1",[10],[3,3,4],"5145550123"),k("GB","44",[10],[4,6],"7400123456"),k("AU","61",[9],[3,3,3],"412345678"),k("DE","49",[10,11],[4,7],"15123456789"),k("FR","33",[9],[1,2,2,2,2],"612345678"),k("IN","91",[10],[5,5],"8123456789"),k("DK","45",[8],[2,2,2,2],"32123456"),k("SE","46",[9],[2,3,4],"701234567"),k("NO","47",[8],[3,2,3],"40612345"),k("FI","358",[9,10],[2,3,4],"412345678"),k("NL","31",[9],[1,4,4],"612345678"),k("BE","32",[9],[3,2,2,2],"470123456"),k("ES","34",[9],[3,3,3],"612345678"),k("IT","39",[9,10],[3,3,4],"3123456789"),k("PT","351",[9],[3,3,3],"912345678"),k("IE","353",[9],[2,3,4],"851234567"),k("CH","41",[9],[2,3,2,2],"781234567"),k("AT","43",[10,11],[3,7],"6641234567"),k("PL","48",[9],[3,3,3],"512345678"),k("CZ","420",[9],[3,3,3],"601123456"),k("GR","30",[10],[3,3,4],"6912345678"),k("RO","40",[9],[3,3,3],"712345678"),k("HU","36",[9],[2,3,4],"201234567"),k("UA","380",[9],[2,3,2,2],"501234567"),k("RU","7",[10],[3,3,2,2],"9123456789"),k("TR","90",[10],[3,3,2,2],"5012345678"),k("IL","972",[9],[2,3,4],"501234567"),k("AE","971",[9],[2,3,4],"501234567"),k("SA","966",[9],[2,3,4],"512345678"),k("ZA","27",[9],[2,3,4],"711234567"),k("NG","234",[10],[3,3,4],"8021234567"),k("KE","254",[9],[3,3,3],"712123456"),k("EG","20",[10],[3,3,4],"1001234567"),k("BR","55",[10,11],[2,5,4],"11961234567"),k("MX","52",[10],[3,3,4],"2221234567"),k("AR","54",[10],[4,6],"1123456789"),k("CL","56",[9],[1,4,4],"221234567"),k("CO","57",[10],[3,3,4],"3211234567"),k("PE","51",[9],[3,3,3],"912345678"),k("CN","86",[11],[3,4,4],"13123456789"),k("JP","81",[10],[2,4,4],"9012345678"),k("KR","82",[9,10],[2,4,4],"1023456789"),k("SG","65",[8],[4,4],"81234567"),k("HK","852",[8],[4,4],"51234567"),k("TW","886",[9],[3,3,3],"912345678"),k("MY","60",[9,10],[2,3,4],"123456789"),k("ID","62",[10,11],[3,4,4],"81234567890"),k("TH","66",[9],[2,3,4],"812345678"),k("PH","63",[10],[3,3,4],"9171234567"),k("VN","84",[9],[3,3,3],"912345678"),k("PK","92",[10],[3,3,4],"3012345678"),k("BD","880",[10],[2,4,4],"1812345678"),k("NZ","64",[9,10],[2,3,4],"211234567"),k("SK","421",[9],[3,3,3],"912123456"),k("BG","359",[9],[2,3,4],"481234567"),k("HR","385",[8,9],[2,3,4],"921234567"),k("RS","381",[8,9],[2,3,4],"601234567"),k("SI","386",[8],[2,3,3],"31234567"),k("LT","370",[8],[3,2,3],"61234567"),k("LV","371",[8],[2,3,3],"21234567"),k("EE","372",[7,8],[3,4],"51234567"),k("IS","354",[7],[3,4],"6111234"),k("LU","352",[9],[3,3,3],"628123456"),k("MA","212",[9],[3,3,3],"650123456"),k("CR","506",[8],[4,4],"83123456"),k("EC","593",[9],[2,3,4],"991234567"),k("UY","598",[8],[1,3,4],"94231234"),k("QA","974",[8],[4,4],"33123456"),k("KW","965",[8],[4,4],"50012345")],aa="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 la(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:bo(r),dialCode:i,lengths:[],groups:[],example:""})}return t}var Ft=[...sa,...la(aa)],pt=ca(Ft);function ca(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 ua=new Map(Ft.map(e=>[e.iso2,e])),da={"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 gr(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 pn(e){return e?ua.get(e.toUpperCase()):void 0}function vo(e){return pn(e?da[e]:void 0)}function fa(e){let t;for(let n of Ft)e.startsWith(n.dialCode)&&(!t||n.dialCode.length>t.dialCode.length)&&(t=n);return t}function Ie(e){return e.replace(/[^\d]/g,"")}function Et(e,t){let n=Ie(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 yo(e,t){let n=Ie(t);return n?`+${e.dialCode}${n}`:""}function zt(e,t,n){let r=(e??"").trim(),i=r.startsWith("+"),o=Ie(r);if(i){if(!o)return{national:"",e164:"",pending:!0,raw:r};let s=n?.previousDigits?Ie(n.previousDigits):"";if(s&&o===s)return{national:o,e164:`+${o}`,pending:!0,raw:r};let a=fa(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 pa(e){let{country:t,national:n,e164:r}=zt(e);if(!r)return!1;let i=Ie(r).length;return i<8||i>15?!1:t?.lengths.length?t.lengths.includes(n.length):n.length>=4}var ha=8;function wo(e,t){if(!e||!t||typeof window>"u")return"below";let n=ha,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)),m=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(m)}px`),t.style.setProperty("--fillo-phone-popover-offset-x","0px");let p=Math.min(t.offsetWidth,m),f=getComputedStyle(e).direction==="rtl"?o.right-p:o.left,b=0,w=f+p-(r-n);w>0&&(b-=w);let v=n-(f+b);return v>0&&(b+=v),t.style.setProperty("--fillo-phone-popover-offset-x",`${Math.round(b)}px`),l}var Ct="This field is required",R={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. Check the link or ask the form owner for help.",loadFailedNetwork:"Couldn't reach the server \u2014 check your connection and try again.",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 and try again."},Ui={submitFailed:R.submitFailed,loadFailedNotFound:R.loadFailedNotFound,loadFailedNetwork:R.loadFailedNetwork,formUnavailable:"This form is unavailable.",formClosed:R.closed,submitRateLimited:"Too many responses are being submitted right now. Wait a moment, then try again.",respondentUnrecognized:"This form couldn't verify who is responding. Ask the form owner for help.",fileUnavailable:"One of the uploaded files is no longer available. Remove it and upload it again.",scopeMissing:"We couldn't tell which entry this response belongs to. Answer the required field and try again.",challengeIncomplete:"Please complete the verification check, then submit.",challengeRetry:"That verification didn't go through. Please complete the check again and resubmit.",reviewAnswers:"We couldn't submit \u2014 please review your answers."};var ma={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 ga(e){return ma[e.kind]??Ct}var O={previewSkip:"Skip",required:Ct,requiredForField:ga,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 _o(e,t){return t.requiredForField?.(e)??t.required}var ba=$t({fileId:le().check(Qe(1)),name:le(),size:Ti().check(On()),mime:le(),url:ge(le())});function Hn(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 lr(e,t){if(dn(t))return e.kind==="calculated"?null:e.kind==="repeating_group"?Hn(e,0):e.required?Ct: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`:Xt().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"||!pa(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 Hn(e,0);let n=t;for(let r of n)if(!r||typeof r!="object"||Array.isArray(r))return"Invalid value";return Hn(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=Pe(ba).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 xo(e,t){let n={},r={};if(e.kind!=="calculated"){let i=so(e,t);if(e.kind==="repeating_group")va(e,i,n,r);else{let o=lr(e,i);o?n[e.id]=o:dn(i)||(r[e.id]=i)}}return{ok:Object.keys(n).length===0,errors:n,data:r}}function ko(e,t){let n=go(e,t),r={},i={};for(let o of n){let s=xo(o,t[o.id]);Object.assign(r,s.errors),Object.assign(i,s.data)}return{ok:Object.keys(r).length===0,errors:r,data:i}}function va(e,t,n,r){let i=lr(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 fn(e,l)){let m=l[u.id],p=lr(u,m);p?n[`${e.id}.${a}.${u.id}`]=p:dn(m)||(c[u.id]=m)}s.push(c)}!i&&s.length>0&&(r[e.id]=s)}var ya=["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"],wa=["heading","paragraph","divider"],_a=[...ya,...wa],br=le().check(Qe(1),oe(128)),Gn=Dn({id:br,label:le().check(oe(1e3)),icon:ge(kt())}),xa=Dn({id:br,kind:Oi(_a),label:ge(le().check(oe(2e3))),options:ge(Pe(Gn).check(oe(200))),rows:ge(Pe(Gn).check(oe(200))),columns:ge(Pe(Gn).check(oe(200)))}),ka=$t({id:br,title:ge(le().check(oe(500))),blocks:Pe(xa).check(oe(500)),next:ge(kt())}),$a=$t({version:Zi(1),title:Un(ge(le().check(oe(2e3))),""),description:ge(le().check(oe(5e3))),pages:Pe(ka).check(Qe(1),oe(50)),settings:Un(ge(Ri(le(),kt())),{})}),Sa=1,cr=1,ur="0.29.1";function we(e,t,n=""){return typeof e=="string"?e.trim().slice(0,t):n}function X(e,t){let n=we(e,t);return n===""?void 0:n}function Yt(e,t){if(typeof e!="string")return;let n=e.slice(0,t);return n.trim()===""?void 0:n}function Ce(e){return typeof e=="boolean"?e:void 0}function $e(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function ze(e,t,n,r){let i=$e(e);return i===void 0?r:Math.max(t,Math.min(n,Math.round(i)))}function Qt(e,t=200){return Array.isArray(e)?e.slice(0,t).flatMap(n=>{if(!n||typeof n!="object")return[];let r=n,i=we(r.id,128),o=we(r.label,1e3),s=r.icon==="thumbs_up"||r.icon==="thumbs_down"?r.icon:void 0;return i&&o?[B({id:i,label:o,icon:s})]:[]}):[]}function ln(e){let t=new Set;for(let{id:n}of e){if(t.has(n))return n;t.add(n)}}function vr(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=we(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 $o(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(!$o(o,t,n,r))return!1;return!0}function Aa(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=vr(c);return Array.isArray(c)&&c.length>0&&u===void 0?[]:u&&u.some(m=>!$o(m.fieldId,i,r,new Set))?[]:[{when:u??[],to:l}]});return o.length?o:void 0}var Fa=["number","rating","linear_scale","calculated"];function qe(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=we(n.fieldId,128);return r?{op:"value",fieldId:r}:null}case"const":{let r=$e(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=qe(i,t+1);if(!o)return null;r.push(o)}return{op:n.op,args:r}}case"sub":case"div":{let r=qe(n.left,t+1),i=qe(n.right,t+1);return r&&i?{op:n.op,left:r,right:i}:null}case"round":{let r=qe(n.arg,t+1);return r?B({op:"round",arg:r,decimals:$e(n.decimals)===void 0?void 0:ze(n.decimals,0,6,0)}):null}case"if":{if(!Array.isArray(n.when))return null;let r=vr(n.when)??[];if(r.length!==n.when.length)return null;let i=qe(n.then,t+1),o=qe(n.else,t+1);return i&&o?{op:"if",when:r,then:i,else:o}:null}default:return null}}function We(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)We(r,t,n);return;case"sub":case"div":We(e.left,t,n),We(e.right,t,n);return;case"round":We(e.arg,t,n);return;case"if":for(let r of e.when)n.add(r.fieldId);We(e.then,t,n),We(e.else,t,n);return}}function Ea(e,t){let n=new Map;for(let s of e)for(let a of s.blocks)he(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=qe(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;We(l,c,u);for(let m of c){let p=n.get(m);if(p===void 0){let h=t.get(m);return h!==void 0?`Calculated field ${a.id} references ${m}, which is a child of repeating group ${h} \u2014 calculations can't reach inside a repeating group (calc operands must be top-level fields)`:`Calculated field ${a.id} references a missing field: ${m} \u2014 remove the reference or restore that field`}if(!Fa.includes(p))return`Calculated field ${a.id} references non-numeric field ${m} (${p}) \u2014 calculations can read number, rating, linear_scale, and calculated fields only`}r.set(a.id,[...c,...u].filter(m=>n.get(m)==="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 Bi=100,ji=5e3;function rt(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+rt(n),0);case"sub":case"div":return 1+rt(e.left)+rt(e.right);case"round":return 1+rt(e.arg);case"if":return 1+rt(e.then)+rt(e.else)}}function za(e){let t=0,n=0;for(let r of e)for(let i of r.blocks)i.kind==="calculated"&&(t+=1,n+=rt(i.calc));return t>Bi?`Form has ${t} calculated fields \u2014 the maximum is ${Bi}; remove some or consolidate them into fewer expressions`:n>ji?`Calculated expressions total ${n} operations \u2014 the maximum is ${ji} across the form; simplify or split up the calculations`:null}var Vi=["short_text","long_text","email","url","phone","number","select","multi_select","dropdown","checkbox","date","rating","linear_scale"],Hi=12,Gi=18e4;function Ca(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 Ia(e){return e.fields.reduce((n,r)=>n+Ca(r),24)*(Number.isFinite(e.maxInstances)?e.maxInstances:0)}function Na(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>Hi)return`Repeating group ${n.id} has ${n.fields.length} template fields \u2014 the maximum is ${Hi}; split it into fewer fields`;for(let a of n.fields)if(!Vi.includes(a.kind))return`Repeating group ${n.id} has a "${a.kind}" child (${a.id}) \u2014 allowed child kinds are ${Vi.join(", ")}`;let i=ln(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=Ia(n);if(s>Gi)return`Repeating group ${n.id} could reach ~${Math.ceil(s/1e3)}KB at ${n.maxInstances} instances \u2014 the maximum is ~${Math.round(Gi/1e3)}KB; lower maxInstances, shorten text limits, or trim the template`}return null}function Ma(e){let t=new Set;for(let r of e)for(let i of r.blocks)he(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 La(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 So(e){return{id:we(e.id,128),visibleIf:vr(e.visibleIf)}}function te(e,t){return{...So(e),kind:t,label:we(e.label,2e3,"Untitled field"),description:X(e.description,5e3),required:Ce(e.required),placeholder:X(e.placeholder,500)}}function qi(e){let t=X(e,2e3);if(t)try{let n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"?t:void 0}catch{return}}function Ta(e){if(!e||typeof e!="object")return;let t=e,n=t.by==="browser"||t.by==="field"||t.by==="identify"||t.by==="email"?t.by:void 0;if(!n)return;let r=n==="field"?X(t.field,128):void 0;if(n==="field"&&!r)return;let i=X(t.scopeField,128),o=t.onRepeat==="update"&&(n==="identify"||n==="email")?"update":"keep";return{by:n,...r?{field:r}:{},...i?{scopeField:i}:{},onRepeat:o}}function Pa(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 Ra(e){let t=e&&typeof e=="object"?e:{};return{submitMode:t.submitMode==="button"||t.submitMode==="auto"?t.submitMode:void 0,submitLabel:X(t.submitLabel,100),successTitle:X(t.successTitle,200),successMessage:X(t.successMessage,5e3),redirectUrl:qi(t.redirectUrl),showProgress:Ce(t.showProgress),responseLimit:Ta(t.responseLimit),trust:Pa(t.trust),notifyEmail:Xt().check(oe(254)).safeParse(t.notifyEmail).success?t.notifyEmail:void 0,notifyEmailIncludeAnswers:Ce(t.notifyEmailIncludeAnswers),notifyEmailAnswerFields:Pe(le().check(Qe(1),oe(128),Zn(/\S/))).check(oe(500)).safeParse(t.notifyEmailAnswerFields).success?[...new Set(t.notifyEmailAnswerFields.map(r=>r.trim()))]:void 0,notifyEmailReplyToField:X(t.notifyEmailReplyToField,128),sendReceipt:Ce(t.sendReceipt),saveProgress:Ce(t.saveProgress),draftAnswersVisible:Ce(t.draftAnswersVisible),resumeEmails:Ce(t.resumeEmails),resumeUrl:qi(t.resumeUrl),draftDigest:Ce(t.draftDigest)}}function B(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function Ao(e){if(!e||typeof e!="object")return null;let t=e,n=t.kind,r=So(t);if(!r.id||typeof n!="string")return null;switch(n){case"heading":return B({...r,kind:n,text:we(t.text,2e3,"Section")});case"paragraph":return B({...r,kind:n,text:we(t.text,5e3)});case"divider":return B({...r,kind:n});case"short_text":case"email":case"url":return B({...te(t,n),maxLength:$e(t.maxLength)===void 0?void 0:ze(t.maxLength,1,2e3,2e3)});case"phone":{let i=X(t.defaultCountry,2)?.toUpperCase();return B({...te(t,n),defaultCountry:i&&/^[A-Z]{2}$/.test(i)?i:void 0})}case"long_text":return B({...te(t,n),maxLength:$e(t.maxLength)===void 0?void 0:ze(t.maxLength,1,2e4,2e4)});case"number":return B({...te(t,n),min:$e(t.min),max:$e(t.max),decimals:$e(t.decimals)===void 0?void 0:ze(t.decimals,0,6,0),prefix:Yt(t.prefix,100),suffix:Yt(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=Qt(t.options);return i.length===0?null:B({...te(t,n),options:i,allowOther:Ce(t.allowOther),shuffleOptions:Ce(t.shuffleOptions)})}case"checkbox":{let i=t.appearance==="toggle"?"toggle":void 0;return B({...te(t,n),appearance:i})}case"signature":return B(te(t,n));case"date":return B({...te(t,n),defaultToday:t.defaultToday===!0?!0:void 0});case"rating":{let i=ze(t.max,1,10,5);return B({...te(t,n),max:i,insightsMetric:t.insightsMetric==="csat"&&i===5?"csat":void 0})}case"linear_scale":{let i=ze(t.min,0,9,1),o=ze(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 B({...te(t,n),min:i,max:o,minLabel:X(t.minLabel,100),maxLabel:X(t.maxLabel,100),insightsMetric:s})}case"ranking":{let i=Qt(t.options);return i.length<2?null:B({...te(t,n),options:i})}case"matrix":{let i=Qt(t.rows),o=Qt(t.columns);return i.length===0||o.length===0?null:B({...te(t,n),rows:i,columns:o})}case"hidden":return B({...te(t,n),required:!1,paramName:X(t.paramName,128),defaultValue:X(t.defaultValue,1e3)});case"calculated":return B({...te(t,n),required:!1,calc:t.calc,decimals:$e(t.decimals)===void 0?void 0:ze(t.decimals,0,6,0),prefix:Yt(t.prefix,100),suffix:Yt(t.suffix,100)});case"file_upload":return B({...te(t,n),maxFiles:ze(t.maxFiles,1,Xs,1),maxFileSizeMb:ze(t.maxFileSizeMb,1,5e3,500),accept:Array.isArray(t.accept)?t.accept.flatMap(i=>{let o=X(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=Ao(s);return a&&he(a)?[a]:[]});return B({...te(t,n),required:!1,fields:o,maxInstances:$e(t.maxInstances)??Number.NaN,minInstances:$e(t.minInstances),addLabel:X(t.addLabel,100),itemLabel:X(t.itemLabel,100)})}case"custom":return B({...te(t,n),component:we(t.component,128),config:t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?t.config:void 0});default:return null}}function Ke(e){let t=$a.safeParse(e);if(!t.success){let w=t.error.issues[0],v=w?.path.join(".");return{ok:!1,error:w?`${v?`${v}: `:""}${w.message}`:"Invalid schema"}}if(t.data.version>Sa)return{ok:!1,error:`Unsupported schema version: ${t.data.version}`};let n=t.data.pages.map(w=>{let v=w.blocks.flatMap(S=>{let C=Ao(S);return C?[C]:[]});return{id:we(w.id,128),title:X(w.title,500),blocks:v,next:w.next}}),r=new Set(n.map(w=>w.id)),i=new Map;for(let w of n)for(let v of w.blocks){if(v.kind!=="calculated")continue;let S=new Set,C=qe(v.calc);if(C){let z=new Set,ue=new Set;We(C,z,ue);for(let Y of z)S.add(Y);for(let Y of ue)S.add(Y)}i.set(v.id,S)}let o=new Set,s=n.map(w=>{for(let v of w.blocks)he(v)&&o.add(v.id);return B({id:w.id,title:w.title,blocks:w.blocks,next:Aa(w.next,r,w.id,new Set(o),i)})}),a=new Set,l=new Set;for(let w of s){if(!w.id)return{ok:!1,error:"Page ids cannot be blank"};if(a.has(w.id))return{ok:!1,error:`Duplicate page id: ${w.id}`};a.add(w.id);for(let v of w.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 S=ln(v.options);if(S)return{ok:!1,error:`Duplicate option id in field ${v.id}: ${S}`}}else if(v.kind==="matrix"){let S=ln(v.rows);if(S)return{ok:!1,error:`Duplicate matrix row id in field ${v.id}: ${S}`};let C=ln(v.columns);if(C)return{ok:!1,error:`Duplicate matrix column id in field ${v.id}: ${C}`}}}}let c=Na(s);if(c)return{ok:!1,error:c};let u=Ma(s),m=La(s,n,u);if(m)return{ok:!1,error:m};let p=Ea(s,u);if(p)return{ok:!1,error:p};let h=za(s);if(h)return{ok:!1,error:h};if(s.every(w=>w.blocks.length===0))return{ok:!1,error:"Schema must contain at least one valid block"};let f={version:cr,title:we(t.data.title,2e3),pages:s,settings:Ra(t.data.settings)},b=X(t.data.description,5e3);return b&&(f.description=b),{ok:!0,schema:f}}function St(e,t){let n=X(e,t);if(n&&!(/[;{}<>]/.test(n)||/url\s*\(/i.test(n)))return n}function Oa(e){return typeof e=="string"&&/^[A-Za-z0-9_-]{8,64}$/.test(e)?e:void 0}function Wi(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,n=B({primary:St(t.primary,200),background:St(t.background,200),text:St(t.text,200),logo:Oa(t.logo)});return Object.keys(n).length>0?n:void 0}function Fo(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=B({colorScheme:n,...Wi(t),radius:St(t.radius,64),fontFamily:St(t.fontFamily,200),dark:Wi(t.dark)});return Object.keys(r).length>0?r:null}function Za(e){throw new Error(`Unhandled field kind: ${JSON.stringify(e)}`)}function yr(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)?yr(o,a[o.id]):"").filter(a=>a!=="");return s.length>0?`${i}: ${s.join(", ")}`:i}case"phone":{let{country:n,national:r,e164:i}=zt(String(t));if(!i)return String(t);let o=Et(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 Za(e)}}function Da(e){return Math.max(0,Math.min(6,Math.round(e)))}function Eo(e){switch(e){case"grouped-comma":return"en-US";case"grouped-dot":return"de-DE";case"grouped":case void 0:return}}function zo(e,t){if(!Number.isFinite(e))return String(e);let n=t?.decimals===void 0?void 0:Da(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 Co(e,t){return t?e.split(t).join(""):e}function Ki(e,t){return t==="."?e:e.split(t).join(".")}function Ua(e,t,n){if(n!==t&&e.includes(n)){let o=e.lastIndexOf(n),s=Co(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 wr(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=Ki(o.replace(/\s/g,""),i):r==="."||r===","?o=Ua(o,r,i):o=Ki(Co(o,r),i),o===""||o==="."||!/^\d*\.?\d*$/.test(o)?e:s?`-${o}`:o}function It(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(m=>m.type==="group")?.value??",",s=i.find(m=>m.type==="decimal")?.value??".",a=o===".",l=/^\s$/.test(o),c=a?[s]:Array.from(new Set([".",s])),u=0;for(let m of r)if(!/\d/.test(m)){if(c.includes(m)){if(++u>1)return!1;continue}if(!(l?/\s/.test(m):m===o))return!1}return!0}var dr="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Ba=256-256%dr.length;function Ji(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<Ba&&(n+=dr[o%dr.length])}}return n}var Io=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}},en="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function _r(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+=en[r>>2],t+=en[(r&3)<<4|i>>4],t+=n+1<e.length?en[(i&15)<<2|o>>6]:"=",t+=n+2<e.length?en[o&63]:"="}return t}var ja=e=>_r(new Io().update(e).digest()),E=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 be(e){return e instanceof Error&&e.name==="FilloError"}async function Xi(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 tn(e){let t=Number(e.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t:void 0}var ct=3,Va=4,tt=3e4,Ha=5*6e4,ke=10*6e4;function nn(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 qn(e,t=!1){let n=be(e)?e.status??0:0;return n===0||n===503||n===504||t&&n===409&&be(e)&&e.retryAfterSec!==void 0}function rn(e){return e>=500||e===429||e===408}function Wn(e){return typeof DOMException<"u"&&e instanceof DOMException&&e.name==="TimeoutError"?new E("Request timed out",0):e}function Ga(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 qa(e){if(e.schemaVersion!==void 0&&e.schemaVersion!==cr)throw new E(`This form uses schema version ${e.schemaVersion}; this SDK supports version ${cr}. Update @usefillo/* to render it.`,426);if(e.minSdkVersion&&Ga(ur,e.minSdkVersion)<0)throw new E(`This form requires @usefillo/* ${e.minSdkVersion} or newer. Current SDK is ${ur}.`,426)}function on(e,t){return n=>t.onProgress?.({uploadedBytes:n,totalBytes:e,fraction:e===0?1:n/e})}async function Wa(e){let t=globalThis.crypto?.subtle;if(t){let n=await t.digest("SHA-1",e);return _r(new Uint8Array(n))}return ja(e)}var Ka="https://fillo.so",Kn={"X-Fillo-Client":`@usefillo/core@${ur}`},hn=class{baseUrl;fetch;activeUploads=0;uploadQueue=new Set;key;constructor(e={}){this.baseUrl=e.baseUrl?e.baseUrl.replace(/\/$/,""):e.sameOrigin?"":Ka,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",...Kn,...t?.headers}:t?.headers,r;try{r=await this.fetch(this.url(e),{...t,headers:n,signal:t?.signal??AbortSignal.timeout(tt)})}catch(i){throw Wn(i)}if(!r.ok){let{message:i,code:o}=await Xi(r,`Request failed: ${r.status}`);throw new E(i,r.status,tn(r),o)}return await r.json()}async getForm(e){let t=await this.json(`/forms/${encodeURIComponent(e)}`);return qa(t),t}syncForm(e,t,n){if(!this.key)return Promise.reject(new E("createClient needs a `key` (pk_\u2026) to sync code-defined forms",401));let r=Ke(t);return r.ok?this.json("/forms/sync",{method:"POST",body:JSON.stringify({key:this.key,id:e,schema:r.schema,theme:Fo(n)})}):Promise.reject(new E(`Invalid form schema: ${r.error}`,400))}async reportInvalidDefinition(e,t){try{let n="formId"in e?{formId:e.formId}:this.key?{key:this.key,id:e.handle}:null;if(!n)return null;let r=await this.fetch(this.url("/forms/definition-report"),{method:"POST",headers:{"Content-Type":"application/json",...Kn},body:JSON.stringify({...n,schema:t}),signal:AbortSignal.timeout(tt)});if(!r.ok)return null;let i=await r.json();return typeof i.formId=="string"&&i.formId?i.formId:null}catch{return null}}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",...Kn},body:JSON.stringify({data:t,meta:n}),signal:AbortSignal.timeout(tt)})}catch(o){throw Wn(o)}if(r.status===422){let o=await r.json().catch(()=>null);if(o?.errors&&typeof o.errors=="object"&&!Array.isArray(o.errors))return{ok:!1,errors:o.errors};throw new E(typeof o?.error=="string"&&o.error?o.error:"Submit failed: 422",422,tn(r),typeof o?.code=="string"&&o.code?o.code:void 0)}if(!r.ok){let{message:o,code:s}=await Xi(r,`Submit failed: ${r.status}`);throw new E(o,r.status,tn(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(be(r)&&(r.status===404||r.status===403))return null;throw r}}async startSession(e,t){try{let n=await this.fetch(this.url(`/forms/${encodeURIComponent(e)}/sessions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageCount:t}),signal:AbortSignal.timeout(tt)});return n.ok?(await n.json()).id:null}catch{return null}}reportProgress(e,t){try{this.fetch(this.url(`/sessions/${encodeURIComponent(e)}/progress`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0,signal:AbortSignal.timeout(tt)}).catch(()=>{})}catch{}}createDraft(e,t){return this.json(`/forms/${encodeURIComponent(e)}/drafts`,{method:"POST",body:JSON.stringify(t)})}getDraft(e,t,n){return this.json(`/drafts/${encodeURIComponent(e)}`,{headers:n?{"X-Fillo-Draft-Token":t,"X-Fillo-Draft-Adopt":"1"}:{"X-Fillo-Draft-Token":t}})}async saveDraft(e,t,n,r){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"X-Fillo-Draft-Token":t},body:JSON.stringify(n),...r?.keepalive?{keepalive:!0}:{}})}async deleteDraft(e,t){await this.json(`/drafts/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-Fillo-Draft-Token":t}})}getUploadSession(e,t,n=AbortSignal.timeout(ke)){return this.json(`/uploads/${encodeURIComponent(e)}`,{...t?{headers:{"X-Fillo-Upload-Token":t}}:{},signal:n})}async uploadFile(e,t,n){await this.acquireUploadSlot(n.signal);try{return n.signal?.throwIfAborted(),await this.performUpload(e,t,n)}finally{this.activeUploads-=1;let r=this.uploadQueue.values().next().value;r&&(this.uploadQueue.delete(r),r())}}async acquireUploadSlot(e){if(e?.throwIfAborted(),this.activeUploads<Va){this.activeUploads+=1;return}await new Promise((t,n)=>{let r=()=>{e?.removeEventListener("abort",i),this.activeUploads+=1,t()},i=()=>{this.uploadQueue.delete(r),n(e?.reason)};this.uploadQueue.add(r),e?.addEventListener("abort",i,{once:!0})})}async performUpload(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,ke));if(c.formId!==e||c.fieldId!==n.fieldId||c.fileName!==r||c.size!==t.size||c.mime.trim().toLowerCase()!==i)throw new E("File does not match this upload session",400);o=c,o.token||=n.uploadToken}else{let c=Ji(24),u=Ji(32),m=()=>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,ke)}),p=Date.now()+ke,h=250;for(;;)try{o=await m();break}catch(f){if(n.signal?.aborted||!qn(f,!0))throw f;let b=p-Date.now();if(b<=0)throw f;await nn(Math.min(h,b),n.signal),h=Math.min(h*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 E("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 E("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,ke)}),l;try{l=await a()}catch(c){if(n.signal?.aborted||!qn(c))throw c;let u=Date.now()+ke,m=250;for(;;){let p=await this.getUploadSession(o.id,o.token,this.uploadSignal(n,Math.max(1,u-Date.now())));if(p.status==="complete"&&p.file)return p.file;if(p.status==="aborted")throw c;try{l=await a();break}catch(f){if(n.signal?.aborted||!qn(f,!0))throw f}let h=u-Date.now();if(h<=0)throw c;await nn(Math.min(m,h),n.signal),m=Math.min(m*2,5e3)}}if(!l.file)throw new E("Upload completed but no file was returned");return l.file}async boxUpload(e,t,n){let r=on(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 b=await this.retry(n,async()=>{let v=await this.fetch(e.uploadUrl,{method:"POST",headers:i,body:f,signal:this.uploadSignal(n)});if(!v.ok&&rn(v.status))throw new E(`Box upload failed: ${v.status}`,v.status);return v});if(!b.ok)throw new E(`Box upload failed: ${b.status}`,b.status);let w=await b.json();return r(t.size),{providerFileId:w.entries?.[0]?.id}}if(e.size!==t.size)throw new E(`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&&rn(f.status))throw new E(`Box session failed: ${f.status}`,f.status);return f});if(!o.ok)throw new E(`Box session failed: ${o.status}`,o.status);let s=await o.json(),a=new Io,l=[],c=0;for(;c<t.size;){n.signal?.throwIfAborted();let f=Math.min(c+s.part_size,t.size),b=new Uint8Array(await t.slice(c,f).arrayBuffer());a.update(b);let w=await Wa(b),v=await this.retry(n,async()=>{let S=await this.fetch(s.session_endpoints.upload_part,{method:"PUT",headers:{...i,"Content-Type":"application/octet-stream",Digest:`sha=${w}`,"Content-Range":`bytes ${c}-${f-1}/${t.size}`},body:b,signal:this.uploadSignal(n)});if(!S.ok&&rn(S.status))throw new E(`Box part failed: ${S.status}`,S.status);return S});if(!v.ok)throw new E(`Box part failed: ${v.status}`,v.status);l.push((await v.json()).part),c=f,r(c)}let u=Date.now()+ke,m=JSON.stringify({parts:l}),p={...i,"Content-Type":"application/json",Digest:`sha=${_r(a.digest())}`},h=0;for(;;){n.signal?.throwIfAborted();let f=u-Date.now();if(f<=0)throw new E("Box upload processing timed out",0);let b;try{if(b=await this.fetch(s.session_endpoints.commit,{method:"POST",headers:p,body:m,signal:this.uploadSignal(n,Math.min(tt,f))}),!b.ok&&rn(b.status))throw new E(`Box commit failed: ${b.status}`,b.status)}catch(S){if(n.signal?.throwIfAborted(),++h>=ct)throw Wn(S);await nn(Math.min(500*2**h,Math.max(0,u-Date.now())),n.signal);continue}if(h=0,b.status===202){let S=tn(b),C=Date.parse(b.headers.get("retry-after")??""),z=S!==void 0?S*1e3:Number.isFinite(C)?Math.max(1e3,C-Date.now()):1e3;await b.body?.cancel().catch(()=>{}),await nn(Math.min(z,Math.max(0,u-Date.now())),n.signal);continue}if(!b.ok)throw new E(`Box commit failed: ${b.status}`,b.status);let v=(await b.json()).entries?.[0]?.id;if(typeof v!="string"||!v)throw new E("Box upload completed but no file was returned",502);return{providerFileId:v}}}uploadSignal(e,t=tt){let n=AbortSignal.timeout(t);return e.signal?AbortSignal.any([e.signal,n]):n}async retry(e,t){let n=0;for(;;)try{return await t()}catch(r){if(e.signal?.aborted||(n+=1,n>=ct))throw r;await new Promise(i=>setTimeout(i,500*2**n))}}async driveUploadLoop(e,t,n,r){let i=e.uploadedBytes,o=on(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 m=await this.fetch(t,{method:"PUT",headers:{"Content-Range":`bytes ${i}-${l-1}/${n.size}`},body:c,signal:this.uploadSignal(r)});if(m.status===308){let p=m.headers.get("Range")??m.headers.get("range"),h=p?.match(/bytes=0-(\d+)/);h?i=Number(h[1])+1:p==null?i=0:i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ke))).uploadedBytes;break}if(m.ok){i=n.size;break}throw new E(`Drive chunk failed: ${m.status}`,m.status)}catch(m){if(r.signal?.aborted||(u+=1,u>=ct))throw m;if(await new Promise(h=>setTimeout(h,500*2**u)),i=(await this.getUploadSession(e.id,e.token,this.uploadSignal(r,ke))).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>=ct)throw new E("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 E("S3 upload session returned invalid progress",502);let r=on(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 E("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,ke)});if(typeof u.uploadUrl!="string"||!u.uploadUrl)throw new E("S3 part URL was unavailable",502);c=u.uploadUrl;let m=await this.fetch(c,{method:"PUT",body:a,signal:this.uploadSignal(n,Ha)});if(!m.ok)throw new E(`S3 part upload failed: ${m.status}`,m.status);i=s,r(i);break}catch(u){if(n.signal?.aborted)throw u;let m=await this.getUploadSession(e.id,e.token,this.uploadSignal(n,ke));if(m.status==="aborted")throw new E("This upload session was cancelled",409);if(!Number.isSafeInteger(m.uploadedBytes)||m.uploadedBytes<i||m.uploadedBytes>t.size||m.uploadedBytes<t.size&&m.uploadedBytes%e.chunkSize!==0)throw new E("S3 upload session returned invalid progress",502);if(m.uploadedBytes>i){i=m.uploadedBytes,r(i);break}if(l+=1,l>=ct)throw u;await new Promise(p=>setTimeout(p,500*2**l))}}}}async s3PutUpload(e,t,n){let r=on(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 E(`S3 upload failed: ${o.status}`,o.status);r(t.size);return}catch(o){if(n.signal?.aborted||(i+=1,i>=ct))throw o;await new Promise(s=>setTimeout(s,500*2**i))}}};function Me(e={}){return new hn(e)}function Jn(e){let t=e.trim();if(!/^-?\d*\.?\d+$/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function Ja(e=new Date){let t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${e.getFullYear()}-${t}-${n}`}function Yi(e,t,n=new Date){let r=null;for(let i of Ne(e))i.kind!=="date"||!i.defaultToday||t[i.id]!==void 0||(r=r??{...t},r[i.id]=Ja(n));return r??t}function Qi(e,t){let n={};for(let r of Ne(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=Jn(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=Jn(i);o!==null&&Number.isInteger(o)&&o>=1&&o<=(r.max??5)&&(n[r.id]=o);break}case"linear_scale":{let o=Jn(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 Xa(){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 Ya={id:"empty",blocks:[]},eo=!1,to=!1;function Qa(){to||(to=!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 project handle, or pass formId for a dashboard-built form: https://fillo.so/docs"))}function el(){eo||(eo=!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 No=new Map,it=new Set;function xr(){try{return globalThis.localStorage??null}catch{return null}}function Mo(e){return`fillo:submission:${e}`}function cn(){let e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();let t=new Uint8Array(16);return e?.getRandomValues?(e.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")):`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function Lo(e,t,n,r){if(it.has(t))return e.get(n)??null;let i=xr();if(!i)return e.get(n)??null;let o;try{o=i.getItem(t)}catch{return e.get(n)??null}try{let s=JSON.parse(o??"null");if(s&&r(s))return s}catch{}return null}function To(e,t,n,r){e.set(n,r);let i=xr();if(!i){it.add(t);return}try{i.setItem(t,JSON.stringify(r)),it.delete(t)}catch{it.add(t)}}function kr(e){return Lo(No,Mo(e),e,t=>typeof t.key=="string")}function Po(e,t){To(No,Mo(e),e,t)}function tl(e){let t=kr(e);if(t?.key)return t.key;let n={key:cn()};return Po(e,n),n.key}function nl(e,t){let n=kr(e);Po(e,{key:n?.key??cn(),submittedAt:new Date().toISOString(),responseId:t})}function fr(e,t,n){let r=po(e.settings,n);return r===null?t:`${t}::${r}`}function Xn(e,t,n){return e.settings.responseLimit?.by!=="browser"||!t?!1:!!kr(fr(e,t,n))?.submittedAt}var $r=new Map,Sr=new Map,un=new Map;function W(e){return Sr.get(e)??0}function sn(e,t,n){return Math.max(un.get(JSON.stringify(["person",e,t??null]))??0,n?un.get(JSON.stringify(["draft",e,n]))??0:0)}function Ar(e){return`fillo:draft:${e}`}function Ge(e,t){let n=Lo($r,Ar(e),e,r=>{let i=r;return typeof i.id=="string"&&typeof i.token=="string"});return n?.respondentId&&t&&n.respondentId!==t?null:n}function ut(e,t,n){Sr.set(e,W(e)+1),To($r,Ar(e),e,{...t,respondentId:n??t.respondentId})}function Yn(e,t=!1,n){let r=t?Ge(e):null,i=W(e)+1;Sr.set(e,i),t&&(un.set(JSON.stringify(["person",e,n??r?.respondentId??null]),i),r&&un.set(JSON.stringify(["draft",e,r.id]),i)),$r.delete(e);let o=Ar(e),s=xr();if(!s){it.add(o);return}try{s.removeItem(o),it.delete(o)}catch{it.add(o)}}function Qn(e){return be(e)&&(e.status===401||e.status===403||e.status===404)}var rl=1500;function Ro(e,t){if(be(e)){let n=e.status??0;if(n===404)return t.loadFailedNotFound;switch(e.code){case"submit_rate_limited":return t.submitRateLimited;case"workspace_unavailable":case"provision_closed":return t.formClosed;case"respondent_unrecognized":return t.respondentUnrecognized;case"invalid_file_reference":return t.fileUnavailable;case"response_scope_missing":return t.scopeMissing}if(n>0)return t.submitFailed}return t.loadFailedNetwork}function il(e,t,n){if(be(e)){let r=e.status??0;if(t&&r>0&&e.message)return e.code?`${e.message} (${e.code})`:e.message;if(r>0&&r<500&&r!==408&&r!==429)return n.formUnavailable;if(r>0)return n.submitFailed}return Ro(e,n)}function Oo(e){let{onChange:t,onSubmitted:n}=e,r={...Ui,...e.respondentErrorStrings},i=Ke(e.form);if(!i.ok)throw new Error(`Invalid form schema: ${i.error}`);let o=i.schema,s=e.formId,a=e.client,l=e.respondent,c=l?.id,u=0,m={...e.initialData??{}},p=et(o,{...m}),h={},f=0,b,w=[];function v(){return e.previewNavigation===!0&&e.skipValidation===!0&&!a&&!s&&!e.resolveFormId}function S(){return ft(o,p,v()?b:void 0)}function C(){v()&&w.push({pageIndex:f,startPageId:b})}let z="idle",ue=!1,Y=!1,me=!1,Z=0,_e=new Set,Re=!1;queueMicrotask(()=>{if(Y||me)return;if(typeof location<"u"&&location.search){let _=Object.fromEntries(new URLSearchParams(location.search)),x=null;for(let[$,F]of Object.entries(Qi(o,_)))p[$]===void 0&&(x=x??{...p},x[$]=F);x&&z==="idle"&&(p=et(o,x),P())}let g=Yi(o,p);g!==p&&z==="idle"&&(p=et(o,g),P()),z==="idle"&&Xn(o,s,p)&&(z="submitted",ue=!0,P());let y=!1;if(o.settings.saveProgress&&(!c||l?.id)&&s&&a&&typeof location<"u"&&location.hash.includes("fillo-draft=")){let _=/fillo-draft=([^&]+)/.exec(location.hash),x="";try{x=_?.[1]?decodeURIComponent(_[1]):""}catch{}let $=x.indexOf(".");if($>0&&$<x.length-1){y=!0;let F=Z,M=K,I=s,Q=a,G=W(I),fe=l?.id,U=x.slice(0,$),J=x.slice($+1);Q.getDraft(U,J,!0).then(ee=>{if(M.refs.set(F,{id:U,token:ee.token??J}),!de(F,I,Q)||W(I)!==G){_n(I,Q,F,G,fe,{id:U,token:ee.token??J,existing:!0});return}ut(I,{id:U,token:ee.token??J},fe);try{history.replaceState(null,"",location.pathname+location.search)}catch{}}).catch(ee=>{de(F,I,Q)&&Qn(ee)&&(Re=!0,P())}).finally(()=>{de(F,I,Q)&&Vt()})}else Re=!0,P()}y||Vt()});let V,Se=new Set,Je=new Set,gt=Date.now(),A=cn(),se=null,H=!1,ne=0,Ae=!1,Le=!1,Xe="created",D=!1,T=null,K={ownerId:c,first:Z,last:Z,refs:new Map};function xe(g){let y=Ge(g,l?.id);return!l?.id&&(c||y?.respondentId)?null:y}let re=null,Dt=Promise.resolve(),Oe=!1,yn=!1,wn=!1,Ut=!1;function Rr(){ne+=1,H=!1,se=null}function Or(){A=cn(),z="idle",V=void 0,ue=!1,Xe="created",Rr()}function Zr(){let g={...m};if(typeof location<"u"&&location.search){let y=Object.fromEntries(new URLSearchParams(location.search));for(let[_,x]of Object.entries(Qi(o,y)))g[_]===void 0&&(g[_]=x)}return et(o,Yi(o,g))}function de(g,y,_){return!Y&&Z===g&&s===y&&a===_}function Dr(g,y,_,x,$,F){return de(g,y,_)&&!_e.has(g)&&sn(y,$,F)<=x&&(W(y)===x||!Ge(y))}function _n(g,y,_,x,$,F){let M=Ge(g),I=_e.has(_)||sn(g,$,F.id)>x,Q=!$||$===(l?.id??c)||g!==s;if(M?.id===F.id){if(!I&&Q&&F.existing&&M.token!==F.token){let G=W(g);y.getDraft(F.id,F.token).then(fe=>{let U=Ge(g);if(W(g)!==G||U?.id!==M.id||U.token!==M.token){sn(g,$,F.id)>x&&U?.id!==F.id&&y.deleteDraft(F.id,F.token).catch(()=>{});return}if($&&$!==(l?.id??c)&&g===s)return;let J={id:F.id,token:F.token};ut(g,J,$),de(_,g,y)&&(T=J,jt(fe))}).catch(()=>{})}return}T?.id!==F.id&&(I?y.deleteDraft(F.id,F.token).catch(()=>{}):!M&&Q&&ut(g,{id:F.id,token:F.token},$))}function Ur(){let g=o.pages.length,y=Math.min(f,Math.max(g-1,0)),_=o.pages[y]??Ya;return{data:p,errors:h,status:z,pageIndex:y,pageCount:g,page:_,blocks:Vn(o,_,p),isFirstPage:y===0,isLastPage:v()&&b!==void 0?S().at(-1)===_.id:sr(o,_.id,p),uploading:Se.size>0,submitError:V,restoredSubmission:ue,resumedDraft:Ae,editingPrevious:Le,duplicateSubmission:Xe==="duplicate",updatedSubmission:Xe==="updated",resumeLinkFailed:Re}}let Br=Ur();function P(){Br=Ur();for(let g of Je)g()}function xn(g,y){try{n?.(g,y)}catch(_){console.error("[fillo] onSubmitted handler threw:",_)}}function jr(g){let y=o.pages[g];if(!y)return{};let _={};for(let x of Vn(o,y,p))he(x)&&(v()&&x.kind==="file_upload"||Object.assign(_,xo(x,p[x.id]).errors));return _}function Vr(g){return o.pages.findIndex(y=>Vn(o,y,p).some(_=>{if(_.id in g)return!0;if(_.kind!=="repeating_group")return!1;let x=p[_.id];return Array.isArray(x)?x.some(($,F)=>$&&typeof $=="object"&&!Array.isArray($)?fn(_,$).some(M=>`${_.id}.${F}.${M.id}`in g):!1):!1}))}function Bt(){return!!(!Y&&o.settings.saveProgress&&a&&s&&!yn)}function ps(){let g=new Set;for(let y of o.pages)for(let _ of y.blocks)he(_)&&g.add(_.id);return g}function jt(g){if(z!=="idle"||H)return;let y=ps(),_=null;for(let[F,M]of Object.entries(g.data??{}))p[F]===void 0&&y.has(F)&&(_=_??{...p},_[F]=M);let x=typeof g.page=="number"&&Number.isFinite(g.page)?Math.max(0,Math.min(Math.floor(g.page),o.pages.length-1)):0,$=x>0&&f===0;!_&&!$||(_&&(p=et(o,_)),$&&(f=x),Ae=!0,P())}function Vt(){if(Y||z!=="idle"||!l?.id&&c)return;if(!Bt()){Hr();return}let g=s,y=a,_=Z,x=K,$=W(g),F=l?.id,M=T??xe(g);if(M&&!wn){wn=!0,F&&!M.respondentId&&(ut(g,M,F),$=W(g)),T=M,x.refs.set(_,M),y.getDraft(M.id,M.token).then(I=>{de(_,g,y)&&W(g)===$&&jt(I)}).catch(I=>{!de(_,g,y)||W(g)!==$||Qn(I)&&(Yn(g),T=null,l?.hash&&Vt())});return}!M&&!Ut&&l?.hash&&(Ut=!0,y.createDraft(g,{data:{},page:0,respondent:l}).then(I=>{if(x.refs.set(_,I),!Dr(_,g,y,$,F,I.id)||T){_n(g,y,_,$,F,I);return}if(T={id:I.id,token:I.token},ut(g,T,F),I.existing){let Q=W(g);return y.getDraft(I.id,I.token).then(G=>{de(_,g,y)&&W(g)===Q&&jt(G)})}Hr()}).catch(I=>{de(_,g,y)&&(be(I)&&I.status!==void 0&&I.status>=400&&I.status<500||(Ut=!1))}))}function Hr(){if(D||o.settings.responseLimit?.onRepeat!=="update"||!a||!s||!l?.hash||z!=="idle")return;D=!0;let g=a,y=s,_=Z,x=po(o.settings,p)??void 0;g.fetchOwnResponse(y,l,x).then($=>{!de(_,y,g)||!$||z!=="idle"||H||Ae||(jt({data:$.data,page:0}),Ae&&(Ae=!1,Le=!0,P()))}).catch(()=>{})}function kn(g=!1){if(re&&(clearTimeout(re),re=null),!Bt()||z!=="idle"||!Oe)return;let y=s,_=a,x=Z,$=K;Oe=!1;let F=l,M=l?.id??c,I={data:p,page:Math.max(0,Math.min(f,o.pages.length-1))},Q=T??xe(y),G=W(y),fe=()=>_e.has(x)||sn(y,M,Q?.id)>G;Dt=Dt.then(async()=>{if(fe())return;let U=de(x,y,_),J=U?W(y):G,ee=U?l:F,Ze=U?l?.id??c:M,De=U?{data:p,page:Math.max(0,Math.min(f,o.pages.length-1))}:I,pe=$.refs.get(x),st=Ge(y,Ze),Fe=U?T??xe(y):Q??(pe?.id===st?.id&&pe?.token===st?.token?st:null);!U&&Fe&&Fe!==Q&&(J=W(y));try{if(Fe)try{await _.saveDraft(Fe.id,Fe.token,De,g?{keepalive:!0}:void 0),de(x,y,_)&&W(y)===J&&(T=Fe);return}catch(bt){if(fe()||W(y)!==J)return;if(!Qn(bt))throw bt;Yn(y),J=W(y),de(x,y,_)&&(T=null)}let ae=await _.createDraft(y,ee?.hash?{...De,respondent:ee}:De);if($.refs.set(x,ae),!Dr(x,y,_,J,Ze,ae.id)){_n(y,_,x,J,Ze,ae);return}T={id:ae.id,token:ae.token},ut(y,T,Ze),ae.existing&&(Oe=!0)}catch(ae){if(!de(x,y,_))return;be(ae)&&ae.status!==void 0&&ae.status>=400&&ae.status<500&&ae.status!==429?yn=!0:Oe=!0}})}function hs(){!Bt()||z!=="idle"||(Oe=!0,re&&clearTimeout(re),re=setTimeout(()=>{re=null,kn()},rl))}function Gr(){!Bt()||!H&&!T||(Oe=!0,kn())}function qr(g=s,y=Z,_=!0,x=K.ownerId){if(_e.add(y),g&&_&&Yn(g,!0,x),!(y!==Z||g!==s)){for(let $=K.first;$<=K.last;$++)_e.add($);me=!0,u+=1,Z+=1,K={ownerId:l?.id??c,first:Z,last:Z,refs:new Map},Dt=Promise.resolve(),re&&(clearTimeout(re),re=null),Oe=!1,T=null}}function ms(g,y){if(!H&&a&&s){H=!0;let x=a,$=s,F=ne;x.startSession($,o.pages.length).then(M=>{!Y&&F===ne&&a===x&&s===$&&(se=M)})}p=et(o,{...p,[g]:y}),t?.(p),V=void 0;let _=`${g}.`;(g in h||Object.keys(h).some(x=>x.startsWith(_)))&&(h=Object.fromEntries(Object.entries(h).filter(([x])=>x!==g&&!x.startsWith(_)))),P(),hs()}function gs(g,y){y?(Se.add(g),g in h&&(h=Object.fromEntries(Object.entries(h).filter(([_])=>_!==g)))):Se.delete(g),P()}function Wr(g){if(g.length===0)return-1;let y=o.pages.length,_=Math.min(f,Math.max(y-1,0)),x=o.pages[_]?.id,$=x===void 0?-1:g.indexOf(x);if($>=0)return $;let F=0;for(let M=0;M<g.length;M++){let I=o.pages.findIndex(Q=>Q.id===g[M]);I>=0&&I<=_&&(F=M)}return F}function bs(){let g=o.pages.length,y=Math.min(f,Math.max(g-1,0));if(!e.skipValidation||e.previewNavigation===!0){let I=jr(y);if(h=I,Object.keys(I).length>0){P();return}}let _=o.pages[y],x=S(),$=Wr(x);if((v()&&b!==void 0?x.at(-1)===_?.id:_?sr(o,_.id,p):!0)||$<0||$+1>=x.length){Kr();return}let M=o.pages.findIndex(I=>I.id===x[$+1]);C(),f=M>=0?M:Math.min(y+1,g-1),se&&a&&a.reportProgress(se,{furthestPage:f}),P(),Gr()}function vs(){h={};let g=v()?w.pop():void 0;if(g){f=Math.min(g.pageIndex,o.pages.length-1),b=g.startPageId,V=void 0,P();return}let y=ft(o,p),_=Wr(y);if(_>0){let x=o.pages.findIndex($=>$.id===y[_-1]);f=x>=0?x:Math.max(Math.min(f,o.pages.length-1)-1,0)}else if(y.length>0){let x=o.pages.findIndex($=>$.id===y[0]);f=x>=0?x:0}P(),Gr()}function ys(){!v()||z==="submitting"||z==="submitted"||f>=o.pages.length-1||(C(),f+=1,b=o.pages[f]?.id,h={},V=void 0,P())}async function Kr(){if(Y||z==="submitting"||z==="submitted")return;if(v()&&(h=jr(f),Object.keys(h).length>0)){P();return}let g=ko(o,p);if(!g.ok){let U=e.skipValidation&&!(a&&s),J=U?Object.fromEntries(Object.entries(g.errors).filter(([Ze])=>o.pages.every(De=>De.blocks.every(pe=>!(he(pe)&&pe.id===Ze&&pe.kind==="file_upload"))))):g.errors;if(U&&Object.keys(J).length===0){h={},z="submitted",P(),xn(void 0,p);return}h=J;let ee=Vr(J);ee>=0&&(f=ee,b=void 0,w.length=0),P();return}let y=a,_=Z,x=u,$=K,F=o,M=l,I=se,Q=A,G=s,fe=()=>!Y&&x===u&&a===y;if(y&&e.resolveFormId){z="submitting",V=void 0,P();try{if(G=await e.resolveFormId(),!fe())return;s=G}catch(U){throw fe()&&(z="idle",V=il(U,e.verboseResolutionErrors===!0,r),P()),U}}if(y&&G){let U=F.settings.responseLimit?.by==="browser"?tl(fr(F,G,g.data)):void 0,J=U??Q,ee=F.settings.saveProgress?T??xe(G):null,Ze=W(G),De=e.challengeRequired?e.getChallengeToken?.():void 0;if(e.challengeRequired&&!De){z="idle",V=r.challengeIncomplete,P();return}z="submitting",V=void 0,P();let pe;try{pe=await y.submit(G,g.data,{hp:e.getHoneypot?.()??"",elapsedMs:Date.now()-gt,surface:e.surface??"headless",attribution:Xa(),submissionKey:J,draft:ee?{id:ee.id,token:ee.token}:void 0,respondent:M,challengeToken:De})}catch(j){if(!fe())throw j;if(z="idle",be(j)&&j.code==="challenge_failed"){V=r.challengeRetry,e.onChallengeFailed?.(),P();return}throw V=Ro(j,r),P(),j}if(!pe.ok){if(!fe())return;h=pe.errors??{};let j=Vr(h);j>=0?f=j:V=r.reviewAnswers,z="idle",P();return}let st=fe()?se:I;st&&y.reportProgress(st,{completed:!0}),U&&nl(fr(F,G,g.data),pe.responseId);let Fe=fe(),ae=[...$.refs.values()];Fe&&T&&ae.push(T);let bt=[...new Map(ae.map(j=>[JSON.stringify([j.id,j.token]),j])).values()];for(let j of bt)(j.id!==ee?.id||j.token!==ee?.token)&&y.deleteDraft(j.id,j.token).catch(()=>{});let Ht=Ge(G),ws=!Ht&&W(G)===Ze||!!(Ht&&[...bt,ee].some(j=>j?.id===Ht.id&&j.token===Ht.token));for(let j=$.first;j<=$.last;j++)_e.add(j);if(qr(G,Fe?Z:_,ws,$.ownerId),!Fe)return;Xe=pe.duplicate?"duplicate":pe.updated?"updated":"created",z="submitted",P(),xn(pe.responseId,g.data);return}if(e.skipValidation){z="submitted",P(),xn(void 0,g.data);return}a&&!s?Qa():el(),z="error",P()}return{getState:()=>Br,subscribe(g){return Je.add(g),()=>{Je.delete(g)}},setValue:ms,setUploading:gs,next:bs,skipPreviewPage:ys,back:vs,submit:Kr,setContext(g){let y="formId"in g&&g.formId!==s||"client"in g&&g.client!==a,_="respondent"in g&&!!(l?.id&&!g.respondent?.id||g.respondent?.id&&c&&c!==g.respondent.id);if((y||"respondent"in g&&(g.respondent?.id!==l?.id||g.respondent?.hash!==l?.hash))&&(Z+=1,Dt=Promise.resolve(),y||_?(u+=1,K={ownerId:"respondent"in g?g.respondent?.id??c:l?.id??c,first:Z,last:Z,refs:new Map},_?Or():(z==="submitting"&&(z="idle"),Rr())):(K.last=Z,K.ownerId=g.respondent?.id??c),_&&(m={},Ae=!1,Le=!1,h={},f=0),(y||_)&&(re&&clearTimeout(re),re=null,Oe=!1),T=null,wn=!1,Ut=!1,D=!1,yn=!1),"formId"in g&&(s=g.formId),"client"in g&&(a=g.client),"respondent"in g&&(l=g.respondent,l?.id&&(c=l.id)),g.respondentErrorStrings&&(r={...Ui,...g.respondentErrorStrings}),g.form&&g.form!==o){let $=Ke(g.form);if(!$.ok)throw new Error(`Invalid form schema: ${$.error}`);o=$.schema,p=et(o,p)}_&&(p=Zr()),z==="idle"&&Xn(o,s,p)&&(z="submitted",ue=!0),Vt(),P()},flushDraft(){kn(!0)},resetDraft(){if(z==="submitting")return;let g=T??(s?xe(s):null),y=s?Ge(s):null,_=!y||!!(g&&g.id===y.id&&g.token===y.token);qr(s,Z,_),Or(),g&&a&&a.deleteDraft(g.id,g.token).catch(()=>{}),p=Zr(),h={},f=0,b=void 0,w.length=0,V=void 0,Ae=!1,Le=!1,Xn(o,s,p)&&(z="submitted",ue=!0),P()},destroy(){Y=!0,u+=1,Z+=1,re&&(clearTimeout(re),re=null),Je.clear()}}}function ol(e){return he(e)&&(e.kind==="select"||e.kind==="dropdown"||e.kind==="checkbox"||e.kind==="rating"||e.kind==="linear_scale")}function Zo(e){let t=e.filter(n=>he(n)&&n.kind!=="hidden"&&n.kind!=="calculated");return t.length!==1?!0:!ol(t[0])}function Do(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||!sr(n.form,o.id,i))return!1;let s=go(n.form,i).filter(a=>a.kind!=="hidden"&&a.kind!=="calculated");return s.length!==1||s[0]?.id!==e.id?!1:ko(n.form,i).ok}function Uo(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 sl=Math.sqrt(1.05*.05)-.05,al=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,ll=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;function er(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function pr(e){let t=e.trim(),n=null,r=al.exec(t);if(r)n=`${r[1]}${r[2]}${r[3]}`;else{let a=ll.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*er(i)+.7152*er(o)+.0722*er(s)}function cl(e){if(!e||e.colorScheme==="light"||e.colorScheme==="dark"||!e.background||Bo(e))return e;let t=pr(e.background);return t==null?e:{...e,colorScheme:t>sl?"light":"dark"}}function Bo(e){if(!e||e.colorScheme==="light"||e.colorScheme==="dark")return!1;let t=e.dark;return!!(t&&(t.primary||t.background||t.text))}var ul="#18181b";function tr(e){let t=pr(e);if(t==null)return null;let n=1.05/(t+.05),r=(t+.05)/((pr(ul)??0)+.05);return n>=r?"light":"dark"}var dl=[["primary","--fillo-primary"],["background","--fillo-bg"],["text","--fillo-text"]],an={light:{primary:"#18181b",background:"transparent",text:"#18181b"},dark:{primary:"#fafafa",background:"transparent",text:"#f4f4f5"}};function jo(e){let t=cl(Fo(e));if(!t)return null;let n={},r={};t.colorScheme&&(r["data-fillo-color-scheme"]=t.colorScheme);let i=Bo(t)?t.dark:void 0;for(let[o,s]of dl){let a=t[o];if(!i){a&&(n[s]=a);continue}let l=i[o];!a&&!l||(n[s]=`light-dark(${a??an.light[o]}, ${l??an.dark[o]})`)}if(t.radius&&(n["--fillo-radius"]=t.radius),t.fontFamily&&(n["--fillo-font"]=t.fontFamily),i){let o=tr(t.primary??an.light.primary),s=tr(i.primary??an.dark.primary);o&&s&&(r["data-fillo-on-primary"]=o,r["data-fillo-on-primary-dark"]=s)}else if(t.primary){let o=tr(t.primary);o&&(r["data-fillo-on-primary"]=o)}return(t.primary||t.background||t.text||i)&&(r["data-fillo-has-color-theme"]=""),{vars:n,attrs:r}}function Fr(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 Er(e){return typeof e=="object"&&e!==null&&"__filloCodeForm"in e}var He=new Map,fl=e=>new Promise(t=>setTimeout(t,e));function pl(e){if(!be(e))return!0;let t=e.status??0;return t===0||t===408||t===429||t>=500}async function hl(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(!pl(i)||r>=2)throw i;let o=be(i)?i.retryAfterSec:void 0;await fl(Math.min(o?o*1e3:n*(1+Math.random()*.5),15e3)),n*=2}}function Vo(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 Ho(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 hr=e=>e==="published"?36e5:6e4,ml=e=>!!(e.staged||e.resolvedSchema||e.syncError||e.accepting===!1||e.uploadsAvailable===!1);function Go(e,t){return`fillo:sync:v5:${e.baseUrl}|${e.key}|${t}`}function gl(e,t,n){try{let r=globalThis.localStorage?.getItem(Go(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.manageUrl!==void 0&&typeof i.manageUrl!="string"||i.status!==void 0&&i.status!=="draft"&&i.status!=="published")return null;let o=hr(i.status);return Date.now()-i.ts>o?null:i}catch{return null}}function bl(e,t,n,r){if(!(r.staged||r.resolvedSchema||r.syncError||r.accepting===!1)&&!r.challenge)try{globalThis.localStorage?.setItem(Go(e,t),JSON.stringify({formId:r.formId,slug:r.slug,manageUrl:r.manageUrl,status:r.status,uploadFileSizeLimitMb:r.uploadFileSizeLimitMb,hash:n,ts:Date.now()}))}catch{}}function zr(e,t,n){let r=JSON.stringify(t.schema)+JSON.stringify(t.theme??null),i=Vo(r),o=`${e.baseUrl}:${e.key}:${t.id}:${i}`,s=Ne(t.schema).some(u=>u.kind==="file_upload"),a=He.get(o);if(a&&!n?.bypassCache){if(a.expiresAt===null||!s&&a.expiresAt>Date.now())return a.promise;He.delete(o)}if(!n?.bypassCache&&!s){let u=gl(e,t.id,i);if(u){let m=Promise.resolve({formId:u.formId,slug:u.slug,manageUrl:u.manageUrl,status:u.status,uploadFileSizeLimitMb:u.uploadFileSizeLimitMb});return He.set(o,{promise:m,expiresAt:u.ts+hr(u.status)}),m}}let l=hl(e,t),c={promise:l,expiresAt:null};return He.set(o,c),l.then(u=>{if(He.get(o)===c){if(s||ml(u)){He.delete(o);return}c.expiresAt=Date.now()+hr(u.status),bl(e,t.id,i,u)}},()=>{He.get(o)===c&&He.delete(o)}),l}var vl=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},yl=Symbol.for("fillo.block");var wl=["label","description","required","placeholder"],q=(e,t,n,r={})=>({name:e,kind:t,props:[...wl,...n],...r}),no=(e,t,n)=>({name:e,kind:t,props:n?["text"]:[],textChildren:n,content:!0}),nr=["options","allowOther","shuffleOptions"],_l=[q("Text","short_text",["maxLength"]),q("LongText","long_text",["maxLength"]),q("Email","email",["maxLength"]),q("Url","url",["maxLength"]),q("Phone","phone",["defaultCountry"]),q("Number","number",["min","max","decimals","prefix","suffix","notation"]),q("Select","select",nr,{optionChildren:!0}),q("MultiSelect","multi_select",nr,{optionChildren:!0}),q("Dropdown","dropdown",nr,{optionChildren:!0}),q("Checkbox","checkbox",["appearance"]),q("Rating","rating",["max","insightsMetric"]),q("Scale","linear_scale",["min","max","minLabel","maxLabel","insightsMetric"]),q("Ranking","ranking",["options"],{optionChildren:!0}),q("Matrix","matrix",["rows","columns"]),q("Signature","signature",[]),q("Date","date",["defaultToday"]),q("FileUpload","file_upload",["maxFiles","maxFileSizeMb","accept"]),q("Hidden","hidden",["paramName","defaultValue"]),q("Calculated","calculated",["calc","decimals","prefix","suffix"]),q("RepeatingGroup","repeating_group",["minInstances","maxInstances","addLabel","itemLabel"],{blockChildren:!0}),q("Custom","custom",["component","config"]),no("Heading","heading",!0),no("Paragraph","paragraph",!0),{name:"Divider",kind:"divider",props:[],content:!0}],xl={name:"Page",kind:"__page",props:["title"]},kl={name:"Option",kind:"__option",props:["label","icon"]};function rr(e){let t=()=>{throw new vl("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[yl]=e,t}var op=Object.fromEntries([..._l.map(e=>[e.name,rr(e)]),["Page",rr(xl)],["Option",rr(kl)]]);var $l=1440*6e4,ro=new Map,io=new Set;function Sl(e){try{return Vo(JSON.stringify(e)??"")}catch{return"unserializable"}}function Al(e){let t=`fillo:definition-report:v1:${e}`;try{let n=Number(globalThis.localStorage?.getItem(t));if(Number.isFinite(n)&&Date.now()-n<$l)return!1;globalThis.localStorage?.setItem(t,String(Date.now()))}catch{}return!0}function oo(e,t,n){return typeof e.reportInvalidDefinition=="function"?e.reportInvalidDefinition(t,n):Promise.resolve(null)}function qo(e,t){let n=t.formId??(t.handle?`handle:${t.handle}`:""),r=`${e?.baseUrl??""}|${e?.key??""}|${n}|${Sl(t.definition)}`,i=ro.get(r);if(i)return i;let o;return t.formId?(e&&Al(r)&&oo(e,{formId:t.formId},t.definition),o=Promise.resolve(t.formId)):t.handle&&e?.key?o=oo(e,{handle:t.handle},t.definition):o=Promise.resolve(null),o=o.then(s=>{if(!io.has(r)){io.add(r);let a=s?t.formId?"Showing the version published on Fillo instead, or hiding the form if nothing is published":"Showing the version published on Fillo instead":"Nothing is published to show instead, so the form is hidden";console.error(`[fillo] This form's definition is invalid: ${t.reason}. ${a}. Fix the definition in your code.`)}return s}),ro.set(r,o),o}function Fl(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 Cr(){return typeof process<"u"&&process.env?.NODE_ENV!=="production"}function Wo(){if(Cr())return!0;if(typeof window>"u")return!1;let e=window.location?.hostname;return typeof e=="string"&&Fl(e)}var El=/\{\{\s*([\w-]+)\s*\}\}/g;function ir(e,t,n){if(!e.includes("{{"))return e;let r=Ne(n);return e.replace(El,(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 Ko(e,t,n){let r=i=>i===void 0?i:ir(i,t,n);switch(e.kind){case"heading":case"paragraph":return{...e,text:ir(e.text,t,n)};case"divider":return e;default:return{...e,label:ir(e.label,t,n),description:r(e.description)}}}var zl="fillo-",Cl=0,Ot='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Il(e){return e.matches(Ot)?e:e.querySelector(Ot)}function Nl(e){return Array.from(e.querySelectorAll(Ot)).find(n=>!n.closest(".fillo-group-instance-header"))??null}function as(e,t){let n=`${zl}${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 ht(e,t){let n=jo(t);if(n){for(let[r,i]of Object.entries(n.attrs))e.setAttribute(r,i);for(let[r,i]of Object.entries(n.vars))e.style.setProperty(r,i)}}function ot(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 Ml(e){let t=new URL(ot(e)??"https://fillo.so");return t.searchParams.set("utm_source","form_badge"),t.toString()}function gn(e){return typeof e=="string"||typeof e=="number"?String(e):""}function Jo(e,t,n){let r=gn(e);if(r==="")return r;let i=Number(r);return Number.isFinite(i)?zo(i,{locale:n,decimals:t}):r}function L(e,t){for(let n of t)n&&e.appendChild(n);return e}var bn="http://www.w3.org/2000/svg",Ll={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 ls(e){if(!e)return null;let t=document.createElementNS(bn,"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(bn,"path");return n.setAttribute("d",Ll[e]),t.appendChild(n),t}function cs(){let e=document.createElementNS(bn,"svg");e.setAttribute("class","fillo-option-check"),e.setAttribute("width","1em"),e.setAttribute("height","1em"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linecap","square"),e.setAttribute("stroke-linejoin","miter"),e.setAttribute("aria-hidden","true"),e.setAttribute("focusable","false");let t=document.createElementNS(bn,"path");return t.setAttribute("d","M4 12l5 5L20 6"),e.appendChild(t),e}function ce(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 us(e,t,n,r){e.addEventListener("keydown",i=>{let o=getComputedStyle(e).direction==="rtl",s=n===null?-1:t.indexOf(n),a=Uo(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 ve(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 Nt(e,t){let n=t.field,r=n.kind==="number"?n:void 0,i=r?.notation!==void 0,o=Eo(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?Jo(t.value,r?.decimals,o):gn(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,m=()=>{a.value=c,a.setSelectionRange(u,u)};i?(a.addEventListener("input",()=>{if(!It(a.value,o))return m();c=a.value,u=a.selectionStart??a.value.length,t.setValue(wr(a.value,o),{render:!1})}),a.addEventListener("change",()=>{if(!It(a.value,o))return m();c=a.value,t.setValue(wr(a.value,o))}),a.addEventListener("blur",()=>{let p=t.getValue?.()??t.value;a.value=Jo(p,r?.decimals,o),c=a.value,u=a.value.length})):(a.addEventListener("input",()=>{if(!It(a.value,o))return m();c=a.value,u=a.selectionStart??a.value.length,t.setValue(a.value,{render:!1})}),a.addEventListener("change",()=>{if(!It(a.value,o))return m();c=a.value,t.setValue(a.value)}))}else a.addEventListener("input",()=>t.setValue(a.value,{render:!1})),a.addEventListener("change",()=>t.setValue(a.value));ce(a,n,t.error,t.ids);let l=a;return r&&(r.prefix||r.suffix)&&(l=L(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])),ve(n,t.error,l,t.ids)}function Tl(){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 Pl(){if(!(typeof Intl>"u"))try{let e=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof e=="string"&&e?e:void 0}catch{return}}function Rl(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 Ol(e){let t=e.field,n=zt(gn(e.value)).country??pn(t.defaultCountry)??vo(Pl())??pn(Tl())??Ft[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"});L(o,[s,a,d("span",{className:"fillo-phone-caret",text:"\u25BE",attrs:{"aria-hidden":"true"}})]),L(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"}});ce(l,e.field,e.error,e.ids);let c=()=>e.getValue?.()??e.value,u=()=>{let A=Ie(gn(c()));return A.startsWith(n.dialCode)?A.slice(n.dialCode.length):A},m=()=>{s.textContent=gr(n.iso2),a.textContent=`+${n.dialCode}`,o.setAttribute("aria-label",`Country: ${n.name} (+${n.dialCode})`)},p=()=>{l.value=Et(n,u()),l.placeholder=Et(n,n.example)},h=A=>e.setValue(A?yo(n,A):"",{render:!1}),f=A=>e.setValue(A,{render:!1});m(),p(),l.addEventListener("input",()=>{let A=l.value,se=l.selectionStart??A.length,H=Ie(A.slice(0,se)).length;if(A.trimStart().startsWith("+")){let ne=zt(A,n,{previousDigits:u()});if(ne.pending){f(ne.raw??A);return}ne.country&&(n=ne.country,m()),h(ne.country?ne.national:Ie(A))}else h(Ie(A));l.value=Et(n,u()),Rl(l,H)});let b=e.registerOverlay,w=e.announce,v=null,S=0,C=pt,z=null,ue=null,Y,me=`${e.ids.inputId}-countries`,Z=()=>{if(!v)return;let A=wo(i,v);v.classList.toggle("fillo-phone-popover--above",A==="above"),v.classList.toggle("fillo-phone-popover--below",A==="below")},_e=()=>{z?.();let A=()=>Z();Z(),window.addEventListener("resize",A),window.addEventListener("scroll",A,!0),z=()=>{window.removeEventListener("resize",A),window.removeEventListener("scroll",A,!0)}},Re=A=>{let se=A.relatedTarget;if(se){i.contains(se)||V();return}queueMicrotask(()=>{v&&!i.contains(document.activeElement)&&V()})},V=()=>{clearTimeout(Y),z?.(),z=null,v?.remove(),v=null,o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-controls"),document.removeEventListener("mousedown",Se),i.removeEventListener("focusout",Re),ue?.(),ue=null},Se=A=>{i.contains(A.target)||V()},Je=A=>{A&&(n=A,m(),h(u()),p(),V(),w?.(O.phoneCountrySelected(A.name)),l.focus())},gt=A=>{let se=d("div",{className:"fillo-phone-popover fillo-phone-popover--below"}),H=d("input",{className:"fillo-phone-search",attrs:{type:"text",role:"combobox","aria-expanded":"true","aria-controls":me,"aria-autocomplete":"list","aria-label":"Search country or code",placeholder:"Search country or code"}});A&&(H.value=A);let ne=d("ul",{className:"fillo-phone-list",attrs:{role:"listbox",id:me,"aria-label":"Country"}}),Ae=()=>{if(ne.replaceChildren(),C.length===0){ne.appendChild(d("li",{className:"fillo-phone-empty",text:"No matches",attrs:{role:"option","aria-disabled":"true"}})),H.removeAttribute("aria-activedescendant"),Z();return}C.forEach((D,T)=>{let K=d("li",{className:`fillo-phone-option${T===S?" fillo-phone-option--active":""}`,attrs:{id:`${me}-opt-${T}`,role:"option","aria-selected":String(D.iso2===n.iso2)}});L(K,[d("span",{className:"fillo-phone-flag-emoji",text:gr(D.iso2),attrs:{"aria-hidden":"true"}}),d("span",{className:"fillo-phone-option-name",text:D.name}),d("span",{className:"fillo-phone-option-dial",text:`+${D.dialCode}`})]),K.addEventListener("mouseenter",()=>{S=T,H.setAttribute("aria-activedescendant",K.id),Le()}),K.addEventListener("mousedown",xe=>{xe.preventDefault(),Je(D)}),ne.appendChild(K)}),H.setAttribute("aria-activedescendant",`${me}-opt-${S}`),Z()},Le=()=>{[...ne.children].forEach((D,T)=>D.classList.toggle("fillo-phone-option--active",T===S)),document.getElementById(`${me}-opt-${S}`)?.scrollIntoView({block:"nearest"})},Xe=D=>{let T=D.trim().toLowerCase(),K=T.replace(/[^\d]/g,"");C=T?pt.filter(xe=>xe.name.toLowerCase().includes(T)||xe.iso2.toLowerCase()===T||K.length>0&&xe.dialCode.startsWith(K)):pt,S=0,Ae(),clearTimeout(Y),Y=setTimeout(()=>w?.(O.phoneResultsCount(C.length)),300)};H.addEventListener("input",()=>Xe(H.value)),H.addEventListener("keydown",D=>{if(D.key==="ArrowDown"){if(D.preventDefault(),C.length===0)return;S=Math.min(S+1,C.length-1),Le(),H.setAttribute("aria-activedescendant",`${me}-opt-${S}`)}else if(D.key==="ArrowUp"){if(D.preventDefault(),C.length===0)return;S=Math.max(S-1,0),Le(),H.setAttribute("aria-activedescendant",`${me}-opt-${S}`)}else D.key==="Enter"?(D.preventDefault(),Je(C[S])):D.key==="Escape"&&(D.preventDefault(),V(),o.focus())}),L(se,[H,ne]),v=se,i.appendChild(se),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",me),A?Xe(A):(C=pt,S=Math.max(0,pt.indexOf(n)),Ae()),_e(),Le(),document.addEventListener("mousedown",Se),i.addEventListener("focusout",Re),ue=b?.(V)??null,requestAnimationFrame(()=>{if(H.focus(),A){let D=H.value.length;H.setSelectionRange(D,D)}})};return o.addEventListener("click",()=>v?V():gt()),o.addEventListener("keydown",A=>{if(!v){if(A.key==="ArrowDown"||A.key==="ArrowUp"){A.preventDefault(),gt();return}A.key.length===1&&A.key!==" "&&!A.ctrlKey&&!A.metaKey&&!A.altKey&&(A.preventDefault(),gt(A.key))}}),L(r,[i,l]),ve(e.field,e.error,r,e.ids)}function Zl(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)),ce(t,e.field,e.error,e.ids),ve(e.field,e.error,t,e.ids)}function Dl(e){let t=e.field,n=Tr(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"}});ce(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)}),L(c,[u,ls(l.icon),d("span",{className:"fillo-option-label",text:l.label,attrs:{"data-fillo":"optionLabel"}}),l.icon&&r===l.id?cs():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})}),L(l,[L(d("span",{className:"fillo-option-main"}),[c,d("span",{className:"fillo-option-label",text:R.other,attrs:{"data-fillo":"optionLabel"}})])]),s){let u=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":R.otherPrompt}});u.value=o?r:"",u.placeholder=R.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 ve(t,e.error,a,e.ids)}function Ul(e){let t=e.field,n=Tr(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"}});ce(l,t,e.error,e.ids,{requiredSupported:!1});let c=u=>e.setValue(u);for(let u of n){let m=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"}});m.toggleAttribute("data-selected",r.includes(u.id));let p=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});p.checked=r.includes(u.id),p.addEventListener("change",()=>{let h=a();c(p.checked?[...h,u.id]:h.filter(f=>f!==u.id))}),L(m,[p,ls(u.icon),d("span",{className:"fillo-option-label",text:u.label,attrs:{"data-fillo":"optionLabel"}}),u.icon&&r.includes(u.id)?cs():null]),l.appendChild(m)}if(t.allowOther){let u=o!==void 0||s?.has(t.id)===!0,m=d("label",{className:`fillo-option fillo-option--other${u?" fillo-option--selected fillo-option--with-other":""}`,attrs:{"data-fillo":"option"}});m.toggleAttribute("data-selected",u);let p=d("input",{className:"fillo-option-input",attrs:{type:"checkbox"}});if(p.checked=u,p.addEventListener("change",()=>{let h=a().filter(f=>i.has(f));p.checked?(s?.add(t.id),c(h)):(s?.delete(t.id),c(h))}),L(m,[L(d("span",{className:"fillo-option-main"}),[p,d("span",{className:"fillo-option-label",text:R.other,attrs:{"data-fillo":"optionLabel"}})])]),u){let h=d("input",{className:"fillo-input fillo-other-input",attrs:{type:"text","aria-label":R.otherPrompt}});h.value=o??"",h.placeholder=R.otherPlaceholder,h.addEventListener("input",()=>{s?.add(t.id);let f=a().filter(b=>i.has(b));e.setValue(h.value?[...f,h.value]:f,{render:!1})}),h.addEventListener("change",()=>{s?.add(t.id);let f=a().filter(b=>i.has(b));e.setValue(h.value?[...f,h.value]:f)}),m.appendChild(h),o===void 0&&queueMicrotask(()=>h.focus())}l.appendChild(m)}return ve(t,e.error,l,e.ids)}function Bl(e){let t="__fillo_other__",n=new Set(e.options.map(r=>r.id));for(;n.has(t);)t+="_";return t}function jl(e){let t=e.field,n=typeof e.value=="string"?e.value:"",r=Bl(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 Tr(t))c.appendChild(d("option",{text:u.label,attrs:{value:u.id}}));if(t.allowOther&&c.appendChild(d("option",{text:`${R.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))}),ce(c,t,e.error,e.ids),L(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":R.otherPrompt}});u.value=o?n:"",u.placeholder=R.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 ve(t,e.error,a,e.ids)}function Vl(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)}),ce(c,e.field,e.error,e.ids),L(s,[l,c,L(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)),ce(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)"})),L(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 Hl(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"}});ce(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 us(s,r,i,a=>e.setValue(a)),ve(e.field,e.error,s,e.ids)}function Gl(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},(m,p)=>t+p),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"}});ce(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[m,p]of i.entries()){let h=d("button",{className:`fillo-scale-step${e.value===p?" fillo-scale-step--active":""}`,text:String(p),attrs:{type:"button",role:"radio","aria-label":String(p),"aria-checked":String(e.value===p),tabindex:String(m===o?0:-1),"data-fillo":"option"}});h.toggleAttribute("data-selected",e.value===p),h.addEventListener("click",f=>{f.detail===0&&e.value===p||e.setValue(e.value===p?null:p)}),c.appendChild(h)}return us(c,i,r,m=>e.setValue(m)),l.appendChild(c),("minLabel"in e.field||"maxLabel"in e.field)&&L(l,[L(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}})])]),ve(e.field,e.error,l,e.ids)}function ql(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"}});ce(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"}),m=d("span",{className:"fillo-ranking-controls"}),p=b=>{let w=a+b;if(w<0||w>=i.length)return;let v=[...i];[v[a],v[w]]=[v[w],v[a]],e.setValue(v),n?.(O.rankingPosition(c.label,w+1,i.length))},h=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`}});h.toggleAttribute("disabled",a===0),h.addEventListener("click",()=>p(-1));let f=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`}});f.toggleAttribute("disabled",a===i.length-1),f.addEventListener("click",()=>p(1)),L(m,[h,f]),L(u,[d("span",{className:"fillo-ranking-index",text:String(a+1)}),d("span",{className:"fillo-ranking-label",text:c.label}),m]),s.appendChild(u)}return o.appendChild(s),ve(e.field,e.error,o,e.ids)}function Wl(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,m=!!e.error&&!!t.required&&!u,p=w=>`${e.ids.inputId}-${l.id}-${w.id}`,h=document.createElement("tr"),f=d("th",{attrs:{scope:"row"}}),b=d("div",{attrs:{role:"radiogroup","aria-labelledby":`${e.ids.labelId} ${c}`,"aria-owns":t.columns.map(p).join(" ")}});b.appendChild(d("span",{text:l.label,attrs:{id:c}})),f.appendChild(b),h.appendChild(f);for(let w of t.columns){let v=d("td",{attrs:{"data-label":w.label}}),S=d("label",{className:"fillo-matrix-cell"}),C=d("input",{className:"fillo-option-input",attrs:{id:p(w),type:"radio",name:`${e.ids.name}-${l.id}`,"aria-label":`${l.label}: ${w.label}`}});t.required&&C.setAttribute("aria-required","true"),m&&C.setAttribute("aria-invalid","true"),C.checked=n[l.id]===w.id,C.addEventListener("change",()=>e.setValue({...n,[l.id]:w.id})),S.appendChild(C),v.appendChild(S),h.appendChild(v)}s.appendChild(h)}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 ce(a,e.field,e.error,e.ids,{requiredSupported:!1}),a.appendChild(r),ve(e.field,e.error,a,e.ids)}function Kl(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?O.signatureSigned:O.signatureEmpty)};if(c(),l&&s){let w=new Image;w.onload=()=>s.drawImage(w,0,0,r.width,r.height),w.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"}});ce(u,e.field,e.error,e.ids);let m=w=>{s&&(s.clearRect(0,0,r.width,r.height),w.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(w,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",()=>m(u.value));let p=w=>{let v=r.getBoundingClientRect();return{x:(w.clientX-v.left)/v.width*r.width,y:(w.clientY-v.top)/v.height*r.height}};r.addEventListener("pointerdown",w=>{if(!s)return;a=!0,l=!0,o.style.display="none",c(),u.value&&(u.value=""),r.setPointerCapture(w.pointerId);let v=p(w);s.beginPath(),s.moveTo(v.x,v.y)}),r.addEventListener("pointermove",w=>{if(!a||!s)return;let v=p(w);s.lineWidth=2.4,s.lineCap="round",s.strokeStyle=getComputedStyle(r).color||"#18181b",s.lineTo(v.x,v.y),s.stroke()});let h=()=>{a&&(a=!1,l&&e.setValue(r.toDataURL("image/png"),{render:!1}))};r.addEventListener("pointerup",h),r.addEventListener("pointercancel",h),i.addEventListener("click",()=>{s?.clearRect(0,0,r.width,r.height),l=!1,o.style.display="",u.value="",c(),e.setValue(null,{render:!1})}),L(n,[r,o,i]);let f=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 L(f,[b,u]),L(t,[n,f]),ve(e.field,e.error,t,e.ids)}function Xo(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 Rt(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 Yo(e){let t=d("span",{className:`fillo-file-state fillo-file-state--${e}`,attrs:{"aria-hidden":"true"}});return t.appendChild(Rt(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 Ir(){let e=Rt(["m7 7 10 10M17 7 7 17"],16);return e.setAttribute("class","fillo-file-action-icon"),e}function Qo(e){let t=Rt([e],16);return t.setAttribute("class","fillo-group-icon"),t}function mn(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 Jl(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(p=>p.error===void 0).length,u=d("div");if(c>0){let p=d("input",{className:"fillo-input",attrs:{id:e.ids.inputId,type:"file",hidden:""}});o>1&&(p.multiple=!0),t.accept?.length&&(p.accept=t.accept.join(",")),p.disabled=!i,p.addEventListener("change",()=>{if(!i)return;let f=Array.from(p.files??[]);p.value="",e.uploadFiles?.(t,f)});let h=d("div",{className:`fillo-dropzone${i?"":" fillo-dropzone--disabled"}`,attrs:{role:"button",tabindex:"0","aria-labelledby":e.ids.labelId,"data-fillo":"control"}});if(ce(h,t,e.error,e.ids,{requiredSupported:!1}),i||h.setAttribute("aria-disabled","true"),h.addEventListener("dragover",f=>{f.preventDefault(),h.classList.add("fillo-dropzone--over"),h.setAttribute("data-drag-over","")}),h.addEventListener("dragleave",()=>{h.classList.remove("fillo-dropzone--over"),h.removeAttribute("data-drag-over")}),h.addEventListener("drop",f=>{f.preventDefault(),h.classList.remove("fillo-dropzone--over"),h.removeAttribute("data-drag-over"),i&&e.uploadFiles?.(t,Array.from(f.dataTransfer?.files??[]))}),h.addEventListener("click",()=>{i&&p.click()}),h.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),i&&p.click())}),h.appendChild(p),i)L(h,[d("span",{className:"fillo-dropzone-title",text:O.dropzoneTitle(o>1)}),d("span",{className:"fillo-dropzone-hint",text:O.dropzoneHint(s)})]);else if(r==="render_only")h.appendChild(d("span",{className:"fillo-dropzone-hint",text:O.uploadsRenderOnly}));else if(n.storageFixUrl){let f=d("span",{className:"fillo-dropzone-hint",text:"Connect file storage to enable uploads"});f.append(" \u2014 "),f.appendChild(d("a",{text:n.storageFixUrl,attrs:{href:n.storageFixUrl,target:"_blank",rel:"noopener noreferrer"}})),h.appendChild(f)}else h.appendChild(d("span",{className:"fillo-dropzone-hint",text:O.uploadsUnavailable}));u.appendChild(h)}if(a.length>0||l.length>0){let p=d("ul",{className:"fillo-files"});for(let h of a){let f=d("li",{className:"fillo-file fillo-file--done"}),b=d("span",{className:"fillo-file-content"});L(b,[d("span",{className:"fillo-file-name",text:h.name}),d("span",{className:"fillo-file-meta",text:O.uploadedFile(Xo(h.size))})]);let w=d("span",{className:"fillo-file-actions"});w.appendChild(mn("fillo-file-remove",`${O.uploadRemove} ${h.name}`,Ir(),()=>e.setValue(a.filter(v=>v.fileId!==h.fileId)))),L(f,[Yo("done"),b,w]),p.appendChild(f)}for(let h of l){let f=h.error!==void 0,b=d("li",{className:`fillo-file${f?" fillo-file--failed":""}`});b.appendChild(Yo(f?"failed":"uploading"));let w=d("span",{className:"fillo-file-content"});if(w.appendChild(d("span",{className:"fillo-file-name",text:h.name})),f){let v=d("span",{className:"fillo-file-actions"});w.appendChild(d("span",{className:"fillo-file-error",text:h.error??""})),b.appendChild(w),!h.tooLarge&&c>0&&v.appendChild(mn("fillo-file-retry",`${O.uploadRetry} ${h.name}`,O.uploadRetry,()=>n.uploadAction?.(h.key,"retry"))),v.appendChild(mn("fillo-file-remove",`${O.uploadDismiss} ${h.name}`,Ir(),()=>n.uploadAction?.(h.key,"dismiss"))),b.appendChild(v)}else{let v=d("span",{className:"fillo-progress-bar"});v.style.width=`${h.fraction*100}%`,w.appendChild(d("span",{className:"fillo-file-meta",text:O.uploadingFile(Math.round(h.fraction*100),Xo(h.size))}));let S=d("span",{className:"fillo-file-actions"});S.appendChild(mn("fillo-file-remove",`${O.uploadCancel} ${h.name}`,Ir(),()=>n.uploadAction?.(h.key,"cancel"))),L(b,[w,S,L(d("span",{className:"fillo-progress",attrs:{role:"progressbar","aria-label":`Uploading ${h.name}`,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(Math.round(h.fraction*100))}}),[v])])}p.appendChild(b)}u.appendChild(p)}let m=n.uploadNotice;return m&&u.appendChild(d("p",{className:"fillo-upload-notice",text:m})),ve(t,e.error,u,e.ids)}function Xl(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?yr(t,r):"\u2014",attrs:{id:e.ids.inputId}});return t.description&&o.setAttribute("aria-describedby",e.ids.descriptionId),n.appendChild(o),n}var es=new Map;function Tr(e){if(!e.shuffleOptions)return e.options;let t=`${e.id}|${e.options.map(o=>o.id).join(",")}`,n=es.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]]}es.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 Mt(e){let t=e.getValue?.()??e.value;return Array.isArray(t)?t:[]}function Yl(e,t){return Math.max(t.length,e.minInstances??1)}function Ql(e){return Math.max(e.minInstances??1,0)}function Nr(e,t){let n=[...e];for(;n.length<t;)n.push({});return n}function ec(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=Mt(e),a=Yl(t,s),l=Ql(t),c=d("div",{className:"fillo-group",attrs:{id:e.ids.inputId,"data-fillo":"control"}});ce(c,t,e.error,e.ids,{requiredSupported:!1});for(let p=0;p<a;p++){let h=s[p]??{},f=O.groupInstanceLabel(o,p+1,a),b=d("div",{className:"fillo-group-instance",attrs:{role:"group","aria-label":f,tabindex:"-1"}}),w=d("div",{className:"fillo-group-instance-header"}),v=d("button",{className:"fillo-group-remove",attrs:{type:"button","aria-label":O.groupRemoveLabel(o,p+1)}});v.appendChild(Qo("M6 6l12 12M18 6 6 18"));let S=a>l;v.toggleAttribute("disabled",!S),S||(v.setAttribute("aria-disabled","true"),v.setAttribute("title",`At least ${l} ${l===1?"entry":"entries"} required`)),v.addEventListener("click",()=>{if(a<=l)return;let C=Nr(Mt(e),a);C.splice(p,1),e.setValue(C),n.setGroupFocus?.({groupId:t.id,cardIndex:p-1,intoControl:!1}),r?.(O.groupInstanceRemoved(o,C.length))}),L(w,[d("p",{className:"fillo-group-instance-title",text:f}),v]),b.appendChild(w);for(let C of fn(t,h)){let z=`${t.id}.${p}.${C.id}`,ue={...C,id:z},Y=as(i,z),me=(Re,V)=>{let Se=Nr(Mt(e),a);Se[p]={...Se[p]??{},[C.id]:Re},e.setValue(Se,V)},Z={field:ue,value:h[C.id],error:e.api.errors[z],ids:Y,api:e.api,setValue:me,getValue:()=>Mt(e)[p]?.[C.id],announce:n.announce,announceAlert:n.announceAlert,registerOverlay:n.registerOverlay,activeOtherFields:n.activeOtherFields},_e=n.renderChildField?.(Z)??ds(Z);_e&&b.appendChild(_e)}c.appendChild(b)}let u=a>=t.maxInstances,m=d("button",{className:"fillo-group-add",attrs:{type:"button"}});return m.append(Qo("M12 5v14M5 12h14"),t.addLabel||O.groupAdd),m.toggleAttribute("disabled",u),u&&(m.setAttribute("aria-disabled","true"),m.setAttribute("title",`Maximum ${t.maxInstances} ${t.maxInstances===1?"entry":"entries"}`)),m.addEventListener("click",()=>{if(a>=t.maxInstances)return;let p=Nr(Mt(e),a);p.push({}),e.setValue(p),n.setGroupFocus?.({groupId:t.id,cardIndex:p.length-1,intoControl:!0}),r?.(O.groupInstanceAdded(o,p.length,p.length))}),c.appendChild(m),ve(t,e.error,c,e.ids)}var tc={short_text:e=>Nt("text",e),email:e=>Nt("email",e),url:e=>Nt("url",e),phone:Ol,number:e=>Nt("number",e),date:e=>Nt("date",e),long_text:Zl,select:Dl,multi_select:Ul,dropdown:jl,checkbox:Vl,rating:Hl,linear_scale:Gl,ranking:ql,matrix:Wl,signature:Kl,file_upload:Jl,calculated:Xl,repeating_group:ec};function ds(e){if(e.field.kind==="hidden"||e.field.kind==="custom")return null;let t=tc[e.field.kind];return t?t(e):null}var nc="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",ts="fillo-turnstile-script",rc=2e4,ic=/^[A-Za-z0-9_-]{1,255}$/,Lt=null;function mt(){return globalThis.turnstile}function oc(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Turnstile needs a browser")):mt()?Promise.resolve():Lt||(Lt=new Promise((e,t)=>{let n=()=>{mt()?e():t(new Error("Turnstile loaded without its global"))},r=document.getElementById(ts);if(r){if(mt()){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=ts,i.src=nc,i.async=!0,i.defer=!0,i.addEventListener("load",n,{once:!0}),i.addEventListener("error",()=>{i.remove(),Lt=null,t(new Error("Turnstile script failed to load"))},{once:!0}),document.head.appendChild(i)}),Lt)}function ns(){return d("div",{className:"fillo-turnstile",attrs:{"data-fillo":"turnstile"}})}var Zt=class{constructor(t,n){this.target=t;this.options=n;this.element.className="fillo-dom-root",n.preview===!0&&hc(),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${++Cl}`;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=ns();turnstileWidgetId=null;turnstileSiteKey;turnstileLoadInFlight=!1;turnstileAttempt=0;challengeFrame=null;challengeFrameSrc=null;challengeFrameOrigin=null;challengeMessageHandler=null;challengeWatchdog=null;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||lc()}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;syncFormUrl;uploadsAvailable;uploadFileSizeLimitMb;resolutionFailureCode=null;async resolve(){try{this.challenge=this.options.renderOnly?void 0:this.options.challenge;let t=Er(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}let r=os(t.schema);if(r){await this.showPublishedInstead(r,t.schema,t.id);return}!this.options.client&&this.options.formId&&(this.options.client=Me());let i=this.options.client;if(i?.key&&(this.resolveFormIdFn=async()=>{try{let o=await zr(i,t,{bypassCache:!0});if(this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.syncFormUrl=o.manageUrl,this.uploadsAvailable=o.uploadsAvailable,this.uploadFileSizeLimitMb=o.uploadFileSizeLimitMb,o.status==="draft")throw new E("This form is no longer published. Submission was stopped before sending answers.",403,void 0,"form_not_published");if(o.accepting===!1)throw new E("This form is no longer accepting responses. Submission was stopped before sending answers.",403,void 0,o.acceptingReason??"form_not_accepting");let s=Ke(o.resolvedSchema??t.schema);if(!s.ok)throw new E(`The canonical form schema was invalid: ${s.error}`,502,void 0,"invalid_sync_schema");if(this.schema&&!Ho(this.schema,s.schema))throw new E("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 E(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(),ss();if(i&&!i.key&&!this.options.formId){this.reportSyncFailure(new E('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 zr(i,t);if(this.destroyed)return;if((o.staged||o.syncError)&&!o.resolvedSchema)throw new E("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?rs(o.acceptingReason):null,this.stagedNotice=!!o.staged,this.draftNotice=o.status==="draft",this.syncWarningCode=o.warningCode,this.syncWarningUrl=o.warningUrl,this.syncFormUrl=o.manageUrl,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 E(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&&!Er(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(),ss();this.options.client??=Me();let r=os(n);if(r){await this.showPublishedInstead(r,n,void 0);return}this.setSchema(n,this.options.theme,this.options.formId);return}if(!this.options.formId)throw new E("Provide either `form`, or a `formId`.",0);this.options.client??=Me(),await this.loadPublished(this.options.formId)}catch(t){if(this.destroyed)return;this.handleError(Pt(t))}}async showPublishedInstead(t,n,r){let i=new E(`This form's definition is invalid: ${t}. In production, Fillo shows the published version of this form instead.`,422,void 0,Tt);if(this.devChrome()){this.handleError(i);return}this.options.onError?.(i),this.render(),!this.options.client&&this.options.formId&&(this.options.client=Me());let o=await qo(this.options.client,{formId:this.options.formId,handle:r,definition:n,reason:t});if(!this.destroyed){if(!o){this.fatalError=i,this.phase="error",this.render(i);return}this.options.client??=Me();try{await this.loadPublished(o)}catch{if(this.destroyed)return;this.fatalError=i,this.phase="error",this.render(i)}}}async loadPublished(t){let n=this.options.client??Me();this.options.client=n,this.render();let r=await n.getForm(t);if(!this.destroyed){if(r.accepting===!1?this.notOpenVariant=rs(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 E(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)}}setSchema(t,n,r){if(this.destroyed)return;let i=Ke(t);if(!i.ok)throw new E(`This form could not be rendered: ${i.error}`,422,void 0,Tt);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,c=this;this.engine=Oo({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,get challengeRequired(){return!l&&!!c.challenge},getChallengeToken:()=>this.challengeToken,onChallengeFailed:()=>this.resetChallengeWidget()});let u=this.engine.getState().status,m=this.engine.getState().resumedDraft,p=this.engine.getState().editingPrevious,h=this.engine.getState().errors,f=this.engine.getState().resumeLinkFailed;this.engine.subscribe(()=>{let b=this.engine?.getState();b&&(b.status!==u||b.resumedDraft!==m||b.editingPrevious!==p||b.errors!==h||b.resumeLinkFailed!==f)&&(b.editingPrevious&&!p?this.announce(R.editNotice):b.resumedDraft&&!m?this.announce(R.resumeNotice):b.resumeLinkFailed&&!f&&this.announce(O.resumeLinkExpired),u=b.status,m=b.resumedDraft,p=b.editingPrevious,h=b.errors,f=b.resumeLinkFailed,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=Ke(t);if(!i.ok)throw new E(`This form could not be rendered: ${i.error}`,422,void 0,Tt);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(O.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===0||a.status!==void 0&&a.status>=500?O.uploadUnavailable:O.uploadFailed,c=this.inFlight.get(i);c&&(c.error=l),this.announceAlert(l),this.options.onError?.(a)}finally{this.fieldActive(t)===0&&this.engine?.setUploading(t,!1),this.queueRender()}}async uploadFiles(t,n){if(!this.schema||this.notOpenVariant)return;let r=t.maxFiles??1,i=r>1&&Array.isArray(this.mutableData[t.id])?this.mutableData[t.id].length:0,o=Math.max(0,r-i-this.fieldActive(t.id)),s=n.slice(0,o),a=t.maxFileSizeMb??500,l=this.uploadFileSizeLimitMb?Math.min(a,this.uploadFileSizeLimitMb):a,c=l*1024*1024,u=s.filter(f=>f.size<=c),m=s.filter(f=>f.size>c),p=n.length-s.length,h=s.length-u.length;if(p>0||h>0){let f=[];p>0&&f.push(`You can attach up to ${r} file${r===1?"":"s"}. ${p} ${p===1?"file was":"files were"} not added.`);let b=f.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 f of m){let b=O.fileTooLarge(l),w=`${f.name}-${f.size}-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;this.inFlight.set(w,{fieldId:t.id,name:f.name,size:f.size,fraction:0,error:b,tooLarge:!0,file:f,controller:new AbortController,maxFiles:r}),this.announceAlert(b)}if(u.length===0){this.queueRender();return}await Promise.all(u.map(f=>this.startUpload(t.id,f,r)))}destroy(){this.destroyed=!0,this.teardownDraftFlush(),this.closeOverlays(),this.teardownTurnstileWidget();for(let t of this.inFlight.values())t.controller.abort();this.inFlight.clear(),this.engine?.destroy(),this.engine=null,this.target.replaceChildren()}storageBlocked(){return this.uploadsAvailable===!1}registerOverlay=t=>(this.overlays.add(t),()=>this.overlays.delete(t));closeOverlays(){if(this.overlays.size!==0){for(let t of Array.from(this.overlays))try{t()}catch{}this.overlays.clear()}}ensureChallengeWidget(t){t.bridgeUrl?this.ensureChallengeBridge(t.bridgeUrl):this.ensureTurnstileWidget(t.siteKey)}ensureChallengeBridge(t){if(typeof window>"u")return;let n;try{n=new URL(t)}catch{this.handleChallengeError();return}if(n.protocol!=="https:"&&n.protocol!=="http:"){this.handleChallengeError();return}n.searchParams.set("origin",window.location.origin),n.searchParams.set("theme",this.options.challengeTheme??"auto"),this.formId&&ic.test(this.formId)&&n.searchParams.set("cdata",this.formId),n.searchParams.set("appearance",(this.options.challengeAppearance??"interaction-only")==="interaction-only"?"interaction-only":"always");let r=n.toString();if(this.challengeFrame&&this.challengeFrameSrc===r)return;this.teardownTurnstileWidget();let i=++this.turnstileAttempt,o=d("iframe",{className:"fillo-turnstile-frame",attrs:{src:r,title:"Human verification",width:"300",height:"65",referrerpolicy:"no-referrer"}});this.challengeFrame=o,this.challengeFrameSrc=r,this.challengeFrameOrigin=n.origin,this.turnstileContainer.appendChild(o),this.setChallengeFrameVisible((this.options.challengeAppearance??"interaction-only")!=="interaction-only");let s=a=>{if(i!==this.turnstileAttempt||this.destroyed||a.origin!==this.challengeFrameOrigin||!this.challengeFrame||a.source!==this.challengeFrame.contentWindow)return;let l=a.data;switch(l?.type){case"fillo:challenge:ready":this.settleChallengeWatchdog();break;case"fillo:challenge:token":this.settleChallengeWatchdog(),typeof l.token=="string"&&l.token.length>0&&this.handleChallengeToken(l.token),(this.options.challengeAppearance??"interaction-only")==="interaction-only"&&this.setChallengeFrameVisible(!1);break;case"fillo:challenge:interactive":this.setChallengeFrameVisible(!0);break;case"fillo:challenge:interactive-done":(this.options.challengeAppearance??"interaction-only")==="interaction-only"&&this.setChallengeFrameVisible(!1);break;case"fillo:challenge:expired":this.handleChallengeToken(void 0);break;case"fillo:challenge:error":this.settleChallengeWatchdog(),this.handleChallengeToken(void 0),this.handleChallengeError();break}};this.challengeMessageHandler=s,window.addEventListener("message",s),this.challengeWatchdog=window.setTimeout(()=>{i!==this.turnstileAttempt||this.destroyed||(this.handleChallengeToken(void 0),this.handleChallengeError())},rc)}setChallengeFrameVisible(t){let n=this.challengeFrame;n&&(n.setAttribute("height",t?"65":"0"),t?(n.removeAttribute("aria-hidden"),n.removeAttribute("tabindex")):(n.setAttribute("aria-hidden","true"),n.setAttribute("tabindex","-1")),this.turnstileContainer.setAttribute("data-fillo-challenge-visible",t?"true":"false"))}settleChallengeWatchdog(){this.challengeWatchdog!==null&&typeof window<"u"&&window.clearTimeout(this.challengeWatchdog),this.challengeWatchdog=null}teardownChallengeBridge(){this.challengeMessageHandler&&typeof window<"u"&&window.removeEventListener("message",this.challengeMessageHandler),this.challengeMessageHandler=null,this.settleChallengeWatchdog(),this.challengeFrame?.remove(),this.challengeFrame=null,this.challengeFrameSrc=null,this.challengeFrameOrigin=null}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;oc().then(()=>{if(this.destroyed||n!==this.turnstileAttempt)return;let r=mt();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(R.challengeUnavailable),this.queueRender()}resetChallengeWidget(){this.challengeToken=void 0,this.challengeFrame&&this.challengeFrameOrigin?this.challengeFrame.contentWindow?.postMessage({type:"fillo:challenge:reset"},this.challengeFrameOrigin):this.turnstileWidgetId&&mt()?.reset(this.turnstileWidgetId),this.queueRender()}teardownTurnstileWidget(){if(this.turnstileWidgetId===null&&!this.turnstileLoadInFlight&&this.challengeFrame===null)return;this.turnstileAttempt++,this.teardownChallengeBridge();let t=mt();if(this.turnstileWidgetId&&t)try{t.remove(this.turnstileWidgetId)}catch{}this.turnstileWidgetId=null,this.turnstileLoadInFlight=!1,this.challengeError=!1,this.turnstileContainer=ns(),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(Ot)).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(Ot))[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&&Il(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?Nl(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"}});ht(s,this.theme),L(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===Tt;if(s&&!this.devChrome()&&!this.options.renderOnly&&!this.options.renderError){let c=d("div",{attrs:{"data-fillo":"root","data-state":"unavailable","data-error-code":Tt}});c.hidden=!0,this.element.appendChild(c);return}let a=o.code==="form_target_required"&&this.devChrome()?`${o.message} (${o.code})`:s&&this.devChrome()?o.message:null,l=this.options.renderError?.(o)??d("div",{className:"fillo-form fillo-form--error",text:a??(this.genericUnavailable?"This form is unavailable.":gc(o))});l.hasAttribute("data-fillo")||l.setAttribute("data-fillo","root"),l.hasAttribute("data-state")||l.setAttribute("data-state","error"),o.code&&!l.hasAttribute("data-error-code")&&l.setAttribute("data-error-code",o.code),l.hasAttribute("role")||l.setAttribute("role","alert"),ht(l,this.theme),this.element.appendChild(l);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"}});ht(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(Mr(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)??ac(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"),ht(l,this.theme),this.element.appendChild(l),this.brandingVisible()&&this.element.appendChild(Mr(this.fetchedBrandLabel,this.fetchedBrandHref)),!a.restoredSubmission&&!this.liveSubmissionHandled){this.liveSubmissionHandled=!0;let c=ot(this.schema.settings.redirectUrl);c&&typeof window<"u"?window.location.assign(c):(l.focus(),this.announce(l.textContent??""))}return}this.devChrome()&&L(this.element,mc({preview:this.options.preview===!0,devNotices:this.options.devNotices,syncError:this.syncErrorNotice,staged:this.stagedNotice,draft:this.draftNotice,warningUrl:this.syncWarningUrl,formUrl:this.syncFormUrl,noClient:!this.options.client&&!this.options.renderOnly})),this.element.appendChild(this.renderForm()),this.brandingVisible()&&this.element.appendChild(Mr(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"}});ht(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"?R.closedTitle:R.notOpenTitle})),i.appendChild(d("p",{className:"fillo-not-open-body",text:t==="closed"?R.closed:R.notOpenBody})),L(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),ht(o,this.theme);let s=()=>{t.isLastPage?this.submit():this.next()};if(!n){let f=o;f.noValidate=!0,f.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 f=d("div",{className:"fillo-resume",attrs:{"data-fillo":"resume"}});f.appendChild(d("span",{className:"fillo-resume-text",text:l.editingPrevious?R.editNotice:R.resumeNotice}));let b=d("button",{className:"fillo-resume-clear",text:R.resumeStartOver,attrs:{type:"button"}});b.addEventListener("click",()=>this.resetDraft()),f.appendChild(b),a.appendChild(f)}else l?.resumeLinkFailed&&a.appendChild(d("div",{className:"fillo-resume fillo-resume--expired",attrs:{"data-fillo":"resume"},text:O.resumeLinkExpired}));if(t.pageCount>1&&this.schema?.settings.showProgress!==!1){let f=ft(t.form,t.data),b=Math.max(f.length,1),w=f.indexOf(t.page.id),v=w>=0?w+1:Math.min(t.pageIndex+1,b),S=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)}});S.appendChild(d("div",{className:"fillo-progress-fill",attrs:{"data-fillo":"progressFill"}})),S.firstElementChild?.style.setProperty("--fillo-progress-value",`${v/b*100}%`),a.appendChild(S)}if(t.pageIndex===0){let f=d("header",{className:"fillo-header",attrs:{"data-fillo":"header"}});t.form.title&&f.appendChild(d("h1",{className:"fillo-title",text:t.form.title,attrs:{"data-fillo":"title"}})),t.form.description&&f.appendChild(d("p",{className:"fillo-form-description",text:t.form.description,attrs:{"data-fillo":"description"}})),a.appendChild(f)}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 f of t.blocks){let b=this.renderBlock(Ko(f,this.mutableData,t.form),t);b&&c.appendChild(b)}if(a.appendChild(c),!n){let f=d("input",{className:"fillo-hp",attrs:{type:"text",name:"fillo_hp_field",tabindex:"-1",autocomplete:"off","aria-hidden":"true"}});f.style.position="absolute",f.style.left="-9999px",f.style.top="auto",f.style.width="1px",f.style.height="1px",f.style.opacity="0",f.style.overflow="hidden",f.style.pointerEvents="none",f.addEventListener("input",()=>{this.hpValue=f.value}),a.appendChild(f)}if(i){let f=d("div",{className:"fillo-turnstile-slot",attrs:{"data-fillo":"turnstile-slot"}});f.appendChild(this.turnstileContainer),this.challengeError&&f.appendChild(d("p",{className:"fillo-turnstile-error",attrs:{role:"alert"},text:R.challengeUnavailable})),a.appendChild(f),this.ensureChallengeWidget(this.challenge)}else(this.turnstileWidgetId!==null||this.turnstileLoadInFlight||this.challengeFrame!==null)&&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 f=d("p",{className:"fillo-submit-error",attrs:{role:"alert"},text:u}),b=this.devChrome()&&this.resolutionFailureCode==="form_not_published"&&this.syncWarningCode==="storage_required"?ot(this.syncWarningUrl):null;b&&(f.append(" Connect storage: "),f.appendChild(d("a",{text:b,attrs:{href:b,target:"_blank",rel:"noopener noreferrer"}}))),a.appendChild(f)}let p=!(t.form.settings.submitMode==="auto")||!t.isLastPage||Zo(ho(t.form,t.data))||i;if(p||t.pageCount>1&&!t.isFirstPage){let f=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()),f.appendChild(b)}if(p){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",w=>{w.preventDefault(),s()}),f.appendChild(b)}a.appendChild(f)}return o}fieldRenderer(t){return t.kind==="custom"?this.options.customComponents?.[t.component]??this.options.components?.custom:this.options.components?.[t.kind]??ds}renderChildField=t=>this.fieldRenderer(t.field)?.(t)??null;setGroupFocus=t=>{this.focusIntent=t};renderBlock(t,n){if(!he(t))return sc(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};Do(t,o,a)&&this.submit()},i={field:t,value:n.data[t.id],error:n.errors[t.id]===Ct?_o(t,O):n.errors[t.id],ids:as(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()?ot(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 sc(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 ac(e){let t=d("div",{className:"fillo-form fillo-form--success"}),n=d("div",{className:"fillo-success"});return L(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 Mr(e,t){return d("a",{className:"fillo-powered",text:e??"Powered by Fillo",attrs:{href:Ml(t),target:"_blank",rel:"nofollow noopener noreferrer"}})}function rs(e){return e==="expired"||e==="capped"||e==="storage_full"?"closed":"notOpen"}function lc(){return Wo()}function cc(){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 uc(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 dc(e){let t=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});t.append("Code changes are staged, not live. This page shows your draft, while respondents still get the live version. ");let n=ot(e);return n?(t.appendChild(d("a",{text:"Review and publish in Fillo",attrs:{href:n,target:"_blank",rel:"noopener noreferrer"}})),t.append(".")):t.append("Review and publish the changes in Fillo."),t}function fc(e,t){let n=d("div",{className:"fillo-devwarning",attrs:{role:"alert"}});n.append("Draft form preview \u2014 the form renders for local testing, but Fillo will reject the submission and save no response until you publish it. ");let r=ot(e),i=ot(t);return r?(n.appendChild(d("a",{text:"Connect storage to publish",attrs:{href:r,target:"_blank",rel:"noopener noreferrer"}})),n.append(". ")):i&&(n.appendChild(d("a",{text:"Open in Fillo to publish",attrs:{href:i,target:"_blank",rel:"noopener noreferrer"}})),n.append(". ")),n.append("(Shown only in development and preview.)"),n}function pc(){return d("span",{className:"fillo-preview-badge",text:"Preview",attrs:{"data-fillo":"preview-badge"}})}var is=!1;function hc(){is||Cr()||(is=!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 mc(e){let t=[];return e.preview&&t.push(pc()),e.devNotices===!1||(e.syncError?t.push(uc(e.syncError)):e.staged?t.push(dc(e.formUrl)):e.draft?t.push(fc(e.warningUrl,e.formUrl)):e.noClient&&t.push(cc())),t}var Tt="invalid_form_definition";function os(e){let t=Ke(e);return t.ok?null:t.error??"invalid form definition"}function gc(e){return e.status===404?R.loadFailedNotFound:e.status===0?R.loadFailedNetwork:e.status===422?R.renderFailed:R.loadFailed}function ss(){return new E("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 be(e)?e:new E(e instanceof Error?e.message:String(e),0)}function vn(e,t){let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new E(`Fillo mount target not found: ${String(e)}`,0);let r={...t,initialData:t.initialData??{}};return new Zt(n,r)}function fs(e){let t=d("div");return vn(t,e),t}var bc=typeof HTMLElement<"u"?HTMLElement:class{},Lr=class extends bc{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 Zt&&this.instance.setClient(t)}set theme(t){this.assignedTheme=t,this.mounted&&this.instance instanceof Zt&&this.instance.setTheme(t)}set initialData(t){this.assignedInitialData=t,this.mounted&&this.scheduleMount()}scheduleMount(){this.mountScheduled||(this.mountScheduled=!0,queueMicrotask(()=>{this.mountScheduled=!1,this.isConnected&&this.mount()}))}previewAttrEnabled(){let t=this.getAttribute("data-preview");return t!==null&&t!=="false"&&t!=="0"}renderOnlyAttrEnabled(){let t=this.getAttribute("data-render-only");return t!==null&&t!=="false"&&t!=="0"}mount(){this.instance?.destroy();let t=this.getAttribute("publishable-key")??void 0,n=this.getAttribute("form-id")??void 0,r=this.assignedClient??(n||t?Me({key:t}):void 0);this.instance=vn(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 Pr(e="fillo-form"){typeof customElements>"u"||customElements.get(e)||customElements.define(e,Lr)}typeof customElements<"u"&&Pr();return As(vc);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefillo/dom",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "Framework-agnostic DOM renderer and web component for embedding Fillo forms.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -45,7 +45,7 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@usefillo/core": "^0.28.0"
48
+ "@usefillo/core": "^0.29.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "axe-core": "^4.10.0",