@dmitryvim/form-builder 0.2.16 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.locale||"en",a=t.config.translations[o],l=t.config.translations.en;let r=(a==null?void 0:a[e])||(l==null?void 0:l[e])||e;if(n)for(const[i,s]of Object.entries(n))r=r.replace(new RegExp(`\\{${i}\\}`,"g"),String(s));return r}function Te(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push($("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push($("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push($("hintMinLength",n,{min:e.minLength})))}function qe(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push($("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push($("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push($("hintMinValue",n,{min:e.min})))}function Me(e,t,n){e.maxSizeMB&&t.push($("hintMaxSize",n,{size:e.maxSizeMB}))}function He(e,t,n){var o;(o=e.accept)!=null&&o.extensions&&t.push($("hintFormats",n,{formats:e.accept.extensions.map(a=>a.toUpperCase()).join(",")}))}function Be(e,t,n){e.pattern&&t.push($("hintPattern",n,{pattern:e.pattern}))}function A(e,t){const n=[];return Te(e,n,t),e.type!=="slider"&&qe(e,n,t),Me(e,n,t),He(e,n,t),Be(e,n,t),n.join(" \u2022 ")}function U(e){const t=[];if(!e||typeof e!="object")return t.push("Schema must be an object"),t;if(!Array.isArray(e.elements))return t.push("Schema missing elements array"),t;if("columns"in e&&e.columns!==void 0){const o=e.columns,a=[1,2,3,4];(!Number.isInteger(o)||!a.includes(o))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${o})`)}if("prefillHints"in e&&e.prefillHints){const o=e.prefillHints;Array.isArray(o)&&o.forEach((a,l)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${l}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${l}] must have a 'values' property of type object`);else for(const r in a.values)e.elements.some(i=>i.key===r)||t.push(`schema.prefillHints[${l}] references non-existent field "${r}"`)})}function n(o,a){o.forEach((l,r)=>{const i=`${a}[${r}]`;if(l.type||t.push(`${i}: missing type`),l.key||t.push(`${i}: missing key`),l.enableIf){const s=l.enableIf;(!s.key||typeof s.key!="string")&&t.push(`${i}: enableIf must have a 'key' property of type string`),"equals"in s||t.push(`${i}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${i}.elements`),l.type==="container"&&l.elements){if("columns"in l&&l.columns!==void 0){const s=l.columns,u=[1,2,3,4];(!Number.isInteger(s)||!u.includes(s))&&t.push(`${i}: columns must be 1, 2, 3, or 4 (got ${s})`)}if("prefillHints"in l&&l.prefillHints){const s=l.prefillHints;Array.isArray(s)&&s.forEach((u,d)=>{if((!u.label||typeof u.label!="string")&&t.push(`${i}: prefillHints[${d}] must have a 'label' property of type string`),!u.values||typeof u.values!="object")t.push(`${i}: prefillHints[${d}] must have a 'values' property of type object`);else for(const c in u.values)l.elements.some(v=>v.key===c)||t.push(`container "${l.key}": prefillHints[${d}] references non-existent field "${c}"`)})}n(l.elements,`${i}.elements`)}if(l.type==="select"&&l.options){const s=l.default;s!=null&&s!==""&&(l.options.some(u=>u.value===s)||t.push(`${i}: default "${s}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function z(e){return e&&typeof e=="object"&&e.constructor===Object}function L(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function q(e,t){return e?`${e}.${t}`:t}function B(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function V(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const l=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(l))return;o=o[l]}else o=o[a]}return o}function M(e,t,n){var o;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const a=(o=e.scope)!=null?o:"relative";let l;if(a==="relative")l=n!=null?n:t;else if(a==="absolute")l=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${a}")`);const r=V(l,e.key);if("equals"in e)return Ie(r,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function Ie(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e=="object"&&typeof t=="object")try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){if(n instanceof TypeError&&(n.message.includes("circular")||n.message.includes("cyclic")))return console.warn("deepEqual: Circular reference detected in enableIf comparison, using reference equality"),e===t;throw n}return e===t}function R(e,t,n=!1){const o=document.createElement("span");o.className="char-counter",o.style.cssText=`
1
+ var FormBuilder=(function(q){"use strict";function $(e,t,n){const o=t.config.locale||"en",a=t.config.translations[o],l=t.config.translations.en;let r=(a==null?void 0:a[e])||(l==null?void 0:l[e])||e;if(n)for(const[i,c]of Object.entries(n))r=r.replace(new RegExp(`\\{${i}\\}`,"g"),String(c));return r}function ze(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push($("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push($("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push($("hintMinLength",n,{min:e.minLength})))}function Ie(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push($("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push($("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push($("hintMinValue",n,{min:e.min})))}function Re(e,t,n){e.maxSizeMB&&t.push($("hintMaxSize",n,{size:e.maxSizeMB}))}function De(e,t,n){var o;(o=e.accept)!=null&&o.extensions&&t.push($("hintFormats",n,{formats:e.accept.extensions.map(a=>a.toUpperCase()).join(",")}))}function je(e,t,n){e.pattern&&t.push($("hintPattern",n,{pattern:e.pattern}))}function T(e,t){const n=[];return ze(e,n,t),e.type!=="slider"&&Ie(e,n,t),Re(e,n,t),De(e,n,t),je(e,n,t),n.join(" \u2022 ")}function _(e){const t=[];if(!e||typeof e!="object")return t.push("Schema must be an object"),t;if(!Array.isArray(e.elements))return t.push("Schema missing elements array"),t;if("columns"in e&&e.columns!==void 0){const o=e.columns,a=[1,2,3,4];(!Number.isInteger(o)||!a.includes(o))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${o})`)}if("prefillHints"in e&&e.prefillHints){const o=e.prefillHints;Array.isArray(o)&&o.forEach((a,l)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${l}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${l}] must have a 'values' property of type object`);else for(const r in a.values)e.elements.some(i=>i.key===r)||t.push(`schema.prefillHints[${l}] references non-existent field "${r}"`)})}function n(o,a){o.forEach((l,r)=>{const i=`${a}[${r}]`;if(l.type||t.push(`${i}: missing type`),l.key||t.push(`${i}: missing key`),l.enableIf){const c=l.enableIf;(!c.key||typeof c.key!="string")&&t.push(`${i}: enableIf must have a 'key' property of type string`),"equals"in c||t.push(`${i}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${i}.elements`),l.type==="container"&&l.elements){if("columns"in l&&l.columns!==void 0){const c=l.columns,u=[1,2,3,4];(!Number.isInteger(c)||!u.includes(c))&&t.push(`${i}: columns must be 1, 2, 3, or 4 (got ${c})`)}if("prefillHints"in l&&l.prefillHints){const c=l.prefillHints;Array.isArray(c)&&c.forEach((u,d)=>{if((!u.label||typeof u.label!="string")&&t.push(`${i}: prefillHints[${d}] must have a 'label' property of type string`),!u.values||typeof u.values!="object")t.push(`${i}: prefillHints[${d}] must have a 'values' property of type object`);else for(const s in u.values)l.elements.some(p=>p.key===s)||t.push(`container "${l.key}": prefillHints[${d}] references non-existent field "${s}"`)})}n(l.elements,`${i}.elements`)}if(l.type==="select"&&l.options){const c=l.default;c!=null&&c!==""&&(l.options.some(u=>u.value===c)||t.push(`${i}: default "${c}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function R(e){return e&&typeof e=="object"&&e.constructor===Object}function L(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function M(e,t){return e?`${e}.${t}`:t}function z(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function J(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const l=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(l))return;o=o[l]}else o=o[a]}return o}function H(e,t,n){var o;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const a=(o=e.scope)!=null?o:"relative";let l;if(a==="relative")l=n!=null?n:t;else if(a==="absolute")l=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${a}")`);const r=J(l,e.key);if("equals"in e)return Oe(r,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function Oe(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e=="object"&&typeof t=="object")try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){if(n instanceof TypeError&&(n.message.includes("circular")||n.message.includes("cyclic")))return console.warn("deepEqual: Circular reference detected in enableIf comparison, using reference equality"),e===t;throw n}return e===t}function D(e,t,n=!1){const o=document.createElement("span");o.className="char-counter",o.style.cssText=`
2
2
  position: absolute;
3
3
  ${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
4
4
  right: 10px;
@@ -7,7 +7,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
7
7
  pointer-events: none;
8
8
  background: var(--fb-background-color);
9
9
  padding: 0 4px;
10
- `;const a=()=>{const l=t.value.length,r=e.minLength,i=e.maxLength;if(r==null&&i==null){o.textContent="";return}l===0||r!=null&&l<r?(r!=null&&i!=null?o.textContent=`${r}-${i}`:i!=null?o.textContent=`\u2264${i}`:r!=null&&(o.textContent=`\u2265${r}`),o.style.color="var(--fb-text-secondary-color)"):i!=null&&l>i?(o.textContent=`${l}/${i}`,o.style.color="var(--fb-error-color)"):(i!=null?o.textContent=`${l}/${i}`:o.textContent=`${l}`,o.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",a),a(),o}function ze(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
10
+ `;const a=()=>{const l=t.value.length,r=e.minLength,i=e.maxLength;if(r==null&&i==null){o.textContent="";return}l===0||r!=null&&l<r?(r!=null&&i!=null?o.textContent=`${r}-${i}`:i!=null?o.textContent=`\u2264${i}`:r!=null&&(o.textContent=`\u2265${r}`),o.style.color="var(--fb-text-secondary-color)"):i!=null&&l>i?(o.textContent=`${l}/${i}`,o.style.color="var(--fb-error-color)"):(i!=null?o.textContent=`${l}/${i}`:o.textContent=`${l}`,o.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",a),a(),o}function Ue(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
11
11
  padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
12
12
  padding-right: 60px;
13
13
  border: var(--fb-border-width) solid var(--fb-border-color);
@@ -19,7 +19,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
19
19
  transition: all var(--fb-transition-duration) ease-in-out;
20
20
  width: 100%;
21
21
  box-sizing: border-box;
22
- `,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,a.config.readonly||(r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")})),!a.config.readonly&&t.instance){const i=()=>{const s=r.value===""?null:r.value;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=R(e,r,!1);l.appendChild(i)}n.appendChild(l)}function Re(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function v(){c.querySelectorAll(".multiple-text-item").forEach((f,y)=>{const b=f.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function p(f="",y=-1){const b=document.createElement("div");b.className="multiple-text-item flex items-center gap-2";const x=document.createElement("div");x.style.cssText="position: relative; flex: 1;";const C=document.createElement("input");if(C.type="text",C.style.cssText=`
22
+ `,r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,a.config.readonly||(r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")})),!a.config.readonly&&t.instance){const i=()=>{const c=r.value===""?null:r.value;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=D(e,r,!1);l.appendChild(i)}n.appendChild(l)}function Pe(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],c=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function p(){s.querySelectorAll(".multiple-text-item").forEach((v,C)=>{const y=v.querySelector("input");y&&(y.name=`${o}[${C}]`)})}function f(v="",C=-1){const y=document.createElement("div");y.className="multiple-text-item flex items-center gap-2";const b=document.createElement("div");b.style.cssText="position: relative; flex: 1;";const x=document.createElement("input");if(x.type="text",x.style.cssText=`
23
23
  padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
24
24
  padding-right: 60px;
25
25
  border: var(--fb-border-width) solid var(--fb-border-color);
@@ -31,27 +31,27 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
31
31
  transition: all var(--fb-transition-duration) ease-in-out;
32
32
  width: 100%;
33
33
  box-sizing: border-box;
34
- `,C.placeholder=e.placeholder||$("placeholderText",r),C.value=f,C.readOnly=r.config.readonly,r.config.readonly||(C.addEventListener("focus",()=>{C.style.borderColor="var(--fb-border-focus-color)",C.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",C.style.outlineOffset="0"}),C.addEventListener("blur",()=>{C.style.borderColor="var(--fb-border-color)",C.style.outline="none"}),C.addEventListener("mouseenter",()=>{document.activeElement!==C&&(C.style.borderColor="var(--fb-border-hover-color)")}),C.addEventListener("mouseleave",()=>{document.activeElement!==C&&(C.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const w=()=>{const k=C.value===""?null:C.value;t.instance.triggerOnChange(C.name,k)};C.addEventListener("blur",w),C.addEventListener("input",w)}if(x.appendChild(C),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=R(e,C,!1);x.appendChild(w)}return b.appendChild(x),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),v(),b}function m(){if(r.config.readonly)return;const f=c.querySelectorAll(".multiple-text-item"),y=f.length;f.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 rounded",x.style.cssText=`
34
+ `,x.placeholder=e.placeholder||$("placeholderText",r),x.value=v,x.readOnly=r.config.readonly,r.config.readonly||(x.addEventListener("focus",()=>{x.style.borderColor="var(--fb-border-focus-color)",x.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",x.style.outlineOffset="0"}),x.addEventListener("blur",()=>{x.style.borderColor="var(--fb-border-color)",x.style.outline="none"}),x.addEventListener("mouseenter",()=>{document.activeElement!==x&&(x.style.borderColor="var(--fb-border-hover-color)")}),x.addEventListener("mouseleave",()=>{document.activeElement!==x&&(x.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const w=()=>{const k=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,k)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(b.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=D(e,x,!1);b.appendChild(w)}return y.appendChild(b),C===-1?s.appendChild(y):s.insertBefore(y,s.children[C]),p(),y}function m(){if(r.config.readonly)return;const v=s.querySelectorAll(".multiple-text-item"),C=v.length;v.forEach(y=>{let b=y.querySelector(".remove-item-btn");b||(b=document.createElement("button"),b.type="button",b.className="remove-item-btn px-2 py-1 rounded",b.style.cssText=`
35
35
  color: var(--fb-error-color);
36
36
  background-color: transparent;
37
37
  transition: background-color var(--fb-transition-duration);
38
- `,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),v(),E(),m())},b.appendChild(x));const C=y<=u;x.disabled=C,x.style.opacity=C?"0.5":"1",x.style.pointerEvents=C?"none":"auto"})}let g=null,h=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const f=document.createElement("button");f.type="button",f.className="add-text-btn px-3 py-1 rounded",f.style.cssText=`
38
+ `,b.innerHTML="\u2715",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{const w=Array.from(s.children).indexOf(y);s.children.length>u&&(c.splice(w,1),y.remove(),p(),E(),m())},y.appendChild(b));const x=C<=u;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-text-btn px-3 py-1 rounded",v.style.cssText=`
39
39
  color: var(--fb-primary-color);
40
40
  border: var(--fb-border-width) solid var(--fb-primary-color);
41
41
  background-color: transparent;
42
42
  font-size: var(--fb-font-size);
43
43
  transition: all var(--fb-transition-duration);
44
- `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{s.push(e.default||""),p(e.default||""),E(),m()},h=document.createElement("span"),h.className="text-sm text-gray-500",g.appendChild(f),g.appendChild(h),n.appendChild(g)}function E(){if(!g||!h)return;const f=g.querySelector(".add-text-btn");if(f){const y=s.length>=d;f.disabled=y,f.style.opacity=y?"0.5":"1",f.style.pointerEvents=y?"none":"auto"}h.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(f=>p(f)),E(),m()}function te(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,v)=>{var p,m;if(!c)return;const g=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(g);v?(c.classList.add("invalid"),c.title=v,h||(h=document.createElement("div"),h.id=g,h.className="error-message",h.style.cssText=`
44
+ `,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{c.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-text-btn");if(v){const C=c.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(v=>f(v)),E(),m()}function oe(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:c}=n,u=(s,p)=>{var f,m;if(!s)return;const h=`error-${s.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(h);p?(s.classList.add("invalid"),s.title=p,g||(g=document.createElement("div"),g.id=h,g.className="error-message",g.style.cssText=`
45
45
  color: var(--fb-error-color);
46
46
  font-size: var(--fb-font-size-small);
47
47
  margin-top: 0.25rem;
48
- `,c.nextSibling?(p=c.parentNode)==null||p.insertBefore(h,c.nextSibling):(m=c.parentNode)==null||m.appendChild(h)),h.textContent=v,h.style.display="block"):(c.classList.remove("invalid"),c.title="",h&&h.remove())},d=(c,v,p)=>{let m=!1;const{state:g}=n;if(!s&&v){if(e.minLength!==void 0&&e.minLength!==null&&v.length<e.minLength){const h=$("minLength",g,{min:e.minLength});r.push(`${p}: ${h}`),u(c,h),m=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&v.length>e.maxLength){const h=$("maxLength",g,{max:e.maxLength});r.push(`${p}: ${h}`),u(c,h),m=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(v)){const h=$("patternMismatch",g);r.push(`${p}: ${h}`),u(c,h),m=!0}}catch(h){const E=$("invalidPattern",g);r.push(`${p}: ${E}`),u(c,E),m=!0}}m||u(c,null)};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["]`),v=[],p=[];if(c.forEach((m,g)=>{var h;const E=(h=m==null?void 0:m.value)!=null?h:"";p.push(E),v.push(E===""?null:E),d(m,E,`${t}[${g}]`)}),!s){const{state:m}=n,g=(o=e.minCount)!=null?o:1,h=(a=e.maxCount)!=null?a:1/0,E=p.filter(f=>f.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${$("required",m)}`),E.length<g&&r.push(`${t}: ${$("minItems",m,{min:g})}`),E.length>h&&r.push(`${t}: ${$("maxItems",m,{max:h})}`)}return{value:v,errors:r}}else{const c=i.querySelector(`[name$="${t}"]`),v=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&v===""){const p=$("required",n.state);return r.push(`${t}: ${p}`),u(c,p),{value:null,errors:r}}return c&&d(c,v,t),{value:v===""?null:v,errors:r}}}function ne(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateTextField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function De(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("textarea");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",r.style.cssText="padding-bottom: 24px;",r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.rows=e.rows||4,r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{const s=r.value===""?null:r.value;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=R(e,r,!0);l.appendChild(i)}n.appendChild(l)}function je(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function v(){c.querySelectorAll(".multiple-textarea-item").forEach((f,y)=>{const b=f.querySelector("textarea");b&&(b.name=`${o}[${y}]`)})}function p(f="",y=-1){const b=document.createElement("div");b.className="multiple-textarea-item";const x=document.createElement("div");x.style.cssText="position: relative;";const C=document.createElement("textarea");if(C.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",C.style.cssText="padding-bottom: 24px;",C.placeholder=e.placeholder||$("placeholderText",r),C.rows=e.rows||4,C.value=f,C.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const k=C.value===""?null:C.value;t.instance.triggerOnChange(C.name,k)};C.addEventListener("blur",w),C.addEventListener("input",w)}if(x.appendChild(C),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=R(e,C,!0);x.appendChild(w)}return b.appendChild(x),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),v(),b}function m(){if(r.config.readonly)return;const f=c.querySelectorAll(".multiple-textarea-item"),y=f.length;f.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",x.innerHTML="\u2715",x.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),v(),E(),m())},b.appendChild(x));const C=y<=u;x.disabled=C,x.style.opacity=C?"0.5":"1",x.style.pointerEvents=C?"none":"auto"})}let g=null,h=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const f=document.createElement("button");f.type="button",f.className="add-textarea-btn px-3 py-1 rounded",f.style.cssText=`
48
+ `,s.nextSibling?(f=s.parentNode)==null||f.insertBefore(g,s.nextSibling):(m=s.parentNode)==null||m.appendChild(g)),g.textContent=p,g.style.display="block"):(s.classList.remove("invalid"),s.title="",g&&g.remove())},d=(s,p,f)=>{let m=!1;const{state:h}=n;if(!c&&p){if(e.minLength!==void 0&&e.minLength!==null&&p.length<e.minLength){const g=$("minLength",h,{min:e.minLength});r.push(`${f}: ${g}`),u(s,g),m=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&p.length>e.maxLength){const g=$("maxLength",h,{max:e.maxLength});r.push(`${f}: ${g}`),u(s,g),m=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(p)){const g=$("patternMismatch",h);r.push(`${f}: ${g}`),u(s,g),m=!0}}catch(g){const E=$("invalidPattern",h);r.push(`${f}: ${E}`),u(s,E),m=!0}}m||u(s,null)};if(e.multiple){const s=i.querySelectorAll(`[name^="${t}["]`),p=[],f=[];if(s.forEach((m,h)=>{var g;const E=(g=m==null?void 0:m.value)!=null?g:"";f.push(E),p.push(E===""?null:E),d(m,E,`${t}[${h}]`)}),!c){const{state:m}=n,h=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,E=f.filter(v=>v.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${$("required",m)}`),E.length<h&&r.push(`${t}: ${$("minItems",m,{min:h})}`),E.length>g&&r.push(`${t}: ${$("maxItems",m,{max:g})}`)}return{value:p,errors:r}}else{const s=i.querySelector(`[name$="${t}"]`),p=(l=s==null?void 0:s.value)!=null?l:"";if(!c&&e.required&&p===""){const f=$("required",n.state);return r.push(`${t}: ${f}`),u(s,f),{value:null,errors:r}}return s&&d(s,p,t),{value:p===""?null:p,errors:r}}}function le(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateTextField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function ae(e){e.style.overflow="hidden",e.style.resize="none";const t=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(1,t);const n=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`)};e.addEventListener("input",n),setTimeout(()=>{e.isConnected&&n()},0)}function Ve(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("textarea");if(r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",r.style.cssText="padding-bottom: 24px;",r.name=o,r.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",r.rows=e.rows||4,r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{const c=r.value===""?null:r.value;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",i),r.addEventListener("input",i)}if((e.autoExpand||a.config.readonly)&&ae(r),l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const i=D(e,r,!0);l.appendChild(i)}n.appendChild(l)}function We(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],c=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function p(){s.querySelectorAll(".multiple-textarea-item").forEach((v,C)=>{const y=v.querySelector("textarea");y&&(y.name=`${o}[${C}]`)})}function f(v="",C=-1){const y=document.createElement("div");y.className="multiple-textarea-item";const b=document.createElement("div");b.style.cssText="position: relative;";const x=document.createElement("textarea");if(x.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",x.style.cssText="padding-bottom: 24px;",x.placeholder=e.placeholder||$("placeholderText",r),x.rows=e.rows||4,x.value=v,x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const k=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,k)};x.addEventListener("blur",w),x.addEventListener("input",w)}if((e.autoExpand||r.config.readonly)&&ae(x),b.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=D(e,x,!0);b.appendChild(w)}return y.appendChild(b),C===-1?s.appendChild(y):s.insertBefore(y,s.children[C]),p(),y}function m(){if(r.config.readonly)return;const v=s.querySelectorAll(".multiple-textarea-item"),C=v.length;v.forEach(y=>{let b=y.querySelector(".remove-item-btn");b||(b=document.createElement("button"),b.type="button",b.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",b.innerHTML="\u2715",b.onclick=()=>{const w=Array.from(s.children).indexOf(y);s.children.length>u&&(c.splice(w,1),y.remove(),p(),E(),m())},y.appendChild(b));const x=C<=u;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-textarea-btn px-3 py-1 rounded",v.style.cssText=`
49
49
  color: var(--fb-primary-color);
50
50
  border: var(--fb-border-width) solid var(--fb-primary-color);
51
51
  background-color: transparent;
52
52
  font-size: var(--fb-font-size);
53
53
  transition: all var(--fb-transition-duration);
54
- `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{s.push(e.default||""),p(e.default||""),E(),m()},h=document.createElement("span"),h.className="text-sm text-gray-500",g.appendChild(f),g.appendChild(h),n.appendChild(g)}function E(){if(!g||!h)return;const f=g.querySelector(".add-textarea-btn");if(f){const y=s.length>=d;f.disabled=y,f.style.opacity=y?"0.5":"1",f.style.pointerEvents=y?"none":"auto"}h.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(f=>p(f)),E(),m()}function Oe(e,t,n){return te(e,t,n)}function Pe(e,t,n,o){ne(e,t,n,o)}function re(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
54
+ `,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{c.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-textarea-btn");if(v){const C=c.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(v=>f(v)),E(),m()}function _e(e,t,n){return oe(e,t,n)}function Je(e,t,n,o){le(e,t,n,o);const{scopeRoot:a,state:l}=o;if(e.autoExpand||l.config.readonly)if(e.multiple)a.querySelectorAll(`textarea[name^="${t}["]`).forEach(r=>{r.dispatchEvent(new Event("input"))});else{const r=a.querySelector(`textarea[name="${t}"]`);r&&r.dispatchEvent(new Event("input"))}}function ie(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
55
55
  position: absolute;
56
56
  top: 50%;
57
57
  transform: translateY(-50%);
@@ -61,27 +61,55 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
61
61
  pointer-events: none;
62
62
  background: var(--fb-background-color);
63
63
  padding: 0 4px;
64
- `;const o=e.min,a=e.max;let l="";o!=null&&a!=null?l=`${o} \u2013 ${a}`:a!=null?l=`\u2264${a}`:o!=null&&(l=`\u2265${o}`),n.textContent=l;const r=()=>{const i=t.value?parseFloat(t.value):null;if(i!=null){const s=o!=null&&i<o,u=a!=null&&i>a;n.style.color=s||u?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",r),r(),n}function Ue(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="number",r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",r.name=o,r.placeholder=e.placeholder||"0",e.min!==void 0&&(r.min=e.min.toString()),e.max!==void 0&&(r.max=e.max.toString()),e.step!==void 0&&(r.step=e.step.toString()),r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{const s=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,s)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.min!=null||e.max!=null)){const i=re(e,r);l.appendChild(i)}n.appendChild(l)}function Ve(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function v(){c.querySelectorAll(".multiple-number-item").forEach((f,y)=>{const b=f.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function p(f="",y=-1){const b=document.createElement("div");b.className="multiple-number-item flex items-center gap-2";const x=document.createElement("div");x.style.cssText="position: relative; flex: 1;";const C=document.createElement("input");if(C.type="number",C.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",C.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",C.placeholder=e.placeholder||"0",e.min!==void 0&&(C.min=e.min.toString()),e.max!==void 0&&(C.max=e.max.toString()),e.step!==void 0&&(C.step=e.step.toString()),C.value=f.toString(),C.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const k=C.value?parseFloat(C.value):null;t.instance.triggerOnChange(C.name,k)};C.addEventListener("blur",w),C.addEventListener("input",w)}if(x.appendChild(C),!r.config.readonly&&(e.min!=null||e.max!=null)){const w=re(e,C);x.appendChild(w)}return b.appendChild(x),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),v(),b}function m(){if(r.config.readonly)return;const f=c.querySelectorAll(".multiple-number-item"),y=f.length;f.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",x.innerHTML="\u2715",x.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),v(),E(),m())},b.appendChild(x));const C=y<=u;x.disabled=C,x.style.opacity=C?"0.5":"1",x.style.pointerEvents=C?"none":"auto"})}let g=null,h=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const f=document.createElement("button");f.type="button",f.className="add-number-btn px-3 py-1 rounded",f.style.cssText=`
64
+ `;const o=e.min,a=e.max;let l="";o!=null&&a!=null?l=`${o} \u2013 ${a}`:a!=null?l=`\u2264${a}`:o!=null&&(l=`\u2265${o}`),n.textContent=l;const r=()=>{const i=t.value?parseFloat(t.value):null;if(i!=null){const c=o!=null&&i<o,u=a!=null&&i>a;n.style.color=c||u?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",r),r(),n}function Ye(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="number",r.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",r.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",r.name=o,r.placeholder=e.placeholder||"0",e.min!==void 0&&(r.min=e.min.toString()),e.max!==void 0&&(r.max=e.max.toString()),e.step!==void 0&&(r.step=e.step.toString()),r.value=t.prefill[e.key]||e.default||"",r.readOnly=a.config.readonly,!a.config.readonly&&t.instance){const i=()=>{const c=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",i),r.addEventListener("input",i)}if(l.appendChild(r),!a.config.readonly&&(e.min!=null||e.max!=null)){const i=ie(e,r);l.appendChild(i)}n.appendChild(l)}function Ge(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],c=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function p(){s.querySelectorAll(".multiple-number-item").forEach((v,C)=>{const y=v.querySelector("input");y&&(y.name=`${o}[${C}]`)})}function f(v="",C=-1){const y=document.createElement("div");y.className="multiple-number-item flex items-center gap-2";const b=document.createElement("div");b.style.cssText="position: relative; flex: 1;";const x=document.createElement("input");if(x.type="number",x.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",x.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",x.placeholder=e.placeholder||"0",e.min!==void 0&&(x.min=e.min.toString()),e.max!==void 0&&(x.max=e.max.toString()),e.step!==void 0&&(x.step=e.step.toString()),x.value=v.toString(),x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const k=x.value?parseFloat(x.value):null;t.instance.triggerOnChange(x.name,k)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(b.appendChild(x),!r.config.readonly&&(e.min!=null||e.max!=null)){const w=ie(e,x);b.appendChild(w)}return y.appendChild(b),C===-1?s.appendChild(y):s.insertBefore(y,s.children[C]),p(),y}function m(){if(r.config.readonly)return;const v=s.querySelectorAll(".multiple-number-item"),C=v.length;v.forEach(y=>{let b=y.querySelector(".remove-item-btn");b||(b=document.createElement("button"),b.type="button",b.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",b.innerHTML="\u2715",b.onclick=()=>{const w=Array.from(s.children).indexOf(y);s.children.length>u&&(c.splice(w,1),y.remove(),p(),E(),m())},y.appendChild(b));const x=C<=u;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-number-btn px-3 py-1 rounded",v.style.cssText=`
65
65
  color: var(--fb-primary-color);
66
66
  border: var(--fb-border-width) solid var(--fb-primary-color);
67
67
  background-color: transparent;
68
68
  font-size: var(--fb-font-size);
69
69
  transition: all var(--fb-transition-duration);
70
- `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{s.push(e.default||""),p(e.default||""),E(),m()},h=document.createElement("span"),h.className="text-sm text-gray-500",g.appendChild(f),g.appendChild(h),n.appendChild(g)}function E(){if(!g||!h)return;const f=g.querySelector(".add-number-btn");if(f){const y=s.length>=d;f.disabled=y,f.style.opacity=y?"0.5":"1",f.style.pointerEvents=y?"none":"auto"}h.textContent=`${s.length}/${d===1/0?"\u221E":d}`}s.forEach(f=>p(f)),E(),m()}function _e(e,t,n){var o,a,l,r,i;const s=[],{scopeRoot:u,skipValidation:d}=n,c=(p,m)=>{var g,h;if(!p)return;const E=`error-${p.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(E);m?(p.classList.add("invalid"),p.title=m,f||(f=document.createElement("div"),f.id=E,f.className="error-message",f.style.cssText=`
70
+ `,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{c.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-number-btn");if(v){const C=c.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(v=>f(v)),E(),m()}function Xe(e,t,n){var o,a,l,r,i;const c=[],{scopeRoot:u,skipValidation:d}=n,s=(f,m)=>{var h,g;if(!f)return;const E=`error-${f.getAttribute("name")||Math.random().toString(36).substring(7)}`;let v=document.getElementById(E);m?(f.classList.add("invalid"),f.title=m,v||(v=document.createElement("div"),v.id=E,v.className="error-message",v.style.cssText=`
71
71
  color: var(--fb-error-color);
72
72
  font-size: var(--fb-font-size-small);
73
73
  margin-top: 0.25rem;
74
- `,p.nextSibling?(g=p.parentNode)==null||g.insertBefore(f,p.nextSibling):(h=p.parentNode)==null||h.appendChild(f)),f.textContent=m,f.style.display="block"):(p.classList.remove("invalid"),p.title="",f&&f.remove())},v=(p,m,g)=>{let h=!1;const{state:E}=n;if(!d&&e.min!==void 0&&e.min!==null&&m<e.min){const f=$("minValue",E,{min:e.min});s.push(`${g}: ${f}`),c(p,f),h=!0}else if(!d&&e.max!==void 0&&e.max!==null&&m>e.max){const f=$("maxValue",E,{max:e.max});s.push(`${g}: ${f}`),c(p,f),h=!0}h||c(p,null)};if(e.multiple){const p=u.querySelectorAll(`[name^="${t}["]`),m=[];if(p.forEach((g,h)=>{var E,f,y;const b=(E=g==null?void 0:g.value)!=null?E:"";if(b===""){m.push(null),c(g,null);return}const x=parseFloat(b);if(!d&&!Number.isFinite(x)){const w=$("notANumber",n.state);s.push(`${t}[${h}]: ${w}`),c(g,w),m.push(null);return}v(g,x,`${t}[${h}]`);const C=Number.isInteger((f=e.decimals)!=null?f:0)&&(y=e.decimals)!=null?y:0;m.push(Number(x.toFixed(C)))}),!d){const{state:g}=n,h=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,f=m.filter(y=>y!==null);e.required&&f.length===0&&s.push(`${t}: ${$("required",g)}`),f.length<h&&s.push(`${t}: ${$("minItems",g,{min:h})}`),f.length>E&&s.push(`${t}: ${$("maxItems",g,{max:E})}`)}return{value:m,errors:s}}else{const p=u.querySelector(`[name$="${t}"]`),m=(l=p==null?void 0:p.value)!=null?l:"",{state:g}=n;if(!d&&e.required&&m===""){const f=$("required",g);return s.push(`${t}: ${f}`),c(p,f),{value:null,errors:s}}if(m==="")return c(p,null),{value:null,errors:s};const h=parseFloat(m);if(!d&&!Number.isFinite(h)){const f=$("notANumber",g);return s.push(`${t}: ${f}`),c(p,f),{value:null,errors:s}}v(p,h,t);const E=Number.isInteger((r=e.decimals)!=null?r:0)&&(i=e.decimals)!=null?i:0;return{value:Number(h.toFixed(E)),errors:s}}}function We(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function Je(e,t,n,o){const a=t.state,l=document.createElement("select");if(l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.name=o,l.disabled=a.config.readonly,(e.options||[]).forEach(r=>{const i=document.createElement("option");i.value=r.value,i.textContent=r.label,(t.prefill[e.key]||e.default)===r.value&&(i.selected=!0),l.appendChild(i)}),!a.config.readonly&&t.instance){const r=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("change",r)}if(n.appendChild(l),!a.config.readonly){const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=A(e,a),n.appendChild(r)}}function Ye(e,t,n,o){var a,l,r,i;const s=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],c=(a=e.minCount)!=null?a:1,v=(l=e.maxCount)!=null?l:1/0;for(;d.length<c;)d.push(e.default||((i=(r=e.options)==null?void 0:r[0])==null?void 0:i.value)||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function m(){p.querySelectorAll(".multiple-select-item").forEach((b,x)=>{const C=b.querySelector("select");C&&(C.name=`${o}[${x}]`)})}function g(b="",x=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const w=document.createElement("select");if(w.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",w.disabled=s.config.readonly,(e.options||[]).forEach(k=>{const S=document.createElement("option");S.value=k.value,S.textContent=k.label,b===k.value&&(S.selected=!0),w.appendChild(S)}),!s.config.readonly&&t.instance){const k=()=>{t.instance.triggerOnChange(w.name,w.value)};w.addEventListener("change",k)}return C.appendChild(w),x===-1?p.appendChild(C):p.insertBefore(C,p.children[x]),m(),C}function h(){if(s.config.readonly)return;const b=p.querySelectorAll(".multiple-select-item"),x=b.length;b.forEach(C=>{let w=C.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",w.innerHTML="\u2715",w.onclick=()=>{const S=Array.from(p.children).indexOf(C);p.children.length>c&&(d.splice(S,1),C.remove(),m(),y(),h())},C.appendChild(w));const k=x<=c;w.disabled=k,w.style.opacity=k?"0.5":"1",w.style.pointerEvents=k?"none":"auto"})}let E=null,f=null;if(!s.config.readonly){E=document.createElement("div"),E.className="flex items-center gap-3 mt-2";const b=document.createElement("button");b.type="button",b.className="add-select-btn px-3 py-1 rounded",b.style.cssText=`
74
+ `,f.nextSibling?(h=f.parentNode)==null||h.insertBefore(v,f.nextSibling):(g=f.parentNode)==null||g.appendChild(v)),v.textContent=m,v.style.display="block"):(f.classList.remove("invalid"),f.title="",v&&v.remove())},p=(f,m,h)=>{let g=!1;const{state:E}=n;if(!d&&e.min!==void 0&&e.min!==null&&m<e.min){const v=$("minValue",E,{min:e.min});c.push(`${h}: ${v}`),s(f,v),g=!0}else if(!d&&e.max!==void 0&&e.max!==null&&m>e.max){const v=$("maxValue",E,{max:e.max});c.push(`${h}: ${v}`),s(f,v),g=!0}g||s(f,null)};if(e.multiple){const f=u.querySelectorAll(`[name^="${t}["]`),m=[];if(f.forEach((h,g)=>{var E,v,C;const y=(E=h==null?void 0:h.value)!=null?E:"";if(y===""){m.push(null),s(h,null);return}const b=parseFloat(y);if(!d&&!Number.isFinite(b)){const w=$("notANumber",n.state);c.push(`${t}[${g}]: ${w}`),s(h,w),m.push(null);return}p(h,b,`${t}[${g}]`);const x=Number.isInteger((v=e.decimals)!=null?v:0)&&(C=e.decimals)!=null?C:0;m.push(Number(b.toFixed(x)))}),!d){const{state:h}=n,g=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,v=m.filter(C=>C!==null);e.required&&v.length===0&&c.push(`${t}: ${$("required",h)}`),v.length<g&&c.push(`${t}: ${$("minItems",h,{min:g})}`),v.length>E&&c.push(`${t}: ${$("maxItems",h,{max:E})}`)}return{value:m,errors:c}}else{const f=u.querySelector(`[name$="${t}"]`),m=(l=f==null?void 0:f.value)!=null?l:"",{state:h}=n;if(!d&&e.required&&m===""){const v=$("required",h);return c.push(`${t}: ${v}`),s(f,v),{value:null,errors:c}}if(m==="")return s(f,null),{value:null,errors:c};const g=parseFloat(m);if(!d&&!Number.isFinite(g)){const v=$("notANumber",h);return c.push(`${t}: ${v}`),s(f,v),{value:null,errors:c}}p(f,g,t);const E=Number.isInteger((r=e.decimals)!=null?r:0)&&(i=e.decimals)!=null?i:0;return{value:Number(g.toFixed(E)),errors:c}}}function Ze(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.classList.remove("invalid"),l.title="")}}function Ke(e,t,n,o){const a=t.state,l=document.createElement("select");if(l.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.name=o,l.disabled=a.config.readonly,(e.options||[]).forEach(r=>{const i=document.createElement("option");i.value=r.value,i.textContent=r.label,(t.prefill[e.key]||e.default)===r.value&&(i.selected=!0),l.appendChild(i)}),!a.config.readonly&&t.instance){const r=()=>{t.instance.triggerOnChange(o,l.value)};l.addEventListener("change",r)}if(n.appendChild(l),!a.config.readonly){const r=document.createElement("p");r.className="text-xs text-gray-500 mt-1",r.textContent=T(e,a),n.appendChild(r)}}function Qe(e,t,n,o){var a,l,r,i;const c=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],s=(a=e.minCount)!=null?a:1,p=(l=e.maxCount)!=null?l:1/0;for(;d.length<s;)d.push(e.default||((i=(r=e.options)==null?void 0:r[0])==null?void 0:i.value)||"");const f=document.createElement("div");f.className="space-y-2",n.appendChild(f);function m(){f.querySelectorAll(".multiple-select-item").forEach((y,b)=>{const x=y.querySelector("select");x&&(x.name=`${o}[${b}]`)})}function h(y="",b=-1){const x=document.createElement("div");x.className="multiple-select-item flex items-center gap-2";const w=document.createElement("select");if(w.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",w.disabled=c.config.readonly,(e.options||[]).forEach(k=>{const S=document.createElement("option");S.value=k.value,S.textContent=k.label,y===k.value&&(S.selected=!0),w.appendChild(S)}),!c.config.readonly&&t.instance){const k=()=>{t.instance.triggerOnChange(w.name,w.value)};w.addEventListener("change",k)}return x.appendChild(w),b===-1?f.appendChild(x):f.insertBefore(x,f.children[b]),m(),x}function g(){if(c.config.readonly)return;const y=f.querySelectorAll(".multiple-select-item"),b=y.length;y.forEach(x=>{let w=x.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",w.innerHTML="\u2715",w.onclick=()=>{const S=Array.from(f.children).indexOf(x);f.children.length>s&&(d.splice(S,1),x.remove(),m(),C(),g())},x.appendChild(w));const k=b<=s;w.disabled=k,w.style.opacity=k?"0.5":"1",w.style.pointerEvents=k?"none":"auto"})}let E=null,v=null;if(!c.config.readonly){E=document.createElement("div"),E.className="flex items-center gap-3 mt-2";const y=document.createElement("button");y.type="button",y.className="add-select-btn px-3 py-1 rounded",y.style.cssText=`
75
75
  color: var(--fb-primary-color);
76
76
  border: var(--fb-border-width) solid var(--fb-primary-color);
77
77
  background-color: transparent;
78
78
  font-size: var(--fb-font-size);
79
79
  transition: all var(--fb-transition-duration);
80
- `,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{var x,C;const w=e.default||((C=(x=e.options)==null?void 0:x[0])==null?void 0:C.value)||"";d.push(w),g(w),y(),h()},f=document.createElement("span"),f.className="text-sm text-gray-500",E.appendChild(b),E.appendChild(f),n.appendChild(E)}function y(){if(!E||!f)return;const b=E.querySelector(".add-select-btn");if(b){const x=d.length>=v;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"}f.textContent=`${d.length}/${v===1/0?"\u221E":v}`}if(d.forEach(b=>g(b)),y(),h(),!s.config.readonly){const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=A(e,s),n.appendChild(b)}}function Ge(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(u,d)=>{var c,v;if(!u)return;const p=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(p);d?(u.classList.add("invalid"),u.title=d,m||(m=document.createElement("div"),m.id=p,m.className="error-message",m.style.cssText=`
80
+ `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{var b,x;const w=e.default||((x=(b=e.options)==null?void 0:b[0])==null?void 0:x.value)||"";d.push(w),h(w),C(),g()},v=document.createElement("span"),v.className="text-sm text-gray-500",E.appendChild(y),E.appendChild(v),n.appendChild(E)}function C(){if(!E||!v)return;const y=E.querySelector(".add-select-btn");if(y){const b=d.length>=p;y.disabled=b,y.style.opacity=b?"0.5":"1",y.style.pointerEvents=b?"none":"auto"}v.textContent=`${d.length}/${p===1/0?"\u221E":p}`}if(d.forEach(y=>h(y)),C(),g(),!c.config.readonly){const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=T(e,c),n.appendChild(y)}}function et(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(u,d)=>{var s,p;if(!u)return;const f=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(f);d?(u.classList.add("invalid"),u.title=d,m||(m=document.createElement("div"),m.id=f,m.className="error-message",m.style.cssText=`
81
81
  color: var(--fb-error-color);
82
82
  font-size: var(--fb-font-size-small);
83
83
  margin-top: 0.25rem;
84
- `,u.nextSibling?(c=u.parentNode)==null||c.insertBefore(m,u.nextSibling):(v=u.parentNode)==null||v.appendChild(m)),m.textContent=d,m.style.display="block"):(u.classList.remove("invalid"),u.title="",m&&m.remove())},s=(u,d,c,v)=>{var p,m;if(r)return;const{state:g}=n,h=d.filter(v),E="minCount"in c&&(p=c.minCount)!=null?p:1,f="maxCount"in c&&(m=c.maxCount)!=null?m:1/0;c.required&&h.length===0&&a.push(`${u}: ${$("required",g)}`),h.length<E&&a.push(`${u}: ${$("minItems",g,{min:E})}`),h.length>f&&a.push(`${u}: ${$("maxItems",g,{max:f})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),d=[];return u.forEach(c=>{var v;const p=(v=c==null?void 0:c.value)!=null?v:"";d.push(p),i(c,null)}),s(t,d,e,c=>c!==""),{value:d,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),d=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&d===""){const c=$("required",n.state);return a.push(`${t}: ${c}`),i(u,c),{value:null,errors:a}}else i(u,null);return{value:d===""?null:d,errors:a}}}function Xe(e,t,n,o){const{scopeRoot:a}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.querySelectorAll("option").forEach(s=>{s.selected=s.value===String(n[i])}),r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${l.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.querySelectorAll("option").forEach(r=>{r.selected=r.value===String(n)}),l.classList.remove("invalid"),l.title="")}}function Ze(e,t,n,o){const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=n||$("previewAlt",o);const l=new FileReader;l.onload=r=>{var i;a.src=((i=r.target)==null?void 0:i.result)||""},l.readAsDataURL(t),e.appendChild(a)}function Qe(e,t,n,o,a,l){const r=URL.createObjectURL(t);e.onclick=null;const i=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(i,e),i.innerHTML=`
84
+ `,u.nextSibling?(s=u.parentNode)==null||s.insertBefore(m,u.nextSibling):(p=u.parentNode)==null||p.appendChild(m)),m.textContent=d,m.style.display="block"):(u.classList.remove("invalid"),u.title="",m&&m.remove())},c=(u,d,s,p)=>{var f,m;if(r)return;const{state:h}=n,g=d.filter(p),E="minCount"in s&&(f=s.minCount)!=null?f:1,v="maxCount"in s&&(m=s.maxCount)!=null?m:1/0;s.required&&g.length===0&&a.push(`${u}: ${$("required",h)}`),g.length<E&&a.push(`${u}: ${$("minItems",h,{min:E})}`),g.length>v&&a.push(`${u}: ${$("maxItems",h,{max:v})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),d=[];return u.forEach(s=>{var p;const f=(p=s==null?void 0:s.value)!=null?p:"";d.push(f),i(s,null)}),c(t,d,e,s=>s!==""),{value:d,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),d=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&d===""){const s=$("required",n.state);return a.push(`${t}: ${s}`),i(u,s),{value:null,errors:a}}else i(u,null);return{value:d===""?null:d,errors:a}}}function tt(e,t,n,o){const{scopeRoot:a}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["]`);l.forEach((r,i)=>{i<n.length&&(r.value=n[i]!=null?String(n[i]):"",r.querySelectorAll("option").forEach(c=>{c.selected=c.value===String(n[i])}),r.classList.remove("invalid"),r.title="")}),n.length!==l.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${l.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"]`);l&&(l.value=n!=null?String(n):"",l.querySelectorAll("option").forEach(r=>{r.selected=r.value===String(n)}),l.classList.remove("invalid"),l.title="")}}function j(e){e.style.backgroundColor="var(--fb-primary-color)",e.style.color="#ffffff",e.style.borderColor="var(--fb-primary-color)"}function O(e){e.style.backgroundColor="transparent",e.style.color="var(--fb-text-color)",e.style.borderColor="var(--fb-border-color)"}function se(e,t,n,o,a){const l=e.options||[],r=document.createElement("div");r.className="fb-switcher-group",r.style.cssText=`
85
+ display: inline-flex;
86
+ flex-direction: row;
87
+ flex-wrap: nowrap;
88
+ `;const i=[];return l.forEach((c,u)=>{const d=document.createElement("button");d.type="button",d.className="fb-switcher-btn",d.dataset.value=c.value,d.textContent=c.label,d.style.cssText=`
89
+ padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
90
+ font-size: var(--fb-font-size);
91
+ border-width: var(--fb-border-width);
92
+ border-style: solid;
93
+ cursor: ${o?"default":"pointer"};
94
+ transition: background-color var(--fb-transition-duration), color var(--fb-transition-duration), border-color var(--fb-transition-duration);
95
+ white-space: nowrap;
96
+ line-height: 1.25;
97
+ outline: none;
98
+ `,l.length===1?d.style.borderRadius="var(--fb-border-radius)":u===0?(d.style.borderRadius="var(--fb-border-radius) 0 0 var(--fb-border-radius)",d.style.borderRightWidth="0"):u===l.length-1?d.style.borderRadius="0 var(--fb-border-radius) var(--fb-border-radius) 0":(d.style.borderRadius="0",d.style.borderRightWidth="0"),c.value===t?j(d):O(d),o||(d.addEventListener("click",()=>{n.value=c.value,i.forEach(s=>{s.dataset.value===c.value?j(s):O(s)}),a&&a(c.value)}),d.addEventListener("mouseenter",()=>{n.value!==c.value&&(d.style.backgroundColor="var(--fb-background-hover-color)")}),d.addEventListener("mouseleave",()=>{n.value!==c.value&&(d.style.backgroundColor="transparent")})),i.push(d),r.appendChild(d)}),r}function nt(e,t,n,o){var a,l;const r=t.state,i=String((l=(a=t.prefill[e.key])!=null?a:e.default)!=null?l:""),c=document.createElement("input");c.type="hidden",c.name=o,c.value=i;const u=r.config.readonly,d=!u&&t.instance?p=>{t.instance.triggerOnChange(o,p)}:null,s=se(e,i,c,u,d);if(n.appendChild(c),n.appendChild(s),!u){const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1",p.textContent=T(e,r),n.appendChild(p)}}function rt(e,t,n,o){var a,l,r,i;const c=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],s=(a=e.minCount)!=null?a:1,p=(l=e.maxCount)!=null?l:1/0;for(;d.length<s;)d.push(e.default||((i=(r=e.options)==null?void 0:r[0])==null?void 0:i.value)||"");const f=c.config.readonly,m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function h(){m.querySelectorAll(".multiple-switcher-item").forEach((b,x)=>{const w=b.querySelector("input[type=hidden]");w&&(w.name=`${o}[${x}]`)})}function g(b="",x=-1){const w=x===-1?m.children.length:x,k=`${o}[${w}]`,S=document.createElement("div");S.className="multiple-switcher-item flex items-center gap-2";const F=document.createElement("input");F.type="hidden",F.name=k,F.value=b,S.appendChild(F);const N=!f&&t.instance?Zt=>{t.instance.triggerOnChange(F.name,Zt)}:null,A=se(e,b,F,f,N);return S.appendChild(A),x===-1?m.appendChild(S):m.insertBefore(S,m.children[x]),h(),S}function E(){if(f)return;const b=m.querySelectorAll(".multiple-switcher-item"),x=b.length;b.forEach(w=>{let k=w.querySelector(".remove-item-btn");k||(k=document.createElement("button"),k.type="button",k.className="remove-item-btn px-2 py-1 rounded",k.style.cssText=`
99
+ color: var(--fb-error-color);
100
+ background-color: transparent;
101
+ transition: background-color var(--fb-transition-duration);
102
+ `,k.innerHTML="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{const F=Array.from(m.children).indexOf(w);m.children.length>s&&(d.splice(F,1),w.remove(),h(),y(),E())},w.appendChild(k));const S=x<=s;k.disabled=S,k.style.opacity=S?"0.5":"1",k.style.pointerEvents=S?"none":"auto"})}let v=null,C=null;if(!f){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const b=document.createElement("button");b.type="button",b.className="add-switcher-btn px-3 py-1 rounded",b.style.cssText=`
103
+ color: var(--fb-primary-color);
104
+ border: var(--fb-border-width) solid var(--fb-primary-color);
105
+ background-color: transparent;
106
+ font-size: var(--fb-font-size);
107
+ transition: all var(--fb-transition-duration);
108
+ `,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{var x,w;const k=e.default||((w=(x=e.options)==null?void 0:x[0])==null?void 0:w.value)||"";d.push(k),g(k),y(),E()},C=document.createElement("span"),C.className="text-sm text-gray-500",v.appendChild(b),v.appendChild(C),n.appendChild(v)}function y(){if(!v||!C)return;const b=v.querySelector(".add-switcher-btn");if(b){const x=d.length>=p;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"}C.textContent=`${d.length}/${p===1/0?"\u221E":p}`}if(d.forEach(b=>g(b)),y(),E(),!f){const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=T(e,c),n.appendChild(b)}}function ot(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(d,s)=>{var p,f;if(!d)return;const m=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(m);s?(d.classList.add("invalid"),d.title=s,h||(h=document.createElement("div"),h.id=m,h.className="error-message",h.style.cssText=`
109
+ color: var(--fb-error-color);
110
+ font-size: var(--fb-font-size-small);
111
+ margin-top: 0.25rem;
112
+ `,d.nextSibling?(p=d.parentNode)==null||p.insertBefore(h,d.nextSibling):(f=d.parentNode)==null||f.appendChild(h)),h.textContent=s,h.style.display="block"):(d.classList.remove("invalid"),d.title="",h&&h.remove())},c=(d,s,p,f)=>{var m,h;if(r)return;const{state:g}=n,E=s.filter(f),v="minCount"in p&&(m=p.minCount)!=null?m:1,C="maxCount"in p&&(h=p.maxCount)!=null?h:1/0;p.required&&E.length===0&&a.push(`${d}: ${$("required",g)}`),E.length<v&&a.push(`${d}: ${$("minItems",g,{min:v})}`),E.length>C&&a.push(`${d}: ${$("maxItems",g,{max:C})}`)},u=new Set("options"in e?e.options.map(d=>d.value):[]);if("multiple"in e&&e.multiple){const d=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`),s=[];return d.forEach(p=>{var f;const m=(f=p==null?void 0:p.value)!=null?f:"";if(s.push(m),!r&&m!==""&&!u.has(m)){const h=$("invalidOption",n.state);i(p,h),a.push(`${t}: ${h}`)}else i(p,null)}),c(t,s,e,p=>p!==""),{value:s,errors:a}}else{const d=l.querySelector(`input[type="hidden"][name$="${t}"]`),s=(o=d==null?void 0:d.value)!=null?o:"";if(!r&&e.required&&s===""){const p=$("required",n.state);return a.push(`${t}: ${p}`),i(d,p),{value:null,errors:a}}if(!r&&s!==""&&!u.has(s)){const p=$("invalidOption",n.state);return a.push(`${t}: ${p}`),i(d,p),{value:null,errors:a}}return i(d,null),{value:s===""?null:s,errors:a}}}function lt(e,t,n,o){var a;const{scopeRoot:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSwitcherField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`);r.forEach((i,c)=>{var u;if(c<n.length){const d=n[c]!=null?String(n[c]):"";i.value=d;const s=(u=i.parentElement)==null?void 0:u.querySelector(".fb-switcher-group");s&&s.querySelectorAll(".fb-switcher-btn").forEach(p=>{p.dataset.value===d?j(p):O(p)}),i.classList.remove("invalid"),i.title=""}}),n.length!==r.length&&console.warn(`updateSwitcherField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=l.querySelector(`input[type="hidden"][name="${t}"]`);if(r){const i=n!=null?String(n):"";r.value=i;const c=(a=r.parentElement)==null?void 0:a.querySelector(".fb-switcher-group");c&&c.querySelectorAll(".fb-switcher-btn").forEach(u=>{u.dataset.value===i?j(u):O(u)}),r.classList.remove("invalid"),r.title=""}}}function at(e,t,n,o){const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=n||$("previewAlt",o);const l=new FileReader;l.onload=r=>{var i;a.src=((i=r.target)==null?void 0:i.result)||""},l.readAsDataURL(t),e.appendChild(a)}function it(e,t,n,o,a,l){const r=URL.createObjectURL(t);e.onclick=null;const i=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(i,e),i.innerHTML=`
85
113
  <div class="relative group h-full">
86
114
  <video class="w-full h-full object-contain" controls preload="auto" muted src="${r}">
87
115
  ${L($("videoNotSupported",a))}
@@ -95,28 +123,28 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
95
123
  </button>
96
124
  </div>
97
125
  </div>
98
- `,Ke(i,o,a,l),i}function Ke(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=r=>{r.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const l=e.querySelector(".delete-file-btn");l&&(l.onclick=r=>{r.stopPropagation(),et(e,t,n,o)})}function et(e,t,n,o){var a;n.resourceIndex.delete(t);const l=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');l&&(l.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&J(e,o.dragHandler),e.innerHTML=`
126
+ `,st(i,o,a,l),i}function st(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=r=>{r.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const l=e.querySelector(".delete-file-btn");l&&(l.onclick=r=>{r.stopPropagation(),ct(e,t,n,o)})}function ct(e,t,n,o){var a;n.resourceIndex.delete(t);const l=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');l&&(l.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&X(e,o.dragHandler),e.innerHTML=`
99
127
  <div class="flex flex-col items-center justify-center h-full text-gray-400">
100
128
  <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
101
129
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
102
130
  </svg>
103
131
  <div class="text-sm text-center">${L($("clickDragText",n))}</div>
104
132
  </div>
105
- `}function tt(e,t,n,o){const a=document.createElement("video");a.className="w-full h-full object-contain",a.controls=!0,a.preload="metadata",a.muted=!0,a.src=t,a.appendChild(document.createTextNode($("videoNotSupported",o))),e.appendChild(a)}function nt(e,t,n){at(e,n,()=>{var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),e.innerHTML=`
133
+ `}function ut(e,t,n,o){const a=document.createElement("video");a.className="w-full h-full object-contain",a.controls=!0,a.preload="metadata",a.muted=!0,a.src=t,a.appendChild(document.createTextNode($("videoNotSupported",o))),e.appendChild(a)}function dt(e,t,n){vt(e,n,()=>{var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),e.innerHTML=`
106
134
  <div class="flex flex-col items-center justify-center h-full text-gray-400">
107
135
  <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
108
136
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
109
137
  </svg>
110
138
  <div class="text-sm text-center">${L($("clickDragText",n))}</div>
111
139
  </div>
112
- `})}async function rt(e,t,n,o,a,l,r){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?Ze(e,t.file,n,l):t.type&&t.type.startsWith("video/")?e=Qe(e,t.file,t.type,o,l,r):e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${L(n)}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&nt(e,o,l))}async function ot(e,t,n,o,a){if(!a.config.getThumbnail){W(e,a);return}try{const l=await a.config.getThumbnail(t);if(l)if(B(e),o&&o.type&&o.type.startsWith("video/"))tt(e,l,o.type,a);else{const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n||$("previewAlt",a),r.src=l,e.appendChild(r)}else W(e,a)}catch(l){console.error("Failed to get thumbnail:",l),e.innerHTML=`
140
+ `})}async function pt(e,t,n,o,a,l,r){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?at(e,t.file,n,l):t.type&&t.type.startsWith("video/")?e=it(e,t.file,t.type,o,l,r):e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${L(n)}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&dt(e,o,l))}async function ft(e,t,n,o,a){if(!a.config.getThumbnail){G(e,a);return}try{const l=await a.config.getThumbnail(t);if(l)if(z(e),o&&o.type&&o.type.startsWith("video/"))ut(e,l,o.type,a);else{const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n||$("previewAlt",a),r.src=l,e.appendChild(r)}else G(e,a)}catch(l){console.error("Failed to get thumbnail:",l),e.innerHTML=`
113
141
  <div class="flex flex-col items-center justify-center h-full text-gray-400">
114
142
  <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
115
143
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
116
144
  </svg>
117
145
  <div class="text-sm text-center">${L(n||$("previewUnavailable",a))}</div>
118
146
  </div>
119
- `}}async function oe(e,t,n,o={}){const{fileName:a="",isReadonly:l=!1,deps:r=null}=o;if(!l&&r&&(!r.picker||!r.fileUploadHandler||!r.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");B(e),l&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await rt(e,i,a,t,l,n,r):await ot(e,t,a,i,n)}async function _(e,t,n){var o,a;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",i=r.toLowerCase().match(/\.psd$/),s=document.createElement("div");s.className=i?"space-y-2":"space-y-3";const u=document.createElement("div");i?u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const d=!i&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),c=((a=l==null?void 0:l.type)==null?void 0:a.startsWith("video/"))||r.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(d)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`<img src="${m}" alt="${L(r)}" class="w-full h-auto">`:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`}catch(m){console.warn("getThumbnail failed for",e,m),u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`}else u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`;else if(c)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`
147
+ `}}async function ce(e,t,n,o={}){const{fileName:a="",isReadonly:l=!1,deps:r=null}=o;if(!l&&r&&(!r.picker||!r.fileUploadHandler||!r.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");z(e),l&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await pt(e,i,a,t,l,n,r):await ft(e,t,a,i,n)}async function Y(e,t,n){var o,a;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",i=r.toLowerCase().match(/\.psd$/),c=document.createElement("div");c.className=i?"space-y-2":"space-y-3";const u=document.createElement("div");i?u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const d=!i&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),s=((a=l==null?void 0:l.type)==null?void 0:a.startsWith("video/"))||r.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(d)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`<img src="${m}" alt="${L(r)}" class="w-full h-auto">`:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`}catch(m){console.warn("getThumbnail failed for",e,m),u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`}else u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F5BC}\uFE0F</div><div class="text-sm">${L(r)}</div></div></div>`;else if(s)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`
120
148
  <div class="relative group">
121
149
  <video class="w-full h-auto" controls preload="auto" muted src="${m}">
122
150
  ${L($("videoNotSupported",t))}
@@ -129,27 +157,27 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
129
157
  </div>
130
158
  </div>
131
159
  </div>
132
- `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`}catch(m){console.warn("getThumbnail failed for video",e,m),u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`}else u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`;else{const m=i?"\u{1F3A8}":"\u{1F4C1}",g=i?"PSD File":"Document";i?u.innerHTML=`
160
+ `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`}catch(m){console.warn("getThumbnail failed for video",e,m),u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`}else u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${L(r)}</div></div></div>`;else{const m=i?"\u{1F3A8}":"\u{1F4C1}",h=i?"PSD File":"Document";i?u.innerHTML=`
133
161
  <div class="flex items-center space-x-3">
134
162
  <div class="text-3xl text-gray-400">${m}</div>
135
163
  <div class="flex-1 min-w-0">
136
164
  <div class="text-sm font-medium text-gray-900 truncate">${L(r)}</div>
137
- <div class="text-xs text-gray-500">${g}</div>
165
+ <div class="text-xs text-gray-500">${h}</div>
138
166
  </div>
139
167
  </div>
140
- `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${m}</div><div class="text-sm">${L(r)}</div><div class="text-xs text-gray-500 mt-1">${g}</div></div></div>`}const v=document.createElement("p");v.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",v.textContent=r;const p=document.createElement("button");return p.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",p.textContent=$("downloadButton",t),p.onclick=m=>{m.preventDefault(),m.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):it(e,r,t)},s.appendChild(u),s.appendChild(v),s.appendChild(p),s}function le(e,t,n,o,a,l){B(e);const r=()=>{const v=[$("clickDragTextMultiple",n)];return a&&v.push(a),l&&v.push(l),v.join(" \u2022 ")},i=!e.classList.contains("grid");if((!t||t.length===0)&&i){const v=document.createElement("div");v.className="grid grid-cols-4 gap-3 mb-3";for(let m=0;m<4;m++){const g=document.createElement("div");g.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors";const h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("class","w-12 h-12 text-gray-400"),h.setAttribute("fill","currentColor"),h.setAttribute("viewBox","0 0 24 24");const E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d","M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"),h.appendChild(E),g.appendChild(h),g.onclick=()=>{let f=e.parentElement;for(;f&&!f.classList.contains("space-y-2");)f=f.parentElement;!f&&e.classList.contains("space-y-2")&&(f=e);const y=f==null?void 0:f.querySelector('input[type="file"]');y&&y.click()},v.appendChild(g)}const p=document.createElement("div");p.className="text-center text-xs text-gray-500 mt-2",p.textContent=r(),e.appendChild(v),e.appendChild(p);return}const s=document.createElement("div");s.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,d=(Math.floor(u/4)+1)*4;for(let v=0;v<d;v++){const p=document.createElement("div");if(t&&v<t.length){const m=t[v],g=n.resourceIndex.get(m);if(p.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",p.dataset.resourceId=m,lt(p,m,g,n).catch(h=>{console.error("Failed to render thumbnail:",h),p.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
168
+ `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${m}</div><div class="text-sm">${L(r)}</div><div class="text-xs text-gray-500 mt-1">${h}</div></div></div>`}const p=document.createElement("p");p.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",p.textContent=r;const f=document.createElement("button");return f.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",f.textContent=$("downloadButton",t),f.onclick=m=>{m.preventDefault(),m.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):ht(e,r,t)},c.appendChild(u),c.appendChild(p),c.appendChild(f),c}function ue(e,t,n,o,a,l){z(e);const r=()=>{const p=[$("clickDragTextMultiple",n)];return a&&p.push(a),l&&p.push(l),p.join(" \u2022 ")},i=!e.classList.contains("grid");if((!t||t.length===0)&&i){const p=document.createElement("div");p.className="grid grid-cols-4 gap-3 mb-3";for(let m=0;m<4;m++){const h=document.createElement("div");h.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors";const g=document.createElementNS("http://www.w3.org/2000/svg","svg");g.setAttribute("class","w-12 h-12 text-gray-400"),g.setAttribute("fill","currentColor"),g.setAttribute("viewBox","0 0 24 24");const E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d","M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"),g.appendChild(E),h.appendChild(g),h.onclick=()=>{let v=e.parentElement;for(;v&&!v.classList.contains("space-y-2");)v=v.parentElement;!v&&e.classList.contains("space-y-2")&&(v=e);const C=v==null?void 0:v.querySelector('input[type="file"]');C&&C.click()},p.appendChild(h)}const f=document.createElement("div");f.className="text-center text-xs text-gray-500 mt-2",f.textContent=r(),e.appendChild(p),e.appendChild(f);return}const c=document.createElement("div");c.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,d=(Math.floor(u/4)+1)*4;for(let p=0;p<d;p++){const f=document.createElement("div");if(t&&p<t.length){const m=t[p],h=n.resourceIndex.get(m);if(f.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",f.dataset.resourceId=m,mt(f,m,h,n).catch(g=>{console.error("Failed to render thumbnail:",g),f.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
141
169
  <div class="text-2xl mb-1">\u{1F4C1}</div>
142
170
  <div class="text-xs">${L($("previewError",n))}</div>
143
- </div>`}),o){const h=document.createElement("div");h.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const E=document.createElement("button");E.className="bg-red-600 text-white px-2 py-1 rounded text-xs",E.textContent=$("removeElement",n),E.onclick=f=>{f.stopPropagation(),o(m)},h.appendChild(E),p.appendChild(h)}}else p.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors",p.innerHTML='<svg class="w-12 h-12 text-gray-400" fill="currentColor" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',p.onclick=()=>{let m=e.parentElement;for(;m&&!m.classList.contains("space-y-2");)m=m.parentElement;!m&&e.classList.contains("space-y-2")&&(m=e);const g=m==null?void 0:m.querySelector('input[type="file"]');g&&g.click()};s.appendChild(p)}e.appendChild(s);const c=document.createElement("div");c.className="text-center text-xs text-gray-500 mt-2",c.textContent=r(),e.appendChild(c)}function ae(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
171
+ </div>`}),o){const g=document.createElement("div");g.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const E=document.createElement("button");E.className="bg-red-600 text-white px-2 py-1 rounded text-xs",E.textContent=$("removeElement",n),E.onclick=v=>{v.stopPropagation(),o(m)},g.appendChild(E),f.appendChild(g)}}else f.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors",f.innerHTML='<svg class="w-12 h-12 text-gray-400" fill="currentColor" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',f.onclick=()=>{let m=e.parentElement;for(;m&&!m.classList.contains("space-y-2");)m=m.parentElement;!m&&e.classList.contains("space-y-2")&&(m=e);const h=m==null?void 0:m.querySelector('input[type="file"]');h&&h.click()};c.appendChild(f)}e.appendChild(c);const s=document.createElement("div");s.className="text-center text-xs text-gray-500 mt-2",s.textContent=r(),e.appendChild(s)}function de(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
144
172
  <svg class="${L(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
