@dmitryvim/form-builder 0.2.14 → 0.2.15

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.
@@ -19,7 +19,7 @@ var FormBuilder=(function(N){"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=I(e,r,!1);l.appendChild(i)}n.appendChild(l)}function He(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,p=(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 h(){c.querySelectorAll(".multiple-text-item").forEach((d,b)=>{const y=d.querySelector("input");y&&(y.name=`${o}[${b}]`)})}function m(d="",b=-1){const y=document.createElement("div");y.className="multiple-text-item flex items-center gap-2";const C=document.createElement("div");C.style.cssText="position: relative; flex: 1;";const x=document.createElement("input");if(x.type="text",x.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 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=I(e,r,!1);l.appendChild(i)}n.appendChild(l)}function He(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,p=(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 h(){c.querySelectorAll(".multiple-text-item").forEach((d,y)=>{const b=d.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function f(d="",y=-1){const b=document.createElement("div");b.className="multiple-text-item flex items-center gap-2";const C=document.createElement("div");C.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(N){"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
- `,x.placeholder=e.placeholder||$("placeholderText",r),x.value=d,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 S=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=I(e,x,!1);C.appendChild(w)}return y.appendChild(C),b===-1?c.appendChild(y):c.insertBefore(y,c.children[b]),h(),y}function f(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-text-item"),b=d.length;d.forEach(y=>{let C=y.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=`
34
+ `,x.placeholder=e.placeholder||$("placeholderText",r),x.value=d,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 S=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=I(e,x,!1);C.appendChild(w)}return b.appendChild(C),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),h(),b}function m(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-text-item"),y=d.length;d.forEach(b=>{let C=b.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=`
35
35
  color: var(--fb-error-color);
36
36
  background-color: transparent;
37
37
  transition: background-color var(--fb-transition-duration);
38
- `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const w=Array.from(c.children).indexOf(y);c.children.length>u&&(s.splice(w,1),y.remove(),h(),E(),f())},y.appendChild(C));const x=b<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-text-btn px-3 py-1 rounded",d.style.cssText=`
38
+ `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),h(),E(),m())},b.appendChild(C));const x=y<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-text-btn px-3 py-1 rounded",d.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
- `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-text-btn");if(d){const b=s.length>=p;d.disabled=b,d.style.opacity=b?"0.5":"1",d.style.pointerEvents=b?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>m(d)),E(),f()}function K(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var m,f;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
44
+ `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-text-btn");if(d){const y=s.length>=p;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>f(d)),E(),m()}function K(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var f,m;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,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?(m=c.parentNode)==null||m.insertBefore(g,c.nextSibling):(f=c.parentNode)==null||f.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},p=(c,h,m)=>{let f=!1;const{state:v}=n;if(!s&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength){const g=$("minLength",v,{min:e.minLength});r.push(`${m}: ${g}`),u(c,g),f=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength){const g=$("maxLength",v,{max:e.maxLength});r.push(`${m}: ${g}`),u(c,g),f=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(h)){const g=$("patternMismatch",v);r.push(`${m}: ${g}`),u(c,g),f=!0}}catch(g){const E=$("invalidPattern",v);r.push(`${m}: ${E}`),u(c,E),f=!0}}f||u(c,null)};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["]`),h=[],m=[];if(c.forEach((f,v)=>{var g;const E=(g=f==null?void 0:f.value)!=null?g:"";m.push(E),h.push(E===""?null:E),p(f,E,`${t}[${v}]`)}),!s){const{state:f}=n,v=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,E=m.filter(d=>d.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${$("required",f)}`),E.length<v&&r.push(`${t}: ${$("minItems",f,{min:v})}`),E.length>g&&r.push(`${t}: ${$("maxItems",f,{max:g})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name$="${t}"]`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const m=$("required",n.state);return r.push(`${t}: ${m}`),u(c,m),{value:null,errors:r}}return c&&p(c,h,t),{value:h===""?null:h,errors:r}}}function ee(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 Be(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=I(e,r,!0);l.appendChild(i)}n.appendChild(l)}function ze(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,p=(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 h(){c.querySelectorAll(".multiple-textarea-item").forEach((d,b)=>{const y=d.querySelector("textarea");y&&(y.name=`${o}[${b}]`)})}function m(d="",b=-1){const y=document.createElement("div");y.className="multiple-textarea-item";const C=document.createElement("div");C.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=d,x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const S=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=I(e,x,!0);C.appendChild(w)}return y.appendChild(C),b===-1?c.appendChild(y):c.insertBefore(y,c.children[b]),h(),y}function f(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-textarea-item"),b=d.length;d.forEach(y=>{let C=y.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",C.innerHTML="\u2715",C.onclick=()=>{const w=Array.from(c.children).indexOf(y);c.children.length>u&&(s.splice(w,1),y.remove(),h(),E(),f())},y.appendChild(C));const x=b<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-textarea-btn px-3 py-1 rounded",d.style.cssText=`
48
+ `,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(g,c.nextSibling):(m=c.parentNode)==null||m.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},p=(c,h,f)=>{let m=!1;const{state:v}=n;if(!s&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength){const g=$("minLength",v,{min:e.minLength});r.push(`${f}: ${g}`),u(c,g),m=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength){const g=$("maxLength",v,{max:e.maxLength});r.push(`${f}: ${g}`),u(c,g),m=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(h)){const g=$("patternMismatch",v);r.push(`${f}: ${g}`),u(c,g),m=!0}}catch(g){const E=$("invalidPattern",v);r.push(`${f}: ${E}`),u(c,E),m=!0}}m||u(c,null)};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["]`),h=[],f=[];if(c.forEach((m,v)=>{var g;const E=(g=m==null?void 0:m.value)!=null?g:"";f.push(E),h.push(E===""?null:E),p(m,E,`${t}[${v}]`)}),!s){const{state:m}=n,v=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,E=f.filter(d=>d.trim()!=="");e.required&&E.length===0&&r.push(`${t}: ${$("required",m)}`),E.length<v&&r.push(`${t}: ${$("minItems",m,{min:v})}`),E.length>g&&r.push(`${t}: ${$("maxItems",m,{max:g})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name$="${t}"]`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const f=$("required",n.state);return r.push(`${t}: ${f}`),u(c,f),{value:null,errors:r}}return c&&p(c,h,t),{value:h===""?null:h,errors:r}}}function ee(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 Be(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=I(e,r,!0);l.appendChild(i)}n.appendChild(l)}function ze(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,p=(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 h(){c.querySelectorAll(".multiple-textarea-item").forEach((d,y)=>{const b=d.querySelector("textarea");b&&(b.name=`${o}[${y}]`)})}function f(d="",y=-1){const b=document.createElement("div");b.className="multiple-textarea-item";const C=document.createElement("div");C.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=d,x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const S=x.value===""?null:x.value;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const w=I(e,x,!0);C.appendChild(w)}return b.appendChild(C),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),h(),b}function m(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-textarea-item"),y=d.length;d.forEach(b=>{let C=b.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",C.innerHTML="\u2715",C.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),h(),E(),m())},b.appendChild(C));const x=y<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-textarea-btn px-3 py-1 rounded",d.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
- `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-textarea-btn");if(d){const b=s.length>=p;d.disabled=b,d.style.opacity=b?"0.5":"1",d.style.pointerEvents=b?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>m(d)),E(),f()}function Ie(e,t,n){return K(e,t,n)}function Re(e,t,n,o){ee(e,t,n,o)}function te(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
54
+ `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-textarea-btn");if(d){const y=s.length>=p;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>f(d)),E(),m()}function Ie(e,t,n){return K(e,t,n)}function Re(e,t,n,o){ee(e,t,n,o)}function te(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,30 +61,29 @@ var FormBuilder=(function(N){"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 De(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=te(e,r);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,p=(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 h(){c.querySelectorAll(".multiple-number-item").forEach((d,b)=>{const y=d.querySelector("input");y&&(y.name=`${o}[${b}]`)})}function m(d="",b=-1){const y=document.createElement("div");y.className="multiple-number-item flex items-center gap-2";const C=document.createElement("div");C.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=d.toString(),x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const S=x.value?parseFloat(x.value):null;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.min!=null||e.max!=null)){const w=te(e,x);C.appendChild(w)}return y.appendChild(C),b===-1?c.appendChild(y):c.insertBefore(y,c.children[b]),h(),y}function f(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-number-item"),b=d.length;d.forEach(y=>{let C=y.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",C.innerHTML="\u2715",C.onclick=()=>{const w=Array.from(c.children).indexOf(y);c.children.length>u&&(s.splice(w,1),y.remove(),h(),E(),f())},y.appendChild(C));const x=b<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-number-btn px-3 py-1 rounded",d.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 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 De(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=te(e,r);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,p=(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 h(){c.querySelectorAll(".multiple-number-item").forEach((d,y)=>{const b=d.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function f(d="",y=-1){const b=document.createElement("div");b.className="multiple-number-item flex items-center gap-2";const C=document.createElement("div");C.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=d.toString(),x.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const w=()=>{const S=x.value?parseFloat(x.value):null;t.instance.triggerOnChange(x.name,S)};x.addEventListener("blur",w),x.addEventListener("input",w)}if(C.appendChild(x),!r.config.readonly&&(e.min!=null||e.max!=null)){const w=te(e,x);C.appendChild(w)}return b.appendChild(C),y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),h(),b}function m(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-number-item"),y=d.length;d.forEach(b=>{let C=b.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",C.innerHTML="\u2715",C.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),h(),E(),m())},b.appendChild(C));const x=y<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-number-btn px-3 py-1 rounded",d.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
- `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),m(e.default||""),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-number-btn");if(d){const b=s.length>=p;d.disabled=b,d.style.opacity=b?"0.5":"1",d.style.pointerEvents=b?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>m(d)),E(),f()}function Oe(e,t,n){var o,a,l,r,i;const s=[],{scopeRoot:u,skipValidation:p}=n,c=(m,f)=>{var v,g;if(!m)return;const E=`error-${m.getAttribute("name")||Math.random().toString(36).substring(7)}`;let d=document.getElementById(E);f?(m.classList.add("invalid"),m.title=f,d||(d=document.createElement("div"),d.id=E,d.className="error-message",d.style.cssText=`
70
+ `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{s.push(e.default||""),f(e.default||""),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-number-btn");if(d){const y=s.length>=p;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}s.forEach(d=>f(d)),E(),m()}function Oe(e,t,n){var o,a,l,r,i;const s=[],{scopeRoot:u,skipValidation:p}=n,c=(f,m)=>{var v,g;if(!f)return;const E=`error-${f.getAttribute("name")||Math.random().toString(36).substring(7)}`;let d=document.getElementById(E);m?(f.classList.add("invalid"),f.title=m,d||(d=document.createElement("div"),d.id=E,d.className="error-message",d.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
- `,m.nextSibling?(v=m.parentNode)==null||v.insertBefore(d,m.nextSibling):(g=m.parentNode)==null||g.appendChild(d)),d.textContent=f,d.style.display="block"):(m.classList.remove("invalid"),m.title="",d&&d.remove())},h=(m,f,v)=>{let g=!1;const{state:E}=n;if(!p&&e.min!==void 0&&e.min!==null&&f<e.min){const d=$("minValue",E,{min:e.min});s.push(`${v}: ${d}`),c(m,d),g=!0}else if(!p&&e.max!==void 0&&e.max!==null&&f>e.max){const d=$("maxValue",E,{max:e.max});s.push(`${v}: ${d}`),c(m,d),g=!0}g||c(m,null)};if(e.multiple){const m=u.querySelectorAll(`[name^="${t}["]`),f=[];if(m.forEach((v,g)=>{var E,d,b;const y=(E=v==null?void 0:v.value)!=null?E:"";if(y===""){f.push(null),c(v,null);return}const C=parseFloat(y);if(!p&&!Number.isFinite(C)){const w=$("notANumber",n.state);s.push(`${t}[${g}]: ${w}`),c(v,w),f.push(null);return}h(v,C,`${t}[${g}]`);const x=Number.isInteger((d=e.decimals)!=null?d:0)&&(b=e.decimals)!=null?b:0;f.push(Number(C.toFixed(x)))}),!p){const{state:v}=n,g=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,d=f.filter(b=>b!==null);e.required&&d.length===0&&s.push(`${t}: ${$("required",v)}`),d.length<g&&s.push(`${t}: ${$("minItems",v,{min:g})}`),d.length>E&&s.push(`${t}: ${$("maxItems",v,{max:E})}`)}return{value:f,errors:s}}else{const m=u.querySelector(`[name$="${t}"]`),f=(l=m==null?void 0:m.value)!=null?l:"",{state:v}=n;if(!p&&e.required&&f===""){const d=$("required",v);return s.push(`${t}: ${d}`),c(m,d),{value:null,errors:s}}if(f==="")return c(m,null),{value:null,errors:s};const g=parseFloat(f);if(!p&&!Number.isFinite(g)){const d=$("notANumber",v);return s.push(`${t}: ${d}`),c(m,d),{value:null,errors:s}}h(m,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:s}}}function Ue(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 Pe(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=F(e,a),n.appendChild(r)}}function Ve(e,t,n,o){var a,l,r,i;const s=t.state,u=t.prefill[e.key]||[],p=Array.isArray(u)?[...u]:[],c=(a=e.minCount)!=null?a:1,h=(l=e.maxCount)!=null?l:1/0;for(;p.length<c;)p.push(e.default||((i=(r=e.options)==null?void 0:r[0])==null?void 0:i.value)||"");const m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function f(){m.querySelectorAll(".multiple-select-item").forEach((y,C)=>{const x=y.querySelector("select");x&&(x.name=`${o}[${C}]`)})}function v(y="",C=-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=s.config.readonly,(e.options||[]).forEach(S=>{const k=document.createElement("option");k.value=S.value,k.textContent=S.label,y===S.value&&(k.selected=!0),w.appendChild(k)}),!s.config.readonly&&t.instance){const S=()=>{t.instance.triggerOnChange(w.name,w.value)};w.addEventListener("change",S)}return x.appendChild(w),C===-1?m.appendChild(x):m.insertBefore(x,m.children[C]),f(),x}function g(){if(s.config.readonly)return;const y=m.querySelectorAll(".multiple-select-item"),C=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 k=Array.from(m.children).indexOf(x);m.children.length>c&&(p.splice(k,1),x.remove(),f(),b(),g())},x.appendChild(w));const S=C<=c;w.disabled=S,w.style.opacity=S?"0.5":"1",w.style.pointerEvents=S?"none":"auto"})}let E=null,d=null;if(!s.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=`
74
+ `,f.nextSibling?(v=f.parentNode)==null||v.insertBefore(d,f.nextSibling):(g=f.parentNode)==null||g.appendChild(d)),d.textContent=m,d.style.display="block"):(f.classList.remove("invalid"),f.title="",d&&d.remove())},h=(f,m,v)=>{let g=!1;const{state:E}=n;if(!p&&e.min!==void 0&&e.min!==null&&m<e.min){const d=$("minValue",E,{min:e.min});s.push(`${v}: ${d}`),c(f,d),g=!0}else if(!p&&e.max!==void 0&&e.max!==null&&m>e.max){const d=$("maxValue",E,{max:e.max});s.push(`${v}: ${d}`),c(f,d),g=!0}g||c(f,null)};if(e.multiple){const f=u.querySelectorAll(`[name^="${t}["]`),m=[];if(f.forEach((v,g)=>{var E,d,y;const b=(E=v==null?void 0:v.value)!=null?E:"";if(b===""){m.push(null),c(v,null);return}const C=parseFloat(b);if(!p&&!Number.isFinite(C)){const w=$("notANumber",n.state);s.push(`${t}[${g}]: ${w}`),c(v,w),m.push(null);return}h(v,C,`${t}[${g}]`);const x=Number.isInteger((d=e.decimals)!=null?d:0)&&(y=e.decimals)!=null?y:0;m.push(Number(C.toFixed(x)))}),!p){const{state:v}=n,g=(o=e.minCount)!=null?o:1,E=(a=e.maxCount)!=null?a:1/0,d=m.filter(y=>y!==null);e.required&&d.length===0&&s.push(`${t}: ${$("required",v)}`),d.length<g&&s.push(`${t}: ${$("minItems",v,{min:g})}`),d.length>E&&s.push(`${t}: ${$("maxItems",v,{max:E})}`)}return{value:m,errors:s}}else{const f=u.querySelector(`[name$="${t}"]`),m=(l=f==null?void 0:f.value)!=null?l:"",{state:v}=n;if(!p&&e.required&&m===""){const d=$("required",v);return s.push(`${t}: ${d}`),c(f,d),{value:null,errors:s}}if(m==="")return c(f,null),{value:null,errors:s};const g=parseFloat(m);if(!p&&!Number.isFinite(g)){const d=$("notANumber",v);return s.push(`${t}: ${d}`),c(f,d),{value:null,errors:s}}h(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:s}}}function Ue(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 Pe(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=F(e,a),n.appendChild(r)}}function Ve(e,t,n,o){var a,l,r,i;const s=t.state,u=t.prefill[e.key]||[],p=Array.isArray(u)?[...u]:[],c=(a=e.minCount)!=null?a:1,h=(l=e.maxCount)!=null?l:1/0;for(;p.length<c;)p.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((b,C)=>{const x=b.querySelector("select");x&&(x.name=`${o}[${C}]`)})}function v(b="",C=-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=s.config.readonly,(e.options||[]).forEach(S=>{const k=document.createElement("option");k.value=S.value,k.textContent=S.label,b===S.value&&(k.selected=!0),w.appendChild(k)}),!s.config.readonly&&t.instance){const S=()=>{t.instance.triggerOnChange(w.name,w.value)};w.addEventListener("change",S)}return x.appendChild(w),C===-1?f.appendChild(x):f.insertBefore(x,f.children[C]),m(),x}function g(){if(s.config.readonly)return;const b=f.querySelectorAll(".multiple-select-item"),C=b.length;b.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 k=Array.from(f.children).indexOf(x);f.children.length>c&&(p.splice(k,1),x.remove(),m(),y(),g())},x.appendChild(w));const S=C<=c;w.disabled=S,w.style.opacity=S?"0.5":"1",w.style.pointerEvents=S?"none":"auto"})}let E=null,d=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=`
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
- `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{var C,x;const w=e.default||((x=(C=e.options)==null?void 0:C[0])==null?void 0:x.value)||"";p.push(w),v(w),b(),g()},d=document.createElement("span"),d.className="text-sm text-gray-500",E.appendChild(y),E.appendChild(d),n.appendChild(E)}function b(){if(!E||!d)return;const y=E.querySelector(".add-select-btn");if(y){const C=p.length>=h;y.disabled=C,y.style.opacity=C?"0.5":"1",y.style.pointerEvents=C?"none":"auto"}d.textContent=`${p.length}/${h===1/0?"\u221E":h}`}if(p.forEach(y=>v(y)),b(),g(),!s.config.readonly){const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=F(e,s),n.appendChild(y)}}function _e(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(u,p)=>{var c,h;if(!u)return;const m=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(m);p?(u.classList.add("invalid"),u.title=p,f||(f=document.createElement("div"),f.id=m,f.className="error-message",f.style.cssText=`
80
+ `,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{var C,x;const w=e.default||((x=(C=e.options)==null?void 0:C[0])==null?void 0:x.value)||"";p.push(w),v(w),y(),g()},d=document.createElement("span"),d.className="text-sm text-gray-500",E.appendChild(b),E.appendChild(d),n.appendChild(E)}function y(){if(!E||!d)return;const b=E.querySelector(".add-select-btn");if(b){const C=p.length>=h;b.disabled=C,b.style.opacity=C?"0.5":"1",b.style.pointerEvents=C?"none":"auto"}d.textContent=`${p.length}/${h===1/0?"\u221E":h}`}if(p.forEach(b=>v(b)),y(),g(),!s.config.readonly){const b=document.createElement("p");b.className="text-xs text-gray-500 mt-1",b.textContent=F(e,s),n.appendChild(b)}}function _e(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,i=(u,p)=>{var c,h;if(!u)return;const f=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(f);p?(u.classList.add("invalid"),u.title=p,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(f,u.nextSibling):(h=u.parentNode)==null||h.appendChild(f)),f.textContent=p,f.style.display="block"):(u.classList.remove("invalid"),u.title="",f&&f.remove())},s=(u,p,c,h)=>{var m,f;if(r)return;const{state:v}=n,g=p.filter(h),E="minCount"in c&&(m=c.minCount)!=null?m:1,d="maxCount"in c&&(f=c.maxCount)!=null?f:1/0;c.required&&g.length===0&&a.push(`${u}: ${$("required",v)}`),g.length<E&&a.push(`${u}: ${$("minItems",v,{min:E})}`),g.length>d&&a.push(`${u}: ${$("maxItems",v,{max:d})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),p=[];return u.forEach(c=>{var h;const m=(h=c==null?void 0:c.value)!=null?h:"";p.push(m),i(c,null)}),s(t,p,e,c=>c!==""),{value:p,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),p=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&p===""){const c=$("required",n.state);return a.push(`${t}: ${c}`),i(u,c),{value:null,errors:a}}else i(u,null);return{value:p===""?null:p,errors:a}}}function We(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 Je(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 Ye(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?(c=u.parentNode)==null||c.insertBefore(m,u.nextSibling):(h=u.parentNode)==null||h.appendChild(m)),m.textContent=p,m.style.display="block"):(u.classList.remove("invalid"),u.title="",m&&m.remove())},s=(u,p,c,h)=>{var f,m;if(r)return;const{state:v}=n,g=p.filter(h),E="minCount"in c&&(f=c.minCount)!=null?f:1,d="maxCount"in c&&(m=c.maxCount)!=null?m:1/0;c.required&&g.length===0&&a.push(`${u}: ${$("required",v)}`),g.length<E&&a.push(`${u}: ${$("minItems",v,{min:E})}`),g.length>d&&a.push(`${u}: ${$("maxItems",v,{max:d})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),p=[];return u.forEach(c=>{var h;const f=(h=c==null?void 0:c.value)!=null?h:"";p.push(f),i(c,null)}),s(t,p,e,c=>c!==""),{value:p,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),p=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&p===""){const c=$("required",n.state);return a.push(`${t}: ${c}`),i(u,c),{value:null,errors:a}}else i(u,null);return{value:p===""?null:p,errors:a}}}function We(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 Je(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 Ye(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
85
  <div class="relative group h-full">
86
- <video class="w-full h-full object-contain" controls preload="auto" muted>
87
- <source src="${r}" type="${n}">
86
+ <video class="w-full h-full object-contain" controls preload="auto" muted src="${r}">
88
87
  ${L($("videoNotSupported",a))}
89
88
  </video>
90
89
  <div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
@@ -103,7 +102,7 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
103
102
  </svg>
104
103
  <div class="text-sm text-center">${L($("clickDragText",n))}</div>
105
104
  </div>
106
- `}function Ze(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;const l=document.createElement("source");l.src=t,l.type=n,a.appendChild(l),a.appendChild(document.createTextNode($("videoNotSupported",o))),e.appendChild(a)}function Qe(e,t,n){nt(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=`
105
+ `}function Ze(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 Qe(e,t,n){nt(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=`
107
106
  <div class="flex flex-col items-center justify-center h-full text-gray-400">
108
107
  <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
109
108
  <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"/>
@@ -117,10 +116,9 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
117
116
  </svg>
118
117
  <div class="text-sm text-center">${L(n||$("previewUnavailable",a))}</div>
119
118
  </div>
120
- `}}async function ne(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}");M(e),l&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await Ke(e,i,a,t,l,n,r):await et(e,t,a,i,n)}async function P(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 p=!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(p)if(t.config.getThumbnail)try{const f=await t.config.getThumbnail(e);f?u.innerHTML=`<img src="${f}" 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(f){console.warn("getThumbnail failed for",e,f),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 f=await t.config.getThumbnail(e);f?u.innerHTML=`
119
+ `}}async function ne(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}");M(e),l&&e.classList.add("cursor-pointer");const i=n.resourceIndex.get(t);i&&i.file&&i.file instanceof File?await Ke(e,i,a,t,l,n,r):await et(e,t,a,i,n)}async function P(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 p=!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(p)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=`
121
120
  <div class="relative group">
122
- <video class="w-full h-auto" controls preload="auto" muted>
123
- <source src="${f}" type="${(l==null?void 0:l.type)||"video/mp4"}">
121
+ <video class="w-full h-auto" controls preload="auto" muted src="${m}">
124
122
  ${L($("videoNotSupported",t))}
125
123
  </video>
126
124
  <div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
@@ -131,18 +129,18 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
131
129
  </div>
132
130
  </div>
133
131
  </div>
134
- `: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(f){console.warn("getThumbnail failed for video",e,f),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 f=i?"\u{1F3A8}":"\u{1F4C1}",v=i?"PSD File":"Document";i?u.innerHTML=`
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}",v=i?"PSD File":"Document";i?u.innerHTML=`
135
133
  <div class="flex items-center space-x-3">
136
- <div class="text-3xl text-gray-400">${f}</div>
134
+ <div class="text-3xl text-gray-400">${m}</div>
137
135
  <div class="flex-1 min-w-0">
138
136
  <div class="text-sm font-medium text-gray-900 truncate">${L(r)}</div>
139
137
  <div class="text-xs text-gray-500">${v}</div>
140
138
  </div>
141
139
  </div>
142
- `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${f}</div><div class="text-sm">${L(r)}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const h=document.createElement("p");h.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",h.textContent=r;const m=document.createElement("button");return m.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",m.textContent=$("downloadButton",t),m.onclick=f=>{f.preventDefault(),f.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):rt(e,r,t)},s.appendChild(u),s.appendChild(h),s.appendChild(m),s}function re(e,t,n,o,a,l){M(e);const r=()=>{const h=[$("clickDragTextMultiple",n)];return a&&h.push(a),l&&h.push(l),h.join(" \u2022 ")},i=!e.classList.contains("grid");if((!t||t.length===0)&&i){const h=document.createElement("div");h.className="grid grid-cols-4 gap-3 mb-3";for(let f=0;f<4;f++){const v=document.createElement("div");v.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),v.appendChild(g),v.onclick=()=>{let d=e.parentElement;for(;d&&!d.classList.contains("space-y-2");)d=d.parentElement;!d&&e.classList.contains("space-y-2")&&(d=e);const b=d==null?void 0:d.querySelector('input[type="file"]');b&&b.click()},h.appendChild(v)}const m=document.createElement("div");m.className="text-center text-xs text-gray-500 mt-2",m.textContent=r(),e.appendChild(h),e.appendChild(m);return}const s=document.createElement("div");s.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,p=(Math.floor(u/4)+1)*4;for(let h=0;h<p;h++){const m=document.createElement("div");if(t&&h<t.length){const f=t[h],v=n.resourceIndex.get(f);if(m.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",m.dataset.resourceId=f,tt(m,f,v,n).catch(g=>{console.error("Failed to render thumbnail:",g),m.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
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">${v}</div></div></div>`}const h=document.createElement("p");h.className=i?"hidden":"text-sm font-medium text-gray-900 text-center",h.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):rt(e,r,t)},s.appendChild(u),s.appendChild(h),s.appendChild(f),s}function re(e,t,n,o,a,l){M(e);const r=()=>{const h=[$("clickDragTextMultiple",n)];return a&&h.push(a),l&&h.push(l),h.join(" \u2022 ")},i=!e.classList.contains("grid");if((!t||t.length===0)&&i){const h=document.createElement("div");h.className="grid grid-cols-4 gap-3 mb-3";for(let m=0;m<4;m++){const v=document.createElement("div");v.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),v.appendChild(g),v.onclick=()=>{let d=e.parentElement;for(;d&&!d.classList.contains("space-y-2");)d=d.parentElement;!d&&e.classList.contains("space-y-2")&&(d=e);const y=d==null?void 0:d.querySelector('input[type="file"]');y&&y.click()},h.appendChild(v)}const f=document.createElement("div");f.className="text-center text-xs text-gray-500 mt-2",f.textContent=r(),e.appendChild(h),e.appendChild(f);return}const s=document.createElement("div");s.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,p=(Math.floor(u/4)+1)*4;for(let h=0;h<p;h++){const f=document.createElement("div");if(t&&h<t.length){const m=t[h],v=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,tt(f,m,v,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">
143
141
  <div class="text-2xl mb-1">\u{1F4C1}</div>
144
142
  <div class="text-xs">${L($("previewError",n))}</div>
145
- </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=d=>{d.stopPropagation(),o(f)},g.appendChild(E),m.appendChild(g)}}else m.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",m.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>',m.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 v=f==null?void 0:f.querySelector('input[type="file"]');v&&v.click()};s.appendChild(m)}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 oe(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
143
+ </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=d=>{d.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 v=m==null?void 0:m.querySelector('input[type="file"]');v&&v.click()};s.appendChild(f)}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 oe(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
146
144
  <svg class="${L(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
147
145
  <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"/>
148
146
  </svg>
@@ -157,8 +155,7 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
157
155
  </svg>
158
156
  </div>`;else if(n&&(l=n.type)!=null&&l.startsWith("video/"))if(n.file&&n.file instanceof File){const r=URL.createObjectURL(n.file);e.innerHTML=`
159
157
  <div class="relative group h-full w-full">
160
- <video class="w-full h-full object-contain" preload="metadata" muted>
161
- <source src="${r}" type="${n.type}">
158
+ <video class="w-full h-full object-contain" preload="metadata" muted src="${r}">
162
159
  </video>
163
160
  <div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
164
161
  <div class="bg-white bg-opacity-90 rounded-full p-1">
@@ -170,8 +167,7 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
170
167
  </div>
171
168
  `}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);r?e.innerHTML=`
172
169
  <div class="relative group h-full w-full">
173
- <video class="w-full h-full object-contain" preload="metadata" muted>
174
- <source src="${r}" type="${n.type}">
170
+ <video class="w-full h-full object-contain" preload="metadata" muted src="${r}">
175
171
  </video>
176
172
  <div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
177
173
  <div class="bg-white bg-opacity-90 rounded-full p-1">
@@ -202,7 +198,7 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
202
198
  <div class="text-sm text-center">${L($("clickDragText",t))}</div>
203
199
  ${o}
204
200
  </div>
205
- `}async function le(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(p){const c=p instanceof Error?p:new Error(String(p));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,ne(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,s)}function _(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 nt(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 ae(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 rt(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();ot(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 ot(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 ie(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 lt(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 p="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?p=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(p=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}ne(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 se(e,t,n,o,a,l){_(e,async r=>{const i=Array.from(r);for(const s of i){const u=await ae(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 ce(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await ae(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 at(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)P(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(h=>`.${h}`).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],p=()=>i.click(),c=h=>{if(h.length>0){const m={picker:i,fileUploadHandler:p,dragHandler:c};le(h[0],s,o,l,m,t.instance)}};if(u)lt(u,s,o,r,l,{picker:i,fileUploadHandler:p,dragHandler:c});else{const h=F(e,l);V(s,l,h)}s.onclick=p,_(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const h={picker:i,fileUploadHandler:p,dragHandler:c};le(i.files[0],s,o,l,h,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function it(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=>{P(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(){re(p,c,l,m=>{const f=c.indexOf(m);f>-1&&c.splice(f,1),r()},h)};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(m=>`.${m}`).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 p=document.createElement("div");p.className="files-list";const c=t.prefill[e.key]||[];ie(c,l);const h=F(e,l);r(),se(u,c,l,r,o,t.instance),ce(s,c,l,r,o,t.instance),u.appendChild(p),i.appendChild(u),i.appendChild(s),n.appendChild(i)}}function st(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 p=document.createElement("div");p.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(h=>{P(h,i).then(m=>{p.appendChild(m)}).catch(m=>{console.error("Failed to render file preview:",m)})}):p.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(p)}else{const p=document.createElement("div");p.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 h=document.createElement("div");h.className="files-list space-y-2",p.appendChild(c),p.appendChild(h);const m=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];ie(m,i);const f=F(e,i),v=()=>{const E=m.length===1?$("fileCountSingle",i,{count:m.length}):$("fileCountPlural",i,{count:m.length}),d=s>0||u<1/0?` ${$("fileCountRange",i,{min:s,max:u})}`:"";return E+d},g=()=>{re(h,m,i,E=>{m.splice(m.indexOf(E),1),g()},f,v())};se(h,m,i,g,o,t.instance),ce(c,m,i,g,o,t.instance),g(),n.appendChild(p)}}function ue(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,u=(p,c,h)=>{var m,f;if(r)return;const{state:v}=n,g="minCount"in h&&(m=h.minCount)!=null?m:0,E="maxCount"in h&&(f=h.maxCount)!=null?f:1/0;h.required&&c.length===0&&a.push(`${p}: ${$("required",v)}`),c.length<g&&a.push(`${p}: ${$("minFiles",v,{min:g})}`),c.length>E&&a.push(`${p}: ${$("maxFiles",v,{max:E})}`)};if(s){const p=A(i,t),c=l.querySelector(`input[type="file"][name="${p}"]`),h=c==null?void 0:c.closest(".space-y-2"),m=(h==null?void 0:h.querySelector(".files-list"))||null,f=[];return m&&m.querySelectorAll(".resource-pill").forEach(v=>{const g=v.dataset.resourceId;g&&f.push(g)}),u(t,f,e),{value:f,errors:a}}else{const p=l.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=p==null?void 0:p.value)!=null?o:"";return!r&&e.required&&c===""?(a.push(`${t}: ${$("required",n.state)}`),{value:null,errors:a}):{value:c||null,errors:a}}}function de(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",p=(s=u.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";p&&(["jpg","jpeg","png","gif","webp"].includes(p)?c=`image/${p==="jpg"?"jpeg":p}`:["mp4","webm","mov","avi"].includes(p)&&(c=`video/${p==="mov"?"quicktime":p}`)),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 p="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?p=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(p=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function q(e){return e?e.toUpperCase():"#000000"}function W(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function pe(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 me(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=q(e),o=document.createElement("div");o.style.cssText=`
201
+ `}async function le(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(p){const c=p instanceof Error?p:new Error(String(p));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,ne(t,s,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,s)}function _(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 nt(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 ae(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 rt(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();ot(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 ot(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 ie(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 lt(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 p="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?p=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(p=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}ne(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 se(e,t,n,o,a,l){_(e,async r=>{const i=Array.from(r);for(const s of i){const u=await ae(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 ce(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const i=await ae(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 at(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)P(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(h=>`.${h}`).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],p=()=>i.click(),c=h=>{if(h.length>0){const f={picker:i,fileUploadHandler:p,dragHandler:c};le(h[0],s,o,l,f,t.instance)}};if(u)lt(u,s,o,r,l,{picker:i,fileUploadHandler:p,dragHandler:c});else{const h=F(e,l);V(s,l,h)}s.onclick=p,_(s,c),i.onchange=()=>{if(i.files&&i.files.length>0){const h={picker:i,fileUploadHandler:p,dragHandler:c};le(i.files[0],s,o,l,h,t.instance)}},r.appendChild(s),r.appendChild(i),n.appendChild(r)}}function it(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=>{P(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(){re(p,c,l,f=>{const m=c.indexOf(f);m>-1&&c.splice(m,1),r()},h)};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(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 p=document.createElement("div");p.className="files-list";const c=t.prefill[e.key]||[];ie(c,l);const h=F(e,l);r(),se(u,c,l,r,o,t.instance),ce(s,c,l,r,o,t.instance),u.appendChild(p),i.appendChild(u),i.appendChild(s),n.appendChild(i)}}function st(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 p=document.createElement("div");p.className="space-y-4";const c=t.prefill[e.key]||[];c.length>0?c.forEach(h=>{P(h,i).then(f=>{p.appendChild(f)}).catch(f=>{console.error("Failed to render file preview:",f)})}):p.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(p)}else{const p=document.createElement("div");p.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 h=document.createElement("div");h.className="files-list space-y-2",p.appendChild(c),p.appendChild(h);const f=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];ie(f,i);const m=F(e,i),v=()=>{const E=f.length===1?$("fileCountSingle",i,{count:f.length}):$("fileCountPlural",i,{count:f.length}),d=s>0||u<1/0?` ${$("fileCountRange",i,{min:s,max:u})}`:"";return E+d},g=()=>{re(h,f,i,E=>{f.splice(f.indexOf(E),1),g()},m,v())};se(h,f,i,g,o,t.instance),ce(c,f,i,g,o,t.instance),g(),n.appendChild(p)}}function ue(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:i}=n,s=e.type==="files"||"multiple"in e&&!!e.multiple,u=(p,c,h)=>{var f,m;if(r)return;const{state:v}=n,g="minCount"in h&&(f=h.minCount)!=null?f:0,E="maxCount"in h&&(m=h.maxCount)!=null?m:1/0;h.required&&c.length===0&&a.push(`${p}: ${$("required",v)}`),c.length<g&&a.push(`${p}: ${$("minFiles",v,{min:g})}`),c.length>E&&a.push(`${p}: ${$("maxFiles",v,{max:E})}`)};if(s){const p=A(i,t),c=l.querySelector(`input[type="file"][name="${p}"]`),h=c==null?void 0:c.closest(".space-y-2"),f=(h==null?void 0:h.querySelector(".files-list"))||null,m=[];return f&&f.querySelectorAll(".resource-pill").forEach(v=>{const g=v.dataset.resourceId;g&&m.push(g)}),u(t,m,e),{value:m,errors:a}}else{const p=l.querySelector(`input[name$="${t}"][type="hidden"]`),c=(o=p==null?void 0:p.value)!=null?o:"";return!r&&e.required&&c===""?(a.push(`${t}: ${$("required",n.state)}`),{value:null,errors:a}):{value:c||null,errors:a}}}function de(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",p=(s=u.split(".").pop())==null?void 0:s.toLowerCase();let c="application/octet-stream";p&&(["jpg","jpeg","png","gif","webp"].includes(p)?c=`image/${p==="jpg"?"jpeg":p}`:["mp4","webm","mov","avi"].includes(p)&&(c=`video/${p==="mov"?"quicktime":p}`)),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 p="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?p=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(p=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:s,type:p,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function q(e){return e?e.toUpperCase():"#000000"}function W(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function pe(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 fe(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=q(e),o=document.createElement("div");o.style.cssText=`
206
202
  width: 32px;
207
203
  height: 32px;
208
204
  border-radius: var(--fb-border-radius);
@@ -212,7 +208,7 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
212
208
  font-size: var(--fb-font-size);
213
209
  color: var(--fb-text-color);
214
210
  font-family: var(--fb-font-family-mono, monospace);
215
- `,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function fe(e,t,n){const o=q(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
211
+ `,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function me(e,t,n){const o=q(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
216
212
  display: flex;
217
213
  align-items: center;
218
214
  gap: 8px;
@@ -239,27 +235,27 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
239
235
  position: absolute;
240
236
  opacity: 0;
241
237
  pointer-events: none;
242
- `,r.addEventListener("input",()=>{const s=r.value.trim();if(W(s)){const u=pe(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(W(s)){const u=pe(s);r.value=u,l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid")}}),i.addEventListener("change",()=>{const s=q(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 ct(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=me(l);n.appendChild(r)}else{const r=fe(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
238
+ `,r.addEventListener("input",()=>{const s=r.value.trim();if(W(s)){const u=pe(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(W(s)){const u=pe(s);r.value=u,l.style.backgroundColor=u,i.value=u.toLowerCase(),r.classList.remove("invalid")}}),i.addEventListener("change",()=>{const s=q(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 ct(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=fe(l);n.appendChild(r)}else{const r=me(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
243
239
  font-size: var(--fb-font-size-small);
244
240
  color: var(--fb-text-secondary-color);
245
- `,r.textContent=F(e,a),n.appendChild(r)}}function ut(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,p=(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 h(){c.querySelectorAll(".multiple-colour-item").forEach((d,b)=>{const y=d.querySelector("input");y&&(y.name=`${o}[${b}]`)})}function m(d="#000000",b=-1){const y=document.createElement("div");if(y.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const C=me(d);for(;C.firstChild;)y.appendChild(C.firstChild)}else{const C=`${o}[${c.children.length}]`,x=fe(d,C,t);x.style.flex="1",y.appendChild(x)}return b===-1?c.appendChild(y):c.insertBefore(y,c.children[b]),h(),y}function f(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-colour-item"),b=d.length;d.forEach(y=>{let C=y.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=`
241
+ `,r.textContent=F(e,a),n.appendChild(r)}}function ut(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,p=(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 h(){c.querySelectorAll(".multiple-colour-item").forEach((d,y)=>{const b=d.querySelector("input");b&&(b.name=`${o}[${y}]`)})}function f(d="#000000",y=-1){const b=document.createElement("div");if(b.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const C=fe(d);for(;C.firstChild;)b.appendChild(C.firstChild)}else{const C=`${o}[${c.children.length}]`,x=me(d,C,t);x.style.flex="1",b.appendChild(x)}return y===-1?c.appendChild(b):c.insertBefore(b,c.children[y]),h(),b}function m(){if(r.config.readonly)return;const d=c.querySelectorAll(".multiple-colour-item"),y=d.length;d.forEach(b=>{let C=b.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=`
246
242
  color: var(--fb-error-color);
247
243
  background-color: transparent;
248
244
  transition: background-color var(--fb-transition-duration);
249
- `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const w=Array.from(c.children).indexOf(y);c.children.length>u&&(s.splice(w,1),y.remove(),h(),E(),f())},y.appendChild(C));const x=b<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-colour-btn px-3 py-1 rounded",d.style.cssText=`
245
+ `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const w=Array.from(c.children).indexOf(b);c.children.length>u&&(s.splice(w,1),b.remove(),h(),E(),m())},b.appendChild(C));const x=y<=u;C.disabled=x,C.style.opacity=x?"0.5":"1",C.style.pointerEvents=x?"none":"auto"})}let v=null,g=null;if(!r.config.readonly){v=document.createElement("div"),v.className="flex items-center gap-3 mt-2";const d=document.createElement("button");d.type="button",d.className="add-colour-btn px-3 py-1 rounded",d.style.cssText=`
250
246
  color: var(--fb-primary-color);
251
247
  border: var(--fb-border-width) solid var(--fb-primary-color);
252
248
  background-color: transparent;
253
249
  font-size: var(--fb-font-size);
254
250
  transition: all var(--fb-transition-duration);
255
- `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{const b=e.default||"#000000";s.push(b),m(b),E(),f()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-colour-btn");if(d){const b=s.length>=p;d.disabled=b,d.style.opacity=b?"0.5":"1",d.style.pointerEvents=b?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}if(s.forEach(d=>m(d)),E(),f(),!r.config.readonly){const d=document.createElement("p");d.className="mt-1",d.style.cssText=`
251
+ `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{const y=e.default||"#000000";s.push(y),f(y),E(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(d),v.appendChild(g),n.appendChild(v)}function E(){if(!v||!g)return;const d=v.querySelector(".add-colour-btn");if(d){const y=s.length>=p;d.disabled=y,d.style.opacity=y?"0.5":"1",d.style.pointerEvents=y?"none":"auto"}g.textContent=`${s.length}/${p===1/0?"\u221E":p}`}if(s.forEach(d=>f(d)),E(),m(),!r.config.readonly){const d=document.createElement("p");d.className="mt-1",d.style.cssText=`
256
252
  font-size: var(--fb-font-size-small);
257
253
  color: var(--fb-text-secondary-color);
258
- `,d.textContent=F(e,r),n.appendChild(d)}}function dt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var m,f;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
254
+ `,d.textContent=F(e,r),n.appendChild(d)}}function dt(e,t,n){var o,a,l;const r=[],{scopeRoot:i,skipValidation:s}=n,u=(c,h)=>{var f,m;if(!c)return;const v=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(c.classList.add("invalid"),c.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
259
255
  color: var(--fb-error-color);
260
256
  font-size: var(--fb-font-size-small);
261
257
  margin-top: 0.25rem;
262
- `,c.nextSibling?(m=c.parentNode)==null||m.insertBefore(g,c.nextSibling):(f=c.parentNode)==null||f.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},p=(c,h,m)=>{const{state:f}=n;if(!h){if(!s&&e.required){const g=$("required",f);return r.push(`${m}: ${g}`),u(c,g),""}return u(c,null),""}const v=q(h);if(!s&&!W(v)){const g=$("invalidHexColour",f);return r.push(`${m}: ${g}`),u(c,g),h}return u(c,null),v};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["].colour-hex-input`),h=[];if(c.forEach((m,f)=>{var v;const g=(v=m==null?void 0:m.value)!=null?v:"",E=p(m,g,`${t}[${f}]`);h.push(E)}),!s){const{state:m}=n,f=(o=e.minCount)!=null?o:1,v=(a=e.maxCount)!=null?a:1/0,g=h.filter(E=>E!=="");e.required&&g.length===0&&r.push(`${t}: ${$("required",m)}`),g.length<f&&r.push(`${t}: ${$("minItems",m,{min:f})}`),g.length>v&&r.push(`${t}: ${$("maxItems",m,{max:v})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name="${t}"].colour-hex-input`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const m=$("required",n.state);return r.push(`${t}: ${m}`),u(c,m),{value:"",errors:r}}return{value:p(c,h,t),errors:r}}}function pt(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=q(n[i]);r.value=s,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const p=u.querySelector(".colour-swatch"),c=u.querySelector(".colour-picker-hidden");p&&(p.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=q(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 he(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 J(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 R(e,t){return Math.round(e/t)*t}function ve(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 p=n.scale||"linear",c=n.min,h=n.max,m=(l=n.step)!=null?l:1;if(p==="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 d=J(e,c,h);u.value=(d*1e3).toString()}else u.min=c.toString(),u.max=h.toString(),u.step=m.toString(),u.value=e.toString();u.style.cssText=`
258
+ `,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(g,c.nextSibling):(m=c.parentNode)==null||m.appendChild(g)),g.textContent=h,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},p=(c,h,f)=>{const{state:m}=n;if(!h){if(!s&&e.required){const g=$("required",m);return r.push(`${f}: ${g}`),u(c,g),""}return u(c,null),""}const v=q(h);if(!s&&!W(v)){const g=$("invalidHexColour",m);return r.push(`${f}: ${g}`),u(c,g),h}return u(c,null),v};if(e.multiple){const c=i.querySelectorAll(`[name^="${t}["].colour-hex-input`),h=[];if(c.forEach((f,m)=>{var v;const g=(v=f==null?void 0:f.value)!=null?v:"",E=p(f,g,`${t}[${m}]`);h.push(E)}),!s){const{state:f}=n,m=(o=e.minCount)!=null?o:1,v=(a=e.maxCount)!=null?a:1/0,g=h.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>v&&r.push(`${t}: ${$("maxItems",f,{max:v})}`)}return{value:h,errors:r}}else{const c=i.querySelector(`[name="${t}"].colour-hex-input`),h=(l=c==null?void 0:c.value)!=null?l:"";if(!s&&e.required&&h===""){const f=$("required",n.state);return r.push(`${t}: ${f}`),u(c,f),{value:"",errors:r}}return{value:p(c,h,t),errors:r}}}function pt(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=q(n[i]);r.value=s,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const p=u.querySelector(".colour-swatch"),c=u.querySelector(".colour-picker-hidden");p&&(p.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=q(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 he(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 J(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 R(e,t){return Math.round(e/t)*t}function ve(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 p=n.scale||"linear",c=n.min,h=n.max,f=(l=n.step)!=null?l:1;if(p==="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 d=J(e,c,h);u.value=(d*1e3).toString()}else u.min=c.toString(),u.max=h.toString(),u.step=f.toString(),u.value=e.toString();u.style.cssText=`
263
259
  height: 6px;
264
260
  border-radius: 3px;
265
261
  background: linear-gradient(
@@ -273,11 +269,11 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
273
269
  transition: background 0.1s ease-in-out;
274
270
  cursor: ${a?"not-allowed":"pointer"};
275
271
  opacity: ${a?"0.6":"1"};
276
- `,s.appendChild(u);const f=document.createElement("div");f.className="flex justify-between",f.style.cssText=`
272
+ `,s.appendChild(u);const m=document.createElement("div");m.className="flex justify-between",m.style.cssText=`
277
273
  font-size: var(--fb-font-size-small);
278
274
  color: var(--fb-text-secondary-color);
279
275
  margin-top: 4px;
280
- `;const v=document.createElement("span");v.textContent=c.toString();const g=document.createElement("span");g.textContent=h.toString(),f.appendChild(v),f.appendChild(g),s.appendChild(f);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
276
+ `;const v=document.createElement("span");v.textContent=c.toString();const g=document.createElement("span");g.textContent=h.toString(),m.appendChild(v),m.appendChild(g),s.appendChild(m);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
281
277
  min-width: 60px;
282
278
  text-align: right;
283
279
  font-size: var(--fb-font-size);
@@ -285,64 +281,64 @@ var FormBuilder=(function(N){"use strict";function $(e,t,n){const o=t.config.loc
285
281
  font-family: var(--fb-font-family-mono, monospace);
286
282
  font-weight: 500;
287
283
  padding-top: 2px;
288
- `,E.textContent=e.toFixed(m<1?2:0),i.appendChild(s),i.appendChild(E),r.appendChild(i),!a){const d=()=>{let b;if(p==="exponential"){const C=parseFloat(u.value)/1e3;b=he(C,c,h),b=R(b,m),b=Math.max(c,Math.min(h,b))}else b=parseFloat(u.value),b=R(b,m);E.textContent=b.toFixed(m<1?2:0);const y=(b-c)/(h-c)*100;u.style.background=`linear-gradient(
284
+ `,E.textContent=e.toFixed(f<1?2:0),i.appendChild(s),i.appendChild(E),r.appendChild(i),!a){const d=()=>{let y;if(p==="exponential"){const C=parseFloat(u.value)/1e3;y=he(C,c,h),y=R(y,f),y=Math.max(c,Math.min(h,y))}else y=parseFloat(u.value),y=R(y,f);E.textContent=y.toFixed(f<1?2:0);const b=(y-c)/(h-c)*100;u.style.background=`linear-gradient(
289
285
  to right,
290
286
  var(--fb-primary-color) 0%,
291
- var(--fb-primary-color) ${y}%,
292
- var(--fb-border-color) ${y}%,
287
+ var(--fb-primary-color) ${b}%,
288
+ var(--fb-border-color) ${b}%,
293
289
  var(--fb-border-color) 100%
294
- )`,o.instance&&o.instance.triggerOnChange(t,b)};u.addEventListener("input",d),u.addEventListener("change",d)}return r}function mt(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=ve(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=`
290
+ )`,o.instance&&o.instance.triggerOnChange(t,y)};u.addEventListener("input",d),u.addEventListener("change",d)}return r}function ft(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=ve(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=`
295
291
  font-size: var(--fb-font-size-small);
296
292
  color: var(--fb-text-secondary-color);
297
- `,u.textContent=F(e,l),n.appendChild(u)}}function ft(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,p=(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 h=document.createElement("div");h.className="space-y-3",n.appendChild(h);function m(){h.querySelectorAll(".multiple-slider-item").forEach((b,y)=>{const C=b.querySelector("input[type=range]");C&&C.setAttribute("name",`${o}[${y}]`)})}function f(b=c,y=-1){const C=document.createElement("div");C.className="multiple-slider-item flex items-start gap-2";const x=`${o}[${h.children.length}]`,w=ve(b,x,e,t,r.config.readonly);return w.style.flex="1",C.appendChild(w),y===-1?h.appendChild(C):h.insertBefore(C,h.children[y]),m(),C}function v(){if(r.config.readonly)return;const b=h.querySelectorAll(".multiple-slider-item"),y=b.length;b.forEach(C=>{let x=C.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=`
293
+ `,u.textContent=F(e,l),n.appendChild(u)}}function mt(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,p=(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 h=document.createElement("div");h.className="space-y-3",n.appendChild(h);function f(){h.querySelectorAll(".multiple-slider-item").forEach((y,b)=>{const C=y.querySelector("input[type=range]");C&&C.setAttribute("name",`${o}[${b}]`)})}function m(y=c,b=-1){const C=document.createElement("div");C.className="multiple-slider-item flex items-start gap-2";const x=`${o}[${h.children.length}]`,w=ve(y,x,e,t,r.config.readonly);return w.style.flex="1",C.appendChild(w),b===-1?h.appendChild(C):h.insertBefore(C,h.children[b]),f(),C}function v(){if(r.config.readonly)return;const y=h.querySelectorAll(".multiple-slider-item"),b=y.length;y.forEach(C=>{let x=C.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=`
298
294
  color: var(--fb-error-color);
299
295
  background-color: transparent;
300
296
  transition: background-color var(--fb-transition-duration);
301
297
  margin-top: 8px;
302
- `,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const S=Array.from(h.children).indexOf(C);h.children.length>u&&(s.splice(S,1),C.remove(),m(),d(),v())},C.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 b=document.createElement("button");b.type="button",b.className="add-slider-btn px-3 py-1 rounded",b.style.cssText=`
298
+ `,x.innerHTML="\u2715",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{const S=Array.from(h.children).indexOf(C);h.children.length>u&&(s.splice(S,1),C.remove(),f(),d(),v())},C.appendChild(x));const w=b<=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 y=document.createElement("button");y.type="button",y.className="add-slider-btn px-3 py-1 rounded",y.style.cssText=`
303
299
  color: var(--fb-primary-color);
304
300
  border: var(--fb-border-width) solid var(--fb-primary-color);
305
301
  background-color: transparent;
306
302
  font-size: var(--fb-font-size);
307
303
  transition: all var(--fb-transition-duration);
308
- `,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{s.push(c),f(c),d(),v()},E=document.createElement("span"),E.className="text-sm text-gray-500",g.appendChild(b),g.appendChild(E),n.appendChild(g)}function d(){if(!g||!E)return;const b=g.querySelector(".add-slider-btn");if(b){const y=s.length>=p;b.disabled=y,b.style.opacity=y?"0.5":"1",b.style.pointerEvents=y?"none":"auto"}E.textContent=`${s.length}/${p===1/0?"\u221E":p}`}if(s.forEach(b=>f(b)),d(),v(),!r.config.readonly){const b=document.createElement("p");b.className="mt-1",b.style.cssText=`
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),d(),v()},E=document.createElement("span"),E.className="text-sm text-gray-500",g.appendChild(y),g.appendChild(E),n.appendChild(g)}function d(){if(!g||!E)return;const y=g.querySelector(".add-slider-btn");if(y){const b=s.length>=p;y.disabled=b,y.style.opacity=b?"0.5":"1",y.style.pointerEvents=b?"none":"auto"}E.textContent=`${s.length}/${p===1/0?"\u221E":p}`}if(s.forEach(y=>m(y)),d(),v(),!r.config.readonly){const y=document.createElement("p");y.className="mt-1",y.style.cssText=`
309
305
  font-size: var(--fb-font-size-small);
310
306
  color: var(--fb-text-secondary-color);
311
- `,b.textContent=F(e,r),n.appendChild(b)}}function ht(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,p=e.max,c=(o=e.step)!=null?o:1,h=e.scale||"linear",m=(v,g)=>{var E,d;if(!v)return;const b=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let y=document.getElementById(b);if(g){if(v.classList.add("invalid"),v.title=g,!y){y=document.createElement("div"),y.id=b,y.className="error-message",y.style.cssText=`
307
+ `,y.textContent=F(e,r),n.appendChild(y)}}function ht(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,p=e.max,c=(o=e.step)!=null?o:1,h=e.scale||"linear",f=(v,g)=>{var E,d;if(!v)return;const y=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(y);if(g){if(v.classList.add("invalid"),v.title=g,!b){b=document.createElement("div"),b.id=y,b.className="error-message",b.style.cssText=`
312
308
  color: var(--fb-error-color);
313
309
  font-size: var(--fb-font-size-small);
314
310
  margin-top: 0.25rem;
315
- `;const C=v.closest(".slider-container");C&&C.nextSibling?(E=C.parentNode)==null||E.insertBefore(y,C.nextSibling):C&&((d=C.parentNode)==null||d.appendChild(y))}y.textContent=g,y.style.display="block"}else v.classList.remove("invalid"),v.title="",y&&y.remove()},f=(v,g)=>{const{state:E}=n,d=v.value;if(!d){if(!s&&e.required){const y=$("required",E);return r.push(`${g}: ${y}`),m(v,y),null}return m(v,null),null}let b;if(h==="exponential"){const y=parseFloat(d)/1e3;b=he(y,u,p),b=R(b,c)}else b=parseFloat(d),b=R(b,c);if(!s){if(b<u){const y=$("minValue",E,{min:u});return r.push(`${g}: ${y}`),m(v,y),b}if(b>p){const y=$("maxValue",E,{max:p});return r.push(`${g}: ${y}`),m(v,y),b}}return m(v,null),b};if(e.multiple){const v=i.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(v.forEach((E,d)=>{const b=f(E,`${t}[${d}]`);g.push(b)}),!s){const{state:E}=n,d=(a=e.minCount)!=null?a:1,b=(l=e.maxCount)!=null?l:1/0,y=g.filter(C=>C!==null);e.required&&y.length===0&&r.push(`${t}: ${$("required",E)}`),y.length<d&&r.push(`${t}: ${$("minItems",E,{min:d})}`),y.length>b&&r.push(`${t}: ${$("maxItems",E,{max:b})}`)}return{value:g,errors:r}}else{const v=i.querySelector(`input[type="range"][name="${t}"]`);return v?{value:f(v,t),errors:r}:(!s&&e.required&&r.push(`${t}: ${$("required",n.state)}`),{value:null,errors:r})}}function vt(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 p=l.querySelectorAll(`input[type="range"][name^="${t}["]`);p.forEach((c,h)=>{if(h<n.length&&n[h]!==null){const m=Number(n[h]);if(u==="exponential"){const v=J(m,r,i);c.value=(v*1e3).toString()}else c.value=m.toString();const f=c.closest(".slider-container");if(f){const v=f.querySelector(".slider-value");v&&(v.textContent=m.toFixed(s<1?2:0));const g=(m-r)/(i-r)*100;c.style.background=`linear-gradient(
311
+ `;const C=v.closest(".slider-container");C&&C.nextSibling?(E=C.parentNode)==null||E.insertBefore(b,C.nextSibling):C&&((d=C.parentNode)==null||d.appendChild(b))}b.textContent=g,b.style.display="block"}else v.classList.remove("invalid"),v.title="",b&&b.remove()},m=(v,g)=>{const{state:E}=n,d=v.value;if(!d){if(!s&&e.required){const b=$("required",E);return r.push(`${g}: ${b}`),f(v,b),null}return f(v,null),null}let y;if(h==="exponential"){const b=parseFloat(d)/1e3;y=he(b,u,p),y=R(y,c)}else y=parseFloat(d),y=R(y,c);if(!s){if(y<u){const b=$("minValue",E,{min:u});return r.push(`${g}: ${b}`),f(v,b),y}if(y>p){const b=$("maxValue",E,{max:p});return r.push(`${g}: ${b}`),f(v,b),y}}return f(v,null),y};if(e.multiple){const v=i.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(v.forEach((E,d)=>{const y=m(E,`${t}[${d}]`);g.push(y)}),!s){const{state:E}=n,d=(a=e.minCount)!=null?a:1,y=(l=e.maxCount)!=null?l:1/0,b=g.filter(C=>C!==null);e.required&&b.length===0&&r.push(`${t}: ${$("required",E)}`),b.length<d&&r.push(`${t}: ${$("minItems",E,{min:d})}`),b.length>y&&r.push(`${t}: ${$("maxItems",E,{max:y})}`)}return{value:g,errors:r}}else{const v=i.querySelector(`input[type="range"][name="${t}"]`);return v?{value:m(v,t),errors:r}:(!s&&e.required&&r.push(`${t}: ${$("required",n.state)}`),{value:null,errors:r})}}function vt(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 p=l.querySelectorAll(`input[type="range"][name^="${t}["]`);p.forEach((c,h)=>{if(h<n.length&&n[h]!==null){const f=Number(n[h]);if(u==="exponential"){const v=J(f,r,i);c.value=(v*1e3).toString()}else c.value=f.toString();const m=c.closest(".slider-container");if(m){const v=m.querySelector(".slider-value");v&&(v.textContent=f.toFixed(s<1?2:0));const g=(f-r)/(i-r)*100;c.style.background=`linear-gradient(
316
312
  to right,
317
313
  var(--fb-primary-color) 0%,
318
314
  var(--fb-primary-color) ${g}%,
319
315
  var(--fb-border-color) ${g}%,
320
316
  var(--fb-border-color) 100%
321
- )`}c.classList.remove("invalid"),c.title=""}}),n.length!==p.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${p.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const p=l.querySelector(`input[type="range"][name="${t}"]`);if(p&&n!==null&&n!==void 0){const c=Number(n);if(u==="exponential"){const m=J(c,r,i);p.value=(m*1e3).toString()}else p.value=c.toString();const h=p.closest(".slider-container");if(h){const m=h.querySelector(".slider-value");m&&(m.textContent=c.toFixed(s<1?2:0));const f=(c-r)/(i-r)*100;p.style.background=`linear-gradient(
317
+ )`}c.classList.remove("invalid"),c.title=""}}),n.length!==p.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${p.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const p=l.querySelector(`input[type="range"][name="${t}"]`);if(p&&n!==null&&n!==void 0){const c=Number(n);if(u==="exponential"){const f=J(c,r,i);p.value=(f*1e3).toString()}else p.value=c.toString();const h=p.closest(".slider-container");if(h){const f=h.querySelector(".slider-value");f&&(f.textContent=c.toFixed(s<1?2:0));const m=(c-r)/(i-r)*100;p.style.background=`linear-gradient(
322
318
  to right,
323
319
  var(--fb-primary-color) 0%,
324
- var(--fb-primary-color) ${f}%,
325
- var(--fb-border-color) ${f}%,
320
+ var(--fb-primary-color) ${m}%,
321
+ var(--fb-border-color) ${m}%,
326
322
  var(--fb-border-color) 100%
327
- )`}p.classList.remove("invalid"),p.title=""}}}function Y(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 G=null;function gt(e){G=e}function D(e,t){if(!G)throw new Error("renderElement not initialized. Import from components/index.ts");return G(e,t)}function ge(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 ye(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=ge(e,o);p&&r.appendChild(p)}const u={path:A(t.path,e.key),prefill:((a=t.prefill)==null?void 0:a[e.key])||{},formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||i.appendChild(D(p,u))}),r.appendChild(i),n.appendChild(r)}function be(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 p=document.createElement("span");p.className="text-sm text-gray-500";const c=document.createElement("div");if(c.className="space-y-4",!t.state.config.readonly){const d=ge(e,e.key);d&&u.appendChild(d)}const h=(a=e.minCount)!=null?a:0,m=(l=e.maxCount)!=null?l:1/0,f=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,v=()=>c.querySelectorAll(":scope > .containerItem").length,g=()=>{const d=document.createElement("button");return d.type="button",d.className="add-container-btn px-3 py-1 rounded",d.style.cssText=`
323
+ )`}p.classList.remove("invalid"),p.title=""}}}function Y(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 G=null;function gt(e){G=e}function D(e,t){if(!G)throw new Error("renderElement not initialized. Import from components/index.ts");return G(e,t)}function ge(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 be(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=ge(e,o);p&&r.appendChild(p)}const u={path:A(t.path,e.key),prefill:((a=t.prefill)==null?void 0:a[e.key])||{},formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||i.appendChild(D(p,u))}),r.appendChild(i),n.appendChild(r)}function ye(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 p=document.createElement("span");p.className="text-sm text-gray-500";const c=document.createElement("div");if(c.className="space-y-4",!t.state.config.readonly){const d=ge(e,e.key);d&&u.appendChild(d)}const h=(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,v=()=>c.querySelectorAll(":scope > .containerItem").length,g=()=>{const d=document.createElement("button");return d.type="button",d.className="add-container-btn px-3 py-1 rounded",d.style.cssText=`
328
324
  color: var(--fb-primary-color);
329
325
  border: var(--fb-border-width) solid var(--fb-primary-color);
330
326
  background-color: transparent;
331
327
  font-size: var(--fb-font-size);
332
328
  transition: all var(--fb-transition-duration);
333
- `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{if(v()<m){const b=v(),y=s.formRoot?Y(s.formRoot):{},C={state:t.state,path:A(t.path,`${e.key}[${b}]`),prefill:{},formData:y},x=document.createElement("div");x.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",x.setAttribute("data-container-item",`${e.key}[${b}]`);const w=document.createElement("div"),S=e.columns||1;if(S===1?w.className="space-y-4":w.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(D(k,C))}),x.appendChild(w),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
329
+ `,d.textContent="+",d.addEventListener("mouseenter",()=>{d.style.backgroundColor="var(--fb-background-hover-color)"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor="transparent"}),d.onclick=()=>{if(v()<f){const y=v(),b=s.formRoot?Y(s.formRoot):{},C={state:t.state,path:A(t.path,`${e.key}[${y}]`),prefill:{},formData:b},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"),S=e.columns||1;if(S===1?w.className="space-y-4":w.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(D(k,C))}),x.appendChild(w),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
334
330
  color: var(--fb-error-color);
335
331
  background-color: transparent;
336
332
  transition: background-color var(--fb-transition-duration);
337
- `,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{x.remove(),E()},x.style.position="relative",x.appendChild(k)}c.appendChild(x),E()}},d},E=()=>{const d=v(),b=u.querySelector(".add-container-btn");b&&(b.disabled=d>=m,b.style.opacity=d>=m?"0.5":"1",b.style.pointerEvents=d>=m?"none":"auto"),p.textContent=`${d}/${m===1/0?"\u221E":m}`};if(f&&Array.isArray(f)&&f.forEach((d,b)=>{var y;const C={state:t.state,path:A(t.path,`${e.key}[${b}]`),prefill:d||{},formData:(y=t.formData)!=null?y: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}[${b}]`);const w=document.createElement("div"),S=e.columns||1;if(S===1?w.className="space-y-4":w.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(D(k,C))}),x.appendChild(w),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
333
+ `,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{x.remove(),E()},x.style.position="relative",x.appendChild(k)}c.appendChild(x),E()}},d},E=()=>{const d=v(),y=u.querySelector(".add-container-btn");y&&(y.disabled=d>=f,y.style.opacity=d>=f?"0.5":"1",y.style.pointerEvents=d>=f?"none":"auto"),p.textContent=`${d}/${f===1/0?"\u221E":f}`};if(m&&Array.isArray(m)&&m.forEach((d,y)=>{var b;const C={state:t.state,path:A(t.path,`${e.key}[${y}]`),prefill:d||{},formData:(b=t.formData)!=null?b: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"),S=e.columns||1;if(S===1?w.className="space-y-4":w.className=`grid grid-cols-${S} gap-4`,e.elements.forEach(k=>{k.hidden||w.appendChild(D(k,C))}),x.appendChild(w),!s.config.readonly){const k=document.createElement("button");k.type="button",k.className="absolute top-2 right-2 px-2 py-1 rounded",k.style.cssText=`
338
334
  color: var(--fb-error-color);
339
335
  background-color: transparent;
340
336
  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=()=>{x.remove(),E()},x.style.position="relative",x.appendChild(k)}c.appendChild(x)}),!s.config.readonly)for(;v()<h;){const d=v(),b={state:t.state,path:A(t.path,`${e.key}[${d}]`),prefill:{},formData:(i=t.formData)!=null?i:t.prefill},y=document.createElement("div");y.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",y.setAttribute("data-container-item",`${e.key}[${d}]`);const C=document.createElement("div"),x=e.columns||1;x===1?C.className="space-y-4":C.className=`grid grid-cols-${x} gap-4`,e.elements.forEach(S=>{S.hidden||C.appendChild(D(S,b))}),y.appendChild(C);const w=document.createElement("button");w.type="button",w.className="absolute top-2 right-2 px-2 py-1 rounded",w.style.cssText=`
337
+ `,k.textContent="\u2715",k.addEventListener("mouseenter",()=>{k.style.backgroundColor="var(--fb-background-hover-color)"}),k.addEventListener("mouseleave",()=>{k.style.backgroundColor="transparent"}),k.onclick=()=>{x.remove(),E()},x.style.position="relative",x.appendChild(k)}c.appendChild(x)}),!s.config.readonly)for(;v()<h;){const d=v(),y={state:t.state,path:A(t.path,`${e.key}[${d}]`),prefill:{},formData:(i=t.formData)!=null?i:t.prefill},b=document.createElement("div");b.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",b.setAttribute("data-container-item",`${e.key}[${d}]`);const C=document.createElement("div"),x=e.columns||1;x===1?C.className="space-y-4":C.className=`grid grid-cols-${x} gap-4`,e.elements.forEach(S=>{S.hidden||C.appendChild(D(S,y))}),b.appendChild(C);const w=document.createElement("button");w.type="button",w.className="absolute top-2 right-2 px-2 py-1 rounded",w.style.cssText=`
342
338
  color: var(--fb-error-color);
343
339
  background-color: transparent;
344
340
  transition: background-color var(--fb-transition-duration);
345
- `,w.textContent="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{v()>h&&(y.remove(),E())},y.style.position="relative",y.appendChild(w),c.appendChild(y)}if(u.appendChild(c),!s.config.readonly){const d=document.createElement("div");d.className="flex items-center gap-3 mt-2",d.appendChild(g()),d.appendChild(p),u.appendChild(d)}E(),n.appendChild(u)}let X=null;function yt(e){X=e}function xe(e,t,n){if(!X)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return X(e,t,n)}function Ce(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,p)=>{var c,h;if(l)return;const{state:m}=n,f="minCount"in p&&(c=p.minCount)!=null?c:0,v="maxCount"in p&&(h=p.maxCount)!=null?h:1/0;p.required&&u.length===0&&o.push(`${s}: ${$("required",m)}`),u.length<f&&o.push(`${s}: ${$("minItems",m,{min:f})}`),u.length>v&&o.push(`${s}: ${$("maxItems",m,{max:v})}`)};if("multiple"in e&&e.multiple){const s=[],u=a.querySelectorAll("[data-container-item]"),p=Array.from(u).filter(c=>{const h=c.getAttribute("data-container-item");return h==null?void 0:h.startsWith(`${t}[`)}).length;for(let c=0;c<p;c++){const h={},m=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(f=>{var v;if(f.enableIf)try{const g=(v=n.instance)!=null&&v.getState().formRoot?Y(n.instance.getState().formRoot):{};if(!T(f.enableIf,g,h))return}catch(g){console.error(`Error evaluating enableIf for field "${f.key}" in container "${t}[${c}]":`,g)}if(f.hidden||f.type==="hidden")h[f.key]=f.default!==void 0?f.default:null;else{const g=`${t}[${c}].${f.key}`;h[f.key]=xe({...f,key:g},{path:r},m)}}),s.push(h)}return i(t,s,e),{value:s,errors:o}}else{const s={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(p=>{var c;if(p.enableIf)try{const h=(c=n.instance)!=null&&c.getState().formRoot?Y(n.instance.getState().formRoot):{};if(!T(p.enableIf,h,s))return}catch(h){console.error(`Error evaluating enableIf for field "${p.key}" in container "${t}":`,h)}if(p.hidden||p.type==="hidden")s[p.key]=p.default!==void 0?p.default:null;else{const h=`${t}.${p.key}`;s[p.key]=xe({...p,key:h},{path:r},u)}}),{value:s,errors:o}}}function Ee(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)=>{B(i)&&e.elements.forEach(u=>{const p=u.key,c=`${t}[${s}].${p}`,h=i[p];h!==void 0&&a.updateField(c,h)})});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(!B(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 bt(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&&B(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?be(r,t,n):ye(r,t,n,o)}function $e(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&&B(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function xt(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=$e(e);return Ce(o,t,n)}function Ct(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=$e(e);return Ee(a,t,n,o)}function Et(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(p=>{p.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 $t(e,t){var n,o;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},l=t.path?z(a,t.path):void 0;return!T(e.enableIf,a,l)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function wt(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 j(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 p=n.path.match(/^(.+)\[(\d+)\]$/);if(p){const c=p[1],h=parseInt(p[2],10),m=l.querySelector(`[data-container-item="${c}[${h}]"]`);m&&m.querySelectorAll("input, select, textarea").forEach(f=>{const v=f.getAttribute("name");if(v){const g=v.match(/\.([^.[\]]+)$/);if(g){const E=g[1];f instanceof HTMLSelectElement?u[E]=f.value:f instanceof HTMLInputElement?f.type==="checkbox"?u[E]=f.checked:f.type==="radio"?f.checked&&(u[E]=f.value):u[E]=f.value:f instanceof HTMLTextAreaElement&&(u[E]=f.value)}}})}}else{const p=r.key,c=wt(p,l);c!==void 0?s[p]=c:s=(a=n.formData)!=null?a:n.prefill}try{T(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(p){console.error(`Error re-evaluating enableIf for field "${t.key}":`,p)}}function kt(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 p=new MutationObserver(()=>{const c=a.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{j(e,t,n)}),c.addEventListener("input",()=>{j(e,t,n)}),p.disconnect())});p.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{j(e,t,n)}),u.addEventListener("input",()=>{j(e,t,n)})}function Lt(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 St(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(),Et(n,t)},t}function Ft(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Lt(e);if(t.appendChild(n),e.description||e.hint){const o=St(e);t.appendChild(o)}return t}function Nt(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?He(e,t,n,o):Me(e,t,n,o);break;case"textarea":a?ze(e,t,n,o):Be(e,t,n,o);break;case"number":a?je(e,t,n,o):De(e,t,n,o);break;case"select":a?Ve(e,t,n,o):Pe(e,t,n,o);break;case"file":a?st(e,t,n,o):at(e,t,n,o);break;case"files":it(e,t,n,o);break;case"colour":a?ut(e,t,n,o):ct(e,t,n,o);break;case"slider":a?ft(e,t,n,o):mt(e,t,n,o);break;case"group":bt(e,t,n,o);break;case"container":a?be(e,t,n):ye(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 Z(e,t){const n=$t(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=Ft(e);o.appendChild(a);const l=A(t.path,e.key);return Nt(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),kt(o,e,t),o}gt(Z);const Q={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 At(e){const t={...Q.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...Q.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Q,...e,translations:t},debounceTimer:null}}function Tt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const H={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 qt(e){const t={...H,...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(`
341
+ `,w.textContent="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{v()>h&&(b.remove(),E())},b.style.position="relative",b.appendChild(w),c.appendChild(b)}if(u.appendChild(c),!s.config.readonly){const d=document.createElement("div");d.className="flex items-center gap-3 mt-2",d.appendChild(g()),d.appendChild(p),u.appendChild(d)}E(),n.appendChild(u)}let X=null;function bt(e){X=e}function xe(e,t,n){if(!X)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return X(e,t,n)}function Ce(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,p)=>{var c,h;if(l)return;const{state:f}=n,m="minCount"in p&&(c=p.minCount)!=null?c:0,v="maxCount"in p&&(h=p.maxCount)!=null?h:1/0;p.required&&u.length===0&&o.push(`${s}: ${$("required",f)}`),u.length<m&&o.push(`${s}: ${$("minItems",f,{min:m})}`),u.length>v&&o.push(`${s}: ${$("maxItems",f,{max:v})}`)};if("multiple"in e&&e.multiple){const s=[],u=a.querySelectorAll("[data-container-item]"),p=Array.from(u).filter(c=>{const h=c.getAttribute("data-container-item");return h==null?void 0:h.startsWith(`${t}[`)}).length;for(let c=0;c<p;c++){const h={},f=a.querySelector(`[data-container-item="${t}[${c}]"]`)||a;e.elements.forEach(m=>{var v;if(m.enableIf)try{const g=(v=n.instance)!=null&&v.getState().formRoot?Y(n.instance.getState().formRoot):{};if(!T(m.enableIf,g,h))return}catch(g){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${c}]":`,g)}if(m.hidden||m.type==="hidden")h[m.key]=m.default!==void 0?m.default:null;else{const g=`${t}[${c}].${m.key}`;h[m.key]=xe({...m,key:g},{path:r},f)}}),s.push(h)}return i(t,s,e),{value:s,errors:o}}else{const s={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(p=>{var c;if(p.enableIf)try{const h=(c=n.instance)!=null&&c.getState().formRoot?Y(n.instance.getState().formRoot):{};if(!T(p.enableIf,h,s))return}catch(h){console.error(`Error evaluating enableIf for field "${p.key}" in container "${t}":`,h)}if(p.hidden||p.type==="hidden")s[p.key]=p.default!==void 0?p.default:null;else{const h=`${t}.${p.key}`;s[p.key]=xe({...p,key:h},{path:r},u)}}),{value:s,errors:o}}}function Ee(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)=>{B(i)&&e.elements.forEach(u=>{const p=u.key,c=`${t}[${s}].${p}`,h=i[p];h!==void 0&&a.updateField(c,h)})});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(!B(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 yt(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&&B(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?ye(r,t,n):be(r,t,n,o)}function $e(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&&B(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function xt(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=$e(e);return Ce(o,t,n)}function Ct(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=$e(e);return Ee(a,t,n,o)}function Et(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(p=>{p.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 $t(e,t){var n,o;if(!e.enableIf)return!1;try{const a=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},l=t.path?z(a,t.path):void 0;return!T(e.enableIf,a,l)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function wt(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 j(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 p=n.path.match(/^(.+)\[(\d+)\]$/);if(p){const c=p[1],h=parseInt(p[2],10),f=l.querySelector(`[data-container-item="${c}[${h}]"]`);f&&f.querySelectorAll("input, select, textarea").forEach(m=>{const v=m.getAttribute("name");if(v){const g=v.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 p=r.key,c=wt(p,l);c!==void 0?s[p]=c:s=(a=n.formData)!=null?a:n.prefill}try{T(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(p){console.error(`Error re-evaluating enableIf for field "${t.key}":`,p)}}function kt(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 p=new MutationObserver(()=>{const c=a.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{j(e,t,n)}),c.addEventListener("input",()=>{j(e,t,n)}),p.disconnect())});p.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{j(e,t,n)}),u.addEventListener("input",()=>{j(e,t,n)})}function Lt(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 St(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(),Et(n,t)},t}function Ft(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=Lt(e);if(t.appendChild(n),e.description||e.hint){const o=St(e);t.appendChild(o)}return t}function Nt(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?He(e,t,n,o):Me(e,t,n,o);break;case"textarea":a?ze(e,t,n,o):Be(e,t,n,o);break;case"number":a?je(e,t,n,o):De(e,t,n,o);break;case"select":a?Ve(e,t,n,o):Pe(e,t,n,o);break;case"file":a?st(e,t,n,o):at(e,t,n,o);break;case"files":it(e,t,n,o);break;case"colour":a?ut(e,t,n,o):ct(e,t,n,o);break;case"slider":a?mt(e,t,n,o):ft(e,t,n,o);break;case"group":yt(e,t,n,o);break;case"container":a?ye(e,t,n):be(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 Z(e,t){const n=$t(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=Ft(e);o.appendChild(a);const l=A(t.path,e.key);return Nt(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),kt(o,e,t),o}gt(Z);const Q={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 At(e){const t={...Q.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...Q.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Q,...e,translations:t},debounceTimer:null}}function Tt(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const H={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 qt(e){const t={...H,...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(`
346
342
  `)}function Mt(e,t){const n=qt(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=`
347
343
  [data-fb-root="true"] {
348
344
  ${n}
@@ -359,4 +355,4 @@ ${n}
359
355
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
360
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 Bt={text:{validate:K,update:ee},textarea:{validate:Ie,update:Re},number:{validate:Oe,update:Ue},select:{validate:_e,update:We},file:{validate:ue,update:de},files:{validate:ue,update:de},colour:{validate:dt,update:pt},slider:{validate:ht,update:vt},container:{validate:Ce,update:Ee},group:{validate:xt,update:Ct}};function ke(e){return Bt[e]||null}function zt(e,t,n){const o=ke(e.type);return o&&o.validate?o.validate(e,t,n):null}function It(e,t,n,o){const a=ke(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class O{constructor(t){this.instanceId=Tt(),this.state=At(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=`
361
357
  border-top: var(--fb-border-width) solid var(--fb-border-color);
362
- `,t.forEach(l=>{const r=document.createElement("button");r.type="button",we(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 p=document.createElement("div");p.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(r);l.forEach(h=>{const m=document.createElement("button");m.type="button",we(m,!1);const f=this.resolveActionLabel(h.key,h.label,c);m.textContent=f,m.addEventListener("click",v=>{v.preventDefault(),v.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(h.value,h.key,h.related_field)}),p.appendChild(m)}),s.appendChild(p)});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,M(t),t.setAttribute("data-fb-root","true"),Mt(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 p=Z(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});i.appendChild(p)}),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},p=zt(l,s,u);return p!==null?(n.push(...p.errors),p.value):(console.warn(`Unknown field type "${l.type}" for key "${s}"`),null)};return yt(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!T(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:""};It(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 p=null;if(a){const c=a.match(/^(.+)\[(\d+)\]$/);if(c){const h=c[1],m=c[2],f=this.state.formRoot.querySelector(`[data-container-item="${h}[${m}]"]`);f&&(p=f.querySelector(`[data-field-key="${l.key}"]`))}else{const h=this.state.formRoot.querySelector(`[data-container="${a}"]`);h&&(p=h.querySelector(`[data-field-key="${l.key}"]`))}}else p=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(p){const c=p;try{let h;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(h=z(t,a));const m=T(l.enableIf,t,h),f=c.getAttribute("data-conditionally-disabled")==="true";if(m&&f){const v=a?z(t,a):t,g=Z(l,{path:a,prefill:v&&typeof v=="object"?v:{},formData:t,state:this.state,instance:this});(i=c.parentNode)==null||i.replaceChild(g,c)}else if(!m&&!f){const v=document.createElement("div");v.className="fb-field-wrapper-disabled",v.style.display="none",v.setAttribute("data-field-key",l.key),v.setAttribute("data-conditionally-disabled","true"),(s=c.parentNode)==null||s.replaceChild(v,c)}}catch(h){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${u}":`,h)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const p=t==null?void 0:t[l.key];Array.isArray(p)?p.forEach((c,h)=>{n(l.elements,`${u}[${h}]`)}):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&&M(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 Le(e){return new O(e)}return typeof window!="undefined"&&(window.FormBuilder=O,window.createFormBuilder=Le,window.validateSchema=U),N.FormBuilderInstance=O,N.createFormBuilder=Le,N.default=O,N.defaultTheme=H,N.exampleThemes=Ht,N.validateSchema=U,Object.defineProperty(N,"__esModule",{value:!0}),N})({});
358
+ `,t.forEach(l=>{const r=document.createElement("button");r.type="button",we(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 p=document.createElement("div");p.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(r);l.forEach(h=>{const f=document.createElement("button");f.type="button",we(f,!1);const m=this.resolveActionLabel(h.key,h.label,c);f.textContent=m,f.addEventListener("click",v=>{v.preventDefault(),v.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(h.value,h.key,h.related_field)}),p.appendChild(f)}),s.appendChild(p)});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,M(t),t.setAttribute("data-fb-root","true"),Mt(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 p=Z(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});i.appendChild(p)}),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},p=zt(l,s,u);return p!==null?(n.push(...p.errors),p.value):(console.warn(`Unknown field type "${l.type}" for key "${s}"`),null)};return bt(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!T(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:""};It(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 p=null;if(a){const c=a.match(/^(.+)\[(\d+)\]$/);if(c){const h=c[1],f=c[2],m=this.state.formRoot.querySelector(`[data-container-item="${h}[${f}]"]`);m&&(p=m.querySelector(`[data-field-key="${l.key}"]`))}else{const h=this.state.formRoot.querySelector(`[data-container="${a}"]`);h&&(p=h.querySelector(`[data-field-key="${l.key}"]`))}}else p=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(p){const c=p;try{let h;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(h=z(t,a));const f=T(l.enableIf,t,h),m=c.getAttribute("data-conditionally-disabled")==="true";if(f&&m){const v=a?z(t,a):t,g=Z(l,{path:a,prefill:v&&typeof v=="object"?v:{},formData:t,state:this.state,instance:this});(i=c.parentNode)==null||i.replaceChild(g,c)}else if(!f&&!m){const v=document.createElement("div");v.className="fb-field-wrapper-disabled",v.style.display="none",v.setAttribute("data-field-key",l.key),v.setAttribute("data-conditionally-disabled","true"),(s=c.parentNode)==null||s.replaceChild(v,c)}}catch(h){console.error(`Error re-evaluating enableIf for field "${l.key}" at path "${u}":`,h)}}}if((l.type==="container"||l.type==="group")&&"elements"in l&&l.elements){const p=t==null?void 0:t[l.key];Array.isArray(p)?p.forEach((c,h)=>{n(l.elements,`${u}[${h}]`)}):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&&M(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 Le(e){return new O(e)}return typeof window!="undefined"&&(window.FormBuilder=O,window.createFormBuilder=Le,window.validateSchema=U),N.FormBuilderInstance=O,N.createFormBuilder=Le,N.default=O,N.defaultTheme=H,N.exampleThemes=Ht,N.validateSchema=U,Object.defineProperty(N,"__esModule",{value:!0}),N})({});