reactaform 1.8.91 → 1.8.93
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.
- package/dist/reactaform.cjs.js +36 -25
- package/dist/reactaform.css +1 -1
- package/dist/reactaform.es.js +1289 -1268
- package/package.json +1 -1
package/dist/reactaform.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),G=require("react"),Ur=require("react-dom");function nr(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),G=require("react"),Ur=require("react-dom");function nr(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const u=nr(G),fe=nr(Ur),Wr=`/* ReactaForm CSS Custom Properties (CSS Variables) */\r
|
|
2
2
|
\r
|
|
3
3
|
/* Default Light Theme */\r
|
|
4
4
|
:root {\r
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
--reactaform-secondary-bg: #fff;\r
|
|
8
8
|
--reactaform-text-color: #000;\r
|
|
9
9
|
--reactaform-text-muted: #666;\r
|
|
10
|
+
--reactaform-form-border-color: #000000;\r
|
|
10
11
|
--reactaform-border-color: #ccc;\r
|
|
11
12
|
--reactaform-border-hover: #999;\r
|
|
12
13
|
--reactaform-border-focus: #4CAF50;\r
|
|
@@ -35,14 +36,18 @@
|
|
|
35
36
|
--reactaform-font-size: 14px;\r
|
|
36
37
|
--reactaform-font-weight: 500;\r
|
|
37
38
|
\r
|
|
39
|
+
--reactaform-label-font-family: var(--reactaform-font-family);\r
|
|
38
40
|
--reactaform-label-font-size: 14px;\r
|
|
39
41
|
--reactaform-label-font-weight: 600;\r
|
|
40
42
|
\r
|
|
41
43
|
/* Layout */\r
|
|
42
44
|
--reactaform-border-radius: 0px;\r
|
|
45
|
+
--reactaform-form-border-radius: 0px;\r
|
|
46
|
+
--reactaform-form-border-style: solid;\r
|
|
47
|
+
--reactaform-form-border-width: 0px;\r
|
|
43
48
|
\r
|
|
44
49
|
/* Shadows */\r
|
|
45
|
-
--reactaform-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\r
|
|
50
|
+
--reactaform-form-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\r
|
|
46
51
|
\r
|
|
47
52
|
/* Button Variables */\r
|
|
48
53
|
--reactaform-button-bg: var(--reactaform-success-color);\r
|
|
@@ -93,6 +98,8 @@
|
|
|
93
98
|
--reactaform-border-color: #3A3A3A; /* Default border */\r
|
|
94
99
|
--reactaform-border-hover: #4A4A4A; /* Hover */\r
|
|
95
100
|
--reactaform-border-focus: #4DA6FF; /* Accent blue focus */\r
|
|
101
|
+
\r
|
|
102
|
+
--reactaform-form-border-color: #333333;\r
|
|
96
103
|
\r
|
|
97
104
|
/* Status colors */\r
|
|
98
105
|
--reactaform-error-color: #FF6B6B;\r
|
|
@@ -102,7 +109,7 @@
|
|
|
102
109
|
--reactaform-option-menu-hover-bg: rgba(255, 255, 255, 0.06);\r
|
|
103
110
|
\r
|
|
104
111
|
/* Shadows (subtle for dark mode) */\r
|
|
105
|
-
--reactaform-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);\r
|
|
112
|
+
--reactaform-form-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);\r
|
|
106
113
|
\r
|
|
107
114
|
/* Tooltip */\r
|
|
108
115
|
--reactaform-tooltip-color-bg: rgba(40, 40, 40, 0.95);\r
|
|
@@ -113,12 +120,15 @@
|
|
|
113
120
|
.reactaform-container {\r
|
|
114
121
|
font-family: var(--reactaform-font-family, sans-serif);\r
|
|
115
122
|
font-size: var(--reactaform-font-size, 14px);\r
|
|
116
|
-
background
|
|
117
|
-
color: var(--reactaform-text-color);\r
|
|
118
|
-
padding: var(--reactaform-container-padding);\r
|
|
119
|
-
border-radius: var(--reactaform-border-radius);\r
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
background: var(--reactaform-primary-bg, #f9f9f9);\r
|
|
124
|
+
color: var(--reactaform-text-color, #000000);\r
|
|
125
|
+
padding: var(--reactaform-container-padding, 12px);\r
|
|
126
|
+
border-radius: var(--reactaform-form-border-radius, 0px);\r
|
|
127
|
+
border-color: var(--reactaform-form-border-color, #000000);\r
|
|
128
|
+
border-style: var(--reactaform-form-border-style, solid);\r
|
|
129
|
+
border-width: var(--reactaform-form-border-width, 0px);\r
|
|
130
|
+
box-shadow: var(--reactaform-form-shadow, none);\r
|
|
131
|
+
gap: var(--reactaform-space-lg, 12px);\r
|
|
122
132
|
max-width: 100%;\r
|
|
123
133
|
margin: 0 auto;\r
|
|
124
134
|
/* Removed internal scrolling - let parent container handle it */\r
|
|
@@ -134,8 +144,8 @@
|
|
|
134
144
|
grid-template-columns: var(--reactaform-field-grid-columns, 1fr 2fr);\r
|
|
135
145
|
align-items: start;\r
|
|
136
146
|
padding: 0;\r
|
|
137
|
-
gap: var(--reactaform-column-gap);\r
|
|
138
|
-
margin-bottom: var(--reactaform-field-gap);\r
|
|
147
|
+
gap: var(--reactaform-column-gap, 8px);\r
|
|
148
|
+
margin-bottom: var(--reactaform-field-gap, 8px);\r
|
|
139
149
|
}\r
|
|
140
150
|
\r
|
|
141
151
|
/* Labels */\r
|
|
@@ -145,7 +155,8 @@
|
|
|
145
155
|
white-space: normal;\r
|
|
146
156
|
line-height: 1.4;\r
|
|
147
157
|
min-width: 100px;\r
|
|
148
|
-
color: var(--reactaform-text-color);\r
|
|
158
|
+
color: var(--reactaform-text-color, #000000);\r
|
|
159
|
+
font-family: var(--reactaform-label-font-family, var(--reactaform-font-family, sans-serif));\r
|
|
149
160
|
font-weight: var(--reactaform-label-font-weight, 600);\r
|
|
150
161
|
font-size: var(--reactaform-label-font-size, 14px);\r
|
|
151
162
|
user-select: none;\r
|
|
@@ -157,25 +168,25 @@
|
|
|
157
168
|
/* Input Base */\r
|
|
158
169
|
.reactaform-input {\r
|
|
159
170
|
width: 100%;\r
|
|
160
|
-
color: var(--reactaform-text-color);\r
|
|
161
|
-
border: 1px solid var(--reactaform-border-color);\r
|
|
162
|
-
border-radius: var(--reactaform-border-radius);\r
|
|
163
|
-
padding: var(--reactaform-input-padding);\r
|
|
171
|
+
color: var(--reactaform-text-color, #000000);\r
|
|
172
|
+
border: 1px solid var(--reactaform-border-color, #ccc);\r
|
|
173
|
+
border-radius: var(--reactaform-border-radius, 0px);\r
|
|
174
|
+
padding: var(--reactaform-input-padding, 8px);\r
|
|
164
175
|
box-sizing: border-box;\r
|
|
165
|
-
background-color: var(--reactaform-input-bg);\r
|
|
166
|
-
font-size: var(--reactaform-font-size);\r
|
|
167
|
-
font-weight: var(--reactaform-font-weight);\r
|
|
176
|
+
background-color: var(--reactaform-input-bg, #ffffff);\r
|
|
177
|
+
font-size: var(--reactaform-font-size, 14px);\r
|
|
178
|
+
font-weight: var(--reactaform-font-weight, 400);\r
|
|
168
179
|
transition: border-color 0.2s ease;\r
|
|
169
180
|
box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);\r
|
|
170
181
|
}\r
|
|
171
182
|
\r
|
|
172
183
|
.reactaform-input:hover {\r
|
|
173
|
-
border-color: var(--reactaform-border-hover);\r
|
|
184
|
+
border-color: var(--reactaform-border-hover, #4A4A4A);\r
|
|
174
185
|
}\r
|
|
175
186
|
\r
|
|
176
187
|
.reactaform-input:focus {\r
|
|
177
188
|
outline: none;\r
|
|
178
|
-
border-color: var(--reactaform-border-focus);\r
|
|
189
|
+
border-color: var(--reactaform-border-focus, #4DA6FF);\r
|
|
179
190
|
/* Bright, prominent focus ring with cyan glow for maximum visibility on dark backgrounds */\r
|
|
180
191
|
box-shadow: 0 0 0 3px rgba(34,211,238,0.4),\r
|
|
181
192
|
0 0 16px rgba(34,211,238,0.25),\r
|
|
@@ -329,9 +340,9 @@
|
|
|
329
340
|
\r
|
|
330
341
|
\r
|
|
331
342
|
}\r
|
|
332
|
-
`,ke=G.createContext(void 0),L=()=>{const e=G.useContext(ke);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class se{map={};register(r,t){if(!r||typeof r!="string")throw new Error("Registry key must be a non-empty string");this.map[r]=t}get(r){if(!(!r||typeof r!="string"))return this.map[r]}has(r){return!r||typeof r!="string"?!1:r in this.map}list(){return Object.keys(this.map)}entries(){return Object.entries(this.map)}values(){return Object.values(this.map)}size(){return Object.keys(this.map).length}unregister(r){return r in this.map?(delete this.map[r],!0):!1}clear(){this.map={}}registerAll(r){Array.isArray(r)?r.forEach(([t,n])=>{t&&typeof t=="string"&&this.register(t,n)}):r&&typeof r=="object"&&Object.entries(r).forEach(([t,n])=>{t&&typeof t=="string"&&this.register(t,n)})}getOrDefault(r,t){const n=this.get(r);return n!==void 0?n:t}}const ar=typeof process<"u"&&process.env.NODE_ENV==="test";function or(e,r=300,t){const n=G.useRef(),a=G.useRef(e),o=G.useRef(null),i=t?.leading===!0,c=t?.trailing!==!1;G.useEffect(()=>{a.current=e},[e]),G.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const s=p=>{a.current(...p)},u=G.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=void 0),o.current=null},[]),l=G.useCallback(()=>{n.current&&c&&o.current&&(clearTimeout(n.current),n.current=void 0,s(o.current),o.current=null)},[c]);return{callback:G.useCallback((...p)=>{if(ar){s(p);return}const g=i&&!n.current;o.current=p,g&&s(p),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=void 0,c&&o.current&&(s(o.current),o.current=null)},r)},[i,c,r]),cancel:u,flush:l}}const V={field:"reactaform-field",label:"reactaform-label",input:"reactaform-input",textInput:"reactaform-input--text",inputNumber:"reactaform-input--number",inputSelect:"reactaform-select",rangeInput:"reactaform-input--range",button:"reactaform-button"},B=(...e)=>{const r=[];for(const t of e)t&&(typeof t=="string"?r.push(t):typeof t=="object"&&Object.entries(t).forEach(([n,a])=>{a&&r.push(n)}));return r.join(" ")};function ie(e){return e.toLowerCase().includes("dark")}function _r(e){if(!e)return!1;const r=e.trim();let t=0,n=0,a=0;if(r.startsWith("#")){const i=r.substring(1);i.length===3||i.length===4?(t=parseInt(i[0]+i[0],16),n=parseInt(i[1]+i[1],16),a=parseInt(i[2]+i[2],16)):(i.length===6||i.length===8)&&(t=parseInt(i.substring(0,2),16),n=parseInt(i.substring(2,4),16),a=parseInt(i.substring(4,6),16))}else if(r.startsWith("rgb")){const i=r.match(/\d+(\.\d+)?/g);i&&i.length>=3&&(t=parseFloat(i[0]),n=parseFloat(i[1]),a=parseFloat(i[2]))}else return!1;return(t*299+n*587+a*114)/1e3<128}const Kr=()=>d.jsxs("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),d.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Gr=({content:e,size:r="medium",animation:t=!0})=>{const{t:n,theme:a,formStyle:o,fieldStyle:i}=L(),[c,s]=m.useState(!1),[u,l]=m.useState({x:0,y:0}),[f,p]=m.useState(!1),g=m.useRef(null),x=m.useRef(null),j=m.useRef(null),h=m.useId(),v=ie(a),[E,R]=m.useState(void 0);m.useLayoutEffect(()=>{if(!g.current)return;const S="rgba(255,255,255,0.1)",b=getComputedStyle(g.current).getPropertyValue("--reactaform-primary-bg").trim();if(b&&typeof CSS<"u"&&CSS.supports?.("color: color-mix(in srgb, red, blue)")){const C=_r(b)?"black":"white";R(`color-mix(in srgb, var(--reactaform-primary-bg) 85%, ${C} 15%)`)}else R(S)},[]);const F=m.useMemo(()=>{const y={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:E??(v?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"),color:`var(--reactaform-text-color, ${v?"#f0f0f0":"#333"})`,border:`1px solid ${v?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:t?"all 0.2s ease":void 0,marginLeft:"0.3em"},text:{...{small:{padding:"4px 8px",fontSize:"11px",maxWidth:"200px"},medium:{padding:"6px 10px",fontSize:"12px",maxWidth:"240px"},large:{padding:"8px 12px",fontSize:"13px",maxWidth:"280px"}}[r],position:"fixed",backgroundColor:`var(--reactaform-tooltip-color-bg, ${v?"rgba(45,45,45,0.95)":"rgba(34, 10, 170, 0.92)"})`,color:`var(--reactaform-tooltip-color, ${v?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${v?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:v?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,pointerEvents:"none",transition:t?"opacity 0.2s ease":void 0,whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,pointerEvents:"auto"}},b=(N,M,k)=>{const P=N?.[M];return(k&&P?P[k]:void 0)??{}};return{icon:{...y.icon,...b(o,"tooltip","icon"),...b(i,"tooltip","icon")},text:{...y.text,...b(o,"tooltip","text"),...b(i,"tooltip","text")},textVisible:y.textVisible}},[v,r,t,o,i,E]);m.useLayoutEffect(()=>{if(!c||!g.current||!x.current){p(!1);return}const S=g.current.getBoundingClientRect();j.current=S;const y=x.current.getBoundingClientRect(),b=8,C=window.innerWidth,N=window.innerHeight,M=-4;let k=S.right+b,A=S.top+S.height/2-y.height/2+M;k+y.width>C-b&&(k=S.left-b-y.width),k=Math.max(b,Math.min(k,C-y.width-b)),A=Math.max(b,Math.min(A,N-y.height-b)),l({x:k,y:A}),p(!0);const P=g.current.closest("[data-reactaform-theme]"),_=document.getElementById("popup-root");if(P&&_){const ce=getComputedStyle(P);_.style.setProperty("--reactaform-tooltip-color-bg",ce.getPropertyValue("--reactaform-tooltip-color-bg")),_.style.setProperty("--reactaform-tooltip-color",ce.getPropertyValue("--reactaform-tooltip-color"))}},[c]);const w=typeof document<"u"?document.getElementById("popup-root"):null,I=d.jsx("div",{ref:x,"data-tooltip-id":h,style:{...F.text,transform:f?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...f?F.textVisible:{},top:u.y,left:u.x},children:n(e)});return d.jsxs(d.Fragment,{children:[d.jsx("span",{"data-testid":"tooltip-icon",ref:g,"aria-describedby":c?h:void 0,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{...F.icon},children:d.jsx(Kr,{})}),c&&(w?fe.createPortal(I,w):I)]})},sr=m.memo(Gr),ye=m.memo(({field:e,error:r,children:t,showLabel:n=!0})=>{const{t:a}=L(),o=e.labelLayout==="column-center"?"center":"left",i=m.useMemo(()=>{const u={display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)"};return u["--label-align"]=o,u},[o]),c=m.useMemo(()=>({textAlign:o,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"}),[o]),s=m.useMemo(()=>({display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"}),[]);return d.jsxs("div",{className:`${V.field} column-layout`,style:i,children:[n&&d.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:c,children:a(e.displayName)}),d.jsxs("div",{style:s,children:[d.jsx("div",{style:{flex:1,minWidth:0},children:t}),e.tooltip&&d.jsx(sr,{content:e.tooltip})]}),r&&d.jsx(je,{id:`${e.name}-error`,children:r})]})});ye.displayName="ColumnFieldLayout";const ir=m.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>{const{t:a}=L(),o=m.useMemo(()=>({display:"flex",alignItems:"center",gap:"3px"}),[]);return d.jsxs("div",{className:`${V.field} row-layout`,children:[d.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:{textAlign:"left"},children:a(e.displayName)}),d.jsxs("div",{children:[d.jsxs("div",{style:o,children:[n?d.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end"},children:t}):t,e.tooltip&&d.jsx(sr,{content:e.tooltip})]}),r&&d.jsx(je,{id:`${e.name}-error`,children:r})]})]})});ir.displayName="RowFieldLayout";const z=m.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?d.jsx(ye,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?d.jsx(ye,{field:e,error:r,showLabel:!1,children:t}):d.jsx(ir,{field:e,error:r,rightAlign:n,children:t}));z.displayName="StandardFieldLayout";const je=m.memo(({children:e,id:r})=>{const t=m.useMemo(()=>({color:"var(--reactaform-error-color)",fontSize:"13px",marginTop:"4px",fontWeight:"var(--reactaform-font-weight)",display:"flex",flex:1,justifyContent:"flex-start",alignItems:"flex-start"}),[]);return d.jsx("div",{id:r,style:t,children:e})});je.displayName="ErrorDiv";const cr=m.memo(({name:e,onChange:r})=>{const{t}=L();return d.jsxs("div",{style:{marginBottom:16},children:[d.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[d.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),d.jsx("input",{id:"instance-name-input",type:"text",value:e,className:B(V.input,V.textInput),onChange:n=>r(n.target.value),placeholder:t("Enter instance name")})]}),d.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});cr.displayName="InstanceName";class Jr extends se{registerInCategory(r,t,n){this.get(r)||this.register(r,{});const a=this.get(r);a[t]=n}getFromCategory(r,t){return this.get(r)?.[t]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const lr=new se,ur=new Jr,Ee=new se;function mr(e,r){lr.register(e,r)}function fr(e,r,t){ur.registerInCategory(e,r,t)}function dr(e,r){if(zt(e)){console.warn(`[ReactaForm] Can't override builtin type field validation handler for type "${e}".`);return}Ee.register(e,r)}function T(e,r){Ee.register(e,r)}function pr(e,r){return ur.getFromCategory(e,r)||null}function gr(e){return lr.get(e)||null}function hr(e){return Ee.get(e)||null}function Yr(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const qe=new Map,Ue=new Map;function Ne(e,r,t,n){if(!r||!r.validationHandlerName)return null;let a,o;if(typeof r.validationHandlerName=="string")a=e,o=r.validationHandlerName;else if(Array.isArray(r.validationHandlerName)){const[s,u]=r.validationHandlerName;if(u)a=s,o=u;else if(s)a=e,o=s;else return null}else return null;const i=`${a}:${o}`;let c=qe.get(i);if(c===void 0&&(c=pr(a,o)||null,qe.set(i,c)),c)try{return c(r.name,t,n)||null}catch(s){return String(s instanceof Error?s.message:s)}return null}function Xr(e,r,t,n){return Ne(e,r,t,n)}function yr(e,r,t,n){const a=hr(r.type);if(a){const o=a(r,t,n);if(o)return o}else if(String(t??"").trim()==="")return r.required?n("Value required"):null;return Ne(e,r,t,n)}async function Zr(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const n=e.validationHandlerName;let a=Ue.get(n);if(a===void 0&&(a=gr(n)||null,Ue.set(n,a)),a)try{const o=a(r,t);return Yr(o)?await o||null:o||null}catch(o){return[String(o instanceof Error?o.message:o)]}return null}function O(e,r){const{definitionName:t,t:n,fieldValidationMode:a}=L();return m.useCallback(o=>a==="realTime"?yr(t,e,o,n):r??null,[t,e,n,a,r])}const Qr=({field:e,value:r=!1,onChange:t,onError:n,error:a})=>{const{t:o}=L(),c=O(e,a)(r);m.useEffect(()=>{a||n?.(c)},[c,a,n]);const s=m.useCallback(f=>{t?.(f.target.checked)},[t]),u=m.useCallback(f=>{(f.key===" "||f.key==="Space"||f.key==="Spacebar"||f.code==="Space"||f.key==="Enter")&&(f.preventDefault(),t?.(!r))},[t,r]),l=e.name;return d.jsx(z,{field:e,rightAlign:!1,error:c,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[d.jsx("label",{className:V.label,htmlFor:l,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),d.jsx("input",{id:l,"data-testid":"boolean-checkbox",type:"checkbox",checked:r,onChange:s,onKeyDown:u,"aria-checked":r,"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0,style:{cursor:"pointer",margin:"8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",accentColor:"#0000FF"}})]})})};function W({value:e,onChange:r,onError:t,validate:n}){const a=m.useRef(null),o=m.useRef(null),i=m.useRef(t),[c,s]=m.useState(null);m.useEffect(()=>{i.current=t},[t]),m.useEffect(()=>{const l=String(e??"");if(!(document.activeElement===a.current)){const p=n(l);p!==o.current&&(o.current=p,i.current?.(p??null),s(p)),a.current&&a.current.value!==l&&(a.current.value=l)}},[e,n]);const u=m.useCallback(l=>{const f=l.target.value,p=n(f);p!==o.current&&(o.current=p,s(p),i.current?.(p??null)),r?.(f)},[r,n]);return{inputRef:a,error:c,handleChange:u}}const We=[{label:"Black",value:"#000000"},{label:"White",value:"#ffffff"},{label:"Red",value:"#ff0000"},{label:"Green",value:"#008000"},{label:"Blue",value:"#0000ff"},{label:"Yellow",value:"#ffff00"},{label:"Cyan",value:"#00ffff"},{label:"Magenta",value:"#ff00ff"},{label:"Orange",value:"#ffa500"},{label:"Purple",value:"#800080"},{label:"Brown",value:"#a52a2a"},{label:"Gray",value:"#808080"},{label:"Light Gray",value:"#d3d3d3"},{label:"Pink",value:"#ffc0cb"}],et=/^#([0-9A-F]{3}){1,2}$/i,rt="#000000",tt=e=>et.test(e),pe=e=>{if(!e||!tt(e))return rt;const r=e.toLowerCase();return r.length===4?"#"+r.slice(1).split("").map(t=>t+t).join(""):r},nt=e=>{const r=parseInt(e.slice(1),16);return{r:r>>16&255,g:r>>8&255,b:r&255}},at=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),i=O(e,a),c=m.useMemo(()=>pe(r),[r]),{inputRef:s,error:u,handleChange:l}=W({value:c,onChange:t,onError:n,validate:i}),[f,p]=m.useState(c);m.useEffect(()=>{a||n?.(u)},[u,a,n]),m.useEffect(()=>{p(c)},[c]);const g=m.useCallback(F=>{const w=pe(F.target.value);p(w),l({target:{value:w}})},[l]),x=m.useCallback(F=>{const w=pe(F.target.value);p(w),l({target:{value:w}})},[l]),h=m.useMemo(()=>new Set(We.map(F=>F.value)),[]).has(f),{r:v,g:E,b:R}=m.useMemo(()=>nt(f),[f]);return d.jsx(z,{field:e,error:u,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[d.jsxs("select",{id:e.name,value:f,onChange:x,className:B(V.input,V.inputSelect),"aria-invalid":!!u,children:[We.map(F=>d.jsx("option",{value:F.value,children:o(F.label)},F.value)),!h&&d.jsxs("option",{value:f,children:["(",v,", ",E,", ",R,")"]})]}),d.jsx("label",{style:{width:"2.5em",height:"1.8em",border:"1px solid #ccc",borderRadius:4,backgroundColor:f,cursor:"pointer",overflow:"hidden",flexShrink:0},children:d.jsx("input",{ref:s,id:`${e.name}-color`,type:"color",defaultValue:f,onChange:g,style:{opacity:0,width:"100%",height:"100%"},"aria-invalid":!!u})})]})})},_e=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Ke=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return _e(e)?e:"";const t=_e(e);if(t){const n=t.getUTCFullYear(),a=String(t.getUTCMonth()+1).padStart(2,"0"),o=String(t.getUTCDate()).padStart(2,"0");return`${n}-${a}-${o}`}return""},ot=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),i=Ke(r),{inputRef:c,error:s,handleChange:u}=W({value:i,onChange:t,onError:n,validate:o});return m.useEffect(()=>{a||n?.(s)},[s,a,n]),d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"date",ref:c,defaultValue:Ke(r),onChange:u,className:B(V.input,V.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},st=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,theme:i,formStyle:c,fieldStyle:s}=L(),u=m.useRef(null),l=m.useRef(n),[f,p]=m.useState(!1),[g,x]=m.useState(null);m.useEffect(()=>{l.current=n},[n]);const j=O(e,a),[h,v]=m.useState(null),E=m.useRef(null);m.useEffect(()=>{const b=String(r??"");let C=j(b);if(C&&e.options.length>0){const N=String(e.options[0].value);t?.(N),C=null}C!==E.current&&(E.current=C,v(C),l.current?.(C??null))},[r,j,t,e.options]);const R=()=>{if(!u.current)return;const b=u.current.getBoundingClientRect();x({x:b.left,y:b.bottom}),p(C=>!C)},F=b=>{const C=j(b);C!==E.current&&(E.current=C,v(C),l.current?.(C??null)),t?.(b),p(!1)},w=m.useMemo(()=>{const b=e.options.find(C=>String(C.value)===String(r));return b?o(b.label):""},[e.options,r,o]),I=(b,C,N)=>{if(!C)return{};const k=b?.[C];return(N&&k?k[N]:void 0)??{}},S=m.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...I(c,"dropdown","control"),...I(s,void 0,"control")}),[c,s]),y=m.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...I(c,"dropdown","arrow"),...I(s,void 0,"arrow")}),[c,s]);return d.jsxs("div",{children:[d.jsx(z,{field:e,error:h,children:d.jsxs("div",{ref:u,className:"reactaform-input",style:S,onClick:R,tabIndex:0,role:"combobox","aria-haspopup":"listbox","aria-expanded":f,"aria-invalid":!!h,"aria-describedby":h?`${e.name}-error`:void 0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),R())},children:[d.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w}),d.jsx("span",{style:y,"aria-hidden":!0,children:"▼"})]})}),f&&g&&d.jsx(it,{position:g,options:e.options,selectedValue:String(r),onSelect:F,onClose:()=>p(!1),controlRef:u,theme:i,t:o})]})},it=({position:e,options:r,selectedValue:t,onSelect:n,onClose:a,controlRef:o,theme:i,t:c})=>{const s=m.useRef(null),[u,l]=m.useState(-1),{formStyle:f,fieldStyle:p}=L(),g=ie(i??"light");m.useLayoutEffect(()=>{if(!o.current)return;const y=o.current.closest("[data-reactaform-theme]"),b=document.getElementById("popup-root");if(y&&b){const C=getComputedStyle(y);b.style.setProperty("--reactaform-secondary-bg",C.getPropertyValue("--reactaform-secondary-bg")),b.style.setProperty("--reactaform-text-color",C.getPropertyValue("--reactaform-text-color")),b.style.setProperty("--reactaform-option-menu-hover-bg",C.getPropertyValue("--reactaform-option-menu-hover-bg"))}},[o]);const x=(y,b,C)=>{if(!b)return{};const M=y?.[b];return(C&&M?M[C]:void 0)??{}},j=m.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...x(f,"dropdown","popup"),...x(p,void 0,"popup")}),[f,p]),h=m.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...x(f,"dropdown","option"),...x(p,void 0,"option")}),[f,p]);m.useEffect(()=>{const y=b=>{const C=b.target;!s.current?.contains(C)&&!o.current?.contains(C)&&a()};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[a,o]),m.useEffect(()=>{if(s.current&&r.length>0){const y=r.findIndex(b=>String(b.value)===t);requestAnimationFrame(()=>l(y>=0?y:0))}},[r,t]),m.useEffect(()=>{if(!s.current||u<0)return;const y=s.current.querySelector(`#opt-${u}`);y&&requestAnimationFrame(()=>y.focus())},[u]);const v=250,E=200,[R,F]=m.useState(null),[w,I]=m.useState(null);if(m.useEffect(()=>{if(typeof window>"u")return;const y=()=>{let N=e.x,M=e.y,k=v;const A=o?.current;if(A){const P=A.getBoundingClientRect();N=P.left,M=P.bottom,k=Math.max(80,Math.round(P.width))}N=Math.min(N,window.innerWidth-k),M=Math.min(M,window.innerHeight-E),F({left:N,top:M}),I(k)};y(),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y);let b=null;const C=o?.current;return typeof ResizeObserver<"u"&&C&&(b=new ResizeObserver(()=>y()),b.observe(C)),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y),b&&C&&b.unobserve(C)}},[o,e.x,e.y]),typeof window>"u")return null;let S=document.getElementById("popup-root");return S||(S=document.createElement("div"),S.id="popup-root",document.body.appendChild(S)),fe.createPortal(d.jsx("div",{ref:s,role:"listbox","aria-activedescendant":u>=0?`opt-${u}`:void 0,style:{position:"fixed",top:R?R.top:e.y,left:R?R.left:e.x,width:w??v,...j},"data-reactaform-theme":i??"light",children:r.map((y,b)=>{const C=String(y.value)===t,N=g?"var(--reactaform-option-menu-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-option-menu-hover-bg, #eee)",M={...h,background:b===u?N:h.background,fontWeight:C?"bold":"normal"};return d.jsx("div",{id:`opt-${b}`,onMouseDown:k=>{k.stopPropagation(),n(String(y.value))},onKeyDown:k=>{const A=r.length;switch(k.key){case"ArrowDown":k.preventDefault(),l(P=>(P+1)%A);break;case"ArrowUp":k.preventDefault(),l(P=>(P-1+A)%A);break;case"Home":k.preventDefault(),l(0);break;case"End":k.preventDefault(),l(A-1);break;case"Enter":case" ":k.preventDefault(),k.stopPropagation(),n(String(y.value));break;case"Escape":k.preventDefault(),a(),o?.current?.focus();break}},tabIndex:b===u?0:-1,role:"option","aria-selected":C,style:M,onMouseEnter:k=>{k.currentTarget.style.background=N,l(b)},onMouseLeave:k=>{k.currentTarget.style.background="transparent",l(A=>A===b?-1:A)},children:c(y.label)},String(y.value))})}),S)},ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:c,children:d.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:i,onChange:s,className:B(V.input,V.textInput),"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})},lt=({field:e})=>{const{theme:r}=L(),{color:t=ie(r)?"#444444":"#CCCCCC",thickness:n=1,margin:a="8px 0"}=e;return d.jsx("div",{style:{width:"auto",height:"0",borderTop:`${n}px solid ${t}`,margin:a}})},ut=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),[i,c]=m.useState(!1),s=m.useRef(null),u=m.useRef(n),l=m.useRef(null),[f,p]=m.useState(null);m.useEffect(()=>{u.current=n},[n]);const g=(w,I)=>I.some(S=>S.name===w.name&&S.size===w.size&&S.lastModified===w.lastModified),x=O(e,a);m.useEffect(()=>{const w=x(r??[]);t?.(r),w!==l.current&&(l.current=w,p(w),u.current?.(w??null))},[r,x]);const j=w=>{const I=w.target.files;let S=null;if(I&&I.length>0){const b=Array.from(I);if(e.multiple){const C=Array.isArray(r)?r:[],N=b.filter(M=>!g(M,C));S=[...C,...N]}else S=b[0]}const y=x(S??[]);y!==l.current&&(l.current=y,p(y),u.current?.(y??null)),t?.(S),w.target&&(w.target.value="")},h=w=>{w.preventDefault(),w.stopPropagation(),c(!1);const I=w.dataTransfer.files;if(I&&I.length>0){const S=Array.from(I);let y=null;if(e.multiple){const C=Array.isArray(r)?r:[],N=S.filter(M=>!g(M,C));y=[...C,...N]}else y=S[0];const b=x(y);b!==l.current&&(l.current=b,p(b),u.current?.(b??null)),t?.(y)}},v=w=>{w.preventDefault(),w.stopPropagation(),c(!0)},E=w=>{w.preventDefault(),w.stopPropagation(),c(!1)},R=w=>{if(Array.isArray(r)&&typeof w=="number"){const I=r.filter((b,C)=>C!==w),S=I.length>0?I:null,y=x(S??[]);y!==l.current&&(l.current=y,p(y),u.current?.(y??null)),t?.(S)}else{const I=x([]);I!==l.current&&(l.current=I,p(I),u.current?.(I??null)),t?.(null)}},F=()=>{const w=Array.isArray(r)?r:r?[r]:[];return w.length===0?null:d.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:w.map((I,S)=>d.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[d.jsx("input",{type:"text",value:I.name,disabled:!0,readOnly:!0,title:I.name,className:"reactaform-input",style:{flex:1,cursor:"default",opacity:.8,minWidth:0}}),d.jsx("button",{type:"button",onClick:()=>R(Array.isArray(r)?S:void 0),"aria-label":o("Remove file"),style:{background:"transparent",border:"none",color:"var(--reactaform-color-error, #ef4444)",cursor:"pointer",padding:"2px 6px",fontSize:"1.125rem",lineHeight:1,borderRadius:"4px",transition:"background-color 0.2s",flexShrink:0},onMouseEnter:y=>{y.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${I.name}-${S}`))})};return d.jsx(z,{field:e,error:f,children:d.jsxs("div",{style:{width:"100%"},children:[d.jsxs("div",{className:"reactaform-input",onDrop:h,onDragOver:v,onDragLeave:E,style:{position:"relative",borderStyle:"dashed",borderColor:i?"var(--reactaform-color-primary, #2563eb)":f?"var(--reactaform-color-error, #ef4444)":void 0,borderWidth:"1px",borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:i?"var(--reactaform-bg-hover, #f0f9ff)":void 0,transition:"all 0.2s ease",cursor:"pointer",minHeight:"var(--reactaform-input-height, 34px)",width:"100%",maxWidth:"100%",alignSelf:"stretch",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},onClick:()=>s.current?.click(),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),s.current?.click())},role:"button","aria-label":e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop"),"aria-invalid":!!f,"aria-describedby":f?`${e.name}-error`:void 0,children:[d.jsx("input",{id:e.name,ref:s,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:j}),d.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),d.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:i?o("Drop files here"):e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop")}),e.accept&&d.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:i?0:1,transition:"opacity 0.15s ease",pointerEvents:i?"none":"auto"},children:e.accept})]}),F()]})})},mt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),i=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:c,error:s,handleChange:u}=W({value:i,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"text",defaultValue:i,ref:c,onChange:u,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o}),u=a??c;return d.jsx(z,{field:e,error:u,children:d.jsx("input",{id:e.name,type:"text",ref:i,defaultValue:String(r??""),onChange:s,className:B(V.input,V.inputNumber),"aria-invalid":!!u,"aria-describedby":u?`${e.name}-error`:void 0})})};function dt(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const pt=({field:e,value:r})=>{const{language:t,t:n}=L(),a=e.alignment||"center",o={left:"flex-start",center:"center",right:"flex-end"},i=typeof r=="string"?r:"";let c=i&&i.trim()!==""?i:typeof e.defaultValue=="string"?e.defaultValue:"";c&&!c.startsWith("/")&&(c=`${dt()}${c}`);const s=e.localized?.split(";").map(h=>h.trim()),[u,l]=m.useState(c||""),f=m.useRef(c||null);if(m.useEffect(()=>{if(!c)return;const h=c.split("/"),v=h.pop(),E=v.lastIndexOf(".");if(E===-1)return;const R=v.substring(0,E),F=v.substring(E);let w=null;s?.includes(t)&&(w=`${R}_${t}${F}`);const I=new AbortController;if(w){const S=[...h,w].join("/");fetch(S,{method:"HEAD",signal:I.signal}).then(y=>{const b=y.ok?S:c;b!==f.current&&(f.current=b,l(b))}).catch(()=>{c!==f.current&&(f.current=c,l(c))})}else{const S=c;S!==f.current&&(f.current=S,requestAnimationFrame(()=>l(S)))}return()=>{I.abort()}},[c,t,s]),!u)return null;const{width:p,height:g}=e,x={},j={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return p&&g?(x.width=p,x.height=g,j.width=`${p}px`,j.height=`${g}px`):p&&!g?(x.width=p,j.width=`${p}px`,j.height="auto"):!p&&g&&(x.height=g,j.width="auto",j.height=`${g}px`),d.jsx(z,{field:e,children:d.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:o[a]||"center",margin:"0 0"},children:d.jsx("img",{src:u,alt:n?.(e.displayName||"Image")||e.displayName||"Image",...x,style:j})})})},gt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),i=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:c,error:s,handleChange:u}=W({value:i,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"text",defaultValue:i,ref:c,onChange:u,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},br=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:c,children:d.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:i,onChange:s,className:B(V.input,V.inputNumber),"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})};br.displayName="IntegerInput";const ht=m.memo(br),yt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:c,children:d.jsx("textarea",{id:e.name,defaultValue:String(r??""),ref:i,onChange:s,style:{resize:"vertical",minHeight:e.minHeight??"80px",width:"100%",boxSizing:"border-box"},className:B(V.input,V.textInput),"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})},bt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=m.useRef(n);m.useEffect(()=>{o.current=n},[n]);const{t:i,theme:c,formStyle:s,fieldStyle:u}=L(),l=(N,M,k)=>{if(!M)return{};const P=N?.[M];return(k&&P?P[k]:void 0)??{}},f=m.useRef(null),[p,g]=m.useState(!1),[x,j]=m.useState(null),h=m.useMemo(()=>e.options.map(N=>({value:N.value,label:i(N.label)})),[e.options,i]),v=m.useMemo(()=>{const N=Array.isArray(r)?r:[],M=new Set(h.map(k=>k.value));return N.filter(k=>M.has(k))},[r,h]),E=O(e,a),[R,F]=m.useState(null),w=m.useRef(null);m.useEffect(()=>{const N=E(Array.isArray(r)?r:[]);N!==w.current&&(w.current=N,F(N),o.current?.(N??null))},[r,E]);const I=()=>{if(!f.current)return;const N=f.current.getBoundingClientRect();j({x:N.left,y:N.bottom}),g(M=>!M)},S=N=>{const M=v.includes(N)?v.filter(A=>A!==N):[...v,N],k=E(M);k!==w.current&&(w.current=k,F(k),o.current?.(k??null)),t?.(M)},y=m.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...l(s,"multiSelect","control"),...l(u,void 0,"control")}),[s,u]),b=m.useMemo(()=>({position:"absolute",right:"1.5em",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",padding:0,...l(s,"multiSelect","clearButton"),...l(u,void 0,"clearButton")}),[s,u]),C=m.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...l(s,"multiSelect","arrow"),...l(u,void 0,"arrow")}),[s,u]);return d.jsxs("div",{children:[d.jsx(z,{field:e,error:R,children:d.jsx("div",{style:{width:"100%"},children:d.jsxs("div",{ref:f,className:"reactaform-multiselection-control reactaform-input",style:y,onClick:I,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!R,"aria-describedby":R?`${e.name}-error`:void 0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),I())},children:[d.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",h.length," selected"]}),v.length>0&&d.jsx("button",{type:"button","aria-label":"Clear selections",onClick:N=>{N.stopPropagation(),t?.([])},style:b,children:d.jsx("span",{style:b,"aria-hidden":!0,children:"✖"})}),d.jsx("span",{style:C,"aria-hidden":!0,children:"▼"})]})})}),p&&x&&d.jsx(vt,{position:x,options:h,selectedValues:v,onToggleOption:S,onClose:()=>g(!1),controlRef:f,theme:c})]})},vt=({position:e,options:r,selectedValues:t,onToggleOption:n,onClose:a,controlRef:o,theme:i})=>{const c=m.useRef(null),[s,u]=m.useState(-1),{formStyle:l,fieldStyle:f}=L(),p=ie(i??"light");m.useLayoutEffect(()=>{if(!o.current)return;const S=o.current.closest("[data-reactaform-theme]"),y=document.getElementById("popup-root");if(S&&y){const b=getComputedStyle(S);y.style.setProperty("--reactaform-secondary-bg",b.getPropertyValue("--reactaform-secondary-bg")),y.style.setProperty("--reactaform-text-color",b.getPropertyValue("--reactaform-text-color")),y.style.setProperty("--reactaform-option-menu-hover-bg",b.getPropertyValue("--reactaform-option-menu-hover-bg"))}},[o]);const g=(S,y,b)=>{if(!y)return{};const N=S?.[y];return(b&&N?N[b]:void 0)??{}},x=m.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...g(l,"multiSelect","popup"),...g(f,void 0,"popup")}),[l,f]),j=m.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...g(l,"multiSelect","option"),...g(f,void 0,"option")}),[l,f]);m.useEffect(()=>{const S=y=>{const b=y.target;!c.current?.contains(b)&&!o.current?.contains(b)&&a()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[a,o]),m.useEffect(()=>{c.current&&r.length>0&&requestAnimationFrame(()=>u(S=>S===-1?0:S))},[r.length]),m.useEffect(()=>{if(!c.current||s<0)return;const S=c.current.querySelector(`#multi-opt-${s}`);S&&requestAnimationFrame(()=>S.focus())},[s]);const h=250,v=200,[E,R]=m.useState(null),[F,w]=m.useState(null);if(m.useEffect(()=>{if(typeof window>"u")return;const S=()=>{let C=e.x,N=e.y,M=h;const k=o?.current;if(k){const A=k.getBoundingClientRect();C=A.left,N=A.bottom,M=Math.max(80,Math.round(A.width))}C=Math.min(C,window.innerWidth-M),N=Math.min(N,window.innerHeight-v),R({left:C,top:N}),w(M)};S(),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S);let y=null;const b=o?.current;return typeof ResizeObserver<"u"&&b&&(y=new ResizeObserver(()=>S()),y.observe(b)),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S),y&&b&&y.unobserve(b)}},[o,e.x,e.y]),typeof window>"u")return null;let I=document.getElementById("popup-root");return I||(I=document.createElement("div"),I.id="popup-root",document.body.appendChild(I)),fe.createPortal(d.jsx("div",{ref:c,role:"listbox","aria-activedescendant":s>=0?`multi-opt-${s}`:void 0,style:{position:"fixed",top:E?E.top:e.y,left:E?E.left:e.x,width:F??h,...x},"data-reactaform-theme":i??"light",children:r.map((S,y)=>{const b=t.includes(S.value),C=p?"var(--reactaform-option-menu-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-option-menu-hover-bg, #eee)",N={...j,background:y===s?C:j.background};return d.jsxs("div",{id:`multi-opt-${y}`,onMouseDown:M=>{M.stopPropagation(),n(S.value)},onKeyDown:M=>{const k=r.length;switch(M.key){case"ArrowDown":M.preventDefault(),u(A=>(A+1)%k);break;case"ArrowUp":M.preventDefault(),u(A=>(A-1+k)%k);break;case"Home":M.preventDefault(),u(0);break;case"End":M.preventDefault(),u(k-1);break;case"Enter":case" ":M.preventDefault(),M.stopPropagation(),n(S.value);break;case"Escape":M.preventDefault(),a(),o?.current?.focus();break}},tabIndex:y===s?0:-1,role:"option","aria-selected":b,style:N,onMouseEnter:M=>{M.currentTarget.style.background=C,u(y)},onMouseLeave:M=>{M.currentTarget.style.background="transparent",u(k=>k===y?-1:k)},children:[d.jsx("input",{type:"checkbox",checked:b,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:p?"#10b981":"#22c55e",cursor:"pointer"}}),S.label]},S.value)})}),I)},xt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:String(r??""),onChange:t,onError:n,validate:o}),u=Math.max(1,Math.round(e.step??1));return d.jsx(z,{field:e,error:c,children:d.jsx("input",{id:e.name,type:"number",defaultValue:String(r??""),ref:i,min:e.min??void 0,max:e.max??void 0,step:u,onChange:s,style:{width:"100%",height:"100%"},className:V.input,"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})},wt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:c,children:d.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:i,onChange:s,className:B(V.input,V.textInput),"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})},St=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),i=O(e,a),c=e.layout?.toLowerCase()==="horizontal"?"row":"column",s=m.useRef(n);m.useEffect(()=>{s.current=n},[n]);const[u,l]=m.useState(null),f=m.useRef(null),p=m.useCallback(h=>{h!==f.current&&(f.current=h,l(h),s.current?.(h))},[]);m.useEffect(()=>{const h=r!=null?String(r):"",v=i(h);if(v&&e.options.length>0){const E=String(e.options[0].value);t?.(E)}p(v)},[r,e.options,i,t,p]);const g=h=>{const v=h.target.value,E=i(v);p(E),t?.(v)},x={display:"flex",flexDirection:c,flexWrap:c==="row"?"wrap":"nowrap",gap:c==="row"?"12px":"4px",alignItems:c==="row"?"center":"stretch",width:"100%",padding:c==="row"?"8px":void 0,boxSizing:"border-box"},j={display:c==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:c==="column"?6:0,cursor:"pointer",width:c==="column"?"100%":void 0,justifyContent:"flex-start"};return d.jsx(z,{field:e,error:u,children:d.jsx("div",{className:V.input,"aria-labelledby":`${e.name}-label`,"aria-invalid":!!u,style:x,children:e.options.map(h=>{const v=String(h.value),E=`${e.name}-${v}`;return d.jsxs("label",{className:B(V.label),style:j,onMouseDown:R=>R.preventDefault(),onClick:()=>{String(r??"")!==v&&g({target:{value:v}})},children:[d.jsx("input",{id:E,type:"radio",name:e.name,value:v,checked:String(r??"")===v,onChange:g,style:{width:"1.1em",height:"1.1em"}}),d.jsx("span",{style:{userSelect:"none",textAlign:c==="column"?"left":void 0,flex:c==="column"?1:void 0,fontWeight:400},children:o(h.label)})]},v)})})})},Ct={display:"flex",gap:4},kt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},jt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),i=O(e,a),c=e.max??5,s=e.icon?.trim()||"★",[u,l]=m.useState(null),f=m.useRef([]),p=m.useMemo(()=>Math.min(Math.max(r??0,0),c),[r,c]),g=m.useMemo(()=>i(p)??null,[i,p]);m.useEffect(()=>{n?.(g)},[g,n]);const x=m.useCallback(h=>{const v=Math.min(Math.max(h,0),c);i(v),t?.(v)},[c,i,t]),j=m.useCallback((h,v)=>{switch(h.key){case"Enter":case" ":h.preventDefault(),x(v+1);break;case"ArrowRight":case"ArrowUp":h.preventDefault(),f.current[Math.min(c-1,v+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":h.preventDefault(),f.current[Math.max(0,v-1)]?.focus();break}},[c,x]);return d.jsx(z,{field:e,error:g,children:d.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!g,"aria-describedby":g?`${e.name}-error`:void 0,style:Ct,children:Array.from({length:c},(h,v)=>{const E=v<p,F=u!==null&&v<=u||E?"gold":"lightgray";return d.jsx("span",{ref:w=>f.current[v]=w,role:"radio",tabIndex:p>0?v===p-1?0:-1:v===0?0:-1,"aria-checked":E,"aria-label":`Rating ${v+1}`,title:o(`${e.displayName} ${v+1}`),onClick:()=>x(v+1),onKeyDown:w=>j(w,v),onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),style:{...kt,color:F},children:s},v)})})})},Et=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),i=O(e,a),{inputRef:c,error:s,handleChange:u}=W({value:r,onChange:t,onError:n,validate:i}),[l,f]=m.useState(!1),p=()=>f(g=>!g);return d.jsx(z,{field:e,error:s,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[d.jsx("input",{id:e.name,type:l?"text":"password",defaultValue:String(r??""),ref:c,onChange:u,className:B(V.input,V.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0}),d.jsx("button",{type:"button",onClick:p,"aria-label":o(l?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:l?"🙈":"👁️"})]})})},Nt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),i=e.min??0,c=e.max??100,[s,u]=m.useState(()=>isNaN(Number(r))?String(i):String(Number(r)));m.useEffect(()=>{const g=isNaN(Number(r))?String(i):String(Number(r));u(g)},[r,i]);const l=m.useMemo(()=>o(s)??null,[o,s]);m.useEffect(()=>{n?.(l)},[l,n]);const f=m.useCallback(g=>{const x=g.target.value;u(x),o(x),t?.(x)},[o,t]),p=isNaN(Number(s))?String(i):String(Number(s));return d.jsx(z,{field:e,error:l,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[d.jsx("input",{id:`${e.name}-range`,type:"range",value:p,onChange:f,min:i,max:c,step:"1.0",style:{padding:0,flex:1},className:V.rangeInput,"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0}),d.jsx("input",{id:e.name,type:"text",value:s,onChange:f,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:B(V.input,V.textInput),"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0})]})})},Ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,formStyle:i,fieldStyle:c,fieldValidationMode:s}=L(),l=O(e,a)(r);m.useEffect(()=>{s==="realTime"&&n?.(l)},[l,s,n]);const f=i,p=c,g=(F,w,I)=>{if(!w)return{};const S=F?.[w];return(I&&S?S[I]:void 0)??{}},x=m.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...g(f,"switch","label"),...g(p,void 0,"label")}),[f,p]),j=m.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...g(f,"switch","hiddenInput"),...g(p,void 0,"hiddenInput")}),[f,p]),h=m.useMemo(()=>({position:"absolute",cursor:"pointer",top:0,left:0,right:0,bottom:0,backgroundColor:"var(--reactaform-switch-off-bg, #ccc)",transition:"0.3s",borderRadius:24,borderWidth:2,borderStyle:"solid",borderColor:"transparent",...g(f,"switch","slider"),...g(p,void 0,"slider")}),[f,p]),v=m.useMemo(()=>({position:"absolute",height:16,width:16,left:2,bottom:2,backgroundColor:"white",transition:"0.3s",borderRadius:"50%",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.3)",...g(f,"switch","knob"),...g(p,void 0,"knob")}),[f,p]),E=!!r,R=()=>{t?.(!E)};return d.jsx(z,{field:e,error:null,rightAlign:!1,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[d.jsx("label",{className:V.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),d.jsxs("label",{style:x,children:[d.jsx("input",{id:e.name,type:"checkbox",checked:E,readOnly:!0,"aria-label":o(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:j,tabIndex:-1}),d.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":E,"aria-invalid":!1,"aria-describedby":void 0,onClick:R,onKeyDown:F=>{(F.key===" "||F.key==="Spacebar"||F.key==="Space"||F.key==="Enter")&&(F.preventDefault(),R())},className:`reactaform-switch ${E?"active checked on":""} `,style:E?{...h,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:h,children:d.jsx("span",{style:{...v,transform:E?"translateX(20px)":void 0}})})]})]})})},Ge=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:c,children:d.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:i,onChange:s,className:B(V.input,V.textInput),placeholder:e.placeholder,"aria-invalid":!!c,"aria-describedby":c?`${e.name}-error`:void 0})})},It=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o}),u=a??c;return d.jsx(z,{field:e,error:u,children:d.jsx("input",{id:e.name,type:"time",ref:i,defaultValue:r,step:e.includeSeconds?1:60,onChange:s,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:B(V.input,V.textInput),"aria-invalid":!!u,"aria-describedby":u?`${e.name}-error`:void 0})})};function Mt({pos:e,options:r,onClose:t,onClickOption:n}){const a=m.useRef(null),o=m.useRef(!1),[i,c]=m.useState({top:e?.y??0,left:e?.x??0,ready:!1}),s=typeof window<"u"?document.getElementById("popup-root")||document.body:null;return m.useEffect(()=>{function u(l){o.current||l.target.dataset?.popupMenu==="item"||a.current&&l.target instanceof Node&&!a.current.contains(l.target)&&t()}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),m.useLayoutEffect(()=>{if(!a.current||!e||e.x==null||e.y==null)return;const u=a.current.getBoundingClientRect(),l=window.innerWidth,f=window.innerHeight;let p=e.x,g=e.y;p+u.width>l&&(p=Math.max(0,l-u.width-10)),g+u.height>f&&(g=Math.max(0,e.y-u.height-5)),c({top:g,left:p,ready:!0})},[e,r]),!s||r===void 0||r.length===0||!e||e.x==null||e.y==null?null:fe.createPortal(d.jsx("div",{ref:a,onMouseDown:u=>{u.stopPropagation()},style:{position:"fixed",top:i.top,left:i.left,visibility:i.ready?"visible":"hidden",backgroundColor:"var(--reactaform-primary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:"var(--reactaform-border-radius, 4px)",boxShadow:"var(--reactaform-shadow, 0 2px 10px rgba(0,0,0,0.2))",zIndex:9999,minWidth:"var(--reactaform-menu-min-width, 150px)",maxHeight:"var(--reactaform-menu-max-height, 300px)",overflowY:"auto",pointerEvents:"auto"},children:r.map((u,l)=>d.jsx("div",{"data-popup-menu":"item",onMouseDown:f=>{f.stopPropagation(),o.current=!0},onClick:f=>{f.stopPropagation(),f.preventDefault(),n(u),t(),setTimeout(()=>{o.current=!1},100)},style:{padding:"var(--reactaform-menu-item-padding, 8px 12px)",cursor:"pointer",fontSize:"var(--reactaform-menu-item-font-size, 0.8em)",borderBottom:l<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:f=>{f.currentTarget.style.backgroundColor="var(--reactaform-option-menu-hover-bg, #e0e0e0)"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"},children:u.label},u.label??l))}),s)}const Fe={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},Ie={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Me={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Ve={},Vt=new Set([...Object.keys(Fe),...Object.keys(Ie),...Object.keys(Me)]);for(const e of Vt){const r={},t=Fe[e]??[],n=Ie[e]??{},a=Me[e]??{};for(const o of t){const i=n[o];r[o]={name:typeof i=="string"?i:String(o),shortName:o,factor:Object.prototype.hasOwnProperty.call(a,o)?a[o]:void 0}}for(const[o,i]of Object.entries(n))if(!r[o]){const c=typeof i=="string"?i:String(o);r[o]={name:c,shortName:o,factor:Object.prototype.hasOwnProperty.call(a,o)?a[o]:void 0}}for(const[o,i]of Object.entries(a))r[o]||(r[o]={name:String(o),shortName:String(o),factor:i});Ve[e]=r}function vr(e,r,t){if(e==="C"){if(r==="F")return t*(9/5)+32;if(r==="K")return t+273.15}else if(e==="F"){if(r==="C")return(t-32)*5/9;if(r==="K")return(t-32)*5/9+273.15}else if(e==="K"){if(r==="C")return t-273.15;if(r==="F")return(t-273.15)*9/5+32}return t}function xr(e){const r=Ve[e];if(!r)return null;const t={},n=[];for(const[o,i]of Object.entries(r))typeof i.factor=="number"&&(t[o]=i.factor),n.push(o);return{default:Object.keys(r)[0]??"",units:n,factors:t}}const Rt=Object.freeze(Object.defineProperty({__proto__:null,convertTemperature:vr,dimensionUnitDisplayMap:Ie,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,getUnitFactors:xr,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),wr=m.memo(({disabled:e,inputValue:r,selectedUnit:t,dimension:n,unitFactors:a,onConversionSelect:o,t:i})=>{const[c,s]=m.useState(!1),[u,l]=m.useState(null),[f,p]=m.useState([]),g=m.useCallback(h=>{if(e)return;const v=parseFloat(r);if(!Number.isFinite(v))return;const E=h.currentTarget.getBoundingClientRect();l({x:E.left,y:E.bottom});const R=[];if(n==="temperature")a.units.forEach(w=>{const I=vr(t,w,v);Number.isFinite(I)&&R.push({label:`${I.toFixed(6)} ${i(w)}`,value:I.toString(),unit:w})});else{const w=a.factors[t];w!==void 0&&Object.entries(a.factors).forEach(([I,S])=>{const y=v/w*S;Number.isFinite(y)&&R.push({label:`${y.toFixed(6)} ${i(I)}`,value:y.toString(),unit:I})})}p(R),s(R.length>0)},[e,r,t,n,a,i]),x=m.useCallback(h=>{s(!1),l(null),o(h)},[o]),j=m.useCallback(()=>{s(!1),l(null)},[]);return d.jsxs(d.Fragment,{children:[d.jsx("button",{onClick:g,disabled:e,"aria-disabled":e,style:{width:"var(--reactaform-unit-btn-width, 2.5em)",height:"var(--reactaform-unit-btn-height, 2.5em)",padding:"0",border:"none",borderRadius:"var(--reactaform-button-border-radius, var(--reactaform-border-radius, 0.25em))",backgroundColor:e?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:e?"not-allowed":"pointer",opacity:e?.6:1,display:"flex",alignItems:"center",justifyContent:"center"},className:V.button,children:d.jsx("span",{style:{fontSize:"1em",lineHeight:"1",pointerEvents:"none"},children:"⇄"})}),c&&f.length>0&&d.jsx(Mt,{pos:u,options:f,onClose:j,onClickOption:x})]})});wr.displayName="ConversionButton";const $t=({field:e,value:r,onChange:t,onError:n})=>{const{t:a}=L(),o=O(e),i=e.dimension,c=m.useMemo(()=>i?xr(i):null,[i]),s=String(r?.[0]??""),u=String(r?.[1]??c?.default??""),[l,f]=m.useState(s),[p,g]=m.useState(u);m.useEffect(()=>{f(s)},[s]),m.useEffect(()=>{g(u)},[u]);const x=o([l,p]);m.useEffect(()=>{n?.(x)},[x,n]);const j=m.useCallback(F=>{const w=F.target.value;f(w),o([w,p]),t?.([w,p])},[p,o,t]),h=m.useCallback(F=>{const w=F.target.value;g(w),o([l,w]),t?.([l,w])},[l,o,t]),v=m.useCallback(F=>{f(F.value),g(F.unit),t?.([F.value,F.unit])},[t]),E=m.useMemo(()=>c?c.units.map(F=>d.jsx("option",{value:F,children:a(F)},F)):[],[c,a]);if(!i||!c)return null;const R=!!x||!l.trim();return d.jsx(z,{field:e,error:x,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[d.jsx("input",{id:e.name,type:"text",value:l,onChange:j,style:{flex:"2 1 0"},className:B(V.input,V.textInput),"aria-invalid":!!x,"aria-describedby":x?`${e.name}-error`:void 0}),d.jsx("select",{id:`${e.name}-unit`,value:p,onChange:h,style:{flex:"1 1 0"},className:B(V.input,V.inputSelect),"aria-invalid":!!x,"aria-describedby":x?`${e.name}-error`:void 0,children:E}),d.jsx(wr,{disabled:R,inputValue:l,selectedUnit:p,dimension:i,unitFactors:c,onConversionSelect:v,t:a})]})})},At=m.memo($t),Dt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e),{inputRef:i,error:c,handleChange:s}=W({value:r,onChange:t,onError:n,validate:o}),u=a??c;return d.jsx(z,{field:e,error:u,children:d.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:i,onChange:s,className:B(V.input,V.textInput),placeholder:"https://example.com","aria-invalid":!!u,"aria-describedby":u?`${e.name}-error`:void 0})})},Pt={checkbox:!1,switch:!1,radio:!1,dropdown:!1,"multi-selection":!1,color:!1,rating:!1,file:!1,image:!1,separator:!1,string:{wait:200},text:{wait:200},multiline:{wait:200},email:{wait:200},password:{wait:200},phone:{wait:200},url:{wait:200},int:{wait:200},float:{wait:200},unit:{wait:100},date:{wait:150},time:{wait:150},slider:{wait:100,leading:!0,trailing:!0},stepper:{wait:100,leading:!0,trailing:!0}},me=new se,Re={checkbox:Qr,color:at,date:ot,dropdown:st,email:ct,file:ut,float:ft,"float-array":mt,image:pt,int:ht,"int-array":gt,"multi-selection":bt,multiline:yt,password:Et,phone:wt,radio:St,rating:jt,separator:lt,slider:Nt,string:Ge,stepper:xt,switch:Ft,text:Ge,time:It,unit:At,url:Dt};function zt(e){return e in Re}function Ot(e,r){const{wait:t=200,leading:n,trailing:a}=r,o=m.memo(i=>{const c=m.useRef(i.onChange);m.useEffect(()=>{c.current=i.onChange},[i.onChange]);const{callback:s,cancel:u}=or((...l)=>{c.current?.(...l)},t,{leading:n,trailing:a});return m.useEffect(()=>u,[u]),m.createElement(e,{...i,onChange:s})});return o.displayName="DebouncedFieldWrapper",o}function Sr(e,r,t){const n=r;if(!t&&e in Re){console.warn(`Can't overwrite base component type "${e}".`);return}const a=Pt[e];if(a===!1){me.register(e,n);return}const o=a??{wait:200};ar?me.register(e,n):me.register(e,Ot(n,o))}function $e(e,r){Sr(e,r,!1)}function Ae(e){return me.get(e)}let Je=!1;function Lt(){Je||(Object.entries(Re).forEach(([e,r])=>{Sr(e,r,!0)}),Je=!0)}const Tt=(e,r)=>{const t=new Map;let n=null,a=null,o=0;for(const i of e){const c=i.group;if(!c){n=null,a=null;continue}if(c===n)r[i.name].group=a??c;else{if(!t.has(c))t.set(c,1),a=null,r[i.name].group=c;else{const s=t.get(c),u=`${c}(${s})`;t.set(c,s+1),a=u,r[i.name].group=u,o++}n=c}}return o},Ht=(e,r={})=>{const{includeEmpty:t=!0}=r,n=[];let a=null,o=[],i=0;for(const s of e){const u=s.group||null;u!==a?((o.length>0||t)&&(o.length===0&&i++,n.push({name:a,fields:o})),a=u,o=[s]):o.push(s)}(o.length>0||t)&&(o.length===0&&i++,n.push({name:a,fields:o}));const c=Math.max(0,...n.map(s=>s.fields.length));return{groups:n,metadata:{totalGroups:n.length,emptyGroups:i,largestGroup:c}}},Cr=m.memo(({field:e,value:r,handleChange:t,handleError:n,error:a})=>{const o=Ae(e.type),i=m.useMemo(()=>r,[r]),c=m.useCallback(u=>t(e.name,u),[t,e.name]),s=m.useCallback(u=>n?.(e.name,u),[n,e.name]);return o?d.jsx(o,{field:e,value:i,onChange:c,onError:s,error:a}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError&&e.error===r.error);Cr.displayName="FieldWrapper";const kr=(e,r,t,n,a)=>{const o=a?a[e.name]??null:void 0;return d.jsx(m.Fragment,{children:d.jsx(Cr,{field:e,value:r[e.name],handleChange:t,handleError:n,error:o})},e.name)},jr=m.memo(({groupName:e,isOpen:r,fields:t,valuesMap:n,handleChange:a,handleError:o,errorsMap:i,toggleGroup:c,t:s})=>{const u=m.useCallback(()=>c(e),[c,e]),{formStyle:l,fieldStyle:f}=L(),p=m.useMemo(()=>({border:"1px solid var(--reactaform-border-color, #bbb)",padding:"var(--reactaform-fieldset-padding, 0.5em)",borderRadius:"var(--reactaform-border-radius, 4px)",marginBottom:"var(--reactaform-space, 8px)",...l?.fieldset||{},...f?.fieldset||{}}),[l,f]),g=m.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...l?.legend||{},...f?.legend||{}}),[l,f]);return d.jsxs("fieldset",{style:p,children:[d.jsxs("legend",{onClick:u,style:g,children:[d.jsx("span",{children:s(e)}),d.jsx("span",{children:r?"▼":"▶"})]}),r&&t.map(x=>kr(x,n,a,o,i))]})});jr.displayName="FieldGroup";const Bt=(e,r,t,n,a,o,i,c,s,u)=>{const l=r.slice(0,c).filter(g=>i[g.name]),f=Ht(l),p=[];return f.groups.forEach(g=>{if(g.name){const x=e[g.name]??!0;p.push(d.jsx(jr,{groupName:g.name,isOpen:x,fields:g.fields,valuesMap:t,handleChange:a,handleError:o,errorsMap:u,toggleGroup:s,t:n},g.name))}else g.fields.forEach(x=>p.push(kr(x,t,a,o,u)))}),p},qt=e=>{const r={};return e.forEach(t=>{r[t.name]=!1}),r},De=(e,r,t,n)=>{const a=r[e];if(!a||!a.children)return;const o=t[e],i=o!=null?String(o):"",c=a.children[i];!c||!Array.isArray(c)||c.forEach(s=>{typeof s=="string"&&(n[s]=!0,De(s,r,t,n))})},Er=(e,r,t)=>{const n=r[e];!n||!n.children||Object.values(n.children).filter(Array.isArray).flat().forEach(a=>{typeof a=="string"&&a in t&&(t[a]=!1,Er(a,r,t))})},Ut=(e,r,t,n)=>{const a={...t};return e.forEach(o=>{(!o.parents||Object.keys(o.parents).length===0)&&(a[o.name]=!0,De(o.name,n,r,a))}),a},Wt=(e,r,t,n,a)=>{const o={...e};if(Er(n,r,o),a!=null){const i=r[n];if(i&&i.children){const c=String(a),s=i.children[c];s&&Array.isArray(s)&&s.forEach(u=>{typeof u=="string"&&(o[u]=!0,De(u,r,t,o))})}}return o},Pe=new se;function ze(e,r){Pe.register(e,r)}function _t(e){return Pe.get(e)}function Kt(e){return Pe.get(e)}ze("Preset_AlertSubmitHandler",(e,r,t)=>{const n={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:t},a=JSON.stringify(n,null,2);alert(a)});async function Gt(e,r,t,n,a,o,i){const c=Object.values(a).filter(Boolean);if(c.length>0)return{success:!1,message:n("Please fix validation errors before submitting."),errors:c};const s={...t},u=[];if(e&&Array.isArray(e.properties))for(const l of e.properties){const f=l.name,p=s[f];if(p==null)continue;const g=l.type;try{if(g==="int"||g==="number"||g==="float"){const x=String(p).trim();if(x==="")s[f]=0;else{const j=Number(x);isNaN(j)?u.push(n("Invalid number format for field {{1}}",l.displayName||f)):s[f]=j}}else if(g==="int-array"||g==="float-array"){const x=String(p).split(",").map(v=>v.trim()).filter(Boolean),j=[];let h=!1;for(const v of x){const E=Number(v);if(isNaN(E)){u.push(n("Invalid number {{1}} in array for field {{2}}",v,l.displayName||f)),h=!0;break}j.push(E)}h||(s[f]=j)}}catch(x){u.push(n("Error processing field {{1}}: {{2}}",l.displayName||f,x instanceof Error?x.message:String(x)))}}if(u.length>0)return{success:!1,message:n("Data transformation errors occurred."),errors:u};if(i){const l=await i(s,n);if(l&&l.length>0)return{success:!1,message:n("Validation failed"),errors:l}}else{const l=await Zr(e,s,n);if(l&&l.length>0)return{success:!1,message:n("Validation failed"),errors:l}}if(o)try{const l=await o(e,r?.name??null,s,n);if(l&&l.length>0)return{success:!1,message:n("Submission failed"),errors:Array.isArray(l)?l:[String(l)]}}catch(l){return{success:!1,message:n("Submission handler error occurred"),errors:[String(l instanceof Error?l.message:l)]}}else if(e&&typeof e.submitHandlerName=="string"){const l=_t(e.submitHandlerName);if(l)try{const f=await l(e,r?.name??null,s,n);if(f&&f.length>0)return{success:!1,message:n("Submission failed"),errors:Array.isArray(f)?f:[String(f)]}}catch(f){return{success:!1,message:n("Submission handler error occurred"),errors:[String(f instanceof Error?f.message:f)]}}}return{success:!0,message:n("Form submitted successfully."),data:s}}const Nr=({message:e,success:r,onDismiss:t,t:n})=>e?d.jsxs("div",{role:"status",style:{marginBottom:12,padding:12,borderRadius:6,backgroundColor:r?"rgba(76, 175, 80, 0.12)":"rgba(225, 29, 72, 0.06)",border:`1px solid ${r?"rgba(76,175,80,0.3)":"rgba(225,29,72,0.12)"}`,color:r?"var(--reactaform-success-color, #4CAF50)":"var(--reactaform-error-color, #e11d48)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[d.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:e}),d.jsx("button",{onClick:t,"aria-label":n("Dismiss"),style:{marginLeft:12,background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:16,lineHeight:1},children:"×"})]}):null;Nr.displayName="SubmissionMessage";const Jt=({onClick:e,disabled:r=!1,t})=>{const[n,a]=m.useState(!1);return d.jsx("button",{onClick:e,disabled:r,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{padding:"var(--reactaform-button-padding, var(--reactaform-space) 12px)",backgroundColor:r?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",border:"none",borderRadius:"4px",cursor:r?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",fontSize:"var(--reactaform-button-font-size, 14px)",fontWeight:"var(--reactaform-button-font-weight, 500)",boxShadow:"var(--reactaform-button-shadow, none)",marginTop:"var(--reactaform-button-margin-top, 0.5em)",transition:"opacity 0.2s ease",opacity:r?"var(--reactaform-button-disabled-opacity, 0.6)":n?"var(--reactaform-button-hover-opacity, 0.9)":"1"},children:t("Submit")})},Fr=({definition:e,instance:r,onSubmit:t=void 0,onValidation:n=void 0,chunkSize:a=50,chunkDelay:o=50})=>{const{properties:i,displayName:c}=e,s=L(),{t:u,formStyle:l,language:f,displayInstanceName:p}=s,g={...s,definitionName:e?.name??s.definitionName},[x,j]=m.useState("en"),[h,v]=m.useState([]),[E,R]=m.useState({}),[F,w]=m.useState({}),[I,S]=m.useState({}),[y,b]=m.useState({}),[C,N]=m.useState({}),[M,k]=m.useState(null),[A,P]=m.useState(null),[_,ce]=m.useState(0),[Te,zr]=m.useState(!1),[He,ne]=m.useState(r.name||""),J=m.useRef(r),de=m.useRef(!1);m.useEffect(()=>{const D=Object.fromEntries(i.map($=>[$.name,{...$,children:{}}]));i.forEach($=>{$.parents&&Object.entries($.parents).forEach(([ee,re])=>{const ae=D[ee];ae&&re.forEach(qr=>{ae.children||(ae.children={});const Be=String(qr);ae.children[Be]=[...ae.children[Be]||[],$.name]})})}),Tt(i,D);const H=Object.values(D),q={};H.forEach($=>{if($.type==="unit"){const ee=typeof $.defaultValue=="number"?String($.defaultValue):"",re=typeof $.defaultUnit=="string"?$.defaultUnit:String($.defaultUnit??"m");q[$.name]=[ee,re]}else q[$.name]=$.defaultValue}),J.current=r,Object.keys(r.values).forEach($=>{D[$]!==void 0&&(q[$]=r.values[$])});const Y=qt(H),K={};H.forEach($=>{$.group&&!($.group in K)&&(K[$.group]=!0)});const Z=requestAnimationFrame(()=>{v(H),R(D),w(q),S(Ut(H,q,Y,D)),b(K),zr(!0),ne(r.name)});return()=>cancelAnimationFrame(Z)},[i,r,e]),m.useEffect(()=>{if(!Te||_>=h.length)return;const D=setTimeout(()=>{ce(H=>Math.min(H+a,h.length))},o);return()=>clearTimeout(D)},[Te,_,h.length,a,o]);const Or=m.useCallback((D,H)=>{k(null),P(null),w(q=>{const Y={...q,[D]:H},K=E[D];return K&&["checkbox","dropdown","multi-select","radio","switch"].includes(K.type)&&S($=>Wt($,E,Y,D,String(H))),Y})},[E,k,P]);m.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{f!==x&&(j(f||"en"),k(null),P(null))}),()=>cancelAnimationFrame(D)},[f,x]),m.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{if(de.current){de.current=!1,J.current=r,ne(r.name||"");return}J.current=r,k(null),P(null),ne(r.name||"")}),()=>cancelAnimationFrame(D)},[r,r.name]);const Lr=m.useCallback((D,H)=>{N(q=>H?{...q,[D]:String(H)}:Object.fromEntries(Object.entries(q).filter(([K])=>K!==D)))},[]),Tr=async()=>{de.current=!0;const D=J.current?.name;J.current.name=He;let H=C;if(g.fieldValidationMode==="onSubmission"){const Z={};if(h.forEach($=>{const ee=F[$.name];if(ee===void 0)return;const re=yr(g.definitionName,$,ee,u);re&&(Z[$.name]=re)}),N(Z),H=Z,Object.keys(Z).length>0){k(u("Please fix validation errors before submitting the form.")),P(!1);return}else k(null),P(null)}const q=await Gt(e,J.current,F,u,H,t,n),Y=typeof q.message=="string"?q.message:String(q.message),K=Object.values(q.errors??{}).join(`
|
|
333
|
-
`);
|
|
334
|
-
`+K:Y),P(q.success),q.success||(J.current.name=D??J.current.name,ne(D??""))},Hr=D=>{b(H=>({...H,[D]:!H[D]}))},Br=m.useMemo(()=>g.fieldValidationMode==="realTime"?Object.values(C).some(Boolean):!1,[C,g.fieldValidationMode]);return d.jsx(ke.Provider,{value:g,children:d.jsxs("div",{style:l.container,children:[c&&d.jsx("h2",{style:l.titleStyle,children:u(c)}),d.jsx(Nr,{message:M,success:A,onDismiss:()=>{k(null),P(null)},t:u}),p&&r&&d.jsx(cr,{name:He,onChange:D=>{ne(D),k(null),P(null)}}),d.jsxs(d.Fragment,{children:[Bt(y,h,F,u,Or,Lr,I,_,Hr,C),_<h.length&&d.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"},children:u(`Loading more fields... (${_}/${h.length})`)})]}),d.jsx(Jt,{onClick:Tr,disabled:Br,t:u})]})})},Ir={en:{name:"English",nativeName:"English"},fr:{name:"French",nativeName:"Français"},de:{name:"German",nativeName:"Deutsch"},es:{name:"Spanish",nativeName:"Español"},"zh-cn":{name:"Chinese (Simplified)",nativeName:"简体中文"},bg:{name:"Bulgarian",nativeName:"Български"},cs:{name:"Czech",nativeName:"Čeština"},da:{name:"Danish",nativeName:"Dansk"},el:{name:"Greek",nativeName:"Ελληνικά"},fi:{name:"Finnish",nativeName:"Suomi"},hi:{name:"Hindi",nativeName:"हिन्दी"},hu:{name:"Hungarian",nativeName:"Magyar"},id:{name:"Indonesian",nativeName:"Bahasa Indonesia"},it:{name:"Italian",nativeName:"Italiano"},ja:{name:"Japanese",nativeName:"日本語"},ko:{name:"Korean",nativeName:"한국어"},ms:{name:"Malay",nativeName:"Bahasa Melayu"},nl:{name:"Dutch",nativeName:"Nederlands"},no:{name:"Norwegian",nativeName:"Norsk"},pl:{name:"Polish",nativeName:"Polski"},pt:{name:"Portuguese",nativeName:"Português"},ro:{name:"Romanian",nativeName:"Română"},ru:{name:"Russian",nativeName:"Русский"},sk:{name:"Slovak",nativeName:"Slovenčina"},sv:{name:"Swedish",nativeName:"Svenska"},th:{name:"Thai",nativeName:"ไทย"},tr:{name:"Turkish",nativeName:"Türkçe"},uk:{name:"Ukrainian",nativeName:"Українська"},vi:{name:"Vietnamese",nativeName:"Tiếng Việt"},"zh-tw":{name:"Chinese (Traditional)",nativeName:"繁體中文"}},Yt=()=>Ir,ge=new Map,le=new Map,te=new Set,be=new Map,Xt=async e=>{try{let r={};const t=e.toLowerCase();switch(t){case"fr":r=(await Promise.resolve().then(()=>require("./common-CiL5z7rS.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-pqSYL5rx.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-BeQ3x_ll.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-C9xi6Anp.js"))).default;break;case"en":r={};break;default:if(Ir[t]){const a=`https://reactaform.vercel.app/locales/${t}/common.json`,o=await fetch(a);o.ok&&(r=await o.json())}else r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},Zt=async e=>{if(!e)return{success:!1,translations:{},error:"Language is required"};if(!e||e.toLowerCase()==="en")return{success:!0,translations:{},fromCache:!1};const r=e.toLowerCase();if(ge.has(r))return{success:!0,translations:ge.get(r)||{},fromCache:!0};const t=await Xt(r);return t.success&&(ge.set(r,t.translations),be.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},Qt=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const t=`${e.toLowerCase()}/${r}`;if(te.has(t))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(le.has(t))return{success:!0,translations:le.get(t)||{},fromCache:!0};try{let n=r;!r.includes("/")&&!r.includes(".")&&(n=`/locales/${e}/${r}.json`);const a=await fetch(n);if(!a.ok)return a.status===404?(le.set(t,{}),be.set(t,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(te.add(t),{success:!1,translations:{},error:`HTTP ${a.status}`,fromCache:!1});const o=a.headers.get("content-type")||"";!o.includes("application/json")&&!o.includes("text/json")&&Mr()&&console.warn(`Translation file at ${n} has unexpected content-type: ${o}`);const i=await a.text();if(!i){const u="Empty translation file";return te.add(t),{success:!1,translations:{},error:u}}let c;try{c=JSON.parse(i)}catch(u){const l=`Invalid JSON in translation file: ${u instanceof Error?u.message:String(u)}`;return te.add(t),{success:!1,translations:{},error:l}}if(!c||typeof c!="object"){const u="Invalid translation file format";return te.add(t),{success:!1,translations:{},error:u}}const s=Object.fromEntries(Object.entries(c).map(([u,l])=>[u,typeof l=="string"?l:String(l)]));return le.set(t,s),be.set(t,{loadedAt:new Date,size:Object.keys(s).length,source:"user"}),{success:!0,translations:s,fromCache:!1}}catch(n){const a=`Failed to load user translations: ${n instanceof Error?n.message:"Unknown error"}`;return te.add(t),{success:!1,translations:{},error:a}}};function Mr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function en(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(t,n)=>{const a=parseInt(n,10)-1,o=r[a];return o==null?t:String(o)})}const rn=(e,r,t)=>(n,...a)=>{let o=n,i=!1;return!n||typeof n!="string"?String(n||""):(e.toLowerCase()==="en"?(o=n,i=!0):n in t?(o=t[n],i=!0):n in r?(o=r[n],i=!0):o=n,o=en(o,a),!i&&Mr()&&console.debug(`Missing translation for "${n}" in language "${e}"`),o)};function tn(e){return/^[-+]?\d*$/.test(e)}function nn(e){const r=/^[-+]?\d*$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const an=",",on=e=>!e||e.trim()===""?[]:e.split(an).map(r=>r.trim()).filter(Boolean).map(r=>Number(r)),Ye=(e,r,t)=>{const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!tn(n))return t("Must be a valid integer");const a=parseInt(n,10);if(Number.isNaN(a))return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?a<e.min:a<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?a>e.max:a>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const o=Number(e.step);if(!Number.isInteger(o))return t("Invalid step value");if(a%o!==0)return t("Must be a multiple of {{1}}",o)}return null};function sn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!nn(n))return t("Each value must be a valid integer");const a=on(n);if(e.minCount!==void 0&&a.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&a.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const o of a){if(e.min!==void 0&&(e.minInclusive?o<e.min:o<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?o>e.max:o>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return null}function ve(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;const a=Number(n);if(Number.isNaN(a))return t("Must be a valid float");if(e.min!==void 0){const o=e.type==="slider"?!0:e.minInclusive??!0;if(o?a<e.min:a<=e.min)return t("Must be {{1}} {{2}}",o?"≥":">",e.min)}if(e.max!==void 0){const o=e.type==="slider"?!0:e.maxInclusive??!0;if(o?a>e.max:a>=e.max)return t("Must be {{1}} {{2}}",o?"≤":"<",e.max)}return null}const cn=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function ln(e){return e.split(",").map(r=>r.trim()).every(r=>cn.test(r))}const un=",",mn=e=>!e||e.trim()===""?[]:e.split(un).map(r=>r.trim()).filter(Boolean).map(r=>Number(r));function fn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!ln(n))return t("Each value must be a valid float");const a=mn(n);if(e.minCount!==void 0&&a.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&a.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const o of a){if(e.min!==void 0&&(e.minInclusive?o<e.min:o<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?o>e.max:o>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return null}const he=new WeakMap;function Oe(e,r,t,n,...a){if(e.pattern==null)return null;const o=String(r);let i=null;if(e.pattern){const c=he.get(e);if(c&&c.pattern===e.pattern)i=c.regex;else try{const s=new RegExp(e.pattern);he.set(e,{pattern:e.pattern,regex:s}),i=s}catch{he.set(e,{pattern:e.pattern,regex:null}),i=null}}return i&&!i.test(o)?e.patternErrorMessage?t(e.patternErrorMessage):n?t(n,...a):t("Input does not match pattern: {{1}}",e.pattern):null}function ue(e,r,t){const n=String(r);return n.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&n.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&n.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):Oe(e,r,t,"Invalid text format")}const xe=e=>{if(!e)return null;const r=Date.parse(e);return Number.isNaN(r)?null:r},Xe=new WeakMap,dn=e=>{let r=Xe.get(e);return r||(r={minTime:xe(e.minDate),maxTime:xe(e.maxDate)},Xe.set(e,r)),r};function pn(e,r,t){if(r==null||String(r).trim()==="")return e.required?t("Value required"):null;const n=String(r).trim(),a=xe(n);if(a===null)return t("Invalid date format");const{minTime:o,maxTime:i}=dn(e);return o!==null&&a<o?t("Date must be on or after {{1}}",e.minDate):i!==null&&a>i?t("Date must be on or before {{1}}",e.maxDate):null}function gn(e,r,t){const n=String(r);if(!n||n.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const a=i=>{const c=i.split(":").map(l=>parseInt(l,10));if(c.some(l=>Number.isNaN(l)))return NaN;const s=c.length;if(s<2||s>3)return NaN;if(s===2&&(c[0]<0||c[0]>23||c[1]<0||c[1]>59))return NaN;if(s===3&&(c[0]<0||c[0]>23||c[1]<0||c[1]>59||c[2]<0||c[2]>59))return NaN;let u=0;if(c.length===3)u=c[0]*3600+c[1]*60+c[2];else if(c.length===2)u=c[0]*3600+c[1]*60;else if(c.length===1)u=c[0]*3600;else return NaN;return u},o=a(n);if(Number.isNaN(o))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const i=a(e.min);if(!Number.isNaN(i)&&o<i)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const i=a(e.max);if(!Number.isNaN(i)&&o>i)return t("Time must be on or before {{1}}",e.max)}return null}function hn(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function yn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:hn(n)?Oe(e,r,t,t("Email does not match pattern: {{1}}",e.pattern)):t("Must be valid email format")}function bn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:Oe(e,n,t,"Invalid phone number format")}const vn=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,xn=e=>{try{return new URL(e),!0}catch{return!1}};function wn(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;if(vn.test(n)||xn(n))return null;if(e.allowRelative===!0){if(!n.startsWith("/")||encodeURI(n)!==n)return t("Must be a valid URL");try{return new URL(n,"http://example.com"),null}catch{return t("Must be a valid URL")}}return t("Must be a valid URL")}function Sn(e,r,t){const n=Array.isArray(r)?r:[],a=n[0],o=n[1]?String(n[1]).trim():"";return String(a??"").trim()===""||o===""?e.required?t("Value required"):null:ve(e,a,t)}function Cn(e,r,t){if(Array.isArray(r))return r.length===0?t("Select a file"):r.every(n=>n instanceof File)?null:t("Invalid file input");if(!(r instanceof File)){const n=String(r);return e.required&&(r==null||typeof n=="string"&&n.trim()==="")?t("Select a file"):t("Invalid file input: {{1}}",n)}return null}function kn(e,r,t){const n=String(r);return n===""||n===null||n===void 0?e.required?t("Value required"):null:e.options?.some(a=>String(a.value)===n)?null:t("Invalid option selected")}function jn(e,r,t){const a=String(r??"").trim();if(a==="")return e.required?t("Value required"):null;const o=a.split(",").map(i=>i.trim()).filter(i=>i!=="");if(o.length===0)return e.required?t("Value required"):null;for(const i of o)if(!e.options?.some(c=>String(c.value)===i))return t("Invalid option selected");return null}const En=/^#([0-9A-F]{3}){1,2}$/i,Nn=e=>En.test(e);function Fn(e,r,t){const n=String(r).trim();return n===""?e.required?t("Value required"):null:Nn(n)?null:t("Invalid color format")}function In(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;let a=r;return typeof r!="number"&&(a=parseFloat(n)),Number.isNaN(a)||a<=0?t("Invalid value"):e.max!==void 0&&a>e.max?t("Must be ≤ {{1}}",e.max):null}let Ze=!1;function Vr(){Ze||(T("int",Ye),T("stepper",Ye),T("int-array",sn),T("float",ve),T("slider",ve),T("float-array",fn),T("text",ue),T("string",ue),T("multiline",ue),T("password",ue),T("email",yn),T("date",pn),T("time",gn),T("url",wn),T("phone",bn),T("unit",Sn),T("dropdown",kn),T("multi-selection",jn),T("color",Fn),T("rating",In),T("file",Cn),Ze=!0)}Vr();Lt();Vr();const Mn=e=>({container:{padding:"var(--reactaform-space-sm, 8px)",margin:"0 auto",backgroundColor:"transparent",borderRadius:0,color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, system-ui, -apple-system, sans-serif)",boxSizing:"border-box",minHeight:e?.minHeight??"0",...e?.width?{width:e.width,overflowX:"auto"}:{maxWidth:"100%"},...e?.height?{height:e.height,overflowY:"auto"}:{}},buttonStyle:{padding:"var(--reactaform-space-sm, 8px) var(--reactaform-space-md, 16px)",backgroundColor:"var(--reactaform-color-primary)",color:"var(--reactaform-color-background)",border:"1px solid var(--reactaform-color-primary)",borderRadius:"var(--reactaform-border-radius, 6px)",cursor:"pointer",fontSize:e?.fontSize||"1rem",fontWeight:"600",transition:"all 0.2s ease",boxShadow:"var(--reactaform-shadow-small, 0 1px 3px rgba(0, 0, 0, 0.12))"},titleStyle:{marginBottom:"var(--reactaform-space-lg, 24px)",color:"var(--reactaform-color-text)",fontSize:typeof e?.fontSize=="number"?`${e.fontSize*1.5}px`:"1.5rem",fontWeight:"700",lineHeight:"1.2",textAlign:"left"}}),Vn=e=>{const r={color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",transition:"all 0.2s ease",outline:"none",width:"100%",boxSizing:"border-box"};return{container:{fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",fontSize:e?.fontSize||"var(--reactaform-font-size, 1rem)",width:"100%",maxWidth:e?.width||"100%",marginBottom:"var(--reactaform-space-md, 16px)"},label:{display:"block",marginBottom:"var(--reactaform-space-xs, 4px)",fontWeight:"500",color:"var(--reactaform-color-text)",fontSize:"var(--reactaform-font-size, 1rem)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)"},input:r,textInput:r,optionInput:r,select:{...r,cursor:"pointer",backgroundRepeat:"no-repeat",backgroundPosition:"right 8px center",backgroundSize:"16px",paddingRight:"32px",backgroundImage:`url("data:image/svg+xml;utf8,<svg
|
|
343
|
+
`,ke=G.createContext(void 0),L=()=>{const e=G.useContext(ke);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class ie{map={};register(r,t){if(!r||typeof r!="string")throw new Error("Registry key must be a non-empty string");this.map[r]=t}get(r){if(!(!r||typeof r!="string"))return this.map[r]}has(r){return!r||typeof r!="string"?!1:r in this.map}list(){return Object.keys(this.map)}entries(){return Object.entries(this.map)}values(){return Object.values(this.map)}size(){return Object.keys(this.map).length}unregister(r){return r in this.map?(delete this.map[r],!0):!1}clear(){this.map={}}registerAll(r){Array.isArray(r)?r.forEach(([t,n])=>{t&&typeof t=="string"&&this.register(t,n)}):r&&typeof r=="object"&&Object.entries(r).forEach(([t,n])=>{t&&typeof t=="string"&&this.register(t,n)})}getOrDefault(r,t){const n=this.get(r);return n!==void 0?n:t}}const ar=typeof process<"u"&&process.env.NODE_ENV==="test";function or(e,r=300,t){const n=G.useRef(),a=G.useRef(e),o=G.useRef(null),c=t?.leading===!0,i=t?.trailing!==!1;G.useEffect(()=>{a.current=e},[e]),G.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const s=p=>{a.current(...p)},m=G.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=void 0),o.current=null},[]),l=G.useCallback(()=>{n.current&&i&&o.current&&(clearTimeout(n.current),n.current=void 0,s(o.current),o.current=null)},[i]);return{callback:G.useCallback((...p)=>{if(ar){s(p);return}const h=c&&!n.current;o.current=p,h&&s(p),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=void 0,i&&o.current&&(s(o.current),o.current=null)},r)},[c,i,r]),cancel:m,flush:l}}const V={field:"reactaform-field",label:"reactaform-label",input:"reactaform-input",textInput:"reactaform-input--text",inputNumber:"reactaform-input--number",inputSelect:"reactaform-select",rangeInput:"reactaform-input--range",button:"reactaform-button"},B=(...e)=>{const r=[];for(const t of e)t&&(typeof t=="string"?r.push(t):typeof t=="object"&&Object.entries(t).forEach(([n,a])=>{a&&r.push(n)}));return r.join(" ")};function ne(e){return e.toLowerCase().includes("dark")}function _r(e){if(!e)return!1;const r=e.trim();let t=0,n=0,a=0;if(r.startsWith("#")){const c=r.substring(1);c.length===3||c.length===4?(t=parseInt(c[0]+c[0],16),n=parseInt(c[1]+c[1],16),a=parseInt(c[2]+c[2],16)):(c.length===6||c.length===8)&&(t=parseInt(c.substring(0,2),16),n=parseInt(c.substring(2,4),16),a=parseInt(c.substring(4,6),16))}else if(r.startsWith("rgb")){const c=r.match(/\d+(\.\d+)?/g);c&&c.length>=3&&(t=parseFloat(c[0]),n=parseFloat(c[1]),a=parseFloat(c[2]))}else return!1;return(t*299+n*587+a*114)/1e3<128}const Kr=()=>d.jsxs("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),d.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Gr=({content:e,size:r="medium",animation:t=!0})=>{const{t:n,theme:a,formStyle:o,fieldStyle:c}=L(),[i,s]=u.useState(!1),[m,l]=u.useState({x:0,y:0}),[f,p]=u.useState(!1),h=u.useRef(null),w=u.useRef(null),j=u.useRef(null),b=u.useId(),y=ne(a),[N,M]=u.useState(void 0);u.useLayoutEffect(()=>{if(!h.current)return;const E="rgba(255,255,255,0.1)",g=getComputedStyle(h.current).getPropertyValue("--reactaform-primary-bg").trim();if(g&&typeof CSS<"u"&&CSS.supports?.("color: color-mix(in srgb, red, blue)")){const v=_r(g)?"black":"white";M(`color-mix(in srgb, var(--reactaform-primary-bg) 85%, ${v} 15%)`)}else M(E)},[]);const F=u.useMemo(()=>{const x={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:N??(y?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"),color:`var(--reactaform-text-color, ${y?"#f0f0f0":"#333"})`,border:`1px solid ${y?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:t?"all 0.2s ease":void 0,marginLeft:"0.3em"},text:{...{small:{padding:"4px 8px",fontSize:"11px",maxWidth:"200px"},medium:{padding:"6px 10px",fontSize:"12px",maxWidth:"240px"},large:{padding:"8px 12px",fontSize:"13px",maxWidth:"280px"}}[r],position:"fixed",backgroundColor:`var(--reactaform-tooltip-color-bg, ${y?"rgba(45,45,45,0.95)":"rgba(34, 10, 170, 0.92)"})`,color:`var(--reactaform-tooltip-color, ${y?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${y?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:y?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,pointerEvents:"none",transition:t?"opacity 0.2s ease":void 0,whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,pointerEvents:"auto"}},g=(C,k,S)=>{const $=C?.[k];return(S&&$?$[S]:void 0)??{}};return{icon:{...x.icon,...g(o,"tooltip","icon"),...g(c,"tooltip","icon")},text:{...x.text,...g(o,"tooltip","text"),...g(c,"tooltip","text")},textVisible:x.textVisible}},[y,r,t,o,c,N]);u.useLayoutEffect(()=>{if(!i||!h.current||!w.current){p(!1);return}const E=h.current.getBoundingClientRect();j.current=E;const x=w.current.getBoundingClientRect(),g=8,v=window.innerWidth,C=window.innerHeight,k=-4;let S=E.right+g,A=E.top+E.height/2-x.height/2+k;S+x.width>v-g&&(S=E.left-g-x.width),S=Math.max(g,Math.min(S,v-x.width-g)),A=Math.max(g,Math.min(A,C-x.height-g)),l({x:S,y:A}),p(!0);const $=h.current.closest("[data-reactaform-theme]"),W=document.getElementById("popup-root");if($&&W){const ce=getComputedStyle($);W.style.setProperty("--reactaform-tooltip-color-bg",ce.getPropertyValue("--reactaform-tooltip-color-bg")),W.style.setProperty("--reactaform-tooltip-color",ce.getPropertyValue("--reactaform-tooltip-color"))}},[i]);const I=typeof document<"u"?document.getElementById("popup-root"):null,R=d.jsx("div",{ref:w,"data-tooltip-id":b,style:{...F.text,transform:f?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...f?F.textVisible:{},top:m.y,left:m.x},children:n(e)});return d.jsxs(d.Fragment,{children:[d.jsx("span",{"data-testid":"tooltip-icon",ref:h,"aria-describedby":i?b:void 0,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{...F.icon},children:d.jsx(Kr,{})}),i&&(I?fe.createPortal(R,I):R)]})},sr=u.memo(Gr),be=u.memo(({field:e,error:r,children:t,showLabel:n=!0})=>{const{t:a}=L(),o=e.labelLayout==="column-center"?"center":"left",c=u.useMemo(()=>{const m={display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)"};return m["--label-align"]=o,m},[o]),i=u.useMemo(()=>({textAlign:o,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"}),[o]),s=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"}),[]);return d.jsxs("div",{className:`${V.field} column-layout`,style:c,children:[n&&d.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:i,children:a(e.displayName)}),d.jsxs("div",{style:s,children:[d.jsx("div",{style:{flex:1,minWidth:0},children:t}),e.tooltip&&d.jsx(sr,{content:e.tooltip})]}),r&&d.jsx(je,{id:`${e.name}-error`,children:r})]})});be.displayName="ColumnFieldLayout";const ir=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>{const{t:a}=L(),o=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"3px"}),[]);return d.jsxs("div",{className:`${V.field} row-layout`,children:[d.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:{textAlign:"left"},children:a(e.displayName)}),d.jsxs("div",{children:[d.jsxs("div",{style:o,children:[n?d.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end"},children:t}):t,e.tooltip&&d.jsx(sr,{content:e.tooltip})]}),r&&d.jsx(je,{id:`${e.name}-error`,children:r})]})]})});ir.displayName="RowFieldLayout";const z=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?d.jsx(be,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?d.jsx(be,{field:e,error:r,showLabel:!1,children:t}):d.jsx(ir,{field:e,error:r,rightAlign:n,children:t}));z.displayName="StandardFieldLayout";const je=u.memo(({children:e,id:r})=>{const t=u.useMemo(()=>({color:"var(--reactaform-error-color, red)",fontSize:"13px",marginTop:"4px",fontWeight:"var(--reactaform-font-weight)",display:"flex",flex:1,justifyContent:"flex-start",alignItems:"flex-start",userSelect:"none"}),[]);return d.jsx("div",{id:r,style:t,children:e})});je.displayName="ErrorDiv";const cr=u.memo(({name:e,onChange:r})=>{const{t}=L();return d.jsxs("div",{style:{marginBottom:16},children:[d.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[d.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),d.jsx("input",{id:"instance-name-input",type:"text",value:e,className:B(V.input,V.textInput),onChange:n=>r(n.target.value),placeholder:t("Enter instance name")})]}),d.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});cr.displayName="InstanceName";class Jr extends ie{registerInCategory(r,t,n){this.get(r)||this.register(r,{});const a=this.get(r);a[t]=n}getFromCategory(r,t){return this.get(r)?.[t]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const lr=new ie,ur=new Jr,Ee=new ie;function mr(e,r){lr.register(e,r)}function fr(e,r,t){ur.registerInCategory(e,r,t)}function dr(e,r){if(zt(e)){console.warn(`[ReactaForm] Can't override builtin type field validation handler for type "${e}".`);return}Ee.register(e,r)}function T(e,r){Ee.register(e,r)}function pr(e,r){return ur.getFromCategory(e,r)||null}function gr(e){return lr.get(e)||null}function hr(e){return Ee.get(e)||null}function Yr(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const qe=new Map,Ue=new Map;function Ne(e,r,t,n){if(!r||!r.validationHandlerName)return null;let a,o;if(typeof r.validationHandlerName=="string")a=e,o=r.validationHandlerName;else if(Array.isArray(r.validationHandlerName)){const[s,m]=r.validationHandlerName;if(m)a=s,o=m;else if(s)a=e,o=s;else return null}else return null;const c=`${a}:${o}`;let i=qe.get(c);if(i===void 0&&(i=pr(a,o)||null,qe.set(c,i)),i)try{return i(r.name,t,n)||null}catch(s){return String(s instanceof Error?s.message:s)}return null}function Xr(e,r,t,n){return Ne(e,r,t,n)}function br(e,r,t,n){const a=hr(r.type);if(a){const o=a(r,t,n);if(o)return o}else if(String(t??"").trim()==="")return r.required?n("Value required"):null;return Ne(e,r,t,n)}async function Zr(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const n=e.validationHandlerName;let a=Ue.get(n);if(a===void 0&&(a=gr(n)||null,Ue.set(n,a)),a)try{const o=a(r,t);return Yr(o)?await o||null:o||null}catch(o){return[String(o instanceof Error?o.message:o)]}return null}function O(e,r){const{definitionName:t,t:n,fieldValidationMode:a}=L();return u.useCallback(o=>a==="realTime"?br(t,e,o,n):r??null,[t,e,n,a,r])}const Qr=({field:e,value:r=!1,onChange:t,onError:n,error:a})=>{const{t:o}=L(),i=O(e,a)(r);u.useEffect(()=>{a||n?.(i)},[i,a,n]);const s=u.useCallback(f=>{t?.(f.target.checked)},[t]),m=u.useCallback(f=>{(f.key===" "||f.key==="Space"||f.key==="Spacebar"||f.code==="Space"||f.key==="Enter")&&(f.preventDefault(),t?.(!r))},[t,r]),l=e.name;return d.jsx(z,{field:e,rightAlign:!1,error:i,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[d.jsx("label",{className:V.label,htmlFor:l,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),d.jsx("input",{id:l,"data-testid":"boolean-checkbox",type:"checkbox",checked:r,onChange:s,onKeyDown:m,"aria-checked":r,"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0,style:{cursor:"pointer",margin:"8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",accentColor:"#0000FF"}})]})})};function _({value:e,onChange:r,onError:t,validate:n}){const a=u.useRef(null),o=u.useRef(null),c=u.useRef(t),[i,s]=u.useState(null);u.useEffect(()=>{c.current=t},[t]),u.useEffect(()=>{const l=String(e??"");if(!(document.activeElement===a.current)){const p=n(l);p!==o.current&&(o.current=p,c.current?.(p??null),s(p)),a.current&&a.current.value!==l&&(a.current.value=l)}},[e,n]);const m=u.useCallback(l=>{const f=l.target.value,p=n(f);p!==o.current&&(o.current=p,s(p),c.current?.(p??null)),r?.(f)},[r,n]);return{inputRef:a,error:i,handleChange:m}}const We=[{label:"Black",value:"#000000"},{label:"White",value:"#ffffff"},{label:"Red",value:"#ff0000"},{label:"Green",value:"#008000"},{label:"Blue",value:"#0000ff"},{label:"Yellow",value:"#ffff00"},{label:"Cyan",value:"#00ffff"},{label:"Magenta",value:"#ff00ff"},{label:"Orange",value:"#ffa500"},{label:"Purple",value:"#800080"},{label:"Brown",value:"#a52a2a"},{label:"Gray",value:"#808080"},{label:"Light Gray",value:"#d3d3d3"},{label:"Pink",value:"#ffc0cb"}],et=/^#([0-9A-F]{3}){1,2}$/i,rt="#000000",tt=e=>et.test(e),pe=e=>{if(!e||!tt(e))return rt;const r=e.toLowerCase();return r.length===4?"#"+r.slice(1).split("").map(t=>t+t).join(""):r},nt=e=>{const r=parseInt(e.slice(1),16);return{r:r>>16&255,g:r>>8&255,b:r&255}},at=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),c=O(e,a),i=u.useMemo(()=>pe(r),[r]),{inputRef:s,error:m,handleChange:l}=_({value:i,onChange:t,onError:n,validate:c}),[f,p]=u.useState(i);u.useEffect(()=>{a||n?.(m)},[m,a,n]),u.useEffect(()=>{p(i)},[i]);const h=u.useCallback(F=>{const I=pe(F.target.value);p(I),l({target:{value:I}})},[l]),w=u.useCallback(F=>{const I=pe(F.target.value);p(I),l({target:{value:I}})},[l]),b=u.useMemo(()=>new Set(We.map(F=>F.value)),[]).has(f),{r:y,g:N,b:M}=u.useMemo(()=>nt(f),[f]);return d.jsx(z,{field:e,error:m,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[d.jsxs("select",{id:e.name,value:f,onChange:w,className:B(V.input,V.inputSelect),"aria-invalid":!!m,children:[We.map(F=>d.jsx("option",{value:F.value,children:o(F.label)},F.value)),!b&&d.jsxs("option",{value:f,children:["(",y,", ",N,", ",M,")"]})]}),d.jsx("label",{style:{width:"2.5em",height:"1.8em",border:"1px solid #ccc",borderRadius:4,backgroundColor:f,cursor:"pointer",overflow:"hidden",flexShrink:0},children:d.jsx("input",{ref:s,id:`${e.name}-color`,type:"color",defaultValue:f,onChange:h,style:{opacity:0,width:"100%",height:"100%"},"aria-invalid":!!m})})]})})},_e=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Ke=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return _e(e)?e:"";const t=_e(e);if(t){const n=t.getUTCFullYear(),a=String(t.getUTCMonth()+1).padStart(2,"0"),o=String(t.getUTCDate()).padStart(2,"0");return`${n}-${a}-${o}`}return""},ot=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),c=Ke(r),{inputRef:i,error:s,handleChange:m}=_({value:c,onChange:t,onError:n,validate:o});return u.useEffect(()=>{a||n?.(s)},[s,a,n]),d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"date",ref:i,defaultValue:Ke(r),onChange:m,className:B(V.input,V.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},st=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,theme:c,formStyle:i,fieldStyle:s}=L(),m=u.useRef(null),l=u.useRef(n),[f,p]=u.useState(!1),[h,w]=u.useState(null);u.useEffect(()=>{l.current=n},[n]);const j=O(e,a),[b,y]=u.useState(null),N=u.useRef(null);u.useEffect(()=>{const g=String(r??"");let v=j(g);if(v&&e.options.length>0){const C=String(e.options[0].value);t?.(C),v=null}v!==N.current&&(N.current=v,y(v),l.current?.(v??null))},[r,j,t,e.options]);const M=()=>{if(!m.current)return;const g=m.current.getBoundingClientRect();w({x:g.left,y:g.bottom}),p(v=>!v)},F=g=>{const v=j(g);v!==N.current&&(N.current=v,y(v),l.current?.(v??null)),t?.(g),p(!1)},I=u.useMemo(()=>{const g=e.options.find(v=>String(v.value)===String(r));return g?o(g.label):""},[e.options,r,o]),R=(g,v,C)=>{if(!v)return{};const S=g?.[v];return(C&&S?S[C]:void 0)??{}},E=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5em)",display:"flex",alignItems:"center",boxSizing:"border-box",padding:"0 0.75em",cursor:"pointer",position:"relative",textAlign:"left",...R(i,"dropdown","control"),...R(s,void 0,"control")}),[i,s]),x=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...R(i,"dropdown","arrow"),...R(s,void 0,"arrow")}),[i,s]);return d.jsxs("div",{children:[d.jsx(z,{field:e,error:b,children:d.jsxs("div",{ref:m,className:"reactaform-input",style:E,onClick:M,tabIndex:0,role:"combobox","aria-haspopup":"listbox","aria-expanded":f,"aria-invalid":!!b,"aria-describedby":b?`${e.name}-error`:void 0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),M())},children:[d.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingRight:"1.8em",display:"block"},children:I}),d.jsx("span",{style:x,"aria-hidden":!0,children:"▼"})]})}),f&&h&&d.jsx(it,{position:h,options:e.options,selectedValue:String(r),onSelect:F,onClose:()=>p(!1),controlRef:m,theme:c,t:o})]})},it=({position:e,options:r,selectedValue:t,onSelect:n,onClose:a,controlRef:o,theme:c,t:i})=>{const s=u.useRef(null),[m,l]=u.useState(-1),{formStyle:f,fieldStyle:p}=L(),h=ne(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const x=o.current.closest("[data-reactaform-theme]"),g=document.getElementById("popup-root");if(x&&g){const v=getComputedStyle(x);g.style.setProperty("--reactaform-secondary-bg",v.getPropertyValue("--reactaform-secondary-bg")),g.style.setProperty("--reactaform-text-color",v.getPropertyValue("--reactaform-text-color")),g.style.setProperty("--reactaform-option-menu-hover-bg",v.getPropertyValue("--reactaform-option-menu-hover-bg"))}},[o]);const w=(x,g,v)=>{if(!g)return{};const k=x?.[g];return(v&&k?k[v]:void 0)??{}},j=u.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...w(f,"dropdown","popup"),...w(p,void 0,"popup")}),[f,p]),b=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...w(f,"dropdown","option"),...w(p,void 0,"option")}),[f,p]);u.useEffect(()=>{const x=g=>{const v=g.target;!s.current?.contains(v)&&!o.current?.contains(v)&&a()};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[a,o]),u.useEffect(()=>{if(s.current&&r.length>0){const x=r.findIndex(g=>String(g.value)===t);requestAnimationFrame(()=>l(x>=0?x:0))}},[r,t]),u.useEffect(()=>{if(!s.current||m<0)return;const x=s.current.querySelector(`#opt-${m}`);x&&requestAnimationFrame(()=>x.focus())},[m]);const y=250,N=200,[M,F]=u.useState(null),[I,R]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const x=()=>{let C=e.x,k=e.y,S=y;const A=o?.current;if(A){const $=A.getBoundingClientRect();C=$.left,k=$.bottom,S=Math.max(80,Math.round($.width))}C=Math.min(C,window.innerWidth-S),k=Math.min(k,window.innerHeight-N),F({left:C,top:k}),R(S)};x(),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x);let g=null;const v=o?.current;return typeof ResizeObserver<"u"&&v&&(g=new ResizeObserver(()=>x()),g.observe(v)),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x),g&&v&&g.unobserve(v)}},[o,e.x,e.y]),typeof window>"u")return null;let E=document.getElementById("popup-root");return E||(E=document.createElement("div"),E.id="popup-root",document.body.appendChild(E)),fe.createPortal(d.jsx("div",{ref:s,role:"listbox","aria-activedescendant":m>=0?`opt-${m}`:void 0,style:{position:"fixed",top:M?M.top:e.y,left:M?M.left:e.x,width:I??y,...j},"data-reactaform-theme":c??"light",children:r.map((x,g)=>{const v=String(x.value)===t,C=h?"var(--reactaform-option-menu-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-option-menu-hover-bg, #eee)",k={...b,background:g===m?C:b.background,fontWeight:v?"bold":"normal"};return d.jsx("div",{id:`opt-${g}`,onMouseDown:S=>{S.stopPropagation(),n(String(x.value))},onKeyDown:S=>{const A=r.length;switch(S.key){case"ArrowDown":S.preventDefault(),l($=>($+1)%A);break;case"ArrowUp":S.preventDefault(),l($=>($-1+A)%A);break;case"Home":S.preventDefault(),l(0);break;case"End":S.preventDefault(),l(A-1);break;case"Enter":case" ":S.preventDefault(),S.stopPropagation(),n(String(x.value));break;case"Escape":S.preventDefault(),a(),o?.current?.focus();break}},tabIndex:g===m?0:-1,role:"option","aria-selected":v,style:k,onMouseEnter:S=>{S.currentTarget.style.background=C,l(g)},onMouseLeave:S=>{S.currentTarget.style.background="transparent",l(A=>A===g?-1:A)},children:i(x.label)},String(x.value))})}),E)},ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:i,children:d.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:c,onChange:s,className:B(V.input,V.textInput),"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},lt=({field:e})=>{const{theme:r}=L(),{color:t=ne(r)?"#444444":"#CCCCCC",thickness:n=1,margin:a="8px 0"}=e;return d.jsx("div",{style:{width:"auto",height:"0",borderTop:`${n}px solid ${t}`,margin:a}})},ut=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,theme:c}=L(),[i,s]=u.useState(!1),m=u.useRef(null),l=u.useRef(n),f=u.useRef(null),[p,h]=u.useState(null),w=ne(c);u.useEffect(()=>{l.current=n},[n]);const j=(g,v)=>v.some(C=>C.name===g.name&&C.size===g.size&&C.lastModified===g.lastModified),b=O(e,a);u.useEffect(()=>{const g=b(r??[]);t?.(r),g!==f.current&&(f.current=g,h(g),l.current?.(g??null))},[r,b]);const y=g=>{const v=g.target.files;let C=null;if(v&&v.length>0){const S=Array.from(v);if(e.multiple){const A=Array.isArray(r)?r:[],$=S.filter(W=>!j(W,A));C=[...A,...$]}else C=S[0]}const k=b(C??[]);k!==f.current&&(f.current=k,h(k),l.current?.(k??null)),t?.(C),g.target&&(g.target.value="")},N=g=>{g.preventDefault(),g.stopPropagation(),s(!1);const v=g.dataTransfer.files;if(v&&v.length>0){const C=Array.from(v);let k=null;if(e.multiple){const A=Array.isArray(r)?r:[],$=C.filter(W=>!j(W,A));k=[...A,...$]}else k=C[0];const S=b(k);S!==f.current&&(f.current=S,h(S),l.current?.(S??null)),t?.(k)}},M=g=>{g.preventDefault(),g.stopPropagation(),s(!0)},F=g=>{g.preventDefault(),g.stopPropagation(),s(!1)},I=g=>{if(Array.isArray(r)&&typeof g=="number"){const v=r.filter((S,A)=>A!==g),C=v.length>0?v:null,k=b(C??[]);k!==f.current&&(f.current=k,h(k),l.current?.(k??null)),t?.(C)}else{const v=b([]);v!==f.current&&(f.current=v,h(v),l.current?.(v??null)),t?.(null)}},R=()=>{const g=Array.isArray(r)?r:r?[r]:[];return g.length===0?null:d.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:g.map((v,C)=>d.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[d.jsx("input",{type:"text",value:v.name,disabled:!0,readOnly:!0,title:v.name,className:"reactaform-input",style:{flex:1,cursor:"default",opacity:.8,minWidth:0}}),d.jsx("button",{type:"button",onClick:()=>I(Array.isArray(r)?C:void 0),"aria-label":o("Remove file"),style:{background:"transparent",border:"none",color:"var(--reactaform-color-error, #ef4444)",cursor:"pointer",padding:"2px 6px",fontSize:"1.125rem",lineHeight:1,borderRadius:"4px",transition:"background-color 0.2s",flexShrink:0},onMouseEnter:k=>{k.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:k=>{k.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${v.name}-${C}`))})},[E,x]=u.useState(!1);return d.jsx(z,{field:e,error:p,children:d.jsxs("div",{style:{width:"100%"},children:[d.jsxs("div",{className:"reactaform-input",onDrop:N,onDragOver:M,onDragLeave:F,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),style:{position:"relative",borderStyle:"dashed",borderColor:i?"var(--reactaform-color-primary, #2563eb)":E?"var(--reactaform-border-hover, #4A4A4A)":p?"var(--reactaform-color-error, #ef4444)":void 0,borderWidth:"1px",borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:i?`var(--reactaform-bg-hover, ${w?"#070707":"#eff6ff"})`:void 0,transition:"all 0.2s ease",cursor:"pointer",minHeight:"var(--reactaform-input-height, 34px)",width:"100%",maxWidth:"100%",alignSelf:"stretch",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",userSelect:"none"},onClick:()=>m.current?.click(),onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),m.current?.click())},role:"button","aria-label":e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop"),"aria-invalid":!!p,"aria-describedby":p?`${e.name}-error`:void 0,children:[d.jsx("input",{id:e.name,ref:m,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:y}),d.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),d.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:i?o("Drop files here"):e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop")}),e.accept&&d.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:i?0:1,transition:"opacity 0.15s ease",pointerEvents:i?"none":"auto"},children:e.accept})]}),R()]})})},mt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:i,error:s,handleChange:m}=_({value:c,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:i,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o}),m=a??i;return d.jsx(z,{field:e,error:m,children:d.jsx("input",{id:e.name,type:"text",ref:c,defaultValue:String(r??""),onChange:s,className:B(V.input,V.inputNumber),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})};function dt(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const pt=({field:e,value:r})=>{const{language:t,t:n}=L(),a=e.alignment||"center",o={left:"flex-start",center:"center",right:"flex-end"},c=typeof r=="string"?r:"";let i=c&&c.trim()!==""?c:typeof e.defaultValue=="string"?e.defaultValue:"";i&&!i.startsWith("/")&&(i=`${dt()}${i}`);const s=e.localized?.split(";").map(b=>b.trim()),[m,l]=u.useState(i||""),f=u.useRef(i||null);if(u.useEffect(()=>{if(!i)return;const b=i.split("/"),y=b.pop(),N=y.lastIndexOf(".");if(N===-1)return;const M=y.substring(0,N),F=y.substring(N);let I=null;s?.includes(t)&&(I=`${M}_${t}${F}`);const R=new AbortController;if(I){const E=[...b,I].join("/");fetch(E,{method:"HEAD",signal:R.signal}).then(x=>{const g=x.ok?E:i;g!==f.current&&(f.current=g,l(g))}).catch(()=>{i!==f.current&&(f.current=i,l(i))})}else{const E=i;E!==f.current&&(f.current=E,requestAnimationFrame(()=>l(E)))}return()=>{R.abort()}},[i,t,s]),!m)return null;const{width:p,height:h}=e,w={},j={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return p&&h?(w.width=p,w.height=h,j.width=`${p}px`,j.height=`${h}px`):p&&!h?(w.width=p,j.width=`${p}px`,j.height="auto"):!p&&h&&(w.height=h,j.width="auto",j.height=`${h}px`),d.jsx(z,{field:e,children:d.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:o[a]||"center",margin:"0 0"},children:d.jsx("img",{src:m,alt:n?.(e.displayName||"Image")||e.displayName||"Image",...w,style:j})})})},gt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:i,error:s,handleChange:m}=_({value:c,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:s,children:d.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:i,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},yr=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:i,children:d.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:s,className:B(V.input,V.inputNumber),"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})};yr.displayName="IntegerInput";const ht=u.memo(yr),bt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:i,children:d.jsx("textarea",{id:e.name,defaultValue:String(r??""),ref:c,onChange:s,style:{resize:"vertical",minHeight:e.minHeight??"80px",width:"100%",boxSizing:"border-box"},className:B(V.input,V.textInput),"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},yt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=u.useRef(n);u.useEffect(()=>{o.current=n},[n]);const{t:c,theme:i,formStyle:s,fieldStyle:m}=L(),l=(C,k,S)=>{if(!k)return{};const $=C?.[k];return(S&&$?$[S]:void 0)??{}},f=u.useRef(null),[p,h]=u.useState(!1),[w,j]=u.useState(null),b=u.useMemo(()=>e.options.map(C=>({value:C.value,label:c(C.label)})),[e.options,c]),y=u.useMemo(()=>{const C=Array.isArray(r)?r:[],k=new Set(b.map(S=>S.value));return C.filter(S=>k.has(S))},[r,b]),N=O(e,a),[M,F]=u.useState(null),I=u.useRef(null);u.useEffect(()=>{const C=N(Array.isArray(r)?r:[]);C!==I.current&&(I.current=C,F(C),o.current?.(C??null))},[r,N]);const R=()=>{if(!f.current)return;const C=f.current.getBoundingClientRect();j({x:C.left,y:C.bottom}),h(k=>!k)},E=C=>{const k=y.includes(C)?y.filter(A=>A!==C):[...y,C],S=N(k);S!==I.current&&(I.current=S,F(S),o.current?.(S??null)),t?.(k)},x=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",textAlign:"left",...l(s,"multiSelect","control"),...l(m,void 0,"control")}),[s,m]),g=u.useMemo(()=>({position:"absolute",right:"1.5em",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",padding:0,...l(s,"multiSelect","clearButton"),...l(m,void 0,"clearButton")}),[s,m]),v=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...l(s,"multiSelect","arrow"),...l(m,void 0,"arrow")}),[s,m]);return d.jsxs("div",{children:[d.jsx(z,{field:e,error:M,children:d.jsx("div",{style:{width:"100%"},children:d.jsxs("div",{ref:f,className:"reactaform-multiselection-control reactaform-input",style:x,onClick:R,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!M,"aria-describedby":M?`${e.name}-error`:void 0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),R())},children:[d.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[y.length," / ",b.length," selected"]}),y.length>0&&d.jsx("button",{type:"button","aria-label":"Clear selections",onClick:C=>{C.stopPropagation(),t?.([])},style:g,children:d.jsx("span",{style:g,"aria-hidden":!0,children:"✖"})}),d.jsx("span",{style:v,"aria-hidden":!0,children:"▼"})]})})}),p&&w&&d.jsx(vt,{position:w,options:b,selectedValues:y,onToggleOption:E,onClose:()=>h(!1),controlRef:f,theme:i})]})},vt=({position:e,options:r,selectedValues:t,onToggleOption:n,onClose:a,controlRef:o,theme:c})=>{const i=u.useRef(null),[s,m]=u.useState(-1),{formStyle:l,fieldStyle:f}=L(),p=ne(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const E=o.current.closest("[data-reactaform-theme]"),x=document.getElementById("popup-root");if(E&&x){const g=getComputedStyle(E);x.style.setProperty("--reactaform-secondary-bg",g.getPropertyValue("--reactaform-secondary-bg")),x.style.setProperty("--reactaform-text-color",g.getPropertyValue("--reactaform-text-color")),x.style.setProperty("--reactaform-option-menu-hover-bg",g.getPropertyValue("--reactaform-option-menu-hover-bg"))}},[o]);const h=(E,x,g)=>{if(!x)return{};const C=E?.[x];return(g&&C?C[g]:void 0)??{}},w=u.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...h(l,"multiSelect","popup"),...h(f,void 0,"popup")}),[l,f]),j=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...h(l,"multiSelect","option"),...h(f,void 0,"option")}),[l,f]);u.useEffect(()=>{const E=x=>{const g=x.target;!i.current?.contains(g)&&!o.current?.contains(g)&&a()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[a,o]),u.useEffect(()=>{i.current&&r.length>0&&requestAnimationFrame(()=>m(E=>E===-1?0:E))},[r.length]),u.useEffect(()=>{if(!i.current||s<0)return;const E=i.current.querySelector(`#multi-opt-${s}`);E&&requestAnimationFrame(()=>E.focus())},[s]);const b=250,y=200,[N,M]=u.useState(null),[F,I]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const E=()=>{let v=e.x,C=e.y,k=b;const S=o?.current;if(S){const A=S.getBoundingClientRect();v=A.left,C=A.bottom,k=Math.max(80,Math.round(A.width))}v=Math.min(v,window.innerWidth-k),C=Math.min(C,window.innerHeight-y),M({left:v,top:C}),I(k)};E(),window.addEventListener("scroll",E,!0),window.addEventListener("resize",E);let x=null;const g=o?.current;return typeof ResizeObserver<"u"&&g&&(x=new ResizeObserver(()=>E()),x.observe(g)),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E),x&&g&&x.unobserve(g)}},[o,e.x,e.y]),typeof window>"u")return null;let R=document.getElementById("popup-root");return R||(R=document.createElement("div"),R.id="popup-root",document.body.appendChild(R)),fe.createPortal(d.jsx("div",{ref:i,role:"listbox","aria-activedescendant":s>=0?`multi-opt-${s}`:void 0,style:{position:"fixed",top:N?N.top:e.y,left:N?N.left:e.x,width:F??b,...w},"data-reactaform-theme":c??"light",children:r.map((E,x)=>{const g=t.includes(E.value),v=p?"var(--reactaform-option-menu-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-option-menu-hover-bg, #eee)",C={...j,background:x===s?v:j.background};return d.jsxs("div",{id:`multi-opt-${x}`,onMouseDown:k=>{k.stopPropagation(),n(E.value)},onKeyDown:k=>{const S=r.length;switch(k.key){case"ArrowDown":k.preventDefault(),m(A=>(A+1)%S);break;case"ArrowUp":k.preventDefault(),m(A=>(A-1+S)%S);break;case"Home":k.preventDefault(),m(0);break;case"End":k.preventDefault(),m(S-1);break;case"Enter":case" ":k.preventDefault(),k.stopPropagation(),n(E.value);break;case"Escape":k.preventDefault(),a(),o?.current?.focus();break}},tabIndex:x===s?0:-1,role:"option","aria-selected":g,style:C,onMouseEnter:k=>{k.currentTarget.style.background=v,m(x)},onMouseLeave:k=>{k.currentTarget.style.background="transparent",m(S=>S===x?-1:S)},children:[d.jsx("input",{type:"checkbox",checked:g,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:p?"#10b981":"#22c55e",cursor:"pointer"}}),E.label]},E.value)})}),R)},xt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:String(r??""),onChange:t,onError:n,validate:o}),m=Math.max(1,Math.round(e.step??1));return d.jsx(z,{field:e,error:i,children:d.jsx("input",{id:e.name,type:"number",defaultValue:String(r??""),ref:c,min:e.min??void 0,max:e.max??void 0,step:m,onChange:s,style:{width:"100%",height:"100%"},className:V.input,"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},wt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:i,children:d.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:c,onChange:s,className:B(V.input,V.textInput),"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},St=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),c=O(e,a),i=e.layout?.toLowerCase()==="horizontal"?"row":"column",s=u.useRef(n);u.useEffect(()=>{s.current=n},[n]);const[m,l]=u.useState(null),f=u.useRef(null),p=u.useCallback(b=>{b!==f.current&&(f.current=b,l(b),s.current?.(b))},[]);u.useEffect(()=>{const b=r!=null?String(r):"",y=c(b);if(y&&e.options.length>0){const N=String(e.options[0].value);t?.(N)}p(y)},[r,e.options,c,t,p]);const h=b=>{const y=b.target.value,N=c(y);p(N),t?.(y)},w={display:"flex",flexDirection:i,flexWrap:i==="row"?"wrap":"nowrap",gap:i==="row"?"12px":"4px",alignItems:i==="row"?"center":"stretch",width:"100%",padding:i==="row"?"8px":void 0,boxSizing:"border-box"},j={display:i==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:i==="column"?6:0,cursor:"pointer",width:i==="column"?"100%":void 0,justifyContent:"flex-start"};return d.jsx(z,{field:e,error:m,children:d.jsx("div",{className:V.input,"aria-labelledby":`${e.name}-label`,"aria-invalid":!!m,style:w,children:e.options.map(b=>{const y=String(b.value),N=`${e.name}-${y}`;return d.jsxs("label",{className:B(V.label),style:j,onMouseDown:M=>M.preventDefault(),onClick:()=>{String(r??"")!==y&&h({target:{value:y}})},children:[d.jsx("input",{id:N,type:"radio",name:e.name,value:y,checked:String(r??"")===y,onChange:h,style:{width:"1.1em",height:"1.1em"}}),d.jsx("span",{style:{userSelect:"none",textAlign:i==="column"?"left":void 0,flex:i==="column"?1:void 0,fontWeight:400},children:o(b.label)})]},y)})})})},Ct={display:"flex",gap:4},kt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},jt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),c=O(e,a),i=e.max??5,s=e.icon?.trim()||"★",[m,l]=u.useState(null),f=u.useRef([]),p=u.useMemo(()=>Math.min(Math.max(r??0,0),i),[r,i]),h=u.useMemo(()=>c(p)??null,[c,p]);u.useEffect(()=>{n?.(h)},[h,n]);const w=u.useCallback(b=>{const y=Math.min(Math.max(b,0),i);c(y),t?.(y)},[i,c,t]),j=u.useCallback((b,y)=>{switch(b.key){case"Enter":case" ":b.preventDefault(),w(y+1);break;case"ArrowRight":case"ArrowUp":b.preventDefault(),f.current[Math.min(i-1,y+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":b.preventDefault(),f.current[Math.max(0,y-1)]?.focus();break}},[i,w]);return d.jsx(z,{field:e,error:h,children:d.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!h,"aria-describedby":h?`${e.name}-error`:void 0,style:Ct,children:Array.from({length:i},(b,y)=>{const N=y<p,F=m!==null&&y<=m||N?"gold":"lightgray";return d.jsx("span",{ref:I=>f.current[y]=I,role:"radio",tabIndex:p>0?y===p-1?0:-1:y===0?0:-1,"aria-checked":N,"aria-label":`Rating ${y+1}`,title:o(`${e.displayName} ${y+1}`),onClick:()=>w(y+1),onKeyDown:I=>j(I,y),onMouseEnter:()=>l(y),onMouseLeave:()=>l(null),style:{...kt,color:F},children:s},y)})})})},Et=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=L(),c=O(e,a),{inputRef:i,error:s,handleChange:m}=_({value:r,onChange:t,onError:n,validate:c}),[l,f]=u.useState(!1),p=()=>f(h=>!h);return d.jsx(z,{field:e,error:s,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[d.jsx("input",{id:e.name,type:l?"text":"password",defaultValue:String(r??""),ref:i,onChange:m,className:B(V.input,V.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0}),d.jsx("button",{type:"button",onClick:p,"aria-label":o(l?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:l?"🙈":"👁️"})]})})},Nt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),c=e.min??0,i=e.max??100,[s,m]=u.useState(()=>isNaN(Number(r))?String(c):String(Number(r)));u.useEffect(()=>{const h=isNaN(Number(r))?String(c):String(Number(r));m(h)},[r,c]);const l=u.useMemo(()=>o(s)??null,[o,s]);u.useEffect(()=>{n?.(l)},[l,n]);const f=u.useCallback(h=>{const w=h.target.value;m(w),o(w),t?.(w)},[o,t]),p=isNaN(Number(s))?String(c):String(Number(s));return d.jsx(z,{field:e,error:l,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[d.jsx("input",{id:`${e.name}-range`,type:"range",value:p,onChange:f,min:c,max:i,step:"1.0",style:{padding:0,flex:1},className:V.rangeInput,"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0}),d.jsx("input",{id:e.name,type:"text",value:s,onChange:f,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:B(V.input,V.textInput),"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0})]})})},Ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,formStyle:c,fieldStyle:i,fieldValidationMode:s}=L(),l=O(e,a)(r);u.useEffect(()=>{s==="realTime"&&n?.(l)},[l,s,n]);const f=c,p=i,h=(F,I,R)=>{if(!I)return{};const E=F?.[I];return(R&&E?E[R]:void 0)??{}},w=u.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...h(f,"switch","label"),...h(p,void 0,"label")}),[f,p]),j=u.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...h(f,"switch","hiddenInput"),...h(p,void 0,"hiddenInput")}),[f,p]),b=u.useMemo(()=>({position:"absolute",cursor:"pointer",top:0,left:0,right:0,bottom:0,backgroundColor:"var(--reactaform-switch-off-bg, #ccc)",transition:"0.3s",borderRadius:24,borderWidth:2,borderStyle:"solid",borderColor:"transparent",...h(f,"switch","slider"),...h(p,void 0,"slider")}),[f,p]),y=u.useMemo(()=>({position:"absolute",height:16,width:16,left:2,bottom:2,backgroundColor:"white",transition:"0.3s",borderRadius:"50%",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.3)",...h(f,"switch","knob"),...h(p,void 0,"knob")}),[f,p]),N=!!r,M=()=>{t?.(!N)};return d.jsx(z,{field:e,error:null,rightAlign:!1,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[d.jsx("label",{className:V.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),d.jsxs("label",{style:w,children:[d.jsx("input",{id:e.name,type:"checkbox",checked:N,readOnly:!0,"aria-label":o(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:j,tabIndex:-1}),d.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":N,"aria-invalid":!1,"aria-describedby":void 0,onClick:M,onKeyDown:F=>{(F.key===" "||F.key==="Spacebar"||F.key==="Space"||F.key==="Enter")&&(F.preventDefault(),M())},className:`reactaform-switch ${N?"active checked on":""} `,style:N?{...b,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:b,children:d.jsx("span",{style:{...y,transform:N?"translateX(20px)":void 0}})})]})]})})},Ge=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e,a),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o});return d.jsx(z,{field:e,error:i,children:d.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:s,className:B(V.input,V.textInput),placeholder:e.placeholder,"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},It=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o}),m=a??i;return d.jsx(z,{field:e,error:m,children:d.jsx("input",{id:e.name,type:"time",ref:c,defaultValue:r,step:e.includeSeconds?1:60,onChange:s,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:B(V.input,V.textInput),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})};function Mt({pos:e,options:r,onClose:t,onClickOption:n}){const a=u.useRef(null),o=u.useRef(!1),[c,i]=u.useState({top:e?.y??0,left:e?.x??0,ready:!1}),s=typeof window<"u"?document.getElementById("popup-root")||document.body:null;return u.useEffect(()=>{function m(l){o.current||l.target.dataset?.popupMenu==="item"||a.current&&l.target instanceof Node&&!a.current.contains(l.target)&&t()}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[t]),u.useLayoutEffect(()=>{if(!a.current||!e||e.x==null||e.y==null)return;const m=a.current.getBoundingClientRect(),l=window.innerWidth,f=window.innerHeight;let p=e.x,h=e.y;p+m.width>l&&(p=Math.max(0,l-m.width-10)),h+m.height>f&&(h=Math.max(0,e.y-m.height-5)),i({top:h,left:p,ready:!0})},[e,r]),!s||r===void 0||r.length===0||!e||e.x==null||e.y==null?null:fe.createPortal(d.jsx("div",{ref:a,onMouseDown:m=>{m.stopPropagation()},style:{position:"fixed",top:c.top,left:c.left,visibility:c.ready?"visible":"hidden",backgroundColor:"var(--reactaform-primary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:"var(--reactaform-border-radius, 4px)",boxShadow:"var(--reactaform-shadow, 0 2px 10px rgba(0,0,0,0.2))",zIndex:9999,minWidth:"var(--reactaform-menu-min-width, 150px)",maxHeight:"var(--reactaform-menu-max-height, 300px)",overflowY:"auto",pointerEvents:"auto"},children:r.map((m,l)=>d.jsx("div",{"data-popup-menu":"item",onMouseDown:f=>{f.stopPropagation(),o.current=!0},onClick:f=>{f.stopPropagation(),f.preventDefault(),n(m),t(),setTimeout(()=>{o.current=!1},100)},style:{padding:"var(--reactaform-menu-item-padding, 8px 12px)",cursor:"pointer",fontSize:"var(--reactaform-menu-item-font-size, 0.8em)",borderBottom:l<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:f=>{f.currentTarget.style.backgroundColor="var(--reactaform-option-menu-hover-bg, #e0e0e0)"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"},children:m.label},m.label??l))}),s)}const Fe={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},Ie={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Me={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Ve={},Vt=new Set([...Object.keys(Fe),...Object.keys(Ie),...Object.keys(Me)]);for(const e of Vt){const r={},t=Fe[e]??[],n=Ie[e]??{},a=Me[e]??{};for(const o of t){const c=n[o];r[o]={name:typeof c=="string"?c:String(o),shortName:o,factor:Object.prototype.hasOwnProperty.call(a,o)?a[o]:void 0}}for(const[o,c]of Object.entries(n))if(!r[o]){const i=typeof c=="string"?c:String(o);r[o]={name:i,shortName:o,factor:Object.prototype.hasOwnProperty.call(a,o)?a[o]:void 0}}for(const[o,c]of Object.entries(a))r[o]||(r[o]={name:String(o),shortName:String(o),factor:c});Ve[e]=r}function vr(e,r,t){if(e==="C"){if(r==="F")return t*(9/5)+32;if(r==="K")return t+273.15}else if(e==="F"){if(r==="C")return(t-32)*5/9;if(r==="K")return(t-32)*5/9+273.15}else if(e==="K"){if(r==="C")return t-273.15;if(r==="F")return(t-273.15)*9/5+32}return t}function xr(e){const r=Ve[e];if(!r)return null;const t={},n=[];for(const[o,c]of Object.entries(r))typeof c.factor=="number"&&(t[o]=c.factor),n.push(o);return{default:Object.keys(r)[0]??"",units:n,factors:t}}const Rt=Object.freeze(Object.defineProperty({__proto__:null,convertTemperature:vr,dimensionUnitDisplayMap:Ie,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,getUnitFactors:xr,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),wr=u.memo(({disabled:e,inputValue:r,selectedUnit:t,dimension:n,unitFactors:a,onConversionSelect:o,t:c})=>{const[i,s]=u.useState(!1),[m,l]=u.useState(null),[f,p]=u.useState([]),h=u.useCallback(b=>{if(e)return;const y=parseFloat(r);if(!Number.isFinite(y))return;const N=b.currentTarget.getBoundingClientRect();l({x:N.left,y:N.bottom});const M=[];if(n==="temperature")a.units.forEach(I=>{const R=vr(t,I,y);Number.isFinite(R)&&M.push({label:`${R.toFixed(6)} ${c(I)}`,value:R.toString(),unit:I})});else{const I=a.factors[t];I!==void 0&&Object.entries(a.factors).forEach(([R,E])=>{const x=y/I*E;Number.isFinite(x)&&M.push({label:`${x.toFixed(6)} ${c(R)}`,value:x.toString(),unit:R})})}p(M),s(M.length>0)},[e,r,t,n,a,c]),w=u.useCallback(b=>{s(!1),l(null),o(b)},[o]),j=u.useCallback(()=>{s(!1),l(null)},[]);return d.jsxs(d.Fragment,{children:[d.jsx("button",{onClick:h,disabled:e,"aria-disabled":e,style:{width:"var(--reactaform-unit-btn-width, 2.5em)",height:"auto",padding:"var(--reactaform-input-padding)",boxSizing:"border-box",border:"none",borderRadius:"var(--reactaform-button-border-radius, var(--reactaform-border-radius, 0.25em))",backgroundColor:e?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:e?"not-allowed":"pointer",opacity:e?.6:1,display:"flex",alignItems:"center",justifyContent:"center",alignSelf:"center",lineHeight:1},children:d.jsx("span",{style:{fontSize:"1em",pointerEvents:"none"},children:"⇄"})}),i&&f.length>0&&d.jsx(Mt,{pos:m,options:f,onClose:j,onClickOption:w})]})});wr.displayName="ConversionButton";const At=({field:e,value:r,onChange:t,onError:n})=>{const{t:a}=L(),o=O(e),c=e.dimension,i=u.useMemo(()=>c?xr(c):null,[c]),s=String(r?.[0]??""),m=String(r?.[1]??i?.default??""),[l,f]=u.useState(s),[p,h]=u.useState(m);u.useEffect(()=>{f(s)},[s]),u.useEffect(()=>{h(m)},[m]);const w=o([l,p]);u.useEffect(()=>{n?.(w)},[w,n]);const j=u.useCallback(F=>{const I=F.target.value;f(I),o([I,p]),t?.([I,p])},[p,o,t]),b=u.useCallback(F=>{const I=F.target.value;h(I),o([l,I]),t?.([l,I])},[l,o,t]),y=u.useCallback(F=>{f(F.value),h(F.unit),t?.([F.value,F.unit])},[t]),N=u.useMemo(()=>i?i.units.map(F=>d.jsx("option",{value:F,children:a(F)},F)):[],[i,a]);if(!c||!i)return null;const M=!!w||!l.trim();return d.jsx(z,{field:e,error:w,children:d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[d.jsx("input",{id:e.name,type:"text",value:l,onChange:j,style:{flex:"2 1 0"},className:B(V.input,V.textInput),"aria-invalid":!!w,"aria-describedby":w?`${e.name}-error`:void 0}),d.jsx("select",{id:`${e.name}-unit`,value:p,onChange:b,style:{flex:"1 1 0"},className:B(V.input,V.inputSelect),"aria-invalid":!!w,"aria-describedby":w?`${e.name}-error`:void 0,children:N}),d.jsx(wr,{disabled:M,inputValue:l,selectedUnit:p,dimension:c,unitFactors:i,onConversionSelect:y,t:a})]})})},$t=u.memo(At),Dt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=O(e),{inputRef:c,error:i,handleChange:s}=_({value:r,onChange:t,onError:n,validate:o}),m=a??i;return d.jsx(z,{field:e,error:m,children:d.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:c,onChange:s,className:B(V.input,V.textInput),placeholder:"https://example.com","aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},Pt={checkbox:!1,switch:!1,radio:!1,dropdown:!1,"multi-selection":!1,color:!1,rating:!1,file:!1,image:!1,separator:!1,string:{wait:200},text:{wait:200},multiline:{wait:200},email:{wait:200},password:{wait:200},phone:{wait:200},url:{wait:200},int:{wait:200},float:{wait:200},unit:{wait:100},date:{wait:150},time:{wait:150},slider:{wait:100,leading:!0,trailing:!0},stepper:{wait:100,leading:!0,trailing:!0}},me=new ie,Re={checkbox:Qr,color:at,date:ot,dropdown:st,email:ct,file:ut,float:ft,"float-array":mt,image:pt,int:ht,"int-array":gt,"multi-selection":yt,multiline:bt,password:Et,phone:wt,radio:St,rating:jt,separator:lt,slider:Nt,string:Ge,stepper:xt,switch:Ft,text:Ge,time:It,unit:$t,url:Dt};function zt(e){return e in Re}function Ot(e,r){const{wait:t=200,leading:n,trailing:a}=r,o=u.memo(c=>{const i=u.useRef(c.onChange);u.useEffect(()=>{i.current=c.onChange},[c.onChange]);const{callback:s,cancel:m}=or((...l)=>{i.current?.(...l)},t,{leading:n,trailing:a});return u.useEffect(()=>m,[m]),u.createElement(e,{...c,onChange:s})});return o.displayName="DebouncedFieldWrapper",o}function Sr(e,r,t){const n=r;if(!t&&e in Re){console.warn(`Can't overwrite base component type "${e}".`);return}const a=Pt[e];if(a===!1){me.register(e,n);return}const o=a??{wait:200};ar?me.register(e,n):me.register(e,Ot(n,o))}function Ae(e,r){Sr(e,r,!1)}function $e(e){return me.get(e)}let Je=!1;function Lt(){Je||(Object.entries(Re).forEach(([e,r])=>{Sr(e,r,!0)}),Je=!0)}const Tt=(e,r)=>{const t=new Map;let n=null,a=null,o=0;for(const c of e){const i=c.group;if(!i){n=null,a=null;continue}if(i===n)r[c.name].group=a??i;else{if(!t.has(i))t.set(i,1),a=null,r[c.name].group=i;else{const s=t.get(i),m=`${i}(${s})`;t.set(i,s+1),a=m,r[c.name].group=m,o++}n=i}}return o},Ht=(e,r={})=>{const{includeEmpty:t=!0}=r,n=[];let a=null,o=[],c=0;for(const s of e){const m=s.group||null;m!==a?((o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o})),a=m,o=[s]):o.push(s)}(o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o}));const i=Math.max(0,...n.map(s=>s.fields.length));return{groups:n,metadata:{totalGroups:n.length,emptyGroups:c,largestGroup:i}}},Cr=u.memo(({field:e,value:r,handleChange:t,handleError:n,error:a})=>{const o=$e(e.type),c=u.useMemo(()=>r,[r]),i=u.useCallback(m=>t(e.name,m),[t,e.name]),s=u.useCallback(m=>n?.(e.name,m),[n,e.name]);return o?d.jsx(o,{field:e,value:c,onChange:i,onError:s,error:a}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError&&e.error===r.error);Cr.displayName="FieldWrapper";const kr=(e,r,t,n,a)=>{const o=a?a[e.name]??null:void 0;return d.jsx(u.Fragment,{children:d.jsx(Cr,{field:e,value:r[e.name],handleChange:t,handleError:n,error:o})},e.name)},jr=u.memo(({groupName:e,isOpen:r,fields:t,valuesMap:n,handleChange:a,handleError:o,errorsMap:c,toggleGroup:i,t:s})=>{const m=u.useCallback(()=>i(e),[i,e]),{formStyle:l,fieldStyle:f}=L(),p=u.useMemo(()=>({border:"1px solid var(--reactaform-border-color, #bbb)",padding:"var(--reactaform-fieldset-padding, 0.5em)",borderRadius:"var(--reactaform-border-radius, 4px)",marginBottom:"var(--reactaform-space, 8px)",...l?.fieldset||{},...f?.fieldset||{}}),[l,f]),h=u.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...l?.legend||{},...f?.legend||{}}),[l,f]);return d.jsxs("fieldset",{style:p,children:[d.jsxs("legend",{onClick:m,style:h,children:[d.jsx("span",{children:s(e)}),d.jsx("span",{children:r?" ▼":" ▶"})]}),r&&t.map(w=>kr(w,n,a,o,c))]})});jr.displayName="FieldGroup";const Bt=(e,r,t,n,a,o,c,i,s,m)=>{const l=r.slice(0,i).filter(h=>c[h.name]),f=Ht(l),p=[];return f.groups.forEach(h=>{if(h.name){const w=e[h.name]??!0;p.push(d.jsx(jr,{groupName:h.name,isOpen:w,fields:h.fields,valuesMap:t,handleChange:a,handleError:o,errorsMap:m,toggleGroup:s,t:n},h.name))}else h.fields.forEach(w=>p.push(kr(w,t,a,o,m)))}),p},qt=e=>{const r={};return e.forEach(t=>{r[t.name]=!1}),r},De=(e,r,t,n)=>{const a=r[e];if(!a||!a.children)return;const o=t[e],c=o!=null?String(o):"",i=a.children[c];!i||!Array.isArray(i)||i.forEach(s=>{typeof s=="string"&&(n[s]=!0,De(s,r,t,n))})},Er=(e,r,t)=>{const n=r[e];!n||!n.children||Object.values(n.children).filter(Array.isArray).flat().forEach(a=>{typeof a=="string"&&a in t&&(t[a]=!1,Er(a,r,t))})},Ut=(e,r,t,n)=>{const a={...t};return e.forEach(o=>{(!o.parents||Object.keys(o.parents).length===0)&&(a[o.name]=!0,De(o.name,n,r,a))}),a},Wt=(e,r,t,n,a)=>{const o={...e};if(Er(n,r,o),a!=null){const c=r[n];if(c&&c.children){const i=String(a),s=c.children[i];s&&Array.isArray(s)&&s.forEach(m=>{typeof m=="string"&&(o[m]=!0,De(m,r,t,o))})}}return o},Pe=new ie;function ze(e,r){Pe.register(e,r)}function _t(e){return Pe.get(e)}function Kt(e){return Pe.get(e)}ze("Preset_AlertSubmitHandler",(e,r,t)=>{const n={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:t},a=JSON.stringify(n,null,2);alert(a)});async function Gt(e,r,t,n,a,o,c){const i=Object.values(a).filter(Boolean);if(i.length>0)return{success:!1,message:n("Please fix validation errors before submitting."),errors:i};const s={...t},m=[];if(e&&Array.isArray(e.properties))for(const l of e.properties){const f=l.name,p=s[f];if(p==null)continue;const h=l.type;try{if(h==="int"||h==="number"||h==="float"){const w=String(p).trim();if(w==="")s[f]=0;else{const j=Number(w);isNaN(j)?m.push(n("Invalid number format for field {{1}}",l.displayName||f)):s[f]=j}}else if(h==="int-array"||h==="float-array"){const w=String(p).split(",").map(y=>y.trim()).filter(Boolean),j=[];let b=!1;for(const y of w){const N=Number(y);if(isNaN(N)){m.push(n("Invalid number {{1}} in array for field {{2}}",y,l.displayName||f)),b=!0;break}j.push(N)}b||(s[f]=j)}}catch(w){m.push(n("Error processing field {{1}}: {{2}}",l.displayName||f,w instanceof Error?w.message:String(w)))}}if(m.length>0)return{success:!1,message:n("Data transformation errors occurred."),errors:m};if(c){const l=await c(s,n);if(l&&l.length>0)return{success:!1,message:n("Validation failed"),errors:l}}else{const l=await Zr(e,s,n);if(l&&l.length>0)return{success:!1,message:n("Validation failed"),errors:l}}if(o)try{const l=await o(e,r?.name??null,s,n);if(l&&l.length>0)return{success:!1,message:n("Submission failed"),errors:Array.isArray(l)?l:[String(l)]}}catch(l){return{success:!1,message:n("Submission handler error occurred"),errors:[String(l instanceof Error?l.message:l)]}}else if(e&&typeof e.submitHandlerName=="string"){const l=_t(e.submitHandlerName);if(l)try{const f=await l(e,r?.name??null,s,n);if(f&&f.length>0)return{success:!1,message:n("Submission failed"),errors:Array.isArray(f)?f:[String(f)]}}catch(f){return{success:!1,message:n("Submission handler error occurred"),errors:[String(f instanceof Error?f.message:f)]}}}return{success:!0,message:n("Form submitted successfully."),data:s}}const Nr=({message:e,success:r,onDismiss:t,t:n})=>e?d.jsxs("div",{role:"status",style:{marginBottom:12,padding:12,borderRadius:6,backgroundColor:r?"rgba(76, 175, 80, 0.12)":"rgba(225, 29, 72, 0.06)",border:`1px solid ${r?"rgba(76,175,80,0.3)":"rgba(225,29,72,0.12)"}`,color:r?"var(--reactaform-success-color, #4CAF50)":"var(--reactaform-error-color, #e11d48)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[d.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:e}),d.jsx("button",{onClick:t,"aria-label":n("Dismiss"),style:{marginLeft:12,background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:16,lineHeight:1},children:"×"})]}):null;Nr.displayName="SubmissionMessage";const Jt=({onClick:e,disabled:r=!1,t})=>{const[n,a]=u.useState(!1);return d.jsx("button",{onClick:e,disabled:r,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{padding:"var(--reactaform-button-padding, var(--reactaform-space) 12px)",backgroundColor:r?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",border:"none",borderRadius:"4px",cursor:r?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",fontSize:"var(--reactaform-button-font-size, 14px)",fontWeight:"var(--reactaform-button-font-weight, 500)",boxShadow:"var(--reactaform-button-shadow, none)",marginTop:"var(--reactaform-button-margin-top, 0.5em)",transition:"opacity 0.2s ease",opacity:r?"var(--reactaform-button-disabled-opacity, 0.6)":n?"var(--reactaform-button-hover-opacity, 0.9)":"1"},children:t("Submit")})},Fr=({definition:e,instance:r,onSubmit:t=void 0,onValidation:n=void 0,chunkSize:a=50,chunkDelay:o=50})=>{const{properties:c,displayName:i}=e,s=L(),{t:m,formStyle:l,language:f,displayInstanceName:p}=s,h={...s,definitionName:e?.name??s.definitionName},[w,j]=u.useState("en"),[b,y]=u.useState([]),[N,M]=u.useState({}),[F,I]=u.useState({}),[R,E]=u.useState({}),[x,g]=u.useState({}),[v,C]=u.useState({}),[k,S]=u.useState(null),[A,$]=u.useState(null),[W,ce]=u.useState(0),[Te,zr]=u.useState(!1),[He,ae]=u.useState(r.name||""),J=u.useRef(r),de=u.useRef(!1);u.useEffect(()=>{const P=Object.fromEntries(c.map(D=>[D.name,{...D,children:{}}]));c.forEach(D=>{D.parents&&Object.entries(D.parents).forEach(([ee,re])=>{const oe=P[ee];oe&&re.forEach(qr=>{oe.children||(oe.children={});const Be=String(qr);oe.children[Be]=[...oe.children[Be]||[],D.name]})})}),Tt(c,P);const H=Object.values(P),q={};H.forEach(D=>{if(D.type==="unit"){const ee=typeof D.defaultValue=="number"?String(D.defaultValue):"",re=typeof D.defaultUnit=="string"?D.defaultUnit:String(D.defaultUnit??"m");q[D.name]=[ee,re]}else q[D.name]=D.defaultValue}),J.current=r,Object.keys(r.values).forEach(D=>{P[D]!==void 0&&(q[D]=r.values[D])});const Y=qt(H),K={};H.forEach(D=>{D.group&&!(D.group in K)&&(K[D.group]=!0)});const Z=requestAnimationFrame(()=>{y(H),M(P),I(q),E(Ut(H,q,Y,P)),g(K),zr(!0),ae(r.name)});return()=>cancelAnimationFrame(Z)},[c,r,e]),u.useEffect(()=>{if(!Te||W>=b.length)return;const P=setTimeout(()=>{ce(H=>Math.min(H+a,b.length))},o);return()=>clearTimeout(P)},[Te,W,b.length,a,o]);const Or=u.useCallback((P,H)=>{S(null),$(null),I(q=>{const Y={...q,[P]:H},K=N[P];return K&&["checkbox","dropdown","multi-select","radio","switch"].includes(K.type)&&E(D=>Wt(D,N,Y,P,String(H))),Y})},[N,S,$]);u.useEffect(()=>{let P=0;return P=requestAnimationFrame(()=>{f!==w&&(j(f||"en"),S(null),$(null))}),()=>cancelAnimationFrame(P)},[f,w]),u.useEffect(()=>{let P=0;return P=requestAnimationFrame(()=>{if(de.current){de.current=!1,J.current=r,ae(r.name||"");return}J.current=r,S(null),$(null),ae(r.name||"")}),()=>cancelAnimationFrame(P)},[r,r.name]);const Lr=u.useCallback((P,H)=>{C(q=>H?{...q,[P]:String(H)}:Object.fromEntries(Object.entries(q).filter(([K])=>K!==P)))},[]),Tr=async()=>{de.current=!0;const P=J.current?.name;J.current.name=He;let H=v;if(h.fieldValidationMode==="onSubmission"){const Z={};if(b.forEach(D=>{const ee=F[D.name];if(ee===void 0)return;const re=br(h.definitionName,D,ee,m);re&&(Z[D.name]=re)}),C(Z),H=Z,Object.keys(Z).length>0){S(m("Please fix validation errors before submitting the form.")),$(!1);return}else S(null),$(null)}const q=await Gt(e,J.current,F,m,H,t,n),Y=typeof q.message=="string"?q.message:String(q.message),K=Object.values(q.errors??{}).join(`
|
|
344
|
+
`);S(K?Y+`
|
|
345
|
+
`+K:Y),$(q.success),q.success||(J.current.name=P??J.current.name,ae(P??""))},Hr=P=>{g(H=>({...H,[P]:!H[P]}))},Br=u.useMemo(()=>h.fieldValidationMode==="realTime"?Object.values(v).some(Boolean):!1,[v,h.fieldValidationMode]);return d.jsx(ke.Provider,{value:h,children:d.jsxs("div",{style:l.container,children:[i&&d.jsx("h2",{style:l.titleStyle,children:m(i)}),d.jsx(Nr,{message:k,success:A,onDismiss:()=>{S(null),$(null)},t:m}),p&&r&&d.jsx(cr,{name:He,onChange:P=>{ae(P),S(null),$(null)}}),d.jsxs(d.Fragment,{children:[Bt(x,b,F,m,Or,Lr,R,W,Hr,v),W<b.length&&d.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"},children:m(`Loading more fields... (${W}/${b.length})`)})]}),d.jsx(Jt,{onClick:Tr,disabled:Br,t:m})]})})},Ir={en:{name:"English",nativeName:"English"},fr:{name:"French",nativeName:"Français"},de:{name:"German",nativeName:"Deutsch"},es:{name:"Spanish",nativeName:"Español"},"zh-cn":{name:"Chinese (Simplified)",nativeName:"简体中文"},bg:{name:"Bulgarian",nativeName:"Български"},cs:{name:"Czech",nativeName:"Čeština"},da:{name:"Danish",nativeName:"Dansk"},el:{name:"Greek",nativeName:"Ελληνικά"},fi:{name:"Finnish",nativeName:"Suomi"},hi:{name:"Hindi",nativeName:"हिन्दी"},hu:{name:"Hungarian",nativeName:"Magyar"},id:{name:"Indonesian",nativeName:"Bahasa Indonesia"},it:{name:"Italian",nativeName:"Italiano"},ja:{name:"Japanese",nativeName:"日本語"},ko:{name:"Korean",nativeName:"한국어"},ms:{name:"Malay",nativeName:"Bahasa Melayu"},nl:{name:"Dutch",nativeName:"Nederlands"},no:{name:"Norwegian",nativeName:"Norsk"},pl:{name:"Polish",nativeName:"Polski"},pt:{name:"Portuguese",nativeName:"Português"},ro:{name:"Romanian",nativeName:"Română"},ru:{name:"Russian",nativeName:"Русский"},sk:{name:"Slovak",nativeName:"Slovenčina"},sv:{name:"Swedish",nativeName:"Svenska"},th:{name:"Thai",nativeName:"ไทย"},tr:{name:"Turkish",nativeName:"Türkçe"},uk:{name:"Ukrainian",nativeName:"Українська"},vi:{name:"Vietnamese",nativeName:"Tiếng Việt"},"zh-tw":{name:"Chinese (Traditional)",nativeName:"繁體中文"}},Yt=()=>Ir,ge=new Map,le=new Map,te=new Set,ye=new Map,Xt=async e=>{try{let r={};const t=e.toLowerCase();switch(t){case"fr":r=(await Promise.resolve().then(()=>require("./common-CiL5z7rS.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-pqSYL5rx.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-BeQ3x_ll.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-C9xi6Anp.js"))).default;break;case"en":r={};break;default:if(Ir[t]){const a=`https://reactaform.vercel.app/locales/${t}/common.json`,o=await fetch(a);o.ok&&(r=await o.json())}else r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},Zt=async e=>{if(!e)return{success:!1,translations:{},error:"Language is required"};if(!e||e.toLowerCase()==="en")return{success:!0,translations:{},fromCache:!1};const r=e.toLowerCase();if(ge.has(r))return{success:!0,translations:ge.get(r)||{},fromCache:!0};const t=await Xt(r);return t.success&&(ge.set(r,t.translations),ye.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},Qt=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const t=`${e.toLowerCase()}/${r}`;if(te.has(t))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(le.has(t))return{success:!0,translations:le.get(t)||{},fromCache:!0};try{let n=r;!r.includes("/")&&!r.includes(".")&&(n=`/locales/${e}/${r}.json`);const a=await fetch(n);if(!a.ok)return a.status===404?(le.set(t,{}),ye.set(t,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(te.add(t),{success:!1,translations:{},error:`HTTP ${a.status}`,fromCache:!1});const o=a.headers.get("content-type")||"";!o.includes("application/json")&&!o.includes("text/json")&&Mr()&&console.warn(`Translation file at ${n} has unexpected content-type: ${o}`);const c=await a.text();if(!c){const m="Empty translation file";return te.add(t),{success:!1,translations:{},error:m}}let i;try{i=JSON.parse(c)}catch(m){const l=`Invalid JSON in translation file: ${m instanceof Error?m.message:String(m)}`;return te.add(t),{success:!1,translations:{},error:l}}if(!i||typeof i!="object"){const m="Invalid translation file format";return te.add(t),{success:!1,translations:{},error:m}}const s=Object.fromEntries(Object.entries(i).map(([m,l])=>[m,typeof l=="string"?l:String(l)]));return le.set(t,s),ye.set(t,{loadedAt:new Date,size:Object.keys(s).length,source:"user"}),{success:!0,translations:s,fromCache:!1}}catch(n){const a=`Failed to load user translations: ${n instanceof Error?n.message:"Unknown error"}`;return te.add(t),{success:!1,translations:{},error:a}}};function Mr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function en(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(t,n)=>{const a=parseInt(n,10)-1,o=r[a];return o==null?t:String(o)})}const rn=(e,r,t)=>(n,...a)=>{let o=n,c=!1;return!n||typeof n!="string"?String(n||""):(e.toLowerCase()==="en"?(o=n,c=!0):n in t?(o=t[n],c=!0):n in r?(o=r[n],c=!0):o=n,o=en(o,a),!c&&Mr()&&console.debug(`Missing translation for "${n}" in language "${e}"`),o)};function tn(e){return/^[-+]?\d*$/.test(e)}function nn(e){const r=/^[-+]?\d*$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const an=",",on=e=>!e||e.trim()===""?[]:e.split(an).map(r=>r.trim()).filter(Boolean).map(r=>Number(r)),Ye=(e,r,t)=>{const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!tn(n))return t("Must be a valid integer");const a=parseInt(n,10);if(Number.isNaN(a))return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?a<e.min:a<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?a>e.max:a>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const o=Number(e.step);if(!Number.isInteger(o))return t("Invalid step value");if(a%o!==0)return t("Must be a multiple of {{1}}",o)}return null};function sn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!nn(n))return t("Each value must be a valid integer");const a=on(n);if(e.minCount!==void 0&&a.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&a.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const o of a){if(e.min!==void 0&&(e.minInclusive?o<e.min:o<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?o>e.max:o>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return null}function ve(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;const a=Number(n);if(Number.isNaN(a))return t("Must be a valid float");if(e.min!==void 0){const o=e.type==="slider"?!0:e.minInclusive??!0;if(o?a<e.min:a<=e.min)return t("Must be {{1}} {{2}}",o?"≥":">",e.min)}if(e.max!==void 0){const o=e.type==="slider"?!0:e.maxInclusive??!0;if(o?a>e.max:a>=e.max)return t("Must be {{1}} {{2}}",o?"≤":"<",e.max)}return null}const cn=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function ln(e){return e.split(",").map(r=>r.trim()).every(r=>cn.test(r))}const un=",",mn=e=>!e||e.trim()===""?[]:e.split(un).map(r=>r.trim()).filter(Boolean).map(r=>Number(r));function fn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!ln(n))return t("Each value must be a valid float");const a=mn(n);if(e.minCount!==void 0&&a.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&a.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const o of a){if(e.min!==void 0&&(e.minInclusive?o<e.min:o<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?o>e.max:o>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return null}const he=new WeakMap;function Oe(e,r,t,n,...a){if(e.pattern==null)return null;const o=String(r);let c=null;if(e.pattern){const i=he.get(e);if(i&&i.pattern===e.pattern)c=i.regex;else try{const s=new RegExp(e.pattern);he.set(e,{pattern:e.pattern,regex:s}),c=s}catch{he.set(e,{pattern:e.pattern,regex:null}),c=null}}return c&&!c.test(o)?e.patternErrorMessage?t(e.patternErrorMessage):n?t(n,...a):t("Input does not match pattern: {{1}}",e.pattern):null}function ue(e,r,t){const n=String(r);return n.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&n.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&n.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):Oe(e,r,t,"Invalid text format")}const xe=e=>{if(!e)return null;const r=Date.parse(e);return Number.isNaN(r)?null:r},Xe=new WeakMap,dn=e=>{let r=Xe.get(e);return r||(r={minTime:xe(e.minDate),maxTime:xe(e.maxDate)},Xe.set(e,r)),r};function pn(e,r,t){if(r==null||String(r).trim()==="")return e.required?t("Value required"):null;const n=String(r).trim(),a=xe(n);if(a===null)return t("Invalid date format");const{minTime:o,maxTime:c}=dn(e);return o!==null&&a<o?t("Date must be on or after {{1}}",e.minDate):c!==null&&a>c?t("Date must be on or before {{1}}",e.maxDate):null}function gn(e,r,t){const n=String(r);if(!n||n.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const a=c=>{const i=c.split(":").map(l=>parseInt(l,10));if(i.some(l=>Number.isNaN(l)))return NaN;const s=i.length;if(s<2||s>3)return NaN;if(s===2&&(i[0]<0||i[0]>23||i[1]<0||i[1]>59))return NaN;if(s===3&&(i[0]<0||i[0]>23||i[1]<0||i[1]>59||i[2]<0||i[2]>59))return NaN;let m=0;if(i.length===3)m=i[0]*3600+i[1]*60+i[2];else if(i.length===2)m=i[0]*3600+i[1]*60;else if(i.length===1)m=i[0]*3600;else return NaN;return m},o=a(n);if(Number.isNaN(o))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const c=a(e.min);if(!Number.isNaN(c)&&o<c)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const c=a(e.max);if(!Number.isNaN(c)&&o>c)return t("Time must be on or before {{1}}",e.max)}return null}function hn(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function bn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:hn(n)?Oe(e,r,t,t("Email does not match pattern: {{1}}",e.pattern)):t("Must be valid email format")}function yn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:Oe(e,n,t,"Invalid phone number format")}const vn=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,xn=e=>{try{return new URL(e),!0}catch{return!1}};function wn(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;if(vn.test(n)||xn(n))return null;if(e.allowRelative===!0){if(!n.startsWith("/")||encodeURI(n)!==n)return t("Must be a valid URL");try{return new URL(n,"http://example.com"),null}catch{return t("Must be a valid URL")}}return t("Must be a valid URL")}function Sn(e,r,t){const n=Array.isArray(r)?r:[],a=n[0],o=n[1]?String(n[1]).trim():"";return String(a??"").trim()===""||o===""?e.required?t("Value required"):null:ve(e,a,t)}function Cn(e,r,t){if(Array.isArray(r))return r.length===0?t("Select a file"):r.every(n=>n instanceof File)?null:t("Invalid file input");if(!(r instanceof File)){const n=String(r);return e.required&&(r==null||typeof n=="string"&&n.trim()==="")?t("Select a file"):t("Invalid file input: {{1}}",n)}return null}function kn(e,r,t){const n=String(r);return n===""||n===null||n===void 0?e.required?t("Value required"):null:e.options?.some(a=>String(a.value)===n)?null:t("Invalid option selected")}function jn(e,r,t){const a=String(r??"").trim();if(a==="")return e.required?t("Value required"):null;const o=a.split(",").map(c=>c.trim()).filter(c=>c!=="");if(o.length===0)return e.required?t("Value required"):null;for(const c of o)if(!e.options?.some(i=>String(i.value)===c))return t("Invalid option selected");return null}const En=/^#([0-9A-F]{3}){1,2}$/i,Nn=e=>En.test(e);function Fn(e,r,t){const n=String(r).trim();return n===""?e.required?t("Value required"):null:Nn(n)?null:t("Invalid color format")}function In(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;let a=r;return typeof r!="number"&&(a=parseFloat(n)),Number.isNaN(a)||a<=0?t("Invalid value"):e.max!==void 0&&a>e.max?t("Must be ≤ {{1}}",e.max):null}let Ze=!1;function Vr(){Ze||(T("int",Ye),T("stepper",Ye),T("int-array",sn),T("float",ve),T("slider",ve),T("float-array",fn),T("text",ue),T("string",ue),T("multiline",ue),T("password",ue),T("email",bn),T("date",pn),T("time",gn),T("url",wn),T("phone",yn),T("unit",Sn),T("dropdown",kn),T("multi-selection",jn),T("color",Fn),T("rating",In),T("file",Cn),Ze=!0)}Vr();Lt();Vr();const Mn=e=>({container:{padding:"var(--reactaform-space-sm, 8px)",margin:"0 auto",backgroundColor:"transparent",borderRadius:0,color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, system-ui, -apple-system, sans-serif)",boxSizing:"border-box",minHeight:e?.minHeight??"0",...e?.width?{width:e.width,overflowX:"auto"}:{maxWidth:"100%"},...e?.height?{height:e.height,overflowY:"auto"}:{}},buttonStyle:{padding:"var(--reactaform-space-sm, 8px) var(--reactaform-space-md, 16px)",backgroundColor:"var(--reactaform-color-primary)",color:"var(--reactaform-color-background)",border:"1px solid var(--reactaform-color-primary)",borderRadius:"var(--reactaform-border-radius, 6px)",cursor:"pointer",fontSize:e?.fontSize||"1rem",fontWeight:"600",transition:"all 0.2s ease",boxShadow:"var(--reactaform-shadow-small, 0 1px 3px rgba(0, 0, 0, 0.12))"},titleStyle:{marginBottom:"var(--reactaform-space-lg, 24px)",color:"var(--reactaform-color-text)",fontSize:typeof e?.fontSize=="number"?`${e.fontSize*1.5}px`:"1.5rem",fontWeight:"700",lineHeight:"1.2",textAlign:"left"}}),Vn=e=>{const r={color:"var(--reactaform-color-text)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",transition:"all 0.2s ease",outline:"none",width:"100%",boxSizing:"border-box"};return{container:{fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)",fontSize:e?.fontSize||"var(--reactaform-font-size, 1rem)",width:"100%",maxWidth:e?.width||"100%",marginBottom:"var(--reactaform-space-md, 16px)"},label:{display:"block",marginBottom:"var(--reactaform-space-xs, 4px)",fontWeight:"500",color:"var(--reactaform-color-text)",fontSize:"var(--reactaform-font-size, 1rem)",fontFamily:e?.fontFamily||"var(--reactaform-font-family, inherit)"},input:r,textInput:r,optionInput:r,select:{...r,cursor:"pointer",backgroundRepeat:"no-repeat",backgroundPosition:"right 8px center",backgroundSize:"16px",paddingRight:"32px",backgroundImage:`url("data:image/svg+xml;utf8,<svg
|
|
335
346
|
xmlns='http://www.w3.org/2000/svg'
|
|
336
347
|
viewBox='0 0 24 24'
|
|
337
348
|
fill='none'
|
|
@@ -340,4 +351,4 @@
|
|
|
340
351
|
stroke-linecap='round'
|
|
341
352
|
stroke-linejoin='round'>
|
|
342
353
|
<polyline points='6,9 12,15 18,9'/>
|
|
343
|
-
</svg>")`},textarea:{...r,minHeight:"80px",resize:"vertical",paddingTop:"var(--reactaform-space-sm, 8px)"},error:{color:"var(--reactaform-color-error)",fontSize:"0.875rem",marginTop:"var(--reactaform-space-xs, 4px)",display:"block"}}},Rr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:n="en",defaultTheme:a="light",defaultLocalizeName:o="",defaultFieldValidationMode:i="realTime",className:c="reactaform-container",defaultDisplayInstanceName:s=!0})=>{const u=r,l=o,f=a,p=n,g=m.useMemo(()=>t??{},[t]),[x,j]=m.useState({}),[h,v]=m.useState({});m.useEffect(()=>{let y=!0;return(async()=>{if(p==="en"){y&&(j({}),v({}));return}try{const C=await Zt(p),N=C.success?C.translations:{};y&&j(N);const M=await Qt(p,l),k=M.success?M.translations:{};y&&v(k)}catch{y&&(j({}),v({}))}})(),()=>{y=!1}},[p,l]);const E=m.useMemo(()=>Mn(g),[g]),R=m.useMemo(()=>Vn(g),[g]),F=m.useMemo(()=>rn(p,x,h),[p,x,h]),w=m.useCallback((y,...b)=>F(y,...b),[F]),I=m.useMemo(()=>({definitionName:u,language:p,theme:f,formStyle:E,fieldStyle:R,t:w,fieldValidationMode:i,displayInstanceName:s}),[u,p,f,R,E,w,i,s]),S=g?.height?{height:"100%"}:void 0;return d.jsx(ke.Provider,{value:I,children:d.jsx("div",{"data-reactaform-theme":f,className:c,style:S,children:e})})};function Rn(e){if(!e||typeof e!="object")return"Definition must be an object";const r=e;if(!r.name||typeof r.name!="string")return"Definition must include a 'name' string";if(r.name.trim()==="")return"Definition 'name' cannot be empty";if(!r.version||typeof r.version!="string")return"Definition must include a 'version' string";if(r.properties!==void 0&&!Array.isArray(r.properties))return"'properties' must be an array if provided";if(Array.isArray(r.properties))for(let t=0;t<r.properties.length;t++){const n=r.properties[t];if(!n||typeof n!="object")return`Property at index ${t} must be an object`;if(!n.name||typeof n.name!="string")return`Property at index ${t} must have a string 'name'`;if(n.name.trim()==="")return`Property at index ${t} has an empty 'name'`;if(!n.type||typeof n.type!="string")return`Property '${n.name}' must have a string 'type'`;if(n.type.trim()==="")return`Property '${n.name}' has an empty 'type'`}return null}async function $n(e,r={}){const{validateSchema:t=!0}=r;try{if(!e||typeof e!="string")return{success:!1,error:"jsonData must be a non-empty JSON string"};const n=e.trim();if(!n)return{success:!1,error:"jsonData is empty"};let a;try{a=JSON.parse(n)}catch(o){return{success:!1,error:`Invalid JSON format: ${o instanceof Error?o.message:"Unknown parsing error"}`}}if(t){const o=Rn(a);if(o)return{success:!1,error:`Schema validation failed: ${o}`}}return{success:!0,definition:a}}catch(n){return{success:!1,error:`Unexpected error loading definition: ${n instanceof Error?n.message:"Unknown error"}`}}}function $r(e,r){try{if(!e)return{success:!1,error:"Definition is required"};if(!r||typeof r!="string")return{success:!1,error:"Instance name is required"};const t={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},n=e.properties||[];return Array.isArray(n)&&n.forEach(a=>{const o=a;if(o.type==="unit"){const i=o.defaultUnit,c=Number(o.defaultValue)||void 0;t.values[o.name]=[c||0,i||"m"]}else o.defaultValue!==void 0&&(t.values[o.name]=o.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function An(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(t){return{success:!1,error:`Invalid JSON format: ${t instanceof Error?t.message:"Unknown parsing error"}`}}else r=e;return typeof r!="object"||r===null?{success:!1,error:"Instance must be a valid object"}:{success:!0,instance:r}}catch(r){return{success:!1,error:`Error loading instance: ${r instanceof Error?r.message:"Unknown error"}`}}}function Dn(e,r,t){try{if(!e)return{success:!1,error:"Instance is required"};if(!r)return{success:!1,error:"Latest definition is required"};if(e.definition===r.name&&e.version===r.version)return{success:!0,instance:e};const n={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},a=n.values,o={};(r.properties||[]).forEach(s=>{o[s.name]=s});const i=(s,u,l)=>{if(s==null)return s;const f=u.toLowerCase();try{if(f==="string"||f==="text")return String(s);if(f==="int"||f==="integer"||f==="number"||f==="float"){if(typeof s=="number")return s;if(typeof s=="boolean")return s?1:0;if(typeof s=="string"){const p=s.trim();if(p==="")return null;const g=Number(p);return Number.isNaN(g)?0:g}return 0}if(f==="boolean"||f==="bool"||f==="checkbox"||f==="switch"){if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;if(typeof s=="string"){const p=s.toLowerCase().trim();return["true","1","yes","on"].includes(p)}return!!s}if(f==="unit"){if(Array.isArray(s)&&s.length>=2)return s;if(Array.isArray(s)&&s.length===1)return[s[0],l&&l.defaultUnit||"m"];if(typeof s=="number")return[s,l&&l.defaultUnit||"m"];if(typeof s=="string"){const p=Number(s);return[Number.isNaN(p)?0:p,l&&l.defaultUnit||"m"]}return[0,l&&l.defaultUnit||"m"]}if(f.endsWith("[]")||f==="array"||f==="int-array"||f==="float-array")return Array.isArray(s)?s:typeof s=="string"?s.split(",").map(p=>p.trim()).filter(Boolean):[s]}catch{}return s},c=e.values||{};Object.keys(c).forEach(s=>{const u=c[s],l=o[s];if(!l)return;const f=Array.isArray(u)?"array":u===null?"null":typeof u,p=(l.type||"").toLowerCase();f===p||p==="string"&&typeof u=="string"?a[s]=u:a[s]=i(u,p,l)}),(r.properties||[]).forEach(s=>{const u=s.name;u in a||(a[u]=s.defaultValue)});try{typeof t=="function"&&t?.(e,n,r)}catch(s){return{success:!1,error:`Upgrade callback error: ${s instanceof Error?s.message:String(s)}`}}return{success:!0,instance:n}}catch(n){return{success:!1,error:`Error upgrading instance: ${n instanceof Error?n.message:"Unknown error"}`}}}function Pn(e){const[r,t]=m.useState(null);return m.useEffect(()=>{const n=document.querySelector("[data-reactaform-theme]");if(!n)return;const a=n.closest("[data-reactaform-theme]");if(!a)return;const o=()=>t(a.getAttribute("data-reactaform-theme"));o();const i=new MutationObserver(c=>{for(const s of c)s.type==="attributes"&&s.attributeName==="data-reactaform-theme"&&o()});return i.observe(a,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>i.disconnect()},[e]),r}const zn=({definitionData:e,instance:r,language:t,className:n,theme:a,style:o,fieldValidationMode:i="realTime",displayInstanceName:c=!0,onSubmit:s=void 0,onValidation:u=void 0})=>{const l=m.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),f={fontSize:"inherit",fontFamily:"inherit",...o},p=Pn(),g=a??p??"light",x=t??"en";m.useEffect(()=>{let h=document.getElementById("popup-root");h||(h=document.createElement("div"),h.id="popup-root",document.body.appendChild(h))},[]);const j=m.useMemo(()=>{if(r)return r;if(!l)return null;const h=$r(l,l.name);return!h.success||!h.instance?null:h.instance},[r,l]);return l?j?d.jsx(Rr,{definitionName:l.name,defaultStyle:f,defaultLanguage:x,defaultTheme:g,defaultLocalizeName:l.localization||"",className:n,defaultFieldValidationMode:i,defaultDisplayInstanceName:c,children:d.jsx(Fr,{definition:l,instance:j,onSubmit:s,onValidation:u})}):d.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."}):d.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."})},X=new Map,U={components:new Map,fieldValidators:new Map,fieldTypeValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function Ar(e,r,t){if(!e)return!0;if(t&&!t(e))return!1;switch(r){case"error":throw new Error(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}"`);case"warn":return console.warn(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}". Skipping.`),!1;case"override":return console.info(`Plugin "${e.newPlugin}" is overriding ${e.type} "${e.name}" previously registered by "${e.existingPlugin}"`),!0;case"skip":return!1}}function On(e){const r=[];if(e.components)for(const t of Object.keys(e.components)){const n=Ae(t);if(n){let a;for(const[o,i]of X)if(i.components&&i.components[t]===n){a=o;break}a&&a!==e.name&&r.push({type:"component",name:t,existingPlugin:a,newPlugin:e.name})}}if(e.fieldCustomValidators)for(const[t,n]of Object.entries(e.fieldCustomValidators))for(const a of Object.keys(n)){const i=U.fieldValidators.get(t)?.get(a);pr(t,a)&&i&&i!==e.name&&r.push({type:"fieldCustomValidator",name:`${t}:${a}`,existingPlugin:i,newPlugin:e.name})}if(e.fieldTypeValidators)for(const t of Object.keys(e.fieldTypeValidators)){const n=hr(t),a=U.fieldTypeValidators.get(t);n&&a&&a!==e.name&&r.push({type:"fieldTypeValidator",name:`type:${t}`,existingPlugin:a,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const n=gr(t),a=U.formValidators.get(t);n&&a&&a!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:a,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const n=Kt(t),a=U.submissionHandlers.get(t);n&&a&&a!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:a,newPlugin:e.name})}return r}function oe(e,r,t,n,a,o,i,c){for(const s of Object.keys(e)){let u;if(c?u=a.find(l=>l.type==="fieldCustomValidator"&&l.name===`${c}:${s}`):e===n.components?u=a.find(l=>l.type==="component"&&l.name===s):e===n.formValidators?u=a.find(l=>l.type==="formValidator"&&l.name===s):e===n.fieldTypeValidators?u=a.find(l=>l.type==="fieldTypeValidator"&&l.name===`type:${s}`):e===n.submissionHandlers&&(u=a.find(l=>l.type==="submissionHandler"&&l.name===s)),Ar(u||null,o,i))if(c){const l=r.get(c)||new Map;l.set(s,n.name),r.set(c,l),t(s,e[s])}else r===U.components?r.set(s,e[s]):r.set(s,n.name),t(s,e[s])}}function Ln(e,r){const t=r?.conflictResolution||"error";if(X.has(e.name)){const a={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!Ar(a,t,r?.onConflict))return}const n=On(e);if(e.components&&oe(e.components,U.components,$e,e,n,t,r?.onConflict),e.fieldCustomValidators)for(const[a,o]of Object.entries(e.fieldCustomValidators))oe(o,U.fieldValidators,(i,c)=>fr(a,i,c),e,n,t,r?.onConflict,a);e.formValidators&&oe(e.formValidators,U.formValidators,mr,e,n,t,r?.onConflict),e.fieldTypeValidators&&oe(e.fieldTypeValidators,U.fieldTypeValidators,dr,e,n,t,r?.onConflict),e.submissionHandlers&&oe(e.submissionHandlers,U.submissionHandlers,ze,e,n,t,r?.onConflict),e.setup&&e.setup(),X.set(e.name,e)}function Tn(e,r=!1){const t=X.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const n of Object.keys(t.components))U.components.delete(n);if(t.fieldCustomValidators)for(const[n,a]of Object.entries(t.fieldCustomValidators)){const o=U.fieldValidators.get(n);if(o){for(const i of Object.keys(a))o.delete(i);o.size===0&&U.fieldValidators.delete(n)}}if(t.formValidators)for(const n of Object.keys(t.formValidators))U.formValidators.delete(n);if(t.fieldTypeValidators)for(const n of Object.keys(t.fieldTypeValidators))U.fieldTypeValidators.delete(n);if(t.submissionHandlers)for(const n of Object.keys(t.submissionHandlers))U.submissionHandlers.delete(n)}return X.delete(e),!0}function Hn(e){return X.get(e)}function Bn(){return Array.from(X.values())}function qn(e){return X.has(e)}function Un(e){for(const[r,t]of Object.entries(e))$e(r,t)}function Q(e){return typeof e=="object"&&e!==null}function Le(e){if(!Q(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Dr(e){if(!Q(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(t=>Le(t))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=Q(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Wn(e,r,t={}){try{const{includeMetadata:n=!1,dateFormat:a="iso",fileHandling:o="metadata",prettify:i=!1,excludeFields:c=[],includeOnlyFields:s=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const u=[],l=[],f={},g=(Dr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),x=new Map(g.map(h=>[h.name,h]));for(const[h,v]of Object.entries(e)){if(c.includes(h)){l.push(h);continue}if(s.length>0&&!s.includes(h)){l.push(h);continue}if(v===void 0)continue;const E=x.get(h);try{f[h]=_n(v,E,{dateFormat:a,fileHandling:o})}catch(R){u.push(`Error serializing field '${h}': ${String(R)}`),f[h]=null}}return n&&(f._metadata={serializedAt:new Date().toISOString(),version:(Q(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(f).length-1}),{success:!0,data:i?JSON.stringify(f,null,2):JSON.stringify(f),metadata:{fieldCount:Object.keys(f).length,excludedFields:l,warnings:u}}}catch(n){return{success:!1,error:`Serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function _n(e,r,t={}){const{dateFormat:n="iso",fileHandling:a="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Qe(e,n);case"file":return er(e,a);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(o=>typeof o=="string"?Number(o):o):e;default:return e}return e instanceof Date?Qe(e,n):we(e)||Array.isArray(e)&&we(e[0])?er(e,a):e}function Qe(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const n=new Date(e);if(!isNaN(n.getTime()))t=n;else return e}else return e;switch(r){case"timestamp":return t.getTime();case"locale":return t.toLocaleString();case"iso":default:return t.toISOString()}}function er(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>rr(t,r)):rr(e,r)}function rr(e,r){if(!we(e))return e;const t=e;return r==="metadata"?{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified}:{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified,_note:"Base64 encoding requires async implementation"}}function Kn(e,r,t={}){try{const{strict:n=!1,validateTypes:a=!0,preserveUnknownFields:o=!0,dateFormat:i="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let c;try{c=JSON.parse(e)}catch(j){return{success:!1,error:`Invalid JSON: ${j instanceof Error?j.message:"Unknown parsing error"}`}}if(!c||typeof c!="object")return{success:!1,error:"Parsed data must be an object"};const s=[],u=[],l={},p=(Dr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),g=new Map(p.map(j=>[j.name,j]));for(const j of p){const h=j.name,v=c[h];if(v===void 0){n&&j.required&&u.push(`Required field '${h}' is missing`);continue}try{l[h]=Gn(v,j,{validateTypes:a,dateFormat:i})}catch(E){const R=`Error deserializing field '${h}': ${String(E)}`;n?u.push(R):(s.push(R),l[h]=v)}}if(o)for(const[j,h]of Object.entries(c))!g.has(j)&&j!=="_metadata"&&(n&&s.push(`Unknown field '${j}' preserved`),l[j]=h);const x=u.length>0;return{success:!x,data:l,warnings:s.length>0?s:void 0,validationErrors:x?u:void 0}}catch(n){return{success:!1,error:`Deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Gn(e,r,t={}){const{validateTypes:n=!0,dateFormat:a="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Xn(e,a,n);case"int":case"integer":return Se(e,n);case"float":case"number":return Ce(e,n);case"boolean":return Zn(e,n);case"int-array":return tr(e,"integer",n);case"float-array":return tr(e,"number",n);case"string":case"text":case"email":case"url":case"phone":return n?String(e):e;default:return e}}catch(o){if(n)throw new Error(`Type conversion failed: ${String(o)}`);return e}}function Jn(e,r={}){try{const{prettify:t=!0,includeMetadata:n=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const a={...e};return n&&(a._metadata={serializedAt:new Date().toISOString(),version:a.version||"1.0.0",propertyCount:(Array.isArray(a.properties)?a.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(a,null,2):JSON.stringify(a),metadata:{fieldCount:(Array.isArray(a.properties)?a.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Yn(e,r={}){try{const{strict:t=!1,validateTypes:n=!0}=r;let a;if(typeof e=="string")try{a=JSON.parse(e)}catch(l){return{success:!1,error:`Invalid JSON for definition: ${l instanceof Error?l.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")a={...e};else return{success:!1,error:"Input must be a string or object"};const o=[],i=[],c=["name","version","displayName"];for(const l of c)if(!(l in a)||!a[l])if(t)i.push(`Required field '${l}' is missing`);else switch(o.push(`Missing field '${l}', using default`),l){case"name":a.name="unnamed-definition";break;case"version":a.version="1.0.0";break;case"displayName":a.displayName=a.name||"Unnamed Definition";break}const s=Array.isArray(a.properties)?a.properties:null;s?a.properties=s.map((l,f)=>{const p=Q(l)?l:{},g={...p};if(!p.name){const x=`Property at index ${f} missing 'name'`;t?i.push(x):(o.push(`${x}, using 'field_${f}'`),g.name=`field_${f}`)}return p.displayName||(g.displayName=p.name||`Field ${f}`),p.type||(t&&n?i.push(`Property '${p.name||f}' missing 'type'`):(o.push(`Property '${p.name||f}' missing 'type', using 'string'`),g.type="string")),p.defaultValue===void 0&&(g.defaultValue=null),p.required===void 0&&(g.required=!1),g}):t?i.push("Properties must be an array"):(o.push("Properties not found or invalid, using empty array"),a.properties=[]);const u=i.length>0;return{success:!u,data:a,warnings:o.length>0?o:void 0,validationErrors:u?i:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Xn(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid timestamp: ${e}`);return n}if(typeof e=="string"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid date string: ${e}`);return n}if(t)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"){if(Number.isInteger(e))return e;if(r)throw new Error(`Number ${e} is not an integer`);return Math.floor(e)}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to integer");return e}const n=parseInt(t,10);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to integer`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function Ce(e,r){if(typeof e=="number"){if(r&&!isFinite(e))throw new Error(`Number ${e} is not finite`);return e}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to number");return e}const n=parseFloat(t);if(r&&(isNaN(n)||!isFinite(n)))throw new Error(`Cannot convert "${e}" to number`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Zn(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function tr(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(a=>a.trim()).filter(Boolean).map(a=>r==="integer"?Se(a,t):Ce(a,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((n,a)=>{try{return r==="integer"?Se(n,t):Ce(n,t)}catch(o){if(t)throw new Error(`Array element ${a}: ${o}`);return n}})}function Pr(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Wr,document.head.appendChild(e)}catch{}}typeof document<"u"&&Pr();exports.CSS_CLASSES=V;exports.ReactaForm=zn;exports.ReactaFormProvider=Rr;exports.ReactaFormRenderer=Fr;exports.StandardFieldLayout=z;exports.Units=Rt;exports.combineClasses=B;exports.createInstanceFromDefinition=$r;exports.deserializeDefinition=Yn;exports.deserializeInstance=Kn;exports.getAllPlugins=Bn;exports.getComponent=Ae;exports.getPlugin=Hn;exports.getSupportedLanguages=Yt;exports.hasPlugin=qn;exports.injectReactaFormStyles=Pr;exports.isDarkTheme=ie;exports.loadInstance=An;exports.loadJsonDefinition=$n;exports.registerComponent=$e;exports.registerComponents=Un;exports.registerFieldCustomValidationHandler=fr;exports.registerFieldTypeValidationHandler=dr;exports.registerFormValidationHandler=mr;exports.registerPlugin=Ln;exports.registerSubmissionHandler=ze;exports.serializeDefinition=Jn;exports.serializeInstance=Wn;exports.unregisterPlugin=Tn;exports.upgradeInstanceToLatestDefinition=Dn;exports.useDebouncedCallback=or;exports.useFieldValidator=O;exports.useReactaFormContext=L;exports.useUncontrolledValidatedInput=W;exports.validateFieldValue=Xr;exports.validateFieldWithCustomHandler=Ne;
|
|
354
|
+
</svg>")`},textarea:{...r,minHeight:"80px",resize:"vertical",paddingTop:"var(--reactaform-space-sm, 8px)"},error:{color:"var(--reactaform-color-error)",fontSize:"0.875rem",marginTop:"var(--reactaform-space-xs, 4px)",display:"block"}}},Rr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:n="en",defaultTheme:a="light",defaultLocalizeName:o="",defaultFieldValidationMode:c="realTime",className:i="reactaform-container",defaultDisplayInstanceName:s=!0})=>{const m=r,l=o,f=a,p=n,h=u.useMemo(()=>t??{},[t]),[w,j]=u.useState({}),[b,y]=u.useState({});u.useEffect(()=>{let x=!0;return(async()=>{if(p==="en"){x&&(j({}),y({}));return}try{const v=await Zt(p),C=v.success?v.translations:{};x&&j(C);const k=await Qt(p,l),S=k.success?k.translations:{};x&&y(S)}catch{x&&(j({}),y({}))}})(),()=>{x=!1}},[p,l]);const N=u.useMemo(()=>Mn(h),[h]),M=u.useMemo(()=>Vn(h),[h]),F=u.useMemo(()=>rn(p,w,b),[p,w,b]),I=u.useCallback((x,...g)=>F(x,...g),[F]),R=u.useMemo(()=>({definitionName:m,language:p,theme:f,formStyle:N,fieldStyle:M,t:I,fieldValidationMode:c,displayInstanceName:s}),[m,p,f,M,N,I,c,s]),E=h?.height?{height:"100%"}:void 0;return d.jsx(ke.Provider,{value:R,children:d.jsx("div",{"data-reactaform-theme":f,className:i,style:E,children:e})})};function Rn(e){if(!e||typeof e!="object")return"Definition must be an object";const r=e;if(!r.name||typeof r.name!="string")return"Definition must include a 'name' string";if(r.name.trim()==="")return"Definition 'name' cannot be empty";if(!r.version||typeof r.version!="string")return"Definition must include a 'version' string";if(r.properties!==void 0&&!Array.isArray(r.properties))return"'properties' must be an array if provided";if(Array.isArray(r.properties))for(let t=0;t<r.properties.length;t++){const n=r.properties[t];if(!n||typeof n!="object")return`Property at index ${t} must be an object`;if(!n.name||typeof n.name!="string")return`Property at index ${t} must have a string 'name'`;if(n.name.trim()==="")return`Property at index ${t} has an empty 'name'`;if(!n.type||typeof n.type!="string")return`Property '${n.name}' must have a string 'type'`;if(n.type.trim()==="")return`Property '${n.name}' has an empty 'type'`}return null}async function An(e,r={}){const{validateSchema:t=!0}=r;try{if(!e||typeof e!="string")return{success:!1,error:"jsonData must be a non-empty JSON string"};const n=e.trim();if(!n)return{success:!1,error:"jsonData is empty"};let a;try{a=JSON.parse(n)}catch(o){return{success:!1,error:`Invalid JSON format: ${o instanceof Error?o.message:"Unknown parsing error"}`}}if(t){const o=Rn(a);if(o)return{success:!1,error:`Schema validation failed: ${o}`}}return{success:!0,definition:a}}catch(n){return{success:!1,error:`Unexpected error loading definition: ${n instanceof Error?n.message:"Unknown error"}`}}}function Ar(e,r){try{if(!e)return{success:!1,error:"Definition is required"};if(!r||typeof r!="string")return{success:!1,error:"Instance name is required"};const t={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},n=e.properties||[];return Array.isArray(n)&&n.forEach(a=>{const o=a;if(o.type==="unit"){const c=o.defaultUnit,i=Number(o.defaultValue)||void 0;t.values[o.name]=[i||0,c||"m"]}else o.defaultValue!==void 0&&(t.values[o.name]=o.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function $n(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(t){return{success:!1,error:`Invalid JSON format: ${t instanceof Error?t.message:"Unknown parsing error"}`}}else r=e;return typeof r!="object"||r===null?{success:!1,error:"Instance must be a valid object"}:{success:!0,instance:r}}catch(r){return{success:!1,error:`Error loading instance: ${r instanceof Error?r.message:"Unknown error"}`}}}function Dn(e,r,t){try{if(!e)return{success:!1,error:"Instance is required"};if(!r)return{success:!1,error:"Latest definition is required"};if(e.definition===r.name&&e.version===r.version)return{success:!0,instance:e};const n={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},a=n.values,o={};(r.properties||[]).forEach(s=>{o[s.name]=s});const c=(s,m,l)=>{if(s==null)return s;const f=m.toLowerCase();try{if(f==="string"||f==="text")return String(s);if(f==="int"||f==="integer"||f==="number"||f==="float"){if(typeof s=="number")return s;if(typeof s=="boolean")return s?1:0;if(typeof s=="string"){const p=s.trim();if(p==="")return null;const h=Number(p);return Number.isNaN(h)?0:h}return 0}if(f==="boolean"||f==="bool"||f==="checkbox"||f==="switch"){if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;if(typeof s=="string"){const p=s.toLowerCase().trim();return["true","1","yes","on"].includes(p)}return!!s}if(f==="unit"){if(Array.isArray(s)&&s.length>=2)return s;if(Array.isArray(s)&&s.length===1)return[s[0],l&&l.defaultUnit||"m"];if(typeof s=="number")return[s,l&&l.defaultUnit||"m"];if(typeof s=="string"){const p=Number(s);return[Number.isNaN(p)?0:p,l&&l.defaultUnit||"m"]}return[0,l&&l.defaultUnit||"m"]}if(f.endsWith("[]")||f==="array"||f==="int-array"||f==="float-array")return Array.isArray(s)?s:typeof s=="string"?s.split(",").map(p=>p.trim()).filter(Boolean):[s]}catch{}return s},i=e.values||{};Object.keys(i).forEach(s=>{const m=i[s],l=o[s];if(!l)return;const f=Array.isArray(m)?"array":m===null?"null":typeof m,p=(l.type||"").toLowerCase();f===p||p==="string"&&typeof m=="string"?a[s]=m:a[s]=c(m,p,l)}),(r.properties||[]).forEach(s=>{const m=s.name;m in a||(a[m]=s.defaultValue)});try{typeof t=="function"&&t?.(e,n,r)}catch(s){return{success:!1,error:`Upgrade callback error: ${s instanceof Error?s.message:String(s)}`}}return{success:!0,instance:n}}catch(n){return{success:!1,error:`Error upgrading instance: ${n instanceof Error?n.message:"Unknown error"}`}}}function Pn(e){const[r,t]=u.useState(null);return u.useEffect(()=>{const n=document.querySelector("[data-reactaform-theme]");if(!n)return;const a=n.closest("[data-reactaform-theme]");if(!a)return;const o=()=>t(a.getAttribute("data-reactaform-theme"));o();const c=new MutationObserver(i=>{for(const s of i)s.type==="attributes"&&s.attributeName==="data-reactaform-theme"&&o()});return c.observe(a,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>c.disconnect()},[e]),r}const zn=({definitionData:e,instance:r,language:t,className:n,theme:a,style:o,fieldValidationMode:c="realTime",displayInstanceName:i=!0,onSubmit:s=void 0,onValidation:m=void 0})=>{const l=u.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),f={fontSize:"inherit",fontFamily:"inherit",...o},p=Pn(),h=a??p??"light",w=t??"en";u.useEffect(()=>{let b=document.getElementById("popup-root");b||(b=document.createElement("div"),b.id="popup-root",document.body.appendChild(b))},[]);const j=u.useMemo(()=>{if(r)return r;if(!l)return null;const b=Ar(l,l.name);return!b.success||!b.instance?null:b.instance},[r,l]);return l?j?d.jsx(Rr,{definitionName:l.name,defaultStyle:f,defaultLanguage:w,defaultTheme:h,defaultLocalizeName:l.localization||"",className:n,defaultFieldValidationMode:c,defaultDisplayInstanceName:i,children:d.jsx(Fr,{definition:l,instance:j,onSubmit:s,onValidation:m})}):d.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."}):d.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."})},X=new Map,U={components:new Map,fieldValidators:new Map,fieldTypeValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function $r(e,r,t){if(!e)return!0;if(t&&!t(e))return!1;switch(r){case"error":throw new Error(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}"`);case"warn":return console.warn(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}". Skipping.`),!1;case"override":return console.info(`Plugin "${e.newPlugin}" is overriding ${e.type} "${e.name}" previously registered by "${e.existingPlugin}"`),!0;case"skip":return!1}}function On(e){const r=[];if(e.components)for(const t of Object.keys(e.components)){const n=$e(t);if(n){let a;for(const[o,c]of X)if(c.components&&c.components[t]===n){a=o;break}a&&a!==e.name&&r.push({type:"component",name:t,existingPlugin:a,newPlugin:e.name})}}if(e.fieldCustomValidators)for(const[t,n]of Object.entries(e.fieldCustomValidators))for(const a of Object.keys(n)){const c=U.fieldValidators.get(t)?.get(a);pr(t,a)&&c&&c!==e.name&&r.push({type:"fieldCustomValidator",name:`${t}:${a}`,existingPlugin:c,newPlugin:e.name})}if(e.fieldTypeValidators)for(const t of Object.keys(e.fieldTypeValidators)){const n=hr(t),a=U.fieldTypeValidators.get(t);n&&a&&a!==e.name&&r.push({type:"fieldTypeValidator",name:`type:${t}`,existingPlugin:a,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const n=gr(t),a=U.formValidators.get(t);n&&a&&a!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:a,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const n=Kt(t),a=U.submissionHandlers.get(t);n&&a&&a!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:a,newPlugin:e.name})}return r}function se(e,r,t,n,a,o,c,i){for(const s of Object.keys(e)){let m;if(i?m=a.find(l=>l.type==="fieldCustomValidator"&&l.name===`${i}:${s}`):e===n.components?m=a.find(l=>l.type==="component"&&l.name===s):e===n.formValidators?m=a.find(l=>l.type==="formValidator"&&l.name===s):e===n.fieldTypeValidators?m=a.find(l=>l.type==="fieldTypeValidator"&&l.name===`type:${s}`):e===n.submissionHandlers&&(m=a.find(l=>l.type==="submissionHandler"&&l.name===s)),$r(m||null,o,c))if(i){const l=r.get(i)||new Map;l.set(s,n.name),r.set(i,l),t(s,e[s])}else r===U.components?r.set(s,e[s]):r.set(s,n.name),t(s,e[s])}}function Ln(e,r){const t=r?.conflictResolution||"error";if(X.has(e.name)){const a={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!$r(a,t,r?.onConflict))return}const n=On(e);if(e.components&&se(e.components,U.components,Ae,e,n,t,r?.onConflict),e.fieldCustomValidators)for(const[a,o]of Object.entries(e.fieldCustomValidators))se(o,U.fieldValidators,(c,i)=>fr(a,c,i),e,n,t,r?.onConflict,a);e.formValidators&&se(e.formValidators,U.formValidators,mr,e,n,t,r?.onConflict),e.fieldTypeValidators&&se(e.fieldTypeValidators,U.fieldTypeValidators,dr,e,n,t,r?.onConflict),e.submissionHandlers&&se(e.submissionHandlers,U.submissionHandlers,ze,e,n,t,r?.onConflict),e.setup&&e.setup(),X.set(e.name,e)}function Tn(e,r=!1){const t=X.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const n of Object.keys(t.components))U.components.delete(n);if(t.fieldCustomValidators)for(const[n,a]of Object.entries(t.fieldCustomValidators)){const o=U.fieldValidators.get(n);if(o){for(const c of Object.keys(a))o.delete(c);o.size===0&&U.fieldValidators.delete(n)}}if(t.formValidators)for(const n of Object.keys(t.formValidators))U.formValidators.delete(n);if(t.fieldTypeValidators)for(const n of Object.keys(t.fieldTypeValidators))U.fieldTypeValidators.delete(n);if(t.submissionHandlers)for(const n of Object.keys(t.submissionHandlers))U.submissionHandlers.delete(n)}return X.delete(e),!0}function Hn(e){return X.get(e)}function Bn(){return Array.from(X.values())}function qn(e){return X.has(e)}function Un(e){for(const[r,t]of Object.entries(e))Ae(r,t)}function Q(e){return typeof e=="object"&&e!==null}function Le(e){if(!Q(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Dr(e){if(!Q(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(t=>Le(t))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=Q(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Wn(e,r,t={}){try{const{includeMetadata:n=!1,dateFormat:a="iso",fileHandling:o="metadata",prettify:c=!1,excludeFields:i=[],includeOnlyFields:s=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],l=[],f={},h=(Dr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),w=new Map(h.map(b=>[b.name,b]));for(const[b,y]of Object.entries(e)){if(i.includes(b)){l.push(b);continue}if(s.length>0&&!s.includes(b)){l.push(b);continue}if(y===void 0)continue;const N=w.get(b);try{f[b]=_n(y,N,{dateFormat:a,fileHandling:o})}catch(M){m.push(`Error serializing field '${b}': ${String(M)}`),f[b]=null}}return n&&(f._metadata={serializedAt:new Date().toISOString(),version:(Q(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(f).length-1}),{success:!0,data:c?JSON.stringify(f,null,2):JSON.stringify(f),metadata:{fieldCount:Object.keys(f).length,excludedFields:l,warnings:m}}}catch(n){return{success:!1,error:`Serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function _n(e,r,t={}){const{dateFormat:n="iso",fileHandling:a="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Qe(e,n);case"file":return er(e,a);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(o=>typeof o=="string"?Number(o):o):e;default:return e}return e instanceof Date?Qe(e,n):we(e)||Array.isArray(e)&&we(e[0])?er(e,a):e}function Qe(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const n=new Date(e);if(!isNaN(n.getTime()))t=n;else return e}else return e;switch(r){case"timestamp":return t.getTime();case"locale":return t.toLocaleString();case"iso":default:return t.toISOString()}}function er(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>rr(t,r)):rr(e,r)}function rr(e,r){if(!we(e))return e;const t=e;return r==="metadata"?{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified}:{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified,_note:"Base64 encoding requires async implementation"}}function Kn(e,r,t={}){try{const{strict:n=!1,validateTypes:a=!0,preserveUnknownFields:o=!0,dateFormat:c="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let i;try{i=JSON.parse(e)}catch(j){return{success:!1,error:`Invalid JSON: ${j instanceof Error?j.message:"Unknown parsing error"}`}}if(!i||typeof i!="object")return{success:!1,error:"Parsed data must be an object"};const s=[],m=[],l={},p=(Dr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),h=new Map(p.map(j=>[j.name,j]));for(const j of p){const b=j.name,y=i[b];if(y===void 0){n&&j.required&&m.push(`Required field '${b}' is missing`);continue}try{l[b]=Gn(y,j,{validateTypes:a,dateFormat:c})}catch(N){const M=`Error deserializing field '${b}': ${String(N)}`;n?m.push(M):(s.push(M),l[b]=y)}}if(o)for(const[j,b]of Object.entries(i))!h.has(j)&&j!=="_metadata"&&(n&&s.push(`Unknown field '${j}' preserved`),l[j]=b);const w=m.length>0;return{success:!w,data:l,warnings:s.length>0?s:void 0,validationErrors:w?m:void 0}}catch(n){return{success:!1,error:`Deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Gn(e,r,t={}){const{validateTypes:n=!0,dateFormat:a="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Xn(e,a,n);case"int":case"integer":return Se(e,n);case"float":case"number":return Ce(e,n);case"boolean":return Zn(e,n);case"int-array":return tr(e,"integer",n);case"float-array":return tr(e,"number",n);case"string":case"text":case"email":case"url":case"phone":return n?String(e):e;default:return e}}catch(o){if(n)throw new Error(`Type conversion failed: ${String(o)}`);return e}}function Jn(e,r={}){try{const{prettify:t=!0,includeMetadata:n=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const a={...e};return n&&(a._metadata={serializedAt:new Date().toISOString(),version:a.version||"1.0.0",propertyCount:(Array.isArray(a.properties)?a.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(a,null,2):JSON.stringify(a),metadata:{fieldCount:(Array.isArray(a.properties)?a.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Yn(e,r={}){try{const{strict:t=!1,validateTypes:n=!0}=r;let a;if(typeof e=="string")try{a=JSON.parse(e)}catch(l){return{success:!1,error:`Invalid JSON for definition: ${l instanceof Error?l.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")a={...e};else return{success:!1,error:"Input must be a string or object"};const o=[],c=[],i=["name","version","displayName"];for(const l of i)if(!(l in a)||!a[l])if(t)c.push(`Required field '${l}' is missing`);else switch(o.push(`Missing field '${l}', using default`),l){case"name":a.name="unnamed-definition";break;case"version":a.version="1.0.0";break;case"displayName":a.displayName=a.name||"Unnamed Definition";break}const s=Array.isArray(a.properties)?a.properties:null;s?a.properties=s.map((l,f)=>{const p=Q(l)?l:{},h={...p};if(!p.name){const w=`Property at index ${f} missing 'name'`;t?c.push(w):(o.push(`${w}, using 'field_${f}'`),h.name=`field_${f}`)}return p.displayName||(h.displayName=p.name||`Field ${f}`),p.type||(t&&n?c.push(`Property '${p.name||f}' missing 'type'`):(o.push(`Property '${p.name||f}' missing 'type', using 'string'`),h.type="string")),p.defaultValue===void 0&&(h.defaultValue=null),p.required===void 0&&(h.required=!1),h}):t?c.push("Properties must be an array"):(o.push("Properties not found or invalid, using empty array"),a.properties=[]);const m=c.length>0;return{success:!m,data:a,warnings:o.length>0?o:void 0,validationErrors:m?c:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Xn(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid timestamp: ${e}`);return n}if(typeof e=="string"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid date string: ${e}`);return n}if(t)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"){if(Number.isInteger(e))return e;if(r)throw new Error(`Number ${e} is not an integer`);return Math.floor(e)}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to integer");return e}const n=parseInt(t,10);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to integer`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function Ce(e,r){if(typeof e=="number"){if(r&&!isFinite(e))throw new Error(`Number ${e} is not finite`);return e}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to number");return e}const n=parseFloat(t);if(r&&(isNaN(n)||!isFinite(n)))throw new Error(`Cannot convert "${e}" to number`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Zn(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function tr(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(a=>a.trim()).filter(Boolean).map(a=>r==="integer"?Se(a,t):Ce(a,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((n,a)=>{try{return r==="integer"?Se(n,t):Ce(n,t)}catch(o){if(t)throw new Error(`Array element ${a}: ${o}`);return n}})}function Pr(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Wr,document.head.appendChild(e)}catch{}}typeof document<"u"&&Pr();exports.CSS_CLASSES=V;exports.ReactaForm=zn;exports.ReactaFormProvider=Rr;exports.ReactaFormRenderer=Fr;exports.StandardFieldLayout=z;exports.Units=Rt;exports.combineClasses=B;exports.createInstanceFromDefinition=Ar;exports.deserializeDefinition=Yn;exports.deserializeInstance=Kn;exports.getAllPlugins=Bn;exports.getComponent=$e;exports.getPlugin=Hn;exports.getSupportedLanguages=Yt;exports.hasPlugin=qn;exports.injectReactaFormStyles=Pr;exports.isDarkTheme=ne;exports.loadInstance=$n;exports.loadJsonDefinition=An;exports.registerComponent=Ae;exports.registerComponents=Un;exports.registerFieldCustomValidationHandler=fr;exports.registerFieldTypeValidationHandler=dr;exports.registerFormValidationHandler=mr;exports.registerPlugin=Ln;exports.registerSubmissionHandler=ze;exports.serializeDefinition=Jn;exports.serializeInstance=Wn;exports.unregisterPlugin=Tn;exports.upgradeInstanceToLatestDefinition=Dn;exports.useDebouncedCallback=or;exports.useFieldValidator=O;exports.useReactaFormContext=L;exports.useUncontrolledValidatedInput=_;exports.validateFieldValue=Xr;exports.validateFieldWithCustomHandler=Ne;
|