@dmitryvim/form-builder 0.2.34 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1162 +0,0 @@
1
- var FormBuilder=(function(Se){"use strict";function k(e,t,n){const r=t.config.locale||"en",o=t.config.translations[r],a=t.config.translations.en;let i=(o==null?void 0:o[e])||(a==null?void 0:a[e])||e;if(n)for(const[l,s]of Object.entries(n))i=i.replace(new RegExp(`\\{${l}\\}`,"g"),String(s));return i}function ur(e,t,n){(e.minLength!=null||e.maxLength!=null)&&(e.minLength!=null&&e.maxLength!=null?t.push(k("hintLengthRange",n,{min:e.minLength,max:e.maxLength})):e.maxLength!=null?t.push(k("hintMaxLength",n,{max:e.maxLength})):e.minLength!=null&&t.push(k("hintMinLength",n,{min:e.minLength})))}function cr(e,t,n){(e.min!=null||e.max!=null)&&(e.min!=null&&e.max!=null?t.push(k("hintValueRange",n,{min:e.min,max:e.max})):e.max!=null?t.push(k("hintMaxValue",n,{max:e.max})):e.min!=null&&t.push(k("hintMinValue",n,{min:e.min})))}function dr(e,t,n){var r;const o=(r=e.maxSize)!=null?r:e.maxSizeMB;o&&o!==1/0&&t.push(k("hintMaxSize",n,{size:o}))}function fr(e,t,n){var r;(r=e.accept)!=null&&r.extensions&&t.push(k("hintFormats",n,{formats:e.accept.extensions.map(o=>o.toUpperCase()).join(",")}))}function pr(e,t,n){e.pattern&&t.push(k("hintPattern",n,{pattern:e.pattern}))}function $e(e,t){const n=[];return ur(e,n,t),e.type!=="slider"&&cr(e,n,t),dr(e,n,t),fr(e,n,t),pr(e,n,t),n.join(" \u2022 ")}function bt(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 a=e.columns,i=[1,2,3,4];(!Number.isInteger(a)||!i.includes(a))&&t.push(`schema.columns must be 1, 2, 3, or 4 (got ${a})`)}if("prefillHints"in e&&e.prefillHints){const a=e.prefillHints;Array.isArray(a)&&a.forEach((i,l)=>{if((!i.label||typeof i.label!="string")&&t.push(`schema.prefillHints[${l}] must have a 'label' property of type string`),!i.values||typeof i.values!="object")t.push(`schema.prefillHints[${l}] must have a 'values' property of type object`);else for(const s in i.values)e.elements.some(u=>u.key===s)||t.push(`schema.prefillHints[${l}] references non-existent field "${s}"`)})}function n(a,i,l){if("columns"in a&&a.columns!==void 0){const s=a.columns,u=[1,2,3,4];(!Number.isInteger(s)||!u.includes(s))&&l.push(`${i}: columns must be 1, 2, 3, or 4 (got ${s})`)}if("displayMode"in a&&a.displayMode!==void 0){const s=a.displayMode;s!=="stack"&&s!=="slides"&&l.push(`${i}: displayMode must be "stack" or "slides" (got ${JSON.stringify(s)})`)}}function r(a,i){var l,s;const u=new Set;for(const d of a)if(d.type==="richinput"&&d.flatOutput){const c=d,p=(l=c.textKey)!=null?l:"text",f=(s=c.filesKey)!=null?s:"files";for(const m of a)m!==d&&(m.key===p&&t.push(`${i}: RichInput "${d.key}" flatOutput textKey "${p}" collides with element key "${m.key}"`),m.key===f&&t.push(`${i}: RichInput "${d.key}" flatOutput filesKey "${f}" collides with element key "${m.key}"`));u.has(p)&&t.push(`${i}: RichInput "${d.key}" flatOutput textKey "${p}" collides with another flatOutput key`),u.has(f)&&t.push(`${i}: RichInput "${d.key}" flatOutput filesKey "${f}" collides with another flatOutput key`),u.add(p),u.add(f)}else d.key&&(u.has(d.key)&&t.push(`${i}: Element key "${d.key}" collides with a flatOutput richinput key`),u.add(d.key))}function o(a,i){a.forEach((l,s)=>{const u=`${i}[${s}]`;if(l.type||t.push(`${u}: missing type`),!l.key&&l.type!=="markdown"&&t.push(`${u}: missing key`),l.type==="markdown"){const d=l.content;typeof d!="string"&&t.push(`${u}: markdown element requires "content" to be a string (got ${d===null?"null":typeof d})`)}if(l.enableIf){const d=l.enableIf;(!d.key||typeof d.key!="string")&&t.push(`${u}: enableIf must have a 'key' property of type string`),"equals"in d||t.push(`${u}: enableIf must have at least one operator (equals, etc.)`)}if(l.type==="group"&&"elements"in l&&l.elements&&o(l.elements,`${u}.elements`),l.type==="container"&&l.elements){if(n(l,u,t),"prefillHints"in l&&l.prefillHints){const d=l.prefillHints;Array.isArray(d)&&d.forEach((c,p)=>{if((!c.label||typeof c.label!="string")&&t.push(`${u}: prefillHints[${p}] must have a 'label' property of type string`),!c.values||typeof c.values!="object")t.push(`${u}: prefillHints[${p}] must have a 'values' property of type object`);else for(const f in c.values)l.elements.some(m=>m.key===f)||t.push(`container "${l.key}": prefillHints[${p}] references non-existent field "${f}"`)})}o(l.elements,`${u}.elements`),r(l.elements,`${u}.elements`)}if(l.type==="select"&&l.options){const d=l.default;d!=null&&d!==""&&(l.options.some(c=>c.value===d)||t.push(`${u}: default "${d}" not in options`))}})}return Array.isArray(e.elements)&&(o(e.elements,"elements"),r(e.elements,"elements")),t}function oe(e,t,n){return e.readonly===!0||t.config.readonly===!0||(n==null?void 0:n.inheritedReadonly)===!0}function Ze(e){return e&&typeof e=="object"&&e.constructor===Object}function le(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function vt(e,t){if(e.key)return e.key;const n=t.syntheticElementIds.get(e);if(n!==void 0)return n;const r=`fb-synthetic-${t.syntheticElementIdCounter++}`;return t.syntheticElementIds.set(e,r),r}function Ce(e,t){return e?`${e}.${t}`:t}function ge(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function mr(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Pt(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Wt(e){if(e==="")return null;try{return JSON.parse(e)}catch(t){return e}}function We(e,t){const n=document.createElement("input");return n.type="hidden",n.name=e,n.setAttribute("data-hidden-field","true"),n.value=Pt(t),n}function gt(e,t){if(!e||typeof e!="object")return;const n=t.match(/[^.[\]]+|\[\d+\]/g);if(!n||n.length===0)return;let r=e;for(const o of n){if(r==null)return;if(o.startsWith("[")&&o.endsWith("]")){const a=parseInt(o.slice(1,-1),10);if(!Array.isArray(r)||isNaN(a))return;r=r[a]}else r=r[o]}return r}function He(e,t,n){var r;if(!e||!e.key)throw new Error("Invalid enableIf condition: must have a 'key' property");const o=(r=e.scope)!=null?r:"relative";let a;if(o==="relative")a=n!=null?n:t;else if(o==="absolute")a=t;else throw new Error(`Invalid enableIf scope: must be "relative" or "absolute" (got "${o}")`);const i=gt(a,e.key);if("equals"in e)return hr(i,e.equals);throw new Error("Invalid enableIf condition: no recognized operator (equals, etc.)")}function hr(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 Le(e,t){const n=e.querySelector(":scope > [data-fb-label-row]");n&&n.appendChild(t)}function Te(e,t,n={}){var r;const o=(r=n.label)!=null?r:"",a=n.showCounter!==!1,i=document.createElement("div");i.className="fb-add-row mt-2",i.style.cssText="display:flex;align-items:stretch;width:100%;";const l=document.createElement("button");l.type="button",l.className=`add-${e}-btn`,l.style.cssText=`
2
- flex: 1 1 auto;
3
- display: inline-flex;
4
- align-items: center;
5
- justify-content: center;
6
- gap: 6px;
7
- padding: 6px 10px;
8
- border: 1px dashed var(--fb-primary-color);
9
- border-radius: var(--fb-border-radius);
10
- background: transparent;
11
- color: var(--fb-primary-color);
12
- font-size: var(--fb-font-size-small, var(--fb-font-size));
13
- font-weight: 500;
14
- font-family: var(--fb-font-family);
15
- cursor: pointer;
16
- transition: border-color var(--fb-transition-duration), color var(--fb-transition-duration), background-color var(--fb-transition-duration);
17
- `,l.textContent=o?`+ ${o}`:"+",l.addEventListener("mouseenter",()=>{l.disabled||(l.style.borderStyle="solid",l.style.backgroundColor="var(--fb-background-hover-color)")}),l.addEventListener("mouseleave",()=>{l.style.borderStyle="dashed",l.style.backgroundColor="transparent"}),l.onclick=t;const s=document.createElement("span");return s.className="fb-add-counter",s.style.cssText=`
18
- margin-left: auto;
19
- font-size: var(--fb-font-size-small, 0.875rem);
20
- color: var(--fb-text-secondary-color);
21
- font-weight: 400;
22
- `,a||(s.style.display="none"),i.appendChild(l),{row:i,button:l,counter:s,update:(u,d)=>{const c=u>=d;i.style.display=c?"none":"flex",l.style.display=c?"none":"inline-flex",l.disabled=c,a&&(s.textContent=`${u}/${d===1/0?"\u221E":d}`)}}}function br(e,t={}){var n;const r=(n=t.label)!=null?n:"",o=document.createElement("button");o.type="button",o.className="add-container-btn fb-slide-add",o.style.cssText=`
23
- display: flex;
24
- flex-direction: column;
25
- align-items: center;
26
- justify-content: center;
27
- gap: 12px;
28
- width: 100%;
29
- min-height: 180px;
30
- align-self: stretch;
31
- padding: 24px 16px;
32
- border: 1.5px dashed var(--fb-primary-color);
33
- border-radius: var(--fb-border-radius);
34
- background: transparent;
35
- color: var(--fb-primary-color);
36
- font-size: var(--fb-font-size-small, var(--fb-font-size));
37
- font-weight: 500;
38
- font-family: var(--fb-font-family);
39
- cursor: pointer;
40
- transition: border-color var(--fb-transition-duration), color var(--fb-transition-duration), background-color var(--fb-transition-duration);
41
- `;const a=document.createElement("span");if(a.className="fb-slide-add-circle",a.style.cssText=`
42
- display: inline-flex;
43
- align-items: center;
44
- justify-content: center;
45
- width: 36px;
46
- height: 36px;
47
- border: 1px solid var(--fb-primary-color);
48
- border-radius: 50%;
49
- background: var(--fb-background-color);
50
- font-size: 20px;
51
- line-height: 1;
52
- color: inherit;
53
- transition: inherit;
54
- `,a.textContent="+",o.appendChild(a),r){const l=document.createElement("span");l.textContent=r,o.appendChild(l)}o.addEventListener("mouseenter",()=>{o.disabled||(o.style.borderStyle="solid",o.style.backgroundColor="var(--fb-background-hover-color)")}),o.addEventListener("mouseleave",()=>{o.style.borderStyle="dashed",o.style.backgroundColor="transparent"}),o.onclick=e;const i=document.createElement("span");return i.className="fb-add-counter",i.style.cssText=`
55
- margin-left: auto;
56
- font-size: var(--fb-font-size-small, 0.875rem);
57
- color: var(--fb-text-secondary-color);
58
- font-weight: 400;
59
- `,{tile:o,counter:i,update:(l,s)=>{const u=l>=s;o.style.display=u?"none":"flex",o.disabled=u,i.textContent=`${l}/${s===1/0?"\u221E":s}`}}}function Vt(e,t=!1){e.style.cssText=`
60
- background-color: var(--fb-action-bg-color);
61
- color: var(--fb-action-text-color);
62
- border: var(--fb-border-width) solid var(--fb-action-border-color);
63
- padding: ${t?"0.5rem 1rem":"0.5rem 0.75rem"};
64
- font-size: var(--fb-font-size);
65
- font-weight: var(--fb-font-weight-medium);
66
- border-radius: var(--fb-border-radius);
67
- transition: all var(--fb-transition-duration);
68
- box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
69
- `,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)"})}function Ve(e,t,n=!1){const r=document.createElement("span");r.className="char-counter",r.style.cssText=`
70
- position: absolute;
71
- ${n?"bottom: 8px":"top: 50%; transform: translateY(-50%)"};
72
- right: 10px;
73
- font-size: var(--fb-font-size-small);
74
- color: var(--fb-text-secondary-color);
75
- pointer-events: none;
76
- background: var(--fb-background-color);
77
- padding: 0 4px;
78
- `;const o=()=>{const a=t.value.length,i=e.minLength,l=e.maxLength;if(i==null&&l==null){r.textContent="";return}a===0||i!=null&&a<i?(i!=null&&l!=null?r.textContent=`${i}-${l}`:l!=null?r.textContent=`\u2264${l}`:i!=null&&(r.textContent=`\u2265${i}`),r.style.color="var(--fb-text-secondary-color)"):l!=null&&a>l?(r.textContent=`${a}/${l}`,r.style.color="var(--fb-error-color)"):(l!=null?r.textContent=`${a}/${l}`:r.textContent=`${a}`,r.style.color="var(--fb-text-secondary-color)")};return t.addEventListener("input",o),o(),r}function vr(e,t,n,r){const o=t.state,a=oe(e,o,t),i=document.createElement("div");i.style.cssText="position: relative;";const l=!a&&(e.minLength!=null||e.maxLength!=null),s=document.createElement("input");if(s.type="text",s.className="w-full rounded-lg",s.style.cssText=`
79
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
80
- ${l?"padding-right: 60px;":""}
81
- border: var(--fb-border-width) solid var(--fb-border-color);
82
- border-radius: var(--fb-border-radius);
83
- background-color: ${a?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
84
- color: var(--fb-text-color);
85
- font-size: var(--fb-font-size);
86
- font-family: var(--fb-font-family);
87
- transition: all var(--fb-transition-duration) ease-in-out;
88
- width: 100%;
89
- box-sizing: border-box;
90
- `,s.name=r,s.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",s.value=t.prefill[e.key]||e.default||"",s.readOnly=a,a||(s.addEventListener("focus",()=>{s.style.borderColor="var(--fb-border-focus-color)",s.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",s.style.outlineOffset="0"}),s.addEventListener("blur",()=>{s.style.borderColor="var(--fb-border-color)",s.style.outline="none"}),s.addEventListener("mouseenter",()=>{document.activeElement!==s&&(s.style.borderColor="var(--fb-border-hover-color)")}),s.addEventListener("mouseleave",()=>{document.activeElement!==s&&(s.style.borderColor="var(--fb-border-color)")})),!a&&t.instance){const u=()=>{const d=s.value===""?null:s.value;t.instance.triggerOnChange(r,d)};s.addEventListener("blur",u),s.addEventListener("input",u)}if(i.appendChild(s),l){const u=Ve(e,s,!1);i.appendChild(u)}n.appendChild(i)}function gr(e,t,n,r){var o,a;const i=t.state,l=oe(e,i,t),s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],d=!l&&(e.minLength!=null||e.maxLength!=null),c=(o=e.minCount)!=null?o:1,p=(a=e.maxCount)!=null?a:1/0;for(;u.length<c;)u.push(e.default||"");const f=document.createElement("div");f.className="space-y-2",n.appendChild(f);function m(){f.querySelectorAll(".multiple-text-item").forEach((x,v)=>{const w=x.querySelector("input");w&&(w.name=`${r}[${v}]`)})}function b(x="",v=-1){const w=document.createElement("div");w.className="multiple-text-item flex items-center gap-2";const C=document.createElement("div");C.style.cssText="position: relative; flex: 1;";const y=document.createElement("input");if(y.type="text",y.style.cssText=`
91
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
92
- ${d?"padding-right: 60px;":""}
93
- border: var(--fb-border-width) solid var(--fb-border-color);
94
- border-radius: var(--fb-border-radius);
95
- background-color: ${l?"var(--fb-background-readonly-color)":"var(--fb-background-color)"};
96
- color: var(--fb-text-color);
97
- font-size: var(--fb-font-size);
98
- font-family: var(--fb-font-family);
99
- transition: all var(--fb-transition-duration) ease-in-out;
100
- width: 100%;
101
- box-sizing: border-box;
102
- `,y.placeholder=e.placeholder||k("placeholderText",i),y.value=x,y.readOnly=l,l||(y.addEventListener("focus",()=>{y.style.borderColor="var(--fb-border-focus-color)",y.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",y.style.outlineOffset="0"}),y.addEventListener("blur",()=>{y.style.borderColor="var(--fb-border-color)",y.style.outline="none"}),y.addEventListener("mouseenter",()=>{document.activeElement!==y&&(y.style.borderColor="var(--fb-border-hover-color)")}),y.addEventListener("mouseleave",()=>{document.activeElement!==y&&(y.style.borderColor="var(--fb-border-color)")})),!l&&t.instance){const L=()=>{const R=y.value===""?null:y.value;t.instance.triggerOnChange(y.name,R)};y.addEventListener("blur",L),y.addEventListener("input",L)}if(C.appendChild(y),d){const L=Ve(e,y,!1);C.appendChild(L)}return w.appendChild(C),v===-1?f.appendChild(w):f.insertBefore(w,f.children[v]),m(),w}function g(){if(l)return;const x=f.querySelectorAll(".multiple-text-item"),v=x.length;x.forEach(w=>{let C=w.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 rounded",C.style.cssText=`
103
- color: var(--fb-error-color);
104
- background-color: transparent;
105
- transition: background-color var(--fb-transition-duration);
106
- `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const L=Array.from(f.children).indexOf(w);f.children.length>c&&(u.splice(L,1),w.remove(),m(),h(),g())},w.appendChild(C));const y=v<=c;C.disabled=y,C.style.opacity=y?"0.5":"1",C.style.pointerEvents=y?"none":"auto"})}let E=null;if(!l){const x=Te("text",()=>{u.push(e.default||""),b(e.default||""),h(),g()},{label:e.addLabel});E=x.update,Le(n,x.counter),n.appendChild(x.row)}function h(){E&&E(u.length,p)}u.forEach(x=>b(x)),h(),g()}function _t(e,t,n){var r,o,a;const i=[],{scopeRoot:l,skipValidation:s}=n,u=(c,p)=>{var f,m;if(!c)return;const b=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(b);p?(c.classList.add("invalid"),c.title=p,g||(g=document.createElement("div"),g.id=b,g.className="error-message",g.style.cssText=`
107
- color: var(--fb-error-color);
108
- font-size: var(--fb-font-size-small);
109
- margin-top: 0.25rem;
110
- `,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(g,c.nextSibling):(m=c.parentNode)==null||m.appendChild(g)),g.textContent=p,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},d=(c,p,f)=>{let m=!1;const{state:b}=n;if(!s&&p){if(e.minLength!==void 0&&e.minLength!==null&&p.length<e.minLength){const g=k("minLength",b,{min:e.minLength});i.push(`${f}: ${g}`),u(c,g),m=!0}else if(e.maxLength!==void 0&&e.maxLength!==null&&p.length>e.maxLength){const g=k("maxLength",b,{max:e.maxLength});i.push(`${f}: ${g}`),u(c,g),m=!0}else if(e.pattern)try{if(!new RegExp(e.pattern).test(p)){const g=k("patternMismatch",b);i.push(`${f}: ${g}`),u(c,g),m=!0}}catch(g){const E=k("invalidPattern",b);i.push(`${f}: ${E}`),u(c,E),m=!0}}m||u(c,null)};if(e.multiple){const c=l.querySelectorAll(`[name^="${t}["]`),p=[],f=[];if(c.forEach((m,b)=>{var g;const E=(g=m==null?void 0:m.value)!=null?g:"";f.push(E),p.push(E===""?null:E),d(m,E,`${t}[${b}]`)}),!s){const{state:m}=n,b=(r=e.minCount)!=null?r:1,g=(o=e.maxCount)!=null?o:1/0,E=f.filter(h=>h.trim()!=="");e.required&&E.length===0&&i.push(`${t}: ${k("required",m)}`),E.length<b&&i.push(`${t}: ${k("minItems",m,{min:b})}`),E.length>g&&i.push(`${t}: ${k("maxItems",m,{max:g})}`)}return{value:p,errors:i}}else{const c=l.querySelector(`[name$="${t}"]`),p=(a=c==null?void 0:c.value)!=null?a:"";if(!s&&e.required&&p===""){const f=k("required",n.state);return i.push(`${t}: ${f}`),u(c,f),{value:null,errors:i}}return c&&d(c,p,t),{value:p===""?null:p,errors:i}}}function Kt(e,t,n,r){const{scopeRoot:o}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateTextField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=o.querySelectorAll(`[name^="${t}["]`);a.forEach((i,l)=>{l<n.length&&(i.value=n[l]!=null?String(n[l]):"",i.classList.remove("invalid"),i.title="")}),n.length!==a.length&&console.warn(`updateTextField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=o.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.classList.remove("invalid"),a.title="")}}function Jt(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 yr(e,t,n,r){const o=t.state,a=oe(e,o,t),i=document.createElement("div");i.style.cssText="position: relative;";const l=document.createElement("textarea");if(l.className="w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",l.style.cssText=`
111
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x) 24px var(--fb-input-padding-x);
112
- font-size: var(--fb-font-size);
113
- font-family: var(--fb-font-family);
114
- `,l.name=r,l.placeholder=e.placeholder||"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043A\u0441\u0442",l.rows=e.rows||4,l.value=t.prefill[e.key]||e.default||"",l.readOnly=a,!a&&t.instance){const s=()=>{const u=l.value===""?null:l.value;t.instance.triggerOnChange(r,u)};l.addEventListener("blur",s),l.addEventListener("input",s)}if((e.autoExpand||a)&&Jt(l),i.appendChild(l),!a&&(e.minLength!=null||e.maxLength!=null)){const s=Ve(e,l,!0);i.appendChild(s)}n.appendChild(i)}function xr(e,t,n,r){var o,a;const i=t.state,l=oe(e,i,t),s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],d=(o=e.minCount)!=null?o:1,c=(a=e.maxCount)!=null?a:1/0;for(;u.length<d;)u.push(e.default||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function f(){p.querySelectorAll(".multiple-textarea-item").forEach((h,x)=>{const v=h.querySelector("textarea");v&&(v.name=`${r}[${x}]`)})}function m(h="",x=-1){const v=document.createElement("div");v.className="multiple-textarea-item";const w=document.createElement("div");w.style.cssText="position: relative;";const C=document.createElement("textarea");if(C.className="w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none",C.style.cssText=`
115
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x) 24px var(--fb-input-padding-x);
116
- font-size: var(--fb-font-size);
117
- font-family: var(--fb-font-family);
118
- `,C.placeholder=e.placeholder||k("placeholderText",i),C.rows=e.rows||4,C.value=h,C.readOnly=l,!l&&t.instance){const y=()=>{const L=C.value===""?null:C.value;t.instance.triggerOnChange(C.name,L)};C.addEventListener("blur",y),C.addEventListener("input",y)}if((e.autoExpand||l)&&Jt(C),w.appendChild(C),!l&&(e.minLength!=null||e.maxLength!=null)){const y=Ve(e,C,!0);w.appendChild(y)}return v.appendChild(w),x===-1?p.appendChild(v):p.insertBefore(v,p.children[x]),f(),v}function b(){if(l)return;const h=p.querySelectorAll(".multiple-textarea-item"),x=h.length;h.forEach(v=>{let w=v.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm",w.innerHTML="\u2715",w.onclick=()=>{const y=Array.from(p.children).indexOf(v);p.children.length>d&&(u.splice(y,1),v.remove(),f(),E(),b())},v.appendChild(w));const C=x<=d;w.disabled=C,w.style.opacity=C?"0.5":"1",w.style.pointerEvents=C?"none":"auto"})}let g=null;if(!l){const h=Te("textarea",()=>{u.push(e.default||""),m(e.default||""),E(),b()},{label:e.addLabel});g=h.update,Le(n,h.counter),n.appendChild(h.row)}function E(){g&&g(u.length,c)}u.forEach(h=>m(h)),E(),b()}function wr(e,t,n){return _t(e,t,n)}function Er(e,t,n,r){Kt(e,t,n,r);const{scopeRoot:o,state:a}=r;if(e.autoExpand||oe(e,a))if(e.multiple)o.querySelectorAll(`textarea[name^="${t}["]`).forEach(i=>{i.dispatchEvent(new Event("input"))});else{const i=o.querySelector(`textarea[name="${t}"]`);i&&i.dispatchEvent(new Event("input"))}}function Yt(e,t){const n=document.createElement("span");n.className="number-range-hint",n.style.cssText=`
119
- position: absolute;
120
- top: 50%;
121
- transform: translateY(-50%);
122
- right: 10px;
123
- font-size: var(--fb-font-size-small);
124
- color: var(--fb-text-secondary-color);
125
- pointer-events: none;
126
- background: var(--fb-background-color);
127
- padding: 0 4px;
128
- `;const r=e.min,o=e.max;let a="";r!=null&&o!=null?a=`${r} \u2013 ${o}`:o!=null?a=`\u2264${o}`:r!=null&&(a=`\u2265${r}`),n.textContent=a;const i=()=>{const l=t.value?parseFloat(t.value):null;if(l!=null){const s=r!=null&&l<r,u=o!=null&&l>o;n.style.color=s||u?"var(--fb-error-color)":"var(--fb-text-secondary-color)"}else n.style.color="var(--fb-text-secondary-color)"};return t.addEventListener("input",i),i(),n}function Cr(e,t,n,r){const o=t.state,a=oe(e,o,t),i=document.createElement("div");i.style.cssText="position: relative;";const l=document.createElement("input");if(l.type="number",l.className="w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",l.style.cssText=`
129
- padding: var(--fb-input-padding-y) 60px var(--fb-input-padding-y) var(--fb-input-padding-x);
130
- font-size: var(--fb-font-size);
131
- font-family: var(--fb-font-family);
132
- width: 100%;
133
- box-sizing: border-box;
134
- `,l.name=r,l.placeholder=e.placeholder||"0",e.min!==void 0&&(l.min=e.min.toString()),e.max!==void 0&&(l.max=e.max.toString()),e.step!==void 0&&(l.step=e.step.toString()),l.value=t.prefill[e.key]||e.default||"",l.readOnly=a,!a&&t.instance){const s=()=>{const u=l.value?parseFloat(l.value):null;t.instance.triggerOnChange(r,u)};l.addEventListener("blur",s),l.addEventListener("input",s)}if(i.appendChild(l),!a&&(e.min!=null||e.max!=null)){const s=Yt(e,l);i.appendChild(s)}n.appendChild(i)}function kr(e,t,n,r){var o,a;const i=t.state,l=oe(e,i,t),s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],d=(o=e.minCount)!=null?o:1,c=(a=e.maxCount)!=null?a:1/0;for(;u.length<d;)u.push(e.default||"");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function f(){p.querySelectorAll(".multiple-number-item").forEach((h,x)=>{const v=h.querySelector("input");v&&(v.name=`${r}[${x}]`)})}function m(h="",x=-1){const v=document.createElement("div");v.className="multiple-number-item flex items-center gap-2";const w=document.createElement("div");w.style.cssText="position: relative; flex: 1;";const C=document.createElement("input");if(C.type="number",C.className="w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",C.style.cssText=`
135
- padding: var(--fb-input-padding-y) 60px var(--fb-input-padding-y) var(--fb-input-padding-x);
136
- font-size: var(--fb-font-size);
137
- font-family: var(--fb-font-family);
138
- width: 100%;
139
- box-sizing: border-box;
140
- `,C.placeholder=e.placeholder||"0",e.min!==void 0&&(C.min=e.min.toString()),e.max!==void 0&&(C.max=e.max.toString()),e.step!==void 0&&(C.step=e.step.toString()),C.value=h.toString(),C.readOnly=l,!l&&t.instance){const y=()=>{const L=C.value?parseFloat(C.value):null;t.instance.triggerOnChange(C.name,L)};C.addEventListener("blur",y),C.addEventListener("input",y)}if(w.appendChild(C),!l&&(e.min!=null||e.max!=null)){const y=Yt(e,C);w.appendChild(y)}return v.appendChild(w),x===-1?p.appendChild(v):p.insertBefore(v,p.children[x]),f(),v}function b(){if(l)return;const h=p.querySelectorAll(".multiple-number-item"),x=h.length;h.forEach(v=>{let w=v.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn px-2 py-1 text-red-600 hover:bg-red-50 rounded",w.innerHTML="\u2715",w.onclick=()=>{const y=Array.from(p.children).indexOf(v);p.children.length>d&&(u.splice(y,1),v.remove(),f(),E(),b())},v.appendChild(w));const C=x<=d;w.disabled=C,w.style.opacity=C?"0.5":"1",w.style.pointerEvents=C?"none":"auto"})}let g=null;if(!l){const h=Te("number",()=>{u.push(e.default||""),m(e.default||""),E(),b()},{label:e.addLabel});g=h.update,Le(n,h.counter),n.appendChild(h.row)}function E(){g&&g(u.length,c)}u.forEach(h=>m(h)),E(),b()}function $r(e,t,n){var r,o,a,i,l;const s=[],{scopeRoot:u,skipValidation:d}=n,c=(f,m)=>{var b,g;if(!f)return;const E=`error-${f.getAttribute("name")||Math.random().toString(36).substring(7)}`;let h=document.getElementById(E);m?(f.classList.add("invalid"),f.title=m,h||(h=document.createElement("div"),h.id=E,h.className="error-message",h.style.cssText=`
141
- color: var(--fb-error-color);
142
- font-size: var(--fb-font-size-small);
143
- margin-top: 0.25rem;
144
- `,f.nextSibling?(b=f.parentNode)==null||b.insertBefore(h,f.nextSibling):(g=f.parentNode)==null||g.appendChild(h)),h.textContent=m,h.style.display="block"):(f.classList.remove("invalid"),f.title="",h&&h.remove())},p=(f,m,b)=>{let g=!1;const{state:E}=n;if(!d&&e.min!==void 0&&e.min!==null&&m<e.min){const h=k("minValue",E,{min:e.min});s.push(`${b}: ${h}`),c(f,h),g=!0}else if(!d&&e.max!==void 0&&e.max!==null&&m>e.max){const h=k("maxValue",E,{max:e.max});s.push(`${b}: ${h}`),c(f,h),g=!0}g||c(f,null)};if(e.multiple){const f=u.querySelectorAll(`[name^="${t}["]`),m=[];if(f.forEach((b,g)=>{var E,h,x;const v=(E=b==null?void 0:b.value)!=null?E:"";if(v===""){m.push(null),c(b,null);return}const w=parseFloat(v);if(!d&&!Number.isFinite(w)){const y=k("notANumber",n.state);s.push(`${t}[${g}]: ${y}`),c(b,y),m.push(null);return}p(b,w,`${t}[${g}]`);const C=Number.isInteger((h=e.decimals)!=null?h:0)&&(x=e.decimals)!=null?x:0;m.push(Number(w.toFixed(C)))}),!d){const{state:b}=n,g=(r=e.minCount)!=null?r:1,E=(o=e.maxCount)!=null?o:1/0,h=m.filter(x=>x!==null);e.required&&h.length===0&&s.push(`${t}: ${k("required",b)}`),h.length<g&&s.push(`${t}: ${k("minItems",b,{min:g})}`),h.length>E&&s.push(`${t}: ${k("maxItems",b,{max:E})}`)}return{value:m,errors:s}}else{const f=u.querySelector(`[name$="${t}"]`),m=(a=f==null?void 0:f.value)!=null?a:"",{state:b}=n;if(!d&&e.required&&m===""){const h=k("required",b);return s.push(`${t}: ${h}`),c(f,h),{value:null,errors:s}}if(m==="")return c(f,null),{value:null,errors:s};const g=parseFloat(m);if(!d&&!Number.isFinite(g)){const h=k("notANumber",b);return s.push(`${t}: ${h}`),c(f,h),{value:null,errors:s}}p(f,g,t);const E=Number.isInteger((i=e.decimals)!=null?i:0)&&(l=e.decimals)!=null?l:0;return{value:Number(g.toFixed(E)),errors:s}}}function Lr(e,t,n,r){const{scopeRoot:o}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateNumberField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=o.querySelectorAll(`[name^="${t}["]`);a.forEach((i,l)=>{l<n.length&&(i.value=n[l]!=null?String(n[l]):"",i.classList.remove("invalid"),i.title="")}),n.length!==a.length&&console.warn(`updateNumberField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=o.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.classList.remove("invalid"),a.title="")}}function Sr(e,t,n,r){const o=t.state,a=oe(e,o,t),i=document.createElement("select");if(i.className="w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",i.style.cssText=`
145
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
146
- font-size: var(--fb-font-size);
147
- font-family: var(--fb-font-family);
148
- `,i.name=r,i.disabled=a,(e.options||[]).forEach(l=>{const s=document.createElement("option");s.value=l.value,s.textContent=l.label,(t.prefill[e.key]||e.default)===l.value&&(s.selected=!0),i.appendChild(s)}),!a&&t.instance){const l=()=>{t.instance.triggerOnChange(r,i.value)};i.addEventListener("change",l)}if(n.appendChild(i),!a){const l=document.createElement("p");l.className="text-xs text-gray-500 mt-1",l.textContent=$e(e,o),n.appendChild(l)}}function Tr(e,t,n,r){var o,a,i,l;const s=t.state,u=oe(e,s,t),d=t.prefill[e.key]||[],c=Array.isArray(d)?[...d]:[],p=(o=e.minCount)!=null?o:1,f=(a=e.maxCount)!=null?a:1/0;for(;c.length<p;)c.push(e.default||((l=(i=e.options)==null?void 0:i[0])==null?void 0:l.value)||"");const m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function b(){m.querySelectorAll(".multiple-select-item").forEach((v,w)=>{const C=v.querySelector("select");C&&(C.name=`${r}[${w}]`)})}function g(v="",w=-1){const C=document.createElement("div");C.className="multiple-select-item flex items-center gap-2";const y=document.createElement("select");if(y.className="flex-1 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",y.style.cssText=`
149
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
150
- font-size: var(--fb-font-size);
151
- font-family: var(--fb-font-family);
152
- `,y.disabled=u,(e.options||[]).forEach(L=>{const R=document.createElement("option");R.value=L.value,R.textContent=L.label,v===L.value&&(R.selected=!0),y.appendChild(R)}),!u&&t.instance){const L=()=>{t.instance.triggerOnChange(y.name,y.value)};y.addEventListener("change",L)}return C.appendChild(y),w===-1?m.appendChild(C):m.insertBefore(C,m.children[w]),b(),C}function E(){if(u)return;const v=m.querySelectorAll(".multiple-select-item"),w=v.length;v.forEach(C=>{let y=C.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 R=Array.from(m.children).indexOf(C);m.children.length>p&&(c.splice(R,1),C.remove(),b(),x(),E())},C.appendChild(y));const L=w<=p;y.disabled=L,y.style.opacity=L?"0.5":"1",y.style.pointerEvents=L?"none":"auto"})}let h=null;if(!u){const v=Te("select",()=>{var w,C;const y=e.default||((C=(w=e.options)==null?void 0:w[0])==null?void 0:C.value)||"";c.push(y),g(y),x(),E()},{label:e.addLabel});h=v.update,Le(n,v.counter),n.appendChild(v.row)}function x(){h&&h(c.length,f)}if(c.forEach(v=>g(v)),x(),E(),!u){const v=document.createElement("p");v.className="text-xs text-gray-500 mt-1",v.textContent=$e(e,s),n.appendChild(v)}}function Ar(e,t,n){var r;const o=[],{scopeRoot:a,skipValidation:i}=n,l=(u,d)=>{var c,p;if(!u)return;const f=`error-${u.getAttribute("name")||Math.random().toString(36).substring(7)}`;let m=document.getElementById(f);d?(u.classList.add("invalid"),u.title=d,m||(m=document.createElement("div"),m.id=f,m.className="error-message",m.style.cssText=`
153
- color: var(--fb-error-color);
154
- font-size: var(--fb-font-size-small);
155
- margin-top: 0.25rem;
156
- `,u.nextSibling?(c=u.parentNode)==null||c.insertBefore(m,u.nextSibling):(p=u.parentNode)==null||p.appendChild(m)),m.textContent=d,m.style.display="block"):(u.classList.remove("invalid"),u.title="",m&&m.remove())},s=(u,d,c,p)=>{var f,m;if(i)return;const{state:b}=n,g=d.filter(p),E="minCount"in c&&(f=c.minCount)!=null?f:1,h="maxCount"in c&&(m=c.maxCount)!=null?m:1/0;c.required&&g.length===0&&o.push(`${u}: ${k("required",b)}`),g.length<E&&o.push(`${u}: ${k("minItems",b,{min:E})}`),g.length>h&&o.push(`${u}: ${k("maxItems",b,{max:h})}`)};if("multiple"in e&&e.multiple){const u=a.querySelectorAll(`[name^="${t}["]`),d=[];return u.forEach(c=>{var p;const f=(p=c==null?void 0:c.value)!=null?p:"";d.push(f),l(c,null)}),s(t,d,e,c=>c!==""),{value:d,errors:o}}else{const u=a.querySelector(`[name$="${t}"]`),d=(r=u==null?void 0:u.value)!=null?r:"";if(!i&&e.required&&d===""){const c=k("required",n.state);return o.push(`${t}: ${c}`),l(u,c),{value:null,errors:o}}else l(u,null);return{value:d===""?null:d,errors:o}}}function Fr(e,t,n,r){const{scopeRoot:o}=r;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSelectField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=o.querySelectorAll(`[name^="${t}["]`);a.forEach((i,l)=>{l<n.length&&(i.value=n[l]!=null?String(n[l]):"",i.querySelectorAll("option").forEach(s=>{s.selected=s.value===String(n[l])}),i.classList.remove("invalid"),i.title="")}),n.length!==a.length&&console.warn(`updateSelectField: Multiple field "${t}" has ${a.length} selects but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=o.querySelector(`[name="${t}"]`);a&&(a.value=n!=null?String(n):"",a.querySelectorAll("option").forEach(i=>{i.selected=i.value===String(n)}),a.classList.remove("invalid"),a.title="")}}function Qe(e){e.style.backgroundColor="var(--fb-primary-color)",e.style.color="#ffffff",e.style.borderColor="var(--fb-primary-color)"}function et(e){e.style.backgroundColor="transparent",e.style.color="var(--fb-text-color)",e.style.borderColor="var(--fb-border-color)"}function Gt(e,t,n,r,o){const a=e.options||[],i=document.createElement("div");i.className="fb-switcher-group",i.style.cssText=`
157
- display: inline-flex;
158
- flex-direction: row;
159
- flex-wrap: nowrap;
160
- `;const l=[];return a.forEach((s,u)=>{const d=document.createElement("button");d.type="button",d.className="fb-switcher-btn",d.dataset.value=s.value,d.textContent=s.label,d.style.cssText=`
161
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
162
- font-size: var(--fb-font-size);
163
- border-width: var(--fb-border-width);
164
- border-style: solid;
165
- cursor: ${r?"default":"pointer"};
166
- transition: background-color var(--fb-transition-duration), color var(--fb-transition-duration), border-color var(--fb-transition-duration);
167
- white-space: nowrap;
168
- line-height: 1.25;
169
- outline: none;
170
- `,a.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===a.length-1?d.style.borderRadius="0 var(--fb-border-radius) var(--fb-border-radius) 0":(d.style.borderRadius="0",d.style.borderRightWidth="0"),s.value===t?Qe(d):et(d),r||(d.addEventListener("click",()=>{n.value=s.value,l.forEach(c=>{c.dataset.value===s.value?Qe(c):et(c)}),o&&o(s.value)}),d.addEventListener("mouseenter",()=>{n.value!==s.value&&(d.style.backgroundColor="var(--fb-background-hover-color)")}),d.addEventListener("mouseleave",()=>{n.value!==s.value&&(d.style.backgroundColor="transparent")})),l.push(d),i.appendChild(d)}),i}function Mr(e,t,n,r){var o,a;const i=t.state,l=String((a=(o=t.prefill[e.key])!=null?o:e.default)!=null?a:""),s=document.createElement("input");s.type="hidden",s.name=r,s.value=l;const u=oe(e,i,t),d=!u&&t.instance?p=>{t.instance.triggerOnChange(r,p)}:null,c=Gt(e,l,s,u,d);if(n.appendChild(s),n.appendChild(c),!u){const p=document.createElement("p");p.className="text-xs text-gray-500 mt-1",p.textContent=$e(e,i),n.appendChild(p)}}function zr(e,t,n,r){var o,a,i,l;const s=t.state,u=t.prefill[e.key]||[],d=Array.isArray(u)?[...u]:[],c=(o=e.minCount)!=null?o:1,p=(a=e.maxCount)!=null?a:1/0;for(;d.length<c;)d.push(e.default||((l=(i=e.options)==null?void 0:i[0])==null?void 0:l.value)||"");const f=oe(e,s,t),m=document.createElement("div");m.className="space-y-2",n.appendChild(m);function b(){m.querySelectorAll(".multiple-switcher-item").forEach((v,w)=>{const C=v.querySelector("input[type=hidden]");C&&(C.name=`${r}[${w}]`)})}function g(v="",w=-1){const C=w===-1?m.children.length:w,y=`${r}[${C}]`,L=document.createElement("div");L.className="multiple-switcher-item flex items-center gap-2";const R=document.createElement("input");R.type="hidden",R.name=y,R.value=v,L.appendChild(R);const q=!f&&t.instance?K=>{t.instance.triggerOnChange(R.name,K)}:null,W=Gt(e,v,R,f,q);return L.appendChild(W),w===-1?m.appendChild(L):m.insertBefore(L,m.children[w]),b(),L}function E(){if(f)return;const v=m.querySelectorAll(".multiple-switcher-item"),w=v.length;v.forEach(C=>{let y=C.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=`
171
- color: var(--fb-error-color);
172
- background-color: transparent;
173
- transition: background-color var(--fb-transition-duration);
174
- `,y.innerHTML="\u2715",y.addEventListener("mouseenter",()=>{y.style.backgroundColor="var(--fb-background-hover-color)"}),y.addEventListener("mouseleave",()=>{y.style.backgroundColor="transparent"}),y.onclick=()=>{const R=Array.from(m.children).indexOf(C);m.children.length>c&&(d.splice(R,1),C.remove(),b(),x(),E())},C.appendChild(y));const L=w<=c;y.disabled=L,y.style.opacity=L?"0.5":"1",y.style.pointerEvents=L?"none":"auto"})}let h=null;if(!f){const v=Te("switcher",()=>{var w,C;const y=e.default||((C=(w=e.options)==null?void 0:w[0])==null?void 0:C.value)||"";d.push(y),g(y),x(),E()},{label:e.addLabel});h=v.update,Le(n,v.counter),n.appendChild(v.row)}function x(){h&&h(d.length,p)}if(d.forEach(v=>g(v)),x(),E(),!f){const v=document.createElement("p");v.className="text-xs text-gray-500 mt-1",v.textContent=$e(e,s),n.appendChild(v)}}function Nr(e,t,n){var r;const o=[],{scopeRoot:a,skipValidation:i}=n,l=(d,c)=>{var p,f;if(!d)return;const m=`error-${d.getAttribute("name")||Math.random().toString(36).substring(7)}`;let b=document.getElementById(m);c?(d.classList.add("invalid"),d.title=c,b||(b=document.createElement("div"),b.id=m,b.className="error-message",b.style.cssText=`
175
- color: var(--fb-error-color);
176
- font-size: var(--fb-font-size-small);
177
- margin-top: 0.25rem;
178
- `,d.nextSibling?(p=d.parentNode)==null||p.insertBefore(b,d.nextSibling):(f=d.parentNode)==null||f.appendChild(b)),b.textContent=c,b.style.display="block"):(d.classList.remove("invalid"),d.title="",b&&b.remove())},s=(d,c,p,f)=>{var m,b;if(i)return;const{state:g}=n,E=c.filter(f),h="minCount"in p&&(m=p.minCount)!=null?m:1,x="maxCount"in p&&(b=p.maxCount)!=null?b:1/0;p.required&&E.length===0&&o.push(`${d}: ${k("required",g)}`),E.length<h&&o.push(`${d}: ${k("minItems",g,{min:h})}`),E.length>x&&o.push(`${d}: ${k("maxItems",g,{max:x})}`)},u=new Set("options"in e?e.options.map(d=>d.value):[]);if("multiple"in e&&e.multiple){const d=a.querySelectorAll(`input[type="hidden"][name^="${t}["]`),c=[];return d.forEach(p=>{var f;const m=(f=p==null?void 0:p.value)!=null?f:"";if(c.push(m),!i&&m!==""&&!u.has(m)){const b=k("invalidOption",n.state);l(p,b),o.push(`${t}: ${b}`)}else l(p,null)}),s(t,c,e,p=>p!==""),{value:c,errors:o}}else{const d=a.querySelector(`input[type="hidden"][name$="${t}"]`),c=(r=d==null?void 0:d.value)!=null?r:"";if(!i&&e.required&&c===""){const p=k("required",n.state);return o.push(`${t}: ${p}`),l(d,p),{value:null,errors:o}}if(!i&&c!==""&&!u.has(c)){const p=k("invalidOption",n.state);return o.push(`${t}: ${p}`),l(d,p),{value:null,errors:o}}return l(d,null),{value:c===""?null:c,errors:o}}}function qr(e,t,n,r){var o;const{scopeRoot:a}=r;if("multiple"in e&&e.multiple){if(!Array.isArray(n)){console.warn(`updateSwitcherField: Expected array for multiple field "${t}", got ${typeof n}`);return}const i=a.querySelectorAll(`input[type="hidden"][name^="${t}["]`);i.forEach((l,s)=>{var u;if(s<n.length){const d=n[s]!=null?String(n[s]):"";l.value=d;const c=(u=l.parentElement)==null?void 0:u.querySelector(".fb-switcher-group");c&&c.querySelectorAll(".fb-switcher-btn").forEach(p=>{p.dataset.value===d?Qe(p):et(p)}),l.classList.remove("invalid"),l.title=""}}),n.length!==i.length&&console.warn(`updateSwitcherField: Multiple field "${t}" has ${i.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const i=a.querySelector(`input[type="hidden"][name="${t}"]`);if(i){const l=n!=null?String(n):"";i.value=l;const s=(o=i.parentElement)==null?void 0:o.querySelector(".fb-switcher-group");s&&s.querySelectorAll(".fb-switcher-btn").forEach(u=>{u.dataset.value===l?Qe(u):et(u)}),i.classList.remove("invalid"),i.title=""}}}function Ae(e){return e?typeof e=="object"&&Array.isArray(e.extensions)?e.extensions.map(t=>t.toLowerCase()):typeof e=="string"?e.split(",").map(t=>t.trim()).filter(t=>t.startsWith(".")).map(t=>t.substring(1).toLowerCase()):[]:[]}function Be(e,t){var n,r;if(t.length===0)return!0;const o=(r=(n=e.split(".").pop())==null?void 0:n.toLowerCase())!=null?r:"";return t.includes(o)}function Xt(e,t){return t===1/0?!0:e<=t*1024*1024}function tt(e,t){return Xt(e.size,t)}function _e(e){return e?typeof e=="string"?[]:Array.isArray(e.mime)?e.mime.map(t=>t.toLowerCase()):[]:[]}function Ke(e,t){if(t.length===0)return!0;const n=e.toLowerCase();return t.some(r=>{if(r.endsWith("/*")){const o=r.slice(0,-1);return n.startsWith(o)}return n===r})}function Ir(e){var t;const n=(t=(e.split("/").pop()||"file").split(".").pop())==null?void 0:t.toLowerCase();if(n){if(["jpg","jpeg","png","gif","webp"].includes(n))return`image/${n==="jpg"?"jpeg":n}`;if(["mp4","webm","mov","avi"].includes(n))return`video/${n==="mov"?"quicktime":n}`}return"application/octet-stream"}function nt(e,t){if(t.has(e))return;const n=e.split("/").pop()||"file";t.set(e,{name:n,type:Ir(e),size:0,uploadedAt:new Date,file:void 0,inferredFromExtension:!0})}function yt(e,t){for(const n of e)nt(n,t)}const Zt="fb-file-styles";function ke(){if(typeof document=="undefined"||document.getElementById(Zt))return;const e=document.createElement("style");e.id=Zt,e.setAttribute("data-fb-file-styles","true"),e.textContent=`
179
- @keyframes fb-spin { to { transform: rotate(360deg); } }
180
-
181
- /* \u2500\u2500\u2500 Checker background utility \u2500\u2500\u2500 */
182
- /* Neutral diagonal-stripe background for image previews (never crops) */
183
- .fb-checker {
184
- background-image: repeating-linear-gradient(45deg, #fafafa 0 6px, #f3f4f6 6px 12px);
185
- }
186
-
187
- /* \u2500\u2500\u2500 Spinner \u2500\u2500\u2500 */
188
- .fb-spinner {
189
- width: 36px;
190
- height: 36px;
191
- border: 3px solid rgba(0,0,0,0.12);
192
- border-top-color: var(--fb-text-secondary-color, #6b7280);
193
- border-radius: 50%;
194
- animation: fb-spin 0.7s linear infinite;
195
- flex-shrink: 0;
196
- }
197
-
198
- /* \u2500\u2500\u2500 Wide single-file add tile (empty state) \u2500\u2500\u2500 */
199
- .fb-wide-tile {
200
- width: 100%;
201
- border-radius: 0.75rem;
202
- border: 1px dashed #60a5fa;
203
- background: rgba(239,246,255,0.5);
204
- display: flex;
205
- overflow: hidden;
206
- height: 180px;
207
- transition: border-color 150ms, background 150ms, box-shadow 150ms;
208
- cursor: pointer;
209
- }
210
- .fb-wide-tile:hover {
211
- background: #eff6ff;
212
- }
213
- .fb-wide-tile.fb-drag-over {
214
- border-color: #3b82f6;
215
- border-width: 2px;
216
- background: #eff6ff;
217
- box-shadow: 0 0 0 4px rgba(191,219,254,0.7);
218
- }
219
-
220
- /* Upload zone inside wide tile */
221
- .fb-wide-tile-upload {
222
- flex: 1;
223
- display: flex;
224
- flex-direction: column;
225
- align-items: center;
226
- justify-content: center;
227
- gap: 8px;
228
- color: #2563eb;
229
- padding: 16px;
230
- transition: background 150ms;
231
- cursor: pointer;
232
- background: transparent;
233
- border: none;
234
- font-family: inherit;
235
- }
236
- .fb-wide-tile-upload:hover {
237
- background: rgba(191,219,254,0.25);
238
- }
239
-
240
- /* Vertical dashed divider between upload and library zones */
241
- .fb-wide-tile-divider {
242
- width: 1px;
243
- margin: 16px 0;
244
- border-left: 1px dashed rgba(96,165,250,0.5);
245
- background: transparent;
246
- flex-shrink: 0;
247
- }
248
-
249
- /* Library zone inside wide tile */
250
- .fb-wide-tile-library {
251
- width: 176px;
252
- flex-shrink: 0;
253
- display: flex;
254
- flex-direction: column;
255
- align-items: center;
256
- justify-content: center;
257
- gap: 8px;
258
- color: #2563eb;
259
- padding: 12px;
260
- transition: background 150ms;
261
- cursor: pointer;
262
- background: transparent;
263
- border: none;
264
- font-family: inherit;
265
- }
266
- .fb-wide-tile-library:hover {
267
- background: rgba(191,219,254,0.25);
268
- }
269
-
270
- /* \u2500\u2500\u2500 Multi-file outer grid container \u2500\u2500\u2500 */
271
- .fb-multi-outer {
272
- border-radius: 0.75rem;
273
- border: 1px dashed #cbd5e1;
274
- background: rgba(248,250,252,0.4);
275
- padding: 12px;
276
- transition: border-color 150ms, background 150ms, box-shadow 150ms;
277
- }
278
- .fb-multi-outer.fb-drag-over {
279
- border-width: 2px;
280
- border-color: #3b82f6;
281
- background: rgba(239,246,255,0.4);
282
- box-shadow: 0 0 0 4px rgba(191,219,254,0.7);
283
- }
284
-
285
- /* With files present: white solid border */
286
- .fb-multi-outer.fb-multi-has-files {
287
- border-style: solid;
288
- border-color: #e2e8f0;
289
- background: #fff;
290
- }
291
-
292
- /* The CSS grid inside */
293
- .fb-multi-grid {
294
- display: grid;
295
- grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
296
- gap: 10px;
297
- }
298
-
299
- /* \u2500\u2500\u2500 Multi square add-tile (combined upload + library) \u2500\u2500\u2500 */
300
- .fb-multi-add-tile {
301
- aspect-ratio: 1 / 1;
302
- border-radius: 0.5rem;
303
- border: 1px dashed #60a5fa;
304
- background: rgba(239,246,255,0.5);
305
- display: flex;
306
- flex-direction: column;
307
- overflow: hidden;
308
- transition: background 150ms;
309
- }
310
- .fb-multi-add-tile:hover {
311
- background: #eff6ff;
312
- }
313
- .fb-multi-add-tile.fb-drag-over-tile {
314
- border-width: 2px;
315
- border-color: #3b82f6;
316
- background: rgba(255,255,255,0.8);
317
- }
318
-
319
- /* Upload half of add-tile */
320
- .fb-multi-add-upload {
321
- flex: 1;
322
- display: flex;
323
- flex-direction: column;
324
- align-items: center;
325
- justify-content: center;
326
- gap: 4px;
327
- color: #2563eb;
328
- cursor: pointer;
329
- background: transparent;
330
- border: none;
331
- font-family: inherit;
332
- width: 100%;
333
- transition: background 150ms;
334
- }
335
- .fb-multi-add-upload:hover {
336
- background: rgba(191,219,254,0.35);
337
- }
338
-
339
- /* Horizontal dashed divider inside add-tile */
340
- .fb-multi-add-divider {
341
- border-top: 1px dashed rgba(96,165,250,0.5);
342
- margin: 0;
343
- flex-shrink: 0;
344
- }
345
-
346
- /* Library strip at bottom of add-tile */
347
- .fb-multi-add-library {
348
- padding: 6px 0;
349
- display: flex;
350
- align-items: center;
351
- justify-content: center;
352
- gap: 4px;
353
- color: #2563eb;
354
- font-size: 11px;
355
- font-weight: 500;
356
- cursor: pointer;
357
- background: transparent;
358
- border: none;
359
- font-family: inherit;
360
- width: 100%;
361
- transition: background 150ms;
362
- flex-shrink: 0;
363
- }
364
- .fb-multi-add-library:hover {
365
- background: rgba(191,219,254,0.35);
366
- }
367
-
368
- /* \u2500\u2500\u2500 Capacity placeholder squares \u2500\u2500\u2500 */
369
- .fb-multi-placeholder {
370
- aspect-ratio: 1 / 1;
371
- border-radius: 0.5rem;
372
- border: 1px solid #e2e8f0;
373
- }
374
- .fb-multi-placeholder.fb-drag-over {
375
- border-width: 2px;
376
- border-style: dashed;
377
- border-color: #93c5fd;
378
- background: rgba(219,234,254,0.6);
379
- }
380
-
381
- /* \u2500\u2500\u2500 Filled preview tile \u2500\u2500\u2500 */
382
- .fb-preview-tile {
383
- aspect-ratio: 1 / 1;
384
- border-radius: 0.5rem;
385
- border: 1px solid #e2e8f0;
386
- overflow: hidden;
387
- position: relative;
388
- cursor: pointer;
389
- }
390
- .fb-preview-tile img {
391
- width: 100%;
392
- height: 100%;
393
- object-fit: contain;
394
- display: block;
395
- }
396
-
397
- /* \u2500\u2500\u2500 Uploading placeholder tile \u2500\u2500\u2500 */
398
- .fb-uploading-tile {
399
- aspect-ratio: 1 / 1;
400
- border-radius: 0.5rem;
401
- border: 2px dashed #d1d5db;
402
- display: flex;
403
- flex-direction: column;
404
- align-items: center;
405
- justify-content: center;
406
- gap: 6px;
407
- padding: 6px;
408
- }
409
-
410
- /* \u2500\u2500\u2500 Meta line below multi grid \u2500\u2500\u2500 */
411
- .fb-meta-line {
412
- margin-top: 10px;
413
- display: flex;
414
- align-items: center;
415
- justify-content: space-between;
416
- gap: 8px;
417
- flex-wrap: wrap;
418
- }
419
- .fb-meta-text {
420
- font-size: 12px;
421
- color: #94a3b8;
422
- display: flex;
423
- align-items: center;
424
- gap: 8px;
425
- flex-wrap: wrap;
426
- }
427
- .fb-meta-dot {
428
- width: 4px;
429
- height: 4px;
430
- border-radius: 50%;
431
- background: #cbd5e1;
432
- flex-shrink: 0;
433
- }
434
- .fb-meta-mono {
435
- font-family: ui-monospace, 'JetBrains Mono', monospace;
436
- font-size: 11px;
437
- letter-spacing: -0.02em;
438
- }
439
- .fb-clear-all-btn {
440
- font-size: 12px;
441
- color: #94a3b8;
442
- background: none;
443
- border: none;
444
- cursor: pointer;
445
- padding: 0;
446
- font-family: inherit;
447
- transition: color 150ms;
448
- white-space: nowrap;
449
- flex-shrink: 0;
450
- }
451
- .fb-clear-all-btn:hover {
452
- color: #dc2626;
453
- }
454
-
455
- /* \u2500\u2500\u2500 Empty text (readonly) \u2500\u2500\u2500 */
456
- .fb-tile-empty-text {
457
- font-size: 11px;
458
- color: var(--fb-text-secondary-color, #6b7280);
459
- padding: 4px 0;
460
- }
461
-
462
- /* \u2500\u2500\u2500 Tile action buttons (for zoom popup, compat) \u2500\u2500\u2500 */
463
- .fb-tile-actions {
464
- position: absolute;
465
- top: 3px;
466
- right: 3px;
467
- display: flex;
468
- flex-direction: row;
469
- gap: 3px;
470
- opacity: 0;
471
- transition: opacity var(--fb-transition-duration, 200ms);
472
- z-index: 10;
473
- }
474
- .fb-preview-tile:hover .fb-tile-actions {
475
- opacity: 1;
476
- }
477
- .fb-tile-action-btn {
478
- width: 24px;
479
- height: 24px;
480
- display: flex;
481
- align-items: center;
482
- justify-content: center;
483
- border: 1px solid rgba(15,23,42,0.08);
484
- border-radius: 0.375rem;
485
- cursor: pointer;
486
- background: rgba(255,255,255,0.92);
487
- color: #374151;
488
- padding: 0;
489
- flex-shrink: 0;
490
- box-shadow: 0 1px 2px rgba(0,0,0,0.06);
491
- transition: background var(--fb-transition-duration, 200ms),
492
- color var(--fb-transition-duration, 200ms);
493
- }
494
- .fb-tile-action-btn:hover {
495
- background: #ffffff;
496
- color: #0f172a;
497
- }
498
- .fb-tile-action-remove:hover {
499
- color: #dc2626;
500
- }
501
-
502
- /* Zoom popup action buttons always visible */
503
- .fb-tile-zoom-preview .fb-tile-actions {
504
- position: absolute;
505
- top: 6px;
506
- right: 6px;
507
- opacity: 1;
508
- z-index: 10000;
509
- }
510
-
511
- /* \u2500\u2500\u2500 Hover zoom preview popup \u2500\u2500\u2500 */
512
- .fb-tile-zoom-preview {
513
- position: fixed;
514
- z-index: 9999;
515
- background: var(--fb-background-color, #fff);
516
- border: 1px solid #e2e8f0;
517
- border-radius: 0.5rem;
518
- box-shadow: 0 4px 16px rgba(0,0,0,0.18);
519
- padding: 4px;
520
- width: 350px;
521
- height: 350px;
522
- pointer-events: none;
523
- opacity: 0;
524
- transition: opacity 150ms ease;
525
- }
526
- .fb-tile-zoom-preview.fb-tile-zoom-preview--visible {
527
- opacity: 1;
528
- }
529
- .fb-tile-zoom-preview-img {
530
- width: 100%;
531
- height: 100%;
532
- object-fit: contain;
533
- display: block;
534
- border-radius: calc(0.5rem - 2px);
535
- }
536
-
537
- /* \u2500\u2500\u2500 Single-file uploading state \u2500\u2500\u2500 */
538
- .fb-single-uploading {
539
- height: 180px;
540
- border-radius: 0.75rem;
541
- border: 1px dashed #60a5fa;
542
- background: rgba(239,246,255,0.5);
543
- display: flex;
544
- flex-direction: column;
545
- align-items: center;
546
- justify-content: center;
547
- gap: 8px;
548
- }
549
-
550
- /* \u2500\u2500\u2500 Video overlays \u2500\u2500\u2500 */
551
- .fb-video-overlay {
552
- position: absolute;
553
- inset: 0;
554
- display: flex;
555
- align-items: center;
556
- justify-content: center;
557
- background: rgba(0,0,0,0.25);
558
- }
559
- .fb-play-btn {
560
- background: rgba(255,255,255,0.9);
561
- border-radius: 50%;
562
- display: flex;
563
- align-items: center;
564
- justify-content: center;
565
- }
566
- .fb-video-preview-wrap {
567
- position: relative;
568
- width: 100%;
569
- height: 100%;
570
- }
571
- .fb-video-btn-overlay {
572
- position: absolute;
573
- top: 8px;
574
- right: 8px;
575
- z-index: 10;
576
- display: flex;
577
- gap: 4px;
578
- opacity: 0;
579
- transition: opacity 150ms;
580
- pointer-events: none;
581
- }
582
- .fb-video-preview-wrap:hover .fb-video-btn-overlay {
583
- opacity: 1;
584
- pointer-events: auto;
585
- }
586
- .fb-video-btn {
587
- border: none;
588
- border-radius: 4px;
589
- font-size: 11px;
590
- padding: 4px 8px;
591
- cursor: pointer;
592
- color: #fff;
593
- line-height: 1.2;
594
- }
595
- .fb-video-btn-delete { background: rgba(220,38,38,0.85); }
596
- .fb-video-btn-delete:hover { background: rgba(185,28,28,0.95); }
597
- .fb-video-btn-change { background: rgba(31,41,55,0.85); }
598
- .fb-video-btn-change:hover { background: rgba(17,24,39,0.95); }
599
-
600
- /* \u2500\u2500\u2500 Readonly readonly tile \u2500\u2500\u2500 */
601
- .fb-readonly-tile {
602
- aspect-ratio: 1 / 1;
603
- border-radius: 0.5rem;
604
- border: 1px solid #e2e8f0;
605
- overflow: hidden;
606
- position: relative;
607
- cursor: pointer;
608
- }
609
- .fb-readonly-tile img {
610
- width: 100%;
611
- height: 100%;
612
- object-fit: contain;
613
- display: block;
614
- }
615
- .fb-readonly-tile .fb-tile-actions {
616
- opacity: 0;
617
- }
618
- .fb-readonly-tile:hover .fb-tile-actions {
619
- opacity: 1;
620
- }
621
-
622
- /* \u2500\u2500\u2500 Readonly single-file filled \u2500\u2500\u2500 */
623
- .fb-single-readonly-filled {
624
- position: relative;
625
- border-radius: 0.75rem;
626
- border: 1px solid #e2e8f0;
627
- overflow: hidden;
628
- height: 220px;
629
- display: block;
630
- cursor: pointer;
631
- }
632
- .fb-single-readonly-filled img {
633
- width: 100%;
634
- height: 100%;
635
- object-fit: contain;
636
- display: block;
637
- }
638
-
639
- /* \u2500\u2500\u2500 Readonly multi grid \u2500\u2500\u2500 */
640
- .fb-multi-readonly-grid {
641
- display: grid;
642
- grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
643
- gap: 10px;
644
- }
645
- `,document.head.appendChild(e)}function Qt(){ke();const e=document.createElement("div");return e.className="fb-tile",e}function Ee(e,t){var n,r;const o=(n=e.closest("[data-files-wrapper]"))==null?void 0:n.querySelector(".file-error-message");o&&o.remove();const a=document.createElement("div");a.className="file-error-message error-message",a.style.cssText=`
646
- color: var(--fb-error-color);
647
- font-size: var(--fb-font-size-small);
648
- margin-top: 0.25rem;
649
- `,a.textContent=t,(r=e.closest("[data-files-wrapper]"))==null||r.appendChild(a)}function qe(e){var t;const n=(t=e.closest("[data-files-wrapper]"))==null?void 0:t.querySelector(".file-error-message");n&&n.remove()}function Rr(e,t,n){const r=e.querySelector(".delete-overlay");r&&r.remove();const o=document.createElement("div");o.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 a=document.createElement("button");a.className="bg-red-600 text-white px-3 py-1 rounded text-sm hover:bg-red-700 transition-colors",a.textContent=k("removeElement",t),a.onclick=i=>{i.stopPropagation(),n()},o.appendChild(a),e.appendChild(o)}function Hr(e,t){ke();const n=Qt();n.classList.add("fb-tile-uploading"),n.className+=" fb-uploading-tile";const r=e.length>10?e.substring(0,8)+"\u2026":e;return n.innerHTML=`
650
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;gap:6px;padding:4px;">
651
- <div class="fb-spinner"></div>
652
- <div class="fb-tile-label">${le(r)}</div>
653
- <div class="fb-tile-uploading-text">${le(k("uploadingFile",t))}</div>
654
- </div>`,n}function en(e){var t,n,r;const o=e.querySelector(".fb-multi-grid");if(o)return o;const a=e.querySelector(".fb-tiles-wrap");if(a)return a;(t=e.querySelector(".fb-file-dropzone"))==null||t.remove(),(n=e.querySelector(".fb-wide-tile"))==null||n.remove(),(r=e.querySelector(".fb-multi-outer"))==null||r.remove();const i=document.createElement("div");i.className="fb-tiles-wrap",i.style.cssText="display:flex;flex-wrap:wrap;gap:6px;align-items:flex-start;";const l=document.createElement("div");return l.className="fb-tile fb-tile-add",l.innerHTML="+",i.appendChild(l),e.appendChild(i),i}function xt(e,t,n){e.innerHTML=`
655
- <div class="flex flex-col items-center justify-center h-full text-gray-400">
656
- <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 24 24">
657
- <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"/>
658
- </svg>
659
- <div class="text-sm text-center">${le(k("clickDragText",t))}</div>
660
-
661
- </div>
662
- `}const tn=new WeakMap;function rt(e,t){const n=tn.get(e);n&&(e.removeEventListener("dragover",n.dragover),e.removeEventListener("dragleave",n.dragleave),e.removeEventListener("drop",n.drop));const r=i=>{i.preventDefault(),e.classList.add("border-blue-500","bg-blue-50")},o=i=>{i.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50")},a=i=>{var l;i.preventDefault(),e.classList.remove("border-blue-500","bg-blue-50");const s=(l=i.dataTransfer)==null?void 0:l.files;s&&t(s)};e.addEventListener("dragover",r),e.addEventListener("dragleave",o),e.addEventListener("drop",a),tn.set(e,{dragover:r,dragleave:o,drop:a})}const Br='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><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>',Dr='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><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>',jr='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"/></svg>',Or='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 18a4 4 0 000-8 6 6 0 00-11.5 2A4 4 0 006 20h11M12 12v7M12 12l-3 3M12 12l3 3"/></svg>',Ur='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4h4v16H4z"/><path d="M10 4h4v16h-4z"/><path d="M16 5l3.5 1-3 14L13 19"/></svg>';function Pr(e,t){return!!(e.config.downloadFile||e.config.getDownloadUrl||e.config.getThumbnail||t!=null&&t.file)}function Wr(e,t){return!!(e.config.getDownloadUrl||e.config.getThumbnail||t!=null&&t.file)}function wt(e){const{canRemove:t,removeHandler:n,state:r,resourceId:o,fileName:a,meta:i,replaceHandler:l,libraryHandler:s}=e,u=document.createElement("div");u.className="fb-tile-actions";const d=(c,p,f)=>{const m=document.createElement("button");return m.type="button",m.className=`fb-tile-action-btn ${f}`,m.innerHTML=c,m.title=p,m.setAttribute("aria-label",p),m.addEventListener("click",b=>{b.stopPropagation()}),m};if(l){const c=d(Or,k("replaceFile",r),"fb-tile-action-replace");c.addEventListener("click",()=>l()),u.appendChild(c)}if(s){const c=d(Ur,k("fromLibrary",r),"fb-tile-action-library");c.addEventListener("click",()=>s()),u.appendChild(c)}if(Pr(r,i)){const c=d(Br,k("downloadFile",r),"fb-tile-action-download");c.addEventListener("click",()=>{Vr(o,a,r,i)}),u.appendChild(c)}if(Wr(r,i)){const c=d(Dr,k("openInNewTab",r),"fb-tile-action-open");c.addEventListener("click",()=>{_r(o,r,i).catch(p=>{console.error("Open failed:",p)})}),u.appendChild(c)}if(t&&n){const c=d(jr,k("removeElement",r),"fb-tile-action-remove");c.addEventListener("click",()=>{n()}),u.appendChild(c)}return u}const ot=new WeakMap;function Et(e){let t=ot.get(e);return t||(t=URL.createObjectURL(e),ot.set(e,t)),t}function lt(e){if(!e)return;const t=ot.get(e);t&&(URL.revokeObjectURL(t),ot.delete(e))}function Vr(e,t,n,r){if(n.config.downloadFile){n.config.downloadFile(e,t);return}if((r==null?void 0:r.file)instanceof File){un(r.file,t||r.file.name);return}sn(e,t,n).catch(o=>{console.error("Download failed:",o)})}async function _r(e,t,n){let r=null;t.config.getDownloadUrl?r=t.config.getDownloadUrl(e):t.config.getThumbnail?r=await t.config.getThumbnail(e):(n==null?void 0:n.file)instanceof File&&(r=Et(n.file)),r&&window.open(r,"_blank")}let ye=null,Fe=null,Ie=null,it=null;function Kr(){if(!ye){ye=document.createElement("div"),ye.className="fb-tile-zoom-preview";const e=document.createElement("img");e.className="fb-tile-zoom-preview-img",ye.appendChild(e),ye.addEventListener("mouseenter",rn),ye.addEventListener("mouseleave",nn)}return ye}function Jr(e,t){const n=t.getBoundingClientRect(),r=350,o=6,a=8;let i;n.top-r-o>=a?i=n.top-r-o:n.bottom+o+r+a<=window.innerHeight?i=n.bottom+o:i=Math.max(a,Math.min(window.innerHeight-r-a,n.top));let l=n.left+n.width/2-r/2;l=Math.max(a,Math.min(window.innerWidth-r-a,l)),e.style.top=`${i}px`,e.style.left=`${l}px`}function nn(){Ie!==null&&clearTimeout(Ie),Ie=setTimeout(()=>{Ie=null,on()},100)}function rn(){Ie!==null&&(clearTimeout(Ie),Ie=null)}function on(){Fe!==null&&(clearTimeout(Fe),Fe=null),ye&&ye.parentNode&&(ye.classList.remove("fb-tile-zoom-preview--visible"),ye.parentNode.removeChild(ye)),it=null}function Ct(e,t,n,r){e.dataset.zoomSrc=t,e.dataset.zoomAlt=n,e.addEventListener("mouseenter",()=>{rn(),it!==e&&on(),it=e,Fe=setTimeout(()=>{Fe=null;const o=Kr(),a=o.querySelector(".fb-tile-actions");a&&a.remove();const i=o.querySelector(".fb-tile-zoom-preview-img");i.src=t,i.alt=n,r&&(o.appendChild(r.cloneNode(!0)),Yr(o.querySelector(".fb-tile-actions"),r)),o.style.pointerEvents="auto",Jr(o,e),document.body.appendChild(o),o.getBoundingClientRect(),o.classList.add("fb-tile-zoom-preview--visible")},200)}),e.addEventListener("mouseleave",()=>{Fe!==null?(clearTimeout(Fe),Fe=null,it=null):nn()})}function Yr(e,t){const n=Array.from(t.querySelectorAll(".fb-tile-action-btn"));Array.from(e.querySelectorAll(".fb-tile-action-btn")).forEach((r,o)=>{const a=n[o];a&&r.addEventListener("click",i=>{i.stopPropagation(),a.click()})})}function Gr(e,t,n,r){const o=document.createElement("img");o.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",o.alt=n||k("previewAlt",r);const a=new FileReader;a.onload=i=>{var l;o.src=((l=i.target)==null?void 0:l.result)||""},a.readAsDataURL(t),e.appendChild(o)}function Xr(e,t){e.onclick=null;const n=e.cloneNode(!1);return e.parentNode&&e.parentNode.replaceChild(n,e),n}function Zr(e,t,n,r,o,a){const i=URL.createObjectURL(t),l=Xr(e);return l.innerHTML=`
663
- <div class="fb-video-preview-wrap">
664
- <video style="width:100%;height:100%;object-fit:contain;" controls preload="auto" muted src="${i}">
665
- ${le(k("videoNotSupported",o))}
666
- </video>
667
- <div class="fb-video-btn-overlay">
668
- <button class="fb-video-btn fb-video-btn-delete delete-file-btn">
669
- ${le(k("removeElement",o))}
670
- </button>
671
- <button class="fb-video-btn fb-video-btn-change change-file-btn">
672
- ${le(k("changeButton",o))}
673
- </button>
674
- </div>
675
- </div>
676
- `,Qr(l,r,o,a),l}function Qr(e,t,n,r){const o=e.querySelector(".change-file-btn");o&&(o.onclick=i=>{var l;i.stopPropagation(),(l=r==null?void 0:r.picker)==null||l.click()});const a=e.querySelector(".delete-file-btn");a&&(a.onclick=i=>{i.stopPropagation(),eo(e,t,n,r)})}function eo(e,t,n,r){var o;n.resourceIndex.delete(t);const a=(o=e.parentElement)==null?void 0:o.querySelector('input[type="hidden"]');a&&(a.value=""),r!=null&&r.fileUploadHandler&&(e.onclick=r.fileUploadHandler),e.innerHTML=`
677
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--fb-text-secondary-color,#9ca3af);">
678
- <svg style="width:1.5rem;height:1.5rem;margin-bottom:0.5rem;" fill="currentColor" viewBox="0 0 24 24">
679
- <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"/>
680
- </svg>
681
- <div style="font-size:0.875rem;text-align:center;">${le(k("clickDragText",n))}</div>
682
- </div>
683
- `,r!=null&&r.setupDrop&&r.setupDrop(e)}function ln(e,t,n){Rr(e,n,()=>{var r;n.resourceIndex.delete(t);const o=(r=e.parentElement)==null?void 0:r.querySelector('input[type="hidden"]');o&&(o.value=""),e.innerHTML=`
684
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--fb-text-secondary-color,#9ca3af);">
685
- <svg style="width:1.5rem;height:1.5rem;margin-bottom:0.5rem;" fill="currentColor" viewBox="0 0 24 24">
686
- <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"/>
687
- </svg>
688
- <div style="font-size:0.875rem;text-align:center;">${le(k("clickDragText",n))}</div>
689
- </div>
690
- `})}async function to(e,t,n,r,o,a,i){var l,s,u;!t.file||!(t.file instanceof File)||((l=t.type)!=null&&l.startsWith("image/")?Gr(e,t.file,n,a):(s=t.type)!=null&&s.startsWith("video/")?e=Zr(e,t.file,t.type,r,a,i):e.innerHTML=`<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--fb-text-secondary-color,#9ca3af);"><div style="font-size:36px;margin-bottom:0.5rem;">\u{1F4C1}</div><div style="font-size:0.875rem;">${le(n)}</div></div>`,!o&&!((u=t.type)!=null&&u.startsWith("video/"))&&ln(e,r,a))}function no(e,t,n){const r=document.createElement("video");r.style.cssText="width:100%;height:100%;object-fit:contain;",r.controls=!0,r.preload="metadata",r.muted=!0,r.src=t,r.appendChild(document.createTextNode(k("videoNotSupported",n))),e.appendChild(r)}async function ro(e,t,n,r,o){var a;if(!o.config.getThumbnail){xt(e,o);return}try{const i=await o.config.getThumbnail(t);if(i)if(ge(e),(a=r==null?void 0:r.type)!=null&&a.startsWith("video/"))no(e,i,o);else{const l=document.createElement("img");l.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",l.alt=n||k("previewAlt",o),l.src=i,e.appendChild(l)}else xt(e,o)}catch(i){console.error("Failed to get thumbnail:",i),e.innerHTML=`
691
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--fb-text-secondary-color,#9ca3af);">
692
- <svg style="width:1.5rem;height:1.5rem;margin-bottom:0.5rem;" fill="currentColor" viewBox="0 0 24 24">
693
- <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"/>
694
- </svg>
695
- <div style="font-size:0.875rem;text-align:center;">${le(n||k("previewUnavailable",o))}</div>
696
- </div>
697
- `}}async function kt(e,t,n,r={}){var o;const{fileName:a="",isReadonly:i=!1,deps:l=null}=r;if(!i&&l&&(!l.picker||!l.fileUploadHandler||!l.dragHandler))throw new Error("renderFilePreview: missing deps {picker, fileUploadHandler, dragHandler}");ge(e);const s=n.resourceIndex.get(t);if(s&&s.file&&s.file instanceof File)await to(e,s,a,t,i,n,l);else{await ro(e,t,a,s,n);const u=(o=s==null?void 0:s.type)==null?void 0:o.startsWith("video/");!i&&!u&&ln(e,t,n)}}function oo(e,t,n){var r;if(n)return n;if((r=t==null?void 0:t.name)!=null&&r.includes("."))return t.name;const o=e.includes("/")?e.split("/").pop():e;return o!=null&&o.includes(".")?o:""}async function $t(e,t,n,r={}){var o,a;const i=t.resourceIndex.get(e),l=oo(e,i,n),{canRemove:s=!1,removeHandler:u=null}=r,d=((o=i==null?void 0:i.type)==null?void 0:o.startsWith("image/"))||!!l.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/),c=((a=i==null?void 0:i.type)==null?void 0:a.startsWith("video/"))||!!l.toLowerCase().match(/\.(mp4|webm|avi|mov)$/),p=Qt();p.classList.add("fb-tile-resource"),p.style.cursor="pointer",l&&(p.title=l);const f=(i==null?void 0:i.file)instanceof File?Et(i.file):null,m=async()=>t.config.getDownloadUrl?t.config.getDownloadUrl(e):t.config.getThumbnail?t.config.getThumbnail(e):f;p.onclick=async()=>{const h=await m();h?window.open(h,"_blank"):t.config.downloadFile?t.config.downloadFile(e,l):sn(e,l,t).catch(x=>{console.error("Download failed:",x)})};const b=wt({canRemove:s,removeHandler:u,state:t,resourceId:e,fileName:l,meta:i}),g=async()=>{if(t.config.getThumbnail)try{const h=await t.config.getThumbnail(e);if(h)return h}catch(h){}return f},E=()=>{p.innerHTML='<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F5BC}\uFE0F</div>',p.appendChild(b)};if(d){const h=await g();if(h){const x=document.createElement("img");x.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",x.alt=l,x.src=h,p.appendChild(x),p.appendChild(b),Ct(p,h,l,b)}else E()}else if(c)if(t.config.getThumbnail)try{const h=await t.config.getThumbnail(e);h?(p.innerHTML=`
698
- <img style="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);" alt="${le(l)}" src="${h}">
699
- <div class="fb-video-overlay">
700
- <div class="fb-play-btn" style="width:22px;height:22px;">
701
- <svg width="10" height="12" viewBox="0 0 10 12" fill="currentColor"><path d="M0 0l10 6-10 6z"/></svg>
702
- </div>
703
- </div>`,p.appendChild(b)):(p.innerHTML='<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F3A5}</div>',p.appendChild(b))}catch(h){p.innerHTML='<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F3A5}</div>',p.appendChild(b)}else p.innerHTML='<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F3A5}</div>',p.appendChild(b);else{if(t.config.getThumbnail)try{const x=await t.config.getThumbnail(e);if(x){const v=document.createElement("img");return v.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",v.alt=l||e,v.src=x,p.appendChild(v),p.appendChild(b),p}}catch(x){}const h=l?`<div class="fb-tile-label">${le(l.length>10?l.substring(0,8)+"\u2026":l)}</div>
704
- <svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zm-7 9H5v2h14v-2h-7z"/></svg>`:"";p.innerHTML=`
705
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;padding:6px;gap:4px;">
706
- <div style="font-size:36px;">\u{1F4C1}</div>
707
- ${h}
708
- </div>`,p.appendChild(b)}return p}async function lo(e,t,n,r){var o,a,i;const l=n.resourceIndex.get(t),s=(a=(o=l==null?void 0:l.name)!=null?o:t.split("/").pop())!=null?a:"",u=(i=r.onRemove)!=null?i:null,d=await $t(t,n,s,{canRemove:!0,removeHandler:u});e.className="file-preview-container",e.removeAttribute("style"),ge(e),e.appendChild(d)}async function an(e,t,n,r,o){var a,i;if((a=n==null?void 0:n.type)!=null&&a.startsWith("image/")){if(n.file&&n.file instanceof File){const l=document.createElement("img");l.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",l.alt=n.name,l.src=Et(n.file),e.appendChild(l),Ct(e,l.src,n.name,o!=null?o:null)}else if(r.config.getThumbnail)try{const l=await r.config.getThumbnail(t);if(l){const s=document.createElement("img");s.style.cssText="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);",s.alt=n.name,s.src=l,e.appendChild(s),Ct(e,l,n.name,o!=null?o:null)}else e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F5BC}\uFE0F</div>'}catch(l){const s=l instanceof Error?l:new Error(String(l));r.config.onThumbnailError&&r.config.onThumbnailError(s,t),e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:16px;color:var(--fb-error-color,#ef4444);">\u2715</div>'}else e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F5BC}\uFE0F</div>';o&&e.appendChild(o)}else if((i=n==null?void 0:n.type)!=null&&i.startsWith("video/")){if(n.file&&n.file instanceof File){const l=URL.createObjectURL(n.file);e.innerHTML=`
709
- <video style="width:100%;height:100%;" preload="metadata" muted src="${l}"></video>
710
- <div class="fb-video-overlay">
711
- <div class="fb-play-btn" style="width:20px;height:20px;">
712
- <svg width="8" height="10" viewBox="0 0 8 10" fill="currentColor"><path d="M0 0l8 5-8 5z"/></svg>
713
- </div>
714
- </div>`}else if(r.config.getThumbnail)try{const l=await r.config.getThumbnail(t);l?e.innerHTML=`
715
- <img style="width:100%;height:100%;object-fit:contain;background:var(--fb-file-upload-bg-color,#f3f4f6);" alt="${le(n.name)}" src="${l}">
716
- <div class="fb-video-overlay">
717
- <div class="fb-play-btn" style="width:20px;height:20px;">
718
- <svg width="8" height="10" viewBox="0 0 8 10" fill="currentColor"><path d="M0 0l8 5-8 5z"/></svg>
719
- </div>
720
- </div>`:e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F3A5}</div>'}catch(l){const s=l instanceof Error?l:new Error(String(l));r.config.onThumbnailError&&r.config.onThumbnailError(s,t),e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:16px;color:var(--fb-error-color,#ef4444);">\u2715</div>'}else e.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;font-size:36px;">\u{1F3A5}</div>';o&&e.appendChild(o)}else io(e,t,n,o)}function io(e,t,n,r){var o,a;const i=(a=(o=n==null?void 0:n.name)!=null?o:t.split("/").pop())!=null?a:"";i&&(e.title=i);const l=i?`<div style="font-size:11px;line-height:1.2;text-align:center;color:var(--fb-text-secondary-color,#6b7280);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${le(i)}</div>`:"";e.innerHTML=`
721
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;padding:6px;gap:4px;">
722
- <div style="font-size:36px;">\u{1F4C1}</div>
723
- ${l}
724
- </div>`,r&&e.appendChild(r)}async function sn(e,t,n){try{let r=null;if(n.config.getDownloadUrl?r=n.config.getDownloadUrl(e):n.config.getThumbnail&&(r=await n.config.getThumbnail(e)),r){const o=r.startsWith("http")?r:new URL(r,window.location.href).href,a=await fetch(o);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const i=await a.blob();un(i,t)}else throw new Error("No download URL available for resource")}catch(r){const o=r instanceof Error?r:new Error(String(r));throw n.config.onDownloadError&&n.config.onDownloadError(o,e,t),console.error(`File download failed for ${t}:`,o),o}}function un(e,t){try{const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>{URL.revokeObjectURL(n)},100)}catch(n){throw new Error(`Blob download failed: ${n.message}`)}}async function cn(e,t){if(!t.config.uploadFile)throw new Error("No upload handler configured. Set uploadHandler via FormBuilder.setUploadHandler()");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 r=n instanceof Error?n:new Error(String(n));t.config.onUploadError&&t.config.onUploadError(r,e);const o=new Error(`File upload failed: ${r.message}`);throw o.cause=r,o}}async function ao(e){var t,n,r;const{file:o,container:a,fieldName:i,state:l,deps:s=null,instance:u=null,allowedExtensions:d=[],allowedMimes:c=[],maxSizeMB:p=1/0}=e;if(!Be(o.name,d)){const h=d.join(", ");Ee(a,k("invalidFileExtension",l,{name:o.name,formats:h}));return}if(!Ke(o.type,c)){const h=c.join(", ");Ee(a,k("invalidFileMime",l,{name:o.name,type:o.type,mimes:h}));return}if(!tt(o,p)){Ee(a,k("fileTooLarge",l,{name:o.name,maxSize:p}));return}qe(a);const f=(t=a.parentElement)==null?void 0:t.querySelector('input[type="hidden"]'),m=(f==null?void 0:f.value)||null;ke(),a.innerHTML=`
725
- <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;gap:6px;padding:6px;">
726
- <div class="fb-spinner"></div>
727
- <div style="font-size:11px;color:var(--fb-text-secondary-color,#6b7280);text-align:center;">${le(k("uploadingFile",l))}</div>
728
- </div>`;let b;try{b=await cn(o,l)}catch(h){throw m&&s!=null&&s.onAfterUpload?s.onAfterUpload(a,m):s!=null&&s.onRemove?s.onRemove():xt(a,l),h}l.resourceIndex.set(b,{name:o.name,type:o.type,size:o.size,uploadedAt:new Date,file:o}),m&&m!==b&&lt((n=l.resourceIndex.get(m))==null?void 0:n.file);let g=f;g||(g=document.createElement("input"),g.type="hidden",g.name=i,(r=a.parentElement)==null||r.appendChild(g)),g.value=b;const E=o.type.startsWith("video/");!E&&s!=null&&s.onAfterUpload?s.onAfterUpload(a,b):!E&&s?lo(a,b,l,s).catch(console.error):kt(a,b,l,{fileName:o.name,isReadonly:!1,deps:s}).catch(console.error),u&&!l.config.readonly&&u.triggerOnChange(i,b)}function dn(e,t,n,r){const o=e.filter(m=>!Be(m.name,n.allowedExtensions)),a=e.filter(m=>Be(m.name,n.allowedExtensions)),i=a.filter(m=>!Ke(m.type,n.allowedMimes)),l=a.filter(m=>Ke(m.type,n.allowedMimes)),s=l.filter(m=>!tt(m,n.maxSize)),u=l.filter(m=>tt(m,n.maxSize)),d=n.maxCount===1/0?u.length:Math.max(0,n.maxCount-t),c=u.slice(0,d),p=u.length-c.length,f=[];if(o.length>0){const m=n.allowedExtensions.join(", "),b=o.map(g=>g.name).join(", ");f.push(k("invalidFileExtension",r,{name:b,formats:m}))}if(i.length>0){const m=n.allowedMimes.join(", "),b=i.map(g=>g.name).join(", ");f.push(k("invalidFileMime",r,{name:b,type:i.map(g=>g.type).join(", "),mimes:m}))}if(s.length>0){const m=s.map(b=>b.name).join(", ");f.push(k("fileTooLarge",r,{name:m,maxSize:n.maxSize}))}return p>0&&f.push(k("filesLimitExceeded",r,{skipped:p,max:n.maxCount})),{accepted:c,errorMessage:f.join(" \u2022 ")}}async function fn(e,t,n,r){var o;if(n){const i=en(n),l=(o=i.querySelector(".fb-multi-add-tile-js"))!=null?o:i.querySelector(".fb-tile-add");l&&(l.style.display="none")}const a=[];return await Promise.allSettled(e.map(async i=>{const l=Hr(i.name,r);n&&en(n).appendChild(l);try{const s=await cn(i,r);r.resourceIndex.set(s,{name:i.name,type:i.type,size:i.size,uploadedAt:new Date,file:void 0}),t.push(s)}catch(s){const u=s instanceof Error?s:new Error(String(s)),d=u.cause,c=d instanceof Error?d:d!==void 0?new Error(String(d)):u;a.push({file:i,error:c})}finally{l.remove()}})),{failures:a}}function pn(e,t,n){if(t.length===0)return e;const r=t.map(o=>k("uploadFailed",n,{name:o.file.name,error:o.error.message})).join(" \u2022 ");return e?`${e} \u2022 ${r}`:r}function so(e,t,n,r,o,a,i){rt(e,async l=>{var s;const{accepted:u,errorMessage:d}=dn(Array.from(l),t.length,o,n);d?Ee(e,d):qe(e);const c=(s=e.querySelector(".files-list"))!=null?s:e,{failures:p}=await fn(u,t,c,n),f=pn(d,p,n);f?Ee(e,f):qe(e),r(),i&&a&&!n.config.readonly&&i.triggerOnChange(a,t)})}function uo(e,t,n,r,o,a,i){e.onchange=async()=>{if(!e.files)return;const l=e.closest("[data-files-wrapper]")||e.parentElement,{accepted:s,errorMessage:u}=dn(Array.from(e.files),t.length,o,n);u&&l?Ee(l,u):l&&qe(l);const d=l==null?void 0:l.querySelector(".files-list"),{failures:c}=await fn(s,t,d!=null?d:null,n);if(l){const p=pn(u,c,n);p?Ee(l,p):qe(l)}r(),e.value="",i&&a&&!n.config.readonly&&i.triggerOnChange(a,t)}}function mn(e){var t,n;if(!e.accept)return;if(typeof e.accept=="string"){const l=Ae(e.accept);return l.length>0?{extensions:l}:void 0}const r=(t=e.accept.extensions)!=null?t:[],o=(n=e.accept.mime)!=null?n:[],a=r.map(l=>l.toLowerCase());if(a.length===0&&o.length===0)return;const i={};return a.length>0&&(i.extensions=a),o.length>0&&(i.mime=o),i}function hn(e,t,n,r,o){if(!Be(e.name,t)){const a=t.join(", ");return k("invalidFileExtension",o,{name:e.name,formats:a})}if(!Ke(e.type,n)){const a=n.join(", ");return k("invalidFileMime",o,{name:e.name,type:e.type,mimes:a})}return Xt(e.size,r)?null:k("fileTooLarge",o,{name:e.name,maxSize:r})}function co(e){const t=e.dataset.resourceIds;if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n:[]}catch(n){return[]}}function bn(e,t){var n;const r=t.resourceIndex.get(e.resourceId);t.resourceIndex.set(e.resourceId,{name:e.name,type:e.type,size:e.size,uploadedAt:(n=r==null?void 0:r.uploadedAt)!=null?n:new Date,file:r==null?void 0:r.file})}function vn(e,t){return e instanceof Error&&e.message?e.message:k("pickerError",t)}async function fo(e,t,n,r,o,a,i,l){var s;if(!e.config.pickExistingFiles)return;const u=Ae(t.accept),d=_e(t.accept),c=(s=t.maxSize)!=null?s:1/0,p=co(n),f=a===1/0?1/0:Math.max(0,a-p.length);let m;try{m=await e.config.pickExistingFiles({fieldPath:r,mode:"multiple",accept:mn(t),maxSizeMB:c===1/0?void 0:c,remainingSlots:f===1/0?void 0:f,selectedResourceIds:[...p]})}catch(w){Ee(n,vn(w,e));return}if(m.length===0)return;const b=new Set(p),g=new Set,E=m.filter(w=>b.has(w.resourceId)||g.has(w.resourceId)?!1:(g.add(w.resourceId),!0)).filter(w=>hn(w,u,d,c,e)===null),h=a===1/0?E.length:Math.max(0,a-o.length),x=E.slice(0,h),v=E.length-x.length;if(x.length!==0){qe(n),v>0&&Ee(n,k("filesLimitExceeded",e,{skipped:v,max:a}));for(const w of x)bn(w,e),o.push(w.resourceId);n.dataset.resourceIds=JSON.stringify(o),i(),e.config.readonly||l.triggerOnChange(r,o)}}async function po(e,t,n,r,o,a,i,l){var s,u;if(!e.config.pickExistingFiles)return;const d=Ae(t.accept),c=_e(t.accept),p=(s=t.maxSize)!=null?s:1/0;let f;try{f=await e.config.pickExistingFiles({fieldPath:a,mode:"single",accept:mn(t),maxSizeMB:p===1/0?void 0:p,selectedResourceIds:[]})}catch(h){Ee(n,vn(h,e));return}if(f.length===0)return;const m=f[0],b=hn(m,d,c,p,e);if(b!==null){Ee(n,b);return}qe(n),bn(m,e);let g=r.querySelector('input[type="hidden"]');g||(g=document.createElement("input"),g.type="hidden",g.name=o,r.appendChild(g));const E=g.value||null;E&&E!==m.resourceId&&lt((u=e.resourceIndex.get(E))==null?void 0:u.file),g.value=m.resourceId,await i(m.resourceId),e.config.readonly||l.triggerOnChange(a,m.resourceId)}const gn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 18a4 4 0 000-8 6 6 0 00-11.5 2A4 4 0 006 20h11M12 12v7M12 12l-3 3M12 12l3 3"/></svg>',yn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4h4v16H4z"/><path d="M10 4h4v16h-4z"/><path d="M16 5l3.5 1-3 14L13 19"/></svg>';function mo(e,t,n,r,o,a,i){var l;nt(e,o.resourceIndex);const s=o.resourceIndex.get(e);(l=s==null?void 0:s.type)!=null&&l.startsWith("video/")?kt(t,e,o,{fileName:e,isReadonly:!1,deps:a}).catch(console.error):Lt(t,e,o,a,i);const u=document.createElement("input");u.type="hidden",u.name=n,u.value=e,r.appendChild(u)}function ho(e,t,n,r,o=!1,a=""){ke();const i=document.createElement("div");i.className=`fb-wide-tile${t?" fb-file-card-row":""}${o?" fb-drag-over":""}`;const l=document.createElement("button");l.type="button",l.className="fb-wide-tile-upload fb-file-dropzone";const s=document.createElement("span");s.style.cssText="width:36px;height:36px;display:block;flex-shrink:0;",s.innerHTML=gn,l.appendChild(s);const u=document.createElement("div");if(u.className="fb-wide-tile-label",u.style.cssText="font-size:14px;font-weight:600;",u.textContent=k(o?"dropToUpload":"clickDragText",e),l.appendChild(u),a){const d=document.createElement("div");d.style.cssText="font-size:11px;opacity:0.65;margin-top:2px;",d.textContent=a,l.appendChild(d)}if(l.onclick=d=>{d.stopPropagation(),n()},i.appendChild(l),t&&r){const d=document.createElement("div");d.className="fb-wide-tile-divider",i.appendChild(d);const c=document.createElement("button");c.type="button",c.className="fb-wide-tile-library fb-file-library-card";const p=document.createElement("span");p.style.cssText="width:28px;height:28px;display:block;flex-shrink:0;",p.innerHTML=yn,c.appendChild(p);const f=document.createElement("div");f.style.cssText="font-size:13px;font-weight:600;text-align:center;",f.textContent=k("fromLibrary",e),c.appendChild(f);const m=document.createElement("div");m.style.cssText="font-size:11px;opacity:0.75;text-align:center;",m.textContent=k("libraryHint",e),c.appendChild(m),c.onclick=b=>{b.stopPropagation(),r()},i.appendChild(c)}return xn(i,{onEnter:()=>{const d=i.querySelector(".fb-wide-tile-label");d&&(d.textContent=k("dropToUpload",e))},onLeave:()=>{const d=i.querySelector(".fb-wide-tile-label");d&&(d.textContent=k("clickDragText",e))},activeClass:"fb-drag-over"}),i}function xn(e,t){let n=0;e.addEventListener("dragover",r=>{r.preventDefault()}),e.addEventListener("dragenter",r=>{r.preventDefault(),n++,n===1&&(e.classList.add(t.activeClass),t.onEnter())}),e.addEventListener("dragleave",r=>{r.preventDefault(),n=Math.max(0,n-1),n===0&&(e.classList.remove(t.activeClass),t.onLeave())}),e.addEventListener("drop",()=>{n=0,e.classList.remove(t.activeClass),t.onLeave()})}function Lt(e,t,n,r,o){var a,i;const l=n.resourceIndex.get(t);if((a=l==null?void 0:l.type)!=null&&a.startsWith("video/")){kt(e,t,n,{fileName:(i=l==null?void 0:l.name)!=null?i:"",isReadonly:!1,deps:r}).catch(console.error);return}ke();const s=document.createElement("div");s.className="fb-multi-outer fb-multi-has-files";const u=document.createElement("div");u.className="fb-multi-grid fb-tiles-wrap",s.appendChild(u);const d=wn(t,n,!!r.onRemove,r.onRemove?()=>{var c;return(c=r.onRemove)==null?void 0:c.call(r)}:null,o);for(u.appendChild(d),e.className="file-preview-container",e.removeAttribute("style");e.firstChild;)e.removeChild(e.firstChild);e.appendChild(s)}function bo(e,t,n,r,o=!1){const a=document.createElement("div");a.className=`fb-multi-add-tile fb-multi-add-tile-js${o?" fb-drag-over-tile":""}`;const i=document.createElement("button");i.type="button",i.className="fb-multi-add-upload fb-tile-add fb-file-dropzone";const l=document.createElement("span");l.style.cssText="width:28px;height:28px;display:block;flex-shrink:0;",l.innerHTML=gn,i.appendChild(l);const s=document.createElement("span");if(s.className="fb-multi-add-label",s.style.cssText="font-size:11px;font-weight:600;",s.textContent=k(o?"dropToUpload":"clickDragTextMultiple",e),i.appendChild(s),i.onclick=u=>{u.stopPropagation(),n()},a.appendChild(i),t&&r){const u=document.createElement("div");u.className="fb-multi-add-divider",a.appendChild(u);const d=document.createElement("button");d.type="button",d.className="fb-multi-add-library fb-tile-add-library fb-file-library-card",d.setAttribute("aria-label",k("fromLibrary",e));const c=document.createElement("span");c.style.cssText="width:14px;height:14px;display:block;flex-shrink:0;",c.innerHTML=yn,d.appendChild(c),d.appendChild(document.createTextNode(k("fromLibrary",e))),d.onclick=p=>{p.stopPropagation(),r()},a.appendChild(d)}return a}function wn(e,t,n,r,o){var a,i,l;ke();const s=t.resourceIndex.get(e),u=document.createElement("div");u.className="fb-preview-tile fb-checker fb-tile-resource resource-pill",u.dataset.resourceId=e;const d=wt({canRemove:n&&r!==null,removeHandler:r,state:t,resourceId:e,fileName:(a=s==null?void 0:s.name)!=null?a:"",meta:s,replaceHandler:(i=o==null?void 0:o.replaceHandler)!=null?i:null,libraryHandler:(l=o==null?void 0:o.libraryHandler)!=null?l:null});return an(u,e,s,t,d).catch(c=>{console.error("Failed to render tile:",c)}),u}function En(e=!1){const t=document.createElement("div");return t.className=`fb-multi-placeholder fb-checker${e?" fb-drag-over":""}`,t}function vo(e,t,n,r,o,a){const i=document.createElement("div");i.className="fb-meta-line";const l=document.createElement("div");if(l.className="fb-meta-text",t.maxSize&&t.maxSize!==1/0){const d=document.createElement("span");d.textContent=k("hintMaxSize",e,{size:t.maxSize}),l.appendChild(d),l.appendChild(Cn())}const s=Ae(t.accept);if(s.length>0){const d=document.createElement("span");d.className="fb-meta-mono",d.textContent=s.map(c=>c.toUpperCase()).join(", "),l.appendChild(d),l.appendChild(Cn())}const u=document.createElement("span");if(r<1/0)u.textContent=k("fileCountWithMax",e,{count:n,max:r});else{const d=n===1?"fileCountSingle":"fileCountPlural";u.textContent=k(d,e,{count:n})}if(l.appendChild(u),i.appendChild(l),o&&n>1){const d=document.createElement("button");d.type="button",d.className="fb-clear-all-btn",d.textContent=k("clearAll",e),d.onclick=c=>{c.stopPropagation(),window.confirm(k("clearAll",e)+"?")&&a()},i.appendChild(d)}return i}function Cn(){const e=document.createElement("span");return e.className="fb-meta-dot",e}const St=new WeakMap;function go(e){var t;const{container:n,rids:r,state:o,onRemove:a,maxCount:i,isReadonly:l=!1,onLibraryPick:s,element:u,onClearAll:d,openPicker:c}=e;ke();const p=n.closest("[data-files-wrapper]");p&&(p.dataset.resourceIds=JSON.stringify(r!=null?r:[]));const f=St.get(n);for(f&&(f.disconnect(),St.delete(n));n.firstChild;)n.removeChild(n.firstChild);const m=r!=null?r:[],b=i!=null?i:1/0,g=b!==1/0&&m.length>=b,E=!l&&typeof s=="function",h=c!=null?c:(()=>{var y;const L=(y=n.closest("[data-files-wrapper]"))==null?void 0:y.querySelector('input[type="file"]');L&&L.click()});if(l){if(m.length===0){const y=document.createElement("div");y.className="fb-tile-empty-text",y.textContent=k("noFilesSelected",o),n.appendChild(y)}else{const y=document.createElement("div");y.className="fb-multi-readonly-grid",n.appendChild(y);for(const L of m){const R=o.resourceIndex.get(L),q=document.createElement("div");q.className="fb-readonly-tile fb-checker fb-tile fb-tile-resource",q.dataset.resourceId=L;const W=wt({canRemove:!1,removeHandler:null,state:o,resourceId:L,fileName:(t=R==null?void 0:R.name)!=null?t:"",meta:R});an(q,L,R,o,W).catch(console.error),q.onclick=async()=>{var K;let Y=null;o.config.getDownloadUrl?Y=o.config.getDownloadUrl(L):o.config.getThumbnail?Y=await o.config.getThumbnail(L):(R==null?void 0:R.file)instanceof File&&(Y=URL.createObjectURL(R.file)),Y?window.open(Y,"_blank"):o.config.downloadFile&&o.config.downloadFile(L,(K=R==null?void 0:R.name)!=null?K:"")},y.appendChild(q)}}return}const x=document.createElement("div");x.className=`fb-multi-outer${m.length>0?" fb-multi-has-files":""}`;const v=document.createElement("div");v.className="fb-multi-grid fb-tiles-wrap",x.appendChild(v),n.appendChild(x);for(let y=0;y<m.length;y++){const L=m[y],R=wn(L,o,a!==null,a?()=>a(L):null);v.appendChild(R)}if(!g){const y=bo(o,E,h,s!=null?s:null);v.appendChild(y)}const w=m.length+(g?0:1),C=()=>{const y=getComputedStyle(v).gridTemplateColumns,L=y?y.split(" ").filter(Boolean).length:0;if(!L)return;const R=w%L,q=R===0?0:L-R,W=b===1/0?q:Math.max(0,b-w),K=Math.min(q,W),Y=v.querySelectorAll(".fb-multi-placeholder");if(Y.length>K)for(let Q=Y.length-1;Q>=K;Q--)Y[Q].remove();else if(Y.length<K)for(let Q=Y.length;Q<K;Q++)v.appendChild(En())};if((b===1/0||b>w)&&v.appendChild(En()),requestAnimationFrame(C),typeof ResizeObserver!="undefined"){const y=new ResizeObserver(()=>C());y.observe(v),St.set(n,y)}if(xn(x,{activeClass:"fb-drag-over",onEnter:()=>{v.querySelectorAll(".fb-multi-placeholder").forEach(L=>{L.classList.add("fb-drag-over")});const y=v.querySelector(".fb-multi-add-tile-js");if(y){y.classList.add("fb-drag-over-tile");const L=y.querySelector(".fb-multi-add-label");L&&(L.textContent=k("dropToUpload",o))}},onLeave:()=>{v.querySelectorAll(".fb-multi-placeholder").forEach(L=>{L.classList.remove("fb-drag-over")});const y=v.querySelector(".fb-multi-add-tile-js");if(y){y.classList.remove("fb-drag-over-tile");const L=y.querySelector(".fb-multi-add-label");L&&(L.textContent=k("clickDragTextMultiple",o))}}}),u){const y=vo(o,u,m.length,b,!!d,d!=null?d:(()=>{}));n.appendChild(y)}}function yo(e,t,n,r){var o,a;const i=t.state,l=document.createElement("div");l.className="space-y-2",l.dataset.filesWrapper=r;const s=document.createElement("input");s.type="file",s.name=r,s.style.display="none",s.accept=kn(e.accept);const u=document.createElement("div");u.className="file-preview-container";const d=t.prefill[e.key],c=Ae(e.accept),p=_e(e.accept),f=(o=e.maxSize)!=null?o:1/0,m={fileUploadHandler(){s.click()},dragHandler(h){h.length>0&&ao({file:h[0],container:u,fieldName:r,state:i,deps:g(),instance:t.instance,allowedExtensions:c,allowedMimes:p,maxSizeMB:f})},setupDrop(h){rt(h,m.dragHandler)},onRemove(){var h;const x=l.querySelector('input[type="hidden"]'),v=x==null?void 0:x.value;v&&lt((h=i.resourceIndex.get(v))==null?void 0:h.file),x&&(x.value=""),E()}},b=()=>{const h=!!(i.config.pickExistingFiles&&!e.disableLibrary);return{replaceHandler:i.config.uploadFile?()=>s.click():null,libraryHandler:h?()=>{po(i,e,u,l,r,r,async x=>{Lt(u,x,i,g(),b())},t.instance).catch(x=>{console.error("Library pick failed:",x)})}:null}},g=()=>({picker:s,fileUploadHandler:m.fileUploadHandler,dragHandler:m.dragHandler,setupDrop:m.setupDrop,onRemove:m.onRemove,onAfterUpload:(h,x)=>{Lt(h,x,i,g(),b())}}),E=()=>{for(ke(),u.className="file-preview-container",u.removeAttribute("style");u.firstChild;)u.removeChild(u.firstChild);const h=b().libraryHandler,x=ho(i,h!==null,m.fileUploadHandler,h,!1,$e(e,i));u.appendChild(x),rt(u,m.dragHandler)};if(d){mo(d,u,r,l,i,g(),b());const h=i.resourceIndex.get(d);(a=h==null?void 0:h.type)!=null&&a.startsWith("video/")&&rt(u,m.dragHandler)}else E();s.onchange=()=>{s.files&&s.files.length>0&&m.dragHandler(s.files)},l.appendChild(u),l.appendChild(s),n.appendChild(l)}function kn(e){var t,n,r;return e?typeof e=="string"?e:[...(n=(t=e.extensions)==null?void 0:t.map(o=>`.${o}`))!=null?n:[],...(r=e.mime)!=null?r:[]].join(","):""}function $n(e,t,n,r,o){var a,i;const l=t.state,s=document.createElement("div");s.className="space-y-2",s.dataset.filesWrapper=r;const u=document.createElement("input");u.type="file",u.name=r,u.multiple=!0,u.style.display="none",u.accept=kn(e.accept);const d=document.createElement("div");d.className="files-list-wrapper";const c=document.createElement("div");c.className="files-list",s.appendChild(u),s.appendChild(d),d.appendChild(c);const p=Array.isArray(t.prefill[e.key])?[...t.prefill[e.key]]:[];yt(p,l.resourceIndex),s.dataset.resourceIds=JSON.stringify(p);const f={maxCount:o,allowedExtensions:Ae(e.accept),allowedMimes:_e(e.accept),maxSize:(i=(a=e.maxSize)!=null?a:e.maxSizeMB)!=null?i:1/0},m=()=>{u.click()},b=l.config.pickExistingFiles&&!e.disableLibrary?()=>{fo(l,e,s,r,p,o,g,t.instance).catch(E=>{console.error("Library pick failed:",E)})}:null;function g(){const E=oe(e,l);go({container:c,rids:p,state:l,onRemove:E?null:h=>{var x;lt((x=l.resourceIndex.get(h))==null?void 0:x.file);const v=p.indexOf(h);v>-1&&p.splice(v,1),g()},maxCount:o<1/0?o:void 0,isReadonly:E,onLibraryPick:E?null:b,element:e,onClearAll:E?void 0:()=>{p.splice(0),g()},openPicker:m})}so(d,p,l,g,f,r,t.instance),uo(u,p,l,g,f,r,t.instance),g(),n.appendChild(s)}function xo(e,t,n,r){$n(e,t,n,r,1/0)}function wo(e,t,n,r){var o;$n(e,t,n,r,(o=e.maxCount)!=null?o:1/0)}function Eo(e,t){const n=e.querySelector(`[data-files-wrapper="${t}"]`);if(!n)return[];const r=n.dataset.resourceIds;if(r===void 0)throw new Error(`readMultiFileResourceIds: [data-files-wrapper="${t}"] is missing data-resource-ids attribute. This is a render bug.`);const o=JSON.parse(r);if(!Array.isArray(o))throw new Error(`readMultiFileResourceIds: data-resource-ids on [data-files-wrapper="${t}"] is not a JSON array. Got: ${r}`);return o}function Co(e,t,n,r,o){var a,i;const l="minCount"in n&&(a=n.minCount)!=null?a:0,s="maxCount"in n&&(i=n.maxCount)!=null?i:1/0;n.required&&t.length===0&&o.push(`${e}: ${k("required",r)}`),t.length<l&&o.push(`${e}: ${k("minFiles",r,{min:l})}`),t.length>s&&o.push(`${e}: ${k("maxFiles",r,{max:s})}`)}function Ln(e,t,n,r,o){var a,i;const l="accept"in n?n.accept:void 0,s=Ae(l),u=_e(l);if(s.length===0&&u.length===0)return;const d=s.join(", "),c=u.join(", ");for(const p of t){const f=r.resourceIndex.get(p),m=(a=f==null?void 0:f.name)!=null?a:p;if(s.length>0&&!Be(m,s)){o.push(`${e}: ${k("invalidFileExtension",r,{name:m,formats:d})}`);continue}if(u.length>0&&!(f!=null&&f.inferredFromExtension)){const b=(i=f==null?void 0:f.type)!=null?i:"";Ke(b,u)||o.push(`${e}: ${k("invalidFileMime",r,{name:m,type:b,mimes:c})}`)}}}function Sn(e,t,n,r,o){var a;const i="maxSize"in n&&(a=n.maxSize)!=null?a:1/0;if(i!==1/0)for(const l of t){const s=r.resourceIndex.get(l);s&&s.size>i*1024*1024&&o.push(`${e}: ${k("fileTooLarge",r,{name:s.name,maxSize:i})}`)}}function ko(e,t,n){const{scopeRoot:r,skipValidation:o,path:a,state:i}=n,l=[],s=Ce(a,t),u=Eo(r,s);return o||(Co(t,u,e,i,l),Ln(t,u,e,i,l),Sn(t,u,e,i,l)),{value:u,errors:l}}function $o(e,t,n){var r;const{scopeRoot:o,skipValidation:a,state:i}=n,l=[],s=o.querySelector(`input[name$="${t}"][type="hidden"]`),u=(r=s==null?void 0:s.value)!=null?r:"";return!a&&e.required&&u===""?(l.push(`${t}: ${k("required",i)}`),{value:null,errors:l}):(!a&&u!==""&&(Ln(t,[u],e,i,l),Sn(t,[u],e,i,l)),{value:u||null,errors:l})}function Tn(e,t,n){return e.type==="files"||"multiple"in e&&e.multiple?ko(e,t,n):$o(e,t,n)}function Lo(e,t,n,r){const o=t.state,a=t.prefill[e.key],i=typeof a=="string"?a:"";if(i){yt([i],o.resourceIndex);const l=document.createElement("input");l.type="hidden",l.name=r,l.value=i,n.appendChild(l),$t(i,o).then(s=>{s.classList.add("fb-single-readonly-filled","fb-readonly-tile","fb-checker"),n.appendChild(s)}).catch(console.error)}else n.appendChild(So(o))}function So(e){ke();const t=document.createElement("div");return t.style.cssText=`
729
- height: 220px;
730
- display:flex;
731
- align-items:center;
732
- justify-content:center;
733
- background: repeating-linear-gradient(45deg, #fafafa 0 6px, #f3f4f6 6px 12px);
734
- border-radius:0.75rem;
735
- border:1px solid #e2e8f0;
736
- `,t.innerHTML=`<div style="font-size:11px;text-align:center;color:var(--fb-text-secondary-color,#6b7280);">${le(k("noFileSelected",e))}</div>`,t}function An(e,t,n,r,o){yt(e,t.resourceIndex),ke();const a=document.createElement("div");if(a.dataset.filesWrapper=r,a.dataset.resourceIds=JSON.stringify(e),n.appendChild(a),e.length===0){const s=document.createElement("div");s.className="fb-tile-empty-text",s.textContent=k("noFilesSelected",t),a.appendChild(s);return}const i=document.createElement("div");i.className="fb-multi-readonly-grid",a.appendChild(i);const l=e.map(()=>{const s=document.createElement("div");return s.className="fb-readonly-tile fb-checker fb-tile",i.appendChild(s),s});for(let s=0;s<e.length;s++){const u=e[s],d=l[s],c=t.resourceIndex.get(u);$t(u,t,c==null?void 0:c.name).then(p=>{p.classList.add("fb-readonly-tile","fb-checker","fb-tile-resource"),p.dataset.resourceId=u,d.replaceWith(p)}).catch(()=>{const p=document.createElement("div");p.className="fb-readonly-tile fb-checker fb-tile fb-tile-resource",p.dataset.resourceId=u,d.replaceWith(p)})}}function To(e,t,n,r){const o=t.prefill[e.key],a=Array.isArray(o)?o:[];An(a,t.state,n,r)}function Ao(e,t,n,r){const o=t.prefill[e.key],a=Array.isArray(o)?o:[];An(a,t.state,n,r)}function Fo(e,t,n,r){oe(e,t.state,t)?Lo(e,t,n,r):yo(e,t,n,r)}function Mo(e,t,n,r){oe(e,t.state,t)?To(e,t,n,r):xo(e,t,n,r)}function zo(e,t,n,r){oe(e,t.state,t)?Ao(e,t,n,r):wo(e,t,n,r)}function Fn(e,t,n,r){const{scopeRoot:o,state:a}=r;if(e.type==="files"||"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(l=>{l&&typeof l=="string"&&nt(l,a.resourceIndex)});const i=o.querySelector(`[data-files-wrapper="${t}"]`);i?i.dataset.resourceIds=JSON.stringify(n):console.warn(`updateFileField: [data-files-wrapper="${t}"] not found in DOM; data-resource-ids not updated`)}else{const i=o.querySelector(`input[name="${t}"][type="hidden"]`);if(!i){console.warn(`updateFileField: Hidden input not found for file field "${t}"`);return}i.value=n!=null?String(n):"",n&&typeof n=="string"&&(nt(n,a.resourceIndex),console.info(`updateFileField: File field "${t}" updated. Preview update requires re-render.`))}}function De(e){return e?e.toUpperCase():"#000000"}function Tt(e){return/^#[0-9A-F]{6}$/i.test(e)||/^#[0-9A-F]{3}$/i.test(e)}function Mn(e){if(/^#[0-9A-F]{3}$/i.test(e)){const t=e[1],n=e[2],r=e[3];return`#${t}${t}${n}${n}${r}${r}`.toUpperCase()}return e.toUpperCase()}function zn(e){const t=document.createElement("div");t.className="flex items-center gap-2";const n=De(e),r=document.createElement("div");r.style.cssText=`
737
- width: 32px;
738
- height: 32px;
739
- border-radius: var(--fb-border-radius);
740
- border: var(--fb-border-width) solid var(--fb-border-color);
741
- background-color: ${n};
742
- `;const o=document.createElement("span");return o.style.cssText=`
743
- font-size: var(--fb-font-size);
744
- color: var(--fb-text-color);
745
- font-family: var(--fb-font-family-mono, monospace);
746
- `,o.textContent=n,t.appendChild(r),t.appendChild(o),t}function Nn(e,t,n){const r=De(e),o=document.createElement("div");o.className="colour-picker-wrapper",o.style.cssText=`
747
- display: flex;
748
- align-items: center;
749
- gap: 8px;
750
- `;const a=document.createElement("div");a.className="colour-swatch",a.style.cssText=`
751
- width: 40px;
752
- height: 40px;
753
- border-radius: var(--fb-border-radius);
754
- border: var(--fb-border-width) solid var(--fb-border-color);
755
- background-color: ${r};
756
- cursor: pointer;
757
- transition: border-color var(--fb-transition-duration) ease-in-out;
758
- flex-shrink: 0;
759
- `;const i=document.createElement("input");i.type="text",i.className="colour-hex-input",i.name=t,i.value=r,i.placeholder="#000000",i.style.cssText=`
760
- width: 100px;
761
- padding: var(--fb-input-padding-y) var(--fb-input-padding-x);
762
- border: var(--fb-border-width) solid var(--fb-border-color);
763
- border-radius: var(--fb-border-radius);
764
- background-color: var(--fb-background-color);
765
- color: var(--fb-text-color);
766
- font-size: var(--fb-font-size);
767
- font-family: var(--fb-font-family-mono, monospace);
768
- transition: all var(--fb-transition-duration) ease-in-out;
769
- `;const l=document.createElement("input");return l.type="color",l.className="colour-picker-hidden",l.value=r.toLowerCase(),l.style.cssText=`
770
- position: absolute;
771
- opacity: 0;
772
- pointer-events: none;
773
- `,i.addEventListener("input",()=>{const s=i.value.trim();if(Tt(s)){const u=Mn(s);a.style.backgroundColor=u,l.value=u.toLowerCase(),i.classList.remove("invalid"),n.instance&&n.instance.triggerOnChange(t,u)}else i.classList.add("invalid")}),i.addEventListener("blur",()=>{const s=i.value.trim();if(Tt(s)){const u=Mn(s);i.value=u,a.style.backgroundColor=u,l.value=u.toLowerCase(),i.classList.remove("invalid")}}),l.addEventListener("change",()=>{const s=De(l.value);i.value=s,a.style.backgroundColor=s,n.instance&&n.instance.triggerOnChange(t,s)}),a.addEventListener("click",()=>{l.click()}),a.addEventListener("mouseenter",()=>{a.style.borderColor="var(--fb-border-hover-color)"}),a.addEventListener("mouseleave",()=>{a.style.borderColor="var(--fb-border-color)"}),i.addEventListener("focus",()=>{i.style.borderColor="var(--fb-border-focus-color)",i.style.outline="var(--fb-focus-ring-width) solid var(--fb-focus-ring-color)",i.style.outlineOffset="0"}),i.addEventListener("blur",()=>{i.style.borderColor="var(--fb-border-color)",i.style.outline="none"}),i.addEventListener("mouseenter",()=>{document.activeElement!==i&&(i.style.borderColor="var(--fb-border-hover-color)")}),i.addEventListener("mouseleave",()=>{document.activeElement!==i&&(i.style.borderColor="var(--fb-border-color)")}),o.appendChild(a),o.appendChild(i),o.appendChild(l),o}function No(e,t,n,r){const o=t.state,a=oe(e,o,t),i=t.prefill[e.key]||e.default||"#000000";if(a){const l=zn(i);n.appendChild(l)}else{const l=Nn(i,r,t);n.appendChild(l)}if(!a){const l=document.createElement("p");l.className="mt-1",l.style.cssText=`
774
- font-size: var(--fb-font-size-small);
775
- color: var(--fb-text-secondary-color);
776
- `,l.textContent=$e(e,o),n.appendChild(l)}}function qo(e,t,n,r){var o,a;const i=t.state,l=oe(e,i,t),s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],d=(o=e.minCount)!=null?o:1,c=(a=e.maxCount)!=null?a:1/0;for(;u.length<d;)u.push(e.default||"#000000");const p=document.createElement("div");p.className="space-y-2",n.appendChild(p);function f(){p.querySelectorAll(".multiple-colour-item").forEach((h,x)=>{const v=h.querySelector("input");v&&(v.name=`${r}[${x}]`)})}function m(h="#000000",x=-1){const v=document.createElement("div");if(v.className="multiple-colour-item flex items-center gap-2",l){const w=zn(h);for(;w.firstChild;)v.appendChild(w.firstChild)}else{const w=`${r}[${p.children.length}]`,C=Nn(h,w,t);C.style.flex="1",v.appendChild(C)}return x===-1?p.appendChild(v):p.insertBefore(v,p.children[x]),f(),v}function b(){if(l)return;const h=p.querySelectorAll(".multiple-colour-item"),x=h.length;h.forEach(v=>{let w=v.querySelector(".remove-item-btn");w||(w=document.createElement("button"),w.type="button",w.className="remove-item-btn px-2 py-1 rounded",w.style.cssText=`
777
- color: var(--fb-error-color);
778
- background-color: transparent;
779
- transition: background-color var(--fb-transition-duration);
780
- `,w.innerHTML="\u2715",w.addEventListener("mouseenter",()=>{w.style.backgroundColor="var(--fb-background-hover-color)"}),w.addEventListener("mouseleave",()=>{w.style.backgroundColor="transparent"}),w.onclick=()=>{const y=Array.from(p.children).indexOf(v);p.children.length>d&&(u.splice(y,1),v.remove(),f(),E(),b())},v.appendChild(w));const C=x<=d;w.disabled=C,w.style.opacity=C?"0.5":"1",w.style.pointerEvents=C?"none":"auto"})}let g=null;if(!l){const h=Te("colour",()=>{const x=e.default||"#000000";u.push(x),m(x),E(),b()},{label:e.addLabel});g=h.update,Le(n,h.counter),n.appendChild(h.row)}function E(){g&&g(u.length,c)}if(u.forEach(h=>m(h)),E(),b(),!l){const h=document.createElement("p");h.className="mt-1",h.style.cssText=`
781
- font-size: var(--fb-font-size-small);
782
- color: var(--fb-text-secondary-color);
783
- `,h.textContent=$e(e,i),n.appendChild(h)}}function Io(e,t,n){var r,o,a;const i=[],{scopeRoot:l,skipValidation:s}=n,u=(c,p)=>{var f,m;if(!c)return;const b=`error-${c.getAttribute("name")||Math.random().toString(36).substring(7)}`;let g=document.getElementById(b);p?(c.classList.add("invalid"),c.title=p,g||(g=document.createElement("div"),g.id=b,g.className="error-message",g.style.cssText=`
784
- color: var(--fb-error-color);
785
- font-size: var(--fb-font-size-small);
786
- margin-top: 0.25rem;
787
- `,c.nextSibling?(f=c.parentNode)==null||f.insertBefore(g,c.nextSibling):(m=c.parentNode)==null||m.appendChild(g)),g.textContent=p,g.style.display="block"):(c.classList.remove("invalid"),c.title="",g&&g.remove())},d=(c,p,f)=>{const{state:m}=n;if(!p){if(!s&&e.required){const g=k("required",m);return i.push(`${f}: ${g}`),u(c,g),""}return u(c,null),""}const b=De(p);if(!s&&!Tt(b)){const g=k("invalidHexColour",m);return i.push(`${f}: ${g}`),u(c,g),p}return u(c,null),b};if(e.multiple){const c=l.querySelectorAll(`[name^="${t}["].colour-hex-input`),p=[];if(c.forEach((f,m)=>{var b;const g=(b=f==null?void 0:f.value)!=null?b:"",E=d(f,g,`${t}[${m}]`);p.push(E)}),!s){const{state:f}=n,m=(r=e.minCount)!=null?r:1,b=(o=e.maxCount)!=null?o:1/0,g=p.filter(E=>E!=="");e.required&&g.length===0&&i.push(`${t}: ${k("required",f)}`),g.length<m&&i.push(`${t}: ${k("minItems",f,{min:m})}`),g.length>b&&i.push(`${t}: ${k("maxItems",f,{max:b})}`)}return{value:p,errors:i}}else{const c=l.querySelector(`[name="${t}"].colour-hex-input`),p=(a=c==null?void 0:c.value)!=null?a:"";if(!s&&e.required&&p===""){const f=k("required",n.state);return i.push(`${t}: ${f}`),u(c,f),{value:"",errors:i}}return{value:d(c,p,t),errors:i}}}function Ro(e,t,n,r){const{scopeRoot:o}=r;if(e.multiple){if(!Array.isArray(n)){console.warn(`updateColourField: Expected array for multiple field "${t}", got ${typeof n}`);return}const a=o.querySelectorAll(`[name^="${t}["].colour-hex-input`);a.forEach((i,l)=>{if(l<n.length){const s=De(n[l]);i.value=s,i.classList.remove("invalid"),i.title="";const u=i.closest(".colour-picker-wrapper");if(u){const d=u.querySelector(".colour-swatch"),c=u.querySelector(".colour-picker-hidden");d&&(d.style.backgroundColor=s),c&&(c.value=s.toLowerCase())}}}),n.length!==a.length&&console.warn(`updateColourField: Multiple field "${t}" has ${a.length} inputs but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const a=o.querySelector(`[name="${t}"].colour-hex-input`);if(a){const i=De(n);a.value=i,a.classList.remove("invalid"),a.title="";const l=a.closest(".colour-picker-wrapper");if(l){const s=l.querySelector(".colour-swatch"),u=l.querySelector(".colour-picker-hidden");s&&(s.style.backgroundColor=i),u&&(u.value=i.toLowerCase())}}}}function qn(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const r=Math.log(t),o=Math.log(n);return Math.exp(r+e*(o-r))}function At(e,t,n){if(t<=0)throw new Error("Exponential scale requires min > 0");const r=Math.log(t),o=Math.log(n);return(Math.log(e)-r)/(o-r)}function at(e,t){return Math.round(e/t)*t}function In(e,t,n,r,o){var a;const i=document.createElement("div");i.className="slider-container";const l=document.createElement("div");l.className="flex items-start gap-3";const s=document.createElement("div");s.className="flex-1";const u=document.createElement("input");u.type="range",u.name=t,u.className="slider-input w-full",u.disabled=o;const d=n.scale||"linear",c=n.min,p=n.max,f=(a=n.step)!=null?a:1;if(d==="exponential"){if(c<=0)throw new Error(`Slider "${n.key}": exponential scale requires min > 0 (got ${c})`);u.min="0",u.max="1000",u.step="1";const h=At(e,c,p);u.value=(h*1e3).toString()}else u.min=c.toString(),u.max=p.toString(),u.step=f.toString(),u.value=e.toString();u.style.cssText=`
788
- height: 6px;
789
- border-radius: 3px;
790
- background: linear-gradient(
791
- to right,
792
- var(--fb-primary-color) 0%,
793
- var(--fb-primary-color) ${(e-c)/(p-c)*100}%,
794
- var(--fb-border-color) ${(e-c)/(p-c)*100}%,
795
- var(--fb-border-color) 100%
796
- );
797
- outline: none;
798
- transition: background 0.1s ease-in-out;
799
- cursor: ${o?"not-allowed":"pointer"};
800
- opacity: ${o?"0.6":"1"};
801
- `,s.appendChild(u);const m=document.createElement("div");m.className="flex justify-between",m.style.cssText=`
802
- font-size: var(--fb-font-size-small);
803
- color: var(--fb-text-secondary-color);
804
- margin-top: 4px;
805
- `;const b=document.createElement("span");b.textContent=c.toString();const g=document.createElement("span");g.textContent=p.toString(),m.appendChild(b),m.appendChild(g),s.appendChild(m);const E=document.createElement("span");if(E.className="slider-value",E.style.cssText=`
806
- min-width: 60px;
807
- text-align: right;
808
- font-size: var(--fb-font-size);
809
- color: var(--fb-text-color);
810
- font-family: var(--fb-font-family-mono, monospace);
811
- font-weight: 500;
812
- padding-top: 2px;
813
- `,E.textContent=e.toFixed(f<1?2:0),l.appendChild(s),l.appendChild(E),i.appendChild(l),!o){const h=()=>{let x;if(d==="exponential"){const w=parseFloat(u.value)/1e3;x=qn(w,c,p),x=at(x,f),x=Math.max(c,Math.min(p,x))}else x=parseFloat(u.value),x=at(x,f);E.textContent=x.toFixed(f<1?2:0);const v=(x-c)/(p-c)*100;u.style.background=`linear-gradient(
814
- to right,
815
- var(--fb-primary-color) 0%,
816
- var(--fb-primary-color) ${v}%,
817
- var(--fb-border-color) ${v}%,
818
- var(--fb-border-color) 100%
819
- )`,r.instance&&r.instance.triggerOnChange(t,x)};u.addEventListener("input",h),u.addEventListener("change",h)}return i}function Ho(e,t,n,r){var o;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 a=t.state,i=oe(e,a,t),l=e.default!==void 0?e.default:(e.min+e.max)/2,s=(o=t.prefill[e.key])!=null?o:l,u=In(s,r,e,t,i);if(n.appendChild(u),!i){const d=document.createElement("p");d.className="mt-1",d.style.cssText=`
820
- font-size: var(--fb-font-size-small);
821
- color: var(--fb-text-secondary-color);
822
- `,d.textContent=$e(e,a),n.appendChild(d)}}function Bo(e,t,n,r){var o,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 i=t.state,l=oe(e,i,t),s=t.prefill[e.key]||[],u=Array.isArray(s)?[...s]:[],d=(o=e.minCount)!=null?o:1,c=(a=e.maxCount)!=null?a:1/0,p=e.default!==void 0?e.default:(e.min+e.max)/2;for(;u.length<d;)u.push(p);const f=document.createElement("div");f.className="space-y-3",n.appendChild(f);function m(){f.querySelectorAll(".multiple-slider-item").forEach((x,v)=>{const w=x.querySelector("input[type=range]");w&&w.setAttribute("name",`${r}[${v}]`)})}function b(x=p,v=-1){const w=document.createElement("div");w.className="multiple-slider-item flex items-start gap-2";const C=`${r}[${f.children.length}]`,y=In(x,C,e,t,l);return y.style.flex="1",w.appendChild(y),v===-1?f.appendChild(w):f.insertBefore(w,f.children[v]),m(),w}function g(){if(l)return;const x=f.querySelectorAll(".multiple-slider-item"),v=x.length;x.forEach(w=>{let C=w.querySelector(".remove-item-btn");C||(C=document.createElement("button"),C.type="button",C.className="remove-item-btn px-2 py-1 rounded",C.style.cssText=`
823
- color: var(--fb-error-color);
824
- background-color: transparent;
825
- transition: background-color var(--fb-transition-duration);
826
- margin-top: 8px;
827
- `,C.innerHTML="\u2715",C.addEventListener("mouseenter",()=>{C.style.backgroundColor="var(--fb-background-hover-color)"}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"}),C.onclick=()=>{const L=Array.from(f.children).indexOf(w);f.children.length>d&&(u.splice(L,1),w.remove(),m(),h(),g())},w.appendChild(C));const y=v<=d;C.disabled=y,C.style.opacity=y?"0.5":"1",C.style.pointerEvents=y?"none":"auto"})}let E=null;if(!l){const x=Te("slider",()=>{u.push(p),b(p),h(),g()},{label:e.addLabel});E=x.update,Le(n,x.counter),n.appendChild(x.row)}function h(){E&&E(u.length,c)}if(u.forEach(x=>b(x)),h(),g(),!l){const x=document.createElement("p");x.className="mt-1",x.style.cssText=`
828
- font-size: var(--fb-font-size-small);
829
- color: var(--fb-text-secondary-color);
830
- `,x.textContent=$e(e,i),n.appendChild(x)}}function Do(e,t,n){var r,o,a;const i=[],{scopeRoot:l,skipValidation:s}=n;if(e.min===void 0||e.min===null)throw new Error(`Slider validation: field "${t}" requires "min" property`);if(e.max===void 0||e.max===null)throw new Error(`Slider validation: field "${t}" requires "max" property`);const u=e.min,d=e.max,c=(r=e.step)!=null?r:1,p=e.scale||"linear",f=(b,g)=>{var E,h;if(!b)return;const x=`error-${b.getAttribute("name")||Math.random().toString(36).substring(7)}`;let v=document.getElementById(x);if(g){if(b.classList.add("invalid"),b.title=g,!v){v=document.createElement("div"),v.id=x,v.className="error-message",v.style.cssText=`
831
- color: var(--fb-error-color);
832
- font-size: var(--fb-font-size-small);
833
- margin-top: 0.25rem;
834
- `;const w=b.closest(".slider-container");w&&w.nextSibling?(E=w.parentNode)==null||E.insertBefore(v,w.nextSibling):w&&((h=w.parentNode)==null||h.appendChild(v))}v.textContent=g,v.style.display="block"}else b.classList.remove("invalid"),b.title="",v&&v.remove()},m=(b,g)=>{const{state:E}=n,h=b.value;if(!h){if(!s&&e.required){const v=k("required",E);return i.push(`${g}: ${v}`),f(b,v),null}return f(b,null),null}let x;if(p==="exponential"){const v=parseFloat(h)/1e3;x=qn(v,u,d),x=at(x,c)}else x=parseFloat(h),x=at(x,c);if(!s){if(x<u){const v=k("minValue",E,{min:u});return i.push(`${g}: ${v}`),f(b,v),x}if(x>d){const v=k("maxValue",E,{max:d});return i.push(`${g}: ${v}`),f(b,v),x}}return f(b,null),x};if(e.multiple){const b=l.querySelectorAll(`input[type="range"][name^="${t}["]`),g=[];if(b.forEach((E,h)=>{const x=m(E,`${t}[${h}]`);g.push(x)}),!s){const{state:E}=n,h=(o=e.minCount)!=null?o:1,x=(a=e.maxCount)!=null?a:1/0,v=g.filter(w=>w!==null);e.required&&v.length===0&&i.push(`${t}: ${k("required",E)}`),v.length<h&&i.push(`${t}: ${k("minItems",E,{min:h})}`),v.length>x&&i.push(`${t}: ${k("maxItems",E,{max:x})}`)}return{value:g,errors:i}}else{const b=l.querySelector(`input[type="range"][name="${t}"]`);return b?{value:m(b,t),errors:i}:(!s&&e.required&&i.push(`${t}: ${k("required",n.state)}`),{value:null,errors:i})}}function jo(e,t,n,r){var o;const{scopeRoot:a}=r,i=e.min,l=e.max,s=(o=e.step)!=null?o: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=a.querySelectorAll(`input[type="range"][name^="${t}["]`);d.forEach((c,p)=>{if(p<n.length&&n[p]!==null){const f=Number(n[p]);if(u==="exponential"){const b=At(f,i,l);c.value=(b*1e3).toString()}else c.value=f.toString();const m=c.closest(".slider-container");if(m){const b=m.querySelector(".slider-value");b&&(b.textContent=f.toFixed(s<1?2:0));const g=(f-i)/(l-i)*100;c.style.background=`linear-gradient(
835
- to right,
836
- var(--fb-primary-color) 0%,
837
- var(--fb-primary-color) ${g}%,
838
- var(--fb-border-color) ${g}%,
839
- var(--fb-border-color) 100%
840
- )`}c.classList.remove("invalid"),c.title=""}}),n.length!==d.length&&console.warn(`updateSliderField: Multiple field "${t}" has ${d.length} sliders but received ${n.length} values. Consider re-rendering for add/remove.`)}else{const d=a.querySelector(`input[type="range"][name="${t}"]`);if(d&&n!==null&&n!==void 0){const c=Number(n);if(u==="exponential"){const f=At(c,i,l);d.value=(f*1e3).toString()}else d.value=c.toString();const p=d.closest(".slider-container");if(p){const f=p.querySelector(".slider-value");f&&(f.textContent=c.toFixed(s<1?2:0));const m=(c-i)/(l-i)*100;d.style.background=`linear-gradient(
841
- to right,
842
- var(--fb-primary-color) 0%,
843
- var(--fb-primary-color) ${m}%,
844
- var(--fb-border-color) ${m}%,
845
- var(--fb-border-color) 100%
846
- )`}d.classList.remove("invalid"),d.title=""}}}function Rn(e){const t={};for(const n of e)n.key&&"default"in n&&n.default!==void 0&&(t[n.key]=n.default);return t}function Hn(e,t){return{...t,...e}}function Ft(e){const t={};return e.querySelectorAll("input, select, textarea").forEach(n=>{const r=n.getAttribute("name");r&&!r.includes("[")&&!r.includes(".")&&(n instanceof HTMLSelectElement?t[r]=n.value:n instanceof HTMLInputElement?n.type==="checkbox"?t[r]=n.checked:n.type==="radio"?n.checked&&(t[r]=n.value):t[r]=n.value:n instanceof HTMLTextAreaElement&&(t[r]=n.value))}),t}let Mt=null;function Oo(e){Mt=e}function st(e,t){if(!Mt)throw new Error("renderElement not initialized. Import from components/index.ts");return Mt(e,t)}function Bn(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-2",e.prefillHints.forEach((r,o)=>{const a=document.createElement("button");a.type="button",a.className="fb-prefill-hint",a.textContent=r.label,a.setAttribute("data-hint-values",JSON.stringify(r.values)),a.setAttribute("data-container-key",t),a.setAttribute("data-hint-index",String(o)),n.appendChild(a)}),n}function Dn(e,t,n,r){var o,a;const i=document.createElement("div");i.className="border border-gray-200 rounded-lg p-2 bg-gray-50",i.setAttribute("data-container",r);const l=document.createElement("div"),s=e.columns||1;s===1?l.className="space-y-2":l.className=`grid grid-cols-${s} gap-2`;const u=oe(e,t.state,t);if(!u){const m=Bn(e,r);m&&i.appendChild(m)}const d=Rn(e.elements),c=((o=t.prefill)==null?void 0:o[e.key])||{},p=Hn(c,d),f={path:Ce(t.path,e.key),prefill:p,formData:(a=t.formData)!=null?a:t.prefill,state:t.state,inheritedReadonly:u||t.inheritedReadonly};e.elements.forEach(m=>{var b,g;if(m.type!=="markdown"&&(m.hidden||m.type==="hidden")){const E=(g=(b=c[m.key])!=null?b:"default"in m?m.default:null)!=null?g:null;l.appendChild(We(Ce(f.path,m.key),E))}else l.appendChild(st(m,f))}),i.appendChild(l),n.appendChild(i)}function Uo(e,t){if(e)return"space-y-2";const n=t||1;return n===1?"space-y-2":`grid grid-cols-${n} gap-2`}function zt(e,t){const n=document.createElement("button");n.type="button",n.className="fb-item-remove",n.style.cssText=`
847
- width: 22px;
848
- height: 22px;
849
- display: inline-flex;
850
- align-items: center;
851
- justify-content: center;
852
- padding: 0;
853
- line-height: 1;
854
- font-size: 14px;
855
- color: var(--fb-error-color);
856
- background-color: transparent;
857
- border: 0;
858
- border-radius: 4px;
859
- cursor: pointer;
860
- flex-shrink: 0;
861
- transition: background-color var(--fb-transition-duration);
862
- `,n.textContent="\u2715",n.addEventListener("mouseenter",()=>{n.style.backgroundColor="var(--fb-background-hover-color)"}),n.addEventListener("mouseleave",()=>{n.style.backgroundColor="transparent"}),n.onclick=t;const r=e.querySelector("[data-fb-label-row]");if(r){n.style.marginLeft="auto",r.appendChild(n);return}n.style.position="absolute",n.style.top="8px",n.style.right="8px",e.style.position="relative",e.appendChild(n)}function jn(e,t,n,r){var o,a,i,l;const s=t.state,u=oe(e,s,t),d=u||t.inheritedReadonly,c=document.createElement("div");c.className="border border-gray-200 rounded-lg p-2 bg-gray-50";const p=document.createElement("div"),f=e.displayMode==="slides";if(f){p.className="fb-container-slides";const q=e.columns,W=typeof q=="number"&&q>0?`repeat(${q}, 1fr)`:"repeat(auto-fit, minmax(280px, 1fr))";p.style.cssText=`display:grid;grid-template-columns:${W};gap:8px;align-items:start;`}else p.className="space-y-2";if(!u){const q=Bn(e,e.key);q&&c.appendChild(q)}const m=(o=e.minCount)!=null?o:0,b=(a=e.maxCount)!=null?a:1/0,g=Array.isArray((i=t.prefill)==null?void 0:i[e.key])?t.prefill[e.key]:null,E=Rn(e.elements),h=()=>p.querySelectorAll(":scope > .containerItem").length,x=()=>{if(h()>=b)return;const q=h(),W=s.formRoot?Ft(s.formRoot):{},K={state:t.state,path:Ce(t.path,`${e.key}[${q}]`),prefill:E,formData:W,inheritedReadonly:d},Y=document.createElement("div");Y.className="containerItem border border-gray-300 rounded-lg p-2 bg-white",Y.setAttribute("data-container-item",`${e.key}[${q}]`);const Q=document.createElement("div");Q.className=Uo(f,e.columns),e.elements.forEach(ie=>{var ae;ie.type!=="markdown"&&(ie.hidden||ie.type==="hidden")?Q.appendChild(We(Ce(K.path,ie.key),(ae="default"in ie?ie.default:null)!=null?ae:null)):Q.appendChild(st(ie,K))}),Y.appendChild(Q),u||zt(Y,()=>R(Y)),v&&v.parentElement===p?p.insertBefore(Y,v):p.appendChild(Y),L()};let v=null,w=null,C=null;const y=()=>{if(!v)return;const q=p.querySelector(":scope > .containerItem");q&&q.offsetHeight>0&&(v.style.minHeight=`${q.offsetHeight}px`)},L=()=>{const q=h();w&&w(q,b),C&&C(q,b),v&&y()},R=q=>{q.remove(),L()};if(g&&Array.isArray(g)&&g.forEach((q,W)=>{var K;const Y=Hn(q||{},E),Q={state:t.state,path:Ce(t.path,`${e.key}[${W}]`),prefill:Y,formData:(K=t.formData)!=null?K:t.prefill,inheritedReadonly:d},ie=document.createElement("div");ie.className="containerItem border border-gray-300 rounded-lg p-2 bg-white",ie.setAttribute("data-container-item",`${e.key}[${W}]`);const ae=document.createElement("div");if(f)ae.className="space-y-2";else{const fe=e.columns||1;fe===1?ae.className="space-y-2":ae.className=`grid grid-cols-${fe} gap-2`}e.elements.forEach(fe=>{var ze,xe;if(fe.type!=="markdown"&&(fe.hidden||fe.type==="hidden")){const Pe=(xe=(ze=q==null?void 0:q[fe.key])!=null?ze:"default"in fe?fe.default:null)!=null?xe:null;ae.appendChild(We(Ce(Q.path,fe.key),Pe))}else ae.appendChild(st(fe,Q))}),ie.appendChild(ae),u||zt(ie,()=>R(ie)),p.appendChild(ie)}),!u)for(;h()<m;){const q=h(),W={state:t.state,path:Ce(t.path,`${e.key}[${q}]`),prefill:E,formData:(l=t.formData)!=null?l:t.prefill,inheritedReadonly:d},K=document.createElement("div");K.className="containerItem border border-gray-300 rounded-lg p-2 bg-white",K.setAttribute("data-container-item",`${e.key}[${q}]`);const Y=document.createElement("div");if(f)Y.className="space-y-2";else{const Q=e.columns||1;Q===1?Y.className="space-y-2":Y.className=`grid grid-cols-${Q} gap-2`}e.elements.forEach(Q=>{var ie;Q.type!=="markdown"&&(Q.hidden||Q.type==="hidden")?Y.appendChild(We(Ce(W.path,Q.key),(ie="default"in Q?Q.default:null)!=null?ie:null)):Y.appendChild(st(Q,W))}),K.appendChild(Y),zt(K,()=>{h()>m&&R(K)}),p.appendChild(K)}if(c.appendChild(p),!u)if(f){p.style.alignItems="stretch";const q=br(x,{label:e.addLabel});v=q.tile,w=q.update,Le(n,q.counter),p.appendChild(q.tile)}else{const q=Te("container",x,{label:e.addLabel});C=q.update,Le(n,q.counter),c.appendChild(q.row)}L(),n.appendChild(c),v&&(typeof requestAnimationFrame=="function"?requestAnimationFrame(y):y())}let Nt=null;function Po(e){Nt=e}function On(e,t,n){if(!Nt)throw new Error("validateElement not initialized. Should be set from FormBuilderInstance");return Nt(e,t,n)}function Un(e,t,n){const r=[],{scopeRoot:o,skipValidation:a,path:i}=n;if(!("elements"in e))return{value:null,errors:r};const l=(s,u,d)=>{var c,p;if(a)return;const{state:f}=n,m="minCount"in d&&(c=d.minCount)!=null?c:0,b="maxCount"in d&&(p=d.maxCount)!=null?p:1/0;d.required&&u.length===0&&r.push(`${s}: ${k("required",f)}`),u.length<m&&r.push(`${s}: ${k("minItems",f,{min:m})}`),u.length>b&&r.push(`${s}: ${k("maxItems",f,{max:b})}`)};if("multiple"in e&&e.multiple){const s=[],u=o.querySelectorAll("[data-container-item]");return Array.from(u).filter(d=>{const c=d.getAttribute("data-container-item")||"";if(!c.startsWith(`${t}[`))return!1;const p=c.slice(t.length);return/^\[\d+\]$/.test(p)}).forEach(d=>{const c={},p=(d.getAttribute("data-container-item")||"").match(/\[(\d+)\]$/),f=p?parseInt(p[1],10):0;e.elements.forEach(m=>{var b;if(m.enableIf)try{const h=(b=n.instance)!=null&&b.getState().formRoot?Ft(n.instance.getState().formRoot):{};if(!He(m.enableIf,h,c))return}catch(h){console.error(`Error evaluating enableIf for field "${m.key}" in container "${t}[${f}]":`,h)}const g=`${t}[${f}].${m.key}`,E=On({...m,key:g},{path:i},d);E.spread&&E.value!==null&&typeof E.value=="object"?Object.assign(c,E.value):c[m.key]=E.value}),s.push(c)}),l(t,s,e),{value:s,errors:r}}else{const s={},u=o.querySelector(`[data-container="${t}"]`)||o;return e.elements.forEach(d=>{var c;if(d.enableIf)try{const p=(c=n.instance)!=null&&c.getState().formRoot?Ft(n.instance.getState().formRoot):{};if(!He(d.enableIf,p,s))return}catch(p){console.error(`Error evaluating enableIf for field "${d.key}" in container "${t}":`,p)}{const p=`${t}.${d.key}`,f=On({...d,key:p},{path:i},u);f.spread&&f.value!==null&&typeof f.value=="object"?Object.assign(s,f.value):s[d.key]=f.value}}),{value:s,errors:r}}}function Pn(e,t,n,r){const{instance:o,scopeRoot:a}=r;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((l,s)=>{Ze(l)&&e.elements.forEach(u=>{var d,c;if(u.type==="markdown"||!u.key)return;const p=`${t}[${s}].${u.key}`;if(u.type==="richinput"&&u.flatOutput){const f=u,m=(d=f.textKey)!=null?d:"text",b=(c=f.filesKey)!=null?c:"files",g=l,E={};m in g&&(E[m]=g[m]),b in g&&(E[b]=g[b]),Object.keys(E).length>0&&o.updateField(p,E)}else{const f=l[u.key];f!==void 0&&o.updateField(p,f)}})});const i=a.querySelectorAll(`[data-container-item^="${t}["]`);n.length!==i.length&&console.warn(`updateContainerField: Multiple container field "${t}" item count mismatch. Consider re-rendering for add/remove.`)}else{if(!Ze(n)){console.warn(`updateContainerField: Expected object for container field "${t}", got ${typeof n}`);return}e.elements.forEach(i=>{var l,s;if(i.type==="markdown"||!i.key)return;const u=`${t}.${i.key}`;if(i.type==="richinput"&&i.flatOutput){const d=i,c=(l=d.textKey)!=null?l:"text",p=(s=d.filesKey)!=null?s:"files",f=n,m={};c in f&&(m[c]=f[c]),p in f&&(m[p]=f[p]),Object.keys(m).length>0&&o.updateField(u,m)}else{const d=n[i.key];d!==void 0&&o.updateField(u,d)}})}}function Wo(e,t,n,r){var o,a;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 i={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&&Ze(e.repeat)),minCount:(o=e.repeat)==null?void 0:o.min,maxCount:(a=e.repeat)==null?void 0:a.max};i.multiple?jn(i,t,n):Dn(i,t,n,r)}function Wn(e){var t,n;const r=e;return{type:"container",key:r.key,label:r.label,description:r.description,hint:r.hint,required:r.required,hidden:r.hidden,default:r.default,actions:r.actions,elements:r.elements,multiple:!!(r.repeat&&Ze(r.repeat)),minCount:(t=r.repeat)==null?void 0:t.min,maxCount:(n=r.repeat)==null?void 0:n.max}}function Vo(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 r=Wn(e);return Un(r,t,n)}function _o(e,t,n,r){typeof console!="undefined"&&console.warn&&console.warn(`[Form Builder] The "group" field type is deprecated. Please use type: "container" instead. Field path: "${t}"`);const o=Wn(e);return Pn(o,t,n,r)}function Ko(e){return e!==null&&typeof e=="object"&&"row"in e&&"col"in e&&"rowspan"in e&&"colspan"in e}function Jo(e){if(e===null||typeof e!="object")return!1;const t=e;return typeof t.top=="number"&&typeof t.left=="number"&&typeof t.bottom=="number"&&typeof t.right=="number"}function Yo(e){return Ko(e)?{top:e.row,left:e.col,bottom:e.row+e.rowspan-1,right:e.col+e.colspan-1}:Jo(e)?e:null}function je(e){return e.map(Yo).filter(t=>t!==null)}function Vn(e,t){return Array.from({length:e},()=>Array.from({length:t},()=>""))}function qt(e,t,n){for(let r=0;r<e.length;r++){const o=e[r];if(o.top<0||o.left<0||o.bottom>=t||o.right>=n||o.top>o.bottom||o.left>o.right)return`Merge ${r} out of bounds`;for(let a=r+1;a<e.length;a++){const i=e[a];if(o.top<=i.bottom&&o.bottom>=i.top&&o.left<=i.right&&o.right>=i.left)return`Merges ${r} and ${a} overlap`}}return null}function _n(e,t,n){for(const r of n){if(r.top===e&&r.left===t)return null;if(e>=r.top&&e<=r.bottom&&t>=r.left&&t<=r.right)return r}return null}function ut(e,t,n){var r;return(r=n.find(o=>o.top===e&&o.left===t))!=null?r:null}function Me(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 Oe(e){const t=document.createElement("button");return t.type="button",t.textContent=e.label,t.title=e.title,t.style.cssText=`
863
- position: absolute;
864
- width: ${e.size}px;
865
- height: ${e.size}px;
866
- border-radius: 50%;
867
- border: none;
868
- background: ${e.color};
869
- color: ${e.textColor};
870
- font-size: ${Math.floor(e.size*.6)}px;
871
- line-height: ${e.size}px;
872
- text-align: center;
873
- cursor: pointer;
874
- z-index: 10;
875
- padding: 0;
876
- display: flex;
877
- align-items: center;
878
- justify-content: center;
879
- box-shadow: 0 1px 4px rgba(0,0,0,0.2);
880
- transition: transform 0.1s, opacity 0.1s;
881
- pointer-events: all;
882
- `,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 Go(e,t){const{cells:n,merges:r=[]}=e;if(n.length===0)return;const o=n[0].length,a=document.createElement("table");a.style.cssText=`
883
- width: 100%;
884
- border-collapse: collapse;
885
- border: var(--fb-border-width) solid var(--fb-border-color);
886
- border-radius: var(--fb-border-radius);
887
- font-size: var(--fb-font-size);
888
- font-family: var(--fb-font-family);
889
- color: var(--fb-text-color);
890
- `,n.forEach((l,s)=>{var u,d;const c=(s===0?a.createTHead():(u=a.tBodies[0])!=null?u:a.createTBody()).insertRow();for(let p=0;p<o;p++){if(_n(s,p,r))continue;const f=ut(s,p,r),m=document.createElement(s===0?"th":"td");if(f){const b=f.bottom-f.top+1,g=f.right-f.left+1;b>1&&(m.rowSpan=b),g>1&&(m.colSpan=g)}m.textContent=(d=l[p])!=null?d:"",m.style.cssText=`
891
- padding: 6px 10px;
892
- border: var(--fb-border-width) solid var(--fb-border-color);
893
- text-align: left;
894
- vertical-align: top;
895
- ${s===0?"background-color: var(--fb-background-hover-color); font-weight: 600;":""}
896
- `,c.appendChild(m)}});const i=document.createElement("div");i.style.cssText="overflow-x: auto; max-width: 100%;",i.appendChild(a),t.appendChild(i)}function Xo(e,t,n,r,o,a){if(e.contentEditable==="true")return;e.contentEditable="true",e.focus();const i=document.createRange(),l=window.getSelection();i.selectNodeContents(e),i.collapse(!1),l==null||l.removeAllRanges(),l==null||l.addRange(i);function s(){var c;e.contentEditable="inherit";const p=r();p[t]&&(p[t][n]=(c=e.textContent)!=null?c:""),o()}function u(c){var p,f,m,b;const g=r(),E=(f=(p=g[0])==null?void 0:p.length)!=null?f:0;if(c.key==="Escape"){e.contentEditable="inherit",e.textContent=(b=(m=g[t])==null?void 0:m[n])!=null?b:"",e.removeEventListener("keydown",u),e.removeEventListener("blur",d);return}if(c.key==="Enter"&&!c.shiftKey){c.preventDefault(),c.stopPropagation(),s(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d);const h=t+1<g.length?t+1:t;a(h,n);return}if(c.key==="Tab"){c.preventDefault(),c.stopPropagation(),s(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d);let h=t,x=c.shiftKey?n-1:n+1;x<0&&(x=E-1,h=Math.max(0,t-1)),x>=E&&(x=0,h=Math.min(g.length-1,t+1)),a(h,x)}}function d(){e.contentEditable==="true"&&(s(),e.removeEventListener("keydown",u),e.removeEventListener("blur",d))}e.addEventListener("keydown",u),e.addEventListener("blur",d)}function Zo(){if(document.getElementById("fb-spin-keyframes"))return;const e=document.createElement("style");e.id="fb-spin-keyframes",e.textContent="@keyframes fb-spin { to { transform: rotate(360deg); } }",document.head.appendChild(e)}function Qo(e,t){Zo();const n=document.createElement("div");n.className="fb-table-loading-overlay",n.style.cssText=`
897
- position: absolute; top: 0; left: 0; right: 0; bottom: 0;
898
- background: rgba(255,255,255,0.8); display: flex;
899
- align-items: center; justify-content: center; flex-direction: column;
900
- gap: 8px; z-index: 100;
901
- `;const r=document.createElement("div");r.style.cssText=`
902
- width: 24px; height: 24px; border: 3px solid var(--fb-border-color, #ccc);
903
- border-top-color: var(--fb-primary-color, #0066cc); border-radius: 50%;
904
- animation: fb-spin 0.8s linear infinite;
905
- `;const o=document.createElement("span");return o.textContent=t,o.style.cssText="font-size: var(--fb-font-size-small, 12px); color: var(--fb-text-color, #333);",n.appendChild(r),n.appendChild(o),e.appendChild(n),n}function el(e,t,n,r,o){var a,i,l,s,u,d,c,p;const f=r.state,m=r.instance,b=e.mergeAllowed!==!1,g=(i=(a=e.fieldNames)==null?void 0:a.cells)!=null?i:"cells",E=(s=(l=e.fieldNames)==null?void 0:l.merges)!=null?s:"merges",h=t.cells.length>0?t.cells.map(A=>[...A]):Vn((u=e.rows)!=null?u:3,(d=e.columns)!=null?d:3);let x=t.merges?[...t.merges]:[];const v={anchor:null,focus:null,dragging:!1},w=document.createElement("input");w.type="hidden",w.name=n,w.value=JSON.stringify({[g]:h,[E]:x}),o.appendChild(w);function C(){w.value=JSON.stringify({[g]:h,[E]:x}),m&&m.triggerOnChange(n,{[g]:h,[E]:x})}w._applyExternalUpdate=A=>{h.length=0,A.cells.forEach(T=>h.push([...T])),x.length=0,A.merges&&A.merges.forEach(T=>x.push({...T})),v.anchor=null,v.focus=null,C(),M()};const y=document.createElement("div");y.style.cssText="position: relative; padding: 20px 20px 20px 24px; overflow-x: auto; max-width: 100%;";const L=document.createElement("table");L.style.cssText=`
906
- border-collapse: collapse;
907
- font-size: var(--fb-font-size);
908
- font-family: var(--fb-font-family);
909
- color: var(--fb-text-color);
910
- table-layout: fixed;
911
- `,y.appendChild(L);const R=(p=(c=e.importAccept)==null?void 0:c.map(A=>`.${A.toLowerCase()}`))!=null?p:[];async function q(A){var T,S,B;if(!f.config.parseTableFile)return;if(R.length>0){const F=A.name.toLowerCase().replace(/^.*(\.[^.]+)$/,"$1");if(!R.includes(F))return}const D=Qo(y,k("tableImporting",f));try{const F=await f.config.parseTableFile(A),ee=F.cells,O=(T=F.merges)!=null?T:[];if(O.length>0){const U=qt(O,ee.length,(B=(S=ee[0])==null?void 0:S.length)!=null?B:0);if(U)throw new Error(U)}h.length=0,ee.forEach(U=>h.push([...U])),x.length=0,O.forEach(U=>x.push({...U})),v.anchor=null,v.focus=null,C(),M()}catch(F){const ee=F instanceof Error?F.message:String(F);console.error(k("tableImportError",f).replace("{error}",ee))}finally{D.remove()}}if(e.importAccept&&f.config.parseTableFile){const A=document.createElement("button");A.type="button",A.title=k("tableImportFile",f),A.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.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/></svg>',A.style.cssText=`
912
- position: absolute; top: 2px; left: 2px;
913
- width: 20px; height: 20px;
914
- padding: 0;
915
- display: flex; align-items: center; justify-content: center;
916
- color: var(--fb-text-color, #999);
917
- border: none;
918
- background: transparent;
919
- cursor: pointer;
920
- z-index: 2;
921
- `,A.addEventListener("mouseenter",()=>{A.style.color="var(--fb-primary-color, #0066cc)"}),A.addEventListener("mouseleave",()=>{A.style.color="var(--fb-text-color, #999)"});const T=document.createElement("input");T.type="file",T.accept=R.join(","),T.style.display="none",y.appendChild(T),A.addEventListener("click",()=>{T.click()}),T.addEventListener("change",()=>{var B;const D=(B=T.files)==null?void 0:B[0];D&&q(D),T.value=""}),y.appendChild(A);let S=0;y.addEventListener("dragenter",B=>{B.preventDefault(),S++,S===1&&(y.style.outline="2px dashed var(--fb-primary-color, #0066cc)",y.style.outlineOffset="-2px")}),y.addEventListener("dragover",B=>{B.preventDefault(),B.dataTransfer&&(B.dataTransfer.dropEffect="copy")}),y.addEventListener("dragleave",B=>{B.preventDefault(),S--,S<=0&&(S=0,y.style.outline="",y.style.outlineOffset="")}),y.addEventListener("drop",B=>{var D,F;B.preventDefault(),S=0,y.style.outline="",y.style.outlineOffset="";const ee=(F=(D=B.dataTransfer)==null?void 0:D.files)==null?void 0:F[0];ee&&q(ee)})}o.appendChild(y);const W=document.createElement("div");W.style.cssText=`
922
- position: fixed;
923
- display: none;
924
- background: white;
925
- border: 1px solid var(--fb-border-color);
926
- border-radius: var(--fb-border-radius);
927
- box-shadow: 0 2px 8px rgba(0,0,0,0.15);
928
- padding: 4px;
929
- z-index: 1000;
930
- gap: 4px;
931
- flex-direction: column;
932
- `,o.appendChild(W);function K(A,T){const S=document.createElement("button");return S.type="button",S.textContent=A,S.style.cssText=`
933
- padding: 4px 10px;
934
- font-size: var(--fb-font-size-small);
935
- color: var(--fb-text-color);
936
- border: 1px solid var(--fb-border-color);
937
- border-radius: var(--fb-border-radius);
938
- background: transparent;
939
- cursor: pointer;
940
- white-space: nowrap;
941
- text-align: left;
942
- `,S.addEventListener("mouseenter",()=>{S.style.background="var(--fb-background-hover-color)"}),S.addEventListener("mouseleave",()=>{S.style.background="transparent"}),S.addEventListener("click",()=>{Q(),T()}),S}function Y(A,T){if(!b)return;W.innerHTML="",W.style.display="flex";const S=Me(v),B=S&&(S.r1!==S.r2||S.c1!==S.c2),D=v.anchor&&ut(v.anchor.row,v.anchor.col,x);if(B&&W.appendChild(K(k("tableMergeCells",f),N)),D&&W.appendChild(K(k("tableSplitCell",f),z)),!W.firstChild){Q();return}const F=140,ee=W.children.length*32+8,O=window.innerWidth,U=window.innerHeight,V=A+F>O?A-F:A,G=T+ee>U?T-ee:T;W.style.left=`${V}px`,W.style.top=`${G}px`}function Q(){W.style.display="none"}const ie=new AbortController;document.addEventListener("mousedown",A=>{if(!o.isConnected){ie.abort();return}W.contains(A.target)||Q()},{signal:ie.signal});function ae(){const A=Me(v);L.querySelectorAll("td[data-row]").forEach(T=>{const S=parseInt(T.getAttribute("data-row")||"0",10),B=parseInt(T.getAttribute("data-col")||"0",10),D=v.anchor!==null&&v.anchor.row===S&&v.anchor.col===B,F=A!==null&&S>=A.r1&&S<=A.r2&&B>=A.c1&&B<=A.c2;T.style.outline=D?"2px solid var(--fb-primary-color, #0066cc)":"",T.style.outlineOffset=D?"-2px":"",S===0?T.style.backgroundColor="var(--fb-background-hover-color)":T.style.backgroundColor=F&&!D?"rgba(0,102,204,0.08)":""})}function fe(A,T){v.anchor={row:A,col:T},v.focus=null,ae(),L.focus()}function ze(A,T){const S=L.querySelector(`td[data-row="${A}"][data-col="${T}"]`);if(!S)return;const B=S.querySelector("span");B&&(v.anchor={row:A,col:T},v.focus=null,ae(),Xo(B,A,T,()=>h,C,fe))}function xe(A){var T;const S=h.length>0?h[0].length:(T=e.columns)!=null?T:3,B=Array(S).fill(""),D=A!==void 0?A+1:h.length;h.splice(D,0,B),x=x.map(F=>F.top>=D?{...F,top:F.top+1,bottom:F.bottom+1}:F.top<D&&F.bottom>=D?{...F,bottom:F.bottom+1}:F),C(),M()}function Pe(A){if(h.length<=1)return;const T=A!==void 0?A:v.anchor?v.anchor.row:h.length-1;x=x.map(S=>S.top===T&&S.bottom===T?null:S.top===T?{...S,bottom:S.bottom-1}:S.bottom===T?{...S,bottom:S.bottom-1}:S.top<T&&S.bottom>T?{...S,bottom:S.bottom-1}:S.top>T?{...S,top:S.top-1,bottom:S.bottom-1}:S).filter(S=>S!==null),h.splice(T,1),v.anchor&&v.anchor.row>=h.length&&(v.anchor={row:h.length-1,col:v.anchor.col}),C(),M()}function Ge(A){var T,S;const B=A!==void 0?A+1:(S=(T=h[0])==null?void 0:T.length)!=null?S:0;h.forEach(D=>D.splice(B,0,"")),x=x.map(D=>D.left>=B?{...D,left:D.left+1,right:D.right+1}:D.left<B&&D.right>=B?{...D,right:D.right+1}:D),C(),M()}function $(A){if(h.length===0||h[0].length<=1)return;const T=A!==void 0?A:v.anchor?v.anchor.col:h[0].length-1;x=x.map(S=>S.left===T&&S.right===T?null:S.left===T?{...S,right:S.right-1}:S.right===T?{...S,right:S.right-1}:S.left<T&&S.right>T?{...S,right:S.right-1}:S.left>T?{...S,left:S.left-1,right:S.right-1}:S).filter(S=>S!==null),h.forEach(S=>S.splice(T,1)),v.anchor&&v.anchor.col>=h[0].length&&(v.anchor={row:v.anchor.row,col:h[0].length-1}),C(),M()}function N(){var A,T;if(!b)return;const S=Me(v);if(!S)return;const{r1:B,c1:D,r2:F,c2:ee}=S;if(B===F&&D===ee)return;x=x.filter(j=>!(j.top<=F&&j.bottom>=B&&j.left<=ee&&j.right>=D));const O=h[B][D];for(let j=B;j<=F;j++)for(let X=D;X<=ee;X++)(j!==B||X!==D)&&(h[j][X]="");h[B][D]=O;const U={top:B,left:D,bottom:F,right:ee},V=[...x,U],G=qt(V,h.length,(T=(A=h[0])==null?void 0:A.length)!=null?T:0);if(G){console.warn("Merge validation failed:",G);return}x.push(U),v.anchor={row:B,col:D},v.focus=null,C(),M()}function z(){if(!b||!v.anchor)return;const{row:A,col:T}=v.anchor,S=x.findIndex(B=>B.top===A&&B.left===T);S!==-1&&(x.splice(S,1),v.focus=null,C(),M())}function M(){var A,T;L.innerHTML="";const S=h.length,B=S>0?h[0].length:0,D=Me(v);for(let F=0;F<S;F++){const ee=(F===0?(A=L.tHead)!=null?A:L.createTHead():(T=L.tBodies[0])!=null?T:L.createTBody()).insertRow();for(let O=0;O<B;O++){if(_n(F,O,x))continue;const U=ut(F,O,x),V=document.createElement("td");if(V.setAttribute("data-row",String(F)),V.setAttribute("data-col",String(O)),U){const Z=U.bottom-U.top+1,_=U.right-U.left+1;Z>1&&(V.rowSpan=Z),_>1&&(V.colSpan=_)}const G=D!==null&&F>=D.r1&&F<=D.r2&&O>=D.c1&&O<=D.c2,j=v.anchor!==null&&v.anchor.row===F&&v.anchor.col===O;V.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;":"",G&&!j?"background-color: rgba(0,102,204,0.08);":"",j?"outline: 2px solid var(--fb-primary-color, #0066cc); outline-offset: -2px;":""].join(" ");const X=document.createElement("span");X.textContent=h[F][O],X.style.cssText="display: block; min-height: 1.4em; white-space: pre-wrap; word-break: break-word; outline: none;",V.appendChild(X);const J=F,re=O;V.addEventListener("mousedown",Z=>{if(Z.target.tagName!=="BUTTON"&&Z.target.contentEditable!=="true"){if(Z.button===2){const _=Me(v);if(_&&J>=_.r1&&J<=_.r2&&re>=_.c1&&re<=_.c2)return}Z.shiftKey&&v.anchor?(Z.preventDefault(),v.focus={row:J,col:re},v.dragging=!1,ae()):(v.anchor={row:J,col:re},v.focus=null,v.dragging=!0,ae())}}),V.addEventListener("mouseup",Z=>{if(Z.target.tagName!=="BUTTON"&&v.dragging){v.dragging=!1;const _=Me(v);(!_||_.r1===_.r2&&_.c1===_.c2)&&ze(J,re)}}),V.addEventListener("mousemove",Z=>{if(v.dragging&&Z.buttons===1){const _=v.anchor;_&&(_.row!==J||_.col!==re)&&(v.focus={row:J,col:re},ae())}}),V.addEventListener("contextmenu",Z=>{if(!b)return;const _=Me(v),pe=_&&(_.r1!==_.r2||_.c1!==_.c2),de=v.anchor&&ut(v.anchor.row,v.anchor.col,x);(pe||de)&&(Z.preventDefault(),Y(Z.clientX,Z.clientY))}),ee.appendChild(V)}}he(),L.setAttribute("tabindex","0"),L.onkeydown=F=>{var ee,O;if(L.querySelector("[contenteditable='true']"))return;const U=v.anchor;if(!U)return;const V=h.length,G=V>0?h[0].length:0,j={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};if(j[F.key]){F.preventDefault();const[X,J]=j[F.key],re=Math.max(0,Math.min(V-1,U.row+X)),Z=Math.max(0,Math.min(G-1,U.col+J));F.shiftKey?(v.focus={row:re,col:Z},ae()):fe(re,Z);return}if(F.key==="Enter"){F.preventDefault(),ze(U.row,U.col);return}if(F.key==="Tab"){F.preventDefault();const X=(O=(ee=h[0])==null?void 0:ee.length)!=null?O:0;let J=U.row,re=F.shiftKey?U.col-1:U.col+1;re<0&&(re=X-1,J=Math.max(0,J-1)),re>=X&&(re=0,J=Math.min(h.length-1,J+1)),fe(J,re);return}if(b&&F.key==="m"&&F.ctrlKey&&!F.shiftKey){F.preventDefault(),N();return}b&&F.key==="M"&&F.ctrlKey&&F.shiftKey&&(F.preventDefault(),z())},L.oncopy=F=>{var ee,O,U,V;const G=Me(v);if(!G)return;F.preventDefault();const{r1:j,c1:X,r2:J,c2:re}=G,Z=[],_=[];for(let P=j;P<=J;P++){const ce=[],be=[];for(let ve=X;ve<=re;ve++){const we=(O=(ee=h[P])==null?void 0:ee[ve])!=null?O:"";ce.push(we);const Re=we.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");be.push(`<td>${Re}</td>`)}Z.push(ce.join(" ")),_.push(`<tr>${be.join("")}</tr>`)}const pe=Z.join(`
943
- `),de=`<table>${_.join("")}</table>`;(U=F.clipboardData)==null||U.setData("text/plain",pe),(V=F.clipboardData)==null||V.setData("text/html",de)},L.onpaste=F=>{var ee,O,U,V,G,j,X,J,re;const Z=v.anchor;if(!Z)return;const _=(O=(ee=F.clipboardData)==null?void 0:ee.getData("text/plain"))!=null?O:"",pe=_.includes(" ")||_.split(/\r?\n/).filter(me=>me).length>1,de=L.querySelector("[contenteditable='true']");if(de&&!pe)return;if(F.preventDefault(),de){de.contentEditable="inherit";const me=parseInt((V=(U=de.closest("td"))==null?void 0:U.getAttribute("data-row"))!=null?V:"0",10),Ne=parseInt((j=(G=de.closest("td"))==null?void 0:G.getAttribute("data-col"))!=null?j:"0",10);h[me]&&(h[me][Ne]=(X=de.textContent)!=null?X:"")}if(!_.trim())return;const P=_.split(/\r?\n/).map(me=>me.split(" "));P.length>1&&P[P.length-1].length===1&&P[P.length-1][0]===""&&P.pop();const ce=Z.row,be=Z.col,ve=ce+P.length;for(;h.length<ve;)h.push(Array((re=(J=h[0])==null?void 0:J.length)!=null?re:1).fill(""));const we=Math.max(...P.map(me=>me.length)),Re=be+we;if(h[0]&&Re>h[0].length){const me=Re-h[0].length;h.forEach(Ne=>{for(let Xe=0;Xe<me;Xe++)Ne.push("")})}for(let me=0;me<P.length;me++)for(let Ne=0;Ne<P[me].length;Ne++){const Xe=ce+me,jl=be+Ne;h[Xe]&&(h[Xe][jl]=P[me][Ne])}C(),M()}}const I=Oe({label:"+",title:k("tableAddColumn",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var A;const T=parseInt((A=I.dataset.afterCol)!=null?A:"0",10);Ge(T)}});I.style.position="absolute",I.style.display="none",y.appendChild(I);const H=Oe({label:"+",title:k("tableAddRow",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>{var A;const T=parseInt((A=H.dataset.afterRow)!=null?A:"0",10);xe(T)}});H.style.position="absolute",H.style.display="none",y.appendChild(H);let te=[],ne=[];const ue=Oe({label:"+",title:k("tableAddColumn",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>Ge()});ue.style.position="absolute",ue.style.display="none",y.appendChild(ue);const se=Oe({label:"+",title:k("tableAddRow",f),size:20,color:"var(--fb-primary-color, #0066cc)",textColor:"white",onClick:()=>xe()});se.style.position="absolute",se.style.display="none",y.appendChild(se);function he(){var A,T;te.forEach(O=>O.remove()),te=[],ne.forEach(O=>O.remove()),ne=[];const S=h.length>0?h[0].length:0,B=h.length;if(S>1){const O=Array.from(L.querySelectorAll("thead td[data-col]"));for(const U of O){const V=parseInt((A=U.getAttribute("data-col"))!=null?A:"0",10),G=Oe({label:"\xD7",title:k("tableRemoveColumn",f),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>$(V)});G.setAttribute("data-action","remove-col"),G.setAttribute("data-col",String(V)),G.style.position="absolute",G.style.display="none",y.appendChild(G),te.push(G)}}if(B>1){const O=[...L.tHead?Array.from(L.tHead.rows):[],...L.tBodies[0]?Array.from(L.tBodies[0].rows):[]].filter(U=>U.querySelector("td[data-row]"));for(const U of O){const V=U.querySelector("td[data-row]");if(!V)continue;const G=parseInt((T=V.getAttribute("data-row"))!=null?T:"0",10),j=Oe({label:"\xD7",title:k("tableRemoveRow",f),size:16,color:"var(--fb-error-color, #dc3545)",textColor:"white",onClick:()=>Pe(G)});j.setAttribute("data-action","remove-row"),j.setAttribute("data-row",String(G)),j.style.position="absolute",j.style.display="none",y.appendChild(j),ne.push(j)}}function D(O,U,V,G,j){var X;const J=j?Array.from(L.querySelectorAll("thead td[data-col]")):[];let re=-1,Z=1/0,_=-1,pe=-1,de=1/0;for(let P=0;P<J.length;P++){const ce=J[P].getBoundingClientRect(),be=(ce.left+ce.right)/2,ve=Math.abs(O-be);ve<Z&&(Z=ve,re=P);const we=Math.abs(O-ce.right);we<de&&we<20&&(de=we,_=ce.right-U.left+G,pe=parseInt((X=J[P].getAttribute("data-col"))!=null?X:"0",10))}te.forEach((P,ce)=>{if(!j||ce!==re){P.style.display="none";return}const be=J[ce].getBoundingClientRect(),ve=(be.left+be.right)/2-U.left+G;P.style.left=`${ve-8}px`,P.style.top="2px",P.style.display="flex"}),j&&pe>=0?(I.style.display="flex",I.style.left=`${_-10}px`,I.style.top=`${V.top-U.top-10}px`,I.dataset.afterCol=String(pe)):I.style.display="none"}function F(O,U,V,G,j){var X;const J=[];if(j){if(L.tHead)for(const P of Array.from(L.tHead.rows))P.querySelector("td[data-row]")&&J.push(P);if(L.tBodies[0])for(const P of Array.from(L.tBodies[0].rows))P.querySelector("td[data-row]")&&J.push(P)}let re=-1,Z=1/0,_=-1,pe=-1,de=1/0;for(let P=0;P<J.length;P++){const ce=J[P].getBoundingClientRect(),be=(ce.top+ce.bottom)/2,ve=Math.abs(O-be);ve<Z&&(Z=ve,re=P);const we=Math.abs(O-ce.bottom);if(we<de&&we<14){de=we,_=ce.bottom-U.top;const Re=J[P].querySelector("td[data-row]");pe=parseInt((X=Re==null?void 0:Re.getAttribute("data-row"))!=null?X:"0",10)}}ne.forEach((P,ce)=>{if(!j||ce!==re){P.style.display="none";return}const be=J[ce].getBoundingClientRect(),ve=(be.top+be.bottom)/2-U.top;P.style.left="4px",P.style.top=`${ve-8}px`,P.style.display="flex"}),j&&pe>=0?(H.style.display="flex",H.style.top=`${_-10}px`,H.style.left=`${V.left-U.left+G-10}px`,H.dataset.afterRow=String(pe)):H.style.display="none"}let ee=!1;y.onmousemove=O=>{const U=O.target;if(U.tagName==="BUTTON"&&U.parentElement===y||ee)return;ee=!0;const V=O.clientX,G=O.clientY;requestAnimationFrame(()=>{ee=!1;const j=y.getBoundingClientRect(),X=L.getBoundingClientRect(),J=y.scrollLeft,re=G>=j.top&&G<X.top+4,Z=V>=j.left&&V<X.left+4,_=Math.min(X.right,j.right),pe=V>_-20&&V<=j.right,de=G>X.bottom-4&&G<=j.bottom+20;if(D(V,j,X,J,re),F(G,j,X,J,Z),ue.style.display=pe?"flex":"none",pe&&(ue.style.left=`${j.right-j.left+J-20}px`,ue.style.top=`${(X.top+X.bottom)/2-j.top-10}px`),se.style.display=de?"flex":"none",de){const P=(j.left+j.right)/2-j.left+J;se.style.left=`${P-10}px`,se.style.top=`${X.bottom-j.top-10}px`}})},y.onmouseleave=()=>{te.forEach(O=>{O.style.display="none"}),ne.forEach(O=>{O.style.display="none"}),I.style.display="none",H.style.display="none",ue.style.display="none",se.style.display="none"}}M()}function tl(e){var t,n;return{cells:Vn((t=e.rows)!=null?t:3,(n=e.columns)!=null?n:3),merges:[]}}function It(e){return e!==null&&typeof e=="object"&&"cells"in e&&Array.isArray(e.cells)}function Rt(e,t){return e!==null&&typeof e=="object"&&t in e&&Array.isArray(e[t])}function nl(e,t,n,r){var o,a,i,l;const s=t.state,u=oe(e,s,t),d=t.prefill[e.key],c=(a=(o=e.fieldNames)==null?void 0:o.cells)!=null?a:"cells",p=(l=(i=e.fieldNames)==null?void 0:i.merges)!=null?l:"merges";let f;if(It(d))f={cells:d.cells,merges:d.merges?je(d.merges):[]};else if(d&&Rt(d,c)){const m=d[p];f={cells:d[c],merges:m?je(m):[]}}else if(It(e.default))f={cells:e.default.cells,merges:e.default.merges?je(e.default.merges):[]};else if(e.default&&Rt(e.default,c)){const m=e.default[p];f={cells:e.default[c],merges:m?je(m):[]}}else f=tl(e);if(f.merges&&f.merges.length>0){const m=f.cells.length,b=m>0?f.cells[0].length:0,g=qt(f.merges,m,b);g&&(console.warn(`Table "${e.key}": invalid prefill merges stripped (${g})`),f={...f,merges:[]})}u?Go(f,n):el(e,f,r,t,n)}function rl(e,t,n){var r,o;const{scopeRoot:a,skipValidation:i}=n,l=[],s=(o=(r=e.fieldNames)==null?void 0:r.cells)!=null?o:"cells",u=a.querySelector(`[name="${t}"]`);if(!u)return{value:null,errors:l};let d=null;try{d=JSON.parse(u.value)}catch(c){return l.push(`${t}: invalid table data`),{value:null,errors:l}}if(!i&&e.required){const c=d[s];c!=null&&c.some(p=>p.some(f=>f.trim()!==""))||l.push(`${t}: ${k("required",n.state)}`)}return{value:d,errors:l}}function ol(e,t,n,r){var o,a,i,l;const{scopeRoot:s}=r,u=(a=(o=e.fieldNames)==null?void 0:o.cells)!=null?a:"cells",d=(l=(i=e.fieldNames)==null?void 0:i.merges)!=null?l:"merges",c=s.querySelector(`[name="${t}"]`);if(!c){console.warn(`updateTableField: no hidden input found for "${t}". Re-render to reflect new data.`);return}let p=null;if(It(n))p={cells:n.cells,merges:n.merges?je(n.merges):[]};else if(n&&Rt(n,u)){const f=n[d];p={cells:n[u],merges:f?je(f):[]}}p&&c._applyExternalUpdate?c._applyExternalUpdate(p):c.value=JSON.stringify(n)}function ll(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 r=()=>{e.isConnected&&(e.style.height="0",e.style.height=`${e.scrollHeight}px`,t&&(t.style.height=`${e.scrollHeight}px`))};e.addEventListener("input",r),setTimeout(()=>{e.isConnected&&r()},0)}function Ht(e,t){var n,r,o,a;const i=new Map,l=new Map;for(const s of e){const u=t.resourceIndex.get(s),d=(n=u==null?void 0:u.name)!=null?n:s;l.set(d,((r=l.get(d))!=null?r:0)+1)}for(const s of e){const u=t.resourceIndex.get(s),d=(o=u==null?void 0:u.name)!=null?o:s;((a=l.get(d))!=null?a:1)>1&&u?i.set(s,`${d} (${mr(u.size)})`):i.set(s,d)}return i}function Bt(e){return e?e.type.startsWith("image/"):!1}function Kn(e,t){const n=Ht(e,t),r=new Map;for(const o of e){const a=n.get(o);a&&r.set(a,o)}return r}function Dt(e){return/\s/.test(e)||e.includes('"')?`@"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`@${e}`}function ct(e){const t=[],n=e.length;let r=0;for(;r<n;)if(e[r]==="@"){if(r>0&&!/\s/.test(e[r-1])){r++;continue}const o=r;if(r++,r<n&&e[r]==='"'){r++;let a="";for(;r<n&&e[r]!=='"';)e[r]==="\\"&&r+1<n?(a+=e[r+1],r+=2):(a+=e[r],r++);r<n&&e[r]==='"'&&(r++,(r>=n||/\s/.test(e[r]))&&t.push({start:o,end:r,raw:e.slice(o,r),name:a}))}else if(r<n&&!/\s/.test(e[r])){const a=r;for(;r<n&&!/\s/.test(e[r]);)r++;const i=e.slice(a,r);t.push({start:o,end:r,raw:e.slice(o,r),name:i})}}else r++;return t}function il(e,t){if(t.size===0)return[];const n=ct(e),r=[];for(const o of n){const a=t.get(o.name);a&&r.push({start:o.start,end:o.end,name:o.name,rid:a})}return r}function al(e,t){const n=il(e,t);if(n.length===0)return e;let r="",o=0;for(const a of n)r+=e.slice(o,a.start),r+=`@${a.rid}`,o=a.end;return r+=e.slice(o),r}function Jn(e,t,n){const r=Ht(t,n),o=new Map;for(const s of t){const u=r.get(s);u&&o.set(s,u)}const a=ct(e);if(a.length===0)return e;let i="",l=0;for(const s of a){i+=e.slice(l,s.start);const u=o.get(s.name);u?i+=Dt(u):i+=s.raw,l=s.end}return i+=e.slice(l),i}function Yn(e,t,n,r){if(ge(e),n!=null&&n.file&&Bt(n)){const o=document.createElement("img");o.alt=n.name,o.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const a=new FileReader;a.onload=i=>{var l;o.src=((l=i.target)==null?void 0:l.result)||""},a.readAsDataURL(n.file),e.appendChild(o)}else if(r.config.getThumbnail){r.config.getThumbnail(t).then(a=>{var i;if(!a||!e.isConnected)return;const l=document.createElement("img");l.alt=(i=n==null?void 0:n.name)!=null?i:t,l.src=a,l.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",ge(e),e.appendChild(l)}).catch(a=>{var i,l;(l=(i=r.config).onThumbnailError)==null||l.call(i,a,t)});const o=document.createElement("div");o.style.cssText="width: 100%; height: 100%; background: var(--fb-background-hover-color, #f3f4f6); display: flex; align-items: center; justify-content: center;",o.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(o)}else{const o=document.createElement("div");if(o.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;",o.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 a=document.createElement("span");a.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);",a.textContent=n.name,o.appendChild(a)}e.appendChild(o)}}function Gn(e,t,n,r){if(ge(e),n!=null&&n.file&&Bt(n)){const o=document.createElement("img");o.alt=n.name,o.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;";const a=new FileReader;a.onload=i=>{var l;o.src=((l=i.target)==null?void 0:l.result)||""},a.readAsDataURL(n.file),e.appendChild(o)}else r.config.getThumbnail&&r.config.getThumbnail(t).then(o=>{var a;if(!o||!e.isConnected)return;const i=document.createElement("img");i.alt=(a=n==null?void 0:n.name)!=null?a:t,i.src=o,i.style.cssText="max-width: 120px; max-height: 120px; object-fit: contain; display: block;",ge(e),e.appendChild(i)}).catch(o=>{var a,i;(i=(a=r.config).onThumbnailError)==null||i.call(a,o,t)})}function Xn(e,t){const n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),o=Math.max(4,Math.min(n.left+n.width/2-r.width/2,window.innerWidth-r.width-4)),a=n.top-r.height-8,i=n.bottom+8,l=a>=4?a:i;e.style.left=`${o}px`,e.style.top=`${Math.max(4,l)}px`}function Zn(e,t,n){const r=n.resourceIndex.get(t),o=document.createElement("div");o.className="fb-richinput-portal-tooltip fb-richinput-mention-tooltip",o.style.cssText=`
944
- position: fixed;
945
- z-index: 99999;
946
- background: #fff;
947
- border: 1px solid var(--fb-border-color, #d1d5db);
948
- border-radius: 8px;
949
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
950
- padding: 4px;
951
- pointer-events: none;
952
- min-width: 60px;
953
- max-width: 140px;
954
- `;const a=document.createElement("div");return a.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",Gn(a,t,r,n),o.appendChild(a),document.body.appendChild(o),Xn(o,e),o}function Qn(e,t){var n,r;const{rid:o,state:a,isReadonly:i,onMention:l,onRemove:s}=t,u=a.resourceIndex.get(o),d=(n=u==null?void 0:u.name)!=null?n:o,c=document.createElement("div");c.className="fb-richinput-portal-tooltip fb-richinput-file-tooltip",c.style.cssText=`
955
- position: fixed;
956
- z-index: 99999;
957
- background: #fff;
958
- border: 1px solid var(--fb-border-color, #d1d5db);
959
- border-radius: 8px;
960
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
961
- padding: 4px;
962
- pointer-events: auto;
963
- min-width: 80px;
964
- max-width: 260px;
965
- `;const p=document.createElement("div");p.style.cssText="min-height: 60px; max-height: 120px; display: flex; align-items: center; justify-content: center;",Gn(p,o,u,a),c.appendChild(p);const f=document.createElement("div");f.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);",f.textContent=d,c.appendChild(f);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 b="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=h=>{h.style.background="var(--fb-background-hover-color, #f3f4f6)",h.style.color="var(--fb-text-color, #111827)"},E=h=>{h.style.background="none",h.style.color="var(--fb-text-muted-color, #6b7280)"};if(!i&&l){const h=document.createElement("button");h.type="button",h.title="Mention",h.style.cssText=b,h.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>',h.addEventListener("mouseenter",()=>g(h)),h.addEventListener("mouseleave",()=>E(h)),h.addEventListener("click",x=>{x.stopPropagation(),l(),c.remove()}),m.appendChild(h)}if(a.config.downloadFile){const h=document.createElement("button");h.type="button",h.title="Download",h.style.cssText=b,h.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>',h.addEventListener("mouseenter",()=>g(h)),h.addEventListener("mouseleave",()=>E(h)),h.addEventListener("click",x=>{var v,w;x.stopPropagation(),(w=(v=a.config).downloadFile)==null||w.call(v,o,d)}),m.appendChild(h)}if((r=a.config.getDownloadUrl)!=null?r:a.config.getThumbnail){const h=document.createElement("button");h.type="button",h.title="Open in new window",h.style.cssText=b,h.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>',h.addEventListener("mouseenter",()=>g(h)),h.addEventListener("mouseleave",()=>E(h)),h.addEventListener("click",x=>{var v,w,C,y;if(x.stopPropagation(),a.config.getDownloadUrl){const L=a.config.getDownloadUrl(o);L?window.open(L,"_blank"):(w=(v=a.config).getThumbnail)==null||w.call(v,o).then(R=>{R&&window.open(R,"_blank")}).catch(()=>{})}else(y=(C=a.config).getThumbnail)==null||y.call(C,o).then(L=>{L&&window.open(L,"_blank")}).catch(()=>{})}),m.appendChild(h)}if(!i&&s){const h=document.createElement("button");h.type="button",h.title="Remove",h.style.cssText=b,h.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>',h.addEventListener("mouseenter",()=>{h.style.background="var(--fb-background-hover-color, #f3f4f6)",h.style.color="var(--fb-error-color, #ef4444)"}),h.addEventListener("mouseleave",()=>E(h)),h.addEventListener("click",x=>{x.stopPropagation(),c.remove(),s()}),m.appendChild(h)}return m.children.length>0&&c.appendChild(m),document.body.appendChild(c),Xn(c,e),c}function er(){return{element:null,hideTimer:null}}function dt(e,t=150){e.hideTimer===null&&(e.hideTimer=setTimeout(()=>{e.hideTimer=null,e.element&&(e.element.remove(),e.element=null)},t))}function ft(e){e.hideTimer!==null&&(clearTimeout(e.hideTimer),e.hideTimer=null)}function Ue(e){return e&&e.remove(),null}function sl(e){var t;const n=(t=e.selectionStart)!=null?t:0,r=e.value.slice(0,n);for(let o=r.length-1;o>=0;o--)if(r[o]==="@"){if(o===0||/\s/.test(r[o-1])){let a=r.slice(o+1);return a.startsWith('"')&&(a=a.slice(1)),{query:a,pos:o}}return null}return null}function tr(e,t,n){const r=e.toLowerCase();return t.filter(o=>{var a;return((a=n.get(o))!=null?a:o).toLowerCase().includes(r)})}const pt="font-size: var(--fb-font-size, 14px); font-family: var(--fb-font-family, inherit); line-height: 1.6;",nr="padding: 8px 40px 8px 10px;";function ul(e,t,n,r,o){var a;const i=t.state,l=[...o.files],s={open:!1,query:"",triggerPos:-1,selectedIndex:0},u=new AbortController,d=document.createElement("input");d.type="hidden",d.name=r;function c(){var $,N;const z=y.value,M=Kn(l,i),I=z?al(z,M):null,H=($=e.textKey)!=null?$:"text",te=(N=e.filesKey)!=null?N:"files";return{[H]:z===""?null:I,[te]:[...l]}}function p(){d.value=JSON.stringify(c())}const f=document.createElement("div");f.className="fb-richinput-wrapper",f.style.cssText=`
966
- position: relative;
967
- border: 1px solid var(--fb-border-color, #d1d5db);
968
- border-radius: 16px;
969
- background: var(--fb-background-color, #f9fafb);
970
- transition: box-shadow 0.15s, border-color 0.15s;
971
- `,f.addEventListener("focusin",()=>{f.style.borderColor="var(--fb-primary-color, #0066cc)",f.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),f.addEventListener("focusout",()=>{f.style.borderColor="var(--fb-border-color, #d1d5db)",f.style.boxShadow="none"});const m=document.createElement("div");m.className="fb-richinput-error",m.style.cssText="display: none; color: var(--fb-error-color, #ef4444); font-size: var(--fb-font-size-small, 12px); padding: 4px 10px 6px;";let b=null;function g($){m.textContent=$,m.style.display="block",b&&clearTimeout(b),b=setTimeout(()=>{m.style.display="none",m.textContent="",b=null},5e3)}function E($){var N;const z=Ae(e.accept);if(!Be($.name,z)){const I=z.join(", ");return g(k("invalidFileExtension",i,{name:$.name,formats:I})),!1}const M=(N=e.maxSize)!=null?N:1/0;return tt($,M)?!0:(g(k("fileTooLarge",i,{name:$.name,maxSize:M})),!1)}let h=0;f.addEventListener("dragenter",$=>{$.preventDefault(),h++,f.style.borderColor="var(--fb-primary-color, #0066cc)",f.style.boxShadow="0 0 0 2px color-mix(in srgb, var(--fb-primary-color, #0066cc) 25%, transparent)"}),f.addEventListener("dragover",$=>{$.preventDefault()}),f.addEventListener("dragleave",$=>{$.preventDefault(),h--,h<=0&&(h=0,f.style.borderColor="var(--fb-border-color, #d1d5db)",f.style.boxShadow="none")}),f.addEventListener("drop",$=>{var N,z;$.preventDefault(),h=0,f.style.borderColor="var(--fb-border-color, #d1d5db)",f.style.boxShadow="none";const M=(N=$.dataTransfer)==null?void 0:N.files;if(!M||!i.config.uploadFile)return;const I=(z=e.maxFiles)!=null?z:1/0;for(let H=0;H<M.length;H++){if(l.length>=I){g(k("filesLimitExceeded",i,{skipped:M.length-H,max:I}));break}E(M[H])&&Pe(M[H])}});const x=document.createElement("div");x.className="fb-richinput-files",x.style.cssText="display: none; flex-wrap: wrap; gap: 4px; padding: 6px 10px 0; align-items: center;";const v=document.createElement("input");v.type="file",v.multiple=!0,v.style.display="none",e.accept&&(typeof e.accept=="string"?v.accept=e.accept:v.accept=e.accept.extensions.map($=>$.startsWith(".")?$:`.${$}`).join(","));const w=document.createElement("div");w.style.cssText="position: relative;";const C=document.createElement("div");C.className="fb-richinput-backdrop",C.style.cssText=`
972
- position: absolute;
973
- top: 0; left: 0; right: 0; bottom: 0;
974
- ${nr}
975
- ${pt}
976
- white-space: pre-wrap;
977
- word-break: break-word;
978
- color: transparent;
979
- pointer-events: none;
980
- overflow: hidden;
981
- border-radius: inherit;
982
- box-sizing: border-box;
983
- z-index: 2;
984
- `;const y=document.createElement("textarea");y.name=`${r}__text`,y.placeholder=e.placeholder||k("richinputPlaceholder",i);const L=(a=o.text)!=null?a:"";y.value=L?Jn(L,l,i):"",y.style.cssText=`
985
- width: 100%;
986
- ${nr}
987
- ${pt}
988
- background: transparent;
989
- border: none;
990
- outline: none;
991
- resize: none;
992
- color: var(--fb-text-color, #111827);
993
- box-sizing: border-box;
994
- position: relative;
995
- z-index: 1;
996
- caret-color: var(--fb-text-color, #111827);
997
- `,ll(y,C),y.addEventListener("scroll",()=>{C.scrollTop=y.scrollTop});let R=null;C.addEventListener("mouseover",$=>{var N,z;const M=(z=(N=$.target).closest)==null?void 0:z.call(N,"mark");M!=null&&M.dataset.rid&&(R=Ue(R),R=Zn(M,M.dataset.rid,i))}),C.addEventListener("mouseout",$=>{var N,z,M;if(!((z=(N=$.target).closest)!=null&&z.call(N,"mark")))return;const I=$.relatedTarget;(M=I==null?void 0:I.closest)!=null&&M.call(I,"mark")||(R=Ue(R))}),C.addEventListener("mousedown",$=>{var N,z;if(!((z=(N=$.target).closest)!=null&&z.call(N,"mark")))return;R=Ue(R);const M=C.querySelectorAll("mark");M.forEach(H=>H.style.pointerEvents="none");const I=document.elementFromPoint($.clientX,$.clientY);I&&I.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window,clientX:$.clientX,clientY:$.clientY,button:$.button,buttons:$.buttons,detail:$.detail})),document.addEventListener("mouseup",()=>{M.forEach(H=>H.style.pointerEvents="auto")},{once:!0})});function q(){const $=y.value,N=Kn(l,i),z=ct($);if(z.length===0){C.innerHTML=le($)+`
998
- `;return}let M="",I=0;for(const H of z){M+=le($.slice(I,H.start));const te=N.get(H.name);te?M+=`<mark data-rid="${le(te)}" 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;">${le($.slice(H.start,H.end))}</mark>`:M+=`<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;">${le($.slice(H.start,H.end))}</mark>`,I=H.end}M+=le($.slice(I)),C.innerHTML=M+`
999
- `}const W=document.createElement("button");W.type="button",W.title=k("richinputAttachFile",i),W.style.cssText=`
1000
- position: absolute;
1001
- right: 6px;
1002
- bottom: 6px;
1003
- z-index: 2;
1004
- width: 28px;
1005
- height: 28px;
1006
- border: none;
1007
- border-radius: 6px;
1008
- background: transparent;
1009
- cursor: pointer;
1010
- display: flex;
1011
- align-items: center;
1012
- justify-content: center;
1013
- color: var(--fb-text-muted-color, #9ca3af);
1014
- transition: color 0.15s, background 0.15s;
1015
- `,W.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>',W.addEventListener("mouseenter",()=>{W.style.color="var(--fb-primary-color, #0066cc)",W.style.background="var(--fb-background-hover-color, #f3f4f6)"}),W.addEventListener("mouseleave",()=>{W.style.color="var(--fb-text-muted-color, #9ca3af)",W.style.background="transparent"}),W.addEventListener("click",()=>{var $;const N=($=e.maxFiles)!=null?$:1/0;if(l.length>=N){g(k("filesLimitExceeded",i,{skipped:1,max:N}));return}v.click()});const K=document.createElement("div");K.className="fb-richinput-dropdown",K.style.cssText=`
1016
- display: none;
1017
- position: absolute;
1018
- bottom: 100%;
1019
- left: 0;
1020
- z-index: 1000;
1021
- background: #fff;
1022
- border: 1px solid var(--fb-border-color, #d1d5db);
1023
- border-radius: var(--fb-border-radius, 6px);
1024
- box-shadow: 0 4px 12px rgba(0,0,0,0.12);
1025
- min-width: 180px;
1026
- max-width: 320px;
1027
- max-height: 200px;
1028
- overflow-y: auto;
1029
- margin-bottom: 4px;
1030
- ${pt}
1031
- `;function Y(){return Ht(l,i)}function Q($){ge(K);const N=Y();if($.length===0){K.style.display="none",s.open=!1;return}$.forEach((z,M)=>{var I;const H=i.resourceIndex.get(z),te=document.createElement("div");te.className="fb-richinput-dropdown-item",te.dataset.rid=z,te.style.cssText=`
1032
- padding: 5px 10px;
1033
- cursor: pointer;
1034
- color: var(--fb-text-color, #111827);
1035
- background: ${M===s.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"};
1036
- display: flex;
1037
- align-items: center;
1038
- gap: 8px;
1039
- `;const ne=document.createElement("div");if(ne.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;",H!=null&&H.file&&Bt(H)){const se=document.createElement("img");se.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;";const he=new FileReader;he.onload=A=>{var T;se.src=((T=A.target)==null?void 0:T.result)||""},he.readAsDataURL(H.file),ne.appendChild(se)}else i.config.getThumbnail&&i.config.getThumbnail(z).then(se=>{if(!se||!ne.isConnected)return;const he=document.createElement("img");he.style.cssText="width: 100%; height: 100%; object-fit: cover; display: block;",he.src=se,ge(ne),ne.appendChild(he)}).catch(()=>{}),ne.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>';te.appendChild(ne);const ue=document.createElement("span");ue.style.cssText="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;",ue.textContent=(I=N.get(z))!=null?I:z,te.appendChild(ue),K.appendChild(te)}),K.onmousemove=z=>{var M,I,H;const te=(I=(M=z.target).closest)==null?void 0:I.call(M,".fb-richinput-dropdown-item");if(!te)return;const ne=$.indexOf((H=te.dataset.rid)!=null?H:"");ne===-1||ne===s.selectedIndex||(K.querySelectorAll(".fb-richinput-dropdown-item").forEach((ue,se)=>{ue.style.background=se===ne?"var(--fb-background-hover-color, #f3f4f6)":"transparent"}),s.selectedIndex=ne)},K.onmousedown=z=>{var M,I;z.preventDefault(),z.stopPropagation();const H=(I=(M=z.target).closest)==null?void 0:I.call(M,".fb-richinput-dropdown-item");H!=null&&H.dataset.rid&&fe(H.dataset.rid)},K.style.display="block",s.open=!0}function ie(){const $=sl(y);if(!$){ae();return}s.query=$.query,s.triggerPos=$.pos,s.selectedIndex=0;const N=Y(),z=tr($.query,l,N);Q(z)}function ae(){K.style.display="none",s.open=!1}function fe($){var N,z,M,I;const H=(M=(z=Y().get($))!=null?z:(N=i.resourceIndex.get($))==null?void 0:N.name)!=null?M:$,te=(I=y.selectionStart)!=null?I:0,ne=y.value.slice(0,s.triggerPos),ue=y.value.slice(te),se=`${Dt(H)} `;y.value=`${ne}${se}${ue}`;const he=ne.length+se.length;y.setSelectionRange(he,he),y.dispatchEvent(new Event("input")),ae()}y.addEventListener("input",()=>{var $;q(),p(),($=t.instance)==null||$.triggerOnChange(r,c()),l.length>0?ie():ae()});function ze(){K.querySelectorAll(".fb-richinput-dropdown-item").forEach(($,N)=>{$.style.background=N===s.selectedIndex?"var(--fb-background-hover-color, #f3f4f6)":"transparent"})}y.addEventListener("keydown",$=>{if(!s.open)return;const N=Y(),z=tr(s.query,l,N);$.key==="ArrowDown"?($.preventDefault(),s.selectedIndex=Math.min(s.selectedIndex+1,z.length-1),ze()):$.key==="ArrowUp"?($.preventDefault(),s.selectedIndex=Math.max(s.selectedIndex-1,0),ze()):$.key==="Enter"&&z.length>0?($.preventDefault(),fe(z[s.selectedIndex])):$.key==="Escape"&&ae()}),document.addEventListener("click",$=>{!f.contains($.target)&&!K.contains($.target)&&ae()},{signal:u.signal});function xe(){if(ge(x),l.length===0){x.style.display="none";return}x.style.display="flex",l.forEach($=>{const N=i.resourceIndex.get($),z=document.createElement("div");z.className="fb-richinput-file-thumb",z.style.cssText=`
1040
- position: relative;
1041
- width: 48px;
1042
- height: 48px;
1043
- border: 1px solid var(--fb-border-color, #d1d5db);
1044
- border-radius: 8px;
1045
- overflow: hidden;
1046
- flex-shrink: 0;
1047
- cursor: pointer;
1048
- background: #fff;
1049
- `;const M=document.createElement("div");M.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Yn(M,$,N,i),z.appendChild(M);const I=er(),H=()=>{var ne,ue,se;const he=(ne=y.selectionStart)!=null?ne:y.value.length,A=(se=(ue=Y().get($))!=null?ue:N==null?void 0:N.name)!=null?se:$,T=y.value.slice(0,he),S=y.value.slice(he),B=`${T.length>0&&!/[\s\n]$/.test(T)?`
1050
- `:""}${Dt(A)} `;y.value=`${T}${B}${S}`;const D=he+B.length;y.setSelectionRange(D,D),y.focus(),y.dispatchEvent(new Event("input"))},te=()=>{var ne;const ue=l.indexOf($);ue!==-1&&l.splice(ue,1),xe(),q(),p(),(ne=t.instance)==null||ne.triggerOnChange(r,c())};z.addEventListener("mouseenter",()=>{ft(I),I.element||(I.element=Qn(z,{rid:$,state:i,isReadonly:!1,onMention:H,onRemove:te}),I.element.addEventListener("mouseenter",()=>{ft(I)}),I.element.addEventListener("mouseleave",()=>{dt(I)}))}),z.addEventListener("mouseleave",()=>{dt(I)}),x.appendChild(z)})}function Pe($){if(!i.config.uploadFile)return;const N=`temp-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;i.resourceIndex.set(N,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),l.push(N),xe();const z=x.querySelectorAll(".fb-richinput-file-thumb"),M=z[z.length-1];M&&(M.style.opacity="0.5"),i.config.uploadFile($).then(I=>{var H;const te=l.indexOf(N);te!==-1&&(l[te]=I),i.resourceIndex.delete(N),i.resourceIndex.set(I,{name:$.name,type:$.type,size:$.size,uploadedAt:new Date,file:$}),xe(),q(),p(),(H=t.instance)==null||H.triggerOnChange(r,c())}).catch(I=>{var H,te;const ne=l.indexOf(N);ne!==-1&&l.splice(ne,1),i.resourceIndex.delete(N),xe(),(te=(H=i.config).onUploadError)==null||te.call(H,I,$)})}if(v.addEventListener("change",()=>{var $;const N=v.files;if(!N||N.length===0)return;const z=($=e.maxFiles)!=null?$:1/0;for(let M=0;M<N.length;M++){if(l.length>=z){g(k("filesLimitExceeded",i,{skipped:N.length-M,max:z}));break}E(N[M])&&Pe(N[M])}v.value=""}),w.appendChild(C),w.appendChild(y),w.appendChild(W),w.appendChild(K),f.appendChild(x),f.appendChild(w),f.appendChild(m),e.minLength!=null||e.maxLength!=null){const $=document.createElement("div");$.style.cssText="position: relative; padding: 2px 10px 4px; text-align: right;";const N=Ve(e,y,!1);N.style.cssText=`
1051
- position: static;
1052
- display: inline-block;
1053
- font-size: var(--fb-font-size-small);
1054
- color: var(--fb-text-secondary-color);
1055
- pointer-events: none;
1056
- `,$.appendChild(N),f.appendChild($)}f.appendChild(d),f.appendChild(v),p(),q(),d._applyExternalUpdate=$=>{var N;const z=(N=$.text)!=null?N:"";y.value=z?Jn(z,l,i):"",y.dispatchEvent(new Event("input")),l.length=0;for(const M of $.files)l.push(M);xe(),q(),p()},n.appendChild(f),xe();const Ge=new MutationObserver(()=>{f.isConnected||(u.abort(),R=Ue(R),Ge.disconnect())});f.parentElement&&Ge.observe(f.parentElement,{childList:!0})}function cl(e,t,n,r,o){var a,i;const l=t.state,{text:s,files:u}=o,d=new Map;for(const c of u){const p=l.resourceIndex.get(c);p!=null&&p.name&&d.set(c,p.name)}if(u.length>0){const c=document.createElement("div");c.style.cssText="display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px;",u.forEach(p=>{const f=l.resourceIndex.get(p),m=document.createElement("div");m.style.cssText=`
1057
- position: relative;
1058
- width: 48px; height: 48px;
1059
- border: 1px solid var(--fb-border-color, #d1d5db);
1060
- border-radius: 8px;
1061
- overflow: hidden;
1062
- flex-shrink: 0;
1063
- background: #fff;
1064
- cursor: default;
1065
- `;const b=document.createElement("div");b.style.cssText="width: 48px; height: 48px; border-radius: inherit; overflow: hidden;",Yn(b,p,f,l),m.appendChild(b);const g=er();m.addEventListener("mouseenter",()=>{ft(g),g.element||(g.element=Qn(m,{rid:p,state:l,isReadonly:!0}),g.element.addEventListener("mouseenter",()=>{ft(g)}),g.element.addEventListener("mouseleave",()=>{dt(g)}))}),m.addEventListener("mouseleave",()=>{dt(g)}),c.appendChild(m)}),n.appendChild(c)}if(s){const c=document.createElement("div");c.style.cssText=`
1066
- ${pt}
1067
- color: var(--fb-text-color, #111827);
1068
- white-space: pre-wrap;
1069
- word-break: break-word;
1070
- `;const p=ct(s).filter(f=>d.has(f.name)||[...d.values()].includes(f.name));if(p.length===0)c.textContent=s;else{let f=0;for(const m of p){m.start>f&&c.appendChild(document.createTextNode(s.slice(f,m.start)));const b=document.createElement("span");b.style.cssText=`
1071
- display: inline;
1072
- background: color-mix(in srgb, var(--fb-primary-color, #0066cc) 15%, transparent);
1073
- color: var(--fb-primary-color, #0066cc);
1074
- border-radius: 8px;
1075
- padding: 1px 6px;
1076
- font-weight: 500;
1077
- cursor: default;
1078
- `;const g=d.has(m.name)?m.name:(a=[...d.entries()].find(([,h])=>h===m.name))==null?void 0:a[0],E=(i=d.get(m.name))!=null?i:m.name;if(b.textContent=`@${E}`,g){let h=null;const x=g;b.addEventListener("mouseenter",()=>{h=Ue(h),h=Zn(b,x,l)}),b.addEventListener("mouseleave",()=>{h=Ue(h)})}c.appendChild(b),f=m.end}f<s.length&&c.appendChild(document.createTextNode(s.slice(f)))}n.appendChild(c)}if(!s&&u.length===0){const c=document.createElement("div");c.style.cssText="color: var(--fb-text-muted-color, #6b7280); font-size: var(--fb-font-size, 14px);",c.textContent="\u2014",n.appendChild(c)}}function dl(e,t,n,r){var o,a,i,l;const s=t.state,u=oe(e,s,t),d=(o=e.textKey)!=null?o:"text",c=(a=e.filesKey)!=null?a:"files";let p;if(e.flatOutput){const f=t.prefill[d],m=t.prefill[c];p={text:typeof f=="string"?f:null,files:Array.isArray(m)?m:[]}}else{const f=t.prefill[e.key];if(f&&typeof f=="object"&&!Array.isArray(f)){const m=f,b=(i=m[d])!=null?i:m.text,g=(l=m[c])!=null?l:m.files;p={text:typeof b=="string"?b:null,files:Array.isArray(g)?g:[]}}else typeof f=="string"?p={text:f||null,files:[]}:p={text:null,files:[]}}for(const f of p.files)s.resourceIndex.has(f)||s.resourceIndex.set(f,{name:f,type:"application/octet-stream",size:0,uploadedAt:new Date,file:void 0});if(u)cl(e,t,n,r,p);else{if(!s.config.uploadFile)throw new Error(`RichInput field "${e.key}" requires uploadFile handler in config`);ul(e,t,n,r,p)}}function fl(e,t,n){var r,o;const{scopeRoot:a,state:i,skipValidation:l}=n,s=[],u=(r=e.textKey)!=null?r:"text",d=(o=e.filesKey)!=null?o:"files",c=a.querySelector(`[name="${t}"]`);if(!c)return{value:null,errors:s};let p={};try{const h=JSON.parse(c.value);if(h&&typeof h=="object"&&!Array.isArray(h))p=h;else return s.push(`${t}: invalid richinput data`),{value:null,errors:s}}catch(h){return s.push(`${t}: invalid richinput data`),{value:null,errors:s}}const f=p[u],m=p[d],b=f===null||typeof f=="string"?f:null,g=Array.isArray(m)?m:[],E={[u]:b!=null?b:null,[d]:g};if(!l){const h=!b||b.trim()==="",x=g.length===0;e.required&&h&&x&&s.push(`${t}: ${k("required",i)}`),!h&&b&&(e.minLength!=null&&b.length<e.minLength&&s.push(`${t}: ${k("minLength",i,{min:e.minLength})}`),e.maxLength!=null&&b.length>e.maxLength&&s.push(`${t}: ${k("maxLength",i,{max:e.maxLength})}`)),e.maxFiles!=null&&g.length>e.maxFiles&&s.push(`${t}: ${k("maxFiles",i,{max:e.maxFiles})}`)}return{value:E,errors:s,spread:!!e.flatOutput}}function pl(e,t,n,r){var o,a,i,l;const{scopeRoot:s}=r,u=s.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 c=n,p=(o=e.textKey)!=null?o:"text",f=(a=e.filesKey)!=null?a:"files",m=(i=c[p])!=null?i:c.text,b=(l=c[f])!=null?l:c.files;(m!==void 0||b!==void 0)&&(d={text:typeof m=="string"?m:null,files:Array.isArray(b)?b:[]})}d&&u._applyExternalUpdate?u._applyExternalUpdate(d):d&&(u.value=JSON.stringify(d))}const ml={"":["<em>","</em>"],_:["<strong>","</strong>"],"*":["<strong>","</strong>"],"~":["<s>","</s>"],"\n":["<br />"]," ":["<br />"],"-":["<hr />"]};function rr(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function Je(e){return(e+"").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function jt(e,t){const n=/((?:^|\n+)(?:\n---+|\*[ ]\*(?:[ ]\*)+)\n)|(?:^```[ ]*(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t|[ ]{2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|([ ]{2}\n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm,r=[];let o="";const a=t||{};let i=0,l,s,u,d,c;function p(m){const b=ml[m[1]||""],g=r[r.length-1]===m;return b?b[1]?(g?r.pop():r.push(m),b[g?1:0]):b[0]:m}function f(){let m="";for(;r.length;)m+=p(r[r.length-1]);return m}for(e=e.replace(/^\[(.+?)\]:\s*(.+)$/gm,(m,b,g)=>(a[b.toLowerCase()]=g,"")).replace(/^\n+|\n+$/g,"");u=n.exec(e);)s=e.substring(i,u.index),i=n.lastIndex,l=u[0],s.match(/[^\\](\\\\)*\\$/)||((c=u[3]||u[4])?l='<pre class="code '+(u[4]?"poetry":u[2].toLowerCase())+'"><code'+(u[2]?` class="language-${u[2].toLowerCase()}"`:"")+">"+rr(Je(c).replace(/^\n+|\n+$/g,""))+"</code></pre>":(c=u[6])?(c.match(/\./)&&(u[5]=u[5].replace(/^\d+/gm,"")),d=jt(rr(u[5].replace(/^\s*[>*+.-]/gm,""))),c===">"?c="blockquote":(c=c.match(/\./)?"ol":"ul",d=d.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),l="<"+c+">"+d+"</"+c+">"):u[8]?l=`<img src="${Je(u[8])}" alt="${Je(u[7])}">`:u[10]?(o=o.replace("<a>",`<a href="${Je(u[11]||a[s.toLowerCase()])}">`),l=f()+"</a>"):u[9]?l="<a>":u[12]||u[14]?(c="h"+(u[14]?u[14].length:u[13]>"="?1:2),l="<"+c+">"+jt(u[12]||u[15],a)+"</"+c+">"):u[16]?l="<code>"+Je(u[16])+"</code>":(u[17]||u[1])&&(l=p(u[17]||"--"))),o+=s,o+=l;return(o+e.substring(i)+f()).replace(/^\n+|\n+$/g,"")}const or="fb-markdown-styles";function hl(){if(typeof document=="undefined"||document.getElementById(or))return;const e=document.createElement("style");e.id=or,e.setAttribute("data-fb-markdown-styles","true"),e.textContent=`
1079
- .fb-markdown {
1080
- font-family: var(--fb-font-family, inherit);
1081
- font-size: var(--fb-font-size, 1rem);
1082
- color: var(--fb-text-color, #1f2937);
1083
- line-height: 1.6;
1084
- }
1085
- .fb-markdown h1,
1086
- .fb-markdown h2,
1087
- .fb-markdown h3,
1088
- .fb-markdown h4,
1089
- .fb-markdown h5,
1090
- .fb-markdown h6 {
1091
- font-weight: var(--fb-font-weight-medium, 600);
1092
- color: var(--fb-text-color, #1f2937);
1093
- margin-top: 0.75em;
1094
- margin-bottom: 0.25em;
1095
- }
1096
- .fb-markdown h1 { font-size: 1.5rem; }
1097
- .fb-markdown h2 { font-size: 1.25rem; }
1098
- .fb-markdown h3 { font-size: 1.1rem; }
1099
- .fb-markdown h4,
1100
- .fb-markdown h5,
1101
- .fb-markdown h6 { font-size: 1rem; }
1102
- .fb-markdown p {
1103
- margin-top: 0;
1104
- margin-bottom: 0.5em;
1105
- }
1106
- .fb-markdown ul,
1107
- .fb-markdown ol {
1108
- margin: 0.25em 0 0.5em 1.5em;
1109
- padding: 0;
1110
- }
1111
- .fb-markdown li {
1112
- margin-bottom: 0.15em;
1113
- }
1114
- .fb-markdown a {
1115
- color: var(--fb-primary-color, #2563eb);
1116
- text-decoration: underline;
1117
- }
1118
- .fb-markdown a:hover {
1119
- opacity: 0.8;
1120
- }
1121
- .fb-markdown code {
1122
- background: var(--fb-input-background-color, #f3f4f6);
1123
- border-radius: 3px;
1124
- padding: 0.1em 0.35em;
1125
- font-size: 0.9em;
1126
- font-family: monospace;
1127
- }
1128
- .fb-markdown pre {
1129
- background: var(--fb-input-background-color, #f3f4f6);
1130
- border-radius: var(--fb-border-radius, 0.375rem);
1131
- padding: 0.75em 1em;
1132
- overflow-x: auto;
1133
- margin: 0.5em 0;
1134
- }
1135
- .fb-markdown pre code {
1136
- background: none;
1137
- padding: 0;
1138
- border-radius: 0;
1139
- font-size: inherit;
1140
- }
1141
- .fb-markdown blockquote {
1142
- border-left: 3px solid var(--fb-border-color, #d1d5db);
1143
- margin: 0.5em 0;
1144
- padding-left: 1em;
1145
- color: var(--fb-text-secondary-color, #6b7280);
1146
- }
1147
- .fb-markdown hr {
1148
- border: none;
1149
- border-top: 1px solid var(--fb-border-color, #d1d5db);
1150
- margin: 0.75em 0;
1151
- }
1152
- .fb-markdown strong { font-weight: var(--fb-font-weight-medium, 600); }
1153
- .fb-markdown em { font-style: italic; }
1154
- .fb-markdown s { text-decoration: line-through; }
1155
- `,document.head.appendChild(e)}const bl=["javascript:","data:","vbscript:","blob:"],vl=["javascript:","vbscript:","blob:"];function gl(e){return!!(vl.some(t=>e.startsWith(t))||e.startsWith("data:")&&!e.startsWith("data:image/"))}function yl(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function xl(e){e.querySelectorAll("a[href]").forEach(t=>{var n;const r=((n=t.getAttribute("href"))!=null?n:"").trim().toLowerCase();bl.some(o=>r.startsWith(o))&&t.setAttribute("href","#"),t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer")}),e.querySelectorAll("img[src]").forEach(t=>{var n;const r=((n=t.getAttribute("src"))!=null?n:"").trim().toLowerCase();gl(r)&&t.setAttribute("src","")})}function wl(e,t,n){if(typeof e.content!="string")throw new Error(`renderMarkdown: markdown element${e.key?` "${e.key}"`:""} requires "content" to be a string (got ${e.content===null?"null":typeof e.content})`);hl();const r=document.createElement("div");r.className="fb-markdown";const o=yl(e.content);return r.innerHTML=jt(o),xl(r),n.appendChild(r),r}function El(e,t,n){return{value:void 0,errors:[],skip:!0}}function Cl(e,t,n,r){}function kl(e,t){const n=document.getElementById(e);if(!n)return;const r=!n.classList.contains("hidden");if(document.querySelectorAll('[id^="tooltip-"]').forEach(d=>{d.classList.add("hidden")}),r)return;const o=t.getBoundingClientRect(),a=window.innerWidth,i=window.innerHeight;n&&n.parentElement!==document.body&&document.body.appendChild(n),n.style.visibility="hidden",n.style.position="fixed",n.classList.remove("hidden");const l=n.getBoundingClientRect();n.classList.add("hidden"),n.style.visibility="visible";let s=o.left,u=o.bottom+5;s+l.width>a&&(s=o.right-l.width),u+l.height>i&&(u=o.top-l.height-5),s<10&&(s=10),u<10&&(u=o.bottom+5),n.style.left=`${s}px`,n.style.top=`${u}px`,n.classList.remove("hidden"),setTimeout(()=>{n.classList.add("hidden")},25e3)}typeof document!="undefined"&&document.addEventListener("click",e=>{const t=e.target,n=t.closest("button")&&t.closest("button").onclick,r=t.closest('[id^="tooltip-"]');!n&&!r&&document.querySelectorAll('[id^="tooltip-"]').forEach(o=>{o.classList.add("hidden")})});function lr(e,t){var n,r,o;if(!e.enableIf)return!1;try{const a=(r=(n=t.formData)!=null?n:t.prefill)!=null?r:{},i=((o=e.enableIf.scope)!=null?o:"relative")==="relative"&&t.path?t.prefill:void 0;return!He(e.enableIf,a,i)}catch(a){console.error(`Error evaluating enableIf for field "${e.key}":`,a)}return!1}function $l(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 r=t.querySelector(`[name="${e}"]:checked`);return r?r.value:void 0}else return n.value}else if(n instanceof HTMLTextAreaElement)return n.value}}function mt(e,t,n){var r,o;if(!t.enableIf)return;const a=n.state.formRoot;if(!a){console.error("Cannot re-evaluate enableIf: formRoot is null");return}const i=t.enableIf,l=(r=i.scope)!=null?r:"relative";let s={};const u={};if((!n.path||n.path===""?"absolute":l)==="relative"&&n.path){const d=n.path.match(/^(.+)\[(\d+)\]$/);if(d){const c=d[1],p=parseInt(d[2],10),f=a.querySelector(`[data-container-item="${c}[${p}]"]`);f&&f.querySelectorAll("input, select, textarea").forEach(m=>{const b=m.getAttribute("name");if(b){const g=b.match(/\.([^.[\]]+)$/);if(g){const E=g[1];m instanceof HTMLSelectElement?u[E]=m.value:m instanceof HTMLInputElement?m.type==="checkbox"?u[E]=m.checked:m.type==="radio"?m.checked&&(u[E]=m.value):u[E]=m.value:m instanceof HTMLTextAreaElement&&(u[E]=m.value)}}})}}else{const d=i.key,c=$l(d,a);c!==void 0?s[d]=c:s=(o=n.formData)!=null?o:n.prefill}try{He(i,s,u)?(e.style.display="",e.classList.remove("fb-field-wrapper-disabled"),e.removeAttribute("data-conditionally-disabled")):(e.style.display="none",e.classList.add("fb-field-wrapper-disabled"),e.setAttribute("data-conditionally-disabled","true"))}catch(d){console.error(`Error re-evaluating enableIf for field "${t.key}":`,d)}}function ir(e,t,n){var r;if(!t.enableIf)return;const o=n.state.formRoot;if(!o){console.error("Cannot setup enableIf listeners: formRoot is null");return}const a=t.enableIf,i=(r=a.scope)!=null?r:"relative",l=a.key;let s;i==="relative"&&n.path?s=`${n.path}.${l}`:s=l;const u=o.querySelector(`[name="${s}"]`);if(!u){const d=new MutationObserver(()=>{const c=o.querySelector(`[name="${s}"]`);c&&(c.addEventListener("change",()=>{mt(e,t,n)}),c.addEventListener("input",()=>{mt(e,t,n)}),d.disconnect())});d.observe(o,{childList:!0,subtree:!0});return}u.addEventListener("change",()=>{mt(e,t,n)}),u.addEventListener("input",()=>{mt(e,t,n)})}function Ll(e){var t,n;const r=document.createElement("label");if(r.className="text-sm font-medium text-gray-900",r.textContent=(n=(t=e.label)!=null?t:e.key)!=null?n:"",e.required){const o=document.createElement("span");o.className="text-red-500 ml-1",o.textContent="*",r.appendChild(o)}return r}function Sl(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)}`,r=document.createElement("div");return r.id=n,r.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",r.style.position="fixed",r.textContent=e.description||e.hint||"Field information",document.body.appendChild(r),t.onclick=o=>{o.preventDefault(),o.stopPropagation(),kl(n,t)},t}function Tl(e){const t=document.createElement("div");t.className="flex items-center mb-1",t.dataset.fbLabelRow="";const n=Ll(e);if(t.appendChild(n),e.description||e.hint){const r=Sl(e);t.appendChild(r)}return t}function Al(e,t,n,r){const o="multiple"in e&&e.multiple;switch(e.type){case"text":o?gr(e,t,n,r):vr(e,t,n,r);break;case"textarea":o?xr(e,t,n,r):yr(e,t,n,r);break;case"number":o?kr(e,t,n,r):Cr(e,t,n,r);break;case"select":o?Tr(e,t,n,r):Sr(e,t,n,r);break;case"switcher":o?zr(e,t,n,r):Mr(e,t,n,r);break;case"file":o?zo(e,t,n,r):Fo(e,t,n,r);break;case"files":Mo(e,t,n,r);break;case"colour":o?qo(e,t,n,r):No(e,t,n,r);break;case"slider":o?Bo(e,t,n,r):Ho(e,t,n,r);break;case"group":Wo(e,t,n,r);break;case"container":o?jn(e,t,n):Dn(e,t,n,r);break;case"table":nl(e,t,n,r);break;case"richinput":dl(e,t,n,r);break;default:{const a=document.createElement("div");a.className="text-red-500 text-sm",a.textContent=k("unsupportedFieldType",t.state,{type:e.type}),n.appendChild(a)}}}function Ot(e,t){if(e.type==="markdown"){if(e.hidden===!0){const s=document.createElement("div");return s.style.display="none",s.setAttribute("data-fb-hidden-markdown","true"),s}const i=lr(e,t),l=document.createElement("div");return l.className="mb-2 fb-field-wrapper fb-markdown-wrapper",l.setAttribute("data-field-key",vt(e,t.state)),wl(e,t,l),i&&(l.style.display="none",l.classList.add("fb-field-wrapper-disabled"),l.setAttribute("data-conditionally-disabled","true")),ir(l,e,t),l}const n=lr(e,t),r=document.createElement("div");r.className="mb-2 fb-field-wrapper",r.setAttribute("data-field-key",e.key);const o=Tl(e);r.appendChild(o);const a=Ce(t.path,e.key);return Al(e,t,r,a),n&&(r.style.display="none",r.classList.add("fb-field-wrapper-disabled"),r.setAttribute("data-conditionally-disabled","true")),ir(r,e,t),r}Oo(Ot);const Ut={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,pickExistingFiles:null,parseTableFile:null,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",downloadFile:"Download",openInNewTab:"Open in new tab",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",fileCountWithMax:"{count} / {max} files",fileCountRange:"({min}-{max})",uploadingFile:"Uploading\u2026",filesCounter:"{count}/{max}",fromLibrary:"From library",libraryEmpty:"Library is empty",libraryHint:"Choose from previously uploaded files",dropToUpload:"Release to upload",replaceFile:"Replace",clearAll:"Clear all",pickerError:"Failed to load files from library",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",invalidFileExtension:'File "{name}" has unsupported format. Allowed: {formats}',invalidFileMime:'File "{name}": file type {type} not allowed (allowed: {mimes})',fileTooLarge:'File "{name}" exceeds maximum size of {maxSize}MB',uploadFailed:'Failed to upload "{name}": {error}',filesLimitExceeded:"{skipped} file(s) skipped: 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)",tableImportFile:"Import",tableImporting:"Importing...",tableImportError:"Import failed: {error}",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",downloadFile:"\u0421\u043A\u0430\u0447\u0430\u0442\u044C",openInNewTab:"\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0432 \u043D\u043E\u0432\u043E\u0439 \u0432\u043A\u043B\u0430\u0434\u043A\u0435",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",fileCountWithMax:"{count} / {max} \u0444\u0430\u0439\u043B\u043E\u0432",fileCountRange:"({min}-{max})",uploadingFile:"\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430\u2026",filesCounter:"{count}/{max}",fromLibrary:"\u0418\u0437 \u0431\u0438\u0431\u043B\u0438\u043E\u0442\u0435\u043A\u0438",libraryEmpty:"\u0411\u0438\u0431\u043B\u0438\u043E\u0442\u0435\u043A\u0430 \u043F\u0443\u0441\u0442\u0430",libraryHint:"\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0438\u0437 \u0440\u0430\u043D\u0435\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u043D\u044B\u0445 \u0444\u0430\u0439\u043B\u043E\u0432",dropToUpload:"\u041E\u0442\u043F\u0443\u0441\u0442\u0438\u0442\u0435, \u0447\u0442\u043E\u0431\u044B \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C",replaceFile:"\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C",clearAll:"\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0432\u0441\u0435",pickerError:"\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0444\u0430\u0439\u043B\u044B \u0438\u0437 \u0431\u0438\u0431\u043B\u0438\u043E\u0442\u0435\u043A\u0438",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",invalidFileExtension:'\u0424\u0430\u0439\u043B "{name}" \u0438\u043C\u0435\u0435\u0442 \u043D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442. \u0414\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0435: {formats}',invalidFileMime:'\u0424\u0430\u0439\u043B "{name}": \u0442\u0438\u043F \u0444\u0430\u0439\u043B\u0430 {type} \u043D\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D (\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D\u044B: {mimes})',fileTooLarge:'\u0424\u0430\u0439\u043B "{name}" \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u043C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0440\u0430\u0437\u043C\u0435\u0440 {maxSize}\u041C\u0411',uploadFailed:'\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C "{name}": {error}',filesLimitExceeded:"{skipped} \u0444\u0430\u0439\u043B(\u043E\u0432) \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043E: \u043C\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)",tableImportFile:"\u0418\u043C\u043F\u043E\u0440\u0442",tableImporting:"\u0418\u043C\u043F\u043E\u0440\u0442...",tableImportError:"\u041E\u0448\u0438\u0431\u043A\u0430 \u0438\u043C\u043F\u043E\u0440\u0442\u0430: {error}",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 Fl(e){const t={...Ut.translations};if(e!=null&&e.translations)for(const[n,r]of Object.entries(e.translations))t[n]={...Ut.translations[n]||{},...r};return{schema:null,formRoot:null,resourceIndex:new Map,externalActions:null,version:"1.0.0",config:{...Ut,...e,translations:t},debounceTimer:null,prefill:{},syntheticElementIds:new WeakMap,syntheticElementIdCounter:0}}function Ml(){const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,9);return`inst-${e}-${t}`}const Ye={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.5rem",inputPaddingY:"0.25rem",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 zl(e){const t={...Ye,...e},n=[];return Object.entries(t).forEach(([r,o])=>{const a=r.replace(/([A-Z])/g,"-$1").toLowerCase();n.push(` --fb-${a}: ${o};`)}),n.join(`
1156
- `)}function Nl(e,t){const n=zl(t);let r=e.querySelector("style[data-fb-theme]");r||(r=document.createElement("style"),r.setAttribute("data-fb-theme","true"),e.appendChild(r)),r.textContent=`
1157
- [data-fb-root="true"] {
1158
- ${n}
1159
- }
1160
- `}const ql={default:Ye,dark:{...Ye,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:{...Ye,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 Il(e,t,n){var r;const{scopeRoot:o}=n,a=o.querySelector(`input[type="hidden"][data-hidden-field="true"][name="${t}"]`),i=(r=a==null?void 0:a.value)!=null?r:"";if(i===""){const l="default"in e?e.default:null;return{value:l!==void 0?l:null,errors:[]}}return{value:Wt(i),errors:[]}}function Rl(e,t,n,r){const{scopeRoot:o}=r,a=o.querySelector(`input[type="hidden"][data-hidden-field="true"][name="${t}"]`);a&&(a.value=Pt(n))}const Hl={text:{validate:_t,update:Kt},textarea:{validate:wr,update:Er},number:{validate:$r,update:Lr},select:{validate:Ar,update:Fr},switcher:{validate:Nr,update:qr},file:{validate:Tn,update:Fn},files:{validate:Tn,update:Fn},colour:{validate:Io,update:Ro},slider:{validate:Do,update:jo},container:{validate:Un,update:Pn},group:{validate:Vo,update:_o},table:{validate:rl,update:ol},richinput:{validate:fl,update:pl},hidden:{validate:Il,update:Rl},markdown:{validate:El,update:Cl}};function ar(e){return Hl[e]||null}function Bl(e,t,n){const r=ar(e.type);return r&&r.validate?r.validate(e,t,n):null}function Dl(e,t,n,r){const o=ar(e.type);return o&&o.update?(o.update(e,t,n,r),!0):!1}class ht{constructor(t){this.instanceId=Ml(),this.state=Fl(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 r=this.validateForm(!0);this.reevaluateConditionalFields(),this.state.config.onChange&&this.state.config.onChange(r),this.state.config.onFieldChange&&t!==void 0&&n!==void 0&&this.state.config.onFieldChange(t,n,r),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(r=>r.value===t.value&&r.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 o=this.state.formRoot.querySelector(`[name="${t}"]`);if(o)return o;const a=[t,t.replace(/\[(\d+)\]/g,"[$1]"),t.replace(/\./g,"[")+"]".repeat((t.match(/\./g)||[]).length)];for(const i of a)if(o=this.state.formRoot.querySelector(`[name="${i}"]`),o)return o}const n=this.findSchemaElement(t);if(!n)return null;const r=this.state.formRoot.querySelectorAll(".fb-field-wrapper");for(const o of r){const a=n.label||n.key,i=o.querySelector("label");if(i&&(i.textContent===a||i.textContent===`${a}*`)){let l=o.querySelector(".field-placeholder");return l||(l=document.createElement("div"),l.className="field-placeholder",l.style.display="none",o.appendChild(l)),l}}return null}findSchemaElement(t){if(!this.state.schema||!this.state.schema.elements)return null;let n=this.state.schema.elements,r=null;const o=t.replace(/\[\d+\]/g,"").split(".").filter(Boolean);for(const a of o){if(r=n.find(i=>i.key===a)||null,!r)return null;"elements"in r&&r.elements&&(n=r.elements)}return r}resolveActionLabel(t,n,r,o=!1){if(r&&"actions"in r&&r.actions){const a=r.actions.find(i=>i.key===t);if(a&&a.label)return a.label}if(o&&this.state.schema&&"actions"in this.state.schema&&this.state.schema.actions){const a=this.state.schema.actions.find(i=>i.key===t);if(a&&a.label)return a.label}return n||t}renderFormLevelActions(t,n=[]){if(!this.state.formRoot)return;const r=this.state.formRoot.querySelector(".form-level-actions-container");r&&r.remove();const o=document.createElement("div");o.className="form-level-actions-container mt-3 pt-2 flex flex-wrap gap-2 justify-center",o.style.cssText=`
1161
- border-top: var(--fb-border-width) solid var(--fb-border-color);
1162
- `,t.forEach(a=>{const i=document.createElement("button");i.type="button",Vt(i,!0);const l=n.includes(a),s=this.resolveActionLabel(a.key,a.label,null,l);i.textContent=s,i.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(a.value,a.key,null)}),o.appendChild(i)}),this.state.formRoot.appendChild(o)}renderExternalActions(){if(!this.state.externalActions||!Array.isArray(this.state.externalActions))return;const t=new Map,n=[],r=[];this.state.externalActions.forEach(a=>{!a.key||!a.value||(a.related_field?(t.has(a.related_field)||t.set(a.related_field,[]),t.get(a.related_field).push(a)):n.push(a))}),t.forEach((a,i)=>{const l=this.findFormElementByFieldPath(i);if(!l){console.warn(`External action: Could not find form element for field "${i}", treating as form-level actions`),r.push(...a);return}let s=l.closest(".fb-field-wrapper");if(s||(s=l.parentElement),!s){console.warn(`External action: Could not find wrapper for field "${i}"`);return}const u=s.querySelector(".external-actions-container");u&&u.remove();const d=document.createElement("div");d.className="external-actions-container mt-3 flex flex-wrap gap-2";const c=this.findSchemaElement(i);a.forEach(p=>{const f=document.createElement("button");f.type="button",Vt(f,!1);const m=this.resolveActionLabel(p.key,p.label,c);f.textContent=m,f.addEventListener("click",b=>{b.preventDefault(),b.stopPropagation(),this.state.config.actionHandler&&typeof this.state.config.actionHandler=="function"&&this.state.config.actionHandler(p.value,p.key,p.related_field)}),d.appendChild(f)}),s.appendChild(d)});const o=[...n,...r];o.length>0&&this.renderFormLevelActions(o,n)}handlePrefillHintClick(t){const n=t.target;if(!n.classList.contains("fb-prefill-hint"))return;t.preventDefault(),t.stopPropagation();const r=n.getAttribute("data-hint-values"),o=n.getAttribute("data-root-hint")==="true",a=n.getAttribute("data-container-key");if(!r||!o&&!a){console.warn("Prefill hint missing required data attributes");return}try{const i=JSON.parse(r);for(const l in i){const s=o?l:`${a}.${l}`,u=i[l];this.updateField(s,u)}}catch(i){console.error("Error parsing prefill hint values:",i)}}createRootPrefillHints(t){const n=document.createElement("div");return n.className="fb-prefill-hints flex flex-wrap gap-2 mb-2",t.forEach(r=>{const o=document.createElement("button");o.type="button",o.className="fb-prefill-hint",r.icon?o.textContent=`${r.icon} ${r.label}`:o.textContent=r.label,o.setAttribute("data-hint-values",JSON.stringify(r.values)),o.setAttribute("data-root-hint","true"),n.appendChild(o)}),n}renderForm(t,n,r,o){const a=bt(n);if(a.length>0){console.error("Schema validation errors:",a);return}this.state.formRoot=t,this.state.schema=n,this.state.externalActions=o||null,this.state.prefill=r||{},ge(t),t.setAttribute("data-fb-root","true"),Nl(t,this.state.config.theme);const i=document.createElement("div");if(i.className="space-y-2",n.prefillHints&&!this.state.config.readonly){const u=this.createRootPrefillHints(n.prefillHints);i.appendChild(u)}const l=document.createElement("div"),s=n.columns||1;s===1?l.className="space-y-2":l.className=`grid grid-cols-${s} gap-2`,n.elements.forEach(u=>{var d,c;if(u.type!=="markdown"&&(u.hidden||u.type==="hidden")){const f=(c=(d=r==null?void 0:r[u.key])!=null?d:u.default)!=null?c:null;l.appendChild(We(u.key,f));return}const p=Ot(u,{path:"",prefill:r||{},formData:r||{},state:this.state,instance:this});l.appendChild(p)}),i.appendChild(l),t.appendChild(i),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=[],r={},o=(a,i,l=null)=>{var s;const u=(s=a.key)!=null?s:"",d={scopeRoot:l||this.state.formRoot,state:this.state,instance:this,path:i.path,skipValidation:t},c=Bl(a,u,d);return c!==null?(n.push(...c.errors),{value:c.value,spread:!!c.spread,skip:!!c.skip}):(console.warn(`Unknown field type "${a.type}" for key "${u}"`),{value:null,spread:!1})};return Po(o),this.state.schema.elements.forEach(a=>{var i;if(a.enableIf)try{if(!He(a.enableIf,r))return}catch(l){console.error(`Error evaluating enableIf for field "${a.key}" during validation:`,l)}if(a.type!=="markdown")if(a.hidden||a.type==="hidden"){const l=this.state.formRoot.querySelector(`input[type="hidden"][data-hidden-field="true"][name="${a.key}"]`),s=(i=l==null?void 0:l.value)!=null?i:"";s!==""?r[a.key]=Wt(s):r[a.key]=a.default!==void 0?a.default:null}else{const l=o(a,{path:""});if(l.skip)return;l.spread&&l.value!==null&&typeof l.value=="object"?Object.assign(r,l.value):a.key&&(r[a.key]=l.value)}}),{valid:n.length===0,errors:n,data:r}}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,r=this.state.externalActions,o=this.buildHiddenFieldsData(t.elements);this.renderForm(n,t,o,r||void 0)}buildHiddenFieldsData(t){const n={};for(const r of t){if(r.type==="markdown"||!r.key)continue;const o=r.key;if(r.hidden&&r.default!==void 0&&(n[o]=r.default),r.type==="container"||r.type==="group"){const a=r,i=this.buildHiddenFieldsData(a.elements);Object.keys(i).length>0&&(o in n?typeof n[o]=="object"&&n[o]!==null&&!Array.isArray(n[o])&&(n[o]={...n[o],...i}):n[o]=i)}}return n}buildFlatKeyMap(t){var n,r;const o=new Map;for(const a of t)if(a.type==="richinput"&&a.flatOutput){const i=a,l=(n=i.textKey)!=null?n:"text",s=(r=i.filesKey)!=null?r:"files";o.set(l,{schemaKey:a.key,role:"text"}),o.set(s,{schemaKey:a.key,role:"files"})}return o}setFormData(t){if(!this.state.schema||!this.state.formRoot){console.warn("setFormData: Form not initialized. Call renderForm() first.");return}const n=this.buildFlatKeyMap(this.state.schema.elements),r=new Map;for(const o in t){const a=n.get(o);a?(r.has(a.schemaKey)||r.set(a.schemaKey,{}),r.get(a.schemaKey)[o]=t[o]):this.updateField(o,t[o])}for(const[o,a]of r)this.updateField(o,a)}updateField(t,n){if(!this.state.schema||!this.state.formRoot){console.warn("updateField: Form not initialized. Call renderForm() first.");return}const r=this.findSchemaElement(t);if(!r){console.warn(`updateField: Schema element not found for path "${t}"`);return}const o=this.findFormElementByFieldPath(t);if(!o){console.warn(`updateField: DOM element not found for path "${t}"`);return}this.updateFieldValue(o,r,t,n),this.reevaluateConditionalFields(),(this.state.config.onChange||this.state.config.onFieldChange)&&this.triggerOnChange(t,n)}updateFieldValue(t,n,r,o){const a={scopeRoot:this.state.formRoot,state:this.state,instance:this,path:""};Dl(n,r,o,a)||console.warn(`updateField: No updater found for field type "${n.type}" at path "${r}"`)}findFieldWrapper(t,n){const r=this.state.formRoot,o=vt(t,this.state);if(!n)return r.querySelector(`[data-field-key="${o}"]`);const a=n.match(/^(.+)\[(\d+)\]$/);if(a){const l=r.querySelector(`[data-container-item="${a[1]}[${a[2]}]"]`);return l?l.querySelector(`[data-field-key="${o}"]`):null}const i=r.querySelector(`[data-container="${n}"]`);return i?i.querySelector(`[data-field-key="${o}"]`):null}applyEnableIfVisibility(t,n,r,o,a){var i,l,s,u;try{const d=((i=t.enableIf.scope)!=null?i:"relative")==="relative"&&r?gt(a,r):void 0,c=He(t.enableIf,a,d),p=n.getAttribute("data-conditionally-disabled")==="true";if(c&&p){const f=r?gt(a,r):a,m=Ot(t,{path:r,prefill:f&&typeof f=="object"?f:{},formData:a,state:this.state,instance:this});(l=n.parentNode)==null||l.replaceChild(m,n)}else if(!c&&!p){const f=document.createElement("div");f.className="fb-field-wrapper-disabled",f.style.display="none",f.setAttribute("data-field-key",vt(t,this.state)),f.setAttribute("data-conditionally-disabled","true"),(s=n.parentNode)==null||s.replaceChild(f,n)}}catch(d){console.error(`Error re-evaluating enableIf for field "${(u=t.key)!=null?u:"<no key>"}" at path "${o}":`,d)}}reevaluateConditionalFields(){if(!this.state.schema||!this.state.formRoot)return;const t=this.validateForm(!0).data,n=(r,o)=>{r.forEach(a=>{var i,l;const s=o?`${o}.${(i=a.key)!=null?i:""}`:(l=a.key)!=null?l:"";if(a.enableIf){const u=this.findFieldWrapper(a,o);u&&this.applyEnableIfVisibility(a,u,o,s,t)}if((a.type==="container"||a.type==="group")&&"elements"in a&&a.elements){const u=a.key?t==null?void 0:t[a.key]:void 0;if(Array.isArray(u)){const d=this.state.formRoot.querySelectorAll("[data-container-item]");(s?Array.from(d).filter(c=>{const p=c.getAttribute("data-container-item")||"";if(!p.startsWith(`${s}[`))return!1;const f=p.slice(s.length);return/^\[\d+\]$/.test(f)}):[]).forEach(c=>{const p=c.getAttribute("data-container-item")||"";n(a.elements,p)})}else n(a.elements,s)}})};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&&ge(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 sr(e){return new ht(e)}return typeof window!="undefined"&&(window.FormBuilder=ht,window.createFormBuilder=sr,window.validateSchema=bt),Se.FormBuilderInstance=ht,Se.createFormBuilder=sr,Se.default=ht,Se.defaultTheme=Ye,Se.exampleThemes=ql,Se.validateSchema=bt,Object.defineProperty(Se,"__esModule",{value:!0}),Se})({});