/*! * Stepform v1.0.0 * Multi-step forms for Webflow. Uses the same sf-* attributes as Superform v2, * but hands the final submission to Webflow's own form handler, so submissions * are stored in Webflow and trigger Webflow's form_submission webhook. */(function(){"use strict";const X="1.0.0",nt=document.currentScript;if(window.Stepform&&window.Stepform.__stepform){console.error("[Stepform] The script is included twice on this page. Remove one copy.");return}if(window.Superform&&!window.Superform.__stepform){console.error("[Stepform] Superform is also loaded on this page. Both use the same sf-* attributes, so remove one of the two scripts.");return}const a={form:"sf",debug:"sf-debug",globalDelay:"sf-global-step-delay",saveProgress:"sf-save-progress",prefillUrl:"sf-prefill-url",step:"sf-step",stepProgress:"sf-set-step-progress",stepIndex:"sf-set-step-index",delay:"sf-next-step-delay",goto:"sf-goto",forceGoto:"sf-force-goto",reset:"sf-reset",bindEnter:"sf-bind-enter",bindBackspace:"sf-bind-backspace",logic:"sf-logic",logicGoto:"sf-logic-goto",logicFallback:"sf-logic-fallback",animation:"sf-step-animation",animationDuration:"sf-step-animation-duration",animationEase:"sf-step-animation-ease",el:"sf-el",error:"sf-error",errorClass:"sf-error-class",validation:"sf-validation",checkboxGroup:"sf-checkbox-group",checkboxKeys:"sf-checkbox-bind-key",radioKeys:"sf-radio-bind-key",react:"sf-react",score:"sf-score",scoreCalc:"sf-score-calc",noflash:"sf-noflash",overrideWebflow:"sf-override-webflow",noSave:"sf-no-save",excludeSkipped:"sf-exclude-skipped",scrollTop:"sf-scroll-top",repeat:"sf-repeat",repeatItem:"sf-repeat-item",repeatMin:"sf-repeat-min",repeatMax:"sf-repeat-max",repeatAdd:"sf-repeat-add",repeatRemove:"sf-repeat-remove",repeatNumber:"sf-repeat-number",repeatOutput:"sf-repeat-output"},v=Object.freeze({BEFORE_STEP_CHANGE:"BEFORE_STEP_CHANGE",ON_STEP_CHANGE:"ON_STEP_CHANGE",BEFORE_FORM_SUBMIT:"BEFORE_FORM_SUBMIT",ON_FORM_SUBMIT:"ON_FORM_SUBMIT",ON_SUBMIT_SUCCESS:"ON_SUBMIT_SUCCESS",ON_SUBMIT_ERROR:"ON_SUBMIT_ERROR",ON_INPUT_CHANGE:"ON_INPUT_CHANGE",ON_RESET:"ON_RESET"}),H=5,ot="sf-react-hide",at="sf-repeat-hide",Nt=["name","data-name","sf-error","sf-checkbox-group"],dt=["id","for"],q=new WeakMap,mt="stepform-data",K="sf_form",Z="sf_fill",lt=["prev","previous","back"],Rt=["fade","slide-top","slide-left","slide-bottom","slide-right","none"],Ot={fade:"fade","slide-top":"slide-bottom","slide-bottom":"slide-top","slide-left":"slide-right","slide-right":"slide-left",none:"none"},Ft={"slide-top":["translateY(-100px)","translateY(100px)"],"slide-bottom":["translateY(100px)","translateY(-100px)"],"slide-left":["translateX(-100px)","translateX(100px)"],"slide-right":["translateX(100px)","translateX(-100px)"]},It=["submit","button","reset","image","hidden"],Tt=/^[^\s@]+@[^\s@]+\.[^\s@.]{2,}$/,p={warn:(...o)=>console.warn("[Stepform]",...o),error:(...o)=>console.error("[Stepform]",...o)},x=(o,t)=>t===0?o:`${o}-${t}`,pt=o=>Array.from({length:H},(t,e)=>`[${x(o,e)}]`).join(","),V=o=>window.CSS&&CSS.escape?CSS.escape(String(o)):String(o).replace(/["\\]/g,"\\$&"),gt=o=>new Promise(t=>setTimeout(t,o)),Y=()=>!!(window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);function J(o,t){if(o==null||String(o).trim()==="")return t;const e=String(o).trim(),r=parseFloat(e);return isFinite(r)?/[^m]s$/i.test(e)?r*1e3:r:t}function bt(o,t){return o&&o.hasAttribute(t)?parseFloat(o.getAttribute(t)):NaN}function U(o){return!o||!o.isConnected||o.closest("."+ot)||!o.getClientRects().length?!1:getComputedStyle(o).visibility!=="hidden"}function _t(o){return!!o&&o.style.display!=="none"&&getComputedStyle(o).display!=="none"}function Mt(o){return!o||o.nodeType!==1?!1:o.isContentEditable||o.nodeName==="TEXTAREA"||o.nodeName==="SELECT"?!0:o.nodeName==="INPUT"?!["submit","button","reset","image","checkbox","radio","range","color","file"].includes(o.type):!1}function Q(o){return!!o&&(o.nodeName==="INPUT"&&(o.type==="submit"||o.type==="image")||o.nodeName==="BUTTON"&&o.type==="submit")}function yt(o){const t=/^\s*([a-zA-Z]+)\s*\(([\s\S]*)\)\s*$/.exec(o||"");return t?{name:t[1].toLowerCase(),args:t[2]}:null}function Pt(o){const t=[];let e=0,r=null,i="";for(let s=0;s(o.match(l)||[]).length;return[[t,/\p{N}/gu],[e,/\p{Ll}/gu],[r,/\p{Lu}/gu],[i,/[^\p{L}\p{N}\s]/gu]].every(([l,u])=>l===null?!0:l===0?s(u)===0:s(u)>=l)}function qt(o){try{const t=new URL(o);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function ct(o){if(!/%[0-9a-f]{2}/i.test(o))return o;try{return decodeURIComponent(o)}catch{return o}}function tt(o){const t=e=>{e.parentElement&&Array.from(e.parentElement.children).forEach(r=>{r!==e&&r.matches(".w-checkbox-input--inputType-custom, .w-radio-input--inputType-custom")&&r.classList.toggle("w--redirected-checked",e.checked)})};o.type==="radio"&&o.name&&o.form?o.form.querySelectorAll(`input[type="radio"][name="${V(o.name)}"]`).forEach(t):t(o)}const W=o=>[o].concat(Array.from(o.querySelectorAll("*")));function Ut(o){W(o).forEach(t=>{const e={};Nt.concat(dt).forEach(r=>{t.hasAttribute(r)&&(e[r]=t.getAttribute(r))}),Object.keys(e).length&&q.set(t,e)})}function St(o,t){const e=W(o),r=W(t);e.forEach((i,s)=>{q.has(i)&&r[s]&&q.set(r[s],q.get(i))})}function vt(o,t){W(o).forEach(e=>{const r=q.get(e);r&&Object.keys(r).forEach(i=>{const s=t===1?r[i]:dt.includes(i)?`${r[i]}-${t}`:`${r[i]} ${t}`;e.getAttribute(i)!==s&&e.setAttribute(i,s)}),e.hasAttribute(a.repeatNumber)&&(e.textContent=String(t))})}function ut(o){const t={};return o.querySelectorAll("input, select, textarea").forEach(e=>{const r=q.get(e),i=r&&(r["data-name"]||r.name);if(!i)return;const s=(e.type||"").toLowerCase();["submit","button","reset","image","file","password"].includes(s)||(s==="checkbox"?t[i]=e.checked:s==="radio"?e.checked?t[i]=e.value:i in t||(t[i]=""):e.nodeName==="SELECT"&&e.multiple?t[i]=Array.from(e.selectedOptions).map(n=>n.value):t[i]=e.value)}),t}function Dt(o,t){const e=o.toLowerCase();return["href","src","action","formaction","xlink:href","poster"].includes(e)&&/^\s*(javascript|vbscript|data):/i.test(t)?"#":t}function Ht(){if(document.getElementById("sf-style"))return;const o=document.createElement("style");o.id="sf-style",o.textContent=`.${ot},.${at}{display:none!important}[${a.step}]:focus{outline:none}`,(document.head||document.documentElement).appendChild(o)}const G={read(){try{const o=window.localStorage.getItem(mt),t=o?JSON.parse(o):{};return t&&typeof t=="object"?t:{}}catch{return{}}},write(o,t){try{const e=G.read();t===void 0?delete e[o]:e[o]=t,window.localStorage.setItem(mt,JSON.stringify(e))}catch{G.warned||p.warn("Could not save form progress (browser storage is blocked or full)."),G.warned=!0}}},et=function(){const o=new Map,t=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]),e=new Set,r=(c,d)=>d.forEach(m=>typeof c[m]=="function"&&e.add(c[m]));r(String.prototype,["at","charAt","charCodeAt","codePointAt","concat","endsWith","includes","indexOf","lastIndexOf","localeCompare","normalize","padEnd","padStart","repeat","replace","replaceAll","slice","split","startsWith","substring","substr","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","toString","trim","trimEnd","trimStart"]),r(Array.prototype,["at","concat","includes","indexOf","join","lastIndexOf","slice","toString","flat"]),r(Number.prototype,["toFixed","toPrecision","toString","toLocaleString"]),r(Math,Object.getOwnPropertyNames(Math)),[Number,String,Boolean,parseInt,parseFloat,isNaN,isFinite,Array.isArray,Number.isFinite,Number.isInteger,Number.isNaN,Number.parseFloat,Number.parseInt].forEach(c=>e.add(c));const i={Math,Number,String,Boolean,parseInt,parseFloat,isNaN,isFinite,Array:Object.freeze({isArray:Array.isArray})},s={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},n=["===","!==","**","==","!=","<=",">=","&&","||","??","?.","+","-","*","/","%","<",">","!","(",")","[","]",",",".","?",":"],l={n:` `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0"},u=(c,d)=>Object.prototype.hasOwnProperty.call(c,d);function f(c,d){if(c==null)return;const m=typeof d=="number"?d:String(d);if(t.has(m))throw new Error(`Property "${m}" is not allowed`);return c[m]}function _(c,d){const m=c[d];return m==="u"&&/^[0-9a-fA-F]{4}$/.test(c.substr(d+1,4))?[String.fromCharCode(parseInt(c.substr(d+1,4),16)),d+5]:[u(l,m)?l[m]:m,d+1]}function $(c){const d=[];let m=0;for(;mc.startsWith(E,m));if(w==="?."&&/[0-9]/.test(c[m+2]||"")&&(w="?"),!w)throw new SyntaxError(`Unexpected character "${y}"`);d.push({t:"p",v:w}),m+=w.length}return d.push({t:"eof"}),d}const C={"===":(c,d)=>c===d,"!==":(c,d)=>c!==d,"==":(c,d)=>c==d,"!=":(c,d)=>c!=d,"<":(c,d)=>c":(c,d)=>c>d,"<=":(c,d)=>c<=d,">=":(c,d)=>c>=d,"+":(c,d)=>c+d,"-":(c,d)=>c-d,"*":(c,d)=>c*d,"/":(c,d)=>c/d,"%":(c,d)=>c%d};function I(c){let d=0;const m=()=>c[d],y=()=>c[d++],w=h=>m().t==="p"&&m().v===h,E=h=>{if(!w(h))throw new SyntaxError(`Expected "${h}"`);d++};function O(h,b){return function(){let g=b();for(;m().t==="p"&&h.includes(m().v);){const S=C[y().v],k=g,A=b();g=N=>S(k(N),A(N))}return g}}function T(h){const b=[];if(!w(h))do b.push(j());while(w(",")&&y());return E(h),b}function M(){const h=y();if(h.t==="num"||h.t==="str"){const b=h.v;return()=>b}if(h.t==="tpl")return b=>{let g=h.strs[0];return h.exprs.forEach((S,k)=>{const A=S(b);g+=(A==null?"":String(A))+h.strs[k+1]}),g};if(h.t==="id"){if(u(s,h.v)){const g=s[h.v];return()=>g}if(u(i,h.v)){const g=i[h.v];return()=>g}const b=h.v;return g=>u(g,b)?g[b]:void 0}if(h.t==="p"&&h.v==="("){const b=j();return E(")"),b}if(h.t==="p"&&h.v==="["){const b=T("]");return g=>b.map(S=>S(g))}throw new SyntaxError(h.t==="eof"?"Unexpected end of expression":`Unexpected "${h.v}"`)}function P(){let h=M(),b=null;for(;;){if(w(".")||w("?.")){if(y().v==="?."&&(w("[")||w("(")))continue;const S=y();if(S.t!=="id")throw new SyntaxError("Expected a property name");const k=h,A=S.v,N=L=>{const st=k(L);return[st,f(st,A)]};b=N,h=L=>N(L)[1];continue}if(w("[")){y();const g=h,S=j();E("]");const k=A=>{const N=g(A);return[N,f(N,S(A))]};b=k,h=A=>k(A)[1];continue}if(w("(")){y();const g=T(")"),S=b,k=h;h=A=>{const N=S?S(A):[void 0,k(A)],L=N[1];if(L!=null){if(typeof L!="function"||!e.has(L))throw new Error("This function is not allowed in expressions");return L.apply(N[0],g.map(st=>st(A)))}},b=null;continue}return h}}function B(){const h=m();if(h.t==="p"&&(h.v==="!"||h.v==="-"||h.v==="+")){y();const b=B();return h.v==="!"?g=>!b(g):h.v==="-"?g=>-b(g):g=>+b(g)}if(h.t==="id"&&h.v==="typeof"){y();const b=B();return g=>typeof b(g)}return P()}function F(){const h=B();if(w("**")){y();const b=F();return g=>h(g)**b(g)}return h}const Vt=O(["*","/","%"],F),Wt=O(["+","-"],Vt),zt=O(["<",">","<=",">="],Wt),xt=O(["===","!==","==","!="],zt);function $t(){let h=xt();for(;w("&&");){y();const b=h,g=xt();h=S=>b(S)&&g(S)}return h}function Xt(){let h=$t();for(;w("||")||w("??");){const b=y().v,g=h,S=$t();h=b==="||"?k=>g(k)||S(k):k=>{const A=g(k);return A==null?S(k):A}}return h}function j(){const h=Xt();if(!w("?"))return h;y();const b=j();E(":");const g=j();return S=>h(S)?b(S):g(S)}const Zt=j();if(m().t!=="eof")throw new SyntaxError(`Unexpected "${m().v}"`);return Zt}function z(c){const d=String(c).trim();if(!d)throw new SyntaxError("Empty expression");if(o.has(d))return o.get(d);const m=I($(d));return o.set(d,m),m}return{compile:z,evaluate:(c,d)=>z(c)(d||{})}}();class Gt{constructor(){this.map=new Map}on(t,e){return typeof e!="function"?()=>{}:(this.map.has(t)||this.map.set(t,new Set),this.map.get(t).add(e),()=>this.map.get(t).delete(e))}emit(t,e){const r=this.map.get(t);return r?Array.from(r).map(i=>{try{return i(e)}catch(s){p.error(`A ${t} callback threw an error:`,s);return}}):[]}clear(){this.map.clear()}}const R=[],wt=o=>R.find(t=>t.formName===o);let rt=null;class D{constructor(t,e){const r=e&&typeof e=="object"?e:{},i=typeof t=="string"?document.querySelector(t):t;if(!(i instanceof HTMLElement))throw new Error("[Stepform] Pass a CSS selector or an element for the form container.");if(i.__stepform)return i.__stepform;const s=i.nodeName==="FORM"?i:i.querySelector("form");if(!s)throw new Error('[Stepform] No
found inside the element with the "sf" attribute. Put "sf" on the Form Block or on a wrapper around it.');this.version=X,this.formContainer=i,this.form=s,this.formBlock=s.closest(".w-form")||i,this.formName=i.getAttribute(a.form)||s.getAttribute("name")||s.getAttribute("data-name")||`sf_${R.length}`,this.debugMode=!!r.debugMode,this.debugModeSteps=!!r.debugModeSteps,this.isSubmitted=!1,this.isSubmitting=!1,this.navigationStack=[],this.preventWebflowFormSubmit=i.hasAttribute(a.overrideWebflow),this.excludeSkipped=i.hasAttribute(a.excludeSkipped),this.globalDelay=J(i.getAttribute(a.globalDelay),0),this._events=new Gt,this._navHooks=new Map,this._validationHooks=new Map,this._cleanups=[],this._busy=!1,this._restoring=!1,this._submitIntent=!1,this._lastArrowKey=-1/0,this._inputQueued=!1,this._activeControls=new Set,this._errorStates=new Map,this._fieldByControl=new Map,this._reactions=[],this._uid=R.length;const n=getComputedStyle(s).display;if(this.defaultFormDisplay=n&&n!=="none"?n:"block",this.animation=this._readAnimation(),Ht(),s.setAttribute("novalidate",""),this.steps=this._collectSteps(),!this.steps.length)throw new Error(`[Stepform] Form "${this.formName}" has no visible elements with the "${a.step}" attribute.`);this._normalizeRadioGotos(),this._setupRepeats(),this._collectFields(),this._collectScores(),this._collectReactions(),this._bindEvents(),this._lint(),this.viewManager={goto:u=>this.goto(u)},this.scoreManager={getAllScores:()=>this.getScores()},this.callbackStore={on:(u,f)=>this._events.on(u,f),emit:(u,f)=>this._events.emit(u,f)},this.debugMode&&this.onStepChange(u=>this._debugLog(u)),this._restoreData();const l=this.steps[0];this.steps.forEach(u=>{u.el.style.display=u===l||this.debugModeSteps?u.defaultDisplay:"none"}),this.navigationStack=[l],this._afterStepChange(),i.__stepform=this,R.push(this)}getFormData(){this._syncRepeatOutputs();const t={};return new FormData(this.form).forEach((e,r)=>{if(!Object.prototype.hasOwnProperty.call(t,r)){t[r]=e;return}Array.isArray(t[r])||(t[r]=[t[r]]),t[r].push(e)}),(this.repeats||[]).forEach(e=>{t[e.name]=e.items.map(ut)}),t}addRepeatItem(t){const e=this._repeat(t);if(!e||this.isSubmitting||this.isSubmitted)return null;const r=this._repeatAdd(e);return r&&this._afterRepeatChange(e),r}removeRepeatItem(t,e){const r=this._repeat(t);if(!r||this.isSubmitting||this.isSubmitted)return!1;const i=r.items[e==null?r.items.length-1:e];return!i||r.items.length<=r.min?!1:(i.remove(),r.items.splice(r.items.indexOf(i),1),this._afterRepeatChange(r),!0)}getRepeatCount(t){const e=this._repeat(t);return e?e.items.length:0}getCurrentStep(){return this.navigationStack[this.navigationStack.length-1]}getScores(){const t=Object.assign({},this.scoreVars),e=[];return this.navigationStack.forEach(r=>{e.includes(r)||e.push(r)}),this.scoreItems.filter(r=>e.includes(r.step)).sort((r,i)=>e.indexOf(r.step)-e.indexOf(i.step)).forEach(r=>{r.ops.forEach(i=>{!(i.variable in t)||!Kt(r.el,i.answer)||(i.operation==="add"?t[i.variable]+=i.number:i.operation==="minus"?t[i.variable]-=i.number:i.operation==="multiply"?t[i.variable]*=i.number:i.operation==="divide"&&(t[i.variable]/=i.number))})}),t._rank=Object.keys(this.scoreVars).sort((r,i)=>t[i]-t[r]),t}registerNavigationHook(t,e){return this._navHooks.set(t,e),()=>this._navHooks.delete(t)}registerInputValidationHook(t,e){return this._validationHooks.set(t,e),()=>this._validationHooks.delete(t)}beforeStepChange(t){return this._events.on(v.BEFORE_STEP_CHANGE,t)}onStepChange(t){return this._events.on(v.ON_STEP_CHANGE,t)}beforeFormSubmit(t){return this._events.on(v.BEFORE_FORM_SUBMIT,t)}onFormSubmit(t){return this._events.on(v.ON_FORM_SUBMIT,t)}onSubmitSuccess(t){return this._events.on(v.ON_SUBMIT_SUCCESS,t)}onSubmitError(t){return this._events.on(v.ON_SUBMIT_ERROR,t)}onInputChange(t){return this._events.on(v.ON_INPUT_CHANGE,t)}onReset(t){return this._events.on(v.ON_RESET,t)}next(){return this.goto("next")}prev(){return this.goto("prev")}submit(){return this.goto("submit")}async goto(t,e){const r=e||{};if(this.isSubmitted)return p.warn(`Form "${this.formName}" was already submitted. Call reset() to start again.`),!1;if(this._busy||this.isSubmitting)return!1;this._busy=!0;try{return await this._navigate(t,r,0)}catch(i){return p.error(i),!1}finally{this._busy=!1}}async validateStep(t){const e=t||this.getCurrentStep();if(!e)return!0;const r=this.fields.filter(n=>n.step===e),i=await Promise.all(r.map(n=>this._validateField(n))),s=r.find((n,l)=>!i[l]);return s&&this._focusField(s),!s}reset(){this._busy=!1,this.isSubmitted=!1,this.isSubmitting=!1;let t=!1;(this.repeats||[]).forEach(s=>{for(;s.items.length>s.min;)s.items.pop().remove(),t=!0;for(;s.items.length{s.dirty=!1,this._setFieldError(s,!1)}),this._activeControls.clear(),this._clearSaved();const e=this.steps[0];this.steps.forEach(s=>{s.el.style.display=s===e||this.debugModeSteps?s.defaultDisplay:"none"}),this.navigationStack=[e],this.form.style.display=this.defaultFormDisplay;const r=this._doneEl(),i=this._failEl();r&&(r.style.display="none"),i&&(i.style.display="none"),this._events.emit(v.ON_RESET,this._payload()),this._afterStepChange()}destroy(){this._cleanups.forEach(e=>e()),this._cleanups=[],this._events.clear();const t=R.indexOf(this);t>=0&&R.splice(t,1),delete this.formContainer.__stepform}_readAnimation(){const t=this.formContainer;let e=(t.getAttribute(a.animation)||"fade").trim();return Rt.includes(e)||(p.warn(`Unknown ${a.animation} "${e}", using "fade".`),e="fade"),{type:e,duration:Math.max(0,J(t.getAttribute(a.animationDuration),300)),ease:(t.getAttribute(a.animationEase)||"ease-in").trim()}}_collectSteps(){const t=Array.from(this.form.querySelectorAll(`[${a.step}]`)),e=t.filter(i=>getComputedStyle(i).display!=="none");this.debugMode&&e.length!==t.length&&p.warn(`${t.length-e.length} step(s) in "${this.formName}" have display: none and are not used.`);const r=e.length;return e.map((i,s)=>{const n=bt(i,a.stepProgress),l=bt(i,a.stepIndex);return{name:i.getAttribute(a.step)||`step-${s+1}`,index:s,el:i,defaultDisplay:getComputedStyle(i).display||"block",stepProgressValue:Math.round(isFinite(n)?n:(s+1)/r*100),stepCountValue:isFinite(l)?l:s+1,nextStepDelay:i.hasAttribute(a.delay)?J(i.getAttribute(a.delay),NaN):NaN}})}_stepOf(t){return this.steps.find(e=>e.el.contains(t))||null}_normalizeRadioGotos(){const t=[a.goto,a.logicFallback,a.delay];for(let e=0;e{if(e.nodeName==="INPUT")return;const r=Array.from(e.querySelectorAll('input[type="radio"]'));r.length&&(r.forEach(i=>{t.forEach(s=>{e.hasAttribute(s)&&!i.hasAttribute(s)&&i.setAttribute(s,e.getAttribute(s))}),i.hasAttribute(a.bindEnter)||i.setAttribute(a.bindEnter,"false")}),e.removeAttribute(a.goto),e.removeAttribute(a.delay))})}_collectFields(){this.fields=[],this._claimed=new Set,this.steps.forEach(t=>{t.el.querySelectorAll(`[${a.checkboxGroup}]`).forEach(r=>{this._addField({kind:"checkbox-group",name:r.getAttribute(a.checkboxGroup),step:t,el:r,controls:Array.from(r.querySelectorAll('input[type="checkbox"]'))})});const e=new Set;t.el.querySelectorAll("input, select, textarea").forEach(r=>{if(this._fieldByControl.has(r))return;const i=(r.type||"").toLowerCase();if(!It.includes(i)&&!this._repeatOutputs.has(r)){if(i==="radio"){const s=r.name||r;if(e.has(s))return;e.add(s);const n=r.name?Array.from(t.el.querySelectorAll(`input[type="radio"][name="${V(r.name)}"]`)):[r];this._addField({kind:"radio",name:r.name,step:t,el:r,controls:n});return}this._addField({kind:i==="checkbox"?"checkbox":"input",name:r.getAttribute("name")||"",step:t,el:r,controls:[r]})}})})}_addField(t){t.id=`${this._uid}-${this.fields.length}`,t.dirty=!1,t.showing=!1;const e=(t.el.getAttribute(a.validation)||"").replace(/\s+/g,"");if(t.rule=e?this._parseRule(e,t.el):null,t.rule&&t.kind==="input"){const r=t.el;t.rule.kind==="length"&&(isFinite(t.rule.min)&&!r.hasAttribute("minlength")&&r.setAttribute("minlength",t.rule.min),isFinite(t.rule.max)&&!r.hasAttribute("maxlength")&&r.setAttribute("maxlength",t.rule.max)),t.rule.kind==="minmax"&&["number","range"].includes(r.type)&&(isFinite(t.rule.min)&&!r.hasAttribute("min")&&r.setAttribute("min",t.rule.min),isFinite(t.rule.max)&&!r.hasAttribute("max")&&r.setAttribute("max",t.rule.max))}t.errors=this._findErrors(t),t.controls.forEach(r=>this._fieldByControl.set(r,t)),this.fields.push(t)}_parseRule(t,e){const r=yt(t),i=()=>(p.error(`Invalid ${a.validation} "${t}".`,e),{kind:"invalid"});if(!r)return i();const s=r.args.split(","),n=l=>l==null||l===""?NaN:parseFloat(l);switch(r.name){case"words":case"length":case"minmax":case"checkbox":{const l=n(s[0]),u=n(s[1]);return!isFinite(l)&&!isFinite(u)?i():{kind:r.name,min:l,max:u}}case"hook":return r.args?{kind:"hook",hook:r.args}:i();case"must":return s.length!==4?i():{kind:"must",counts:s.map(l=>l==="any"?null:isFinite(parseInt(l,10))?parseInt(l,10):0)};default:return i()}}_findErrors(t){const e=[],r=(f,_,$)=>{const C=this._errorState(f,_,$);e.includes(C)||e.push(C)},i=new Set([t.name,t.name.replace(/-/g," "),t.name.replace(/ /g,"-")]);if(t.name&&this.formContainer.querySelectorAll(`[${a.error}]`).forEach(f=>{i.has(f.getAttribute(a.error))&&(f.hasAttribute(a.errorClass)?r(f,"class",f.getAttribute(a.errorClass)):r(f,"display"))}),t.kind==="radio")return e;const s=t.el;if(s.hasAttribute(a.errorClass))r(s,"class",s.getAttribute(a.errorClass));else{const f=Array.from(s.classList).slice(1).find(_=>/(error|invalid|fail)/i.test(_));f&&r(s,"class",f)}const n=s.parentElement;n&&n!==this.form&&n.hasAttribute(a.errorClass)&&!n.hasAttribute(a.step)&&r(n,"class",n.getAttribute(a.errorClass));const l=s.nextElementSibling;return[l,s.previousElementSibling,l&&l.nextElementSibling,n&&n!==this.form&&!n.hasAttribute(a.step)?n.nextElementSibling:null].forEach(f=>{f&&this._claimed.has(f)&&!e.some(_=>_.el===f)||this._looksLikeError(f)&&r(f,f.hasAttribute(a.errorClass)?"class":"display",f.getAttribute(a.errorClass))}),e.forEach(f=>this._claimed.add(f.el)),e}_looksLikeError(t){return!t||!(t instanceof HTMLElement)||t.hasAttribute(a.error)||t.hasAttribute(a.step)||t.matches("input, select, textarea, button, label, form, .w-form-done, .w-form-fail")||t.querySelector("input, select, textarea")?!1:/(error|invalid|fail)/i.test(t.getAttribute("class")||"")}_errorState(t,e,r){let i=this._errorStates.get(t);if(i)return i;if(e==="class"&&r){const s=r.split(/\s+/).filter(Boolean);s.forEach(n=>t.classList.remove(n)),i={el:t,mode:e,classes:s,owners:new Set,visible:!1}}else{const s=getComputedStyle(t).display;i={el:t,mode:"display",display:s&&s!=="none"?s:"block",owners:new Set,visible:!1},t.style.display="none",t.hasAttribute("aria-live")||t.setAttribute("aria-live","polite"),t.id||(t.id=`sf-error-${this._uid}-${this._errorStates.size}`)}return this._errorStates.set(t,i),i}_setFieldError(t,e){t.showing=e,t.controls.forEach(r=>{e?r.setAttribute("aria-invalid","true"):r.removeAttribute("aria-invalid"),t.errors.forEach(i=>{if(i.mode!=="display")return;const s=(r.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean);s.includes(i.el.id)||r.setAttribute("aria-describedby",s.concat(i.el.id).join(" "))})}),t.errors.forEach(r=>{e?r.owners.add(t.id):r.owners.delete(t.id);const i=r.owners.size>0;if(i!==r.visible)if(r.visible=i,r.mode==="class")r.classes.forEach(s=>r.el.classList.toggle(s,i));else if(i){if(r.el.style.display=r.display,typeof r.el.animate=="function"&&!Y())try{r.el.animate([{opacity:0},{opacity:1}],{duration:150})}catch{}}else r.el.style.display="none"})}_isActive(t){return t.controls.length&&t.controls.every(e=>e.disabled)?!1:t.kind==="checkbox-group"?U(t.el):t.controls.some(U)}async _validateField(t){const e=this._isActive(t);t.controls.forEach(i=>e?this._activeControls.add(i):this._activeControls.delete(i));let r=!0;if(e)try{r=await this._computeValidity(t)}catch(i){p.error("Validation failed:",i),r=!1}return this._setFieldError(t,!r),r}async _computeValidity(t){const e=t.rule,r=e&&e.kind==="hook";switch(t.kind){case"checkbox-group":{const i=t.controls.filter(n=>n.checked&&!n.disabled).length;return(t.el.hasAttribute("required")||t.controls.some(n=>n.required))&&i===0?!1:e?this._checkRule(t,i):!0}case"radio":{const i=t.controls.find(s=>s.checked);return t.controls.some(s=>s.required)&&!i?!1:r?this._checkRule(t,i?i.value:""):!0}case"checkbox":return t.el.required&&!t.el.checked?!1:r?this._checkRule(t,t.el.checked):!0;default:{const i=t.el;if(i.validity&&i.validity.badInput)return!1;if(i.nodeName==="SELECT"&&i.multiple){const n=Array.from(i.selectedOptions).map(l=>l.value).filter(Boolean);return i.required&&!n.length?!1:r?this._checkRule(t,n):!0}if(i.type==="file"){const n=i.files?i.files.length:0;return i.required&&!n?!1:n?!(i.validity&&!i.validity.valid&&!i.validity.valueMissing):!0}const s=i.value;return String(s).trim()===""?i.required?!1:r?this._checkRule(t,s):!0:!jt(i)||i.type==="email"&&!Tt.test(s.trim())||i.type==="url"&&!qt(s.trim())?!1:e?this._checkRule(t,s):!0}}}async _checkRule(t,e){const r=t.rule,i=s=>(!isFinite(r.min)||s>=r.min)&&(!isFinite(r.max)||s<=r.max);switch(r.kind){case"words":return i(Bt(e));case"length":return i(String(e).length);case"minmax":{const s=parseFloat(e);return isFinite(s)&&i(s)}case"checkbox":return i(e);case"must":return Lt(String(e),...r.counts);case"hook":{const s=this._validationHooks.get(r.hook);if(!s)return p.error(`No validation hook named "${r.hook}" is registered.`,t.el),!1;try{return await s(Object.assign(this._payload(),{value:e,input:t.el}))===!0}catch(n){return p.error(`Validation hook "${r.hook}" threw an error:`,n),!1}}default:return!1}}_focusField(t){const e=t.controls.find(U)||t.controls[0];if(!e)return;try{e.focus({preventScroll:!0})}catch{}const r=(e.closest("label")||e).getBoundingClientRect();(r.top<0||r.bottom>window.innerHeight)&&(e.closest("label")||e).scrollIntoView({block:"center",behavior:Y()?"auto":"smooth"})}_bindEvents(){const t=(r,i,s,n)=>{r.addEventListener(i,s,n),this._cleanups.push(()=>r.removeEventListener(i,s,n))},e=()=>{rt=this};t(this.formContainer,"pointerdown",e),t(this.formContainer,"focusin",e),t(this.formContainer,"click",r=>{r.isTrusted&&e(),this._onClick(r)}),t(this.form,"submit",r=>this._onSubmit(r)),t(window,"submit",r=>{r.target===this.form&&this._submitIntent&&(this._handledExternally=r.defaultPrevented)}),t(this.form,"input",r=>this._onInput(r)),t(this.form,"change",r=>this._onInput(r)),t(this.form,"focusout",r=>{const i=this._fieldByControl.get(r.target);i&&(i.dirty||i.showing)&&this._validateField(i)}),t(document,"keydown",r=>this._onKeydown(r))}_onClick(t){if(this._restoring)return;const e=t.target instanceof Element?t.target:null;if(!e)return;const r=e.closest(`[${a.reset}]`);if(r&&this.formContainer.contains(r)){t.preventDefault(),this.reset();return}const i=e.closest(`[${a.repeatAdd}]`);if(i&&this.formContainer.contains(i)){t.preventDefault();const u=this._repeatFor(i),f=u&&this.addRepeatItem(u.name);f&&this._focusIn(f);return}const s=e.closest(`[${a.repeatRemove}]`);if(s&&this.formContainer.contains(s)){t.preventDefault();const u=s.closest(`[${a.repeatItem}]`),f=u&&this.repeats.find($=>$.items.includes(u));if(!f)return;const _=f.items.indexOf(u);if(this.removeRepeatItem(f.name,_)){const $=f.items[_]||f.items[_-1];if($)this._focusIn($);else{const C=this.formContainer.querySelector(`[${a.repeatAdd}]`);C&&this._repeatFor(C)===f&&C.focus()}}return}const n=e.closest(`[${a.goto}], input[type="submit"], input[type="image"], button`);!n||!this.formContainer.contains(n)||!n.hasAttribute(a.goto)&&!Q(n)||(n.nodeName==="INPUT"&&(n.type==="radio"||n.type==="checkbox")||t.preventDefault(),n.type==="radio"&&performance.now()-this._lastArrowKey<150)||this._activate(n)}_activate(t){const e=t.getAttribute(a.goto)||(Q(t)?"submit":null);if(!e)return;const r=this._stepOf(t);if(r){if(r!==this.getCurrentStep())return;this.goto(e,{source:t})}else this.goto(e,{source:t,external:!t.hasAttribute(a.forceGoto)})}_onSubmit(t){if(this._submitIntent||(t.preventDefault(),t.stopImmediatePropagation(),this._restoring||this.isSubmitted||this.isSubmitting))return;const e=t.submitter||null,r=e&&e.getAttribute(a.goto)||"submit";this.goto(r,{source:e})}_onInput(t){const e=this._fieldByControl.get(t.target);e&&(e.dirty=!0,e.showing&&this._validateField(e)),!this._inputQueued&&(this._inputQueued=!0,Promise.resolve().then(()=>{this._inputQueued=!1;const r=this._payload();this._runReactions(r),this._events.emit(v.ON_INPUT_CHANGE,r)}))}_onKeydown(t){if(t.isComposing||t.altKey||t.ctrlKey||t.metaKey)return;const e=document.activeElement,r=!!e&&this.formContainer.contains(e);if(t.key==="Enter"){r&&e.nodeName==="INPUT"&&!["submit","button","reset","image","file"].includes(e.type)?(t.preventDefault(),this._triggerBound("enter")):!r&&this._ownsKeyboard()&&this._triggerBound("enter");return}if(t.key&&t.key.indexOf("Arrow")===0){r&&e.type==="radio"&&(this._lastArrowKey=performance.now());return}if(!(Mt(e)||!(r||this._ownsKeyboard()))){if(t.key==="Backspace"){this._triggerBound("backspace")&&t.preventDefault();return}t.key&&t.key.length===1&&/[0-9a-z]/i.test(t.key)&&this._selectByKey(t.key)}}_ownsKeyboard(){const t=document.activeElement;return t&&t!==document.body&&t!==document.documentElement||!this._onScreen()?!1:rt&&rt._onScreen()?rt===this:!R.some(e=>e!==this&&e._onScreen())}_onScreen(){if(this.isSubmitted||!U(this.formContainer))return!1;const t=this.formContainer.getBoundingClientRect();return t.bottom>0&&t.top{if(s.type==="radio"||s.type==="checkbox"||!s.hasAttribute(a.goto)&&!Q(s)||!U(s))return!1;const n=s.getAttribute(r);if(n===""||n==="true")return!0;if(n==="false")return!1;const l=(s.getAttribute(a.goto)||"submit").trim();return t==="enter"?l==="next"||l==="submit":lt.includes(l)});return i?(this._activate(i),!0):!1}_selectByKey(t){const e=this.getCurrentStep();if(!e||this._busy||this.isSubmitting)return;const r=e.el.querySelector('input[type="radio"]')?"radio":"checkbox",i=(e.el.getAttribute(r==="radio"?a.radioKeys:a.checkboxKeys)||"number").trim().toLowerCase(),s=t.toLowerCase();let n=-1;if(i==="number"&&/^[0-9]$/.test(s)?n=s==="0"?9:parseInt(s,10)-1:i==="letter"&&/^[a-z]$/.test(s)&&(n=s.charCodeAt(0)-97),n<0)return;const l=Array.from(e.el.querySelectorAll(`input[type="${r}"]`)).filter(U)[n];l&&!l.disabled&&l.click()}async _navigate(t,e,r){if(r>10)throw new Error("Too many chained logic()/hook() redirects.");const i=this.getCurrentStep(),s=await this._resolve(t,e.source||null,i);if(!s)return!1;if("redirect"in s)return s.redirect==null?!1:this._navigate(s.redirect,e,r+1);if(s.submit)return this._submit(e.source||null);if(s.back)return this.navigationStack.length<2?!1:this._moveBack(this.navigationStack.length-2,e);if(i&&s.index===i.index)return!1;const n=this.navigationStack.findIndex(l=>l.index===s.index);return n>=0?this._moveBack(n,e):e.external?(p.warn(`Elements outside a step can only go back to visited steps. Add "${a.forceGoto}" to allow "${t}".`,e.source),!1):this._moveForward(this.steps[s.index],e)}async _resolve(t,e,r){const i=(u,f)=>u>=0&&uu.name===s);return l>=0?{index:l}:s==="submit"?{submit:!0}:(p.error(`"${s}" is not a valid sf-goto value or step name.`,e||""),null)}_evaluateLogic(t){if(!t)return p.error("logic() only works on an element that has sf-logic attributes."),null;const e=this._scope(this._payload());for(let i=0;i0&&await gt(s),this.navigationStack.push(t),await this._transition(r,t,!1,e.instant),!0}async _moveBack(t,e){const r=this.getCurrentStep(),i=this.navigationStack[t];return this._events.emit(v.BEFORE_STEP_CHANGE,Object.assign(this._payload(r),{to:i.name})).includes(!1)?!1:(this.navigationStack=this.navigationStack.slice(0,t+1),await this._transition(r,i,!0,e.instant),!0)}async _transition(t,e,r,i){if(this._afterStepChange(),this.debugModeSteps){e.el.scrollIntoView({block:"start",behavior:"smooth"});return}const s=r?Ot[this.animation.type]:this.animation.type,n=i||Y()?0:this.animation.duration,l=this.animation.ease,u=!!t&&t.el.contains(document.activeElement);if(t&&t!==e){const f=await Et(t.el,s,"out",n,l);t.el.style.display="none",f&&f.cancel()}if(e.el.style.display=e.defaultDisplay,this._scrollToTop(),u){e.el.hasAttribute("tabindex")||e.el.setAttribute("tabindex","-1");try{e.el.focus({preventScroll:!0})}catch{}}Et(e.el,s,"in",n,l)}_scrollToTop(){if(!this.formContainer.hasAttribute(a.scrollTop))return;const t=parseFloat(this.formContainer.getAttribute(a.scrollTop))||0,e=this.formContainer.getBoundingClientRect().top-t;e<0&&window.scrollBy({top:e,behavior:Y()?"auto":"smooth"})}_afterStepChange(){const t=this._payload();this._updateProgress(t.progress),this._runReactions(t),this._events.emit(v.ON_STEP_CHANGE,t)}_payload(t){const e=t===void 0?this.getCurrentStep():t;return{data:this.getFormData(),stepCount:e?e.index:0,progress:e?e.stepProgressValue:0,scores:this.getScores(),step:e?e.name:null,stepNumber:e?e.stepCountValue:0,formName:this.formName,form:this}}_scope(t){return{$f:t.data,$s:t.stepCount,$p:t.progress,$v:t.scores}}_updateProgress(t){const e=Math.max(0,Math.min(100,Math.round(t)));this.formContainer.querySelectorAll(`[${a.el}="progress-bar"]`).forEach(r=>{r.style.width=`${e}%`}),this.formContainer.querySelectorAll(`[${a.el}="progress-text"]`).forEach(r=>{r.textContent=`${e}%`})}async _submit(t){if(this.isSubmitting||this.isSubmitted)return!1;const e=this.getCurrentStep();if(e&&!await this.validateStep(e))return!1;this._runReactions();const r=this._payload();return this._events.emit(v.BEFORE_FORM_SUBMIT,r).includes(!1)?!1:(this.isSubmitting=!0,this._events.emit(v.ON_FORM_SUBMIT,r),this.preventWebflowFormSubmit?(this.isSubmitting=!1,this.isSubmitted=!0,this._clearSaved(),!0):(this._sendToWebflow(t),!0))}_sendToWebflow(t){const e=this._prepareSubmission(),r=this._failEl();r&&(r.style.display="none");const i=this._watchResult();this._handledExternally=null,this._submitIntent=!0;try{const s=Q(t)&&t.form===this.form?t:null;if(typeof this.form.requestSubmit=="function")s?this.form.requestSubmit(s):this.form.requestSubmit();else{const n=new Event("submit",{bubbles:!0,cancelable:!0});this.form.dispatchEvent(n)&&(this._handledExternally=!1,HTMLFormElement.prototype.submit.call(this.form))}}catch(s){p.error("Submitting the form failed:",s),i.cancel(),e(),this.isSubmitting=!1,this._events.emit(v.ON_SUBMIT_ERROR,this._payload());return}finally{this._submitIntent=!1}setTimeout(e,0),(this._handledExternally===!1||i.blind)&&(i.cancel(),this._finishSubmit(!0))}_prepareSubmission(){const t=new Set(this.navigationStack),e=[],r=[];Array.from(this.form.elements).forEach(s=>{if(!s.required)return;const n=this._stepOf(s);n&&(!t.has(n)||!this._activeControls.has(s))&&(s.required=!1,e.push(s))}),this.excludeSkipped&&(this.steps.forEach(s=>{if(t.has(s))return;const n=document.createComment("sf-step");s.el.replaceWith(n),r.push([n,s.el])}),this.fields.forEach(s=>{t.has(s.step)&&s.controls.forEach(n=>{if(this._activeControls.has(n)||!n.isConnected)return;const l=document.createComment("sf-field");n.replaceWith(l),r.push([l,n])})}));let i=!1;return()=>{i||(i=!0,r.reverse().forEach(([s,n])=>s.replaceWith(n)),e.forEach(s=>{s.required=!0}))}}_doneEl(){return this.formBlock.querySelector(":scope > .w-form-done")||this.formContainer.querySelector(".w-form-done")}_failEl(){return this.formBlock.querySelector(":scope > .w-form-fail")||this.formContainer.querySelector(".w-form-fail")}_watchResult(){const t=this._doneEl(),e=this._failEl();if(!t&&!e)return{blind:!0,cancel(){}};let r=!1,i=0;const s=new MutationObserver(()=>{t&&_t(t)?n(!0):e&&_t(e)&&n(!1)}),n=l=>{if(!r){if(r=!0,s.disconnect(),clearTimeout(i),l===null){this.isSubmitting=!1,p.warn("No answer from the Webflow form handler after 30 seconds.");return}this._finishSubmit(l)}};return[t,e].filter(Boolean).forEach(l=>s.observe(l,{attributes:!0,attributeFilter:["style","class"]})),i=setTimeout(()=>n(null),3e4),{blind:!1,cancel(){r=!0,s.disconnect(),clearTimeout(i)}}}_finishSubmit(t){this.isSubmitting=!1,t?(this.isSubmitted=!0,this._clearSaved(),this._events.emit(v.ON_SUBMIT_SUCCESS,this._payload())):this._events.emit(v.ON_SUBMIT_ERROR,this._payload())}_collectScores(){this.scoreVars={};const t=this.formContainer.getAttribute(a.score);t&&t.split(",").map(e=>e.trim()).filter(Boolean).forEach(e=>{/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)?this.scoreVars[e]=0:p.error(`Invalid score variable "${e}" in ${a.score}.`)}),this.scoreItems=[],this.form.querySelectorAll(pt(a.scoreCalc)).forEach(e=>{const r=this._stepOf(e);if(!r)return;const i=[];for(let s=0;s{for(let r=0;r{if(!l)return r;if(!i.has(l)){const u=this.repeats.find(f=>f.items.includes(l));i.set(l,Object.assign({},r,{$r:ut(l),$i:u?u.items.indexOf(l)+1:0}))}return i.get(l)};let n=!1;if(this._reactions.forEach(l=>{let u;try{u=l.expr(s(l.item)),l.failed=!1}catch(_){l.failed||p.error(`${a.react} "${l.raw}" failed: ${_.message}`,l.el),l.failed=!0;return}const f=l.el;switch(l.kind){case"text":{const _=u==null?"":String(u);f.textContent!==_&&(f.textContent=_);break}case"value":{const _=u==null?"":String(u);"value"in f&&f.value!==_&&document.activeElement!==f&&(f.value=_,n=!0),f.setAttribute("value",_);break}case"disable":f.toggleAttribute("disabled",!!u);break;case"visibility":f.classList.toggle(ot,!u);break;case"class":l.name.split(/\s+/).filter(Boolean).forEach(_=>f.classList.toggle(_,!!u));break;case"attr":u==null||u===!1?f.removeAttribute(l.name):f.setAttribute(l.name,Dt(l.name,String(u)));break;default:}}),!n)break}}_restoreData(){const t=this.formContainer;if(this._saveProgress=t.hasAttribute(a.saveProgress),this._prefillUrl=t.hasAttribute(a.prefillUrl),this._saveProgress){const r=G.read()[this.formName];r&&typeof r=="object"&&(this._prepareRepeats(r),this._applyData(r))}const e=new URLSearchParams(window.location.search);if(this._prefillUrl||e.has(Z)){const r=e.get(K);if(r!==null&&(r===this.formName||ct(r)===this.formName)){const i={};e.forEach((s,n)=>{if(n===K||n===Z||n in i)return;const l=e.getAll(n).map(ct);i[ct(n)]=l.length>1?l:l[0]}),this._prepareRepeats(i),this._applyData(i)}}if(this._saveProgress||this._prefillUrl){let r=0;const i=()=>{clearTimeout(r),r=setTimeout(()=>this._persist(),250)};this._events.on(v.ON_INPUT_CHANGE,i),this._events.on(v.ON_STEP_CHANGE,i),this._cleanups.push(()=>clearTimeout(r))}}_persistableData(){const t=this.getFormData();return Array.from(this.form.elements).forEach(e=>{e.name&&(e.type==="password"||e.type==="file"||e.closest(`[${a.noSave}]`))&&delete t[e.name]}),t}_persist(){if(this.isSubmitted||this.isSubmitting)return;const t=this._persistableData();if(this._saveProgress&&G.write(this.formName,t),this._prefillUrl)try{const e=new URL(window.location.href);this._managedKeys().forEach(r=>e.searchParams.delete(r)),e.searchParams.set(K,this.formName),e.searchParams.set(Z,"true"),Object.keys(t).forEach(r=>{this._repeat(r)||[].concat(t[r]).forEach(i=>{i!==""&&i!=null&&e.searchParams.append(r,String(i))})}),window.history.replaceState(window.history.state,"",e.toString())}catch{}}_managedKeys(){const t=new Set([K,Z]);return Array.from(this.form.elements).forEach(e=>{e.name&&t.add(e.name)}),t}_clearSaved(){this._saveProgress&&G.write(this.formName,void 0);try{const t=new URL(window.location.href);if(!this._prefillUrl&&t.searchParams.get(K)!==this.formName)return;this._managedKeys().forEach(e=>t.searchParams.delete(e)),window.history.replaceState(window.history.state,"",t.toString())}catch{}}_applyData(t){this._restoring=!0;try{Object.keys(t).forEach(e=>{if(this._repeat(e))return;const r=[].concat(t[e]).map(s=>s==null?"":String(s)),i=Array.from(this.form.querySelectorAll(`[name="${V(e)}"]`)).filter(s=>/^(INPUT|SELECT|TEXTAREA)$/.test(s.nodeName));i.forEach(s=>{const n=s.type;if(!["password","file","hidden","submit","button","reset","image"].includes(n)&&!s.closest(`[${a.noSave}]`))if(n==="checkbox"){const l=i.length>1?r.includes(s.value):[s.value,"on","true","1","checked"].includes(r[0]);s.checked!==l&&s.click(),tt(s)}else n==="radio"?(r.includes(s.value)&&!s.checked&&s.click(),tt(s)):s.nodeName==="SELECT"&&s.multiple?Array.from(s.options).forEach(l=>{l.selected=r.includes(l.value)}):s.value=r[0]})})}finally{this._restoring=!1}}_setupRepeats(){this.repeats=[],this._repeatOutputs=new Set,this.formContainer.querySelectorAll(`[${a.repeat}]`).forEach(t=>{const e=(t.getAttribute(a.repeat)||"").trim(),r=Array.from(t.querySelectorAll(`[${a.repeatItem}]`)).filter(I=>I.parentElement.closest(`[${a.repeat}]`)===t);if(!e||!r.length){p.warn(`${a.repeat} needs a name and one child element with ${a.repeatItem}.`,t);return}if(this.repeats.some(I=>I.name===e)){p.warn(`Two repeat groups are named "${e}". Names must be unique.`,t);return}r.length>1&&(p.warn(`Repeat group "${e}" has ${r.length} items in the page. Only the first one is used as the template; use ${a.repeatMin} to show more.`,t),r.slice(1).forEach(I=>I.remove()));const i=r[0];Ut(i);const s=i.cloneNode(!0);St(i,s);const n=document.createComment(`sf-repeat ${e}`);i.after(n);const l=(I,z)=>{const c=parseInt(t.getAttribute(I),10);return isFinite(c)&&c>=0?c:z},u=l(a.repeatMin,1),f=Math.max(u,l(a.repeatMax,1/0),1),_=`[${a.repeatOutput}="${V(e)}"], input[type="hidden"][name="${V(e)}"]`,$=this.form.querySelector(_);$?this._repeatOutputs.add($):this.debugMode&&p.warn(`Repeat group "${e}" has no summary field. Add to send all items as one JSON field.`,t),this._stepOf(t)||p.warn(`Repeat group "${e}" is not inside a step, so its fields are not validated.`,t);const C={name:e,el:t,template:s,anchor:n,min:u,max:f,output:$,items:[i]};for(this.repeats.push(C),u===0&&(i.remove(),C.items=[]);C.items.length{this._repeatFor(t)||p.warn(`${a.repeatAdd}="${t.getAttribute(a.repeatAdd)}" does not match any ${a.repeat} group.`,t)})}_repeat(t){return(this.repeats||[]).find(e=>e.name===t)||null}_repeatFor(t){const e=(t.getAttribute(a.repeatAdd)||"").trim();if(e)return this._repeat(e);const r=t.closest(`[${a.repeat}]`);return(this.repeats||[]).find(i=>i.el===r)||null}_repeatAdd(t){if(t.items.length>=t.max)return null;const e=t.template.cloneNode(!0);return St(t.template,e),vt(e,t.items.length+1),t.anchor.parentNode.insertBefore(e,t.anchor),t.items.push(e),e.querySelectorAll('input[type="checkbox"], input[type="radio"]').forEach(tt),e}_renumberRepeat(t){t.items.forEach((r,i)=>vt(r,i+1));const e=t.items.length;this.formContainer.querySelectorAll(`[${a.repeatAdd}]`).forEach(r=>{this._repeatFor(r)===t&&r.classList.toggle(at,e>=t.max)}),t.el.querySelectorAll(`[${a.repeatRemove}]`).forEach(r=>r.classList.toggle(at,e<=t.min))}_afterRepeatChange(t){this._renumberRepeat(t),this._rebuildFields();const e=this._payload();this._runReactions(e),this._events.emit(v.ON_INPUT_CHANGE,e)}_rebuildFields(){const t=new Map;(this.fields||[]).forEach(e=>{t.set(e.controls[0],{dirty:e.dirty,showing:e.showing}),e.showing&&this._setFieldError(e,!1)}),this._fieldByControl.clear(),this._collectFields(),this.fields.forEach(e=>{const r=t.get(e.controls[0]);r&&(e.dirty=r.dirty,r.showing&&this._setFieldError(e,!0))}),Array.from(this._activeControls).forEach(e=>{e.isConnected||this._activeControls.delete(e)}),this._collectScores(),this._reactions=[],this._collectReactions()}_prepareRepeats(t){let e=!1;(this.repeats||[]).forEach(r=>{let i=Array.isArray(t[r.name])?t[r.name].length:0;const s=new Set;for(W(r.template).forEach(n=>{const l=q.get(n);l&&l.name&&s.add(l.name)}),Object.keys(t).forEach(n=>{s.forEach(l=>{if(n===l)i=Math.max(i,1);else if(n.startsWith(l+" ")){const u=Number(n.slice(l.length+1));Number.isInteger(u)&&u>i&&(i=u)}})}),i=Math.min(r.max,i);r.items.length{if(!t.output)return;const e=JSON.stringify(t.items.map(ut));t.output.value!==e&&(t.output.value=e)})}_focusIn(t){const e=Array.from(t.querySelectorAll("input, select, textarea, button, a[href]")).find(r=>r.type!=="hidden"&&U(r));if(e)try{e.focus()}catch{}}_lint(){const t=this.steps.map(r=>r.name);t.forEach((r,i)=>{t.indexOf(r)!==i&&p.warn(`Two steps are named "${r}" in "${this.formName}". Step names must be unique.`)});const e=r=>/^\d+$/.test(r)&&+r{const i=r.getAttribute(a.goto).trim();if(e(i)||p.warn(`sf-goto="${i}" does not match any step name or keyword.`,r),i==="logic()"){for(let n=0;n{this._errorStates.has(r)||p.warn(`sf-error="${r.getAttribute(a.error)}" has no matching field.`,r)})}_debugLog(t){const e=`${this.formName} \u2192 step "${t.step}" (${t.stepCount+1}/${this.steps.length})`;console.groupCollapsed(`%c${e}`,"background:#15181E;color:#fff;padding:3px 8px;border-radius:4px"),console.log("Data",t.data),console.log("Progress",`${t.progress}%`),console.log("Scores",t.scores),console.log("Path",this.navigationStack.map(r=>r.name).join(" \u2192 ")),console.groupEnd()}}function jt(o){const t=o.validity;if(t&&!t.valid&&!t.valueMissing)return!1;const e=o.value.length,r=o.getAttribute("minlength"),i=o.getAttribute("maxlength");return!(r!==null&&e<+r||i!==null&&+i>=0&&e>+i)}function Kt(o,t){const e=o.type;if(e==="checkbox"||e==="radio")return t==="checked"?o.checked:t==="unchecked"||t==="!checked"?!o.checked:o.checked&&o.value===t;if(e==="number"||e==="range")return o.value!==""&&parseFloat(o.value)===parseFloat(t);const r=o.value;return t.startsWith("!")?r!==""&&r!==t.slice(1):r===t}async function Et(o,t,e,r,i){if(!r||t==="none"||typeof o.animate!="function")return null;const s=Ft[t],n={opacity:0},l={opacity:1};s&&(n.transform=e==="in"?s[0]:s[1],l.transform="none");const u=e==="in"?[n,l]:[l,n],f=e==="out"?"forwards":"none";let _;try{_=o.animate(u,{duration:r,easing:i,fill:f})}catch{try{_=o.animate(u,{duration:r,easing:"ease",fill:f})}catch{return null}}return await Promise.race([_.finished.catch(()=>{}),gt(r+200)]),_}let ft=!1,it={debugMode:!1,debugModeSteps:!1};const ht=[],At=o=>{try{o({allForms:R,getForm:wt})}catch(t){p.error("A StepformAPI callback threw an error:",t)}};[window.StepformAPI,window.SuperformAPI].forEach(o=>{Array.isArray(o)&&o.forEach(t=>typeof t=="function"&&ht.push(t))});const kt=Object.freeze({version:X,allForms:R,getForm:wt,get debugConfig(){return it},push(o){typeof o=="function"&&(ft?At(o):ht.push(o))}});D.__stepform=!0,D.version=X,D.events=v,D.expression=et,window.Stepform=D,window.StepformAPI=kt,window.Superform||(window.Superform=D),(!window.SuperformAPI||Array.isArray(window.SuperformAPI))&&(window.SuperformAPI=kt);function Ct(){if(ft)return;const o=nt&&nt.hasAttribute(a.debug)?nt:document.querySelector(`script[${a.debug}]`);it={debugMode:!!o,debugModeSteps:!!o&&(o.getAttribute(a.debug)||"").includes("steps")},document.querySelectorAll(`[${a.form}]`).forEach(t=>{try{new D(t,it)}catch(e){console.error(e&&e.message?e.message:e,t)}}),document.querySelectorAll(`[${a.noflash}]`).forEach(t=>t.removeAttribute(a.noflash)),ft=!0,ht.splice(0).forEach(At),it.debugMode&&console.log(`[Stepform] ${X}: ${R.length} form(s) ready`)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ct,{once:!0}):Ct()})();