@dmitryvim/form-builder 0.2.19 → 0.2.20

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.
@@ -0,0 +1,583 @@
1
+ var FormBuilder=(function(de){"use strict";function L(e,t,n){const o=t.config.locale||"en",a=t.config.translations[o],l=t.config.translations.en;let r=(a==null?void 0:a[e])||(l==null?void 0:l[e])||e;if(n)for(const[s,c]of Object.entries(n))r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(c));return r}function Pt(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push(L("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push(L("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push(L("hintMinLength",n,{min:e.minLength})))}function Vt(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push(L("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push(L("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push(L("hintMinValue",n,{min:e.min})))}function _t(e,t,n){e.maxSizeMB&&t.push(L("hintMaxSize",n,{size:e.maxSizeMB}))}function Wt(e,t,n){var o;(o=e.accept)!=null&&o.extensions&&t.push(L("hintFormats",n,{formats:e.accept.extensions.map(a=>a.toUpperCase()).join(",")}))}function Kt(e,t,n){e.pattern&&t.push(L("hintPattern",n,{pattern:e.pattern}))}function ue(e,t){const n=[];return Pt(e,n,t),e.type!=="slider"&&Vt(e,n,t),_t(e,n,t),Wt(e,n,t),Kt(e,n,t),n.join(" \u2022 ")}function Ie(e){const t=[];if(!e||typeof e!="object")return t.push("Schema must be an object"),t;if(!Array.isArray(e.elements))return t.push("Schema missing elements array"),t;if("columns"in e&&e.columns!==void 0){const o=e.columns,a=[1,2,3,4];(!Number.isInteger(o)||!a.includes(o))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${o})`)}if("prefillHints"in e&&e.prefillHints){const o=e.prefillHints;Array.isArray(o)&&o.forEach((a,l)=>{if((!a.label||typeof a.label!="string")&&t.push(`schema.prefillHints[${l}] must have a 'label' property of type string`),!a.values||typeof a.values!="object")t.push(`schema.prefillHints[${l}] must have a 'values' property of type object`);else for(const r in a.values)e.elements.some(s=>s.key===r)||t.push(`schema.prefillHints[${l}] references non-existent field "${r}"`)})}function n(o,a){o.forEach((l,r)=>{const s=`${a}[${r}]`;if(l.type||t.push(`${s}: missing type`),l.key||t.push(`${s}: missing key`),l.enableIf){const c=l.enableIf;(!c.key||typeof c.key!="string")&&t.push(`${s}: enableIf must have a 'key' property of type string`),"equals"in c||t.push(`${s}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&n(l.elements,`${s}.elements`),l.type==="container"&&l.elements){if("columns"in l&&l.columns!==void 0){const c=l.columns,u=[1,2,3,4];(!Number.isInteger(c)||!u.includes(c))&&t.push(`${s}: columns must be 1, 2, 3, or 4 (got ${c})`)}if("prefillHints"in l&&l.prefillHints){const c=l.prefillHints;Array.isArray(c)&&c.forEach((u,d)=>{if((!u.label||typeof u.label!="string")&&t.push(`${s}: prefillHints[${d}] must have a 'label' property of type string`),!u.values||typeof u.values!="object")t.push(`${s}: prefillHints[${d}] must have a 'values' property of type object`);else for(const i in u.values)l.elements.some(h=>h.key===i)||t.push(`container "${l.key}": prefillHints[${d}] references non-existent field "${i}"`)})}n(l.elements,`${s}.elements`)}if(l.type==="select"&&l.options){const c=l.default;c!=null&&c!==""&&(l.options.some(u=>u.value===c)||t.push(`${s}: default "${c}" not in options`))}})}return Array.isArray(e.elements)&&n(e.elements,"elements"),t}function $e(e){return e&&typeof e=="object"&&e.constructor===Object}function _(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function ge(e,t){return e?`${e}.${t}`:t}function ie(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function Jt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Be(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let o=e;for(const a of n){if(o==null)return;if(a.startsWith("[")&&a.endsWith("]")){const l=parseInt(a.slice(1,-1),10);if(!Array.isArray(o)||isNaN(l))return;o=o[l]}else o=o[a]}return o}function be(e,t,n){var o;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const a=(o=e.scope)!=null?o:"relative";let l;if(a==="relative")l=n!=null?n:t;else if(a==="absolute")l=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${a}")`);const r=Be(l,e.key);if("equals"in e)return Yt(r,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function Yt(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e=="object"&&typeof t=="object")try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){if(n instanceof TypeError&&(n.message.includes("circular")||n.message.includes("cyclic")))return console.warn("deepEqual: Circular reference detected in enableIf comparison, using reference equality"),e===t;throw n}return e===t}function Ce(e,t,n=!1){const o=document.createElement("span");o.className="char-counter",o.style.cssText=`
2
+ position: absolute;
3
+ ${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
4
+ right: 10px;
5
+ font-size: var(--fb-font-size-small);
6
+ color: var(--fb-text-secondary-color);
7
+ pointer-events: none;
8
+ background: var(--fb-background-color);
9
+ padding: 0 4px;
10
+ `;const a=()=>{const l=t.value.length,r=e.minLength,s=e.maxLength;if(r==null&&s==null){o.textContent="";return}l===0||r!=null&&l<r?(r!=null&&s!=null?o.textContent=`${r}-${s}`:s!=null?o.textContent=`\u2264${s}`:r!=null&&(o.textContent=`\u2265${r}`),o.style.color="var(--fb-text-secondary-color)"):s!=null&&l>s?(o.textContent=`${l}/${s}`,o.style.color="var(--fb-error-color)"):(s!=null?o.textContent=`${l}/${s}`:o.textContent=`${l}`,o.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",a),a(),o}function Xt(e,t,n,o){const a=t.state,l=document.createElement("div");l.style.cssText="position: relative;";const r=document.createElement("input");if(r.type="text",r.className="w-full rounded-lg",r.style.cssText=`
11
+ padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
12
+ padding-right: 60px;
13
+ border: var(--fb-border-width) solid var(--fb-border-color);
14
+ border-radius: var(--fb-border-radius);
15
+ background-color: ${a.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
16
+ color: var(--fb-text-color);
17
+ font-size: var(--fb-font-size);
18
+ font-family: var(--fb-font-family);
19
+ transition: all var(--fb-transition-duration) ease-in-out;
20
+ width: 100%;
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 s=()=>{const c=r.value===""?null:r.value;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",s),r.addEventListener("input",s)}if(l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const s=Ce(e,r,!1);l.appendChild(s)}n.appendChild(l)}function Gt(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],c=Array.isArray(s)?[...s]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function h(){i.querySelectorAll(".multiple-text-item").forEach((f,b)=>{const x=f.querySelector("input");x&&(x.name=`${o}[${b}]`)})}function p(f="",b=-1){const x=document.createElement("div");x.className="multiple-text-item flex items-center gap-2";const y=document.createElement("div");y.style.cssText="position: relative; flex: 1;";const E=document.createElement("input");if(E.type="text",E.style.cssText=`
23
+ padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
24
+ padding-right: 60px;
25
+ border: var(--fb-border-width) solid var(--fb-border-color);
26
+ border-radius: var(--fb-border-radius);
27
+ background-color: ${r.config.readonly?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
28
+ color: var(--fb-text-color);
29
+ font-size: var(--fb-font-size);
30
+ font-family: var(--fb-font-family);
31
+ transition: all var(--fb-transition-duration) ease-in-out;
32
+ width: 100%;
33
+ box-sizing: border-box;
34
+ `,E.placeholder=e.placeholder||L("placeholderText",r),E.value=f,E.readOnly=r.config.readonly,r.config.readonly||(E.addEventListener("focus",()=>{E.style.borderColor="var(--fb-border-focus-color)",E.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",E.style.outlineOffset="0"}),E.addEventListener("blur",()=>{E.style.borderColor="var(--fb-border-color)",E.style.outline="none"}),E.addEventListener("mouseenter",()=>{document.activeElement!==E&&(E.style.borderColor="var(--fb-border-hover-color)")}),E.addEventListener("mouseleave",()=>{document.activeElement!==E&&(E.style.borderColor="var(--fb-border-color)")})),!r.config.readonly&&t.instance){const S=()=>{const A=E.value===""?null:E.value;t.instance.triggerOnChange(E.name,A)};E.addEventListener("blur",S),E.addEventListener("input",S)}if(y.appendChild(E),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const S=Ce(e,E,!1);y.appendChild(S)}return x.appendChild(y),b===-1?i.appendChild(x):i.insertBefore(x,i.children[b]),h(),x}function m(){if(r.config.readonly)return;const f=i.querySelectorAll(".multiple-text-item"),b=f.length;f.forEach(x=>{let y=x.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 rounded",y.style.cssText=`
35
+ color: var(--fb-error-color);
36
+ background-color: transparent;
37
+ transition: background-color var(--fb-transition-duration);
38
+ `,y.innerHTML="\u2715",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{const S=Array.from(i.children).indexOf(x);i.children.length>u&&(c.splice(S,1),x.remove(),h(),C(),m())},x.appendChild(y));const E=b<=u;y.disabled=E,y.style.opacity=E?"0.5":"1",y.style.pointerEvents=E?"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 f=document.createElement("button");f.type="button",f.className="add-text-btn px-3 py-1 rounded",f.style.cssText=`
39
+ color: var(--fb-primary-color);
40
+ border: var(--fb-border-width) solid var(--fb-primary-color);
41
+ background-color: transparent;
42
+ font-size: var(--fb-font-size);
43
+ transition: all var(--fb-transition-duration);
44
+ `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{c.push(e.default||""),p(e.default||""),C(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(f),v.appendChild(g),n.appendChild(v)}function C(){if(!v||!g)return;const f=v.querySelector(".add-text-btn");if(f){const b=c.length>=d;f.disabled=b,f.style.opacity=b?"0.5":"1",f.style.pointerEvents=b?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(f=>p(f)),C(),m()}function Qe(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:c}=n,u=(i,h)=>{var p,m;if(!i)return;const v=`error-${i.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(i.classList.add("invalid"),i.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
45
+ color: var(--fb-error-color);
46
+ font-size: var(--fb-font-size-small);
47
+ margin-top: 0.25rem;
48
+ `,i.nextSibling?(p=i.parentNode)==null||p.insertBefore(g,i.nextSibling):(m=i.parentNode)==null||m.appendChild(g)),g.textContent=h,g.style.display="block"):(i.classList.remove("invalid"),i.title="",g&&g.remove())},d=(i,h,p)=>{let m=!1;const{state:v}=n;if(!c&&h){if(e.minLength!==void 0&&e.minLength!==null&&h.length<e.minLength){const g=L("minLength",v,{min:e.minLength});r.push(`${p}: ${g}`),u(i,g),m=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&h.length>e.maxLength){const g=L("maxLength",v,{max:e.maxLength});r.push(`${p}: ${g}`),u(i,g),m=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(h)){const g=L("patternMismatch",v);r.push(`${p}: ${g}`),u(i,g),m=!0}}catch(g){const C=L("invalidPattern",v);r.push(`${p}: ${C}`),u(i,C),m=!0}}m||u(i,null)};if(e.multiple){const i=s.querySelectorAll(`[name^="${t}["]`),h=[],p=[];if(i.forEach((m,v)=>{var g;const C=(g=m==null?void 0:m.value)!=null?g:"";p.push(C),h.push(C===""?null:C),d(m,C,`${t}[${v}]`)}),!c){const{state:m}=n,v=(o=e.minCount)!=null?o:1,g=(a=e.maxCount)!=null?a:1/0,C=p.filter(f=>f.trim()!=="");e.required&&C.length===0&&r.push(`${t}: ${L("required",m)}`),C.length<v&&r.push(`${t}: ${L("minItems",m,{min:v})}`),C.length>g&&r.push(`${t}: ${L("maxItems",m,{max:g})}`)}return{value:h,errors:r}}else{const i=s.querySelector(`[name$="${t}"]`),h=(l=i==null?void 0:i.value)!=null?l:"";if(!c&&e.required&&h===""){const p=L("required",n.state);return r.push(`${t}: ${p}`),u(i,p),{value:null,errors:r}}return i&&d(i,h,t),{value:h===""?null:h,errors:r}}}function et(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,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",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 tt(e){e.style.overflow="hidden",e.style.resize="none";const t=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(1,t);const n=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`)};e.addEventListener("input",n),setTimeout(()=>{e.isConnected&&n()},0)}function Zt(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 s=()=>{const c=r.value===""?null:r.value;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",s),r.addEventListener("input",s)}if((e.autoExpand||a.config.readonly)&&tt(r),l.appendChild(r),!a.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const s=Ce(e,r,!0);l.appendChild(s)}n.appendChild(l)}function Qt(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],c=Array.isArray(s)?[...s]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function h(){i.querySelectorAll(".multiple-textarea-item").forEach((f,b)=>{const x=f.querySelector("textarea");x&&(x.name=`${o}[${b}]`)})}function p(f="",b=-1){const x=document.createElement("div");x.className="multiple-textarea-item";const y=document.createElement("div");y.style.cssText="position: relative;";const E=document.createElement("textarea");if(E.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",E.style.cssText="padding-bottom: 24px;",E.placeholder=e.placeholder||L("placeholderText",r),E.rows=e.rows||4,E.value=f,E.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const S=()=>{const A=E.value===""?null:E.value;t.instance.triggerOnChange(E.name,A)};E.addEventListener("blur",S),E.addEventListener("input",S)}if((e.autoExpand||r.config.readonly)&&tt(E),y.appendChild(E),!r.config.readonly&&(e.minLength!=null||e.maxLength!=null)){const S=Ce(e,E,!0);y.appendChild(S)}return x.appendChild(y),b===-1?i.appendChild(x):i.insertBefore(x,i.children[b]),h(),x}function m(){if(r.config.readonly)return;const f=i.querySelectorAll(".multiple-textarea-item"),b=f.length;f.forEach(x=>{let y=x.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",y.innerHTML="\u2715",y.onclick=()=>{const S=Array.from(i.children).indexOf(x);i.children.length>u&&(c.splice(S,1),x.remove(),h(),C(),m())},x.appendChild(y));const E=b<=u;y.disabled=E,y.style.opacity=E?"0.5":"1",y.style.pointerEvents=E?"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 f=document.createElement("button");f.type="button",f.className="add-textarea-btn px-3 py-1 rounded",f.style.cssText=`
49
+ color: var(--fb-primary-color);
50
+ border: var(--fb-border-width) solid var(--fb-primary-color);
51
+ background-color: transparent;
52
+ font-size: var(--fb-font-size);
53
+ transition: all var(--fb-transition-duration);
54
+ `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{c.push(e.default||""),p(e.default||""),C(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(f),v.appendChild(g),n.appendChild(v)}function C(){if(!v||!g)return;const f=v.querySelector(".add-textarea-btn");if(f){const b=c.length>=d;f.disabled=b,f.style.opacity=b?"0.5":"1",f.style.pointerEvents=b?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(f=>p(f)),C(),m()}function en(e,t,n){return Qe(e,t,n)}function tn(e,t,n,o){et(e,t,n,o);const{scopeRoot:a,state:l}=o;if(e.autoExpand||l.config.readonly)if(e.multiple)a.querySelectorAll(`textarea[name^="${t}["]`).forEach(r=>{r.dispatchEvent(new Event("input"))});else{const r=a.querySelector(`textarea[name="${t}"]`);r&&r.dispatchEvent(new Event("input"))}}function nt(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
55
+ position: absolute;
56
+ top: 50%;
57
+ transform: translateY(-50%);
58
+ right: 10px;
59
+ font-size: var(--fb-font-size-small);
60
+ color: var(--fb-text-secondary-color);
61
+ pointer-events: none;
62
+ background: var(--fb-background-color);
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 s=t.value?parseFloat(t.value):null;if(s!=null){const c=o!=null&&s<o,u=a!=null&&s>a;n.style.color=c||u?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",r),r(),n}function nn(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 s=()=>{const c=r.value?parseFloat(r.value):null;t.instance.triggerOnChange(o,c)};r.addEventListener("blur",s),r.addEventListener("input",s)}if(l.appendChild(r),!a.config.readonly&&(e.min!=null||e.max!=null)){const s=nt(e,r);l.appendChild(s)}n.appendChild(l)}function rn(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],c=Array.isArray(s)?[...s]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function h(){i.querySelectorAll(".multiple-number-item").forEach((f,b)=>{const x=f.querySelector("input");x&&(x.name=`${o}[${b}]`)})}function p(f="",b=-1){const x=document.createElement("div");x.className="multiple-number-item flex items-center gap-2";const y=document.createElement("div");y.style.cssText="position: relative; flex: 1;";const E=document.createElement("input");if(E.type="number",E.className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",E.style.cssText="padding-right: 60px; width: 100%; box-sizing: border-box;",E.placeholder=e.placeholder||"0",e.min!==void 0&&(E.min=e.min.toString()),e.max!==void 0&&(E.max=e.max.toString()),e.step!==void 0&&(E.step=e.step.toString()),E.value=f.toString(),E.readOnly=r.config.readonly,!r.config.readonly&&t.instance){const S=()=>{const A=E.value?parseFloat(E.value):null;t.instance.triggerOnChange(E.name,A)};E.addEventListener("blur",S),E.addEventListener("input",S)}if(y.appendChild(E),!r.config.readonly&&(e.min!=null||e.max!=null)){const S=nt(e,E);y.appendChild(S)}return x.appendChild(y),b===-1?i.appendChild(x):i.insertBefore(x,i.children[b]),h(),x}function m(){if(r.config.readonly)return;const f=i.querySelectorAll(".multiple-number-item"),b=f.length;f.forEach(x=>{let y=x.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",y.innerHTML="\u2715",y.onclick=()=>{const S=Array.from(i.children).indexOf(x);i.children.length>u&&(c.splice(S,1),x.remove(),h(),C(),m())},x.appendChild(y));const E=b<=u;y.disabled=E,y.style.opacity=E?"0.5":"1",y.style.pointerEvents=E?"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 f=document.createElement("button");f.type="button",f.className="add-number-btn px-3 py-1 rounded",f.style.cssText=`
65
+ color: var(--fb-primary-color);
66
+ border: var(--fb-border-width) solid var(--fb-primary-color);
67
+ background-color: transparent;
68
+ font-size: var(--fb-font-size);
69
+ transition: all var(--fb-transition-duration);
70
+ `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{c.push(e.default||""),p(e.default||""),C(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(f),v.appendChild(g),n.appendChild(v)}function C(){if(!v||!g)return;const f=v.querySelector(".add-number-btn");if(f){const b=c.length>=d;f.disabled=b,f.style.opacity=b?"0.5":"1",f.style.pointerEvents=b?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}c.forEach(f=>p(f)),C(),m()}function on(e,t,n){var o,a,l,r,s;const c=[],{scopeRoot:u,skipValidation:d}=n,i=(p,m)=>{var v,g;if(!p)return;const C=`error-${p.getAttribute("name")||Math.random().toString(36).substring(7)}`;let f=document.getElementById(C);m?(p.classList.add("invalid"),p.title=m,f||(f=document.createElement("div"),f.id=C,f.className="error-message",f.style.cssText=`
71
+ color: var(--fb-error-color);
72
+ font-size: var(--fb-font-size-small);
73
+ margin-top: 0.25rem;
74
+ `,p.nextSibling?(v=p.parentNode)==null||v.insertBefore(f,p.nextSibling):(g=p.parentNode)==null||g.appendChild(f)),f.textContent=m,f.style.display="block"):(p.classList.remove("invalid"),p.title="",f&&f.remove())},h=(p,m,v)=>{let g=!1;const{state:C}=n;if(!d&&e.min!==void 0&&e.min!==null&&m<e.min){const f=L("minValue",C,{min:e.min});c.push(`${v}: ${f}`),i(p,f),g=!0}else if(!d&&e.max!==void 0&&e.max!==null&&m>e.max){const f=L("maxValue",C,{max:e.max});c.push(`${v}: ${f}`),i(p,f),g=!0}g||i(p,null)};if(e.multiple){const p=u.querySelectorAll(`[name^="${t}["]`),m=[];if(p.forEach((v,g)=>{var C,f,b;const x=(C=v==null?void 0:v.value)!=null?C:"";if(x===""){m.push(null),i(v,null);return}const y=parseFloat(x);if(!d&&!Number.isFinite(y)){const S=L("notANumber",n.state);c.push(`${t}[${g}]: ${S}`),i(v,S),m.push(null);return}h(v,y,`${t}[${g}]`);const E=Number.isInteger((f=e.decimals)!=null?f:0)&&(b=e.decimals)!=null?b:0;m.push(Number(y.toFixed(E)))}),!d){const{state:v}=n,g=(o=e.minCount)!=null?o:1,C=(a=e.maxCount)!=null?a:1/0,f=m.filter(b=>b!==null);e.required&&f.length===0&&c.push(`${t}: ${L("required",v)}`),f.length<g&&c.push(`${t}: ${L("minItems",v,{min:g})}`),f.length>C&&c.push(`${t}: ${L("maxItems",v,{max:C})}`)}return{value:m,errors:c}}else{const p=u.querySelector(`[name$="${t}"]`),m=(l=p==null?void 0:p.value)!=null?l:"",{state:v}=n;if(!d&&e.required&&m===""){const f=L("required",v);return c.push(`${t}: ${f}`),i(p,f),{value:null,errors:c}}if(m==="")return i(p,null),{value:null,errors:c};const g=parseFloat(m);if(!d&&!Number.isFinite(g)){const f=L("notANumber",v);return c.push(`${t}: ${f}`),i(p,f),{value:null,errors:c}}h(p,g,t);const C=Number.isInteger((r=e.decimals)!=null?r:0)&&(s=e.decimals)!=null?s:0;return{value:Number(g.toFixed(C)),errors:c}}}function ln(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,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",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 an(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 s=document.createElement("option");s.value=r.value,s.textContent=r.label,(t.prefill[e.key]||e.default)===r.value&&(s.selected=!0),l.appendChild(s)}),!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=ue(e,a),n.appendChild(r)}}function sn(e,t,n,o){var a,l,r,s;const c=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],i=(a=e.minCount)!=null?a:1,h=(l=e.maxCount)!=null?l:1/0;for(;d.length<i;)d.push(e.default||((s=(r=e.options)==null?void 0:r[0])==null?void 0:s.value)||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function m(){p.querySelectorAll(".multiple-select-item").forEach((x,y)=>{const E=x.querySelector("select");E&&(E.name=`${o}[${y}]`)})}function v(x="",y=-1){const E=document.createElement("div");E.className="multiple-select-item flex items-center gap-2";const S=document.createElement("select");if(S.className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",S.disabled=c.config.readonly,(e.options||[]).forEach(A=>{const z=document.createElement("option");z.value=A.value,z.textContent=A.label,x===A.value&&(z.selected=!0),S.appendChild(z)}),!c.config.readonly&&t.instance){const A=()=>{t.instance.triggerOnChange(S.name,S.value)};S.addEventListener("change",A)}return E.appendChild(S),y===-1?p.appendChild(E):p.insertBefore(E,p.children[y]),m(),E}function g(){if(c.config.readonly)return;const x=p.querySelectorAll(".multiple-select-item"),y=x.length;x.forEach(E=>{let S=E.querySelector(".remove-item-btn");S||(S=document.createElement("button"),S.type="button",S.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",S.innerHTML="\u2715",S.onclick=()=>{const z=Array.from(p.children).indexOf(E);p.children.length>i&&(d.splice(z,1),E.remove(),m(),b(),g())},E.appendChild(S));const A=y<=i;S.disabled=A,S.style.opacity=A?"0.5":"1",S.style.pointerEvents=A?"none":"auto"})}let C=null,f=null;if(!c.config.readonly){C=document.createElement("div"),C.className="flex items-center gap-3 mt-2";const x=document.createElement("button");x.type="button",x.className="add-select-btn px-3 py-1 rounded",x.style.cssText=`
75
+ color: var(--fb-primary-color);
76
+ border: var(--fb-border-width) solid var(--fb-primary-color);
77
+ background-color: transparent;
78
+ font-size: var(--fb-font-size);
79
+ transition: all var(--fb-transition-duration);
80
+ `,x.textContent="+",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{var y,E;const S=e.default||((E=(y=e.options)==null?void 0:y[0])==null?void 0:E.value)||"";d.push(S),v(S),b(),g()},f=document.createElement("span"),f.className="text-sm text-gray-500",C.appendChild(x),C.appendChild(f),n.appendChild(C)}function b(){if(!C||!f)return;const x=C.querySelector(".add-select-btn");if(x){const y=d.length>=h;x.disabled=y,x.style.opacity=y?"0.5":"1",x.style.pointerEvents=y?"none":"auto"}f.textContent=`${d.length}/${h===1/0?"\u221E":h}`}if(d.forEach(x=>v(x)),b(),g(),!c.config.readonly){const x=document.createElement("p");x.className="text-xs text-gray-500 mt-1",x.textContent=ue(e,c),n.appendChild(x)}}function cn(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,s=(u,d)=>{var i,h;if(!u)return;const p=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(p);d?(u.classList.add("invalid"),u.title=d,m||(m=document.createElement("div"),m.id=p,m.className="error-message",m.style.cssText=`
81
+ color: var(--fb-error-color);
82
+ font-size: var(--fb-font-size-small);
83
+ margin-top: 0.25rem;
84
+ `,u.nextSibling?(i=u.parentNode)==null||i.insertBefore(m,u.nextSibling):(h=u.parentNode)==null||h.appendChild(m)),m.textContent=d,m.style.display="block"):(u.classList.remove("invalid"),u.title="",m&&m.remove())},c=(u,d,i,h)=>{var p,m;if(r)return;const{state:v}=n,g=d.filter(h),C="minCount"in i&&(p=i.minCount)!=null?p:1,f="maxCount"in i&&(m=i.maxCount)!=null?m:1/0;i.required&&g.length===0&&a.push(`${u}: ${L("required",v)}`),g.length<C&&a.push(`${u}: ${L("minItems",v,{min:C})}`),g.length>f&&a.push(`${u}: ${L("maxItems",v,{max:f})}`)};if("multiple"in e&&e.multiple){const u=l.querySelectorAll(`[name^="${t}["]`),d=[];return u.forEach(i=>{var h;const p=(h=i==null?void 0:i.value)!=null?h:"";d.push(p),s(i,null)}),c(t,d,e,i=>i!==""),{value:d,errors:a}}else{const u=l.querySelector(`[name$="${t}"]`),d=(o=u==null?void 0:u.value)!=null?o:"";if(!r&&e.required&&d===""){const i=L("required",n.state);return a.push(`${t}: ${i}`),s(u,i),{value:null,errors:a}}else s(u,null);return{value:d===""?null:d,errors:a}}}function un(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,s)=>{s<n.length&&(r.value=n[s]!=null?String(n[s]):"",r.querySelectorAll("option").forEach(c=>{c.selected=c.value===String(n[s])}),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 Le(e){e.style.backgroundColor="var(--fb-primary-color)",e.style.color="#ffffff",e.style.borderColor="var(--fb-primary-color)"}function Se(e){e.style.backgroundColor="transparent",e.style.color="var(--fb-text-color)",e.style.borderColor="var(--fb-border-color)"}function rt(e,t,n,o,a){const l=e.options||[],r=document.createElement("div");r.className="fb-switcher-group",r.style.cssText=`
85
+ display: inline-flex;
86
+ flex-direction: row;
87
+ flex-wrap: nowrap;
88
+ `;const s=[];return l.forEach((c,u)=>{const d=document.createElement("button");d.type="button",d.className="fb-switcher-btn",d.dataset.value=c.value,d.textContent=c.label,d.style.cssText=`
89
+ padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
90
+ font-size: var(--fb-font-size);
91
+ border-width: var(--fb-border-width);
92
+ border-style: solid;
93
+ cursor: ${o?"default":"pointer"};
94
+ transition: background-color var(--fb-transition-duration), color var(--fb-transition-duration), border-color var(--fb-transition-duration);
95
+ white-space: nowrap;
96
+ line-height: 1.25;
97
+ outline: none;
98
+ `,l.length===1?d.style.borderRadius="var(--fb-border-radius)":u===0?(d.style.borderRadius="var(--fb-border-radius) 0 0 var(--fb-border-radius)",d.style.borderRightWidth="0"):u===l.length-1?d.style.borderRadius="0 var(--fb-border-radius) var(--fb-border-radius) 0":(d.style.borderRadius="0",d.style.borderRightWidth="0"),c.value===t?Le(d):Se(d),o||(d.addEventListener("click",()=>{n.value=c.value,s.forEach(i=>{i.dataset.value===c.value?Le(i):Se(i)}),a&&a(c.value)}),d.addEventListener("mouseenter",()=>{n.value!==c.value&&(d.style.backgroundColor="var(--fb-background-hover-color)")}),d.addEventListener("mouseleave",()=>{n.value!==c.value&&(d.style.backgroundColor="transparent")})),s.push(d),r.appendChild(d)}),r}function dn(e,t,n,o){var a,l;const r=t.state,s=String((l=(a=t.prefill[e.key])!=null?a:e.default)!=null?l:""),c=document.createElement("input");c.type="hidden",c.name=o,c.value=s;const u=r.config.readonly,d=!u&&t.instance?h=>{t.instance.triggerOnChange(o,h)}:null,i=rt(e,s,c,u,d);if(n.appendChild(c),n.appendChild(i),!u){const h=document.createElement("p");h.className="text-xs text-gray-500 mt-1",h.textContent=ue(e,r),n.appendChild(h)}}function pn(e,t,n,o){var a,l,r,s;const c=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],i=(a=e.minCount)!=null?a:1,h=(l=e.maxCount)!=null?l:1/0;for(;d.length<i;)d.push(e.default||((s=(r=e.options)==null?void 0:r[0])==null?void 0:s.value)||"");const p=c.config.readonly,m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function v(){m.querySelectorAll(".multiple-switcher-item").forEach((y,E)=>{const S=y.querySelector("input[type=hidden]");S&&(S.name=`${o}[${E}]`)})}function g(y="",E=-1){const S=E===-1?m.children.length:E,A=`${o}[${S}]`,z=document.createElement("div");z.className="multiple-switcher-item flex items-center gap-2";const X=document.createElement("input");X.type="hidden",X.name=A,X.value=y,z.appendChild(X);const Z=!p&&t.instance?he=>{t.instance.triggerOnChange(X.name,he)}:null,G=rt(e,y,X,p,Z);return z.appendChild(G),E===-1?m.appendChild(z):m.insertBefore(z,m.children[E]),v(),z}function C(){if(p)return;const y=m.querySelectorAll(".multiple-switcher-item"),E=y.length;y.forEach(S=>{let A=S.querySelector(".remove-item-btn");A||(A=document.createElement("button"),A.type="button",A.className="remove-item-btn px-2 py-1 rounded",A.style.cssText=`
99
+ color: var(--fb-error-color);
100
+ background-color: transparent;
101
+ transition: background-color var(--fb-transition-duration);
102
+ `,A.innerHTML="\u2715",A.addEventListener("mouseenter",()=>{A.style.backgroundColor="var(--fb-background-hover-color)"}),A.addEventListener("mouseleave",()=>{A.style.backgroundColor="transparent"}),A.onclick=()=>{const X=Array.from(m.children).indexOf(S);m.children.length>i&&(d.splice(X,1),S.remove(),v(),x(),C())},S.appendChild(A));const z=E<=i;A.disabled=z,A.style.opacity=z?"0.5":"1",A.style.pointerEvents=z?"none":"auto"})}let f=null,b=null;if(!p){f=document.createElement("div"),f.className="flex items-center gap-3 mt-2";const y=document.createElement("button");y.type="button",y.className="add-switcher-btn px-3 py-1 rounded",y.style.cssText=`
103
+ color: var(--fb-primary-color);
104
+ border: var(--fb-border-width) solid var(--fb-primary-color);
105
+ background-color: transparent;
106
+ font-size: var(--fb-font-size);
107
+ transition: all var(--fb-transition-duration);
108
+ `,y.textContent="+",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{var E,S;const A=e.default||((S=(E=e.options)==null?void 0:E[0])==null?void 0:S.value)||"";d.push(A),g(A),x(),C()},b=document.createElement("span"),b.className="text-sm text-gray-500",f.appendChild(y),f.appendChild(b),n.appendChild(f)}function x(){if(!f||!b)return;const y=f.querySelector(".add-switcher-btn");if(y){const E=d.length>=h;y.disabled=E,y.style.opacity=E?"0.5":"1",y.style.pointerEvents=E?"none":"auto"}b.textContent=`${d.length}/${h===1/0?"\u221E":h}`}if(d.forEach(y=>g(y)),x(),C(),!p){const y=document.createElement("p");y.className="text-xs text-gray-500 mt-1",y.textContent=ue(e,c),n.appendChild(y)}}function fn(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r}=n,s=(d,i)=>{var h,p;if(!d)return;const m=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let v=document.getElementById(m);i?(d.classList.add("invalid"),d.title=i,v||(v=document.createElement("div"),v.id=m,v.className="error-message",v.style.cssText=`
109
+ color: var(--fb-error-color);
110
+ font-size: var(--fb-font-size-small);
111
+ margin-top: 0.25rem;
112
+ `,d.nextSibling?(h=d.parentNode)==null||h.insertBefore(v,d.nextSibling):(p=d.parentNode)==null||p.appendChild(v)),v.textContent=i,v.style.display="block"):(d.classList.remove("invalid"),d.title="",v&&v.remove())},c=(d,i,h,p)=>{var m,v;if(r)return;const{state:g}=n,C=i.filter(p),f="minCount"in h&&(m=h.minCount)!=null?m:1,b="maxCount"in h&&(v=h.maxCount)!=null?v:1/0;h.required&&C.length===0&&a.push(`${d}: ${L("required",g)}`),C.length<f&&a.push(`${d}: ${L("minItems",g,{min:f})}`),C.length>b&&a.push(`${d}: ${L("maxItems",g,{max:b})}`)},u=new Set("options"in e?e.options.map(d=>d.value):[]);if("multiple"in e&&e.multiple){const d=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`),i=[];return d.forEach(h=>{var p;const m=(p=h==null?void 0:h.value)!=null?p:"";if(i.push(m),!r&&m!==""&&!u.has(m)){const v=L("invalidOption",n.state);s(h,v),a.push(`${t}: ${v}`)}else s(h,null)}),c(t,i,e,h=>h!==""),{value:i,errors:a}}else{const d=l.querySelector(`input[type="hidden"][name$="${t}"]`),i=(o=d==null?void 0:d.value)!=null?o:"";if(!r&&e.required&&i===""){const h=L("required",n.state);return a.push(`${t}: ${h}`),s(d,h),{value:null,errors:a}}if(!r&&i!==""&&!u.has(i)){const h=L("invalidOption",n.state);return a.push(`${t}: ${h}`),s(d,h),{value:null,errors:a}}return s(d,null),{value:i===""?null:i,errors:a}}}function mn(e,t,n,o){var a;const{scopeRoot:l}=o;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSwitcherField: Expected array for multiple field "${t}", got ${typeof n}`);return}const r=l.querySelectorAll(`input[type="hidden"][name^="${t}["]`);r.forEach((s,c)=>{var u;if(c<n.length){const d=n[c]!=null?String(n[c]):"";s.value=d;const i=(u=s.parentElement)==null?void 0:u.querySelector(".fb-switcher-group");i&&i.querySelectorAll(".fb-switcher-btn").forEach(h=>{h.dataset.value===d?Le(h):Se(h)}),s.classList.remove("invalid"),s.title=""}}),n.length!==r.length&&console.warn(`updateSwitcherField: Multiple field "${t}" has ${r.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const r=l.querySelector(`input[type="hidden"][name="${t}"]`);if(r){const s=n!=null?String(n):"";r.value=s;const c=(a=r.parentElement)==null?void 0:a.querySelector(".fb-switcher-group");c&&c.querySelectorAll(".fb-switcher-btn").forEach(u=>{u.dataset.value===s?Le(u):Se(u)}),r.classList.remove("invalid"),r.title=""}}}function hn(e,t,n,o){const a=document.createElement("img");a.className="w-full h-full object-contain",a.alt=n||L("previewAlt",o);const l=new FileReader;l.onload=r=>{var s;a.src=((s=r.target)==null?void 0:s.result)||""},l.readAsDataURL(t),e.appendChild(a)}function vn(e,t,n,o,a,l){const r=URL.createObjectURL(t);e.onclick=null;const s=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(s,e),s.innerHTML=`
113
+ <div class="relative group h-full">
114
+ <video class="w-full h-full object-contain" controls preload="auto" muted src="${r}">
115
+ ${_(L("videoNotSupported",a))}
116
+ </video>
117
+ <div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
118
+ <button class="bg-red-600 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs delete-file-btn">
119
+ ${_(L("removeElement",a))}
120
+ </button>
121
+ <button class="bg-gray-800 bg-opacity-75 hover:bg-opacity-90 text-white p-1 rounded text-xs change-file-btn">
122
+ ${_(L("changeButton",a))}
123
+ </button>
124
+ </div>
125
+ </div>
126
+ `,gn(s,o,a,l),s}function gn(e,t,n,o){const a=e.querySelector(".change-file-btn");a&&(a.onclick=r=>{r.stopPropagation(),o!=null&&o.picker&&o.picker.click()});const l=e.querySelector(".delete-file-btn");l&&(l.onclick=r=>{r.stopPropagation(),bn(e,t,n,o)})}function bn(e,t,n,o){var a;n.resourceIndex.delete(t);const l=(a=e.parentElement)==null?void 0:a.querySelector('input[type="hidden"]');l&&(l.value=""),o!=null&&o.fileUploadHandler&&(e.onclick=o.fileUploadHandler),o!=null&&o.dragHandler&&Oe(e,o.dragHandler),e.innerHTML=`
127
+ <div class="flex flex-col items-center justify-center h-full text-gray-400">
128
+ <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
129
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
130
+ </svg>
131
+ <div class="text-sm text-center">${_(L("clickDragText",n))}</div>
132
+ </div>
133
+ `}function yn(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(L("videoNotSupported",o))),e.appendChild(a)}function xn(e,t,n){kn(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=`
134
+ <div class="flex flex-col items-center justify-center h-full text-gray-400">
135
+ <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
136
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
137
+ </svg>
138
+ <div class="text-sm text-center">${_(L("clickDragText",n))}</div>
139
+ </div>
140
+ `})}async function En(e,t,n,o,a,l,r){!t.file||!(t.file instanceof File)||(t.type&&t.type.startsWith("image/")?hn(e,t.file,n,l):t.type&&t.type.startsWith("video/")?e=vn(e,t.file,t.type,o,l,r):e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400"><div class="text-2xl mb-2">\u{1F4C1}</div><div class="text-sm">${_(n)}</div></div>`,!a&&!(t.type&&t.type.startsWith("video/"))&&xn(e,o,l))}async function Cn(e,t,n,o,a){if(!a.config.getThumbnail){je(e,a);return}try{const l=await a.config.getThumbnail(t);if(l)if(ie(e),o&&o.type&&o.type.startsWith("video/"))yn(e,l,o.type,a);else{const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n||L("previewAlt",a),r.src=l,e.appendChild(r)}else je(e,a)}catch(l){console.error("Failed to get thumbnail:",l),e.innerHTML=`
141
+ <div class="flex flex-col items-center justify-center h-full text-gray-400">
142
+ <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
143
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
144
+ </svg>
145
+ <div class="text-sm text-center">${_(n||L("previewUnavailable",a))}</div>
146
+ </div>
147
+ `}}async function ot(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}");ie(e),l&&e.classList.add("cursor-pointer");const s=n.resourceIndex.get(t);s&&s.file&&s.file instanceof File?await En(e,s,a,t,l,n,r):await Cn(e,t,a,s,n)}async function De(e,t,n){var o,a;const l=t.resourceIndex.get(e),r=(l==null?void 0:l.name)||e.split("/").pop()||"file",s=r.toLowerCase().match(/\.psd$/),c=document.createElement("div");c.className=s?"space-y-2":"space-y-3";const u=document.createElement("div");s?u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity flex items-center p-3 max-w-sm":u.className="bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";const d=!s&&(((o=l==null?void 0:l.type)==null?void 0:o.startsWith("image/"))||r.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)),i=((a=l==null?void 0:l.type)==null?void 0:a.startsWith("video/"))||r.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);if(d)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`<img src="${m}" alt="${_(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">${_(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">${_(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">${_(r)}</div></div></div>`;else if(i)if(t.config.getThumbnail)try{const m=await t.config.getThumbnail(e);m?u.innerHTML=`
148
+ <div class="relative group">
149
+ <video class="w-full h-auto" controls preload="auto" muted src="${m}">
150
+ ${_(L("videoNotSupported",t))}
151
+ </video>
152
+ <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">
153
+ <div class="bg-white bg-opacity-90 rounded-full p-3">
154
+ <svg class="w-8 h-8 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
155
+ <path d="M8 5v14l11-7z"/>
156
+ </svg>
157
+ </div>
158
+ </div>
159
+ </div>
160
+ `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">\u{1F3A5}</div><div class="text-sm">${_(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">${_(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">${_(r)}</div></div></div>`;else{const m=s?"\u{1F3A8}":"\u{1F4C1}",v=s?"PSD File":"Document";s?u.innerHTML=`
161
+ <div class="flex items-center space-x-3">
162
+ <div class="text-3xl text-gray-400">${m}</div>
163
+ <div class="flex-1 min-w-0">
164
+ <div class="text-sm font-medium text-gray-900 truncate">${_(r)}</div>
165
+ <div class="text-xs text-gray-500">${v}</div>
166
+ </div>
167
+ </div>
168
+ `:u.innerHTML=`<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">${m}</div><div class="text-sm">${_(r)}</div><div class="text-xs text-gray-500 mt-1">${v}</div></div></div>`}const h=document.createElement("p");h.className=s?"hidden":"text-sm font-medium text-gray-900 text-center",h.textContent=r;const p=document.createElement("button");return p.className="w-full px-3 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",p.textContent=L("downloadButton",t),p.onclick=m=>{m.preventDefault(),m.stopPropagation(),t.config.downloadFile?t.config.downloadFile(e,r):$n(e,r,t)},c.appendChild(u),c.appendChild(h),c.appendChild(p),c}function lt(e,t,n,o,a,l){ie(e);const r=()=>{const h=[L("clickDragTextMultiple",n)];return a&&h.push(a),l&&h.push(l),h.join(" \u2022 ")},s=!e.classList.contains("grid");if((!t||t.length===0)&&s){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 C=document.createElementNS("http://www.w3.org/2000/svg","path");C.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(C),v.appendChild(g),v.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 b=f==null?void 0:f.querySelector('input[type="file"]');b&&b.click()},h.appendChild(v)}const p=document.createElement("div");p.className="text-center text-xs text-gray-500 mt-2",p.textContent=r(),e.appendChild(h),e.appendChild(p);return}const c=document.createElement("div");c.className="files-list grid grid-cols-4 gap-3";const u=t?t.length:0,d=(Math.floor(u/4)+1)*4;for(let h=0;h<d;h++){const p=document.createElement("div");if(t&&h<t.length){const m=t[h],v=n.resourceIndex.get(m);if(p.className="resource-pill aspect-square bg-gray-100 rounded-lg overflow-hidden relative group border border-gray-300",p.dataset.resourceId=m,wn(p,m,v,n).catch(g=>{console.error("Failed to render thumbnail:",g),p.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
169
+ <div class="text-2xl mb-1">\u{1F4C1}</div>
170
+ <div class="text-xs">${_(L("previewError",n))}</div>
171
+ </div>`}),o){const g=document.createElement("div");g.className="absolute inset-0 bg-black bg-opacity-50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center";const C=document.createElement("button");C.className="bg-red-600 text-white px-2 py-1 rounded text-xs",C.textContent=L("removeElement",n),C.onclick=f=>{f.stopPropagation(),o(m)},g.appendChild(C),p.appendChild(g)}}else p.className="aspect-square bg-gray-100 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-gray-400 transition-colors",p.innerHTML='<svg class="w-12 h-12 text-gray-400" fill="currentColor" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',p.onclick=()=>{let m=e.parentElement;for(;m&&!m.classList.contains("space-y-2");)m=m.parentElement;!m&&e.classList.contains("space-y-2")&&(m=e);const v=m==null?void 0:m.querySelector('input[type="file"]');v&&v.click()};c.appendChild(p)}e.appendChild(c);const i=document.createElement("div");i.className="text-center text-xs text-gray-500 mt-2",i.textContent=r(),e.appendChild(i)}function at(e,t,n="w-12 h-12"){e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
172
+ <svg class="${_(n)} text-red-400" fill="currentColor" viewBox="0 0 24 24">
173
+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
174
+ </svg>
175
+ <div class="text-xs mt-1 text-red-600">${_(L("previewError",t))}</div>
176
+ </div>`}async function wn(e,t,n,o){var a,l;if(n&&(a=n.type)!=null&&a.startsWith("image/"))if(n.file&&n.file instanceof File){const r=document.createElement("img");r.className="w-full h-full object-contain",r.alt=n.name;const s=new FileReader;s.onload=c=>{var u;r.src=((u=c.target)==null?void 0:u.result)||""},s.readAsDataURL(n.file),e.appendChild(r)}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);if(r){const s=document.createElement("img");s.className="w-full h-full object-contain",s.alt=n.name,s.src=r,e.appendChild(s)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
177
+ <svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
178
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
179
+ </svg>
180
+ </div>`}catch(r){const s=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),at(e,o)}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
181
+ <svg class="w-12 h-12" fill="currentColor" viewBox="0 0 24 24">
182
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
183
+ </svg>
184
+ </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=`
185
+ <div class="relative group h-full w-full">
186
+ <video class="w-full h-full object-contain" preload="metadata" muted src="${r}">
187
+ </video>
188
+ <div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
189
+ <div class="bg-white bg-opacity-90 rounded-full p-1">
190
+ <svg class="w-4 h-4 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
191
+ <path d="M8 5v14l11-7z"/>
192
+ </svg>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ `}else if(o.config.getThumbnail)try{const r=await o.config.getThumbnail(t);r?e.innerHTML=`
197
+ <div class="relative group h-full w-full">
198
+ <video class="w-full h-full object-contain" preload="metadata" muted src="${r}">
199
+ </video>
200
+ <div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
201
+ <div class="bg-white bg-opacity-90 rounded-full p-1">
202
+ <svg class="w-4 h-4 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
203
+ <path d="M8 5v14l11-7z"/>
204
+ </svg>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ `:e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
209
+ <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
210
+ <path d="M8 5v14l11-7z"/>
211
+ </svg>
212
+ <div class="text-xs mt-1">${_((n==null?void 0:n.name)||"Video")}</div>
213
+ </div>`}catch(r){const s=r instanceof Error?r:new Error(String(r));o.config.onThumbnailError&&o.config.onThumbnailError(s,t),at(e,o,"w-8 h-8")}else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
214
+ <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
215
+ <path d="M8 5v14l11-7z"/>
216
+ </svg>
217
+ <div class="text-xs mt-1">${_((n==null?void 0:n.name)||"Video")}</div>
218
+ </div>`;else e.innerHTML=`<div class="flex flex-col items-center justify-center h-full text-gray-400">
219
+ <div class="text-2xl mb-1">\u{1F4C1}</div>
220
+ <div class="text-xs">${_((n==null?void 0:n.name)||"File")}</div>
221
+ </div>`}function je(e,t,n){const o=n?`<div class="text-xs text-gray-500 mt-1">${_(n)}</div>`:"";e.innerHTML=`
222
+ <div class="flex flex-col items-center justify-center h-full text-gray-400">
223
+ <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
224
+ <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
225
+ </svg>
226
+ <div class="text-sm text-center">${_(L("clickDragText",t))}</div>
227
+ ${o}
228
+ </div>
229
+ `}async function it(e,t,n,o,a=null,l){var r,s;let c;if(o.config.uploadFile)try{if(c=await o.config.uploadFile(e),typeof c!="string")throw new Error("Upload handler must return a string resource ID")}catch(d){const i=d instanceof Error?d:new Error(String(d));throw o.config.onUploadError&&o.config.onUploadError(i,e),new Error(`File upload failed: ${i.message}`)}else throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");o.resourceIndex.set(c,{name:e.name,type:e.type,size:e.size,uploadedAt:new Date,file:e});let u=(r=t.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');u||(u=document.createElement("input"),u.type="hidden",u.name=n,(s=t.parentElement)==null||s.appendChild(u)),u.value=c,ot(t,c,o,{fileName:e.name,isReadonly:!1,deps:a}).catch(console.error),l&&!o.config.readonly&&l.triggerOnChange(n,c)}function Oe(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 kn(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=L("removeElement",t),l.onclick=r=>{r.stopPropagation(),n()},a.appendChild(l),e.appendChild(a)}async function st(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 $n(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();Ln(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 Ln(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 ct(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 Sn(e,t,n,o,a,l){var r;if(!a.resourceIndex.has(e)){const c=e.split("/").pop()||"file",u=(r=c.split(".").pop())==null?void 0:r.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),a.resourceIndex.set(e,{name:c,type:d,size:0,uploadedAt:new Date,file:void 0})}ot(t,e,a,{fileName:e,isReadonly:!1,deps:l}).catch(console.error);const s=document.createElement("input");s.type="hidden",s.name=n,s.value=e,o.appendChild(s)}function ut(e,t,n,o,a,l){Oe(e,async r=>{const s=Array.from(r);for(const c of s){const u=await st(c,n);n.resourceIndex.set(u,{name:c.name,type:c.type,size:c.size,uploadedAt:new Date,file:void 0}),t.push(u)}o(),l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)})}function dt(e,t,n,o,a,l){e.onchange=async()=>{if(e.files)for(const r of Array.from(e.files)){const s=await st(r,n);n.resourceIndex.set(s,{name:r.name,type:r.type,size:r.size,uploadedAt:new Date,file:void 0}),t.push(s)}o(),e.value="",l&&a&&!n.config.readonly&&l.triggerOnChange(a,t)}}function Tn(e,t,n,o){var a;const l=t.state;if(l.config.readonly){const r=t.prefill[e.key];if(r)De(r,l).then(s=>{n.appendChild(s)}).catch(s=>{console.error("Failed to render file preview:",s);const c=document.createElement("div");c.className="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500",c.innerHTML=`<div class="text-center">${_(L("previewUnavailable",l))}</div>`,n.appendChild(c)});else{const 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("noFileSelected",l))}</div>`,n.appendChild(s)}}else{const r=document.createElement("div");r.className="space-y-2";const s=document.createElement("input");s.type="file",s.name=o,s.style.display="none",e.accept&&(s.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(h=>`.${h}`).join(","))||"");const c=document.createElement("div");c.className="file-preview-container w-full aspect-square max-w-xs bg-gray-100 rounded-lg overflow-hidden relative group cursor-pointer";const u=t.prefill[e.key],d=()=>s.click(),i=h=>{if(h.length>0){const p={picker:s,fileUploadHandler:d,dragHandler:i};it(h[0],c,o,l,p,t.instance)}};if(u)Sn(u,c,o,r,l,{picker:s,fileUploadHandler:d,dragHandler:i});else{const h=ue(e,l);je(c,l,h)}c.onclick=d,Oe(c,i),s.onchange=()=>{if(s.files&&s.files.length>0){const h={picker:s,fileUploadHandler:d,dragHandler:i};it(s.files[0],c,o,l,h,t.instance)}},r.appendChild(c),r.appendChild(s),n.appendChild(r)}}function An(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 s=t.prefill[e.key]||[];s.length>0?s.forEach(c=>{De(c,l).then(u=>{r.appendChild(u)}).catch(u=>{console.error("Failed to render file preview:",u)})}):r.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${_(L("noFilesSelected",l))}</div></div>`,n.appendChild(r)}else{let r=function(){lt(d,i,l,p=>{const m=i.indexOf(p);m>-1&&i.splice(m,1),r()},h)};const s=document.createElement("div");s.className="space-y-2";const c=document.createElement("input");c.type="file",c.name=o,c.multiple=!0,c.style.display="none",e.accept&&(c.accept=typeof e.accept=="string"?e.accept:((a=e.accept.extensions)==null?void 0:a.map(p=>`.${p}`).join(","))||"");const u=document.createElement("div");u.className="border-2 border-dashed border-gray-300 rounded-lg p-3 hover:border-gray-400 transition-colors";const d=document.createElement("div");d.className="files-list";const i=t.prefill[e.key]||[];ct(i,l);const h=ue(e,l);r(),ut(u,i,l,r,o,t.instance),dt(c,i,l,r,o,t.instance),u.appendChild(d),s.appendChild(u),s.appendChild(c),n.appendChild(s)}}function Fn(e,t,n,o){var a,l,r;const s=t.state,c=(a=e.minCount)!=null?a:0,u=(l=e.maxCount)!=null?l:1/0;if(s.config.readonly){const d=document.createElement("div");d.className="space-y-4";const i=t.prefill[e.key]||[];i.length>0?i.forEach(h=>{De(h,s).then(p=>{d.appendChild(p)}).catch(p=>{console.error("Failed to render file preview:",p)})}):d.innerHTML=`<div class="aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500"><div class="text-center">${_(L("noFilesSelected",s))}</div></div>`,n.appendChild(d)}else{const d=document.createElement("div");d.className="space-y-2";const i=document.createElement("input");i.type="file",i.name=o,i.multiple=!0,i.style.display="none",e.accept&&(i.accept=typeof e.accept=="string"?e.accept:((r=e.accept.extensions)==null?void 0:r.map(C=>`.${C}`).join(","))||"");const h=document.createElement("div");h.className="files-list space-y-2",d.appendChild(i),d.appendChild(h);const p=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];ct(p,s);const m=ue(e,s),v=()=>{const C=p.length===1?L("fileCountSingle",s,{count:p.length}):L("fileCountPlural",s,{count:p.length}),f=c>0||u<1/0?` ${L("fileCountRange",s,{min:c,max:u})}`:"";return C+f},g=()=>{lt(h,p,s,C=>{p.splice(p.indexOf(C),1),g()},m,v())};ut(h,p,s,g,o,t.instance),dt(i,p,s,g,o,t.instance),g(),n.appendChild(d)}}function pt(e,t,n){var o;const a=[],{scopeRoot:l,skipValidation:r,path:s}=n,c=e.type==="files"||"multiple"in e&&!!e.multiple,u=(d,i,h)=>{var p,m;if(r)return;const{state:v}=n,g="minCount"in h&&(p=h.minCount)!=null?p:0,C="maxCount"in h&&(m=h.maxCount)!=null?m:1/0;h.required&&i.length===0&&a.push(`${d}: ${L("required",v)}`),i.length<g&&a.push(`${d}: ${L("minFiles",v,{min:g})}`),i.length>C&&a.push(`${d}: ${L("maxFiles",v,{max:C})}`)};if(c){const d=ge(s,t),i=l.querySelector(`input[type="file"][name="${d}"]`),h=i==null?void 0:i.closest(".space-y-2"),p=(h==null?void 0:h.querySelector(".files-list"))||null,m=[];return p&&p.querySelectorAll(".resource-pill").forEach(v=>{const g=v.dataset.resourceId;g&&m.push(g)}),u(t,m,e),{value:m,errors:a}}else{const d=l.querySelector(`input[name$="${t}"][type="hidden"]`),i=(o=d==null?void 0:d.value)!=null?o:"";return!r&&e.required&&i===""?(a.push(`${t}: ${L("required",n.state)}`),{value:null,errors:a}):{value:i||null,errors:a}}}function ft(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(s=>{var c;if(s&&typeof s=="string"&&!r.resourceIndex.has(s)){const u=s.split("/").pop()||"file",d=(c=u.split(".").pop())==null?void 0:c.toLowerCase();let i="application/octet-stream";d&&(["jpg","jpeg","png","gif","webp"].includes(d)?i=`image/${d==="jpg"?"jpeg":d}`:["mp4","webm","mov","avi"].includes(d)&&(i=`video/${d==="mov"?"quicktime":d}`)),r.resourceIndex.set(s,{name:u,type:i,size:0,uploadedAt:new Date,file:void 0})}}),console.info(`updateFileField: Multiple file field "${t}" updated. Preview update requires re-render.`)}else{const s=l.querySelector(`input[name="${t}"][type="hidden"]`);if(!s){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}if(s.value=n!=null?String(n):"",n&&typeof n=="string"){if(!r.resourceIndex.has(n)){const c=n.split("/").pop()||"file",u=(a=c.split(".").pop())==null?void 0:a.toLowerCase();let d="application/octet-stream";u&&(["jpg","jpeg","png","gif","webp"].includes(u)?d=`image/${u==="jpg"?"jpeg":u}`:["mp4","webm","mov","avi"].includes(u)&&(d=`video/${u==="mov"?"quicktime":u}`)),r.resourceIndex.set(n,{name:c,type:d,size:0,uploadedAt:new Date,file:void 0})}console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`)}}}function ye(e){return e?e.toUpperCase():"#000000"}function Ue(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function mt(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 ht(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=ye(e),o=document.createElement("div");o.style.cssText=`
230
+ width: 32px;
231
+ height: 32px;
232
+ border-radius: var(--fb-border-radius);
233
+ border: var(--fb-border-width) solid var(--fb-border-color);
234
+ background-color: ${n};
235
+ `;const a=document.createElement("span");return a.style.cssText=`
236
+ font-size: var(--fb-font-size);
237
+ color: var(--fb-text-color);
238
+ font-family: var(--fb-font-family-mono, monospace);
239
+ `,a.textContent=n,t.appendChild(o),t.appendChild(a),t}function vt(e,t,n){const o=ye(e),a=document.createElement("div");a.className="colour-picker-wrapper",a.style.cssText=`
240
+ display: flex;
241
+ align-items: center;
242
+ gap: 8px;
243
+ `;const l=document.createElement("div");l.className="colour-swatch",l.style.cssText=`
244
+ width: 40px;
245
+ height: 40px;
246
+ border-radius: var(--fb-border-radius);
247
+ border: var(--fb-border-width) solid var(--fb-border-color);
248
+ background-color: ${o};
249
+ cursor: pointer;
250
+ transition: border-color var(--fb-transition-duration) ease-in-out;
251
+ flex-shrink: 0;
252
+ `;const r=document.createElement("input");r.type="text",r.className="colour-hex-input",r.name=t,r.value=o,r.placeholder="#000000",r.style.cssText=`
253
+ width: 100px;
254
+ padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
255
+ border: var(--fb-border-width) solid var(--fb-border-color);
256
+ border-radius: var(--fb-border-radius);
257
+ background-color: var(--fb-background-color);
258
+ color: var(--fb-text-color);
259
+ font-size: var(--fb-font-size);
260
+ font-family: var(--fb-font-family-mono, monospace);
261
+ transition: all var(--fb-transition-duration) ease-in-out;
262
+ `;const s=document.createElement("input");return s.type="color",s.className="colour-picker-hidden",s.value=o.toLowerCase(),s.style.cssText=`
263
+ position: absolute;
264
+ opacity: 0;
265
+ pointer-events: none;
266
+ `,r.addEventListener("input",()=>{const c=r.value.trim();if(Ue(c)){const u=mt(c);l.style.backgroundColor=u,s.value=u.toLowerCase(),r.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else r.classList.add("invalid")}),r.addEventListener("blur",()=>{const c=r.value.trim();if(Ue(c)){const u=mt(c);r.value=u,l.style.backgroundColor=u,s.value=u.toLowerCase(),r.classList.remove("invalid")}}),s.addEventListener("change",()=>{const c=ye(s.value);r.value=c,l.style.backgroundColor=c,n.instance&&n.instance.triggerOnChange(t,c)}),l.addEventListener("click",()=>{s.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(s),a}function Nn(e,t,n,o){const a=t.state,l=t.prefill[e.key]||e.default||"#000000";if(a.config.readonly){const r=ht(l);n.appendChild(r)}else{const r=vt(l,o,t);n.appendChild(r)}if(!a.config.readonly){const r=document.createElement("p");r.className="mt-1",r.style.cssText=`
267
+ font-size: var(--fb-font-size-small);
268
+ color: var(--fb-text-secondary-color);
269
+ `,r.textContent=ue(e,a),n.appendChild(r)}}function Mn(e,t,n,o){var a,l;const r=t.state,s=t.prefill[e.key]||[],c=Array.isArray(s)?[...s]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0;for(;c.length<u;)c.push(e.default||"#000000");const i=document.createElement("div");i.className="space-y-2",n.appendChild(i);function h(){i.querySelectorAll(".multiple-colour-item").forEach((f,b)=>{const x=f.querySelector("input");x&&(x.name=`${o}[${b}]`)})}function p(f="#000000",b=-1){const x=document.createElement("div");if(x.className="multiple-colour-item flex items-center gap-2",r.config.readonly){const y=ht(f);for(;y.firstChild;)x.appendChild(y.firstChild)}else{const y=`${o}[${i.children.length}]`,E=vt(f,y,t);E.style.flex="1",x.appendChild(E)}return b===-1?i.appendChild(x):i.insertBefore(x,i.children[b]),h(),x}function m(){if(r.config.readonly)return;const f=i.querySelectorAll(".multiple-colour-item"),b=f.length;f.forEach(x=>{let y=x.querySelector(".remove-item-btn");y||(y=document.createElement("button"),y.type="button",y.className="remove-item-btn px-2 py-1 rounded",y.style.cssText=`
270
+ color: var(--fb-error-color);
271
+ background-color: transparent;
272
+ transition: background-color var(--fb-transition-duration);
273
+ `,y.innerHTML="\u2715",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{const S=Array.from(i.children).indexOf(x);i.children.length>u&&(c.splice(S,1),x.remove(),h(),C(),m())},x.appendChild(y));const E=b<=u;y.disabled=E,y.style.opacity=E?"0.5":"1",y.style.pointerEvents=E?"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 f=document.createElement("button");f.type="button",f.className="add-colour-btn px-3 py-1 rounded",f.style.cssText=`
274
+ color: var(--fb-primary-color);
275
+ border: var(--fb-border-width) solid var(--fb-primary-color);
276
+ background-color: transparent;
277
+ font-size: var(--fb-font-size);
278
+ transition: all var(--fb-transition-duration);
279
+ `,f.textContent="+",f.addEventListener("mouseenter",()=>{f.style.backgroundColor="var(--fb-background-hover-color)"}),f.addEventListener("mouseleave",()=>{f.style.backgroundColor="transparent"}),f.onclick=()=>{const b=e.default||"#000000";c.push(b),p(b),C(),m()},g=document.createElement("span"),g.className="text-sm text-gray-500",v.appendChild(f),v.appendChild(g),n.appendChild(v)}function C(){if(!v||!g)return;const f=v.querySelector(".add-colour-btn");if(f){const b=c.length>=d;f.disabled=b,f.style.opacity=b?"0.5":"1",f.style.pointerEvents=b?"none":"auto"}g.textContent=`${c.length}/${d===1/0?"\u221E":d}`}if(c.forEach(f=>p(f)),C(),m(),!r.config.readonly){const f=document.createElement("p");f.className="mt-1",f.style.cssText=`
280
+ font-size: var(--fb-font-size-small);
281
+ color: var(--fb-text-secondary-color);
282
+ `,f.textContent=ue(e,r),n.appendChild(f)}}function qn(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:c}=n,u=(i,h)=>{var p,m;if(!i)return;const v=`error-${i.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(v);h?(i.classList.add("invalid"),i.title=h,g||(g=document.createElement("div"),g.id=v,g.className="error-message",g.style.cssText=`
283
+ color: var(--fb-error-color);
284
+ font-size: var(--fb-font-size-small);
285
+ margin-top: 0.25rem;
286
+ `,i.nextSibling?(p=i.parentNode)==null||p.insertBefore(g,i.nextSibling):(m=i.parentNode)==null||m.appendChild(g)),g.textContent=h,g.style.display="block"):(i.classList.remove("invalid"),i.title="",g&&g.remove())},d=(i,h,p)=>{const{state:m}=n;if(!h){if(!c&&e.required){const g=L("required",m);return r.push(`${p}: ${g}`),u(i,g),""}return u(i,null),""}const v=ye(h);if(!c&&!Ue(v)){const g=L("invalidHexColour",m);return r.push(`${p}: ${g}`),u(i,g),h}return u(i,null),v};if(e.multiple){const i=s.querySelectorAll(`[name^="${t}["].colour-hex-input`),h=[];if(i.forEach((p,m)=>{var v;const g=(v=p==null?void 0:p.value)!=null?v:"",C=d(p,g,`${t}[${m}]`);h.push(C)}),!c){const{state:p}=n,m=(o=e.minCount)!=null?o:1,v=(a=e.maxCount)!=null?a:1/0,g=h.filter(C=>C!=="");e.required&&g.length===0&&r.push(`${t}: ${L("required",p)}`),g.length<m&&r.push(`${t}: ${L("minItems",p,{min:m})}`),g.length>v&&r.push(`${t}: ${L("maxItems",p,{max:v})}`)}return{value:h,errors:r}}else{const i=s.querySelector(`[name="${t}"].colour-hex-input`),h=(l=i==null?void 0:i.value)!=null?l:"";if(!c&&e.required&&h===""){const p=L("required",n.state);return r.push(`${t}: ${p}`),u(i,p),{value:"",errors:r}}return{value:d(i,h,t),errors:r}}}function Hn(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,s)=>{if(s<n.length){const c=ye(n[s]);r.value=c,r.classList.remove("invalid"),r.title="";const u=r.closest(".colour-picker-wrapper");if(u){const d=u.querySelector(".colour-swatch"),i=u.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=c),i&&(i.value=c.toLowerCase())}}}),n.length!==l.length&&console.warn(`updateColourField: Multiple field "${t}" has ${l.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const l=a.querySelector(`[name="${t}"].colour-hex-input`);if(l){const r=ye(n);l.value=r,l.classList.remove("invalid"),l.title="";const s=l.closest(".colour-picker-wrapper");if(s){const c=s.querySelector(".colour-swatch"),u=s.querySelector(".colour-picker-hidden");c&&(c.style.backgroundColor=r),u&&(u.value=r.toLowerCase())}}}}function gt(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 Pe(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 Te(e,t){return Math.round(e/t)*t}function bt(e,t,n,o,a){var l;const r=document.createElement("div");r.className="slider-container";const s=document.createElement("div");s.className="flex items-start gap-3";const c=document.createElement("div");c.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=a;const d=n.scale||"linear",i=n.min,h=n.max,p=(l=n.step)!=null?l:1;if(d==="exponential"){if(i<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${i})`);u.min="0",u.max="1000",u.step="1";const f=Pe(e,i,h);u.value=(f*1e3).toString()}else u.min=i.toString(),u.max=h.toString(),u.step=p.toString(),u.value=e.toString();u.style.cssText=`
287
+ height: 6px;
288
+ border-radius: 3px;
289
+ background: linear-gradient(
290
+ to right,
291
+ var(--fb-primary-color) 0%,
292
+ var(--fb-primary-color) ${(e-i)/(h-i)*100}%,
293
+ var(--fb-border-color) ${(e-i)/(h-i)*100}%,
294
+ var(--fb-border-color) 100%
295
+ );
296
+ outline: none;
297
+ transition: background 0.1s ease-in-out;
298
+ cursor: ${a?"not-allowed":"pointer"};
299
+ opacity: ${a?"0.6":"1"};
300
+ `,c.appendChild(u);const m=document.createElement("div");m.className="flex justify-between",m.style.cssText=`
301
+ font-size: var(--fb-font-size-small);
302
+ color: var(--fb-text-secondary-color);
303
+ margin-top: 4px;
304
+ `;const v=document.createElement("span");v.textContent=i.toString();const g=document.createElement("span");g.textContent=h.toString(),m.appendChild(v),m.appendChild(g),c.appendChild(m);const C=document.createElement("span");if(C.className="slider-value",C.style.cssText=`
305
+ min-width: 60px;
306
+ text-align: right;
307
+ font-size: var(--fb-font-size);
308
+ color: var(--fb-text-color);
309
+ font-family: var(--fb-font-family-mono, monospace);
310
+ font-weight: 500;
311
+ padding-top: 2px;
312
+ `,C.textContent=e.toFixed(p<1?2:0),s.appendChild(c),s.appendChild(C),r.appendChild(s),!a){const f=()=>{let b;if(d==="exponential"){const y=parseFloat(u.value)/1e3;b=gt(y,i,h),b=Te(b,p),b=Math.max(i,Math.min(h,b))}else b=parseFloat(u.value),b=Te(b,p);C.textContent=b.toFixed(p<1?2:0);const x=(b-i)/(h-i)*100;u.style.background=`linear-gradient(
313
+ to right,
314
+ var(--fb-primary-color) 0%,
315
+ var(--fb-primary-color) ${x}%,
316
+ var(--fb-border-color) ${x}%,
317
+ var(--fb-border-color) 100%
318
+ )`,o.instance&&o.instance.triggerOnChange(t,b)};u.addEventListener("input",f),u.addEventListener("change",f)}return r}function zn(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,s=(a=t.prefill[e.key])!=null?a:r,c=bt(s,o,e,t,l.config.readonly);if(n.appendChild(c),!l.config.readonly){const u=document.createElement("p");u.className="mt-1",u.style.cssText=`
319
+ font-size: var(--fb-font-size-small);
320
+ color: var(--fb-text-secondary-color);
321
+ `,u.textContent=ue(e,l),n.appendChild(u)}}function Rn(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,s=t.prefill[e.key]||[],c=Array.isArray(s)?[...s]:[],u=(a=e.minCount)!=null?a:1,d=(l=e.maxCount)!=null?l:1/0,i=e.default!==void 0?e.default:(e.min+e.max)/2;for(;c.length<u;)c.push(i);const h=document.createElement("div");h.className="space-y-3",n.appendChild(h);function p(){h.querySelectorAll(".multiple-slider-item").forEach((b,x)=>{const y=b.querySelector("input[type=range]");y&&y.setAttribute("name",`${o}[${x}]`)})}function m(b=i,x=-1){const y=document.createElement("div");y.className="multiple-slider-item flex items-start gap-2";const E=`${o}[${h.children.length}]`,S=bt(b,E,e,t,r.config.readonly);return S.style.flex="1",y.appendChild(S),x===-1?h.appendChild(y):h.insertBefore(y,h.children[x]),p(),y}function v(){if(r.config.readonly)return;const b=h.querySelectorAll(".multiple-slider-item"),x=b.length;b.forEach(y=>{let E=y.querySelector(".remove-item-btn");E||(E=document.createElement("button"),E.type="button",E.className="remove-item-btn px-2 py-1 rounded",E.style.cssText=`
322
+ color: var(--fb-error-color);
323
+ background-color: transparent;
324
+ transition: background-color var(--fb-transition-duration);
325
+ margin-top: 8px;
326
+ `,E.innerHTML="\u2715",E.addEventListener("mouseenter",()=>{E.style.backgroundColor="var(--fb-background-hover-color)"}),E.addEventListener("mouseleave",()=>{E.style.backgroundColor="transparent"}),E.onclick=()=>{const A=Array.from(h.children).indexOf(y);h.children.length>u&&(c.splice(A,1),y.remove(),p(),f(),v())},y.appendChild(E));const S=x<=u;E.disabled=S,E.style.opacity=S?"0.5":"1",E.style.pointerEvents=S?"none":"auto"})}let g=null,C=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=`
327
+ color: var(--fb-primary-color);
328
+ border: var(--fb-border-width) solid var(--fb-primary-color);
329
+ background-color: transparent;
330
+ font-size: var(--fb-font-size);
331
+ transition: all var(--fb-transition-duration);
332
+ `,b.textContent="+",b.addEventListener("mouseenter",()=>{b.style.backgroundColor="var(--fb-background-hover-color)"}),b.addEventListener("mouseleave",()=>{b.style.backgroundColor="transparent"}),b.onclick=()=>{c.push(i),m(i),f(),v()},C=document.createElement("span"),C.className="text-sm text-gray-500",g.appendChild(b),g.appendChild(C),n.appendChild(g)}function f(){if(!g||!C)return;const b=g.querySelector(".add-slider-btn");if(b){const x=c.length>=d;b.disabled=x,b.style.opacity=x?"0.5":"1",b.style.pointerEvents=x?"none":"auto"}C.textContent=`${c.length}/${d===1/0?"\u221E":d}`}if(c.forEach(b=>m(b)),f(),v(),!r.config.readonly){const b=document.createElement("p");b.className="mt-1",b.style.cssText=`
333
+ font-size: var(--fb-font-size-small);
334
+ color: var(--fb-text-secondary-color);
335
+ `,b.textContent=ue(e,r),n.appendChild(b)}}function In(e,t,n){var o,a,l;const r=[],{scopeRoot:s,skipValidation:c}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const u=e.min,d=e.max,i=(o=e.step)!=null?o:1,h=e.scale||"linear",p=(v,g)=>{var C,f;if(!v)return;const b=`error-${v.getAttribute("name")||Math.random().toString(36).substring(7)}`;let x=document.getElementById(b);if(g){if(v.classList.add("invalid"),v.title=g,!x){x=document.createElement("div"),x.id=b,x.className="error-message",x.style.cssText=`
336
+ color: var(--fb-error-color);
337
+ font-size: var(--fb-font-size-small);
338
+ margin-top: 0.25rem;
339
+ `;const y=v.closest(".slider-container");y&&y.nextSibling?(C=y.parentNode)==null||C.insertBefore(x,y.nextSibling):y&&((f=y.parentNode)==null||f.appendChild(x))}x.textContent=g,x.style.display="block"}else v.classList.remove("invalid"),v.title="",x&&x.remove()},m=(v,g)=>{const{state:C}=n,f=v.value;if(!f){if(!c&&e.required){const x=L("required",C);return r.push(`${g}: ${x}`),p(v,x),null}return p(v,null),null}let b;if(h==="exponential"){const x=parseFloat(f)/1e3;b=gt(x,u,d),b=Te(b,i)}else b=parseFloat(f),b=Te(b,i);if(!c){if(b<u){const x=L("minValue",C,{min:u});return r.push(`${g}: ${x}`),p(v,x),b}if(b>d){const x=L("maxValue",C,{max:d});return r.push(`${g}: ${x}`),p(v,x),b}}return p(v,null),b};if(e.multiple){const v=s.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(v.forEach((C,f)=>{const b=m(C,`${t}[${f}]`);g.push(b)}),!c){const{state:C}=n,f=(a=e.minCount)!=null?a:1,b=(l=e.maxCount)!=null?l:1/0,x=g.filter(y=>y!==null);e.required&&x.length===0&&r.push(`${t}: ${L("required",C)}`),x.length<f&&r.push(`${t}: ${L("minItems",C,{min:f})}`),x.length>b&&r.push(`${t}: ${L("maxItems",C,{max:b})}`)}return{value:g,errors:r}}else{const v=s.querySelector(`input[type="range"][name="${t}"]`);return v?{value:m(v,t),errors:r}:(!c&&e.required&&r.push(`${t}: ${L("required",n.state)}`),{value:null,errors:r})}}function Bn(e,t,n,o){var a;const{scopeRoot:l}=o,r=e.min,s=e.max,c=(a=e.step)!=null?a:1,u=e.scale||"linear";if(e.multiple){if(!Array.isArray(n)){console.warn(`updateSliderField: Expected array for multiple field "${t}", got ${typeof n}`);return}const d=l.querySelectorAll(`input[type="range"][name^="${t}["]`);d.forEach((i,h)=>{if(h<n.length&&n[h]!==null){const p=Number(n[h]);if(u==="exponential"){const v=Pe(p,r,s);i.value=(v*1e3).toString()}else i.value=p.toString();const m=i.closest(".slider-container");if(m){const v=m.querySelector(".slider-value");v&&(v.textContent=p.toFixed(c<1?2:0));const g=(p-r)/(s-r)*100;i.style.background=`linear-gradient(
340
+ to right,
341
+ var(--fb-primary-color) 0%,
342
+ var(--fb-primary-color) ${g}%,
343
+ var(--fb-border-color) ${g}%,
344
+ var(--fb-border-color) 100%
345
+ )`}i.classList.remove("invalid"),i.title=""}}),n.length!==d.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${d.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const d=l.querySelector(`input[type="range"][name="${t}"]`);if(d&&n!==null&&n!==void 0){const i=Number(n);if(u==="exponential"){const p=Pe(i,r,s);d.value=(p*1e3).toString()}else d.value=i.toString();const h=d.closest(".slider-container");if(h){const p=h.querySelector(".slider-value");p&&(p.textContent=i.toFixed(c<1?2:0));const m=(i-r)/(s-r)*100;d.style.background=`linear-gradient(
346
+ to right,
347
+ var(--fb-primary-color) 0%,
348
+ var(--fb-primary-color) ${m}%,
349
+ var(--fb-border-color) ${m}%,
350
+ var(--fb-border-color) 100%
351
+ )`}d.classList.remove("invalid"),d.title=""}}}function yt(e){const t={};for(const n of e)"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function xt(e,t){return{...t,...e}}function Ve(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 _e=null;function Dn(e){_e=e}function Ae(e,t){if(!_e)throw new Error("renderElement not initialized. Import from components/index.ts");return _e(e,t)}function Et(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 Ct(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 s=document.createElement("div"),c=e.columns||1;if(c===1?s.className="space-y-4":s.className=`grid grid-cols-${c} gap-4`,!t.state.config.readonly){const p=Et(e,o);p&&r.appendChild(p)}const u=yt(e.elements),d=((a=t.prefill)==null?void 0:a[e.key])||{},i=xt(d,u),h={path:ge(t.path,e.key),prefill:i,formData:(l=t.formData)!=null?l:t.prefill,state:t.state};e.elements.forEach(p=>{p.hidden||s.appendChild(Ae(p,h))}),r.appendChild(s),n.appendChild(r)}function wt(e,t,n,o){var a,l,r,s;const c=t.state,u=document.createElement("div");u.className="border border-gray-200 rounded-lg p-4 bg-gray-50";const d=document.createElement("span");d.className="text-sm text-gray-500";const i=document.createElement("div");if(i.className="space-y-4",!t.state.config.readonly){const x=Et(e,e.key);x&&u.appendChild(x)}const h=(a=e.minCount)!=null?a:0,p=(l=e.maxCount)!=null?l:1/0,m=Array.isArray((r=t.prefill)==null?void 0:r[e.key])?t.prefill[e.key]:null,v=yt(e.elements),g=()=>i.querySelectorAll(":scope > .containerItem").length,C=()=>{const x=document.createElement("button");return x.type="button",x.className="add-container-btn px-3 py-1 rounded",x.style.cssText=`
352
+ color: var(--fb-primary-color);
353
+ border: var(--fb-border-width) solid var(--fb-primary-color);
354
+ background-color: transparent;
355
+ font-size: var(--fb-font-size);
356
+ transition: all var(--fb-transition-duration);
357
+ `,x.textContent="+",x.addEventListener("mouseenter",()=>{x.style.backgroundColor="var(--fb-background-hover-color)"}),x.addEventListener("mouseleave",()=>{x.style.backgroundColor="transparent"}),x.onclick=()=>{if(g()<p){const y=g(),E=c.formRoot?Ve(c.formRoot):{},S={state:t.state,path:ge(t.path,`${e.key}[${y}]`),prefill:v,formData:E},A=document.createElement("div");A.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",A.setAttribute("data-container-item",`${e.key}[${y}]`);const z=document.createElement("div"),X=e.columns||1;if(X===1?z.className="space-y-4":z.className=`grid grid-cols-${X} gap-4`,e.elements.forEach(Z=>{Z.hidden||z.appendChild(Ae(Z,S))}),A.appendChild(z),!c.config.readonly){const Z=document.createElement("button");Z.type="button",Z.className="absolute top-2 right-2 px-2 py-1 rounded",Z.style.cssText=`
358
+ color: var(--fb-error-color);
359
+ background-color: transparent;
360
+ transition: background-color var(--fb-transition-duration);
361
+ `,Z.textContent="\u2715",Z.addEventListener("mouseenter",()=>{Z.style.backgroundColor="var(--fb-background-hover-color)"}),Z.addEventListener("mouseleave",()=>{Z.style.backgroundColor="transparent"}),Z.onclick=()=>b(A),A.style.position="relative",A.appendChild(Z)}i.appendChild(A),f()}},x},f=()=>{const x=g(),y=u.querySelector(".add-container-btn");y&&(y.disabled=x>=p,y.style.opacity=x>=p?"0.5":"1",y.style.pointerEvents=x>=p?"none":"auto"),d.textContent=`${x}/${p===1/0?"\u221E":p}`},b=x=>{x.remove(),f()};if(m&&Array.isArray(m)&&m.forEach((x,y)=>{var E;const S=xt(x||{},v),A={state:t.state,path:ge(t.path,`${e.key}[${y}]`),prefill:S,formData:(E=t.formData)!=null?E:t.prefill},z=document.createElement("div");z.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",z.setAttribute("data-container-item",`${e.key}[${y}]`);const X=document.createElement("div"),Z=e.columns||1;if(Z===1?X.className="space-y-4":X.className=`grid grid-cols-${Z} gap-4`,e.elements.forEach(G=>{G.hidden||X.appendChild(Ae(G,A))}),z.appendChild(X),!c.config.readonly){const G=document.createElement("button");G.type="button",G.className="absolute top-2 right-2 px-2 py-1 rounded",G.style.cssText=`
362
+ color: var(--fb-error-color);
363
+ background-color: transparent;
364
+ transition: background-color var(--fb-transition-duration);
365
+ `,G.textContent="\u2715",G.addEventListener("mouseenter",()=>{G.style.backgroundColor="var(--fb-background-hover-color)"}),G.addEventListener("mouseleave",()=>{G.style.backgroundColor="transparent"}),G.onclick=()=>b(z),z.style.position="relative",z.appendChild(G)}i.appendChild(z)}),!c.config.readonly)for(;g()<h;){const x=g(),y={state:t.state,path:ge(t.path,`${e.key}[${x}]`),prefill:v,formData:(s=t.formData)!=null?s:t.prefill},E=document.createElement("div");E.className="containerItem border border-gray-300 rounded-lg p-4 bg-white",E.setAttribute("data-container-item",`${e.key}[${x}]`);const S=document.createElement("div"),A=e.columns||1;A===1?S.className="space-y-4":S.className=`grid grid-cols-${A} gap-4`,e.elements.forEach(X=>{X.hidden||S.appendChild(Ae(X,y))}),E.appendChild(S);const z=document.createElement("button");z.type="button",z.className="absolute top-2 right-2 px-2 py-1 rounded",z.style.cssText=`
366
+ color: var(--fb-error-color);
367
+ background-color: transparent;
368
+ transition: background-color var(--fb-transition-duration);
369
+ `,z.textContent="\u2715",z.addEventListener("mouseenter",()=>{z.style.backgroundColor="var(--fb-background-hover-color)"}),z.addEventListener("mouseleave",()=>{z.style.backgroundColor="transparent"}),z.onclick=()=>{g()>h&&b(E)},E.style.position="relative",E.appendChild(z),i.appendChild(E)}if(u.appendChild(i),!c.config.readonly){const x=document.createElement("div");x.className="flex items-center gap-3 mt-2",x.appendChild(C()),x.appendChild(d),u.appendChild(x)}f(),n.appendChild(u)}let We=null;function jn(e){We=e}function kt(e,t,n){if(!We)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return We(e,t,n)}function $t(e,t,n){const o=[],{scopeRoot:a,skipValidation:l,path:r}=n;if(!("elements"in e))return{value:null,errors:o};const s=(c,u,d)=>{var i,h;if(l)return;const{state:p}=n,m="minCount"in d&&(i=d.minCount)!=null?i:0,v="maxCount"in d&&(h=d.maxCount)!=null?h:1/0;d.required&&u.length===0&&o.push(`${c}: ${L("required",p)}`),u.length<m&&o.push(`${c}: ${L("minItems",p,{min:m})}`),u.length>v&&o.push(`${c}: ${L("maxItems",p,{max:v})}`)};if("multiple"in e&&e.multiple){const c=[],u=a.querySelectorAll("[data-container-item]");return Array.from(u).filter(d=>{const i=d.getAttribute("data-container-item")||"";if(!i.startsWith(`${t}[`))return!1;const h=i.slice(t.length);return/^\[\d+\]$/.test(h)}).forEach(d=>{const i={},h=(d.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),p=h?parseInt(h[1],10):0;e.elements.forEach(m=>{var v;if(m.enableIf)try{const g=(v=n.instance)!=null&&v.getState().formRoot?Ve(n.instance.getState().formRoot):{};if(!be(m.enableIf,g,i))return}catch(g){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${p}]":`,g)}if(m.hidden||m.type==="hidden")i[m.key]=m.default!==void 0?m.default:null;else{const g=`${t}[${p}].${m.key}`;i[m.key]=kt({...m,key:g},{path:r},d)}}),c.push(i)}),s(t,c,e),{value:c,errors:o}}else{const c={},u=a.querySelector(`[data-container="${t}"]`)||a;return e.elements.forEach(d=>{var i;if(d.enableIf)try{const h=(i=n.instance)!=null&&i.getState().formRoot?Ve(n.instance.getState().formRoot):{};if(!be(d.enableIf,h,c))return}catch(h){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,h)}if(d.hidden||d.type==="hidden")c[d.key]=d.default!==void 0?d.default:null;else{const h=`${t}.${d.key}`;c[d.key]=kt({...d,key:h},{path:r},u)}}),{value:c,errors:o}}}function Lt(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((s,c)=>{$e(s)&&e.elements.forEach(u=>{const d=u.key,i=`${t}[${c}].${d}`,h=s[d];h!==void 0&&a.updateField(i,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(!$e(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(r=>{const s=r.key,c=`${t}.${s}`,u=n[s];u!==void 0&&a.updateField(c,u)})}}function On(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&&$e(e.repeat)),minCount:(a=e.repeat)==null?void 0:a.min,maxCount:(l=e.repeat)==null?void 0:l.max};r.multiple?wt(r,t,n):Ct(r,t,n,o)}function St(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&&$e(o.repeat)),minCount:(t=o.repeat)==null?void 0:t.min,maxCount:(n=o.repeat)==null?void 0:n.max}}function Un(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=St(e);return $t(o,t,n)}function Pn(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=St(e);return Lt(a,t,n,o)}function Tt(e,t){return Array.from({length:e},()=>Array.from({length:t},()=>""))}function At(e,t,n){for(const o of n){if(o.row===e&&o.col===t)return null;if(e>=o.row&&e<o.row+o.rowspan&&t>=o.col&&t<o.col+o.colspan)return o}return null}function Fe(e,t,n){var o;return(o=n.find(a=>a.row===e&&a.col===t))!=null?o:null}function pe(e){var t;if(!e.anchor)return null;const n=(t=e.focus)!=null?t:e.anchor;return{r1:Math.min(e.anchor.row,n.row),c1:Math.min(e.anchor.col,n.col),r2:Math.max(e.anchor.row,n.row),c2:Math.max(e.anchor.col,n.col)}}function xe(e){const t=document.createElement("button");return t.type="button",t.textContent=e.label,t.title=e.title,t.style.cssText=`
370
+ position: absolute;
371
+ width: ${e.size}px;
372
+ height: ${e.size}px;
373
+ border-radius: 50%;
374
+ border: none;
375
+ background: ${e.color};
376
+ color: ${e.textColor};
377
+ font-size: ${Math.floor(e.size*.6)}px;
378
+ line-height: ${e.size}px;
379
+ text-align: center;
380
+ cursor: pointer;
381
+ z-index: 10;
382
+ padding: 0;
383
+ display: flex;
384
+ align-items: center;
385
+ justify-content: center;
386
+ box-shadow: 0 1px 4px rgba(0,0,0,0.2);
387
+ transition: transform 0.1s, opacity 0.1s;
388
+ pointer-events: all;
389
+ `,t.addEventListener("mouseenter",()=>{t.style.transform="scale(1.15)"}),t.addEventListener("mouseleave",()=>{t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),e.onClick(n)}),t}function Vn(e,t){const{cells:n,merges:o=[]}=e;if(n.length===0)return;const a=n[0].length,l=document.createElement("table");l.style.cssText=`
390
+ width: 100%;
391
+ border-collapse: collapse;
392
+ border: var(--fb-border-width) solid var(--fb-border-color);
393
+ border-radius: var(--fb-border-radius);
394
+ font-size: var(--fb-font-size);
395
+ font-family: var(--fb-font-family);
396
+ color: var(--fb-text-color);
397
+ `,n.forEach((s,c)=>{var u,d;const i=(c===0?l.createTHead():(u=l.tBodies[0])!=null?u:l.createTBody()).insertRow();for(let h=0;h<a;h++){if(At(c,h,o))continue;const p=Fe(c,h,o),m=document.createElement(c===0?"th":"td");p&&(p.rowspan>1&&(m.rowSpan=p.rowspan),p.colspan>1&&(m.colSpan=p.colspan)),m.textContent=(d=s[h])!=null?d:"",m.style.cssText=`
398
+ padding: 6px 10px;
399
+ border: var(--fb-border-width) solid var(--fb-border-color);
400
+ text-align: left;
401
+ vertical-align: top;
402
+ ${c===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":""}
403
+ `,i.appendChild(m)}});const r=document.createElement("div");r.style.cssText="overflow-x: auto; max-width: 100%;",r.appendChild(l),t.appendChild(r)}function _n(e,t,n,o,a,l){if(e.contentEditable==="true")return;e.contentEditable="true",e.focus();const r=document.createRange(),s=window.getSelection();r.selectNodeContents(e),r.collapse(!1),s==null||s.removeAllRanges(),s==null||s.addRange(r);function c(){var i;e.contentEditable="inherit";const h=o();h[t]&&(h[t][n]=(i=e.textContent)!=null?i:""),a()}function u(i){var h,p,m,v;const g=o(),C=(p=(h=g[0])==null?void 0:h.length)!=null?p:0;if(i.key==="Escape"){e.contentEditable="inherit",e.textContent=(v=(m=g[t])==null?void 0:m[n])!=null?v:"",e.removeEventListener("keydown",u),e.removeEventListener("blur",d);return}if(i.key==="Enter"&&!i.shiftKey){i.preventDefault(),i.stopPropagation(),c(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d);const f=t+1<g.length?t+1:t;l(f,n);return}if(i.key==="Tab"){i.preventDefault(),i.stopPropagation(),c(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d);let f=t,b=i.shiftKey?n-1:n+1;b<0&&(b=C-1,f=Math.max(0,t-1)),b>=C&&(b=0,f=Math.min(g.length-1,t+1)),l(f,b)}}function d(){e.contentEditable==="true"&&(c(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d))}e.addEventListener("keydown",u),e.addEventListener("blur",d)}function Wn(e,t,n,o,a){var l,r;const s=o.state,c=o.instance,u=t.cells.length>0?t.cells.map(T=>[...T]):Tt((l=e.rows)!=null?l:3,(r=e.columns)!=null?r:3);let d=t.merges?[...t.merges]:[];const i={anchor:null,focus:null,dragging:!1},h=document.createElement("input");h.type="hidden",h.name=n,h.value=JSON.stringify({cells:u,merges:d}),a.appendChild(h);function p(){h.value=JSON.stringify({cells:u,merges:d}),c&&c.triggerOnChange(n,{cells:u,merges:d})}h._applyExternalUpdate=T=>{u.length=0,T.cells.forEach(k=>u.push([...k])),d.length=0,T.merges&&T.merges.forEach(k=>d.push({...k})),i.anchor=null,i.focus=null,p(),se()};const m=document.createElement("div");m.style.cssText="position: relative; padding: 20px 20px 20px 24px; overflow-x: auto; max-width: 100%;";const v=document.createElement("table");v.style.cssText=`
404
+ border-collapse: collapse;
405
+ font-size: var(--fb-font-size);
406
+ font-family: var(--fb-font-family);
407
+ color: var(--fb-text-color);
408
+ table-layout: fixed;
409
+ `,m.appendChild(v),a.appendChild(m);const g=document.createElement("div");g.style.cssText=`
410
+ position: fixed;
411
+ display: none;
412
+ background: white;
413
+ border: 1px solid var(--fb-border-color);
414
+ border-radius: var(--fb-border-radius);
415
+ box-shadow: 0 2px 8px rgba(0,0,0,0.15);
416
+ padding: 4px;
417
+ z-index: 1000;
418
+ gap: 4px;
419
+ flex-direction: column;
420
+ `,a.appendChild(g);function C(T,k){const w=document.createElement("button");return w.type="button",w.textContent=T,w.style.cssText=`
421
+ padding: 4px 10px;
422
+ font-size: var(--fb-font-size-small);
423
+ color: var(--fb-text-color);
424
+ border: 1px solid var(--fb-border-color);
425
+ border-radius: var(--fb-border-radius);
426
+ background: transparent;
427
+ cursor: pointer;
428
+ white-space: nowrap;
429
+ text-align: left;
430
+ `,w.addEventListener("mouseenter",()=>{w.style.background="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.background="transparent"}),w.addEventListener("click",()=>{b(),k()}),w}function f(T,k){g.innerHTML="",g.style.display="flex";const w=pe(i),q=w&&(w.r1!==w.r2||w.c1!==w.c2),R=i.anchor&&Fe(i.anchor.row,i.anchor.col,d);if(q&&g.appendChild(C(L("tableMergeCells",s),G)),R&&g.appendChild(C(L("tableSplitCell",s),he)),!g.firstChild){b();return}const F=140,j=g.children.length*32+8,H=window.innerWidth,B=window.innerHeight,U=T+F>H?T-F:T,W=k+j>B?k-j:k;g.style.left=`${U}px`,g.style.top=`${W}px`}function b(){g.style.display="none"}const x=new AbortController;document.addEventListener("mousedown",T=>{if(!a.isConnected){x.abort();return}g.contains(T.target)||b()},{signal:x.signal});function y(){const T=pe(i);v.querySelectorAll("td[data-row]").forEach(k=>{const w=parseInt(k.getAttribute("data-row")||"0",10),q=parseInt(k.getAttribute("data-col")||"0",10),R=i.anchor!==null&&i.anchor.row===w&&i.anchor.col===q,F=T!==null&&w>=T.r1&&w<=T.r2&&q>=T.c1&&q<=T.c2;k.style.outline=R?"2px solid var(--fb-primary-color, #0066cc)":"",k.style.outlineOffset=R?"-2px":"",w===0?k.style.backgroundColor="var(--fb-background-hover-color)":k.style.backgroundColor=F&&!R?"rgba(0,102,204,0.08)":""})}function E(T,k){i.anchor={row:T,col:k},i.focus=null,y(),v.focus()}function S(T,k){const w=v.querySelector(`td[data-row="${T}"][data-col="${k}"]`);if(!w)return;const q=w.querySelector("span");q&&(i.anchor={row:T,col:k},i.focus=null,y(),_n(q,T,k,()=>u,p,E))}function A(T){var k;const w=u.length>0?u[0].length:(k=e.columns)!=null?k:3,q=Array(w).fill(""),R=T!==void 0?T+1:u.length;u.splice(R,0,q),d=d.map(F=>F.row>=R?{...F,row:F.row+1}:F.row<R&&F.row+F.rowspan>R?{...F,rowspan:F.rowspan+1}:F),p(),se()}function z(T){if(u.length<=1)return;const k=T!==void 0?T:i.anchor?i.anchor.row:u.length-1;d=d.map(w=>{const q=w.row+w.rowspan-1;return w.row===k&&w.rowspan===1?null:w.row===k?{...w,row:w.row+1,rowspan:w.rowspan-1}:q===k?{...w,rowspan:w.rowspan-1}:w.row<k&&q>k?{...w,rowspan:w.rowspan-1}:w.row>k?{...w,row:w.row-1}:w}).filter(w=>w!==null),u.splice(k,1),i.anchor&&i.anchor.row>=u.length&&(i.anchor={row:u.length-1,col:i.anchor.col}),p(),se()}function X(T){var k,w;const q=T!==void 0?T+1:(w=(k=u[0])==null?void 0:k.length)!=null?w:0;u.forEach(R=>R.splice(q,0,"")),d=d.map(R=>R.col>=q?{...R,col:R.col+1}:R.col<q&&R.col+R.colspan>q?{...R,colspan:R.colspan+1}:R),p(),se()}function Z(T){if(u.length===0||u[0].length<=1)return;const k=T!==void 0?T:i.anchor?i.anchor.col:u[0].length-1;d=d.map(w=>{const q=w.col+w.colspan-1;return w.col===k&&w.colspan===1?null:w.col===k?{...w,col:w.col+1,colspan:w.colspan-1}:q===k?{...w,colspan:w.colspan-1}:w.col<k&&q>k?{...w,colspan:w.colspan-1}:w.col>k?{...w,col:w.col-1}:w}).filter(w=>w!==null),u.forEach(w=>w.splice(k,1)),i.anchor&&i.anchor.col>=u[0].length&&(i.anchor={row:i.anchor.row,col:u[0].length-1}),p(),se()}function G(){const T=pe(i);if(!T)return;const{r1:k,c1:w,r2:q,c2:R}=T;if(k===q&&w===R)return;d=d.filter(j=>{const H=j.row+j.rowspan-1,B=j.col+j.colspan-1;return!(j.row<=q&&H>=k&&j.col<=R&&B>=w)});const F=u[k][w];for(let j=k;j<=q;j++)for(let H=w;H<=R;H++)(j!==k||H!==w)&&(u[j][H]="");u[k][w]=F,d.push({row:k,col:w,rowspan:q-k+1,colspan:R-w+1}),i.anchor={row:k,col:w},i.focus=null,p(),se()}function he(){if(!i.anchor)return;const{row:T,col:k}=i.anchor,w=d.findIndex(q=>q.row===T&&q.col===k);w!==-1&&(d.splice(w,1),i.focus=null,p(),se())}function se(){var T,k;v.innerHTML="";const w=u.length,q=w>0?u[0].length:0,R=pe(i);for(let F=0;F<w;F++){const j=(F===0?(T=v.tHead)!=null?T:v.createTHead():(k=v.tBodies[0])!=null?k:v.createTBody()).insertRow();for(let H=0;H<q;H++){if(At(F,H,d))continue;const B=Fe(F,H,d),U=document.createElement("td");U.setAttribute("data-row",String(F)),U.setAttribute("data-col",String(H)),B&&(B.rowspan>1&&(U.rowSpan=B.rowspan),B.colspan>1&&(U.colSpan=B.colspan));const W=R!==null&&F>=R.r1&&F<=R.r2&&H>=R.c1&&H<=R.c2,O=i.anchor!==null&&i.anchor.row===F&&i.anchor.col===H;U.style.cssText=["border: var(--fb-border-width) solid var(--fb-border-color);","padding: 4px 8px;","min-width: 80px;","vertical-align: top;","cursor: text;","position: relative;",F===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":"",W&&!O?"background-color: rgba(0,102,204,0.08);":"",O?"outline: 2px solid var(--fb-primary-color, #0066cc); outline-offset: -2px;":""].join(" ");const J=document.createElement("span");J.textContent=u[F][H],J.style.cssText="display: block; min-height: 1.4em; white-space: pre-wrap; word-break: break-word; outline: none;",U.appendChild(J);const P=F,Y=H;U.addEventListener("mousedown",K=>{if(K.target.tagName!=="BUTTON"&&K.target.contentEditable!=="true"){if(K.button===2){const V=pe(i);if(V&&P>=V.r1&&P<=V.r2&&Y>=V.c1&&Y<=V.c2)return}K.shiftKey&&i.anchor?(K.preventDefault(),i.focus={row:P,col:Y},i.dragging=!1,y()):(i.anchor={row:P,col:Y},i.focus=null,i.dragging=!0,y())}}),U.addEventListener("mouseup",K=>{if(K.target.tagName!=="BUTTON"&&i.dragging){i.dragging=!1;const V=pe(i);(!V||V.r1===V.r2&&V.c1===V.c2)&&S(P,Y)}}),U.addEventListener("mousemove",K=>{if(i.dragging&&K.buttons===1){const V=i.anchor;V&&(V.row!==P||V.col!==Y)&&(i.focus={row:P,col:Y},y())}}),U.addEventListener("contextmenu",K=>{const V=pe(i),ne=V&&(V.r1!==V.r2||V.c1!==V.c2),ee=i.anchor&&Fe(i.anchor.row,i.anchor.col,d);(ne||ee)&&(K.preventDefault(),f(K.clientX,K.clientY))}),j.appendChild(U)}}I(),v.setAttribute("tabindex","0"),v.onkeydown=F=>{var j,H;if(v.querySelector("[contenteditable='true']"))return;const B=i.anchor;if(!B)return;const U=u.length,W=U>0?u[0].length:0,O={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};if(O[F.key]){F.preventDefault();const[J,P]=O[F.key],Y=Math.max(0,Math.min(U-1,B.row+J)),K=Math.max(0,Math.min(W-1,B.col+P));F.shiftKey?(i.focus={row:Y,col:K},y()):E(Y,K);return}if(F.key==="Enter"){F.preventDefault(),S(B.row,B.col);return}if(F.key==="Tab"){F.preventDefault();const J=(H=(j=u[0])==null?void 0:j.length)!=null?H:0;let P=B.row,Y=F.shiftKey?B.col-1:B.col+1;Y<0&&(Y=J-1,P=Math.max(0,P-1)),Y>=J&&(Y=0,P=Math.min(u.length-1,P+1)),E(P,Y);return}if(F.key==="m"&&F.ctrlKey&&!F.shiftKey){F.preventDefault(),G();return}F.key==="M"&&F.ctrlKey&&F.shiftKey&&(F.preventDefault(),he())},v.oncopy=F=>{var j,H,B,U;const W=pe(i);if(!W)return;F.preventDefault();const{r1:O,c1:J,r2:P,c2:Y}=W,K=[],V=[];for(let D=O;D<=P;D++){const Q=[],oe=[];for(let le=J;le<=Y;le++){const ce=(H=(j=u[D])==null?void 0:j[le])!=null?H:"";Q.push(ce);const ve=ce.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");oe.push(`<td>${ve}</td>`)}K.push(Q.join(" ")),V.push(`<tr>${oe.join("")}</tr>`)}const ne=K.join(`
431
+ `),ee=`<table>${V.join("")}</table>`;(B=F.clipboardData)==null||B.setData("text/plain",ne),(U=F.clipboardData)==null||U.setData("text/html",ee)},v.onpaste=F=>{var j,H,B,U,W,O,J,P,Y;const K=i.anchor;if(!K)return;const V=(H=(j=F.clipboardData)==null?void 0:j.getData("text/plain"))!=null?H:"",ne=V.includes(" ")||V.split(/\r?\n/).filter(re=>re).length>1,ee=v.querySelector("[contenteditable='true']");if(ee&&!ne)return;if(F.preventDefault(),ee){ee.contentEditable="inherit";const re=parseInt((U=(B=ee.closest("td"))==null?void 0:B.getAttribute("data-row"))!=null?U:"0",10),me=parseInt((O=(W=ee.closest("td"))==null?void 0:W.getAttribute("data-col"))!=null?O:"0",10);u[re]&&(u[re][me]=(J=ee.textContent)!=null?J:"")}if(!V.trim())return;const D=V.split(/\r?\n/).map(re=>re.split(" "));D.length>1&&D[D.length-1].length===1&&D[D.length-1][0]===""&&D.pop();const Q=K.row,oe=K.col,le=Q+D.length;for(;u.length<le;)u.push(Array((Y=(P=u[0])==null?void 0:P.length)!=null?Y:1).fill(""));const ce=Math.max(...D.map(re=>re.length)),ve=oe+ce;if(u[0]&&ve>u[0].length){const re=ve-u[0].length;u.forEach(me=>{for(let ke=0;ke<re;ke++)me.push("")})}for(let re=0;re<D.length;re++)for(let me=0;me<D[re].length;me++){const ke=Q+re,Cr=oe+me;u[ke]&&(u[ke][Cr]=D[re][me])}p(),se()}}const te=xe({label:"+",title:L("tableAddColumn",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var T;const k=parseInt((T=te.dataset.afterCol)!=null?T:"0",10);X(k)}});te.style.position="absolute",te.style.display="none",m.appendChild(te);const ae=xe({label:"+",title:L("tableAddRow",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var T;const k=parseInt((T=ae.dataset.afterRow)!=null?T:"0",10);A(k)}});ae.style.position="absolute",ae.style.display="none",m.appendChild(ae);let fe=[],$=[];const M=xe({label:"+",title:L("tableAddColumn",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>X()});M.style.position="absolute",M.style.display="none",m.appendChild(M);const N=xe({label:"+",title:L("tableAddRow",s),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>A()});N.style.position="absolute",N.style.display="none",m.appendChild(N);function I(){var T,k;fe.forEach(H=>H.remove()),fe=[],$.forEach(H=>H.remove()),$=[];const w=u.length>0?u[0].length:0,q=u.length;if(w>1){const H=Array.from(v.querySelectorAll("thead td[data-col]"));for(const B of H){const U=parseInt((T=B.getAttribute("data-col"))!=null?T:"0",10),W=xe({label:"\xD7",title:L("tableRemoveColumn",s),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>Z(U)});W.setAttribute("data-action","remove-col"),W.setAttribute("data-col",String(U)),W.style.position="absolute",W.style.display="none",m.appendChild(W),fe.push(W)}}if(q>1){const H=[...v.tHead?Array.from(v.tHead.rows):[],...v.tBodies[0]?Array.from(v.tBodies[0].rows):[]].filter(B=>B.querySelector("td[data-row]"));for(const B of H){const U=B.querySelector("td[data-row]");if(!U)continue;const W=parseInt((k=U.getAttribute("data-row"))!=null?k:"0",10),O=xe({label:"\xD7",title:L("tableRemoveRow",s),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>z(W)});O.setAttribute("data-action","remove-row"),O.setAttribute("data-row",String(W)),O.style.position="absolute",O.style.display="none",m.appendChild(O),$.push(O)}}function R(H,B,U,W,O){var J;const P=O?Array.from(v.querySelectorAll("thead td[data-col]")):[];let Y=-1,K=1/0,V=-1,ne=-1,ee=1/0;for(let D=0;D<P.length;D++){const Q=P[D].getBoundingClientRect(),oe=(Q.left+Q.right)/2,le=Math.abs(H-oe);le<K&&(K=le,Y=D);const ce=Math.abs(H-Q.right);ce<ee&&ce<20&&(ee=ce,V=Q.right-B.left+W,ne=parseInt((J=P[D].getAttribute("data-col"))!=null?J:"0",10))}fe.forEach((D,Q)=>{if(!O||Q!==Y){D.style.display="none";return}const oe=P[Q].getBoundingClientRect(),le=(oe.left+oe.right)/2-B.left+W;D.style.left=`${le-8}px`,D.style.top="2px",D.style.display="flex"}),O&&ne>=0?(te.style.display="flex",te.style.left=`${V-10}px`,te.style.top=`${U.top-B.top-10}px`,te.dataset.afterCol=String(ne)):te.style.display="none"}function F(H,B,U,W,O){var J;const P=[];if(O){if(v.tHead)for(const D of Array.from(v.tHead.rows))D.querySelector("td[data-row]")&&P.push(D);if(v.tBodies[0])for(const D of Array.from(v.tBodies[0].rows))D.querySelector("td[data-row]")&&P.push(D)}let Y=-1,K=1/0,V=-1,ne=-1,ee=1/0;for(let D=0;D<P.length;D++){const Q=P[D].getBoundingClientRect(),oe=(Q.top+Q.bottom)/2,le=Math.abs(H-oe);le<K&&(K=le,Y=D);const ce=Math.abs(H-Q.bottom);if(ce<ee&&ce<14){ee=ce,V=Q.bottom-B.top;const ve=P[D].querySelector("td[data-row]");ne=parseInt((J=ve==null?void 0:ve.getAttribute("data-row"))!=null?J:"0",10)}}$.forEach((D,Q)=>{if(!O||Q!==Y){D.style.display="none";return}const oe=P[Q].getBoundingClientRect(),le=(oe.top+oe.bottom)/2-B.top;D.style.left="4px",D.style.top=`${le-8}px`,D.style.display="flex"}),O&&ne>=0?(ae.style.display="flex",ae.style.top=`${V-10}px`,ae.style.left=`${U.left-B.left+W-10}px`,ae.dataset.afterRow=String(ne)):ae.style.display="none"}let j=!1;m.onmousemove=H=>{const B=H.target;if(B.tagName==="BUTTON"&&B.parentElement===m||j)return;j=!0;const U=H.clientX,W=H.clientY;requestAnimationFrame(()=>{j=!1;const O=m.getBoundingClientRect(),J=v.getBoundingClientRect(),P=m.scrollLeft,Y=W>=O.top&&W<J.top+4,K=U>=O.left&&U<J.left+4,V=Math.min(J.right,O.right),ne=U>V-20&&U<=O.right,ee=W>J.bottom-4&&W<=O.bottom+20;if(R(U,O,J,P,Y),F(W,O,J,P,K),M.style.display=ne?"flex":"none",ne&&(M.style.left=`${O.right-O.left+P-20}px`,M.style.top=`${(J.top+J.bottom)/2-O.top-10}px`),N.style.display=ee?"flex":"none",ee){const D=(O.left+O.right)/2-O.left+P;N.style.left=`${D-10}px`,N.style.top=`${J.bottom-O.top-10}px`}})},m.onmouseleave=()=>{fe.forEach(H=>{H.style.display="none"}),$.forEach(H=>{H.style.display="none"}),te.style.display="none",ae.style.display="none",M.style.display="none",N.style.display="none"}}se()}function Kn(e){var t,n;return{cells:Tt((t=e.rows)!=null?t:3,(n=e.columns)!=null?n:3),merges:[]}}function Ke(e){return e!==null&&typeof e=="object"&&"cells"in e&&Array.isArray(e.cells)}function Jn(e,t,n,o){const a=t.state,l=t.prefill[e.key],r=Ke(l)?l:Ke(e.default)?e.default:Kn(e);a.config.readonly?Vn(r,n):Wn(e,r,o,t,n)}function Yn(e,t,n){const{scopeRoot:o,skipValidation:a}=n,l=[],r=o.querySelector(`[name="${t}"]`);if(!r)return{value:null,errors:l};let s=null;try{s=JSON.parse(r.value)}catch(c){return l.push(`${t}: invalid table data`),{value:null,errors:l}}return!a&&e.required&&(s.cells.some(c=>c.some(u=>u.trim()!==""))||l.push(`${t}: ${L("required",n.state)}`)),{value:s,errors:l}}function Xn(e,t,n,o){const{scopeRoot:a}=o,l=a.querySelector(`[name="${t}"]`);if(!l){console.warn(`updateTableField: no hidden input found for "${t}". Re-render to reflect new data.`);return}Ke(n)&&l._applyExternalUpdate?l._applyExternalUpdate(n):l.value=JSON.stringify(n)}function Gn(e,t){e.style.overflow="hidden",e.style.resize="none";const n=(e.value.match(/\n/g)||[]).length+1;e.rows=Math.max(3,n);const o=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`,t&&(t.style.height=`${e.scrollHeight}px`))};e.addEventListener("input",o),setTimeout(()=>{e.isConnected&&o()},0)}function Je(e,t){var n,o,a,l;const r=new Map,s=new Map;for(const c of e){const u=t.resourceIndex.get(c),d=(n=u==null?void 0:u.name)!=null?n:c;s.set(d,((o=s.get(d))!=null?o:0)+1)}for(const c of e){const u=t.resourceIndex.get(c),d=(a=u==null?void 0:u.name)!=null?a:c;((l=s.get(d))!=null?l:1)>1&&u?r.set(c,`${d} (${Jt(u.size)})`):r.set(c,d)}return r}function Ye(e){return e?e.type.startsWith("image/"):!1}function Ft(e,t){const n=Je(e,t),o=new Map;for(const a of e){const l=n.get(a);l&&o.set(l,a)}return o}function Xe(e){return/\s/.test(e)||e.includes('"')?`@"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`@${e}`}function Ne(e){const t=[],n=e.length;let o=0;for(;o<n;)if(e[o]==="@"){if(o>0&&!/\s/.test(e[o-1])){o++;continue}const a=o;if(o++,o<n&&e[o]==='"'){o++;let l="";for(;o<n&&e[o]!=='"';)e[o]==="\\"&&o+1<n?(l+=e[o+1],o+=2):(l+=e[o],o++);o<n&&e[o]==='"'&&(o++,(o>=n||/\s/.test(e[o]))&&t.push({start:a,end:o,raw:e.slice(a,o),name:l}))}else if(o<n&&!/\s/.test(e[o])){const l=o;for(;o<n&&!/\s/.test(e[o]);)o++;const r=e.slice(l,o);t.push({start:a,end:o,raw:e.slice(a,o),name:r})}}else o++;return t}function Zn(e,t){if(t.size===0)return[];const n=Ne(e),o=[];for(const a of n){const l=t.get(a.name);l&&o.push({start:a.start,end:a.end,name:a.name,rid:l})}return o}function Qn(e,t){const n=Zn(e,t);if(n.length===0)return e;let o="",a=0;for(const l of n)o+=e.slice(a,l.start),o+=`@${l.rid}`,a=l.end;return o+=e.slice(a),o}function Nt(e,t,n){const o=Je(t,n),a=new Map;for(const c of t){const u=o.get(c);u&&a.set(c,u)}const l=Ne(e);if(l.length===0)return e;let r="",s=0;for(const c of l){r+=e.slice(s,c.start);const u=a.get(c.name);u?r+=Xe(u):r+=c.raw,s=c.end}return r+=e.slice(s),r}function Mt(e,t,n,o){if(ie(e),n!=null&&n.file&&Ye(n)){const a=document.createElement("img");a.alt=n.name,a.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const l=new FileReader;l.onload=r=>{var s;a.src=((s=r.target)==null?void 0:s.result)||""},l.readAsDataURL(n.file),e.appendChild(a)}else if(o.config.getThumbnail){o.config.getThumbnail(t).then(l=>{var r;if(!l||!e.isConnected)return;const s=document.createElement("img");s.alt=(r=n==null?void 0:n.name)!=null?r:t,s.src=l,s.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",ie(e),e.appendChild(s)}).catch(l=>{var r,s;(s=(r=o.config).onThumbnailError)==null||s.call(r,l,t)});const a=document.createElement("div");a.style.cssText="width: 100%; height: 100%; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",a.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',e.appendChild(a)}else{const a=document.createElement("div");if(a.style.cssText="width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; box-sizing: border-box;",a.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',n!=null&&n.name){const l=document.createElement("span");l.style.cssText="font-size: 9px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44px; color: var(--fb-text-color, #111827);",l.textContent=n.name,a.appendChild(l)}e.appendChild(a)}}function qt(e,t,n,o){if(ie(e),n!=null&&n.file&&Ye(n)){const a=document.createElement("img");a.alt=n.name,a.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;";const l=new FileReader;l.onload=r=>{var s;a.src=((s=r.target)==null?void 0:s.result)||""},l.readAsDataURL(n.file),e.appendChild(a)}else o.config.getThumbnail&&o.config.getThumbnail(t).then(a=>{var l;if(!a||!e.isConnected)return;const r=document.createElement("img");r.alt=(l=n==null?void 0:n.name)!=null?l:t,r.src=a,r.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;",ie(e),e.appendChild(r)}).catch(a=>{var l,r;(r=(l=o.config).onThumbnailError)==null||r.call(l,a,t)})}function Ht(e,t){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect(),a=Math.max(4,Math.min(n.left+n.width/2-o.width/2,window.innerWidth-o.width-4)),l=n.top-o.height-8,r=n.bottom+8,s=l>=4?l:r;e.style.left=`${a}px`,e.style.top=`${Math.max(4,s)}px`}function zt(e,t,n){const o=n.resourceIndex.get(t),a=document.createElement("div");a.className="fb-richinput-portal-tooltip fb-richinput-mention-tooltip",a.style.cssText=`
432
+ position: fixed;
433
+ z-index: 99999;
434
+ background: #fff;
435
+ border: 1px solid var(--fb-border-color, #d1d5db);
436
+ border-radius: 8px;
437
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
438
+ padding: 4px;
439
+ pointer-events: none;
440
+ min-width: 60px;
441
+ max-width: 140px;
442
+ `;const l=document.createElement("div");return l.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",qt(l,t,o,n),a.appendChild(l),document.body.appendChild(a),Ht(a,e),a}function Rt(e,t){var n,o;const{rid:a,state:l,isReadonly:r,onMention:s,onRemove:c}=t,u=l.resourceIndex.get(a),d=(n=u==null?void 0:u.name)!=null?n:a,i=document.createElement("div");i.className="fb-richinput-portal-tooltip fb-richinput-file-tooltip",i.style.cssText=`
443
+ position: fixed;
444
+ z-index: 99999;
445
+ background: #fff;
446
+ border: 1px solid var(--fb-border-color, #d1d5db);
447
+ border-radius: 8px;
448
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
449
+ padding: 4px;
450
+ pointer-events: auto;
451
+ min-width: 80px;
452
+ max-width: 260px;
453
+ `;const h=document.createElement("div");h.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",qt(h,a,u,l),i.appendChild(h);const p=document.createElement("div");p.style.cssText="padding: 4px 6px 2px; font-size: 12px; color: var(--fb-text-color, #111827); word-break: break-word; border-top: 1px solid var(--fb-border-color, #d1d5db);",p.textContent=d,i.appendChild(p);const m=document.createElement("div");m.style.cssText="display: flex; align-items: center; gap: 2px; padding: 3px 4px 2px; border-top: 1px solid var(--fb-border-color, #d1d5db); justify-content: center;";const v="background: none; border: none; cursor: pointer; padding: 3px 5px; border-radius: 4px; color: var(--fb-text-muted-color, #6b7280); display: flex; align-items: center; transition: background 0.1s, color 0.1s;",g=f=>{f.style.background="var(--fb-background-hover-color, #f3f4f6)",f.style.color="var(--fb-text-color, #111827)"},C=f=>{f.style.background="none",f.style.color="var(--fb-text-muted-color, #6b7280)"};if(!r&&s){const f=document.createElement("button");f.type="button",f.title="Mention",f.style.cssText=v,f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="4"/><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"/></svg>',f.addEventListener("mouseenter",()=>g(f)),f.addEventListener("mouseleave",()=>C(f)),f.addEventListener("click",b=>{b.stopPropagation(),s(),i.remove()}),m.appendChild(f)}if(l.config.downloadFile){const f=document.createElement("button");f.type="button",f.title="Download",f.style.cssText=v,f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',f.addEventListener("mouseenter",()=>g(f)),f.addEventListener("mouseleave",()=>C(f)),f.addEventListener("click",b=>{var x,y;b.stopPropagation(),(y=(x=l.config).downloadFile)==null||y.call(x,a,d)}),m.appendChild(f)}if((o=l.config.getDownloadUrl)!=null?o:l.config.getThumbnail){const f=document.createElement("button");f.type="button",f.title="Open in new window",f.style.cssText=v,f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',f.addEventListener("mouseenter",()=>g(f)),f.addEventListener("mouseleave",()=>C(f)),f.addEventListener("click",b=>{var x,y,E,S;if(b.stopPropagation(),l.config.getDownloadUrl){const A=l.config.getDownloadUrl(a);A?window.open(A,"_blank"):(y=(x=l.config).getThumbnail)==null||y.call(x,a).then(z=>{z&&window.open(z,"_blank")}).catch(()=>{})}else(S=(E=l.config).getThumbnail)==null||S.call(E,a).then(A=>{A&&window.open(A,"_blank")}).catch(()=>{})}),m.appendChild(f)}if(!r&&c){const f=document.createElement("button");f.type="button",f.title="Remove",f.style.cssText=v,f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>',f.addEventListener("mouseenter",()=>{f.style.background="var(--fb-background-hover-color, #f3f4f6)",f.style.color="var(--fb-error-color, #ef4444)"}),f.addEventListener("mouseleave",()=>C(f)),f.addEventListener("click",b=>{b.stopPropagation(),i.remove(),c()}),m.appendChild(f)}return m.children.length>0&&i.appendChild(m),document.body.appendChild(i),Ht(i,e),i}function It(){return{element:null,hideTimer:null}}function Me(e,t=150){e.hideTimer===null&&(e.hideTimer=setTimeout(()=>{e.hideTimer=null,e.element&&(e.element.remove(),e.element=null)},t))}function qe(e){e.hideTimer!==null&&(clearTimeout(e.hideTimer),e.hideTimer=null)}function Ee(e){return e&&e.remove(),null}function er(e){var t;const n=(t=e.selectionStart)!=null?t:0,o=e.value.slice(0,n);for(let a=o.length-1;a>=0;a--)if(o[a]==="@"){if(a===0||/\s/.test(o[a-1])){let l=o.slice(a+1);return l.startsWith('"')&&(l=l.slice(1)),{query:l,pos:a}}return null}return null}function Bt(e,t,n){const o=e.toLowerCase();return t.filter(a=>{var l;return((l=n.get(a))!=null?l:a).toLowerCase().includes(o)})}const He="font-size: var(--fb-font-size, 14px); font-family: var(--fb-font-family, inherit); line-height: 1.6;",Dt="padding: 12px 52px 12px 14px;";function tr(e,t,n,o,a){var l;const r=t.state,s=[...a.files],c={open:!1,query:"",triggerPos:-1,selectedIndex:0},u=new AbortController,d=document.createElement("input");d.type="hidden",d.name=o;function i(){var $,M;const N=b.value,I=Ft(s,r),T=N?Qn(N,I):null,k=($=e.textKey)!=null?$:"text",w=(M=e.filesKey)!=null?M:"files";return{[k]:N===""?null:T,[w]:[...s]}}function h(){d.value=JSON.stringify(i())}const p=document.createElement("div");p.className="fb-richinput-wrapper",p.style.cssText=`
454
+ position: relative;
455
+ border: 1px solid var(--fb-border-color, #d1d5db);
456
+ border-radius: 16px;
457
+ background: var(--fb-background-color, #f9fafb);
458
+ transition: box-shadow 0.15s, border-color 0.15s;
459
+ `,p.addEventListener("focusin",()=>{p.style.borderColor="var(--fb-primary-color, #0066cc)",p.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),p.addEventListener("focusout",()=>{p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none"});let m=0;p.addEventListener("dragenter",$=>{$.preventDefault(),m++,p.style.borderColor="var(--fb-primary-color, #0066cc)",p.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),p.addEventListener("dragover",$=>{$.preventDefault()}),p.addEventListener("dragleave",$=>{$.preventDefault(),m--,m<=0&&(m=0,p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none")}),p.addEventListener("drop",$=>{var M,N;$.preventDefault(),m=0,p.style.borderColor="var(--fb-border-color, #d1d5db)",p.style.boxShadow="none";const I=(M=$.dataTransfer)==null?void 0:M.files;if(!I||!r.config.uploadFile)return;const T=(N=e.maxFiles)!=null?N:1/0;for(let k=0;k<I.length&&s.length<T;k++)ae(I[k])});const v=document.createElement("div");v.className="fb-richinput-files",v.style.cssText="display: none; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0; align-items: center;";const g=document.createElement("input");g.type="file",g.multiple=!0,g.style.display="none",e.accept&&(typeof e.accept=="string"?g.accept=e.accept:g.accept=e.accept.extensions.map($=>$.startsWith(".")?$:`.${$}`).join(","));const C=document.createElement("div");C.style.cssText="position: relative;";const f=document.createElement("div");f.className="fb-richinput-backdrop",f.style.cssText=`
460
+ position: absolute;
461
+ top: 0; left: 0; right: 0; bottom: 0;
462
+ ${Dt}
463
+ ${He}
464
+ white-space: pre-wrap;
465
+ word-break: break-word;
466
+ color: transparent;
467
+ pointer-events: none;
468
+ overflow: hidden;
469
+ border-radius: inherit;
470
+ box-sizing: border-box;
471
+ z-index: 2;
472
+ `;const b=document.createElement("textarea");b.name=`${o}__text`,b.placeholder=e.placeholder||L("richinputPlaceholder",r);const x=(l=a.text)!=null?l:"";b.value=x?Nt(x,s,r):"",b.style.cssText=`
473
+ width: 100%;
474
+ ${Dt}
475
+ ${He}
476
+ background: transparent;
477
+ border: none;
478
+ outline: none;
479
+ resize: none;
480
+ color: var(--fb-text-color, #111827);
481
+ box-sizing: border-box;
482
+ position: relative;
483
+ z-index: 1;
484
+ caret-color: var(--fb-text-color, #111827);
485
+ `,Gn(b,f),b.addEventListener("scroll",()=>{f.scrollTop=b.scrollTop});let y=null;f.addEventListener("mouseover",$=>{var M,N;const I=(N=(M=$.target).closest)==null?void 0:N.call(M,"mark");I!=null&&I.dataset.rid&&(y=Ee(y),y=zt(I,I.dataset.rid,r))}),f.addEventListener("mouseout",$=>{var M,N,I;if(!((N=(M=$.target).closest)!=null&&N.call(M,"mark")))return;const T=$.relatedTarget;(I=T==null?void 0:T.closest)!=null&&I.call(T,"mark")||(y=Ee(y))}),f.addEventListener("mousedown",$=>{var M,N;if(!((N=(M=$.target).closest)!=null&&N.call(M,"mark")))return;y=Ee(y);const I=f.querySelectorAll("mark");I.forEach(k=>k.style.pointerEvents="none");const T=document.elementFromPoint($.clientX,$.clientY);T&&T.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window,clientX:$.clientX,clientY:$.clientY,button:$.button,buttons:$.buttons,detail:$.detail})),document.addEventListener("mouseup",()=>{I.forEach(k=>k.style.pointerEvents="auto")},{once:!0})});function E(){const $=b.value,M=Ft(s,r),N=Ne($);if(N.length===0){f.innerHTML=_($)+`
486
+ `;return}let I="",T=0;for(const k of N){I+=_($.slice(T,k.start));const w=M.get(k.name);w?I+=`<mark data-rid="${_(w)}" style="background: color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent); color: transparent; border-radius: 8px; padding: 0; border: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent), 0 0 0 3px color-mix(in srgb, var(--fb-primary-color, #0066cc) 30%, transparent); box-decoration-break: clone; -webkit-box-decoration-break: clone; pointer-events: auto; cursor: text;">${_($.slice(k.start,k.end))}</mark>`:I+=`<mark style="color: transparent; background: none; padding: 0; border: none; text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: rgba(239, 68, 68, 0.45); text-underline-offset: 2px;">${_($.slice(k.start,k.end))}</mark>`,T=k.end}I+=_($.slice(T)),f.innerHTML=I+`
487
+ `}const S=document.createElement("button");S.type="button",S.title=L("richinputAttachFile",r),S.style.cssText=`
488
+ position: absolute;
489
+ right: 10px;
490
+ bottom: 10px;
491
+ z-index: 2;
492
+ width: 32px;
493
+ height: 32px;
494
+ border: none;
495
+ border-radius: 8px;
496
+ background: transparent;
497
+ cursor: pointer;
498
+ display: flex;
499
+ align-items: center;
500
+ justify-content: center;
501
+ color: var(--fb-text-muted-color, #9ca3af);
502
+ transition: color 0.15s, background 0.15s;
503
+ `,S.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',S.addEventListener("mouseenter",()=>{S.style.color="var(--fb-primary-color, #0066cc)",S.style.background="var(--fb-background-hover-color, #f3f4f6)"}),S.addEventListener("mouseleave",()=>{S.style.color="var(--fb-text-muted-color, #9ca3af)",S.style.background="transparent"}),S.addEventListener("click",()=>{var $;const M=($=e.maxFiles)!=null?$:1/0;s.length<M&&g.click()});const A=document.createElement("div");A.className="fb-richinput-dropdown",A.style.cssText=`
504
+ display: none;
505
+ position: absolute;
506
+ bottom: 100%;
507
+ left: 0;
508
+ z-index: 1000;
509
+ background: #fff;
510
+ border: 1px solid var(--fb-border-color, #d1d5db);
511
+ border-radius: var(--fb-border-radius, 6px);
512
+ box-shadow: 0 4px 12px rgba(0,0,0,0.12);
513
+ min-width: 180px;
514
+ max-width: 320px;
515
+ max-height: 200px;
516
+ overflow-y: auto;
517
+ margin-bottom: 4px;
518
+ ${He}
519
+ `;function z(){return Je(s,r)}function X($){ie(A);const M=z();if($.length===0){A.style.display="none",c.open=!1;return}$.forEach((N,I)=>{var T;const k=r.resourceIndex.get(N),w=document.createElement("div");w.className="fb-richinput-dropdown-item",w.dataset.rid=N,w.style.cssText=`
520
+ padding: 5px 10px;
521
+ cursor: pointer;
522
+ color: var(--fb-text-color, #111827);
523
+ background: ${I===c.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"};
524
+ display: flex;
525
+ align-items: center;
526
+ gap: 8px;
527
+ `;const q=document.createElement("div");if(q.style.cssText="width: 24px; height: 24px; border-radius: 4px; overflow: hidden; flex-shrink: 0; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",k!=null&&k.file&&Ye(k)){const F=document.createElement("img");F.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const j=new FileReader;j.onload=H=>{var B;F.src=((B=H.target)==null?void 0:B.result)||""},j.readAsDataURL(k.file),q.appendChild(F)}else r.config.getThumbnail&&r.config.getThumbnail(N).then(F=>{if(!F||!q.isConnected)return;const j=document.createElement("img");j.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",j.src=F,ie(q),q.appendChild(j)}).catch(()=>{}),q.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>';w.appendChild(q);const R=document.createElement("span");R.style.cssText="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;",R.textContent=(T=M.get(N))!=null?T:N,w.appendChild(R),A.appendChild(w)}),A.onmousemove=N=>{var I,T,k;const w=(T=(I=N.target).closest)==null?void 0:T.call(I,".fb-richinput-dropdown-item");if(!w)return;const q=$.indexOf((k=w.dataset.rid)!=null?k:"");q===-1||q===c.selectedIndex||(A.querySelectorAll(".fb-richinput-dropdown-item").forEach((R,F)=>{R.style.background=F===q?"var(--fb-background-hover-color, #f3f4f6)":"transparent"}),c.selectedIndex=q)},A.onmousedown=N=>{var I,T;N.preventDefault(),N.stopPropagation();const k=(T=(I=N.target).closest)==null?void 0:T.call(I,".fb-richinput-dropdown-item");k!=null&&k.dataset.rid&&he(k.dataset.rid)},A.style.display="block",c.open=!0}function Z(){const $=er(b);if(!$){G();return}c.query=$.query,c.triggerPos=$.pos,c.selectedIndex=0;const M=z(),N=Bt($.query,s,M);X(N)}function G(){A.style.display="none",c.open=!1}function he($){var M,N,I,T;const k=(I=(N=z().get($))!=null?N:(M=r.resourceIndex.get($))==null?void 0:M.name)!=null?I:$,w=(T=b.selectionStart)!=null?T:0,q=b.value.slice(0,c.triggerPos),R=b.value.slice(w),F=`${Xe(k)} `;b.value=`${q}${F}${R}`;const j=q.length+F.length;b.setSelectionRange(j,j),b.dispatchEvent(new Event("input")),G()}b.addEventListener("input",()=>{var $;E(),h(),($=t.instance)==null||$.triggerOnChange(o,i()),s.length>0?Z():G()});function se(){A.querySelectorAll(".fb-richinput-dropdown-item").forEach(($,M)=>{$.style.background=M===c.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"})}b.addEventListener("keydown",$=>{if(!c.open)return;const M=z(),N=Bt(c.query,s,M);$.key==="ArrowDown"?($.preventDefault(),c.selectedIndex=Math.min(c.selectedIndex+1,N.length-1),se()):$.key==="ArrowUp"?($.preventDefault(),c.selectedIndex=Math.max(c.selectedIndex-1,0),se()):$.key==="Enter"&&N.length>0?($.preventDefault(),he(N[c.selectedIndex])):$.key==="Escape"&&G()}),document.addEventListener("click",$=>{!p.contains($.target)&&!A.contains($.target)&&G()},{signal:u.signal});function te(){if(ie(v),s.length===0){v.style.display="none";return}v.style.display="flex",s.forEach($=>{const M=r.resourceIndex.get($),N=document.createElement("div");N.className="fb-richinput-file-thumb",N.style.cssText=`
528
+ position: relative;
529
+ width: 48px;
530
+ height: 48px;
531
+ border: 1px solid var(--fb-border-color, #d1d5db);
532
+ border-radius: 8px;
533
+ overflow: hidden;
534
+ flex-shrink: 0;
535
+ cursor: pointer;
536
+ background: #fff;
537
+ `;const I=document.createElement("div");I.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Mt(I,$,M,r),N.appendChild(I);const T=It(),k=()=>{var q,R,F;const j=(q=b.selectionStart)!=null?q:b.value.length,H=(F=(R=z().get($))!=null?R:M==null?void 0:M.name)!=null?F:$,B=b.value.slice(0,j),U=b.value.slice(j),W=`${B.length>0&&!/[\s\n]$/.test(B)?`
538
+ `:""}${Xe(H)} `;b.value=`${B}${W}${U}`;const O=j+W.length;b.setSelectionRange(O,O),b.focus(),b.dispatchEvent(new Event("input"))},w=()=>{var q;const R=s.indexOf($);R!==-1&&s.splice(R,1),te(),E(),h(),(q=t.instance)==null||q.triggerOnChange(o,i())};N.addEventListener("mouseenter",()=>{qe(T),T.element||(T.element=Rt(N,{rid:$,state:r,isReadonly:!1,onMention:k,onRemove:w}),T.element.addEventListener("mouseenter",()=>{qe(T)}),T.element.addEventListener("mouseleave",()=>{Me(T)}))}),N.addEventListener("mouseleave",()=>{Me(T)}),v.appendChild(N)})}function ae($){if(!r.config.uploadFile)return;const M=`temp-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;r.resourceIndex.set(M,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),s.push(M),te();const N=v.querySelectorAll(".fb-richinput-file-thumb"),I=N[N.length-1];I&&(I.style.opacity="0.5"),r.config.uploadFile($).then(T=>{var k;const w=s.indexOf(M);w!==-1&&(s[w]=T),r.resourceIndex.delete(M),r.resourceIndex.set(T,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),te(),E(),h(),(k=t.instance)==null||k.triggerOnChange(o,i())}).catch(T=>{var k,w;const q=s.indexOf(M);q!==-1&&s.splice(q,1),r.resourceIndex.delete(M),te(),(w=(k=r.config).onUploadError)==null||w.call(k,T,$)})}if(g.addEventListener("change",()=>{var $;const M=g.files;if(!M||M.length===0)return;const N=($=e.maxFiles)!=null?$:1/0;for(let I=0;I<M.length&&s.length<N;I++)ae(M[I]);g.value=""}),C.appendChild(f),C.appendChild(b),C.appendChild(S),C.appendChild(A),p.appendChild(v),p.appendChild(C),e.minLength!=null||e.maxLength!=null){const $=document.createElement("div");$.style.cssText="position: relative; padding: 2px 14px 6px; text-align: right;";const M=Ce(e,b,!1);M.style.cssText=`
539
+ position: static;
540
+ display: inline-block;
541
+ font-size: var(--fb-font-size-small);
542
+ color: var(--fb-text-secondary-color);
543
+ pointer-events: none;
544
+ `,$.appendChild(M),p.appendChild($)}p.appendChild(d),p.appendChild(g),h(),E(),d._applyExternalUpdate=$=>{var M;const N=(M=$.text)!=null?M:"";b.value=N?Nt(N,s,r):"",b.dispatchEvent(new Event("input")),s.length=0;for(const I of $.files)s.push(I);te(),E(),h()},n.appendChild(p),te();const fe=new MutationObserver(()=>{p.isConnected||(u.abort(),y=Ee(y),fe.disconnect())});p.parentElement&&fe.observe(p.parentElement,{childList:!0})}function nr(e,t,n,o,a){var l,r;const s=t.state,{text:c,files:u}=a,d=new Map;for(const i of u){const h=s.resourceIndex.get(i);h!=null&&h.name&&d.set(i,h.name)}if(u.length>0){const i=document.createElement("div");i.style.cssText="display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px;",u.forEach(h=>{const p=s.resourceIndex.get(h),m=document.createElement("div");m.style.cssText=`
545
+ position: relative;
546
+ width: 48px; height: 48px;
547
+ border: 1px solid var(--fb-border-color, #d1d5db);
548
+ border-radius: 8px;
549
+ overflow: hidden;
550
+ flex-shrink: 0;
551
+ background: #fff;
552
+ cursor: default;
553
+ `;const v=document.createElement("div");v.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Mt(v,h,p,s),m.appendChild(v);const g=It();m.addEventListener("mouseenter",()=>{qe(g),g.element||(g.element=Rt(m,{rid:h,state:s,isReadonly:!0}),g.element.addEventListener("mouseenter",()=>{qe(g)}),g.element.addEventListener("mouseleave",()=>{Me(g)}))}),m.addEventListener("mouseleave",()=>{Me(g)}),i.appendChild(m)}),n.appendChild(i)}if(c){const i=document.createElement("div");i.style.cssText=`
554
+ ${He}
555
+ color: var(--fb-text-color, #111827);
556
+ white-space: pre-wrap;
557
+ word-break: break-word;
558
+ `;const h=Ne(c).filter(p=>d.has(p.name)||[...d.values()].includes(p.name));if(h.length===0)i.textContent=c;else{let p=0;for(const m of h){m.start>p&&i.appendChild(document.createTextNode(c.slice(p,m.start)));const v=document.createElement("span");v.style.cssText=`
559
+ display: inline;
560
+ background: color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent);
561
+ color: var(--fb-primary-color, #0066cc);
562
+ border-radius: 8px;
563
+ padding: 1px 6px;
564
+ font-weight: 500;
565
+ cursor: default;
566
+ `;const g=d.has(m.name)?m.name:(l=[...d.entries()].find(([,f])=>f===m.name))==null?void 0:l[0],C=(r=d.get(m.name))!=null?r:m.name;if(v.textContent=`@${C}`,g){let f=null;const b=g;v.addEventListener("mouseenter",()=>{f=Ee(f),f=zt(v,b,s)}),v.addEventListener("mouseleave",()=>{f=Ee(f)})}i.appendChild(v),p=m.end}p<c.length&&i.appendChild(document.createTextNode(c.slice(p)))}n.appendChild(i)}if(!c&&u.length===0){const i=document.createElement("div");i.style.cssText="color: var(--fb-text-muted-color, #6b7280); font-size: var(--fb-font-size, 14px);",i.textContent="\u2014",n.appendChild(i)}}function rr(e,t,n,o){var a,l,r,s;const c=t.state,u=(a=e.textKey)!=null?a:"text",d=(l=e.filesKey)!=null?l:"files",i=t.prefill[e.key];let h;if(i&&typeof i=="object"&&!Array.isArray(i)){const p=i,m=(r=p[u])!=null?r:p.text,v=(s=p[d])!=null?s:p.files;h={text:typeof m=="string"?m:null,files:Array.isArray(v)?v:[]}}else typeof i=="string"?h={text:i||null,files:[]}:h={text:null,files:[]};for(const p of h.files)c.resourceIndex.has(p)||c.resourceIndex.set(p,{name:p,type:"application/octet-stream",size:0,uploadedAt:new Date,file:void 0});if(c.config.readonly)nr(e,t,n,o,h);else{if(!c.config.uploadFile)throw new Error(`RichInput field "${e.key}" requires uploadFile handler in config`);tr(e,t,n,o,h)}}function or(e,t,n){var o,a;const{scopeRoot:l,state:r,skipValidation:s}=n,c=[],u=(o=e.textKey)!=null?o:"text",d=(a=e.filesKey)!=null?a:"files",i=l.querySelector(`[name="${t}"]`);if(!i)return{value:null,errors:c};let h={};try{const f=JSON.parse(i.value);if(f&&typeof f=="object"&&!Array.isArray(f))h=f;else return c.push(`${t}: invalid richinput data`),{value:null,errors:c}}catch(f){return c.push(`${t}: invalid richinput data`),{value:null,errors:c}}const p=h[u],m=h[d],v=p===null||typeof p=="string"?p:null,g=Array.isArray(m)?m:[],C={[u]:v!=null?v:null,[d]:g};if(!s){const f=!v||v.trim()==="",b=g.length===0;e.required&&f&&b&&c.push(`${t}: ${L("required",r)}`),!f&&v&&(e.minLength!=null&&v.length<e.minLength&&c.push(`${t}: ${L("minLength",r,{min:e.minLength})}`),e.maxLength!=null&&v.length>e.maxLength&&c.push(`${t}: ${L("maxLength",r,{max:e.maxLength})}`)),e.maxFiles!=null&&g.length>e.maxFiles&&c.push(`${t}: ${L("maxFiles",r,{max:e.maxFiles})}`)}return{value:C,errors:c}}function lr(e,t,n,o){var a,l,r,s;const{scopeRoot:c}=o,u=c.querySelector(`[name="${t}"]`);if(!u){console.warn(`updateRichInputField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let d=null;if(n&&typeof n=="object"&&!Array.isArray(n)){const i=n,h=(a=e.textKey)!=null?a:"text",p=(l=e.filesKey)!=null?l:"files",m=(r=i[h])!=null?r:i.text,v=(s=i[p])!=null?s:i.files;(m!==void 0||v!==void 0)&&(d={text:typeof m=="string"?m:null,files:Array.isArray(v)?v:[]})}d&&u._applyExternalUpdate?u._applyExternalUpdate(d):d&&(u.value=JSON.stringify(d))}function ar(e,t){const n=document.getElementById(e);if(!n)return;const o=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),o)return;const a=t.getBoundingClientRect(),l=window.innerWidth,r=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const s=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let c=a.left,u=a.bottom+5;c+s.width>l&&(c=a.right-s.width),u+s.height>r&&(u=a.top-s.height-5),c<10&&(c=10),u<10&&(u=a.bottom+5),n.style.left=`${c}px`,n.style.top=`${u}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,o=t.closest('[id^="tooltip-"]');!n&&!o&&document.querySelectorAll('[id^="tooltip-"]').forEach(a=>{a.classList.add("hidden")})});function ir(e,t){var n,o,a;if(!e.enableIf)return!1;try{const l=(o=(n=t.formData)!=null?n:t.prefill)!=null?o:{},r=((a=e.enableIf.scope)!=null?a:"relative")==="relative"&&t.path?t.prefill:void 0;return!be(e.enableIf,l,r)}catch(l){console.error(`Error evaluating enableIf for field "${e.key}":`,l)}return!1}function sr(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 ze(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,s=(o=r.scope)!=null?o:"relative";let c={};const u={};if((!n.path||n.path===""?"absolute":s)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const i=d[1],h=parseInt(d[2],10),p=l.querySelector(`[data-container-item="${i}[${h}]"]`);p&&p.querySelectorAll("input, select, textarea").forEach(m=>{const v=m.getAttribute("name");if(v){const g=v.match(/\.([^.[\]]+)$/);if(g){const C=g[1];m instanceof HTMLSelectElement?u[C]=m.value:m instanceof HTMLInputElement?m.type==="checkbox"?u[C]=m.checked:m.type==="radio"?m.checked&&(u[C]=m.value):u[C]=m.value:m instanceof HTMLTextAreaElement&&(u[C]=m.value)}}})}}else{const d=r.key,i=sr(d,l);i!==void 0?c[d]=i:c=(a=n.formData)!=null?a:n.prefill}try{be(r,c,u)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function cr(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",s=l.key;let c;r==="relative"&&n.path?c=`${n.path}.${s}`:c=s;const u=a.querySelector(`[name="${c}"]`);if(!u){const d=new MutationObserver(()=>{const i=a.querySelector(`[name="${c}"]`);i&&(i.addEventListener("change",()=>{ze(e,t,n)}),i.addEventListener("input",()=>{ze(e,t,n)}),d.disconnect())});d.observe(a,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{ze(e,t,n)}),u.addEventListener("input",()=>{ze(e,t,n)})}function ur(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 dr(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(),ar(n,t)},t}function pr(e){const t=document.createElement("div");t.className="flex items-center mb-2";const n=ur(e);if(t.appendChild(n),e.description||e.hint){const o=dr(e);t.appendChild(o)}return t}function fr(e,t,n,o){const a="multiple"in e&&e.multiple;switch(e.type){case"text":a?Gt(e,t,n,o):Xt(e,t,n,o);break;case"textarea":a?Qt(e,t,n,o):Zt(e,t,n,o);break;case"number":a?rn(e,t,n,o):nn(e,t,n,o);break;case"select":a?sn(e,t,n,o):an(e,t,n,o);break;case"switcher":a?pn(e,t,n,o):dn(e,t,n,o);break;case"file":a?Fn(e,t,n,o):Tn(e,t,n,o);break;case"files":An(e,t,n,o);break;case"colour":a?Mn(e,t,n,o):Nn(e,t,n,o);break;case"slider":a?Rn(e,t,n,o):zn(e,t,n,o);break;case"group":On(e,t,n,o);break;case"container":a?wt(e,t,n):Ct(e,t,n,o);break;case"table":Jn(e,t,n,o);break;case"richinput":rr(e,t,n,o);break;default:{const l=document.createElement("div");l.className="text-red-500 text-sm",l.textContent=L("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(l)}}}function Ge(e,t){const n=ir(e,t),o=document.createElement("div");o.className="mb-6 fb-field-wrapper",o.setAttribute("data-field-key",e.key);const a=pr(e);o.appendChild(a);const l=ge(t.path,e.key);return fr(e,t,o,l),n&&(o.style.display="none",o.classList.add("fb-field-wrapper-disabled"),o.setAttribute("data-conditionally-disabled","true")),cr(o,e,t),o}Dn(Ge);const Ze={uploadFile:null,downloadFile:null,getThumbnail:null,getDownloadUrl:null,actionHandler:null,onChange:null,onFieldChange:null,onThumbnailError:null,onUploadError:null,onDownloadError:null,debounceMs:300,verboseErrors:!1,enableFilePreview:!0,maxPreviewSize:"200px",readonly:!1,locale:"en",translations:{en:{removeElement:"Remove",clickDragText:"Click or drag file",clickDragTextMultiple:"Click or drag files",noFileSelected:"No file selected",noFilesSelected:"No files selected",downloadButton:"Download",changeButton:"Change",placeholderText:"Enter text",previewAlt:"Preview",previewUnavailable:"Preview unavailable",previewError:"Preview error",videoNotSupported:"Your browser does not support the video tag.",hintLengthRange:"{min}-{max} chars",hintMaxLength:"\u2264{max} chars",hintMinLength:"\u2265{min} chars",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}MB",hintFormats:"{formats}",hintRequired:"Required",hintOptional:"Optional",hintPattern:"Format: {pattern}",fileCountSingle:"{count} file",fileCountPlural:"{count} files",fileCountRange:"({min}-{max})",required:"Required",minItems:"Minimum {min} items required",maxItems:"Maximum {max} items allowed",minLength:"Minimum {min} characters",maxLength:"Maximum {max} characters",minValue:"Must be at least {min}",maxValue:"Must be at most {max}",patternMismatch:"Invalid format",invalidPattern:"Invalid pattern in schema",notANumber:"Must be a number",invalidHexColour:"Invalid hex color",minFiles:"Minimum {min} files required",maxFiles:"Maximum {max} files allowed",unsupportedFieldType:"Unsupported field type: {type}",invalidOption:"Invalid option",tableAddRow:"Add row",tableAddColumn:"Add column",tableRemoveRow:"Remove row",tableRemoveColumn:"Remove column",tableMergeCells:"Merge cells (Ctrl+M)",tableSplitCell:"Split cell (Ctrl+Shift+M)",richinputPlaceholder:"Type text...",richinputAttachFile:"Attach file",richinputMention:"Mention",richinputRemoveFile:"Remove"},ru:{removeElement:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",clickDragText:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B",clickDragTextMultiple:"\u041D\u0430\u0436\u043C\u0438\u0442\u0435 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B",noFileSelected:"\u0424\u0430\u0439\u043B \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D",noFilesSelected:"\u041D\u0435\u0442 \u0444\u0430\u0439\u043B\u043E\u0432",downloadButton:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C",changeButton:"\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",placeholderText:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",previewAlt:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",previewUnavailable:"\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D",previewError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430",videoNotSupported:"\u0412\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0434\u0435\u043E.",hintLengthRange:"{min}-{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMaxLength:"\u2264{max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintMinLength:"\u2265{min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",hintValueRange:"{min}-{max}",hintMaxValue:"\u2264{max}",hintMinValue:"\u2265{min}",hintMaxSize:"\u2264{size}\u041C\u0411",hintFormats:"{formats}",hintRequired:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintOptional:"\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435",hintPattern:"\u0424\u043E\u0440\u043C\u0430\u0442: {pattern}",fileCountSingle:"{count} \u0444\u0430\u0439\u043B",fileCountPlural:"{count} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",required:"\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",minItems:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",maxItems:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432",minLength:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",maxLength:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",minValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 {min}",maxValue:"\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u0431\u043E\u043B\u0435\u0435 {max}",patternMismatch:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442",invalidPattern:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0432 \u0441\u0445\u0435\u043C\u0435",notANumber:"\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0447\u0438\u0441\u043B\u043E\u043C",invalidHexColour:"\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0446\u0432\u0435\u0442\u0430",minFiles:"\u041C\u0438\u043D\u0438\u043C\u0443\u043C {min} \u0444\u0430\u0439\u043B\u043E\u0432",maxFiles:"\u041C\u0430\u043A\u0441\u0438\u043C\u0443\u043C {max} \u0444\u0430\u0439\u043B\u043E\u0432",unsupportedFieldType:"\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u043B\u044F: {type}",invalidOption:"\u041D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435",tableAddRow:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableAddColumn:"\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableRemoveRow:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",tableRemoveColumn:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",tableMergeCells:"\u041E\u0431\u044A\u0435\u0434\u0438\u043D\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0438 (Ctrl+M)",tableSplitCell:"\u0420\u0430\u0437\u0434\u0435\u043B\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0443 (Ctrl+Shift+M)",richinputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442...",richinputAttachFile:"\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C \u0444\u0430\u0439\u043B",richinputMention:"\u0423\u043F\u043E\u043C\u044F\u043D\u0443\u0442\u044C",richinputRemoveFile:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C"}},theme:{}};function mr(e){const t={...Ze.translations};if(e!=null&&e.translations)for(const[n,o]of Object.entries(e.translations))t[n]={...Ze.translations[n]||{},...o};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Ze,...e,translations:t},debounceTimer:null}}function hr(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const we={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 vr(e){const t={...we,...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(`
567
+ `)}function gr(e,t){const n=vr(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=`
568
+ [data-fb-root="true"] {
569
+ ${n}
570
+ }
571
+ `}const br={default:we,dark:{...we,primaryColor:"#60a5fa",primaryHoverColor:"#3b82f6",borderColor:"#4b5563",borderHoverColor:"#6b7280",borderFocusColor:"#60a5fa",backgroundColor:"#1f2937",backgroundHoverColor:"#374151",backgroundReadonlyColor:"#111827",textColor:"#f9fafb",textSecondaryColor:"#9ca3af",textPlaceholderColor:"#6b7280",fileUploadBgColor:"#374151",fileUploadBorderColor:"#4b5563",fileUploadTextColor:"#9ca3af"},klein:{...we,primaryColor:"#0066cc",primaryHoverColor:"#0052a3",errorColor:"#d32f2f",errorHoverColor:"#c62828",successColor:"#388e3c",borderColor:"#e0e0e0",borderHoverColor:"#bdbdbd",borderFocusColor:"#0066cc",borderRadius:"4px",fontSize:"16px",fontSizeSmall:"14px",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif'}};function jt(e,t=!1){e.style.cssText=`
572
+ background-color: var(--fb-action-bg-color);
573
+ color: var(--fb-action-text-color);
574
+ border: var(--fb-border-width) solid var(--fb-action-border-color);
575
+ padding: ${t?"0.5rem 1rem":"0.5rem 0.75rem"};
576
+ font-size: var(--fb-font-size);
577
+ font-weight: var(--fb-font-weight-medium);
578
+ border-radius: var(--fb-border-radius);
579
+ transition: all var(--fb-transition-duration);
580
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
581
+ `,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 yr={text:{validate:Qe,update:et},textarea:{validate:en,update:tn},number:{validate:on,update:ln},select:{validate:cn,update:un},switcher:{validate:fn,update:mn},file:{validate:pt,update:ft},files:{validate:pt,update:ft},colour:{validate:qn,update:Hn},slider:{validate:In,update:Bn},container:{validate:$t,update:Lt},group:{validate:Un,update:Pn},table:{validate:Yn,update:Xn},richinput:{validate:or,update:lr}};function Ot(e){return yr[e]||null}function xr(e,t,n){const o=Ot(e.type);return o&&o.validate?o.validate(e,t,n):null}function Er(e,t,n,o){const a=Ot(e.type);return a&&a.update?(a.update(e,t,n,o),!0):!1}class Re{constructor(t){this.instanceId=hr(),this.state=mr(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 s=a.querySelector(".field-placeholder");return s||(s=document.createElement("div"),s.className="field-placeholder",s.style.display="none",a.appendChild(s)),s}}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=`
582
+ border-top: var(--fb-border-width) solid var(--fb-border-color);
583
+ `,t.forEach(l=>{const r=document.createElement("button");r.type="button",jt(r,!0);const s=n.includes(l),c=this.resolveActionLabel(l.key,l.label,null,s);r.textContent=c,r.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(l.value,l.key,null)}),a.appendChild(r)}),this.state.formRoot.appendChild(a)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],o=[];this.state.externalActions.forEach(l=>{!l.key||!l.value||(l.related_field?(t.has(l.related_field)||t.set(l.related_field,[]),t.get(l.related_field).push(l)):n.push(l))}),t.forEach((l,r)=>{const s=this.findFormElementByFieldPath(r);if(!s){console.warn(`External action: Could not find form element for field "${r}", treating as form-level actions`),o.push(...l);return}let c=s.closest(".fb-field-wrapper");if(c||(c=s.parentElement),!c){console.warn(`External action: Could not find wrapper for field "${r}"`);return}const u=c.querySelector(".external-actions-container");u&&u.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const i=this.findSchemaElement(r);l.forEach(h=>{const p=document.createElement("button");p.type="button",jt(p,!1);const m=this.resolveActionLabel(h.key,h.label,i);p.textContent=m,p.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)}),d.appendChild(p)}),c.appendChild(d)});const a=[...n,...o];a.length>0&&this.renderFormLevelActions(a,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const o=n.getAttribute("data-hint-values"),a=n.getAttribute("data-root-hint")==="true",l=n.getAttribute("data-container-key");if(!o||!a&&!l){console.warn("Prefill hint missing required data attributes");return}try{const r=JSON.parse(o);for(const s in r){const c=a?s:`${l}.${s}`,u=r[s];this.updateField(c,u)}}catch(r){console.error("Error parsing prefill hint values:",r)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-4",t.forEach(o=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",o.icon?a.textContent=`${o.icon} ${o.label}`:a.textContent=o.label,a.setAttribute("data-hint-values",JSON.stringify(o.values)),a.setAttribute("data-root-hint","true"),n.appendChild(a)}),n}renderForm(t,n,o,a){const l=Ie(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,ie(t),t.setAttribute("data-fb-root","true"),gr(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 s=document.createElement("div"),c=n.columns||1;c===1?s.className="space-y-4":s.className=`grid grid-cols-${c} gap-4`,n.elements.forEach(u=>{if(u.hidden)return;const d=Ge(u,{path:"",prefill:o||{},formData:o||{},state:this.state,instance:this});s.appendChild(d)}),r.appendChild(s),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,s=null)=>{const c=l.key,u={scopeRoot:s||this.state.formRoot,state:this.state,instance:this,path:r.path,skipValidation:t},d=xr(l,c,u);return d!==null?(n.push(...d.errors),d.value):(console.warn(`Unknown field type "${l.type}" for key "${c}"`),null)};return jn(a),this.state.schema.elements.forEach(l=>{if(l.enableIf)try{if(!be(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:""};Er(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,s,c;const u=a?`${a}.${l.key}`:l.key;if(l.enableIf){let d=null;if(a){const i=a.match(/^(.+)\[(\d+)\]$/);if(i){const h=i[1],p=i[2],m=this.state.formRoot.querySelector(`[data-container-item="${h}[${p}]"]`);m&&(d=m.querySelector(`[data-field-key="${l.key}"]`))}else{const h=this.state.formRoot.querySelector(`[data-container="${a}"]`);h&&(d=h.querySelector(`[data-field-key="${l.key}"]`))}}else d=this.state.formRoot.querySelector(`[data-field-key="${l.key}"]`);if(d){const i=d;try{let h;((r=l.enableIf.scope)!=null?r:"relative")==="relative"&&a&&(h=Be(t,a));const p=be(l.enableIf,t,h),m=i.getAttribute("data-conditionally-disabled")==="true";if(p&&m){const v=a?Be(t,a):t,g=Ge(l,{path:a,prefill:v&&typeof v=="object"?v:{},formData:t,state:this.state,instance:this});(s=i.parentNode)==null||s.replaceChild(g,i)}else if(!p&&!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"),(c=i.parentNode)==null||c.replaceChild(v,i)}}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 d=t==null?void 0:t[l.key];if(Array.isArray(d)){const i=this.state.formRoot.querySelectorAll("[data-container-item]");Array.from(i).filter(h=>{const p=h.getAttribute("data-container-item")||"";if(!p.startsWith(`${u}[`))return!1;const m=p.slice(u.length);return/^\[\d+\]$/.test(m)}).forEach(h=>{const p=h.getAttribute("data-container-item")||"";n(l.elements,p)})}else n(l.elements,u)}})};n(this.state.schema.elements,"")}destroy(){var t;this.state.debounceTimer!==null&&(clearTimeout(this.state.debounceTimer),this.state.debounceTimer=null),this.state.resourceIndex.clear(),this.state.formRoot&&ie(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 Ut(e){return new Re(e)}return typeof window!="undefined"&&(window.FormBuilder=Re,window.createFormBuilder=Ut,window.validateSchema=Ie),de.FormBuilderInstance=Re,de.createFormBuilder=Ut,de.default=Re,de.defaultTheme=we,de.exampleThemes=br,de.validateSchema=Ie,Object.defineProperty(de,"__esModule",{value:!0}),de})({});