145
173
  <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
146
174
  </svg>
147
175
  <div class="text-xs mt-1 text-red-600">${L($("previewError",t))}</div>
148
- </div>`}async function lt(e,t,n,o){var a,l;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n.name;const i=new FileReader;i.onload=s=>{var u;r.src=((u=s.target)==null?void 0:u.result)||""},i.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const i=document.createElement("img");i.className="w-full h-full object-contain",i.alt=n.name,i.src=r,e.appendChild(i)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
176
+ </div>`}async function mt(e,t,n,o){var a,l;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n.name;const i=new FileReader;i.onload=c=>{var u;r.src=((u=c.target)==null?void 0:u.result)||""},i.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const i=document.createElement("img");i.className="w-full h-full object-contain",i.alt=n.name,i.src=r,e.appendChild(i)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
149
177
  <svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
150
178
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
151
179
  </svg>
152
- </div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),ae(e,o)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
180
+ </div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),de(e,o)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
153
181
  <svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
154
182
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
155
183
  </svg>
@@ -182,7 +210,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
182
210
  <path d="M8 5v14l11-7z"/>
183
211
  </svg>
184
212
  <div class="text-xs mt-1">${L((n==null?void 0:n.name)||"Video")}</div>
185
- </div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),ae(e,o,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
213
+ </div>`}catch(r){const i=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(i,t),de(e,o,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
186
214
  <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
187
215
  <path d="M8 5v14l11-7z"/>
188
216
  </svg>
@@ -190,7 +218,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
190
218
  </div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
191
219
  <div class="text-2xl mb-1">\u{1F4C1}</div>
192
220
  <div class="text-xs">${L((n==null?void 0:n.name)||"File")}</div>
193
- </div>`}function W(e,t,n){const o=n?`<div class="text-xs text-gray-500 mt-1">${L(n)}</div>`:"";e.innerHTML=`
221
+ </div>`}function G(e,t,n){const o=n?`<div class="text-xs text-gray-500 mt-1">${L(n)}</div>`:"";e.innerHTML=`
194
222
  <div class="flex flex-col items-center justify-center h-full text-gray-400">
195
223
  <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
196
224
  <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
@@ -198,7 +226,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
198
226
  <div class="text-sm text-center">${L($("clickDragText",t))}</div>
199
227
  ${o}
200
228
  </div>
201
- `}async function ie(e,t,n,o,a=null,l){var r,i;let s;if(o.config.uploadFile)try{if(s=await o.config.uploadFile(e),typeof s!="string")throw new Error("Upload handler must return a string resource ID")}catch(d){const c=d instanceof Error?d:new Error(String(d));throw o.config.onUploadError&&o.config.onUploadError(c,e),new Error(`File upload failed: ${c.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(s,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let u=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');u||(u=document.createElement("input"),u.type="hidden",u.name=n,(i=t.parentElement)==null||i.appendChild(u)),u.value=s,oe(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,s)}function J(e,t){e.addEventListener("dragover",n=>{n.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")}),e.addEventListener("dragleave",n=>{n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")}),e.addEventListener("drop",n=>{var o;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(o=n.dataTransfer)!=null&&o.files&&t(n.dataTransfer.files)})}function at(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const l=document.createElement("button");l.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",l.textContent=$("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},a.appendChild(l),e.appendChild(a)}async function se(e,t){if(t.config.uploadFile)try{const n=await t.config.uploadFile(e);if(typeof n!="string")throw new Error("Upload handler must return a string resource ID");return n}catch(n){const o=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(o,e),new Error(`File upload failed: ${o.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function it(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,l=await fetch(a);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const r=await l.blob();st(r,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function st(e,t){try{const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function ce(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",l=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";l&&(["jpg","jpeg","png","gif","webp"].includes(l)?r=`image/${l==="jpg"?"jpeg":l}`:["mp4","webm","mov","avi"].includes(l)&&(r=`video/${l==="mov"?"quicktime":l}`)),t.resourceIndex.set(n,{name:a,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function ct(e,t,n,o,a,l){var r;if(!a.resourceIndex.has(e)){const s=e.split("/").pop()||"file",u=(r=s.split(".").pop())==null?void 0:r.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:s,type:d,size:0,uploadedAt:new Date,file:void 0})}oe(t,e,a,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function ue(e,t,n,o,a,l){J(e,async r=>{const i=Array.from(r);for(const s of i){const u=await se(s,n);n.resourceIndex.set(u,{name:s.name,type:s.type,size:s.size,uploadedAt:new Date,file:void 0}),t.push(u)}o(),l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)})}function de(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await se(r,n);n.resourceIndex.set(i,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(i)}o(),e.value="",l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)}}function ut(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)_(r,l).then(i=>{n.appendChild(i)}).catch(i=>{console.error("Failed to render file preview:",i);const s=document.createElement("div");s.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",s.innerHTML=`<div class="text-center">${L($("previewUnavailable",l))}</div>`,n.appendChild(s)});else{const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML=`<div class="text-center">${L($("noFileSelected",l))}</div>`,n.appendChild(i)}}else{const r=document.createElement("div");r.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(v=>`.${v}`).join(","))||"");const s=document.createElement("div");s.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const u=t.prefill[e.key],d=()=>i.click(),c=v=>{if(v.length>0){const p={picker:i,fileUploadHandler:d,dragHandler:c};ie(v[0],s,o,l,p,t.instance)}};if(u)ct(u,s,o,r,l,{picker:i,fileUploadHandler:d,dragHandler:c});else{const v=A(e,l);W(s,l,v)}s.onclick=d,J(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const v={picker:i,fileUploadHandler:d,dragHandler:c};ie(i.files[0],s,o,l,v,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function dt(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=document.createElement("div");r.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(s=>{_(s,l).then(u=>{r.appendChild(u)}).catch(u=>{console.error("Failed to render file preview:",u)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L($("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){le(d,c,l,p=>{const m=c.indexOf(p);m>-1&&c.splice(m,1),r()},v)};const i=document.createElement("div");i.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.multiple=!0,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(p=>`.${p}`).join(","))||"");const u=document.createElement("div");u.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const d=document.createElement("div");d.className="files-list";const c=t.prefill[e.key]||[];ce(c,l);const v=A(e,l);r(),ue(u,c,l,r,o,t.instance),de(s,c,l,r,o,t.instance),u.appendChild(d),i.appendChild(u),i.appendChild(s),n.appendChild(i)}}function pt(e,t,n,o){var a,l,r;const i=t.state,s=(a=e.minCount)!=null?a:0,u=(l=e.maxCount)!=null?l:1/0;if(i.config.readonly){const d=document.createElement("div");d.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(v=>{_(v,i).then(p=>{d.appendChild(p)}).catch(p=>{console.error("Failed to render file preview:",p)})}):d.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L($("noFilesSelected",i))}</div></div>`,n.appendChild(d)}else{const d=document.createElement("div");d.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((r=e.accept.extensions)==null?void 0:r.map(E=>`.${E}`).join(","))||"");const v=document.createElement("div");v.className="files-list space-y-2",d.appendChild(c),d.appendChild(v);const p=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];ce(p,i);const m=A(e,i),g=()=>{const E=p.length===1?$("fileCountSingle",i,{count:p.length}):$("fileCountPlural",i,{count:p.length}),f=s>0||u<1/0?` ${$("fileCountRange",i,{min:s,max:u})}`:"";return E+f},h=()=>{le(v,p,i,E=>{p.splice(p.indexOf(E),1),h()},m,g())};ue(v,p,i,h,o,t.instance),de(c,p,i,h,o,t.instance),h(),n.appendChild(d)}}function pe(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,u=(d,c,v)=>{var p,m;if(r)return;const{state:g}=n,h="minCount"in v&&(p=v.minCount)!=null?p:0,E="maxCount"in v&&(m=v.maxCount)!=null?m:1/0;v.required&&c.length===0&&a.push(`${d}: ${$("required",g)}`),c.length<h&&a.push(`${d}: ${$("minFiles",g,{min:h})}`),c.length>E&&a.push(`${d}: ${$("maxFiles",g,{max:E})}`)};if(s){const d=q(i,t),c=l.querySelector(`input[type="file"][name="${d}"]`),v=c==null?void 0:c.closest(".space-y-2"),p=(v==null?void 0:v.querySelector(".files-list"))||null,m=[];return p&&p.querySelectorAll(".resource-pill").forEach(g=>{const h=g.dataset.resourceId;h&&m.push(h)}),u(t,m,e),{value:m,errors:a}}else{const d=l.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=d==null?void 0:d.value)!=null?o:"";return!r&&e.required&&c===""?(a.push(`${t}: ${$("required",n.state)}`),{value:null,errors:a}):{value:c||null,errors:a}}}function fe(e,t,n,o){var a;const{scopeRoot:l,state:r}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(i=>{var s;if(i&&typeof i=="string"&&!r.resourceIndex.has(i)){const u=i.split("/").pop()||"file",d=(s=u.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?c=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(c=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(i,{name:u,type:c,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const i=l.querySelector(`input[name="${t}"][type="hidden"]`);if(!i){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(i.value=n!=null?String(n):"",n&&typeof n=="string"){if(!r.resourceIndex.has(n)){const s=n.split("/").pop()||"file",u=(a=s.split(".").pop())==null?void 0:a.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:s,type:d,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function H(e){return e?e.toUpperCase():"#000000"}function Y(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function me(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function ve(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=H(e),o=document.createElement("div");o.style.cssText=`
229
+ `}async function pe(e,t,n,o,a=null,l){var r,i;let c;if(o.config.uploadFile)try{if(c=await o.config.uploadFile(e),typeof c!="string")throw new Error("Upload handler must return a string resource ID")}catch(d){const s=d instanceof Error?d:new Error(String(d));throw o.config.onUploadError&&o.config.onUploadError(s,e),new Error(`File upload failed: ${s.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(c,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let u=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');u||(u=document.createElement("input"),u.type="hidden",u.name=n,(i=t.parentElement)==null||i.appendChild(u)),u.value=c,ce(t,c,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,c)}function X(e,t){e.addEventListener("dragover",n=>{n.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")}),e.addEventListener("dragleave",n=>{n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")}),e.addEventListener("drop",n=>{var o;n.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50"),(o=n.dataTransfer)!=null&&o.files&&t(n.dataTransfer.files)})}function vt(e,t,n){const o=e.querySelector(".delete-overlay");o&&o.remove();const a=document.createElement("div");a.className="delete-overlay absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const l=document.createElement("button");l.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",l.textContent=$("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},a.appendChild(l),e.appendChild(a)}async function fe(e,t){if(t.config.uploadFile)try{const n=await t.config.uploadFile(e);if(typeof n!="string")throw new Error("Upload handler must return a string resource ID");return n}catch(n){const o=n instanceof Error?n:new Error(String(n));throw t.config.onUploadError&&t.config.onUploadError(o,e),new Error(`File upload failed: ${o.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()")}async function ht(e,t,n){try{let o=null;if(n.config.getDownloadUrl?o=n.config.getDownloadUrl(e):n.config.getThumbnail&&(o=await n.config.getThumbnail(e)),o){const a=o.startsWith("http")?o:new URL(o,window.location.href).href,l=await fetch(a);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const r=await l.blob();gt(r,t)}else throw new Error("No download URL available for resource")}catch(o){const a=o instanceof Error?o:new Error(String(o));throw n.config.onDownloadError&&n.config.onDownloadError(a,e,t),console.error(`File download failed for ${t}:`,a),a}}function gt(e,t){try{const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}function me(e,t){e.length>0&&e.forEach(n=>{var o;if(!t.resourceIndex.has(n)){const a=n.split("/").pop()||"file",l=(o=a.split(".").pop())==null?void 0:o.toLowerCase();let r="application/octet-stream";l&&(["jpg","jpeg","png","gif","webp"].includes(l)?r=`image/${l==="jpg"?"jpeg":l}`:["mp4","webm","mov","avi"].includes(l)&&(r=`video/${l==="mov"?"quicktime":l}`)),t.resourceIndex.set(n,{name:a,type:r,size:0,uploadedAt:new Date,file:void 0})}})}function yt(e,t,n,o,a,l){var r;if(!a.resourceIndex.has(e)){const c=e.split("/").pop()||"file",u=(r=c.split(".").pop())==null?void 0:r.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:c,type:d,size:0,uploadedAt:new Date,file:void 0})}ce(t,e,a,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const i=document.createElement("input");i.type="hidden",i.name=n,i.value=e,o.appendChild(i)}function ve(e,t,n,o,a,l){X(e,async r=>{const i=Array.from(r);for(const c of i){const u=await fe(c,n);n.resourceIndex.set(u,{name:c.name,type:c.type,size:c.size,uploadedAt:new Date,file:void 0}),t.push(u)}o(),l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)})}function he(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await fe(r,n);n.resourceIndex.set(i,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(i)}o(),e.value="",l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)}}function bt(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)Y(r,l).then(i=>{n.appendChild(i)}).catch(i=>{console.error("Failed to render file preview:",i);const c=document.createElement("div");c.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",c.innerHTML=`<div class="text-center">${L($("previewUnavailable",l))}</div>`,n.appendChild(c)});else{const i=document.createElement("div");i.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",i.innerHTML=`<div class="text-center">${L($("noFileSelected",l))}</div>`,n.appendChild(i)}}else{const r=document.createElement("div");r.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(p=>`.${p}`).join(","))||"");const c=document.createElement("div");c.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const u=t.prefill[e.key],d=()=>i.click(),s=p=>{if(p.length>0){const f={picker:i,fileUploadHandler:d,dragHandler:s};pe(p[0],c,o,l,f,t.instance)}};if(u)yt(u,c,o,r,l,{picker:i,fileUploadHandler:d,dragHandler:s});else{const p=T(e,l);G(c,l,p)}c.onclick=d,X(c,s),i.onchange=()=>{if(i.files&&i.files.length>0){const p={picker:i,fileUploadHandler:d,dragHandler:s};pe(i.files[0],c,o,l,p,t.instance)}},r.appendChild(c),r.appendChild(i),n.appendChild(r)}}function xt(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=document.createElement("div");r.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(c=>{Y(c,l).then(u=>{r.appendChild(u)}).catch(u=>{console.error("Failed to render file preview:",u)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L($("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){ue(d,s,l,f=>{const m=s.indexOf(f);m>-1&&s.splice(m,1),r()},p)};const i=document.createElement("div");i.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(f=>`.${f}`).join(","))||"");const u=document.createElement("div");u.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const d=document.createElement("div");d.className="files-list";const s=t.prefill[e.key]||[];me(s,l);const p=T(e,l);r(),ve(u,s,l,r,o,t.instance),he(c,s,l,r,o,t.instance),u.appendChild(d),i.appendChild(u),i.appendChild(c),n.appendChild(i)}}function Ct(e,t,n,o){var a,l,r;const i=t.state,c=(a=e.minCount)!=null?a:0,u=(l=e.maxCount)!=null?l:1/0;if(i.config.readonly){const d=document.createElement("div");d.className="space-y-4";const s=t.prefill[e.key]||[];s.length>0?s.forEach(p=>{Y(p,i).then(f=>{d.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):d.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${L($("noFilesSelected",i))}</div></div>`,n.appendChild(d)}else{const d=document.createElement("div");d.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.multiple=!0,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((r=e.accept.extensions)==null?void 0:r.map(E=>`.${E}`).join(","))||"");const p=document.createElement("div");p.className="files-list space-y-2",d.appendChild(s),d.appendChild(p);const f=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];me(f,i);const m=T(e,i),h=()=>{const E=f.length===1?$("fileCountSingle",i,{count:f.length}):$("fileCountPlural",i,{count:f.length}),v=c>0||u<1/0?` ${$("fileCountRange",i,{min:c,max:u})}`:"";return E+v},g=()=>{ue(p,f,i,E=>{f.splice(f.indexOf(E),1),g()},m,h())};ve(p,f,i,g,o,t.instance),he(s,f,i,g,o,t.instance),g(),n.appendChild(d)}}function ge(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:i}=n,c=e.type==="files"||"multiple"in e&&!!e.multiple,u=(d,s,p)=>{var f,m;if(r)return;const{state:h}=n,g="minCount"in p&&(f=p.minCount)!=null?f:0,E="maxCount"in p&&(m=p.maxCount)!=null?m:1/0;p.required&&s.length===0&&a.push(`${d}: ${$("required",h)}`),s.length<g&&a.push(`${d}: ${$("minFiles",h,{min:g})}`),s.length>E&&a.push(`${d}: ${$("maxFiles",h,{max:E})}`)};if(c){const d=M(i,t),s=l.querySelector(`input[type="file"][name="${d}"]`),p=s==null?void 0:s.closest(".space-y-2"),f=(p==null?void 0:p.querySelector(".files-list"))||null,m=[];return f&&f.querySelectorAll(".resource-pill").forEach(h=>{const g=h.dataset.resourceId;g&&m.push(g)}),u(t,m,e),{value:m,errors:a}}else{const d=l.querySelector(`input[name$="${t}"][type="hidden"]`),s=(o=d==null?void 0:d.value)!=null?o:"";return!r&&e.required&&s===""?(a.push(`${t}: ${$("required",n.state)}`),{value:null,errors:a}):{value:s||null,errors:a}}}function ye(e,t,n,o){var a;const{scopeRoot:l,state:r}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateFileField: Expected array for multiple file field "${t}", got ${typeof n}`);return}n.forEach(i=>{var c;if(i&&typeof i=="string"&&!r.resourceIndex.has(i)){const u=i.split("/").pop()||"file",d=(c=u.split(".").pop())==null?void 0:c.toLowerCase();let s="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?s=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(s=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(i,{name:u,type:s,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const i=l.querySelector(`input[name="${t}"][type="hidden"]`);if(!i){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(i.value=n!=null?String(n):"",n&&typeof n=="string"){if(!r.resourceIndex.has(n)){const c=n.split("/").pop()||"file",u=(a=c.split(".").pop())==null?void 0:a.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:c,type:d,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function B(e){return e?e.toUpperCase():"#000000"}function Z(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function be(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`.toUpperCase()}return e.toUpperCase()}function xe(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=B(e),o=document.createElement("div");o.style.cssText=`
202
230
  width: 32px;
203
231
  height: 32px;
204
232
  border-radius: var(--fb-border-radius);
@@ -208,7 +236,7 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
208
236
  font-size: var(--fb-font-size);
209
237
  color: var(--fb-text-color);
210
238
  font-family: var(--fb-font-family-mono, monospace);
211
- `,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function he(e,t,n){const o=H(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
239
+ `,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function Ce(e,t,n){const o=B(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
212
240
  display: flex;
213
241
  align-items: center;
214
242
  gap: 8px;
@@ -235,45 +263,45 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
235
263
  position: absolute;
236
264
  opacity: 0;
237
265
  pointer-events: none;
238
- `,r.addEventListener("input",()=>{const s=r.value.trim();if(Y(s)){const u=me(s);l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else r.classList.add("invalid")}),r.addEventListener("blur",()=>{const s=r.value.trim();if(Y(s)){const u=me(s);r.value=u,l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid")}}),i.addEventListener("change",()=>{const s=H(i.value);r.value=s,l.style.backgroundColor=s,n.instance&&n.instance.triggerOnChange(t,s)}),l.addEventListener("click",()=>{i.click()}),l.addEventListener("mouseenter",()=>{l.style.borderColor="var(--fb-border-hover-color)"}),l.addEventListener("mouseleave",()=>{l.style.borderColor="var(--fb-border-color)"}),r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")}),a.appendChild(l),a.appendChild(r),a.appendChild(i),a}function ft(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=ve(l);n.appendChild(r)}else{const r=he(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
266
+ `,r.addEventListener("input",()=>{const c=r.value.trim();if(Z(c)){const u=be(c);l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else r.classList.add("invalid")}),r.addEventListener("blur",()=>{const c=r.value.trim();if(Z(c)){const u=be(c);r.value=u,l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid")}}),i.addEventListener("change",()=>{const c=B(i.value);r.value=c,l.style.backgroundColor=c,n.instance&&n.instance.triggerOnChange(t,c)}),l.addEventListener("click",()=>{i.click()}),l.addEventListener("mouseenter",()=>{l.style.borderColor="var(--fb-border-hover-color)"}),l.addEventListener("mouseleave",()=>{l.style.borderColor="var(--fb-border-color)"}),r.addEventListener("focus",()=>{r.style.borderColor="var(--fb-border-focus-color)",r.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",r.style.outlineOffset="0"}),r.addEventListener("blur",()=>{r.style.borderColor="var(--fb-border-color)",r.style.outline="none"}),r.addEventListener("mouseenter",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-hover-color)")}),r.addEventListener("mouseleave",()=>{document.activeElement!==r&&(r.style.borderColor="var(--fb-border-color)")}),a.appendChild(l),a.appendChild(r),a.appendChild(i),a}function Et(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=xe(l);n.appendChild(r)}else{const r=Ce(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
239
267
  font-size: var(--fb-font-size-small);
240
268
  color: var(--fb-text-secondary-color);
241
- `,r.textContent=A(e,a),n.appendChild(r)}}function mt(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;s.length<u;)s.push(e.default||"#000000");const c=document.createElement("div");c.className="space-y-2",n.appendChild(c);function v(){c.querySelectorAll(".multiple-colour-item").forEach((f,y)=>{const b=f.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function p(f="#000000",y=-1){const b=document.createElement("div");if(b.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const x=ve(f);for(;x.firstChild;)b.appendChild(x.firstChild)}else{const x=`${o}[${c.children.length}]`,C=he(f,x,t);C.style.flex="1",b.appendChild(C)}return y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),v(),b}function m(){if(r.config.readonly)return;const f=c.querySelectorAll(".multiple-colour-item"),y=f.length;f.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 rounded",x.style.cssText=`
269
+ `,r.textContent=T(e,a),n.appendChild(r)}}function $t(e,t,n,o){var a,l;const r=t.state,i=t.prefill[e.key]||[],c=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"#000000");const s=document.createElement("div");s.className="space-y-2",n.appendChild(s);function p(){s.querySelectorAll(".multiple-colour-item").forEach((v,C)=>{const y=v.querySelector("input");y&&(y.name=`${o}[${C}]`)})}function f(v="#000000",C=-1){const y=document.createElement("div");if(y.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const b=xe(v);for(;b.firstChild;)y.appendChild(b.firstChild)}else{const b=`${o}[${s.children.length}]`,x=Ce(v,b,t);x.style.flex="1",y.appendChild(x)}return C===-1?s.appendChild(y):s.insertBefore(y,s.children[C]),p(),y}function m(){if(r.config.readonly)return;const v=s.querySelectorAll(".multiple-colour-item"),C=v.length;v.forEach(y=>{let b=y.querySelector(".remove-item-btn");b||(b=document.createElement("button"),b.type="button",b.className="remove-item-btn px-2 py-1 rounded",b.style.cssText=`
242
270
  color: var(--fb-error-color);
243
271
  background-color: transparent;
244
272
  transition: background-color var(--fb-transition-duration);
245
- `,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),v(),E(),m())},b.appendChild(x));const C=y<=u;x.disabled=C,x.style.opacity=C?"0.5":"1",x.style.pointerEvents=C?"none":"auto"})}let g=null,h=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const f=document.createElement("button");f.type="button",f.className="add-colour-btn px-3 py-1 rounded",f.style.cssText=`
273
+ `,b.innerHTML="\u2715",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{const w=Array.from(s.children).indexOf(y);s.children.length>u&&(c.splice(w,1),y.remove(),p(),E(),m())},y.appendChild(b));const x=C<=u;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"})}let h=null,g=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const v=document.createElement("button");v.type="button",v.className="add-colour-btn px-3 py-1 rounded",v.style.cssText=`
246
274
  color: var(--fb-primary-color);
247
275
  border: var(--fb-border-width) solid var(--fb-primary-color);
248
276
  background-color: transparent;
249
277
  font-size: var(--fb-font-size);
250
278
  transition: all var(--fb-transition-duration);
251
- `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{const y=e.default||"#000000";s.push(y),p(y),E(),m()},h=document.createElement("span"),h.className="text-sm text-gray-500",g.appendChild(f),g.appendChild(h),n.appendChild(g)}function E(){if(!g||!h)return;const f=g.querySelector(".add-colour-btn");if(f){const y=s.length>=d;f.disabled=y,f.style.opacity=y?"0.5":"1",f.style.pointerEvents=y?"none":"auto"}h.textContent=`${s.length}/${d===1/0?"\u221E":d}`}if(s.forEach(f=>p(f)),E(),m(),!r.config.readonly){const f=document.createElement("p");f.className="mt-1",f.style.cssText=`
279
+ `,v.textContent="+",v.addEventListener("mouseenter",()=>{v.style.backgroundColor="var(--fb-background-hover-color)"}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"}),v.onclick=()=>{const C=e.default||"#000000";c.push(C),f(C),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",h.appendChild(v),h.appendChild(g),n.appendChild(h)}function E(){if(!h||!g)return;const v=h.querySelector(".add-colour-btn");if(v){const C=c.length>=d;v.disabled=C,v.style.opacity=C?"0.5":"1",v.style.pointerEvents=C?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}if(c.forEach(v=>f(v)),E(),m(),!r.config.readonly){const v=document.createElement("p");v.className="mt-1",v.style.cssText=`
252
280
  font-size: var(--fb-font-size-small);
253
281
  color: var(--fb-text-secondary-color);
254
- `,f.textContent=A(e,r),n.appendChild(f)}}function vt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,v)=>{var p,m;if(!c)return;const g=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(g);v?(c.classList.add("invalid"),c.title=v,h||(h=document.createElement("div"),h.id=g,h.className="error-message",h.style.cssText=`
282
+ `,v.textContent=T(e,r),n.appendChild(v)}}function wt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:c}=n,u=(s,p)=>{var f,m;if(!s)return;const h=`error-${s.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(h);p?(s.classList.add("invalid"),s.title=p,g||(g=document.createElement("div"),g.id=h,g.className="error-message",g.style.cssText=`
255
283
  color: var(--fb-error-color);
256
284
  font-size: var(--fb-font-size-small);
257
285
  margin-top: 0.25rem;
258
- `,c.nextSibling?(p=c.parentNode)==null||p.insertBefore(h,c.nextSibling):(m=c.parentNode)==null||m.appendChild(h)),h.textContent=v,h.style.display="block"):(c.classList.remove("invalid"),c.title="",h&&h.remove())},d=(c,v,p)=>{const{state:m}=n;if(!v){if(!s&&e.required){const h=$("required",m);return r.push(`${p}: ${h}`),u(c,h),""}return u(c,null),""}const g=H(v);if(!s&&!Y(g)){const h=$("invalidHexColour",m);return r.push(`${p}: ${h}`),u(c,h),v}return u(c,null),g};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["].colour-hex-input`),v=[];if(c.forEach((p,m)=>{var g;const h=(g=p==null?void 0:p.value)!=null?g:"",E=d(p,h,`${t}[${m}]`);v.push(E)}),!s){const{state:p}=n,m=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,h=v.filter(E=>E!=="");e.required&&h.length===0&&r.push(`${t}: ${$("required",p)}`),h.length<m&&r.push(`${t}: ${$("minItems",p,{min:m})}`),h.length>g&&r.push(`${t}: ${$("maxItems",p,{max:g})}`)}return{value:v,errors:r}}else{const c=i.querySelector(`[name="${t}"].colour-hex-input`),v=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&v===""){const p=$("required",n.state);return r.push(`${t}: ${p}`),u(c,p),{value:"",errors:r}}return{value:d(c,v,t),errors:r}}}function ht(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["].colour-hex-input`);l.forEach((r,i)=>{if(i<n.length){const s=H(n[i]);r.value=s,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const d=u.querySelector(".colour-swatch"),c=u.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=s),c&&(c.value=s.toLowerCase())}}}),n.length!==l.length&&console.warn(`updateColourField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"].colour-hex-input`);if(l){const r=H(n);l.value=r,l.classList.remove("invalid"),l.title="";const i=l.closest(".colour-picker-wrapper");if(i){const s=i.querySelector(".colour-swatch"),u=i.querySelector(".colour-picker-hidden");s&&(s.style.backgroundColor=r),u&&(u.value=r.toLowerCase())}}}}function ge(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return Math.exp(o+e*(a-o))}function G(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return(Math.log(e)-o)/(a-o)}function D(e,t){return Math.round(e/t)*t}function ye(e,t,n,o,a){var l;const r=document.createElement("div");r.className="slider-container";const i=document.createElement("div");i.className="flex items-start gap-3";const s=document.createElement("div");s.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=a;const d=n.scale||"linear",c=n.min,v=n.max,p=(l=n.step)!=null?l:1;if(d==="exponential"){if(c<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${c})`);u.min="0",u.max="1000",u.step="1";const f=G(e,c,v);u.value=(f*1e3).toString()}else u.min=c.toString(),u.max=v.toString(),u.step=p.toString(),u.value=e.toString();u.style.cssText=`
286
+ `,s.nextSibling?(f=s.parentNode)==null||f.insertBefore(g,s.nextSibling):(m=s.parentNode)==null||m.appendChild(g)),g.textContent=p,g.style.display="block"):(s.classList.remove("invalid"),s.title="",g&&g.remove())},d=(s,p,f)=>{const{state:m}=n;if(!p){if(!c&&e.required){const g=$("required",m);return r.push(`${f}: ${g}`),u(s,g),""}return u(s,null),""}const h=B(p);if(!c&&!Z(h)){const g=$("invalidHexColour",m);return r.push(`${f}: ${g}`),u(s,g),p}return u(s,null),h};if(e.multiple){const s=i.querySelectorAll(`[name^="${t}["].colour-hex-input`),p=[];if(s.forEach((f,m)=>{var h;const g=(h=f==null?void 0:f.value)!=null?h:"",E=d(f,g,`${t}[${m}]`);p.push(E)}),!c){const{state:f}=n,m=(o=e.minCount)!=null?o:1,h=(a=e.maxCount)!=null?a:1/0,g=p.filter(E=>E!=="");e.required&&g.length===0&&r.push(`${t}: ${$("required",f)}`),g.length<m&&r.push(`${t}: ${$("minItems",f,{min:m})}`),g.length>h&&r.push(`${t}: ${$("maxItems",f,{max:h})}`)}return{value:p,errors:r}}else{const s=i.querySelector(`[name="${t}"].colour-hex-input`),p=(l=s==null?void 0:s.value)!=null?l:"";if(!c&&e.required&&p===""){const f=$("required",n.state);return r.push(`${t}: ${f}`),u(s,f),{value:"",errors:r}}return{value:d(s,p,t),errors:r}}}function kt(e,t,n,o){const{scopeRoot:a}=o;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const l=a.querySelectorAll(`[name^="${t}["].colour-hex-input`);l.forEach((r,i)=>{if(i<n.length){const c=B(n[i]);r.value=c,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const d=u.querySelector(".colour-swatch"),s=u.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=c),s&&(s.value=c.toLowerCase())}}}),n.length!==l.length&&console.warn(`updateColourField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"].colour-hex-input`);if(l){const r=B(n);l.value=r,l.classList.remove("invalid"),l.title="";const i=l.closest(".colour-picker-wrapper");if(i){const c=i.querySelector(".colour-swatch"),u=i.querySelector(".colour-picker-hidden");c&&(c.style.backgroundColor=r),u&&(u.value=r.toLowerCase())}}}}function Ee(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return Math.exp(o+e*(a-o))}function K(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const o=Math.log(t),a=Math.log(n);return(Math.log(e)-o)/(a-o)}function U(e,t){return Math.round(e/t)*t}function $e(e,t,n,o,a){var l;const r=document.createElement("div");r.className="slider-container";const i=document.createElement("div");i.className="flex items-start gap-3";const c=document.createElement("div");c.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=a;const d=n.scale||"linear",s=n.min,p=n.max,f=(l=n.step)!=null?l:1;if(d==="exponential"){if(s<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${s})`);u.min="0",u.max="1000",u.step="1";const v=K(e,s,p);u.value=(v*1e3).toString()}else u.min=s.toString(),u.max=p.toString(),u.step=f.toString(),u.value=e.toString();u.style.cssText=`
259
287
  height: 6px;
260
288
  border-radius: 3px;
261
289
  background: linear-gradient(
262
290
  to right,
263
291
  var(--fb-primary-color) 0%,
264
- var(--fb-primary-color) ${(e-c)/(v-c)*100}%,
265
- var(--fb-border-color) ${(e-c)/(v-c)*100}%,
292
+ var(--fb-primary-color) ${(e-s)/(p-s)*100}%,
293
+ var(--fb-border-color) ${(e-s)/(p-s)*100}%,
266
294
  var(--fb-border-color) 100%
267
295
  );
268
296
  outline: none;
269
297
  transition: background 0.1s ease-in-out;
270
298
  cursor: ${a?"not-allowed":"pointer"};
271
299
  opacity: ${a?"0.6":"1"};
272
- `,s.appendChild(u);const m=document.createElement("div");m.className="flex justify-between",m.style.cssText=`
300
+ `,c.appendChild(u);const m=document.createElement("div");m.className="flex justify-between",m.style.cssText=`
273
301
  font-size: var(--fb-font-size-small);
274
302
  color: var(--fb-text-secondary-color);
275
303
  margin-top: 4px;
276
- `;const g=document.createElement("span");g.textContent=c.toString();const h=document.createElement("span");h.textContent=v.toString(),m.appendChild(g),m.appendChild(h),s.appendChild(m);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
304
+ `;const h=document.createElement("span");h.textContent=s.toString();const g=document.createElement("span");g.textContent=p.toString(),m.appendChild(h),m.appendChild(g),c.appendChild(m);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
277
305
  min-width: 60px;
278
306
  text-align: right;
279
307
  font-size: var(--fb-font-size);
@@ -281,69 +309,69 @@ var FormBuilder=(function(T){"use strict";function $(e,t,n){const o=t.config.loc
281
309
  font-family: var(--fb-font-family-mono, monospace);
282
310
  font-weight: 500;
283
311
  padding-top: 2px;
284
- `,E.textContent=e.toFixed(p<1?2:0),i.appendChild(s),i.appendChild(E),r.appendChild(i),!a){const f=()=>{let y;if(d==="exponential"){const x=parseFloat(u.value)/1e3;y=ge(x,c,v),y=D(y,p),y=Math.max(c,Math.min(v,y))}else y=parseFloat(u.value),y=D(y,p);E.textContent=y.toFixed(p<1?2:0);const b=(y-c)/(v-c)*100;u.style.background=`linear-gradient(
312
+ `,E.textContent=e.toFixed(f<1?2:0),i.appendChild(c),i.appendChild(E),r.appendChild(i),!a){const v=()=>{let C;if(d==="exponential"){const b=parseFloat(u.value)/1e3;C=Ee(b,s,p),C=U(C,f),C=Math.max(s,Math.min(p,C))}else C=parseFloat(u.value),C=U(C,f);E.textContent=C.toFixed(f<1?2:0);const y=(C-s)/(p-s)*100;u.style.background=`linear-gradient(
285
313
  to right,
286
314
  var(--fb-primary-color) 0%,
287
- var(--fb-primary-color) ${b}%,
288
- var(--fb-border-color) ${b}%,
315
+ var(--fb-primary-color) ${y}%,
316
+ var(--fb-border-color) ${y}%,
289
317
  var(--fb-border-color) 100%
290
- )`,o.instance&&o.instance.triggerOnChange(t,y)};u.addEventListener("input",f),u.addEventListener("change",f)}return r}function gt(e,t,n,o){var a;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const l=t.state,r=e.default!==void 0?e.default:(e.min+e.max)/2,i=(a=t.prefill[e.key])!=null?a:r,s=ye(i,o,e,t,l.config.readonly);if(n.appendChild(s),!l.config.readonly){const u=document.createElement("p");u.className="mt-1",u.style.cssText=`
318
+ )`,o.instance&&o.instance.triggerOnChange(t,C)};u.addEventListener("input",v),u.addEventListener("change",v)}return r}function St(e,t,n,o){var a;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const l=t.state,r=e.default!==void 0?e.default:(e.min+e.max)/2,i=(a=t.prefill[e.key])!=null?a:r,c=$e(i,o,e,t,l.config.readonly);if(n.appendChild(c),!l.config.readonly){const u=document.createElement("p");u.className="mt-1",u.style.cssText=`
291
319
  font-size: var(--fb-font-size-small);
292
320
  color: var(--fb-text-secondary-color);
293
- `,u.textContent=A(e,l),n.appendChild(u)}}function yt(e,t,n,o){var a,l;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const r=t.state,i=t.prefill[e.key]||[],s=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0,c=e.default!==void 0?e.default:(e.min+e.max)/2;for(;s.length<u;)s.push(c);const v=document.createElement("div");v.className="space-y-3",n.appendChild(v);function p(){v.querySelectorAll(".multiple-slider-item").forEach((y,b)=>{const x=y.querySelector("input[type=range]");x&&x.setAttribute("name",`${o}[${b}]`)})}function m(y=c,b=-1){const x=document.createElement("div");x.className="multiple-slider-item flex items-start gap-2";const C=`${o}[${v.children.length}]`,w=ye(y,C,e,t,r.config.readonly);return w.style.flex="1",x.appendChild(w),b===-1?v.appendChild(x):v.insertBefore(x,v.children[b]),p(),x}function g(){if(r.config.readonly)return;const y=v.querySelectorAll(".multiple-slider-item"),b=y.length;y.forEach(x=>{let C=x.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 rounded",C.style.cssText=`
321
+ `,u.textContent=T(e,l),n.appendChild(u)}}function Lt(e,t,n,o){var a,l;if(e.min===void 0||e.min===null)throw new Error(`Slider field "${e.key}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider field "${e.key}" requires "max" property`);if(e.min>=e.max)throw new Error(`Slider field "${e.key}": min (${e.min}) must be less than max (${e.max})`);const r=t.state,i=t.prefill[e.key]||[],c=Array.isArray(i)?[...i]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0,s=e.default!==void 0?e.default:(e.min+e.max)/2;for(;c.length<u;)c.push(s);const p=document.createElement("div");p.className="space-y-3",n.appendChild(p);function f(){p.querySelectorAll(".multiple-slider-item").forEach((C,y)=>{const b=C.querySelector("input[type=range]");b&&b.setAttribute("name",`${o}[${y}]`)})}function m(C=s,y=-1){const b=document.createElement("div");b.className="multiple-slider-item flex items-start gap-2";const x=`${o}[${p.children.length}]`,w=$e(C,x,e,t,r.config.readonly);return w.style.flex="1",b.appendChild(w),y===-1?p.appendChild(b):p.insertBefore(b,p.children[y]),f(),b}function h(){if(r.config.readonly)return;const C=p.querySelectorAll(".multiple-slider-item"),y=C.length;C.forEach(b=>{let x=b.querySelector(".remove-item-btn");x||(x=document.createElement("button"),x.type="button",x.className="remove-item-btn px-2 py-1 rounded",x.style.cssText=`
294
322
  color: var(--fb-error-color);
295
323
  background-color: transparent;
296
324
  transition: background-color var(--fb-transition-duration);
297
325
  margin-top: 8px;
298
- `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const k=Array.from(v.children).indexOf(x);v.children.length>u&&(s.splice(k,1),x.remove(),p(),f(),g())},x.appendChild(C));const w=b<=u;C.disabled=w,C.style.opacity=w?"0.5":"1",C.style.pointerEvents=w?"none":"auto"})}let h=null,E=null;if(!r.config.readonly){h=document.createElement("div"),h.className="flex items-center gap-3 mt-2";const y=document.createElement("button");y.type="button",y.className="add-slider-btn px-3 py-1 rounded",y.style.cssText=`
326
+ `,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const k=Array.from(p.children).indexOf(b);p.children.length>u&&(c.splice(k,1),b.remove(),f(),v(),h())},b.appendChild(x));const w=y<=u;x.disabled=w,x.style.opacity=w?"0.5":"1",x.style.pointerEvents=w?"none":"auto"})}let g=null,E=null;if(!r.config.readonly){g=document.createElement("div"),g.className="flex items-center gap-3 mt-2";const C=document.createElement("button");C.type="button",C.className="add-slider-btn px-3 py-1 rounded",C.style.cssText=`
299
327
  color: var(--fb-primary-color);
300
328
  border: var(--fb-border-width) solid var(--fb-primary-color);
301
329
  background-color: transparent;
302
330
  font-size: var(--fb-font-size);
303
331
  transition: all var(--fb-transition-duration);
304
- `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{s.push(c),m(c),f(),g()},E=document.createElement("span"),E.className="text-sm text-gray-500",h.appendChild(y),h.appendChild(E),n.appendChild(h)}function f(){if(!h||!E)return;const y=h.querySelector(".add-slider-btn");if(y){const b=s.length>=d;y.disabled=b,y.style.opacity=b?"0.5":"1",y.style.pointerEvents=b?"none":"auto"}E.textContent=`${s.length}/${d===1/0?"\u221E":d}`}if(s.forEach(y=>m(y)),f(),g(),!r.config.readonly){const y=document.createElement("p");y.className="mt-1",y.style.cssText=`
332
+ `,C.textContent="+",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{c.push(s),m(s),v(),h()},E=document.createElement("span"),E.className="text-sm text-gray-500",g.appendChild(C),g.appendChild(E),n.appendChild(g)}function v(){if(!g||!E)return;const C=g.querySelector(".add-slider-btn");if(C){const y=c.length>=d;C.disabled=y,C.style.opacity=y?"0.5":"1",C.style.pointerEvents=y?"none":"auto"}E.textContent=`${c.length}/${d===1/0?"\u221E":d}`}if(c.forEach(C=>m(C)),v(),h(),!r.config.readonly){const C=document.createElement("p");C.className="mt-1",C.style.cssText=`
305
333
  font-size: var(--fb-font-size-small);
306
334
  color: var(--fb-text-secondary-color);
307
- `,y.textContent=A(e,r),n.appendChild(y)}}function bt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const u=e.min,d=e.max,c=(o=e.step)!=null?o:1,v=e.scale||"linear",p=(g,h)=>{var E,f;if(!g)return;const y=`error-${g.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(y);if(h){if(g.classList.add("invalid"),g.title=h,!b){b=document.createElement("div"),b.id=y,b.className="error-message",b.style.cssText=`
335
+ `,C.textContent=T(e,r),n.appendChild(C)}}function Ft(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:c}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const u=e.min,d=e.max,s=(o=e.step)!=null?o:1,p=e.scale||"linear",f=(h,g)=>{var E,v;if(!h)return;const C=`error-${h.getAttribute("name")||Math.random().toString(36).substring(7)}`;let y=document.getElementById(C);if(g){if(h.classList.add("invalid"),h.title=g,!y){y=document.createElement("div"),y.id=C,y.className="error-message",y.style.cssText=`
308
336
  color: var(--fb-error-color);
309
337
  font-size: var(--fb-font-size-small);
310
338
  margin-top: 0.25rem;
311
- `;const x=g.closest(".slider-container");x&&x.nextSibling?(E=x.parentNode)==null||E.insertBefore(b,x.nextSibling):x&&((f=x.parentNode)==null||f.appendChild(b))}b.textContent=h,b.style.display="block"}else g.classList.remove("invalid"),g.title="",b&&b.remove()},m=(g,h)=>{const{state:E}=n,f=g.value;if(!f){if(!s&&e.required){const b=$("required",E);return r.push(`${h}: ${b}`),p(g,b),null}return p(g,null),null}let y;if(v==="exponential"){const b=parseFloat(f)/1e3;y=ge(b,u,d),y=D(y,c)}else y=parseFloat(f),y=D(y,c);if(!s){if(y<u){const b=$("minValue",E,{min:u});return r.push(`${h}: ${b}`),p(g,b),y}if(y>d){const b=$("maxValue",E,{max:d});return r.push(`${h}: ${b}`),p(g,b),y}}return p(g,null),y};if(e.multiple){const g=i.querySelectorAll(`input[type="range"][name^="${t}["]`),h=[];if(g.forEach((E,f)=>{const y=m(E,`${t}[${f}]`);h.push(y)}),!s){const{state:E}=n,f=(a=e.minCount)!=null?a:1,y=(l=e.maxCount)!=null?l:1/0,b=h.filter(x=>x!==null);e.required&&b.length===0&&r.push(`${t}: ${$("required",E)}`),b.length<f&&r.push(`${t}: ${$("minItems",E,{min:f})}`),b.length>y&&r.push(`${t}: ${$("maxItems",E,{max:y})}`)}return{value:h,errors:r}}else{const g=i.querySelector(`input[type="range"][name="${t}"]`);return g?{value:m(g,t),errors:r}:(!s&&e.required&&r.push(`${t}: ${$("required",n.state)}`),{value:null,errors:r})}}function xt(e,t,n,o){var a;const{scopeRoot:l}=o,r=e.min,i=e.max,s=(a=e.step)!=null?a:1,u=e.scale||"linear";if(e.multiple){if(!Array.isArray(n)){console.warn(`updateSliderField: Expected array for multiple field "${t}", got ${typeof n}`);return}const d=l.querySelectorAll(`input[type="range"][name^="${t}["]`);d.forEach((c,v)=>{if(v<n.length&&n[v]!==null){const p=Number(n[v]);if(u==="exponential"){const g=G(p,r,i);c.value=(g*1e3).toString()}else c.value=p.toString();const m=c.closest(".slider-container");if(m){const g=m.querySelector(".slider-value");g&&(g.textContent=p.toFixed(s<1?2:0));const h=(p-r)/(i-r)*100;c.style.background=`linear-gradient(
339
+ `;const b=h.closest(".slider-container");b&&b.nextSibling?(E=b.parentNode)==null||E.insertBefore(y,b.nextSibling):b&&((v=b.parentNode)==null||v.appendChild(y))}y.textContent=g,y.style.display="block"}else h.classList.remove("invalid"),h.title="",y&&y.remove()},m=(h,g)=>{const{state:E}=n,v=h.value;if(!v){if(!c&&e.required){const y=$("required",E);return r.push(`${g}: ${y}`),f(h,y),null}return f(h,null),null}let C;if(p==="exponential"){const y=parseFloat(v)/1e3;C=Ee(y,u,d),C=U(C,s)}else C=parseFloat(v),C=U(C,s);if(!c){if(C<u){const y=$("minValue",E,{min:u});return r.push(`${g}: ${y}`),f(h,y),C}if(C>d){const y=$("maxValue",E,{max:d});return r.push(`${g}: ${y}`),f(h,y),C}}return f(h,null),C};if(e.multiple){const h=i.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(h.forEach((E,v)=>{const C=m(E,`${t}[${v}]`);g.push(C)}),!c){const{state:E}=n,v=(a=e.minCount)!=null?a:1,C=(l=e.maxCount)!=null?l:1/0,y=g.filter(b=>b!==null);e.required&&y.length===0&&r.push(`${t}: ${$("required",E)}`),y.length<v&&r.push(`${t}: ${$("minItems",E,{min:v})}`),y.length>C&&r.push(`${t}: ${$("maxItems",E,{max:C})}`)}return{value:g,errors:r}}else{const h=i.querySelector(`input[type="range"][name="${t}"]`);return h?{value:m(h,t),errors:r}:(!c&&e.required&&r.push(`${t}: ${$("required",n.state)}`),{value:null,errors:r})}}function Nt(e,t,n,o){var a;const{scopeRoot:l}=o,r=e.min,i=e.max,c=(a=e.step)!=null?a:1,u=e.scale||"linear";if(e.multiple){if(!Array.isArray(n)){console.warn(`updateSliderField: Expected array for multiple field "${t}", got ${typeof n}`);return}const d=l.querySelectorAll(`input[type="range"][name^="${t}["]`);d.forEach((s,p)=>{if(p<n.length&&n[p]!==null){const f=Number(n[p]);if(u==="exponential"){const h=K(f,r,i);s.value=(h*1e3).toString()}else s.value=f.toString();const m=s.closest(".slider-container");if(m){const h=m.querySelector(".slider-value");h&&(h.textContent=f.toFixed(c<1?2:0));const g=(f-r)/(i-r)*100;s.style.background=`linear-gradient(
312
340
  to right,
313
341
  var(--fb-primary-color) 0%,
314
- var(--fb-primary-color) ${h}%,
315
- var(--fb-border-color) ${h}%,
342
+ var(--fb-primary-color) ${g}%,
343
+ var(--fb-border-color) ${g}%,
316
344
  var(--fb-border-color) 100%
317
- )`}c.classList.remove("invalid"),c.title=""}}),n.length!==d.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${d.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const d=l.querySelector(`input[type="range"][name="${t}"]`);if(d&&n!==null&&n!==void 0){const c=Number(n);if(u==="exponential"){const p=G(c,r,i);d.value=(p*1e3).toString()}else d.value=c.toString();const v=d.closest(".slider-container");if(v){const p=v.querySelector(".slider-value");p&&(p.textContent=c.toFixed(s<1?2:0));const m=(c-r)/(i-r)*100;d.style.background=`linear-gradient(
345
+ )`}s.classList.remove("invalid"),s.title=""}}),n.length!==d.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${d.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const d=l.querySelector(`input[type="range"][name="${t}"]`);if(d&&n!==null&&n!==void 0){const s=Number(n);if(u==="exponential"){const f=K(s,r,i);d.value=(f*1e3).toString()}else d.value=s.toString();const p=d.closest(".slider-container");if(p){const f=p.querySelector(".slider-value");f&&(f.textContent=s.toFixed(c<1?2:0));const m=(s-r)/(i-r)*100;d.style.background=`linear-gradient(
318
346
  to right,
319
347
  var(--fb-primary-color) 0%,
320
348
  var(--fb-primary-color) ${m}%,
321
349
  var(--fb-border-color) ${m}%,
322
350
  var(--fb-border-color) 100%
323
- )`}d.classList.remove("invalid"),d.title=""}}}function be(e){const t={};for(const n of e)"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function xe(e,t){return{...t,...e}}function X(e){const t={};return e.querySelectorAll("input, select, textarea").forEach(n=>{const o=n.getAttribute("name");o&&!o.includes("[")&&!o.includes(".")&&(n instanceof HTMLSelectElement?t[o]=n.value:n instanceof HTMLInputElement?n.type==="checkbox"?t[o]=n.checked:n.type==="radio"?n.checked&&(t[o]=n.value):t[o]=n.value:n instanceof HTMLTextAreaElement&&(t[o]=n.value))}),t}let Z=null;function Ct(e){Z=e}function j(e,t){if(!Z)throw new Error("renderElement not initialized. Import from components/index.ts");return Z(e,t)}function Ce(e,t){if(!e.prefillHints||e.prefillHints.length===0)return null;const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",e.prefillHints.forEach((o,a)=>{const l=document.createElement("button");l.type="button",l.className="fb-prefill-hint",l.textContent=o.label,l.setAttribute("data-hint-values",JSON.stringify(o.values)),l.setAttribute("data-container-key",t),l.setAttribute("data-hint-index",String(a)),n.appendChild(l)}),n}function Ee(e,t,n,o){var a,l;const r=document.createElement("div");r.className="border border-gray-200 rounded-lg p-4 bg-gray-50",r.setAttribute("data-container",o);const i=document.createElement("div"),s=e.columns||1;if(s===1?i.className="space-y-4":i.className=`grid grid-cols-${s} gap-4`,!t.state.config.readonly){const p=Ce(e,o);p&&r.appendChild(p)}const u=be(e.elements),d=((a=t.prefill)==null?void 0:a[e.key])||{},c=xe(d,u),v={path:q(t.path,e.key),prefill:c,formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||i.appendChild(j(p,v))}),r.appendChild(i),n.appendChild(r)}function $e(e,t,n,o){var a,l,r,i;const s=t.state,u=document.createElement("div");u.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const d=document.createElement("span");d.className="text-sm text-gray-500";const c=document.createElement("div");if(c.className="space-y-4",!t.state.config.readonly){const y=Ce(e,e.key);y&&u.appendChild(y)}const v=(a=e.minCount)!=null?a:0,p=(l=e.maxCount)!=null?l:1/0,m=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,g=be(e.elements),h=()=>c.querySelectorAll(":scope > .containerItem").length,E=()=>{const y=document.createElement("button");return y.type="button",y.className="add-container-btn px-3 py-1 rounded",y.style.cssText=`
351
+ )`}d.classList.remove("invalid"),d.title=""}}}function we(e){const t={};for(const n of e)"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function ke(e,t){return{...t,...e}}function Q(e){const t={};return e.querySelectorAll("input, select, textarea").forEach(n=>{const o=n.getAttribute("name");o&&!o.includes("[")&&!o.includes(".")&&(n instanceof HTMLSelectElement?t[o]=n.value:n instanceof HTMLInputElement?n.type==="checkbox"?t[o]=n.checked:n.type==="radio"?n.checked&&(t[o]=n.value):t[o]=n.value:n instanceof HTMLTextAreaElement&&(t[o]=n.value))}),t}let ee=null;function At(e){ee=e}function P(e,t){if(!ee)throw new Error("renderElement not initialized. Import from components/index.ts");return ee(e,t)}function Se(e,t){if(!e.prefillHints||e.prefillHints.length===0)return null;const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",e.prefillHints.forEach((o,a)=>{const l=document.createElement("button");l.type="button",l.className="fb-prefill-hint",l.textContent=o.label,l.setAttribute("data-hint-values",JSON.stringify(o.values)),l.setAttribute("data-container-key",t),l.setAttribute("data-hint-index",String(a)),n.appendChild(l)}),n}function Le(e,t,n,o){var a,l;const r=document.createElement("div");r.className="border border-gray-200 rounded-lg p-4 bg-gray-50",r.setAttribute("data-container",o);const i=document.createElement("div"),c=e.columns||1;if(c===1?i.className="space-y-4":i.className=`grid grid-cols-${c} gap-4`,!t.state.config.readonly){const f=Se(e,o);f&&r.appendChild(f)}const u=we(e.elements),d=((a=t.prefill)==null?void 0:a[e.key])||{},s=ke(d,u),p={path:M(t.path,e.key),prefill:s,formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(f=>{f.hidden||i.appendChild(P(f,p))}),r.appendChild(i),n.appendChild(r)}function Fe(e,t,n,o){var a,l,r,i;const c=t.state,u=document.createElement("div");u.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const d=document.createElement("span");d.className="text-sm text-gray-500";const s=document.createElement("div");if(s.className="space-y-4",!t.state.config.readonly){const y=Se(e,e.key);y&&u.appendChild(y)}const p=(a=e.minCount)!=null?a:0,f=(l=e.maxCount)!=null?l:1/0,m=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,h=we(e.elements),g=()=>s.querySelectorAll(":scope > .containerItem").length,E=()=>{const y=document.createElement("button");return y.type="button",y.className="add-container-btn px-3 py-1 rounded",y.style.cssText=`
324
352
  color: var(--fb-primary-color);
325
353
  border: var(--fb-border-width) solid var(--fb-primary-color);
326
354
  background-color: transparent;
327
355
  font-size: var(--fb-font-size);
328
356
  transition: all var(--fb-transition-duration);
329
- `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{if(h()<p){const b=h(),x=s.formRoot?X(s.formRoot):{},C={state:t.state,path:q(t.path,`${e.key}[${b}]`),prefill:g,formData:x},w=document.createElement("div");w.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",w.setAttribute("data-container-item",`${e.key}[${b}]`);const k=document.createElement("div"),S=e.columns||1;if(S===1?k.className="space-y-4":k.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(F=>{F.hidden||k.appendChild(j(F,C))}),w.appendChild(k),!s.config.readonly){const F=document.createElement("button");F.type="button",F.className="absolute top-2 right-2 px-2 py-1 rounded",F.style.cssText=`
357
+ `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{if(g()<f){const b=g(),x=c.formRoot?Q(c.formRoot):{},w={state:t.state,path:M(t.path,`${e.key}[${b}]`),prefill:h,formData:x},k=document.createElement("div");k.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",k.setAttribute("data-container-item",`${e.key}[${b}]`);const S=document.createElement("div"),F=e.columns||1;if(F===1?S.className="space-y-4":S.className=`grid grid-cols-${F} gap-4`,e.elements.forEach(N=>{N.hidden||S.appendChild(P(N,w))}),k.appendChild(S),!c.config.readonly){const N=document.createElement("button");N.type="button",N.className="absolute top-2 right-2 px-2 py-1 rounded",N.style.cssText=`
330
358
  color: var(--fb-error-color);
331
359
  background-color: transparent;
332
360
  transition: background-color var(--fb-transition-duration);
333
- `,F.textContent="\u2715",F.addEventListener("mouseenter",()=>{F.style.backgroundColor="var(--fb-background-hover-color)"}),F.addEventListener("mouseleave",()=>{F.style.backgroundColor="transparent"}),F.onclick=()=>{w.remove(),f()},w.style.position="relative",w.appendChild(F)}c.appendChild(w),f()}},y},f=()=>{const y=h(),b=u.querySelector(".add-container-btn");b&&(b.disabled=y>=p,b.style.opacity=y>=p?"0.5":"1",b.style.pointerEvents=y>=p?"none":"auto"),d.textContent=`${y}/${p===1/0?"\u221E":p}`};if(m&&Array.isArray(m)&&m.forEach((y,b)=>{var x;const C=xe(y||{},g),w={state:t.state,path:q(t.path,`${e.key}[${b}]`),prefill:C,formData:(x=t.formData)!=null?x:t.prefill},k=document.createElement("div");k.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",k.setAttribute("data-container-item",`${e.key}[${b}]`);const S=document.createElement("div"),F=e.columns||1;if(F===1?S.className="space-y-4":S.className=`grid grid-cols-${F} gap-4`,e.elements.forEach(N=>{N.hidden||S.appendChild(j(N,w))}),k.appendChild(S),!s.config.readonly){const N=document.createElement("button");N.type="button",N.className="absolute top-2 right-2 px-2 py-1 rounded",N.style.cssText=`
361
+ `,N.textContent="\u2715",N.addEventListener("mouseenter",()=>{N.style.backgroundColor="var(--fb-background-hover-color)"}),N.addEventListener("mouseleave",()=>{N.style.backgroundColor="transparent"}),N.onclick=()=>C(k),k.style.position="relative",k.appendChild(N)}s.appendChild(k),v()}},y},v=()=>{const y=g(),b=u.querySelector(".add-container-btn");b&&(b.disabled=y>=f,b.style.opacity=y>=f?"0.5":"1",b.style.pointerEvents=y>=f?"none":"auto"),d.textContent=`${y}/${f===1/0?"\u221E":f}`},C=y=>{y.remove(),v()};if(m&&Array.isArray(m)&&m.forEach((y,b)=>{var x;const w=ke(y||{},h),k={state:t.state,path:M(t.path,`${e.key}[${b}]`),prefill:w,formData:(x=t.formData)!=null?x:t.prefill},S=document.createElement("div");S.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",S.setAttribute("data-container-item",`${e.key}[${b}]`);const F=document.createElement("div"),N=e.columns||1;if(N===1?F.className="space-y-4":F.className=`grid grid-cols-${N} gap-4`,e.elements.forEach(A=>{A.hidden||F.appendChild(P(A,k))}),S.appendChild(F),!c.config.readonly){const A=document.createElement("button");A.type="button",A.className="absolute top-2 right-2 px-2 py-1 rounded",A.style.cssText=`
334
362
  color: var(--fb-error-color);
335
363
  background-color: transparent;
336
364
  transition: background-color var(--fb-transition-duration);
337
- `,N.textContent="\u2715",N.addEventListener("mouseenter",()=>{N.style.backgroundColor="var(--fb-background-hover-color)"}),N.addEventListener("mouseleave",()=>{N.style.backgroundColor="transparent"}),N.onclick=()=>{k.remove(),f()},k.style.position="relative",k.appendChild(N)}c.appendChild(k)}),!s.config.readonly)for(;h()<v;){const y=h(),b={state:t.state,path:q(t.path,`${e.key}[${y}]`),prefill:g,formData:(i=t.formData)!=null?i:t.prefill},x=document.createElement("div");x.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",x.setAttribute("data-container-item",`${e.key}[${y}]`);const C=document.createElement("div"),w=e.columns||1;w===1?C.className="space-y-4":C.className=`grid grid-cols-${w} gap-4`,e.elements.forEach(S=>{S.hidden||C.appendChild(j(S,b))}),x.appendChild(C);const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
365
+ `,A.textContent="\u2715",A.addEventListener("mouseenter",()=>{A.style.backgroundColor="var(--fb-background-hover-color)"}),A.addEventListener("mouseleave",()=>{A.style.backgroundColor="transparent"}),A.onclick=()=>C(S),S.style.position="relative",S.appendChild(A)}s.appendChild(S)}),!c.config.readonly)for(;g()<p;){const y=g(),b={state:t.state,path:M(t.path,`${e.key}[${y}]`),prefill:h,formData:(i=t.formData)!=null?i:t.prefill},x=document.createElement("div");x.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",x.setAttribute("data-container-item",`${e.key}[${y}]`);const w=document.createElement("div"),k=e.columns||1;k===1?w.className="space-y-4":w.className=`grid grid-cols-${k} gap-4`,e.elements.forEach(F=>{F.hidden||w.appendChild(P(F,b))}),x.appendChild(w);const S=document.createElement("button");S.type="button",S.className="absolute top-2 right-2 px-2 py-1 rounded",S.style.cssText=`
338
366
  color: var(--fb-error-color);
339
367
  background-color: transparent;
340
368
  transition: background-color var(--fb-transition-duration);
341
- `,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{h()>v&&(x.remove(),f())},x.style.position="relative",x.appendChild(k),c.appendChild(x)}if(u.appendChild(c),!s.config.readonly){const y=document.createElement("div");y.className="flex items-center gap-3 mt-2",y.appendChild(E()),y.appendChild(d),u.appendChild(y)}f(),n.appendChild(u)}let Q=null;function Et(e){Q=e}function we(e,t,n){if(!Q)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return Q(e,t,n)}function ke(e,t,n){const o=[],{scopeRoot:a,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const i=(s,u,d)=>{var c,v;if(l)return;const{state:p}=n,m="minCount"in d&&(c=d.minCount)!=null?c:0,g="maxCount"in d&&(v=d.maxCount)!=null?v:1/0;d.required&&u.length===0&&o.push(`${s}: ${$("required",p)}`),u.length<m&&o.push(`${s}: ${$("minItems",p,{min:m})}`),u.length>g&&o.push(`${s}: ${$("maxItems",p,{max:g})}`)};if("multiple"in e&&e.multiple){const s=[],u=a.querySelectorAll("[data-container-item]"),d=Array.from(u).filter(c=>{const v=c.getAttribute("data-container-item");return v==null?void 0:v.startsWith(`${t}[`)}).length;for(let c=0;c<d;c++){const v={},p=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(m=>{var g;if(m.enableIf)try{const h=(g=n.instance)!=null&&g.getState().formRoot?X(n.instance.getState().formRoot):{};if(!M(m.enableIf,h,v))return}catch(h){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${c}]":`,h)}if(m.hidden||m.type==="hidden")v[m.key]=m.default!==void 0?m.default:null;else{const h=`${t}[${c}].${m.key}`;v[m.key]=we({...m,key:h},{path:r},p)}}),s.push(v)}return i(t,s,e),{value:s,errors:o}}else{const s={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(d=>{var c;if(d.enableIf)try{const v=(c=n.instance)!=null&&c.getState().formRoot?X(n.instance.getState().formRoot):{};if(!M(d.enableIf,v,s))return}catch(v){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,v)}if(d.hidden||d.type==="hidden")s[d.key]=d.default!==void 0?d.default:null;else{const v=`${t}.${d.key}`;s[d.key]=we({...d,key:v},{path:r},u)}}),{value:s,errors:o}}}function Le(e,t,n,o){const{instance:a,scopeRoot:l}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((i,s)=>{z(i)&&e.elements.forEach(u=>{const d=u.key,c=`${t}[${s}].${d}`,v=i[d];v!==void 0&&a.updateField(c,v)})});const r=l.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==r.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!z(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const i=r.key,s=`${t}.${i}`,u=n[i];u!==void 0&&a.updateField(s,u)})}}function $t(e,t,n,o){var a,l;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const r={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&z(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?$e(r,t,n):Ee(r,t,n,o)}function Se(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&z(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function wt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=Se(e);return ke(o,t,n)}function kt(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=Se(e);return Le(a,t,n,o)}function Lt(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),l=window.innerWidth,r=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const i=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let s=a.left,u=a.bottom+5;s+i.width>l&&(s=a.right-i.width),u+i.height>r&&(u=a.top-i.height-5),s<10&&(s=10),u<10&&(u=a.bottom+5),n.style.left=`${s}px`,n.style.top=`${u}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function St(e,t){var n,o,a;if(!e.enableIf)return!1;try{const l=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((a=e.enableIf.scope)!=null?a:"relative")==="relative"&&t.path?t.prefill:void 0;return!M(e.enableIf,l,r)}catch(l){console.error(`Error evaluating enableIf for field "${e.key}":`,l)}return!1}function Ft(e,t){const n=t.querySelector(`[name="${e}"]`);if(n){if(n instanceof HTMLSelectElement)return n.value;if(n instanceof HTMLInputElement){if(n.type==="checkbox")return n.checked;if(n.type==="radio"){const o=t.querySelector(`[name="${e}"]:checked`);return o?o.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function O(e,t,n){var o,a;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const r=t.enableIf,i=(o=r.scope)!=null?o:"relative";let s={};const u={};if((!n.path||n.path===""?"absolute":i)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const c=d[1],v=parseInt(d[2],10),p=l.querySelector(`[data-container-item="${c}[${v}]"]`);p&&p.querySelectorAll("input, select, textarea").forEach(m=>{const g=m.getAttribute("name");if(g){const h=g.match(/\.([^.[\]]+)$/);if(h){const E=h[1];m instanceof HTMLSelectElement?u[E]=m.value:m instanceof HTMLInputElement?m.type==="checkbox"?u[E]=m.checked:m.type==="radio"?m.checked&&(u[E]=m.value):u[E]=m.value:m instanceof HTMLTextAreaElement&&(u[E]=m.value)}}})}}else{const d=r.key,c=Ft(d,l);c!==void 0?s[d]=c:s=(a=n.formData)!=null?a:n.prefill}try{M(r,s,u)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function Nt(e,t,n){var o;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot setup enableIf listeners: formRoot is null");return}const l=t.enableIf,r=(o=l.scope)!=null?o:"relative",i=l.key;let s;r==="relative"&&n.path?s=`${n.path}.${i}`:s=i;const u=a.querySelector(`[name="${s}"]`);if(!u){const d=new MutationObserver(()=>{const c=a.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{O(e,t,n)}),c.addEventListener("input",()=>{O(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{O(e,t,n)}),u.addEventListener("input",()=>{O(e,t,n)})}function At(e){const t=document.createElement("label");if(t.className="text-sm font-medium text-gray-900",t.textContent=e.label||e.key,e.required){const n=document.createElement("span");n.className="text-red-500 ml-1",n.textContent="*",t.appendChild(n)}return t}function Tt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),Lt(n,t)},t}function qt(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=At(e);if(t.appendChild(n),e.description||e.hint){const o=Tt(e);t.appendChild(o)}return t}function Mt(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Re(e,t,n,o):ze(e,t,n,o);break;case"textarea":a?je(e,t,n,o):De(e,t,n,o);break;case"number":a?Ve(e,t,n,o):Ue(e,t,n,o);break;case"select":a?Ye(e,t,n,o):Je(e,t,n,o);break;case"file":a?pt(e,t,n,o):ut(e,t,n,o);break;case"files":dt(e,t,n,o);break;case"colour":a?mt(e,t,n,o):ft(e,t,n,o);break;case"slider":a?yt(e,t,n,o):gt(e,t,n,o);break;case"group":$t(e,t,n,o);break;case"container":a?$e(e,t,n):Ee(e,t,n,o);break;default:{const l=document.createElement("div");l.className="text-red-500 text-sm",l.textContent=$("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(l)}}}function K(e,t){const n=St(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=qt(e);o.appendChild(a);const l=q(t.path,e.key);return Mt(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Nt(o,e,t),o}Ct(K);const ee={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}"}},theme:{}};function Ht(e){const t={...ee.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...ee.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...ee,...e,translations:t},debounceTimer:null}}function Bt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const I={primaryColor:"#3b82f6",primaryHoverColor:"#2563eb",errorColor:"#ef4444",errorHoverColor:"#dc2626",successColor:"#10b981",borderColor:"#d1d5db",borderHoverColor:"#9ca3af",borderFocusColor:"#3b82f6",backgroundColor:"#ffffff",backgroundHoverColor:"#f9fafb",backgroundReadonlyColor:"#f3f4f6",textColor:"#1f2937",textSecondaryColor:"#6b7280",textPlaceholderColor:"#9ca3af",textDisabledColor:"#d1d5db",buttonBgColor:"#3b82f6",buttonTextColor:"#ffffff",buttonBorderColor:"#2563eb",buttonHoverBgColor:"#2563eb",buttonHoverBorderColor:"#1d4ed8",actionBgColor:"#ffffff",actionTextColor:"#374151",actionBorderColor:"#e5e7eb",actionHoverBgColor:"#f9fafb",actionHoverBorderColor:"#d1d5db",fileUploadBgColor:"#f3f4f6",fileUploadBorderColor:"#d1d5db",fileUploadTextColor:"#9ca3af",fileUploadHoverBorderColor:"#3b82f6",inputPaddingX:"0.75rem",inputPaddingY:"0.5rem",borderRadius:"0.5rem",borderWidth:"1px",fontSize:"0.875rem",fontSizeSmall:"0.75rem",fontSizeExtraSmall:"0.625rem",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeightNormal:"400",fontWeightMedium:"500",focusRingWidth:"2px",focusRingColor:"#3b82f6",focusRingOpacity:"0.5",transitionDuration:"200ms"};function It(e){const t={...I,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const l=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${l}: ${a};`)}),n.join(`
342
- `)}function zt(e,t){const n=It(t);let o=e.querySelector("style[data-fb-theme]");o||(o=document.createElement("style"),o.setAttribute("data-fb-theme","true"),e.appendChild(o)),o.textContent=`
369
+ `,S.textContent="\u2715",S.addEventListener("mouseenter",()=>{S.style.backgroundColor="var(--fb-background-hover-color)"}),S.addEventListener("mouseleave",()=>{S.style.backgroundColor="transparent"}),S.onclick=()=>{g()>p&&C(x)},x.style.position="relative",x.appendChild(S),s.appendChild(x)}if(u.appendChild(s),!c.config.readonly){const y=document.createElement("div");y.className="flex items-center gap-3 mt-2",y.appendChild(E()),y.appendChild(d),u.appendChild(y)}v(),n.appendChild(u)}let te=null;function Tt(e){te=e}function Ne(e,t,n){if(!te)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return te(e,t,n)}function Ae(e,t,n){const o=[],{scopeRoot:a,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const i=(c,u,d)=>{var s,p;if(l)return;const{state:f}=n,m="minCount"in d&&(s=d.minCount)!=null?s:0,h="maxCount"in d&&(p=d.maxCount)!=null?p:1/0;d.required&&u.length===0&&o.push(`${c}: ${$("required",f)}`),u.length<m&&o.push(`${c}: ${$("minItems",f,{min:m})}`),u.length>h&&o.push(`${c}: ${$("maxItems",f,{max:h})}`)};if("multiple"in e&&e.multiple){const c=[],u=a.querySelectorAll("[data-container-item]");return Array.from(u).filter(d=>{const s=d.getAttribute("data-container-item")||"";if(!s.startsWith(`${t}[`))return!1;const p=s.slice(t.length);return/^\[\d+\]$/.test(p)}).forEach(d=>{const s={},p=(d.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),f=p?parseInt(p[1],10):0;e.elements.forEach(m=>{var h;if(m.enableIf)try{const g=(h=n.instance)!=null&&h.getState().formRoot?Q(n.instance.getState().formRoot):{};if(!H(m.enableIf,g,s))return}catch(g){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${f}]":`,g)}if(m.hidden||m.type==="hidden")s[m.key]=m.default!==void 0?m.default:null;else{const g=`${t}[${f}].${m.key}`;s[m.key]=Ne({...m,key:g},{path:r},d)}}),c.push(s)}),i(t,c,e),{value:c,errors:o}}else{const c={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(d=>{var s;if(d.enableIf)try{const p=(s=n.instance)!=null&&s.getState().formRoot?Q(n.instance.getState().formRoot):{};if(!H(d.enableIf,p,c))return}catch(p){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,p)}if(d.hidden||d.type==="hidden")c[d.key]=d.default!==void 0?d.default:null;else{const p=`${t}.${d.key}`;c[d.key]=Ne({...d,key:p},{path:r},u)}}),{value:c,errors:o}}}function Te(e,t,n,o){const{instance:a,scopeRoot:l}=o;if("elements"in e)if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateContainerField: Expected array for multiple container field "${t}", got ${typeof n}`);return}n.forEach((i,c)=>{R(i)&&e.elements.forEach(u=>{const d=u.key,s=`${t}[${c}].${d}`,p=i[d];p!==void 0&&a.updateField(s,p)})});const r=l.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==r.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!R(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const i=r.key,c=`${t}.${i}`,u=n[i];u!==void 0&&a.updateField(c,u)})}}function qt(e,t,n,o){var a,l;typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated and will be removed in a future version. Please use type: "container" with multiple: true instead. Field key: "${e.key}"`);const r={key:e.key,label:e.label,description:e.description,hint:e.hint,required:e.required,hidden:e.hidden,default:e.default,actions:e.actions,elements:e.elements,multiple:!!(e.repeat&&R(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?Fe(r,t,n):Le(r,t,n,o)}function qe(e){var t,n;const o=e;return{type:"container",key:o.key,label:o.label,description:o.description,hint:o.hint,required:o.required,hidden:o.hidden,default:o.default,actions:o.actions,elements:o.elements,multiple:!!(o.repeat&&R(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function Mt(e,t,n){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field key: "${t}"`);const o=qe(e);return Ae(o,t,n)}function Ht(e,t,n,o){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const a=qe(e);return Te(a,t,n,o)}function Bt(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),l=window.innerWidth,r=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const i=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let c=a.left,u=a.bottom+5;c+i.width>l&&(c=a.right-i.width),u+i.height>r&&(u=a.top-i.height-5),c<10&&(c=10),u<10&&(u=a.bottom+5),n.style.left=`${c}px`,n.style.top=`${u}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function zt(e,t){var n,o,a;if(!e.enableIf)return!1;try{const l=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((a=e.enableIf.scope)!=null?a:"relative")==="relative"&&t.path?t.prefill:void 0;return!H(e.enableIf,l,r)}catch(l){console.error(`Error evaluating enableIf for field "${e.key}":`,l)}return!1}function It(e,t){const n=t.querySelector(`[name="${e}"]`);if(n){if(n instanceof HTMLSelectElement)return n.value;if(n instanceof HTMLInputElement){if(n.type==="checkbox")return n.checked;if(n.type==="radio"){const o=t.querySelector(`[name="${e}"]:checked`);return o?o.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function V(e,t,n){var o,a;if(!t.enableIf)return;const l=n.state.formRoot;if(!l){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const r=t.enableIf,i=(o=r.scope)!=null?o:"relative";let c={};const u={};if((!n.path||n.path===""?"absolute":i)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const s=d[1],p=parseInt(d[2],10),f=l.querySelector(`[data-container-item="${s}[${p}]"]`);f&&f.querySelectorAll("input, select, textarea").forEach(m=>{const h=m.getAttribute("name");if(h){const g=h.match(/\.([^.[\]]+)$/);if(g){const E=g[1];m instanceof HTMLSelectElement?u[E]=m.value:m instanceof HTMLInputElement?m.type==="checkbox"?u[E]=m.checked:m.type==="radio"?m.checked&&(u[E]=m.value):u[E]=m.value:m instanceof HTMLTextAreaElement&&(u[E]=m.value)}}})}}else{const d=r.key,s=It(d,l);s!==void 0?c[d]=s:c=(a=n.formData)!=null?a:n.prefill}try{H(r,c,u)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function Rt(e,t,n){var o;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot setup enableIf listeners: formRoot is null");return}const l=t.enableIf,r=(o=l.scope)!=null?o:"relative",i=l.key;let c;r==="relative"&&n.path?c=`${n.path}.${i}`:c=i;const u=a.querySelector(`[name="${c}"]`);if(!u){const d=new MutationObserver(()=>{const s=a.querySelector(`[name="${c}"]`);s&&(s.addEventListener("change",()=>{V(e,t,n)}),s.addEventListener("input",()=>{V(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{V(e,t,n)}),u.addEventListener("input",()=>{V(e,t,n)})}function Dt(e){const t=document.createElement("label");if(t.className="text-sm font-medium text-gray-900",t.textContent=e.label||e.key,e.required){const n=document.createElement("span");n.className="text-red-500 ml-1",n.textContent="*",t.appendChild(n)}return t}function jt(e){const t=document.createElement("button");t.type="button",t.className="ml-2 text-gray-400 hover:text-gray-600",t.innerHTML='<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>';const n=`tooltip-${e.key}-${Math.random().toString(36).substr(2,9)}`,o=document.createElement("div");return o.id=n,o.className="hidden absolute z-50 bg-gray-200 text-gray-900 text-sm rounded-lg p-3 max-w-sm border border-gray-300 shadow-lg",o.style.position="fixed",o.textContent=e.description||e.hint||"Field information",document.body.appendChild(o),t.onclick=a=>{a.preventDefault(),a.stopPropagation(),Bt(n,t)},t}function Ot(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Dt(e);if(t.appendChild(n),e.description||e.hint){const o=jt(e);t.appendChild(o)}return t}function Ut(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Pe(e,t,n,o):Ue(e,t,n,o);break;case"textarea":a?We(e,t,n,o):Ve(e,t,n,o);break;case"number":a?Ge(e,t,n,o):Ye(e,t,n,o);break;case"select":a?Qe(e,t,n,o):Ke(e,t,n,o);break;case"switcher":a?rt(e,t,n,o):nt(e,t,n,o);break;case"file":a?Ct(e,t,n,o):bt(e,t,n,o);break;case"files":xt(e,t,n,o);break;case"colour":a?$t(e,t,n,o):Et(e,t,n,o);break;case"slider":a?Lt(e,t,n,o):St(e,t,n,o);break;case"group":qt(e,t,n,o);break;case"container":a?Fe(e,t,n):Le(e,t,n,o);break;default:{const l=document.createElement("div");l.className="text-red-500 text-sm",l.textContent=$("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(l)}}}function ne(e,t){const n=zt(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=Ot(e);o.appendChild(a);const l=M(t.path,e.key);return Ut(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),Rt(o,e,t),o}At(ne);const re={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}",invalidOption:"Invalid option"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}",invalidOption:"\u041D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435"}},theme:{}};function Pt(e){const t={...re.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...re.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...re,...e,translations:t},debounceTimer:null}}function Vt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const I={primaryColor:"#3b82f6",primaryHoverColor:"#2563eb",errorColor:"#ef4444",errorHoverColor:"#dc2626",successColor:"#10b981",borderColor:"#d1d5db",borderHoverColor:"#9ca3af",borderFocusColor:"#3b82f6",backgroundColor:"#ffffff",backgroundHoverColor:"#f9fafb",backgroundReadonlyColor:"#f3f4f6",textColor:"#1f2937",textSecondaryColor:"#6b7280",textPlaceholderColor:"#9ca3af",textDisabledColor:"#d1d5db",buttonBgColor:"#3b82f6",buttonTextColor:"#ffffff",buttonBorderColor:"#2563eb",buttonHoverBgColor:"#2563eb",buttonHoverBorderColor:"#1d4ed8",actionBgColor:"#ffffff",actionTextColor:"#374151",actionBorderColor:"#e5e7eb",actionHoverBgColor:"#f9fafb",actionHoverBorderColor:"#d1d5db",fileUploadBgColor:"#f3f4f6",fileUploadBorderColor:"#d1d5db",fileUploadTextColor:"#9ca3af",fileUploadHoverBorderColor:"#3b82f6",inputPaddingX:"0.75rem",inputPaddingY:"0.5rem",borderRadius:"0.5rem",borderWidth:"1px",fontSize:"0.875rem",fontSizeSmall:"0.75rem",fontSizeExtraSmall:"0.625rem",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeightNormal:"400",fontWeightMedium:"500",focusRingWidth:"2px",focusRingColor:"#3b82f6",focusRingOpacity:"0.5",transitionDuration:"200ms"};function Wt(e){const t={...I,...e},n=[];return Object.entries(t).forEach(([o,a])=>{const l=o.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${l}: ${a};`)}),n.join(`
370
+ `)}function _t(e,t){const n=Wt(t);let o=e.querySelector("style[data-fb-theme]");o||(o=document.createElement("style"),o.setAttribute("data-fb-theme","true"),e.appendChild(o)),o.textContent=`
343
371
  [data-fb-root="true"] {
344
372
  ${n}
345
373
  }
346
- `}const Rt={default:I,dark:{...I,primaryColor:"#60a5fa",primaryHoverColor:"#3b82f6",borderColor:"#4b5563",borderHoverColor:"#6b7280",borderFocusColor:"#60a5fa",backgroundColor:"#1f2937",backgroundHoverColor:"#374151",backgroundReadonlyColor:"#111827",textColor:"#f9fafb",textSecondaryColor:"#9ca3af",textPlaceholderColor:"#6b7280",fileUploadBgColor:"#374151",fileUploadBorderColor:"#4b5563",fileUploadTextColor:"#9ca3af"},klein:{...I,primaryColor:"#0066cc",primaryHoverColor:"#0052a3",errorColor:"#d32f2f",errorHoverColor:"#c62828",successColor:"#388e3c",borderColor:"#e0e0e0",borderHoverColor:"#bdbdbd",borderFocusColor:"#0066cc",borderRadius:"4px",fontSize:"16px",fontSizeSmall:"14px",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif'}};function Fe(e,t=!1){e.style.cssText=`
374
+ `}const Jt={default:I,dark:{...I,primaryColor:"#60a5fa",primaryHoverColor:"#3b82f6",borderColor:"#4b5563",borderHoverColor:"#6b7280",borderFocusColor:"#60a5fa",backgroundColor:"#1f2937",backgroundHoverColor:"#374151",backgroundReadonlyColor:"#111827",textColor:"#f9fafb",textSecondaryColor:"#9ca3af",textPlaceholderColor:"#6b7280",fileUploadBgColor:"#374151",fileUploadBorderColor:"#4b5563",fileUploadTextColor:"#9ca3af"},klein:{...I,primaryColor:"#0066cc",primaryHoverColor:"#0052a3",errorColor:"#d32f2f",errorHoverColor:"#c62828",successColor:"#388e3c",borderColor:"#e0e0e0",borderHoverColor:"#bdbdbd",borderFocusColor:"#0066cc",borderRadius:"4px",fontSize:"16px",fontSizeSmall:"14px",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif'}};function Me(e,t=!1){e.style.cssText=`
347
375
  background-color: var(--fb-action-bg-color);
348
376
  color: var(--fb-action-text-color);
349
377
  border: var(--fb-border-width) solid var(--fb-action-border-color);
@@ -353,6 +381,6 @@ ${n}
353
381
  border-radius: var(--fb-border-radius);
354
382
  transition: all var(--fb-transition-duration);
355
383
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
356
- `,e.addEventListener("mouseenter",()=>{e.style.backgroundColor="var(--fb-action-hover-bg-color)",e.style.borderColor="var(--fb-action-hover-border-color)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="var(--fb-action-bg-color)",e.style.borderColor="var(--fb-action-border-color)"})}const Dt={text:{validate:te,update:ne},textarea:{validate:Oe,update:Pe},number:{validate:_e,update:We},select:{validate:Ge,update:Xe},file:{validate:pe,update:fe},files:{validate:pe,update:fe},colour:{validate:vt,update:ht},slider:{validate:bt,update:xt},container:{validate:ke,update:Le},group:{validate:wt,update:kt}};function Ne(e){return Dt[e]||null}function jt(e,t,n){const o=Ne(e.type);return o&&o.validate?o.validate(e,t,n):null}function Ot(e,t,n,o){const a=Ne(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class P{constructor(t){this.instanceId=Bt(),this.state=Ht(t),this.state.config.verboseErrors&&(globalThis.__formBuilderInstances||(globalThis.__formBuilderInstances=new Set),globalThis.__formBuilderInstances.add(this.instanceId),globalThis.__formBuilderInstances.size>10&&console.warn(`[form-builder] ${globalThis.__formBuilderInstances.size} instances active. Possible memory leak - ensure you call destroy() when done.`))}getInstanceId(){return this.instanceId}getState(){return this.state}setFormRoot(t){this.state.formRoot=t}configure(t){Object.assign(this.state.config,t)}setUploadHandler(t){this.state.config.uploadFile=t}setDownloadHandler(t){this.state.config.downloadFile=t}setThumbnailHandler(t){this.state.config.getThumbnail=t}setActionHandler(t){this.state.config.actionHandler=t}setMode(t){this.state.config.readonly=t==="readonly"}setLocale(t){this.state.config.translations[t]&&(this.state.config.locale=t)}triggerOnChange(t,n){this.state.config.readonly||(this.state.debounceTimer!==null&&clearTimeout(this.state.debounceTimer),this.state.debounceTimer=setTimeout(()=>{const o=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(o),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,o),this.state.debounceTimer=null},this.state.config.debounceMs))}registerAction(t){if(!t||!t.value)throw new Error("Action must have a value property");this.state.externalActions||(this.state.externalActions=[]);const n=this.state.externalActions.findIndex(o=>o.value===t.value&&o.related_field===t.related_field);n>=0?this.state.externalActions[n]=t:this.state.externalActions.push(t)}findFormElementByFieldPath(t){if(!this.state.formRoot)return null;if(!this.state.config.readonly){let a=this.state.formRoot.querySelector(`[name="${t}"]`);if(a)return a;const l=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const r of l)if(a=this.state.formRoot.querySelector(`[name="${r}"]`),a)return a}const n=this.findSchemaElement(t);if(!n)return null;const o=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const a of o){const l=n.label||n.key,r=a.querySelector("label");if(r&&(r.textContent===l||r.textContent===`${l}*`)){let i=a.querySelector(".field-placeholder");return i||(i=document.createElement("div"),i.className="field-placeholder",i.style.display="none",a.appendChild(i)),i}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,o=null;const a=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const l of a){if(o=n.find(r=>r.key===l)||null,!o)return null;"elements"in o&&o.elements&&(n=o.elements)}return o}resolveActionLabel(t,n,o,a=!1){if(o&&"actions"in o&&o.actions){const l=o.actions.find(r=>r.key===t);if(l&&l.label)return l.label}if(a&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const l=this.state.schema.actions.find(r=>r.key===t);if(l&&l.label)return l.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const o=this.state.formRoot.querySelector(".form-level-actions-container");o&&o.remove();const a=document.createElement("div");a.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",a.style.cssText=`
384
+ `,e.addEventListener("mouseenter",()=>{e.style.backgroundColor="var(--fb-action-hover-bg-color)",e.style.borderColor="var(--fb-action-hover-border-color)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="var(--fb-action-bg-color)",e.style.borderColor="var(--fb-action-border-color)"})}const Yt={text:{validate:oe,update:le},textarea:{validate:_e,update:Je},number:{validate:Xe,update:Ze},select:{validate:et,update:tt},switcher:{validate:ot,update:lt},file:{validate:ge,update:ye},files:{validate:ge,update:ye},colour:{validate:wt,update:kt},slider:{validate:Ft,update:Nt},container:{validate:Ae,update:Te},group:{validate:Mt,update:Ht}};function He(e){return Yt[e]||null}function Gt(e,t,n){const o=He(e.type);return o&&o.validate?o.validate(e,t,n):null}function Xt(e,t,n,o){const a=He(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class W{constructor(t){this.instanceId=Vt(),this.state=Pt(t),this.state.config.verboseErrors&&(globalThis.__formBuilderInstances||(globalThis.__formBuilderInstances=new Set),globalThis.__formBuilderInstances.add(this.instanceId),globalThis.__formBuilderInstances.size>10&&console.warn(`[form-builder] ${globalThis.__formBuilderInstances.size} instances active. Possible memory leak - ensure you call destroy() when done.`))}getInstanceId(){return this.instanceId}getState(){return this.state}setFormRoot(t){this.state.formRoot=t}configure(t){Object.assign(this.state.config,t)}setUploadHandler(t){this.state.config.uploadFile=t}setDownloadHandler(t){this.state.config.downloadFile=t}setThumbnailHandler(t){this.state.config.getThumbnail=t}setActionHandler(t){this.state.config.actionHandler=t}setMode(t){this.state.config.readonly=t==="readonly"}setLocale(t){this.state.config.translations[t]&&(this.state.config.locale=t)}triggerOnChange(t,n){this.state.config.readonly||(this.state.debounceTimer!==null&&clearTimeout(this.state.debounceTimer),this.state.debounceTimer=setTimeout(()=>{const o=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(o),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,o),this.state.debounceTimer=null},this.state.config.debounceMs))}registerAction(t){if(!t||!t.value)throw new Error("Action must have a value property");this.state.externalActions||(this.state.externalActions=[]);const n=this.state.externalActions.findIndex(o=>o.value===t.value&&o.related_field===t.related_field);n>=0?this.state.externalActions[n]=t:this.state.externalActions.push(t)}findFormElementByFieldPath(t){if(!this.state.formRoot)return null;if(!this.state.config.readonly){let a=this.state.formRoot.querySelector(`[name="${t}"]`);if(a)return a;const l=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const r of l)if(a=this.state.formRoot.querySelector(`[name="${r}"]`),a)return a}const n=this.findSchemaElement(t);if(!n)return null;const o=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const a of o){const l=n.label||n.key,r=a.querySelector("label");if(r&&(r.textContent===l||r.textContent===`${l}*`)){let i=a.querySelector(".field-placeholder");return i||(i=document.createElement("div"),i.className="field-placeholder",i.style.display="none",a.appendChild(i)),i}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,o=null;const a=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const l of a){if(o=n.find(r=>r.key===l)||null,!o)return null;"elements"in o&&o.elements&&(n=o.elements)}return o}resolveActionLabel(t,n,o,a=!1){if(o&&"actions"in o&&o.actions){const l=o.actions.find(r=>r.key===t);if(l&&l.label)return l.label}if(a&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const l=this.state.schema.actions.find(r=>r.key===t);if(l&&l.label)return l.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const o=this.state.formRoot.querySelector(".form-level-actions-container");o&&o.remove();const a=document.createElement("div");a.className="form-level-actions-container mt-6 pt-4 flex flex-wrap gap-3 justify-center",a.style.cssText=`
357
385
  border-top: var(--fb-border-width) solid var(--fb-border-color);
358
- `,t.forEach(l=>{const r=document.createElement("button");r.type="button",Fe(r,!0);const i=n.includes(l),s=this.resolveActionLabel(l.key,l.label,null,i);r.textContent=s,r.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(l.value,l.key,null)}),a.appendChild(r)}),this.state.formRoot.appendChild(a)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(l=>{!l.key||!l.value||(l.related_field?(t.has(l.related_field)||t.set(l.related_field,[]),t.get(l.related_field).push(l)):n.push(l))}),t.forEach((l,r)=>{const i=this.findFormElementByFieldPath(r);if(!i){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let s=i.closest(".fb-field-wrapper");if(s||(s=i.parentElement),!s){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const u=s.querySelector(".external-actions-container");u&&u.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(r);l.forEach(v=>{const p=document.createElement("button");p.type="button",Fe(p,!1);const m=this.resolveActionLabel(v.key,v.label,c);p.textContent=m,p.addEventListener("click",g=>{g.preventDefault(),g.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(v.value,v.key,v.related_field)}),d.appendChild(p)}),s.appendChild(d)});const a=[...n,...o];a.length>0&&this.renderFormLevelActions(a,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const o=n.getAttribute("data-hint-values"),a=n.getAttribute("data-root-hint")==="true",l=n.getAttribute("data-container-key");if(!o||!a&&!l){console.warn("Prefill hint missing required data attributes");return}try{const r=JSON.parse(o);for(const i in r){const s=a?i:`${l}.${i}`,u=r[i];this.updateField(s,u)}}catch(r){console.error("Error parsing prefill hint values:",r)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",t.forEach(o=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",o.icon?a.textContent=`${o.icon} ${o.label}`:a.textContent=o.label,a.setAttribute("data-hint-values",JSON.stringify(o.values)),a.setAttribute("data-root-hint","true"),n.appendChild(a)}),n}renderForm(t,n,o,a){const l=U(n);if(l.length>0){console.error("Schema validation errors:",l);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=a||null,B(t),t.setAttribute("data-fb-root","true"),zt(t,this.state.config.theme);const r=document.createElement("div");if(r.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const u=this.createRootPrefillHints(n.prefillHints);r.appendChild(u)}const i=document.createElement("div"),s=n.columns||1;s===1?i.className="space-y-4":i.className=`grid grid-cols-${s} gap-4`,n.elements.forEach(u=>{if(u.hidden)return;const d=K(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});i.appendChild(d)}),r.appendChild(i),t.appendChild(r),this.state.config.readonly||t.addEventListener("click",this.handlePrefillHintClick.bind(this)),this.state.config.readonly&&this.state.externalActions&&Array.isArray(this.state.externalActions)&&this.renderExternalActions()}validateForm(t=!1){if(!this.state.schema||!this.state.formRoot)return{valid:!0,errors:[],data:{}};const n=[],o={},a=(l,r,i=null)=>{const s=l.key,u={scopeRoot:i||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},d=jt(l,s,u);return d!==null?(n.push(...d.errors),d.value):(console.warn(`Unknown field type "${l.type}" for key "${s}"`),null)};return Et(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!M(l.enableIf,o))return}catch(r){console.error(`Error evaluating enableIf for field "${l.key}" during validation:`,r)}l.hidden?o[l.key]=l.default!==void 0?l.default:null:o[l.key]=a(l,{path:""})}),{valid:n.length===0,errors:n,data:o}}getFormData(){return this.validateForm(!1)}submitForm(){const t=this.validateForm(!1);return t.valid&&typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formSubmit",data:t.data,schema:this.state.schema},"*"),t}saveDraft(){const t=this.validateForm(!0);return typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formDraft",data:t.data,schema:this.state.schema},"*"),t}clearForm(){if(!this.state.schema||!this.state.formRoot){console.warn("clearForm: Form not initialized. Call renderForm() first.");return}const t=this.state.schema,n=this.state.formRoot,o=this.state.externalActions,a=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,a,o||void 0)}buildHiddenFieldsData(t){const n={};for(const o of t){const a=o.key;if(o.hidden&&o.default!==void 0&&(n[a]=o.default),o.type==="container"||o.type==="group"){const l=o,r=this.buildHiddenFieldsData(l.elements);Object.keys(r).length>0&&(a in n?typeof n[a]=="object"&&n[a]!==null&&!Array.isArray(n[a])&&(n[a]={...n[a],...r}):n[a]=r)}}return n}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}for(const n in t)this.updateField(n,t[n])}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const o=this.findSchemaElement(t);if(!o){console.warn(`updateField: Schema element not found for path "${t}"`);return}const a=this.findFormElementByFieldPath(t);if(!a){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(a,o,t,n),this.reevaluateConditionalFields(),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,o,a){const l={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};Ot(n,o,a,l)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${o}"`)}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(o,a)=>{o.forEach(l=>{var r,i,s;const u=a?`${a}.${l.key}`:l.key;if(l.enableIf){let d=null;if(a){const c=a.match(/^(.+)\[(\d+)\]$/);if(c){const v=c[1],p=c[2],m=this.state.formRoot.querySelector(`[data-container-item="${v}[${p}]"]`);m&&(d=m.querySelector(`[data-field-key="${l.key}"]`))}else{const v=this.state.formRoot.querySelector(`[data-container="${a}"]`);v&&(d=v.querySelector(`[data-field-key="${l.key}"]`))}}else d=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(d){const c=d;try{let v;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(v=V(t,a));const p=M(l.enableIf,t,v),m=c.getAttribute("data-conditionally-disabled")==="true";if(p&&m){const g=a?V(t,a):t,h=K(l,{path:a,prefill:g&&typeof g=="object"?g:{},formData:t,state:this.state,instance:this});(i=c.parentNode)==null||i.replaceChild(h,c)}else if(!p&&!m){const g=document.createElement("div");g.className="fb-field-wrapper-disabled",g.style.display="none",g.setAttribute("data-field-key",l.key),g.setAttribute("data-conditionally-disabled","true"),(s=c.parentNode)==null||s.replaceChild(g,c)}}catch(v){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${u}":`,v)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const d=t==null?void 0:t[l.key];Array.isArray(d)?d.forEach((c,v)=>{n(l.elements,`${u}[${v}]`)}):n(l.elements,u)}})};n(this.state.schema.elements,"")}destroy(){var t;this.state.debounceTimer!==null&&(clearTimeout(this.state.debounceTimer),this.state.debounceTimer=null),this.state.resourceIndex.clear(),this.state.formRoot&&B(this.state.formRoot),this.state.formRoot=null,this.state.schema=null,this.state.externalActions=null,this.state.config.verboseErrors&&((t=globalThis.__formBuilderInstances)==null||t.delete(this.instanceId))}}function Ae(e){return new P(e)}return typeof window!="undefined"&&(window.FormBuilder=P,window.createFormBuilder=Ae,window.validateSchema=U),T.FormBuilderInstance=P,T.createFormBuilder=Ae,T.default=P,T.defaultTheme=I,T.exampleThemes=Rt,T.validateSchema=U,Object.defineProperty(T,"__esModule",{value:!0}),T})({});
386
+ `,t.forEach(l=>{const r=document.createElement("button");r.type="button",Me(r,!0);const i=n.includes(l),c=this.resolveActionLabel(l.key,l.label,null,i);r.textContent=c,r.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(l.value,l.key,null)}),a.appendChild(r)}),this.state.formRoot.appendChild(a)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(l=>{!l.key||!l.value||(l.related_field?(t.has(l.related_field)||t.set(l.related_field,[]),t.get(l.related_field).push(l)):n.push(l))}),t.forEach((l,r)=>{const i=this.findFormElementByFieldPath(r);if(!i){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let c=i.closest(".fb-field-wrapper");if(c||(c=i.parentElement),!c){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const u=c.querySelector(".external-actions-container");u&&u.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const s=this.findSchemaElement(r);l.forEach(p=>{const f=document.createElement("button");f.type="button",Me(f,!1);const m=this.resolveActionLabel(p.key,p.label,s);f.textContent=m,f.addEventListener("click",h=>{h.preventDefault(),h.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(p.value,p.key,p.related_field)}),d.appendChild(f)}),c.appendChild(d)});const a=[...n,...o];a.length>0&&this.renderFormLevelActions(a,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const o=n.getAttribute("data-hint-values"),a=n.getAttribute("data-root-hint")==="true",l=n.getAttribute("data-container-key");if(!o||!a&&!l){console.warn("Prefill hint missing required data attributes");return}try{const r=JSON.parse(o);for(const i in r){const c=a?i:`${l}.${i}`,u=r[i];this.updateField(c,u)}}catch(r){console.error("Error parsing prefill hint values:",r)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",t.forEach(o=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",o.icon?a.textContent=`${o.icon} ${o.label}`:a.textContent=o.label,a.setAttribute("data-hint-values",JSON.stringify(o.values)),a.setAttribute("data-root-hint","true"),n.appendChild(a)}),n}renderForm(t,n,o,a){const l=_(n);if(l.length>0){console.error("Schema validation errors:",l);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=a||null,z(t),t.setAttribute("data-fb-root","true"),_t(t,this.state.config.theme);const r=document.createElement("div");if(r.className="space-y-6",n.prefillHints&&!this.state.config.readonly){const u=this.createRootPrefillHints(n.prefillHints);r.appendChild(u)}const i=document.createElement("div"),c=n.columns||1;c===1?i.className="space-y-4":i.className=`grid grid-cols-${c} gap-4`,n.elements.forEach(u=>{if(u.hidden)return;const d=ne(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});i.appendChild(d)}),r.appendChild(i),t.appendChild(r),this.state.config.readonly||t.addEventListener("click",this.handlePrefillHintClick.bind(this)),this.state.config.readonly&&this.state.externalActions&&Array.isArray(this.state.externalActions)&&this.renderExternalActions()}validateForm(t=!1){if(!this.state.schema||!this.state.formRoot)return{valid:!0,errors:[],data:{}};const n=[],o={},a=(l,r,i=null)=>{const c=l.key,u={scopeRoot:i||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},d=Gt(l,c,u);return d!==null?(n.push(...d.errors),d.value):(console.warn(`Unknown field type "${l.type}" for key "${c}"`),null)};return Tt(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!H(l.enableIf,o))return}catch(r){console.error(`Error evaluating enableIf for field "${l.key}" during validation:`,r)}l.hidden?o[l.key]=l.default!==void 0?l.default:null:o[l.key]=a(l,{path:""})}),{valid:n.length===0,errors:n,data:o}}getFormData(){return this.validateForm(!1)}submitForm(){const t=this.validateForm(!1);return t.valid&&typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formSubmit",data:t.data,schema:this.state.schema},"*"),t}saveDraft(){const t=this.validateForm(!0);return typeof window!="undefined"&&window.parent&&window.parent.postMessage({type:"formDraft",data:t.data,schema:this.state.schema},"*"),t}clearForm(){if(!this.state.schema||!this.state.formRoot){console.warn("clearForm: Form not initialized. Call renderForm() first.");return}const t=this.state.schema,n=this.state.formRoot,o=this.state.externalActions,a=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,a,o||void 0)}buildHiddenFieldsData(t){const n={};for(const o of t){const a=o.key;if(o.hidden&&o.default!==void 0&&(n[a]=o.default),o.type==="container"||o.type==="group"){const l=o,r=this.buildHiddenFieldsData(l.elements);Object.keys(r).length>0&&(a in n?typeof n[a]=="object"&&n[a]!==null&&!Array.isArray(n[a])&&(n[a]={...n[a],...r}):n[a]=r)}}return n}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}for(const n in t)this.updateField(n,t[n])}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const o=this.findSchemaElement(t);if(!o){console.warn(`updateField: Schema element not found for path "${t}"`);return}const a=this.findFormElementByFieldPath(t);if(!a){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(a,o,t,n),this.reevaluateConditionalFields(),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,o,a){const l={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};Xt(n,o,a,l)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${o}"`)}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(o,a)=>{o.forEach(l=>{var r,i,c;const u=a?`${a}.${l.key}`:l.key;if(l.enableIf){let d=null;if(a){const s=a.match(/^(.+)\[(\d+)\]$/);if(s){const p=s[1],f=s[2],m=this.state.formRoot.querySelector(`[data-container-item="${p}[${f}]"]`);m&&(d=m.querySelector(`[data-field-key="${l.key}"]`))}else{const p=this.state.formRoot.querySelector(`[data-container="${a}"]`);p&&(d=p.querySelector(`[data-field-key="${l.key}"]`))}}else d=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(d){const s=d;try{let p;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(p=J(t,a));const f=H(l.enableIf,t,p),m=s.getAttribute("data-conditionally-disabled")==="true";if(f&&m){const h=a?J(t,a):t,g=ne(l,{path:a,prefill:h&&typeof h=="object"?h:{},formData:t,state:this.state,instance:this});(i=s.parentNode)==null||i.replaceChild(g,s)}else if(!f&&!m){const h=document.createElement("div");h.className="fb-field-wrapper-disabled",h.style.display="none",h.setAttribute("data-field-key",l.key),h.setAttribute("data-conditionally-disabled","true"),(c=s.parentNode)==null||c.replaceChild(h,s)}}catch(p){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${u}":`,p)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const d=t==null?void 0:t[l.key];if(Array.isArray(d)){const s=this.state.formRoot.querySelectorAll("[data-container-item]");Array.from(s).filter(p=>{const f=p.getAttribute("data-container-item")||"";if(!f.startsWith(`${u}[`))return!1;const m=f.slice(u.length);return/^\[\d+\]$/.test(m)}).forEach(p=>{const f=p.getAttribute("data-container-item")||"";n(l.elements,f)})}else n(l.elements,u)}})};n(this.state.schema.elements,"")}destroy(){var t;this.state.debounceTimer!==null&&(clearTimeout(this.state.debounceTimer),this.state.debounceTimer=null),this.state.resourceIndex.clear(),this.state.formRoot&&z(this.state.formRoot),this.state.formRoot=null,this.state.schema=null,this.state.externalActions=null,this.state.config.verboseErrors&&((t=globalThis.__formBuilderInstances)==null||t.delete(this.instanceId))}}function Be(e){return new W(e)}return typeof window!="undefined"&&(window.FormBuilder=W,window.createFormBuilder=Be,window.validateSchema=_),q.FormBuilderInstance=W,q.createFormBuilder=Be,q.default=W,q.defaultTheme=I,q.exampleThemes=Jt,q.validateSchema=_,Object.defineProperty(q,"__esModule",{value:!0}),q})({});